Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #if V8_TARGET_ARCH_MIPS |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 7 | #include "src/code-stubs.h" |
| 8 | #include "src/api-arguments.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9 | #include "src/base/bits.h" |
| 10 | #include "src/bootstrapper.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #include "src/codegen.h" |
| 12 | #include "src/ic/handler-compiler.h" |
| 13 | #include "src/ic/ic.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 14 | #include "src/ic/stub-cache.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 15 | #include "src/isolate.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 16 | #include "src/mips/code-stubs-mips.h" |
| 17 | #include "src/regexp/jsregexp.h" |
| 18 | #include "src/regexp/regexp-macro-assembler.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 19 | #include "src/runtime/runtime.h" |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 20 | |
| 21 | namespace v8 { |
| 22 | namespace internal { |
| 23 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 24 | #define __ ACCESS_MASM(masm) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 25 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 26 | void ArrayNArgumentsConstructorStub::Generate(MacroAssembler* masm) { |
| 27 | __ sll(t9, a0, kPointerSizeLog2); |
| 28 | __ Addu(t9, sp, t9); |
| 29 | __ sw(a1, MemOperand(t9, 0)); |
| 30 | __ Push(a1); |
| 31 | __ Push(a2); |
| 32 | __ Addu(a0, a0, Operand(3)); |
| 33 | __ TailCallRuntime(Runtime::kNewArray); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 36 | void FastArrayPushStub::InitializeDescriptor(CodeStubDescriptor* descriptor) { |
| 37 | Address deopt_handler = Runtime::FunctionForId(Runtime::kArrayPush)->entry; |
| 38 | descriptor->Initialize(a0, deopt_handler, -1, JS_FUNCTION_STUB_MODE); |
| 39 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 40 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 41 | void FastFunctionBindStub::InitializeDescriptor( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 42 | CodeStubDescriptor* descriptor) { |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 43 | Address deopt_handler = Runtime::FunctionForId(Runtime::kFunctionBind)->entry; |
| 44 | descriptor->Initialize(a0, deopt_handler, -1, JS_FUNCTION_STUB_MODE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 47 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 48 | Condition cc); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 49 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 50 | Register lhs, |
| 51 | Register rhs, |
| 52 | Label* rhs_not_nan, |
| 53 | Label* slow, |
| 54 | bool strict); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 55 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 56 | Register lhs, |
| 57 | Register rhs); |
| 58 | |
| 59 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 60 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm, |
| 61 | ExternalReference miss) { |
| 62 | // Update the static counter each time a new code stub is generated. |
| 63 | isolate()->counters()->code_stubs()->Increment(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 64 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 65 | CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 66 | int param_count = descriptor.GetRegisterParameterCount(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 67 | { |
| 68 | // Call the runtime system in a fresh internal frame. |
| 69 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 70 | DCHECK(param_count == 0 || |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 71 | a0.is(descriptor.GetRegisterParameter(param_count - 1))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 72 | // Push arguments, adjust sp. |
| 73 | __ Subu(sp, sp, Operand(param_count * kPointerSize)); |
| 74 | for (int i = 0; i < param_count; ++i) { |
| 75 | // Store argument to stack. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 76 | __ sw(descriptor.GetRegisterParameter(i), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 77 | MemOperand(sp, (param_count - 1 - i) * kPointerSize)); |
| 78 | } |
| 79 | __ CallExternalReference(miss, param_count); |
| 80 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 81 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 82 | __ Ret(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 86 | void DoubleToIStub::Generate(MacroAssembler* masm) { |
| 87 | Label out_of_range, only_low, negate, done; |
| 88 | Register input_reg = source(); |
| 89 | Register result_reg = destination(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 90 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 91 | int double_offset = offset(); |
| 92 | // Account for saved regs if input is sp. |
| 93 | if (input_reg.is(sp)) double_offset += 3 * kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 94 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 95 | Register scratch = |
| 96 | GetRegisterThatIsNotOneOf(input_reg, result_reg); |
| 97 | Register scratch2 = |
| 98 | GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch); |
| 99 | Register scratch3 = |
| 100 | GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch2); |
| 101 | DoubleRegister double_scratch = kLithiumScratchDouble; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 102 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 103 | __ Push(scratch, scratch2, scratch3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 104 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 105 | if (!skip_fastpath()) { |
| 106 | // Load double input. |
| 107 | __ ldc1(double_scratch, MemOperand(input_reg, double_offset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 108 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 109 | // Clear cumulative exception flags and save the FCSR. |
| 110 | __ cfc1(scratch2, FCSR); |
| 111 | __ ctc1(zero_reg, FCSR); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 112 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 113 | // Try a conversion to a signed integer. |
| 114 | __ Trunc_w_d(double_scratch, double_scratch); |
| 115 | // Move the converted value into the result register. |
| 116 | __ mfc1(scratch3, double_scratch); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 117 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 118 | // Retrieve and restore the FCSR. |
| 119 | __ cfc1(scratch, FCSR); |
| 120 | __ ctc1(scratch2, FCSR); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 121 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 122 | // Check for overflow and NaNs. |
| 123 | __ And( |
| 124 | scratch, scratch, |
| 125 | kFCSROverflowFlagMask | kFCSRUnderflowFlagMask |
| 126 | | kFCSRInvalidOpFlagMask); |
| 127 | // If we had no exceptions then set result_reg and we are done. |
| 128 | Label error; |
| 129 | __ Branch(&error, ne, scratch, Operand(zero_reg)); |
| 130 | __ Move(result_reg, scratch3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 131 | __ Branch(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 132 | __ bind(&error); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 135 | // Load the double value and perform a manual truncation. |
| 136 | Register input_high = scratch2; |
| 137 | Register input_low = scratch3; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 138 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 139 | __ lw(input_low, |
| 140 | MemOperand(input_reg, double_offset + Register::kMantissaOffset)); |
| 141 | __ lw(input_high, |
| 142 | MemOperand(input_reg, double_offset + Register::kExponentOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 143 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 144 | Label normal_exponent, restore_sign; |
| 145 | // Extract the biased exponent in result. |
| 146 | __ Ext(result_reg, |
| 147 | input_high, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 148 | HeapNumber::kExponentShift, |
| 149 | HeapNumber::kExponentBits); |
| 150 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 151 | // Check for Infinity and NaNs, which should return 0. |
| 152 | __ Subu(scratch, result_reg, HeapNumber::kExponentMask); |
| 153 | __ Movz(result_reg, zero_reg, scratch); |
| 154 | __ Branch(&done, eq, scratch, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 155 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 156 | // Express exponent as delta to (number of mantissa bits + 31). |
| 157 | __ Subu(result_reg, |
| 158 | result_reg, |
| 159 | Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 160 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 161 | // If the delta is strictly positive, all bits would be shifted away, |
| 162 | // which means that we can return 0. |
| 163 | __ Branch(&normal_exponent, le, result_reg, Operand(zero_reg)); |
| 164 | __ mov(result_reg, zero_reg); |
| 165 | __ Branch(&done); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 166 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 167 | __ bind(&normal_exponent); |
| 168 | const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 169 | // Calculate shift. |
| 170 | __ Addu(scratch, result_reg, Operand(kShiftBase + HeapNumber::kMantissaBits)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 171 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 172 | // Save the sign. |
| 173 | Register sign = result_reg; |
| 174 | result_reg = no_reg; |
| 175 | __ And(sign, input_high, Operand(HeapNumber::kSignMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 176 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 177 | // On ARM shifts > 31 bits are valid and will result in zero. On MIPS we need |
| 178 | // to check for this specific case. |
| 179 | Label high_shift_needed, high_shift_done; |
| 180 | __ Branch(&high_shift_needed, lt, scratch, Operand(32)); |
| 181 | __ mov(input_high, zero_reg); |
| 182 | __ Branch(&high_shift_done); |
| 183 | __ bind(&high_shift_needed); |
| 184 | |
| 185 | // Set the implicit 1 before the mantissa part in input_high. |
| 186 | __ Or(input_high, |
| 187 | input_high, |
| 188 | Operand(1 << HeapNumber::kMantissaBitsInTopWord)); |
| 189 | // Shift the mantissa bits to the correct position. |
| 190 | // We don't need to clear non-mantissa bits as they will be shifted away. |
| 191 | // If they weren't, it would mean that the answer is in the 32bit range. |
| 192 | __ sllv(input_high, input_high, scratch); |
| 193 | |
| 194 | __ bind(&high_shift_done); |
| 195 | |
| 196 | // Replace the shifted bits with bits from the lower mantissa word. |
| 197 | Label pos_shift, shift_done; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 198 | __ li(at, 32); |
| 199 | __ subu(scratch, at, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 200 | __ Branch(&pos_shift, ge, scratch, Operand(zero_reg)); |
| 201 | |
| 202 | // Negate scratch. |
| 203 | __ Subu(scratch, zero_reg, scratch); |
| 204 | __ sllv(input_low, input_low, scratch); |
| 205 | __ Branch(&shift_done); |
| 206 | |
| 207 | __ bind(&pos_shift); |
| 208 | __ srlv(input_low, input_low, scratch); |
| 209 | |
| 210 | __ bind(&shift_done); |
| 211 | __ Or(input_high, input_high, Operand(input_low)); |
| 212 | // Restore sign if necessary. |
| 213 | __ mov(scratch, sign); |
| 214 | result_reg = sign; |
| 215 | sign = no_reg; |
| 216 | __ Subu(result_reg, zero_reg, input_high); |
| 217 | __ Movz(result_reg, input_high, scratch); |
| 218 | |
| 219 | __ bind(&done); |
| 220 | |
| 221 | __ Pop(scratch, scratch2, scratch3); |
| 222 | __ Ret(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 226 | // Handle the case where the lhs and rhs are the same object. |
| 227 | // Equality is almost reflexive (everything but NaN), so this is a test |
| 228 | // for "identity and not NaN". |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 229 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 230 | Condition cc) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 231 | Label not_identical; |
| 232 | Label heap_number, return_equal; |
| 233 | Register exp_mask_reg = t5; |
| 234 | |
| 235 | __ Branch(¬_identical, ne, a0, Operand(a1)); |
| 236 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 237 | __ li(exp_mask_reg, Operand(HeapNumber::kExponentMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 238 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 239 | // Test for NaN. Sadly, we can't just compare to Factory::nan_value(), |
| 240 | // so we do the second best thing - test it ourselves. |
| 241 | // They are both equal and they are not both Smis so both of them are not |
| 242 | // Smis. If it's not a heap number, then return equal. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 243 | __ GetObjectType(a0, t4, t4); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 244 | if (cc == less || cc == greater) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 245 | // Call runtime on identical JSObjects. |
| 246 | __ Branch(slow, greater, t4, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 247 | // Call runtime on identical symbols since we need to throw a TypeError. |
| 248 | __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE)); |
| 249 | // Call runtime on identical SIMD values since we must throw a TypeError. |
| 250 | __ Branch(slow, eq, t4, Operand(SIMD128_VALUE_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 251 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 252 | __ Branch(&heap_number, eq, t4, Operand(HEAP_NUMBER_TYPE)); |
| 253 | // Comparing JS objects with <=, >= is complicated. |
| 254 | if (cc != eq) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 255 | __ Branch(slow, greater, t4, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 256 | // Call runtime on identical symbols since we need to throw a TypeError. |
| 257 | __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE)); |
| 258 | // Call runtime on identical SIMD values since we must throw a TypeError. |
| 259 | __ Branch(slow, eq, t4, Operand(SIMD128_VALUE_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 260 | // Normally here we fall through to return_equal, but undefined is |
| 261 | // special: (undefined == undefined) == true, but |
| 262 | // (undefined <= undefined) == false! See ECMAScript 11.8.5. |
| 263 | if (cc == less_equal || cc == greater_equal) { |
| 264 | __ Branch(&return_equal, ne, t4, Operand(ODDBALL_TYPE)); |
| 265 | __ LoadRoot(t2, Heap::kUndefinedValueRootIndex); |
| 266 | __ Branch(&return_equal, ne, a0, Operand(t2)); |
| 267 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 268 | __ Ret(USE_DELAY_SLOT); |
| 269 | if (cc == le) { |
| 270 | // undefined <= undefined should fail. |
| 271 | __ li(v0, Operand(GREATER)); |
| 272 | } else { |
| 273 | // undefined >= undefined should fail. |
| 274 | __ li(v0, Operand(LESS)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | __ bind(&return_equal); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 281 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 282 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 283 | if (cc == less) { |
| 284 | __ li(v0, Operand(GREATER)); // Things aren't less than themselves. |
| 285 | } else if (cc == greater) { |
| 286 | __ li(v0, Operand(LESS)); // Things aren't greater than themselves. |
| 287 | } else { |
| 288 | __ mov(v0, zero_reg); // Things are <=, >=, ==, === themselves. |
| 289 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 290 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 291 | // For less and greater we don't have to check for NaN since the result of |
| 292 | // x < x is false regardless. For the others here is some code to check |
| 293 | // for NaN. |
| 294 | if (cc != lt && cc != gt) { |
| 295 | __ bind(&heap_number); |
| 296 | // It is a heap number, so return non-equal if it's NaN and equal if it's |
| 297 | // not NaN. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 298 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 299 | // The representation of NaN values has all exponent bits (52..62) set, |
| 300 | // and not all mantissa bits (0..51) clear. |
| 301 | // Read top bits of double representation (second word of value). |
| 302 | __ lw(t2, FieldMemOperand(a0, HeapNumber::kExponentOffset)); |
| 303 | // Test that exponent bits are all set. |
| 304 | __ And(t3, t2, Operand(exp_mask_reg)); |
| 305 | // If all bits not set (ne cond), then not a NaN, objects are equal. |
| 306 | __ Branch(&return_equal, ne, t3, Operand(exp_mask_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 307 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 308 | // Shift out flag and all exponent bits, retaining only mantissa. |
| 309 | __ sll(t2, t2, HeapNumber::kNonMantissaBitsInTopWord); |
| 310 | // Or with all low-bits of mantissa. |
| 311 | __ lw(t3, FieldMemOperand(a0, HeapNumber::kMantissaOffset)); |
| 312 | __ Or(v0, t3, Operand(t2)); |
| 313 | // For equal we already have the right value in v0: Return zero (equal) |
| 314 | // if all bits in mantissa are zero (it's an Infinity) and non-zero if |
| 315 | // not (it's a NaN). For <= and >= we need to load v0 with the failing |
| 316 | // value if it's a NaN. |
| 317 | if (cc != eq) { |
| 318 | // All-zero means Infinity means equal. |
| 319 | __ Ret(eq, v0, Operand(zero_reg)); |
| 320 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 321 | __ Ret(USE_DELAY_SLOT); |
| 322 | if (cc == le) { |
| 323 | __ li(v0, Operand(GREATER)); // NaN <= NaN should fail. |
| 324 | } else { |
| 325 | __ li(v0, Operand(LESS)); // NaN >= NaN should fail. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 326 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 327 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 328 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 329 | // No fall through here. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 330 | |
| 331 | __ bind(¬_identical); |
| 332 | } |
| 333 | |
| 334 | |
| 335 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 336 | Register lhs, |
| 337 | Register rhs, |
| 338 | Label* both_loaded_as_doubles, |
| 339 | Label* slow, |
| 340 | bool strict) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 341 | DCHECK((lhs.is(a0) && rhs.is(a1)) || |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 342 | (lhs.is(a1) && rhs.is(a0))); |
| 343 | |
| 344 | Label lhs_is_smi; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 345 | __ JumpIfSmi(lhs, &lhs_is_smi); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 346 | // Rhs is a Smi. |
| 347 | // Check whether the non-smi is a heap number. |
| 348 | __ GetObjectType(lhs, t4, t4); |
| 349 | if (strict) { |
| 350 | // If lhs was not a number and rhs was a Smi then strict equality cannot |
| 351 | // succeed. Return non-equal (lhs is already not zero). |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 352 | __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 353 | __ mov(v0, lhs); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 354 | } else { |
| 355 | // Smi compared non-strictly with a non-Smi non-heap-number. Call |
| 356 | // the runtime. |
| 357 | __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE)); |
| 358 | } |
| 359 | |
| 360 | // Rhs is a smi, lhs is a number. |
| 361 | // Convert smi rhs to double. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 362 | __ sra(at, rhs, kSmiTagSize); |
| 363 | __ mtc1(at, f14); |
| 364 | __ cvt_d_w(f14, f14); |
| 365 | __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 366 | |
| 367 | // We now have both loaded as doubles. |
| 368 | __ jmp(both_loaded_as_doubles); |
| 369 | |
| 370 | __ bind(&lhs_is_smi); |
| 371 | // Lhs is a Smi. Check whether the non-smi is a heap number. |
| 372 | __ GetObjectType(rhs, t4, t4); |
| 373 | if (strict) { |
| 374 | // If lhs was not a number and rhs was a Smi then strict equality cannot |
| 375 | // succeed. Return non-equal. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 376 | __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 377 | __ li(v0, Operand(1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 378 | } else { |
| 379 | // Smi compared non-strictly with a non-Smi non-heap-number. Call |
| 380 | // the runtime. |
| 381 | __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE)); |
| 382 | } |
| 383 | |
| 384 | // Lhs is a smi, rhs is a number. |
| 385 | // Convert smi lhs to double. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 386 | __ sra(at, lhs, kSmiTagSize); |
| 387 | __ mtc1(at, f12); |
| 388 | __ cvt_d_w(f12, f12); |
| 389 | __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 390 | // Fall through to both_loaded_as_doubles. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 394 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 395 | Register lhs, |
| 396 | Register rhs) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 397 | // If either operand is a JS object or an oddball value, then they are |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 398 | // not equal since their pointers are different. |
| 399 | // There is no test for undetectability in strict equality. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 400 | STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 401 | Label first_non_object; |
| 402 | // Get the type of the first operand into a2 and compare it with |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 403 | // FIRST_JS_RECEIVER_TYPE. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 404 | __ GetObjectType(lhs, a2, a2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 405 | __ Branch(&first_non_object, less, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 406 | |
| 407 | // Return non-zero. |
| 408 | Label return_not_equal; |
| 409 | __ bind(&return_not_equal); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 410 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 411 | __ li(v0, Operand(1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 412 | |
| 413 | __ bind(&first_non_object); |
| 414 | // Check for oddballs: true, false, null, undefined. |
| 415 | __ Branch(&return_not_equal, eq, a2, Operand(ODDBALL_TYPE)); |
| 416 | |
| 417 | __ GetObjectType(rhs, a3, a3); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 418 | __ Branch(&return_not_equal, greater, a3, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 419 | |
| 420 | // Check for oddballs: true, false, null, undefined. |
| 421 | __ Branch(&return_not_equal, eq, a3, Operand(ODDBALL_TYPE)); |
| 422 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 423 | // Now that we have the types we might as well check for |
| 424 | // internalized-internalized. |
| 425 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 426 | __ Or(a2, a2, Operand(a3)); |
| 427 | __ And(at, a2, Operand(kIsNotStringMask | kIsNotInternalizedMask)); |
| 428 | __ Branch(&return_not_equal, eq, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | |
| 432 | static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm, |
| 433 | Register lhs, |
| 434 | Register rhs, |
| 435 | Label* both_loaded_as_doubles, |
| 436 | Label* not_heap_numbers, |
| 437 | Label* slow) { |
| 438 | __ GetObjectType(lhs, a3, a2); |
| 439 | __ Branch(not_heap_numbers, ne, a2, Operand(HEAP_NUMBER_TYPE)); |
| 440 | __ lw(a2, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 441 | // If first was a heap number & second wasn't, go to slow case. |
| 442 | __ Branch(slow, ne, a3, Operand(a2)); |
| 443 | |
| 444 | // Both are heap numbers. Load them up then jump to the code we have |
| 445 | // for that. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 446 | __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 447 | __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 448 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 449 | __ jmp(both_loaded_as_doubles); |
| 450 | } |
| 451 | |
| 452 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 453 | // Fast negative check for internalized-to-internalized equality. |
| 454 | static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 455 | Register lhs, Register rhs, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 456 | Label* possible_strings, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 457 | Label* runtime_call) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 458 | DCHECK((lhs.is(a0) && rhs.is(a1)) || |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 459 | (lhs.is(a1) && rhs.is(a0))); |
| 460 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 461 | // a2 is object type of rhs. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 462 | Label object_test, return_equal, return_unequal, undetectable; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 463 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 464 | __ And(at, a2, Operand(kIsNotStringMask)); |
| 465 | __ Branch(&object_test, ne, at, Operand(zero_reg)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 466 | __ And(at, a2, Operand(kIsNotInternalizedMask)); |
| 467 | __ Branch(possible_strings, ne, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 468 | __ GetObjectType(rhs, a3, a3); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 469 | __ Branch(runtime_call, ge, a3, Operand(FIRST_NONSTRING_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 470 | __ And(at, a3, Operand(kIsNotInternalizedMask)); |
| 471 | __ Branch(possible_strings, ne, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 472 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 473 | // Both are internalized. We already checked they weren't the same pointer so |
| 474 | // they are not equal. Return non-equal by returning the non-zero object |
| 475 | // pointer in v0. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 476 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 477 | __ mov(v0, a0); // In delay slot. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 478 | |
| 479 | __ bind(&object_test); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 480 | __ lw(a2, FieldMemOperand(lhs, HeapObject::kMapOffset)); |
| 481 | __ lw(a3, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 482 | __ lbu(t0, FieldMemOperand(a2, Map::kBitFieldOffset)); |
| 483 | __ lbu(t1, FieldMemOperand(a3, Map::kBitFieldOffset)); |
| 484 | __ And(at, t0, Operand(1 << Map::kIsUndetectable)); |
| 485 | __ Branch(&undetectable, ne, at, Operand(zero_reg)); |
| 486 | __ And(at, t1, Operand(1 << Map::kIsUndetectable)); |
| 487 | __ Branch(&return_unequal, ne, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 488 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 489 | __ GetInstanceType(a2, a2); |
| 490 | __ Branch(runtime_call, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 491 | __ GetInstanceType(a3, a3); |
| 492 | __ Branch(runtime_call, lt, a3, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 493 | |
| 494 | __ bind(&return_unequal); |
| 495 | // Return non-equal by returning the non-zero object pointer in v0. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 496 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 497 | __ mov(v0, a0); // In delay slot. |
| 498 | |
| 499 | __ bind(&undetectable); |
| 500 | __ And(at, t1, Operand(1 << Map::kIsUndetectable)); |
| 501 | __ Branch(&return_unequal, eq, at, Operand(zero_reg)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 502 | |
| 503 | // If both sides are JSReceivers, then the result is false according to |
| 504 | // the HTML specification, which says that only comparisons with null or |
| 505 | // undefined are affected by special casing for document.all. |
| 506 | __ GetInstanceType(a2, a2); |
| 507 | __ Branch(&return_equal, eq, a2, Operand(ODDBALL_TYPE)); |
| 508 | __ GetInstanceType(a3, a3); |
| 509 | __ Branch(&return_unequal, ne, a3, Operand(ODDBALL_TYPE)); |
| 510 | |
| 511 | __ bind(&return_equal); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 512 | __ Ret(USE_DELAY_SLOT); |
| 513 | __ li(v0, Operand(EQUAL)); // In delay slot. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 517 | static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input, |
| 518 | Register scratch, |
| 519 | CompareICState::State expected, |
| 520 | Label* fail) { |
| 521 | Label ok; |
| 522 | if (expected == CompareICState::SMI) { |
| 523 | __ JumpIfNotSmi(input, fail); |
| 524 | } else if (expected == CompareICState::NUMBER) { |
| 525 | __ JumpIfSmi(input, &ok); |
| 526 | __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail, |
| 527 | DONT_DO_SMI_CHECK); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 528 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 529 | // We could be strict about internalized/string here, but as long as |
| 530 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 531 | __ bind(&ok); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 535 | // On entry a1 and a2 are the values to be compared. |
| 536 | // On exit a0 is 0, positive or negative to indicate the result of |
| 537 | // the comparison. |
| 538 | void CompareICStub::GenerateGeneric(MacroAssembler* masm) { |
| 539 | Register lhs = a1; |
| 540 | Register rhs = a0; |
| 541 | Condition cc = GetCondition(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 542 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 543 | Label miss; |
| 544 | CompareICStub_CheckInputType(masm, lhs, a2, left(), &miss); |
| 545 | CompareICStub_CheckInputType(masm, rhs, a3, right(), &miss); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 546 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 547 | Label slow; // Call builtin. |
| 548 | Label not_smis, both_loaded_as_doubles; |
| 549 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 550 | Label not_two_smis, smi_done; |
| 551 | __ Or(a2, a1, a0); |
| 552 | __ JumpIfNotSmi(a2, ¬_two_smis); |
| 553 | __ sra(a1, a1, 1); |
| 554 | __ sra(a0, a0, 1); |
| 555 | __ Ret(USE_DELAY_SLOT); |
| 556 | __ subu(v0, a1, a0); |
| 557 | __ bind(¬_two_smis); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 558 | |
| 559 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 560 | // it is certain that at least one operand isn't a smi. |
| 561 | |
| 562 | // Handle the case where the objects are identical. Either returns the answer |
| 563 | // or goes to slow. Only falls through if the objects were not identical. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 564 | EmitIdenticalObjectComparison(masm, &slow, cc); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 565 | |
| 566 | // If either is a Smi (we know that not both are), then they can only |
| 567 | // be strictly equal if the other is a HeapNumber. |
| 568 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 569 | DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 570 | __ And(t2, lhs, Operand(rhs)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 571 | __ JumpIfNotSmi(t2, ¬_smis, t0); |
| 572 | // One operand is a smi. EmitSmiNonsmiComparison generates code that can: |
| 573 | // 1) Return the answer. |
| 574 | // 2) Go to slow. |
| 575 | // 3) Fall through to both_loaded_as_doubles. |
| 576 | // 4) Jump to rhs_not_nan. |
| 577 | // In cases 3 and 4 we have found out we were dealing with a number-number |
| 578 | // comparison and the numbers have been loaded into f12 and f14 as doubles, |
| 579 | // or in GP registers (a0, a1, a2, a3) depending on the presence of the FPU. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 580 | EmitSmiNonsmiComparison(masm, lhs, rhs, |
| 581 | &both_loaded_as_doubles, &slow, strict()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 582 | |
| 583 | __ bind(&both_loaded_as_doubles); |
| 584 | // f12, f14 are the double representations of the left hand side |
| 585 | // and the right hand side if we have FPU. Otherwise a2, a3 represent |
| 586 | // left hand side and a0, a1 represent right hand side. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 587 | Label nan; |
| 588 | __ li(t0, Operand(LESS)); |
| 589 | __ li(t1, Operand(GREATER)); |
| 590 | __ li(t2, Operand(EQUAL)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 591 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 592 | // Check if either rhs or lhs is NaN. |
| 593 | __ BranchF(NULL, &nan, eq, f12, f14); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 594 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 595 | // Check if LESS condition is satisfied. If true, move conditionally |
| 596 | // result to v0. |
| 597 | if (!IsMipsArchVariant(kMips32r6)) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 598 | __ c(OLT, D, f12, f14); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 599 | __ Movt(v0, t0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 600 | // Use previous check to store conditionally to v0 oposite condition |
| 601 | // (GREATER). If rhs is equal to lhs, this will be corrected in next |
| 602 | // check. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 603 | __ Movf(v0, t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 604 | // Check if EQUAL condition is satisfied. If true, move conditionally |
| 605 | // result to v0. |
| 606 | __ c(EQ, D, f12, f14); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 607 | __ Movt(v0, t2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 608 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 609 | Label skip; |
| 610 | __ BranchF(USE_DELAY_SLOT, &skip, NULL, lt, f12, f14); |
| 611 | __ mov(v0, t0); // Return LESS as result. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 612 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 613 | __ BranchF(USE_DELAY_SLOT, &skip, NULL, eq, f12, f14); |
| 614 | __ mov(v0, t2); // Return EQUAL as result. |
| 615 | |
| 616 | __ mov(v0, t1); // Return GREATER as result. |
| 617 | __ bind(&skip); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 620 | __ Ret(); |
| 621 | |
| 622 | __ bind(&nan); |
| 623 | // NaN comparisons always fail. |
| 624 | // Load whatever we need in v0 to make the comparison fail. |
| 625 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 626 | __ Ret(USE_DELAY_SLOT); |
| 627 | if (cc == lt || cc == le) { |
| 628 | __ li(v0, Operand(GREATER)); |
| 629 | } else { |
| 630 | __ li(v0, Operand(LESS)); |
| 631 | } |
| 632 | |
| 633 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 634 | __ bind(¬_smis); |
| 635 | // At this point we know we are dealing with two different objects, |
| 636 | // and neither of them is a Smi. The objects are in lhs_ and rhs_. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 637 | if (strict()) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 638 | // This returns non-equal for some object types, or falls through if it |
| 639 | // was not lucky. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 640 | EmitStrictTwoHeapObjectCompare(masm, lhs, rhs); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 643 | Label check_for_internalized_strings; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 644 | Label flat_string_check; |
| 645 | // Check for heap-number-heap-number comparison. Can jump to slow case, |
| 646 | // or load both doubles and jump to the code that handles |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 647 | // that case. If the inputs are not doubles then jumps to |
| 648 | // check_for_internalized_strings. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 649 | // In this case a2 will contain the type of lhs_. |
| 650 | EmitCheckForTwoHeapNumbers(masm, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 651 | lhs, |
| 652 | rhs, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 653 | &both_loaded_as_doubles, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 654 | &check_for_internalized_strings, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 655 | &flat_string_check); |
| 656 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 657 | __ bind(&check_for_internalized_strings); |
| 658 | if (cc == eq && !strict()) { |
| 659 | // Returns an answer for two internalized strings or two |
| 660 | // detectable objects. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 661 | // Otherwise jumps to string case or not both strings case. |
| 662 | // Assumes that a2 is the type of lhs_ on entry. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 663 | EmitCheckForInternalizedStringsOrObjects( |
| 664 | masm, lhs, rhs, &flat_string_check, &slow); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 667 | // Check for both being sequential one-byte strings, |
| 668 | // and inline if that is the case. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 669 | __ bind(&flat_string_check); |
| 670 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 671 | __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, a2, a3, &slow); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 672 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 673 | __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2, |
| 674 | a3); |
| 675 | if (cc == eq) { |
| 676 | StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, a2, a3, t0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 677 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 678 | StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, a2, a3, t0, |
| 679 | t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 680 | } |
| 681 | // Never falls through to here. |
| 682 | |
| 683 | __ bind(&slow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 684 | if (cc == eq) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 685 | { |
| 686 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 687 | __ Push(lhs, rhs); |
| 688 | __ CallRuntime(strict() ? Runtime::kStrictEqual : Runtime::kEqual); |
| 689 | } |
| 690 | // Turn true into 0 and false into some non-zero value. |
| 691 | STATIC_ASSERT(EQUAL == 0); |
| 692 | __ LoadRoot(a0, Heap::kTrueValueRootIndex); |
| 693 | __ Ret(USE_DELAY_SLOT); |
| 694 | __ subu(v0, v0, a0); // In delay slot. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 695 | } else { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 696 | // Prepare for call to builtin. Push object pointers, a0 (lhs) first, |
| 697 | // a1 (rhs) second. |
| 698 | __ Push(lhs, rhs); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 699 | int ncr; // NaN compare result. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 700 | if (cc == lt || cc == le) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 701 | ncr = GREATER; |
| 702 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 703 | DCHECK(cc == gt || cc == ge); // Remaining cases. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 704 | ncr = LESS; |
| 705 | } |
| 706 | __ li(a0, Operand(Smi::FromInt(ncr))); |
| 707 | __ push(a0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 708 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 709 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 710 | // tagged as a small integer. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 711 | __ TailCallRuntime(Runtime::kCompare); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 712 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 713 | |
| 714 | __ bind(&miss); |
| 715 | GenerateMiss(masm); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 719 | void StoreRegistersStateStub::Generate(MacroAssembler* masm) { |
| 720 | __ mov(t9, ra); |
| 721 | __ pop(ra); |
| 722 | __ PushSafepointRegisters(); |
| 723 | __ Jump(t9); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 724 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 725 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 726 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 727 | void RestoreRegistersStateStub::Generate(MacroAssembler* masm) { |
| 728 | __ mov(t9, ra); |
| 729 | __ pop(ra); |
| 730 | __ PopSafepointRegisters(); |
| 731 | __ Jump(t9); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | |
| 735 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 736 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 737 | // store the registers in any particular way, but we do have to store and |
| 738 | // restore them. |
| 739 | __ MultiPush(kJSCallerSaved | ra.bit()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 740 | if (save_doubles()) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 741 | __ MultiPushFPU(kCallerSavedFPU); |
| 742 | } |
| 743 | const int argument_count = 1; |
| 744 | const int fp_argument_count = 0; |
| 745 | const Register scratch = a1; |
| 746 | |
| 747 | AllowExternalCallThatCantCauseGC scope(masm); |
| 748 | __ PrepareCallCFunction(argument_count, fp_argument_count, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 749 | __ li(a0, Operand(ExternalReference::isolate_address(isolate()))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 750 | __ CallCFunction( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 751 | ExternalReference::store_buffer_overflow_function(isolate()), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 752 | argument_count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 753 | if (save_doubles()) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 754 | __ MultiPopFPU(kCallerSavedFPU); |
| 755 | } |
| 756 | |
| 757 | __ MultiPop(kJSCallerSaved | ra.bit()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 758 | __ Ret(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 762 | void MathPowStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 763 | const Register base = a1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 764 | const Register exponent = MathPowTaggedDescriptor::exponent(); |
| 765 | DCHECK(exponent.is(a2)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 766 | const Register heapnumbermap = t1; |
| 767 | const Register heapnumber = v0; |
| 768 | const DoubleRegister double_base = f2; |
| 769 | const DoubleRegister double_exponent = f4; |
| 770 | const DoubleRegister double_result = f0; |
| 771 | const DoubleRegister double_scratch = f6; |
| 772 | const FPURegister single_scratch = f8; |
| 773 | const Register scratch = t5; |
| 774 | const Register scratch2 = t3; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 775 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 776 | Label call_runtime, done, int_exponent; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 777 | if (exponent_type() == ON_STACK) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 778 | Label base_is_smi, unpack_exponent; |
| 779 | // The exponent and base are supplied as arguments on the stack. |
| 780 | // This can only happen if the stub is called from non-optimized code. |
| 781 | // Load input parameters from stack to double registers. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 782 | __ lw(base, MemOperand(sp, 1 * kPointerSize)); |
| 783 | __ lw(exponent, MemOperand(sp, 0 * kPointerSize)); |
| 784 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 785 | __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 786 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 787 | __ UntagAndJumpIfSmi(scratch, base, &base_is_smi); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 788 | __ lw(scratch, FieldMemOperand(base, JSObject::kMapOffset)); |
| 789 | __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 790 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 791 | __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 792 | __ jmp(&unpack_exponent); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 793 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 794 | __ bind(&base_is_smi); |
| 795 | __ mtc1(scratch, single_scratch); |
| 796 | __ cvt_d_w(double_base, single_scratch); |
| 797 | __ bind(&unpack_exponent); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 798 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 799 | __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent); |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 800 | |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 801 | __ lw(scratch, FieldMemOperand(exponent, JSObject::kMapOffset)); |
| 802 | __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap)); |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 803 | __ ldc1(double_exponent, |
| 804 | FieldMemOperand(exponent, HeapNumber::kValueOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 805 | } else if (exponent_type() == TAGGED) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 806 | // Base is already in double_base. |
| 807 | __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent); |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 808 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 809 | __ ldc1(double_exponent, |
| 810 | FieldMemOperand(exponent, HeapNumber::kValueOffset)); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 811 | } |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 812 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 813 | if (exponent_type() != INTEGER) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 814 | Label int_exponent_convert; |
| 815 | // Detect integer exponents stored as double. |
| 816 | __ EmitFPUTruncate(kRoundToMinusInf, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 817 | scratch, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 818 | double_exponent, |
| 819 | at, |
| 820 | double_scratch, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 821 | scratch2, |
| 822 | kCheckForInexactConversion); |
| 823 | // scratch2 == 0 means there was no conversion error. |
| 824 | __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg)); |
| 825 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 826 | if (exponent_type() == ON_STACK) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 827 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 828 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 829 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 830 | Label not_plus_half; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 831 | // Test for 0.5. |
| 832 | __ Move(double_scratch, 0.5); |
| 833 | __ BranchF(USE_DELAY_SLOT, |
| 834 | ¬_plus_half, |
| 835 | NULL, |
| 836 | ne, |
| 837 | double_exponent, |
| 838 | double_scratch); |
| 839 | // double_scratch can be overwritten in the delay slot. |
| 840 | // Calculates square root of base. Check for the special case of |
| 841 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 842 | __ Move(double_scratch, static_cast<double>(-V8_INFINITY)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 843 | __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch); |
| 844 | __ neg_d(double_result, double_scratch); |
| 845 | |
| 846 | // Add +0 to convert -0 to +0. |
| 847 | __ add_d(double_scratch, double_base, kDoubleRegZero); |
| 848 | __ sqrt_d(double_result, double_scratch); |
| 849 | __ jmp(&done); |
| 850 | |
| 851 | __ bind(¬_plus_half); |
| 852 | __ Move(double_scratch, -0.5); |
| 853 | __ BranchF(USE_DELAY_SLOT, |
| 854 | &call_runtime, |
| 855 | NULL, |
| 856 | ne, |
| 857 | double_exponent, |
| 858 | double_scratch); |
| 859 | // double_scratch can be overwritten in the delay slot. |
| 860 | // Calculates square root of base. Check for the special case of |
| 861 | // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 862 | __ Move(double_scratch, static_cast<double>(-V8_INFINITY)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 863 | __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch); |
| 864 | __ Move(double_result, kDoubleRegZero); |
| 865 | |
| 866 | // Add +0 to convert -0 to +0. |
| 867 | __ add_d(double_scratch, double_base, kDoubleRegZero); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 868 | __ Move(double_result, 1.); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 869 | __ sqrt_d(double_scratch, double_scratch); |
| 870 | __ div_d(double_result, double_result, double_scratch); |
| 871 | __ jmp(&done); |
| 872 | } |
| 873 | |
| 874 | __ push(ra); |
| 875 | { |
| 876 | AllowExternalCallThatCantCauseGC scope(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 877 | __ PrepareCallCFunction(0, 2, scratch2); |
| 878 | __ MovToFloatParameters(double_base, double_exponent); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 879 | __ CallCFunction( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 880 | ExternalReference::power_double_double_function(isolate()), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 881 | 0, 2); |
| 882 | } |
| 883 | __ pop(ra); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 884 | __ MovFromFloatResult(double_result); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 885 | __ jmp(&done); |
| 886 | |
| 887 | __ bind(&int_exponent_convert); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | // Calculate power with integer exponent. |
| 891 | __ bind(&int_exponent); |
| 892 | |
| 893 | // Get two copies of exponent in the registers scratch and exponent. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 894 | if (exponent_type() == INTEGER) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 895 | __ mov(scratch, exponent); |
| 896 | } else { |
| 897 | // Exponent has previously been stored into scratch as untagged integer. |
| 898 | __ mov(exponent, scratch); |
| 899 | } |
| 900 | |
| 901 | __ mov_d(double_scratch, double_base); // Back up base. |
| 902 | __ Move(double_result, 1.0); |
| 903 | |
| 904 | // Get absolute value of exponent. |
| 905 | Label positive_exponent; |
| 906 | __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg)); |
| 907 | __ Subu(scratch, zero_reg, scratch); |
| 908 | __ bind(&positive_exponent); |
| 909 | |
| 910 | Label while_true, no_carry, loop_end; |
| 911 | __ bind(&while_true); |
| 912 | |
| 913 | __ And(scratch2, scratch, 1); |
| 914 | |
| 915 | __ Branch(&no_carry, eq, scratch2, Operand(zero_reg)); |
| 916 | __ mul_d(double_result, double_result, double_scratch); |
| 917 | __ bind(&no_carry); |
| 918 | |
| 919 | __ sra(scratch, scratch, 1); |
| 920 | |
| 921 | __ Branch(&loop_end, eq, scratch, Operand(zero_reg)); |
| 922 | __ mul_d(double_scratch, double_scratch, double_scratch); |
| 923 | |
| 924 | __ Branch(&while_true); |
| 925 | |
| 926 | __ bind(&loop_end); |
| 927 | |
| 928 | __ Branch(&done, ge, exponent, Operand(zero_reg)); |
| 929 | __ Move(double_scratch, 1.0); |
| 930 | __ div_d(double_result, double_scratch, double_result); |
| 931 | // Test whether result is zero. Bail out to check for subnormal result. |
| 932 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 933 | __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero); |
| 934 | |
| 935 | // double_exponent may not contain the exponent value if the input was a |
| 936 | // smi. We set it with exponent value before bailing out. |
| 937 | __ mtc1(exponent, single_scratch); |
| 938 | __ cvt_d_w(double_exponent, single_scratch); |
| 939 | |
| 940 | // Returning or bailing out. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 941 | if (exponent_type() == ON_STACK) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 942 | // The arguments are still on the stack. |
| 943 | __ bind(&call_runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 944 | __ TailCallRuntime(Runtime::kMathPowRT); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 945 | |
| 946 | // The stub is called from non-optimized code, which expects the result |
| 947 | // as heap number in exponent. |
| 948 | __ bind(&done); |
| 949 | __ AllocateHeapNumber( |
| 950 | heapnumber, scratch, scratch2, heapnumbermap, &call_runtime); |
| 951 | __ sdc1(double_result, |
| 952 | FieldMemOperand(heapnumber, HeapNumber::kValueOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 953 | DCHECK(heapnumber.is(v0)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 954 | __ DropAndRet(2); |
| 955 | } else { |
| 956 | __ push(ra); |
| 957 | { |
| 958 | AllowExternalCallThatCantCauseGC scope(masm); |
| 959 | __ PrepareCallCFunction(0, 2, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 960 | __ MovToFloatParameters(double_base, double_exponent); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 961 | __ CallCFunction( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 962 | ExternalReference::power_double_double_function(isolate()), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 963 | 0, 2); |
| 964 | } |
| 965 | __ pop(ra); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 966 | __ MovFromFloatResult(double_result); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 967 | |
| 968 | __ bind(&done); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 969 | __ Ret(); |
| 970 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | |
| 974 | bool CEntryStub::NeedsImmovableCode() { |
| 975 | return true; |
| 976 | } |
| 977 | |
| 978 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 979 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 980 | CEntryStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 981 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
| 982 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 983 | CommonArrayConstructorStub::GenerateStubsAheadOfTime(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 984 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 985 | CreateWeakCellStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 986 | BinaryOpICStub::GenerateAheadOfTime(isolate); |
| 987 | StoreRegistersStateStub::GenerateAheadOfTime(isolate); |
| 988 | RestoreRegistersStateStub::GenerateAheadOfTime(isolate); |
| 989 | BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 990 | StoreFastElementStub::GenerateAheadOfTime(isolate); |
| 991 | TypeofStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 995 | void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) { |
| 996 | StoreRegistersStateStub stub(isolate); |
| 997 | stub.GetCode(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1001 | void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) { |
| 1002 | RestoreRegistersStateStub stub(isolate); |
| 1003 | stub.GetCode(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1007 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
| 1008 | // Generate if not already in cache. |
| 1009 | SaveFPRegsMode mode = kSaveFPRegs; |
| 1010 | CEntryStub(isolate, 1, mode).GetCode(); |
| 1011 | StoreBufferOverflowStub(isolate, mode).GetCode(); |
| 1012 | isolate->set_fp_stubs_generated(true); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1016 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
| 1017 | CEntryStub stub(isolate, 1, kDontSaveFPRegs); |
| 1018 | stub.GetCode(); |
| 1019 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1020 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1021 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1022 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 1023 | // Called from JavaScript; parameters are on stack as if calling JS function |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1024 | // a0: number of arguments including receiver |
| 1025 | // a1: pointer to builtin function |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1026 | // fp: frame pointer (restored after C call) |
| 1027 | // sp: stack pointer (restored as callee's sp after C call) |
| 1028 | // cp: current context (C callee-saved) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1029 | // |
| 1030 | // If argv_in_register(): |
| 1031 | // a2: pointer to the first argument |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1032 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1033 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 1034 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1035 | if (argv_in_register()) { |
| 1036 | // Move argv into the correct register. |
| 1037 | __ mov(s1, a2); |
| 1038 | } else { |
| 1039 | // Compute the argv pointer in a callee-saved register. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1040 | __ Lsa(s1, sp, a0, kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1041 | __ Subu(s1, s1, kPointerSize); |
| 1042 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1043 | |
| 1044 | // Enter the exit frame that transitions from JavaScript to C++. |
| 1045 | FrameScope scope(masm, StackFrame::MANUAL); |
| 1046 | __ EnterExitFrame(save_doubles()); |
| 1047 | |
| 1048 | // s0: number of arguments including receiver (C callee-saved) |
| 1049 | // s1: pointer to first argument (C callee-saved) |
| 1050 | // s2: pointer to builtin function (C callee-saved) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1051 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1052 | // Prepare arguments for C routine. |
| 1053 | // a0 = argc |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1054 | __ mov(s0, a0); |
| 1055 | __ mov(s2, a1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1056 | |
| 1057 | // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We |
| 1058 | // also need to reserve the 4 argument slots on the stack. |
| 1059 | |
| 1060 | __ AssertStackIsAligned(); |
| 1061 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1062 | int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
| 1063 | int frame_alignment_mask = frame_alignment - 1; |
| 1064 | int result_stack_size; |
| 1065 | if (result_size() <= 2) { |
| 1066 | // a0 = argc, a1 = argv, a2 = isolate |
| 1067 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
| 1068 | __ mov(a1, s1); |
| 1069 | result_stack_size = 0; |
| 1070 | } else { |
| 1071 | DCHECK_EQ(3, result_size()); |
| 1072 | // Allocate additional space for the result. |
| 1073 | result_stack_size = |
| 1074 | ((result_size() * kPointerSize) + frame_alignment_mask) & |
| 1075 | ~frame_alignment_mask; |
| 1076 | __ Subu(sp, sp, Operand(result_stack_size)); |
| 1077 | |
| 1078 | // a0 = hidden result argument, a1 = argc, a2 = argv, a3 = isolate. |
| 1079 | __ li(a3, Operand(ExternalReference::isolate_address(isolate()))); |
| 1080 | __ mov(a2, s1); |
| 1081 | __ mov(a1, a0); |
| 1082 | __ mov(a0, sp); |
| 1083 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1084 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1085 | // To let the GC traverse the return address of the exit frames, we need to |
| 1086 | // know where the return address is. The CEntryStub is unmovable, so |
| 1087 | // we can store the address on the stack to be able to find it again and |
| 1088 | // we never have to restore it, because it will not change. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1089 | { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1090 | int kNumInstructionsToJump = 4; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1091 | Label find_ra; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1092 | // Adjust the value in ra to point to the correct return location, 2nd |
| 1093 | // instruction past the real call into C code (the jalr(t9)), and push it. |
| 1094 | // This is the return address of the exit frame. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1095 | if (kArchVariant >= kMips32r6) { |
| 1096 | __ addiupc(ra, kNumInstructionsToJump + 1); |
| 1097 | } else { |
| 1098 | // This branch-and-link sequence is needed to find the current PC on mips |
| 1099 | // before r6, saved to the ra register. |
| 1100 | __ bal(&find_ra); // bal exposes branch delay slot. |
| 1101 | __ Addu(ra, ra, kNumInstructionsToJump * Instruction::kInstrSize); |
| 1102 | } |
| 1103 | __ bind(&find_ra); |
| 1104 | |
| 1105 | // This spot was reserved in EnterExitFrame. |
| 1106 | __ sw(ra, MemOperand(sp, result_stack_size)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1107 | // Stack space reservation moved to the branch delay slot below. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1108 | // Stack is still aligned. |
| 1109 | |
| 1110 | // Call the C routine. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1111 | __ mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC. |
| 1112 | __ jalr(t9); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1113 | // Set up sp in the delay slot. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1114 | __ addiu(sp, sp, -kCArgsSlotsSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1115 | // Make sure the stored 'ra' points to this position. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1116 | DCHECK_EQ(kNumInstructionsToJump, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1117 | masm->InstructionsGeneratedSince(&find_ra)); |
| 1118 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1119 | if (result_size() > 2) { |
| 1120 | DCHECK_EQ(3, result_size()); |
| 1121 | // Read result values stored on stack. |
| 1122 | __ lw(a0, MemOperand(v0, 2 * kPointerSize)); |
| 1123 | __ lw(v1, MemOperand(v0, 1 * kPointerSize)); |
| 1124 | __ lw(v0, MemOperand(v0, 0 * kPointerSize)); |
| 1125 | } |
| 1126 | // Result returned in v0, v1:v0 or a0:v1:v0 - do not destroy these registers! |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1127 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1128 | // Check result for exception sentinel. |
| 1129 | Label exception_returned; |
| 1130 | __ LoadRoot(t0, Heap::kExceptionRootIndex); |
| 1131 | __ Branch(&exception_returned, eq, t0, Operand(v0)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1132 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1133 | // Check that there is no pending exception, otherwise we |
| 1134 | // should have returned the exception sentinel. |
| 1135 | if (FLAG_debug_code) { |
| 1136 | Label okay; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1137 | ExternalReference pending_exception_address( |
| 1138 | Isolate::kPendingExceptionAddress, isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1139 | __ li(a2, Operand(pending_exception_address)); |
| 1140 | __ lw(a2, MemOperand(a2)); |
| 1141 | __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); |
| 1142 | // Cannot use check here as it attempts to generate call into runtime. |
| 1143 | __ Branch(&okay, eq, t0, Operand(a2)); |
| 1144 | __ stop("Unexpected pending exception"); |
| 1145 | __ bind(&okay); |
| 1146 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1147 | |
| 1148 | // Exit C frame and return. |
| 1149 | // v0:v1: result |
| 1150 | // sp: stack pointer |
| 1151 | // fp: frame pointer |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1152 | Register argc; |
| 1153 | if (argv_in_register()) { |
| 1154 | // We don't want to pop arguments so set argc to no_reg. |
| 1155 | argc = no_reg; |
| 1156 | } else { |
| 1157 | // s0: still holds argc (callee-saved). |
| 1158 | argc = s0; |
| 1159 | } |
| 1160 | __ LeaveExitFrame(save_doubles(), argc, true, EMIT_RETURN); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1161 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1162 | // Handling of exception. |
| 1163 | __ bind(&exception_returned); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1164 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1165 | ExternalReference pending_handler_context_address( |
| 1166 | Isolate::kPendingHandlerContextAddress, isolate()); |
| 1167 | ExternalReference pending_handler_code_address( |
| 1168 | Isolate::kPendingHandlerCodeAddress, isolate()); |
| 1169 | ExternalReference pending_handler_offset_address( |
| 1170 | Isolate::kPendingHandlerOffsetAddress, isolate()); |
| 1171 | ExternalReference pending_handler_fp_address( |
| 1172 | Isolate::kPendingHandlerFPAddress, isolate()); |
| 1173 | ExternalReference pending_handler_sp_address( |
| 1174 | Isolate::kPendingHandlerSPAddress, isolate()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1175 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1176 | // Ask the runtime for help to determine the handler. This will set v0 to |
| 1177 | // contain the current pending exception, don't clobber it. |
| 1178 | ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler, |
| 1179 | isolate()); |
| 1180 | { |
| 1181 | FrameScope scope(masm, StackFrame::MANUAL); |
| 1182 | __ PrepareCallCFunction(3, 0, a0); |
| 1183 | __ mov(a0, zero_reg); |
| 1184 | __ mov(a1, zero_reg); |
| 1185 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
| 1186 | __ CallCFunction(find_handler, 3); |
| 1187 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1188 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1189 | // Retrieve the handler context, SP and FP. |
| 1190 | __ li(cp, Operand(pending_handler_context_address)); |
| 1191 | __ lw(cp, MemOperand(cp)); |
| 1192 | __ li(sp, Operand(pending_handler_sp_address)); |
| 1193 | __ lw(sp, MemOperand(sp)); |
| 1194 | __ li(fp, Operand(pending_handler_fp_address)); |
| 1195 | __ lw(fp, MemOperand(fp)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1196 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1197 | // If the handler is a JS frame, restore the context to the frame. Note that |
| 1198 | // the context will be set to (cp == 0) for non-JS frames. |
| 1199 | Label zero; |
| 1200 | __ Branch(&zero, eq, cp, Operand(zero_reg)); |
| 1201 | __ sw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 1202 | __ bind(&zero); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1203 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1204 | // Compute the handler entry address and jump to it. |
| 1205 | __ li(a1, Operand(pending_handler_code_address)); |
| 1206 | __ lw(a1, MemOperand(a1)); |
| 1207 | __ li(a2, Operand(pending_handler_offset_address)); |
| 1208 | __ lw(a2, MemOperand(a2)); |
| 1209 | __ Addu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 1210 | __ Addu(t9, a1, a2); |
| 1211 | __ Jump(t9); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1215 | void JSEntryStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1216 | Label invoke, handler_entry, exit; |
| 1217 | Isolate* isolate = masm->isolate(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1218 | |
| 1219 | // Registers: |
| 1220 | // a0: entry address |
| 1221 | // a1: function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1222 | // a2: receiver |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1223 | // a3: argc |
| 1224 | // |
| 1225 | // Stack: |
| 1226 | // 4 args slots |
| 1227 | // args |
| 1228 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1229 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 1230 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1231 | // Save callee saved registers on the stack. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1232 | __ MultiPush(kCalleeSaved | ra.bit()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1233 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1234 | // Save callee-saved FPU registers. |
| 1235 | __ MultiPushFPU(kCalleeSavedFPU); |
| 1236 | // Set up the reserved register for 0.0. |
| 1237 | __ Move(kDoubleRegZero, 0.0); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1238 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1239 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1240 | // Load argv in s0 register. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1241 | int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1242 | offset_to_argv += kNumCalleeSavedFPU * kDoubleSize; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1243 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1244 | __ InitializeRootRegister(); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1245 | __ lw(s0, MemOperand(sp, offset_to_argv + kCArgsSlotsSize)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1246 | |
| 1247 | // We build an EntryFrame. |
| 1248 | __ li(t3, Operand(-1)); // Push a bad frame pointer to fail if it is used. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1249 | int marker = type(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1250 | __ li(t2, Operand(Smi::FromInt(marker))); |
| 1251 | __ li(t1, Operand(Smi::FromInt(marker))); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1252 | __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1253 | isolate))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1254 | __ lw(t0, MemOperand(t0)); |
| 1255 | __ Push(t3, t2, t1, t0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1256 | // Set up frame pointer for the frame to be pushed. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1257 | __ addiu(fp, sp, -EntryFrameConstants::kCallerFPOffset); |
| 1258 | |
| 1259 | // Registers: |
| 1260 | // a0: entry_address |
| 1261 | // a1: function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1262 | // a2: receiver_pointer |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1263 | // a3: argc |
| 1264 | // s0: argv |
| 1265 | // |
| 1266 | // Stack: |
| 1267 | // caller fp | |
| 1268 | // function slot | entry frame |
| 1269 | // context slot | |
| 1270 | // bad fp (0xff...f) | |
| 1271 | // callee saved registers + ra |
| 1272 | // 4 args slots |
| 1273 | // args |
| 1274 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1275 | // If this is the outermost JS call, set js_entry_sp value. |
| 1276 | Label non_outermost_js; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1277 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1278 | __ li(t1, Operand(ExternalReference(js_entry_sp))); |
| 1279 | __ lw(t2, MemOperand(t1)); |
| 1280 | __ Branch(&non_outermost_js, ne, t2, Operand(zero_reg)); |
| 1281 | __ sw(fp, MemOperand(t1)); |
| 1282 | __ li(t0, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 1283 | Label cont; |
| 1284 | __ b(&cont); |
| 1285 | __ nop(); // Branch delay slot nop. |
| 1286 | __ bind(&non_outermost_js); |
| 1287 | __ li(t0, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
| 1288 | __ bind(&cont); |
| 1289 | __ push(t0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1290 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1291 | // Jump to a faked try block that does the invoke, with a faked catch |
| 1292 | // block that sets the pending exception. |
| 1293 | __ jmp(&invoke); |
| 1294 | __ bind(&handler_entry); |
| 1295 | handler_offset_ = handler_entry.pos(); |
| 1296 | // Caught exception: Store result (exception) in the pending exception |
| 1297 | // field in the JSEnv and return a failure sentinel. Coming in here the |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1298 | // fp will be invalid because the PushStackHandler below sets it to 0 to |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1299 | // signal the existence of the JSEntry frame. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1300 | __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1301 | isolate))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1302 | __ sw(v0, MemOperand(t0)); // We come back from 'invoke'. result is in v0. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1303 | __ LoadRoot(v0, Heap::kExceptionRootIndex); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1304 | __ b(&exit); // b exposes branch delay slot. |
| 1305 | __ nop(); // Branch delay slot nop. |
| 1306 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1307 | // Invoke: Link this frame into the handler chain. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1308 | __ bind(&invoke); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1309 | __ PushStackHandler(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1310 | // If an exception not caught by another handler occurs, this handler |
| 1311 | // returns control to the code after the bal(&invoke) above, which |
| 1312 | // restores all kCalleeSaved registers (including cp and fp) to their |
| 1313 | // saved values before returning a failure to C. |
| 1314 | |
| 1315 | // Clear any pending exceptions. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1316 | __ LoadRoot(t1, Heap::kTheHoleValueRootIndex); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1317 | __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1318 | isolate))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1319 | __ sw(t1, MemOperand(t0)); |
| 1320 | |
| 1321 | // Invoke the function by calling through JS entry trampoline builtin. |
| 1322 | // Notice that we cannot store a reference to the trampoline code directly in |
| 1323 | // this stub, because runtime stubs are not traversed when doing GC. |
| 1324 | |
| 1325 | // Registers: |
| 1326 | // a0: entry_address |
| 1327 | // a1: function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1328 | // a2: receiver_pointer |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1329 | // a3: argc |
| 1330 | // s0: argv |
| 1331 | // |
| 1332 | // Stack: |
| 1333 | // handler frame |
| 1334 | // entry frame |
| 1335 | // callee saved registers + ra |
| 1336 | // 4 args slots |
| 1337 | // args |
| 1338 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1339 | if (type() == StackFrame::ENTRY_CONSTRUCT) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1340 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1341 | isolate); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1342 | __ li(t0, Operand(construct_entry)); |
| 1343 | } else { |
| 1344 | ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate()); |
| 1345 | __ li(t0, Operand(entry)); |
| 1346 | } |
| 1347 | __ lw(t9, MemOperand(t0)); // Deref address. |
| 1348 | |
| 1349 | // Call JSEntryTrampoline. |
| 1350 | __ addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag); |
| 1351 | __ Call(t9); |
| 1352 | |
| 1353 | // Unlink this frame from the handler chain. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1354 | __ PopStackHandler(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1355 | |
| 1356 | __ bind(&exit); // v0 holds result |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1357 | // Check if the current stack frame is marked as the outermost JS frame. |
| 1358 | Label non_outermost_js_2; |
| 1359 | __ pop(t1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1360 | __ Branch(&non_outermost_js_2, |
| 1361 | ne, |
| 1362 | t1, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1363 | Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 1364 | __ li(t1, Operand(ExternalReference(js_entry_sp))); |
| 1365 | __ sw(zero_reg, MemOperand(t1)); |
| 1366 | __ bind(&non_outermost_js_2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1367 | |
| 1368 | // Restore the top frame descriptors from the stack. |
| 1369 | __ pop(t1); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1370 | __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1371 | isolate))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1372 | __ sw(t1, MemOperand(t0)); |
| 1373 | |
| 1374 | // Reset the stack to the callee saved registers. |
| 1375 | __ addiu(sp, sp, -EntryFrameConstants::kCallerFPOffset); |
| 1376 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1377 | // Restore callee-saved fpu registers. |
| 1378 | __ MultiPopFPU(kCalleeSavedFPU); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1379 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1380 | // Restore callee saved registers from the stack. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1381 | __ MultiPop(kCalleeSaved | ra.bit()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1382 | // Return. |
| 1383 | __ Jump(ra); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1387 | void LoadIndexedStringStub::Generate(MacroAssembler* masm) { |
| 1388 | // Return address is in ra. |
| 1389 | Label miss; |
| 1390 | |
| 1391 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 1392 | Register index = LoadDescriptor::NameRegister(); |
| 1393 | Register scratch = t1; |
| 1394 | Register result = v0; |
| 1395 | DCHECK(!scratch.is(receiver) && !scratch.is(index)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1396 | DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1397 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1398 | StringCharAtGenerator char_at_generator(receiver, index, scratch, result, |
| 1399 | &miss, // When not a string. |
| 1400 | &miss, // When not a number. |
| 1401 | &miss, // When index out of range. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1402 | RECEIVER_IS_STRING); |
| 1403 | char_at_generator.GenerateFast(masm); |
| 1404 | __ Ret(); |
| 1405 | |
| 1406 | StubRuntimeCallHelper call_helper; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1407 | char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1408 | |
| 1409 | __ bind(&miss); |
| 1410 | PropertyAccessCompiler::TailCallBuiltin( |
| 1411 | masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC)); |
| 1412 | } |
| 1413 | |
| 1414 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1415 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 1416 | Label miss; |
| 1417 | Register receiver = LoadDescriptor::ReceiverRegister(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1418 | // Ensure that the vector and slot registers won't be clobbered before |
| 1419 | // calling the miss handler. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1420 | DCHECK(!AreAliased(t0, t1, LoadWithVectorDescriptor::VectorRegister(), |
| 1421 | LoadWithVectorDescriptor::SlotRegister())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1422 | |
| 1423 | NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, t0, |
| 1424 | t1, &miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1425 | __ bind(&miss); |
| 1426 | PropertyAccessCompiler::TailCallBuiltin( |
| 1427 | masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC)); |
| 1428 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1429 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1430 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1431 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 1432 | // time or if regexp entry in generated code is turned off runtime switch or |
| 1433 | // at compilation. |
| 1434 | #ifdef V8_INTERPRETED_REGEXP |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1435 | __ TailCallRuntime(Runtime::kRegExpExec); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1436 | #else // V8_INTERPRETED_REGEXP |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1437 | |
| 1438 | // Stack frame on entry. |
| 1439 | // sp[0]: last_match_info (expected JSArray) |
| 1440 | // sp[4]: previous index |
| 1441 | // sp[8]: subject string |
| 1442 | // sp[12]: JSRegExp object |
| 1443 | |
Ben Murdoch | db1b438 | 2012-04-26 19:03:50 +0100 | [diff] [blame] | 1444 | const int kLastMatchInfoOffset = 0 * kPointerSize; |
| 1445 | const int kPreviousIndexOffset = 1 * kPointerSize; |
| 1446 | const int kSubjectOffset = 2 * kPointerSize; |
| 1447 | const int kJSRegExpOffset = 3 * kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1448 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1449 | Label runtime; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1450 | // Allocation of registers for this function. These are in callee save |
| 1451 | // registers and will be preserved by the call to the native RegExp code, as |
| 1452 | // this code is called using the normal C calling convention. When calling |
| 1453 | // directly from generated code the native RegExp code will not do a GC and |
| 1454 | // therefore the content of these registers are safe to use after the call. |
| 1455 | // MIPS - using s0..s2, since we are not using CEntry Stub. |
| 1456 | Register subject = s0; |
| 1457 | Register regexp_data = s1; |
| 1458 | Register last_match_info_elements = s2; |
| 1459 | |
| 1460 | // Ensure that a RegExp stack is allocated. |
| 1461 | ExternalReference address_of_regexp_stack_memory_address = |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1462 | ExternalReference::address_of_regexp_stack_memory_address(isolate()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1463 | ExternalReference address_of_regexp_stack_memory_size = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1464 | ExternalReference::address_of_regexp_stack_memory_size(isolate()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1465 | __ li(a0, Operand(address_of_regexp_stack_memory_size)); |
| 1466 | __ lw(a0, MemOperand(a0, 0)); |
| 1467 | __ Branch(&runtime, eq, a0, Operand(zero_reg)); |
| 1468 | |
| 1469 | // Check that the first argument is a JSRegExp object. |
| 1470 | __ lw(a0, MemOperand(sp, kJSRegExpOffset)); |
| 1471 | STATIC_ASSERT(kSmiTag == 0); |
| 1472 | __ JumpIfSmi(a0, &runtime); |
| 1473 | __ GetObjectType(a0, a1, a1); |
| 1474 | __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE)); |
| 1475 | |
| 1476 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 1477 | __ lw(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset)); |
| 1478 | if (FLAG_debug_code) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1479 | __ SmiTst(regexp_data, t0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1480 | __ Check(nz, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1481 | kUnexpectedTypeForRegExpDataFixedArrayExpected, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1482 | t0, |
| 1483 | Operand(zero_reg)); |
| 1484 | __ GetObjectType(regexp_data, a0, a0); |
| 1485 | __ Check(eq, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1486 | kUnexpectedTypeForRegExpDataFixedArrayExpected, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1487 | a0, |
| 1488 | Operand(FIXED_ARRAY_TYPE)); |
| 1489 | } |
| 1490 | |
| 1491 | // regexp_data: RegExp data (FixedArray) |
| 1492 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 1493 | __ lw(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset)); |
| 1494 | __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP))); |
| 1495 | |
| 1496 | // regexp_data: RegExp data (FixedArray) |
| 1497 | // Check that the number of captures fit in the static offsets vector buffer. |
| 1498 | __ lw(a2, |
| 1499 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1500 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 1501 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 1502 | // Multiplying by 2 comes for free since a2 is smi-tagged. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1503 | STATIC_ASSERT(kSmiTag == 0); |
| 1504 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1505 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 1506 | __ Branch( |
| 1507 | &runtime, hi, a2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1508 | |
| 1509 | // Reset offset for possibly sliced string. |
| 1510 | __ mov(t0, zero_reg); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1511 | __ lw(subject, MemOperand(sp, kSubjectOffset)); |
| 1512 | __ JumpIfSmi(subject, &runtime); |
| 1513 | __ mov(a3, subject); // Make a copy of the original subject string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1514 | // subject: subject string |
| 1515 | // a3: subject string |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1516 | // regexp_data: RegExp data (FixedArray) |
| 1517 | // Handle subject string according to its encoding and representation: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1518 | // (1) Sequential string? If yes, go to (4). |
| 1519 | // (2) Sequential or cons? If not, go to (5). |
| 1520 | // (3) Cons string. If the string is flat, replace subject with first string |
| 1521 | // and go to (1). Otherwise bail out to runtime. |
| 1522 | // (4) Sequential string. Load regexp code according to encoding. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1523 | // (E) Carry on. |
| 1524 | /// [...] |
| 1525 | |
| 1526 | // Deferred code at the end of the stub: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1527 | // (5) Long external string? If not, go to (7). |
| 1528 | // (6) External string. Make it, offset-wise, look like a sequential string. |
| 1529 | // Go to (4). |
| 1530 | // (7) Short external string or not a string? If yes, bail out to runtime. |
| 1531 | // (8) Sliced string. Replace subject with parent. Go to (1). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1532 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1533 | Label seq_string /* 4 */, external_string /* 6 */, check_underlying /* 1 */, |
| 1534 | not_seq_nor_cons /* 5 */, not_long_external /* 7 */; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1535 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1536 | __ bind(&check_underlying); |
| 1537 | __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 1538 | __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset)); |
| 1539 | |
| 1540 | // (1) Sequential string? If yes, go to (4). |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1541 | __ And(a1, |
| 1542 | a0, |
| 1543 | Operand(kIsNotStringMask | |
| 1544 | kStringRepresentationMask | |
| 1545 | kShortExternalStringMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1546 | STATIC_ASSERT((kStringTag | kSeqStringTag) == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1547 | __ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (5). |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1548 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1549 | // (2) Sequential or cons? If not, go to (5). |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1550 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 1551 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1552 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 1553 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1554 | // Go to (5). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1555 | __ Branch(¬_seq_nor_cons, ge, a1, Operand(kExternalStringTag)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1556 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1557 | // (3) Cons string. Check that it's flat. |
| 1558 | // Replace subject with first string and reload instance type. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1559 | __ lw(a0, FieldMemOperand(subject, ConsString::kSecondOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1560 | __ LoadRoot(a1, Heap::kempty_stringRootIndex); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1561 | __ Branch(&runtime, ne, a0, Operand(a1)); |
| 1562 | __ lw(subject, FieldMemOperand(subject, ConsString::kFirstOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1563 | __ jmp(&check_underlying); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1564 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1565 | // (4) Sequential string. Load regexp code according to encoding. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1566 | __ bind(&seq_string); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1567 | // subject: sequential subject string (or look-alike, external string) |
| 1568 | // a3: original subject string |
| 1569 | // Load previous index and check range before a3 is overwritten. We have to |
| 1570 | // use a3 instead of subject here because subject might have been only made |
| 1571 | // to look like a sequential string when it actually is an external string. |
| 1572 | __ lw(a1, MemOperand(sp, kPreviousIndexOffset)); |
| 1573 | __ JumpIfNotSmi(a1, &runtime); |
| 1574 | __ lw(a3, FieldMemOperand(a3, String::kLengthOffset)); |
| 1575 | __ Branch(&runtime, ls, a3, Operand(a1)); |
| 1576 | __ sra(a1, a1, kSmiTagSize); // Untag the Smi. |
| 1577 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1578 | STATIC_ASSERT(kStringEncodingMask == 4); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1579 | STATIC_ASSERT(kOneByteStringTag == 4); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1580 | STATIC_ASSERT(kTwoByteStringTag == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1581 | __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for one-byte. |
| 1582 | __ lw(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1583 | __ sra(a3, a0, 2); // a3 is 1 for ASCII, 0 for UC16 (used below). |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1584 | __ lw(t1, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1585 | __ Movz(t9, t1, a0); // If UC16 (a0 is 0), replace t9 w/kDataUC16CodeOffset. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1586 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1587 | // (E) Carry on. String handling is done. |
| 1588 | // t9: irregexp code |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1589 | // Check that the irregexp code has been generated for the actual string |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1590 | // encoding. If it has, the field contains a code object otherwise it contains |
| 1591 | // a smi (code flushing support). |
| 1592 | __ JumpIfSmi(t9, &runtime); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1593 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1594 | // a1: previous index |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1595 | // a3: encoding of subject string (1 if one_byte, 0 if two_byte); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1596 | // t9: code |
| 1597 | // subject: Subject string |
| 1598 | // regexp_data: RegExp data (FixedArray) |
| 1599 | // All checks done. Now push arguments for native regexp code. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1600 | __ IncrementCounter(isolate()->counters()->regexp_entry_native(), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1601 | 1, a0, a2); |
| 1602 | |
| 1603 | // Isolates: note we add an additional parameter here (isolate pointer). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1604 | const int kRegExpExecuteArguments = 9; |
Ben Murdoch | db1b438 | 2012-04-26 19:03:50 +0100 | [diff] [blame] | 1605 | const int kParameterRegisters = 4; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1606 | __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters); |
| 1607 | |
| 1608 | // Stack pointer now points to cell where return address is to be written. |
| 1609 | // Arguments are before that on the stack or in registers, meaning we |
| 1610 | // treat the return address as argument 5. Thus every argument after that |
| 1611 | // needs to be shifted back by 1. Since DirectCEntryStub will handle |
| 1612 | // allocating space for the c argument slots, we don't need to calculate |
| 1613 | // that into the argument positions on the stack. This is how the stack will |
| 1614 | // look (sp meaning the value of sp at this moment): |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1615 | // [sp + 5] - Argument 9 |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1616 | // [sp + 4] - Argument 8 |
| 1617 | // [sp + 3] - Argument 7 |
| 1618 | // [sp + 2] - Argument 6 |
| 1619 | // [sp + 1] - Argument 5 |
| 1620 | // [sp + 0] - saved ra |
| 1621 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1622 | // Argument 9: Pass current isolate address. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1623 | // CFunctionArgumentOperand handles MIPS stack argument slots. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1624 | __ li(a0, Operand(ExternalReference::isolate_address(isolate()))); |
| 1625 | __ sw(a0, MemOperand(sp, 5 * kPointerSize)); |
| 1626 | |
| 1627 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 1628 | __ li(a0, Operand(1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1629 | __ sw(a0, MemOperand(sp, 4 * kPointerSize)); |
| 1630 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1631 | // Argument 7: Start (high end) of backtracking stack memory area. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1632 | __ li(a0, Operand(address_of_regexp_stack_memory_address)); |
| 1633 | __ lw(a0, MemOperand(a0, 0)); |
| 1634 | __ li(a2, Operand(address_of_regexp_stack_memory_size)); |
| 1635 | __ lw(a2, MemOperand(a2, 0)); |
| 1636 | __ addu(a0, a0, a2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1637 | __ sw(a0, MemOperand(sp, 3 * kPointerSize)); |
| 1638 | |
| 1639 | // Argument 6: Set the number of capture registers to zero to force global |
| 1640 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 1641 | __ mov(a0, zero_reg); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1642 | __ sw(a0, MemOperand(sp, 2 * kPointerSize)); |
| 1643 | |
| 1644 | // Argument 5: static offsets vector buffer. |
| 1645 | __ li(a0, Operand( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1646 | ExternalReference::address_of_static_offsets_vector(isolate()))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1647 | __ sw(a0, MemOperand(sp, 1 * kPointerSize)); |
| 1648 | |
| 1649 | // For arguments 4 and 3 get string length, calculate start of string data |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1650 | // calculate the shift of the index (0 for one-byte and 1 for two-byte). |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1651 | __ Addu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1652 | __ Xor(a3, a3, Operand(1)); // 1 for 2-byte str, 0 for 1-byte. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1653 | // Load the length from the original subject string from the previous stack |
| 1654 | // frame. Therefore we have to use fp, which points exactly to two pointer |
| 1655 | // sizes below the previous sp. (Because creating a new stack frame pushes |
| 1656 | // the previous fp onto the stack and moves up sp by 2 * kPointerSize.) |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1657 | __ lw(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1658 | // If slice offset is not 0, load the length from the original sliced string. |
| 1659 | // Argument 4, a3: End of string data |
| 1660 | // Argument 3, a2: Start of string data |
| 1661 | // Prepare start and end index of the input. |
| 1662 | __ sllv(t1, t0, a3); |
| 1663 | __ addu(t0, t2, t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1664 | __ sllv(t1, a1, a3); |
| 1665 | __ addu(a2, t0, t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1666 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1667 | __ lw(t2, FieldMemOperand(subject, String::kLengthOffset)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1668 | __ sra(t2, t2, kSmiTagSize); |
| 1669 | __ sllv(t1, t2, a3); |
| 1670 | __ addu(a3, t0, t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1671 | // Argument 2 (a1): Previous index. |
| 1672 | // Already there |
| 1673 | |
| 1674 | // Argument 1 (a0): Subject string. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1675 | __ mov(a0, subject); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1676 | |
| 1677 | // Locate the code entry and call it. |
| 1678 | __ Addu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1679 | DirectCEntryStub stub(isolate()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1680 | stub.GenerateCall(masm, t9); |
| 1681 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1682 | __ LeaveExitFrame(false, no_reg, true); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1683 | |
| 1684 | // v0: result |
| 1685 | // subject: subject string (callee saved) |
| 1686 | // regexp_data: RegExp data (callee saved) |
| 1687 | // last_match_info_elements: Last match info elements (callee saved) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1688 | // Check the result. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1689 | Label success; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1690 | __ Branch(&success, eq, v0, Operand(1)); |
| 1691 | // We expect exactly one result since we force the called regexp to behave |
| 1692 | // as non-global. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1693 | Label failure; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1694 | __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1695 | // If not exception it can only be retry. Handle that in the runtime system. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1696 | __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1697 | // Result must now be exception. If there is no pending exception already a |
| 1698 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 1699 | // haven't created the exception yet. Handle that in the runtime system. |
| 1700 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1701 | __ li(a1, Operand(isolate()->factory()->the_hole_value())); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1702 | __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1703 | isolate()))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1704 | __ lw(v0, MemOperand(a2, 0)); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1705 | __ Branch(&runtime, eq, v0, Operand(a1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1706 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1707 | // For exception, throw the exception again. |
| 1708 | __ TailCallRuntime(Runtime::kRegExpExecReThrow); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1709 | |
| 1710 | __ bind(&failure); |
| 1711 | // For failure and exception return null. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1712 | __ li(v0, Operand(isolate()->factory()->null_value())); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1713 | __ DropAndRet(4); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1714 | |
| 1715 | // Process the result from the native regexp code. |
| 1716 | __ bind(&success); |
| 1717 | __ lw(a1, |
| 1718 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
| 1719 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1720 | // Multiplying by 2 comes for free since r1 is smi-tagged. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1721 | STATIC_ASSERT(kSmiTag == 0); |
| 1722 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 1723 | __ Addu(a1, a1, Operand(2)); // a1 was a smi. |
| 1724 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1725 | __ lw(a0, MemOperand(sp, kLastMatchInfoOffset)); |
| 1726 | __ JumpIfSmi(a0, &runtime); |
| 1727 | __ GetObjectType(a0, a2, a2); |
| 1728 | __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE)); |
| 1729 | // Check that the JSArray is in fast case. |
| 1730 | __ lw(last_match_info_elements, |
| 1731 | FieldMemOperand(a0, JSArray::kElementsOffset)); |
| 1732 | __ lw(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset)); |
| 1733 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 1734 | __ Branch(&runtime, ne, a0, Operand(at)); |
| 1735 | // Check that the last match info has space for the capture registers and the |
| 1736 | // additional information. |
| 1737 | __ lw(a0, |
| 1738 | FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset)); |
| 1739 | __ Addu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead)); |
| 1740 | __ sra(at, a0, kSmiTagSize); |
| 1741 | __ Branch(&runtime, gt, a2, Operand(at)); |
| 1742 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1743 | // a1: number of capture registers |
| 1744 | // subject: subject string |
| 1745 | // Store the capture count. |
| 1746 | __ sll(a2, a1, kSmiTagSize + kSmiShiftSize); // To smi. |
| 1747 | __ sw(a2, FieldMemOperand(last_match_info_elements, |
| 1748 | RegExpImpl::kLastCaptureCountOffset)); |
| 1749 | // Store last subject and last input. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1750 | __ sw(subject, |
| 1751 | FieldMemOperand(last_match_info_elements, |
| 1752 | RegExpImpl::kLastSubjectOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1753 | __ mov(a2, subject); |
| 1754 | __ RecordWriteField(last_match_info_elements, |
| 1755 | RegExpImpl::kLastSubjectOffset, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1756 | subject, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1757 | t3, |
| 1758 | kRAHasNotBeenSaved, |
| 1759 | kDontSaveFPRegs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1760 | __ mov(subject, a2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1761 | __ sw(subject, |
| 1762 | FieldMemOperand(last_match_info_elements, |
| 1763 | RegExpImpl::kLastInputOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1764 | __ RecordWriteField(last_match_info_elements, |
| 1765 | RegExpImpl::kLastInputOffset, |
| 1766 | subject, |
| 1767 | t3, |
| 1768 | kRAHasNotBeenSaved, |
| 1769 | kDontSaveFPRegs); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1770 | |
| 1771 | // Get the static offsets vector filled by the native regexp code. |
| 1772 | ExternalReference address_of_static_offsets_vector = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1773 | ExternalReference::address_of_static_offsets_vector(isolate()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1774 | __ li(a2, Operand(address_of_static_offsets_vector)); |
| 1775 | |
| 1776 | // a1: number of capture registers |
| 1777 | // a2: offsets vector |
| 1778 | Label next_capture, done; |
| 1779 | // Capture register counter starts from number of capture registers and |
| 1780 | // counts down until wrapping after zero. |
| 1781 | __ Addu(a0, |
| 1782 | last_match_info_elements, |
| 1783 | Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag)); |
| 1784 | __ bind(&next_capture); |
| 1785 | __ Subu(a1, a1, Operand(1)); |
| 1786 | __ Branch(&done, lt, a1, Operand(zero_reg)); |
| 1787 | // Read the value from the static offsets vector buffer. |
| 1788 | __ lw(a3, MemOperand(a2, 0)); |
| 1789 | __ addiu(a2, a2, kPointerSize); |
| 1790 | // Store the smi value in the last match info. |
| 1791 | __ sll(a3, a3, kSmiTagSize); // Convert to Smi. |
| 1792 | __ sw(a3, MemOperand(a0, 0)); |
| 1793 | __ Branch(&next_capture, USE_DELAY_SLOT); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1794 | __ addiu(a0, a0, kPointerSize); // In branch delay slot. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1795 | |
| 1796 | __ bind(&done); |
| 1797 | |
| 1798 | // Return last match info. |
| 1799 | __ lw(v0, MemOperand(sp, kLastMatchInfoOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1800 | __ DropAndRet(4); |
| 1801 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1802 | // Do the runtime call to execute the regexp. |
| 1803 | __ bind(&runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1804 | __ TailCallRuntime(Runtime::kRegExpExec); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1805 | |
| 1806 | // Deferred code for string handling. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1807 | // (5) Long external string? If not, go to (7). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1808 | __ bind(¬_seq_nor_cons); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1809 | // Go to (7). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1810 | __ Branch(¬_long_external, gt, a1, Operand(kExternalStringTag)); |
| 1811 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1812 | // (6) External string. Make it, offset-wise, look like a sequential string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1813 | __ bind(&external_string); |
| 1814 | __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 1815 | __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset)); |
| 1816 | if (FLAG_debug_code) { |
| 1817 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 1818 | // Sequential strings have already been ruled out. |
| 1819 | __ And(at, a0, Operand(kIsIndirectStringMask)); |
| 1820 | __ Assert(eq, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1821 | kExternalStringExpectedButNotFound, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1822 | at, |
| 1823 | Operand(zero_reg)); |
| 1824 | } |
| 1825 | __ lw(subject, |
| 1826 | FieldMemOperand(subject, ExternalString::kResourceDataOffset)); |
| 1827 | // Move the pointer so that offset-wise, it looks like a sequential string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1828 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1829 | __ Subu(subject, |
| 1830 | subject, |
| 1831 | SeqTwoByteString::kHeaderSize - kHeapObjectTag); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1832 | __ jmp(&seq_string); // Go to (5). |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1833 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1834 | // (7) Short external string or not a string? If yes, bail out to runtime. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1835 | __ bind(¬_long_external); |
| 1836 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 1837 | __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask)); |
| 1838 | __ Branch(&runtime, ne, at, Operand(zero_reg)); |
| 1839 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1840 | // (8) Sliced string. Replace subject with parent. Go to (4). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1841 | // Load offset into t0 and replace subject string with parent. |
| 1842 | __ lw(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset)); |
| 1843 | __ sra(t0, t0, kSmiTagSize); |
| 1844 | __ lw(subject, FieldMemOperand(subject, SlicedString::kParentOffset)); |
| 1845 | __ jmp(&check_underlying); // Go to (4). |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1846 | #endif // V8_INTERPRETED_REGEXP |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1850 | static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) { |
| 1851 | // a0 : number of arguments to the construct function |
| 1852 | // a2 : feedback vector |
| 1853 | // a3 : slot in feedback vector (Smi) |
| 1854 | // a1 : the function to call |
| 1855 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1856 | const RegList kSavedRegs = 1 << 4 | // a0 |
| 1857 | 1 << 5 | // a1 |
| 1858 | 1 << 6 | // a2 |
| 1859 | 1 << 7; // a3 |
| 1860 | |
| 1861 | // Number-of-arguments register must be smi-tagged to call out. |
| 1862 | __ SmiTag(a0); |
| 1863 | __ MultiPush(kSavedRegs); |
| 1864 | |
| 1865 | __ CallStub(stub); |
| 1866 | |
| 1867 | __ MultiPop(kSavedRegs); |
| 1868 | __ SmiUntag(a0); |
| 1869 | } |
| 1870 | |
| 1871 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1872 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1873 | // Cache the called function in a feedback vector slot. Cache states |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1874 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 1875 | // megamorphic. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1876 | // a0 : number of arguments to the construct function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1877 | // a1 : the function to call |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1878 | // a2 : feedback vector |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1879 | // a3 : slot in feedback vector (Smi) |
| 1880 | Label initialize, done, miss, megamorphic, not_array_function; |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 1881 | Label done_initialize_count, done_increment_count; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1882 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1883 | DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()), |
| 1884 | masm->isolate()->heap()->megamorphic_symbol()); |
| 1885 | DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()), |
| 1886 | masm->isolate()->heap()->uninitialized_symbol()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1887 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1888 | // Load the cache state into t2. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1889 | __ Lsa(t2, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1890 | __ lw(t2, FieldMemOperand(t2, FixedArray::kHeaderSize)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1891 | |
| 1892 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 1893 | // function without changing the state. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1894 | // We don't know if t2 is a WeakCell or a Symbol, but it's harmless to read at |
| 1895 | // this position in a symbol (see static asserts in type-feedback-vector.h). |
| 1896 | Label check_allocation_site; |
| 1897 | Register feedback_map = t1; |
| 1898 | Register weak_value = t4; |
| 1899 | __ lw(weak_value, FieldMemOperand(t2, WeakCell::kValueOffset)); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 1900 | __ Branch(&done_increment_count, eq, a1, Operand(weak_value)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1901 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 1902 | __ Branch(&done, eq, t2, Operand(at)); |
| 1903 | __ lw(feedback_map, FieldMemOperand(t2, HeapObject::kMapOffset)); |
| 1904 | __ LoadRoot(at, Heap::kWeakCellMapRootIndex); |
| 1905 | __ Branch(&check_allocation_site, ne, feedback_map, Operand(at)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1906 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1907 | // If the weak cell is cleared, we have a new chance to become monomorphic. |
| 1908 | __ JumpIfSmi(weak_value, &initialize); |
| 1909 | __ jmp(&megamorphic); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1910 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1911 | __ bind(&check_allocation_site); |
| 1912 | // If we came here, we need to see if we are the array function. |
| 1913 | // If we didn't have a matching function, and we didn't find the megamorph |
| 1914 | // sentinel, then we have in the slot either some other function or an |
| 1915 | // AllocationSite. |
| 1916 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 1917 | __ Branch(&miss, ne, feedback_map, Operand(at)); |
| 1918 | |
| 1919 | // Make sure the function is the Array() function |
| 1920 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, t2); |
| 1921 | __ Branch(&megamorphic, ne, a1, Operand(t2)); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 1922 | __ jmp(&done_increment_count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1923 | |
| 1924 | __ bind(&miss); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1925 | |
| 1926 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 1927 | // megamorphic. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1928 | __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1929 | __ Branch(&initialize, eq, t2, Operand(at)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1930 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 1931 | // write-barrier is needed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1932 | __ bind(&megamorphic); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1933 | __ Lsa(t2, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1934 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1935 | __ sw(at, FieldMemOperand(t2, FixedArray::kHeaderSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1936 | __ jmp(&done); |
| 1937 | |
| 1938 | // An uninitialized cache is patched with the function. |
| 1939 | __ bind(&initialize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1940 | // Make sure the function is the Array() function. |
| 1941 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, t2); |
| 1942 | __ Branch(¬_array_function, ne, a1, Operand(t2)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1943 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1944 | // The target function is the Array constructor, |
| 1945 | // Create an AllocationSite if we don't already have it, store it in the |
| 1946 | // slot. |
| 1947 | CreateAllocationSiteStub create_stub(masm->isolate()); |
| 1948 | CallStubInRecordCallTarget(masm, &create_stub); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 1949 | __ Branch(&done_initialize_count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1950 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1951 | __ bind(¬_array_function); |
| 1952 | CreateWeakCellStub weak_cell_stub(masm->isolate()); |
| 1953 | CallStubInRecordCallTarget(masm, &weak_cell_stub); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 1954 | |
| 1955 | __ bind(&done_initialize_count); |
| 1956 | // Initialize the call counter. |
| 1957 | __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
| 1958 | __ li(t0, Operand(Smi::FromInt(1))); |
| 1959 | __ Branch(USE_DELAY_SLOT, &done); |
| 1960 | __ sw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
| 1961 | |
| 1962 | __ bind(&done_increment_count); |
| 1963 | |
| 1964 | // Increment the call count for monomorphic function calls. |
| 1965 | __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
| 1966 | __ lw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
| 1967 | __ Addu(t0, t0, Operand(Smi::FromInt(1))); |
| 1968 | __ sw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
| 1969 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1970 | __ bind(&done); |
| 1971 | } |
| 1972 | |
| 1973 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1974 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 1975 | // a0 : number of arguments |
| 1976 | // a1 : the function to call |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1977 | // a2 : feedback vector |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1978 | // a3 : slot in feedback vector (Smi, for RecordCallTarget) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1979 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1980 | Label non_function; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1981 | // Check that the function is not a smi. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1982 | __ JumpIfSmi(a1, &non_function); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1983 | // Check that the function is a JSFunction. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1984 | __ GetObjectType(a1, t1, t1); |
| 1985 | __ Branch(&non_function, ne, t1, Operand(JS_FUNCTION_TYPE)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1986 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1987 | GenerateRecordCallTarget(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1988 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1989 | __ Lsa(t1, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1990 | Label feedback_register_initialized; |
| 1991 | // Put the AllocationSite from the feedback vector into a2, or undefined. |
| 1992 | __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize)); |
| 1993 | __ lw(t1, FieldMemOperand(a2, AllocationSite::kMapOffset)); |
| 1994 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 1995 | __ Branch(&feedback_register_initialized, eq, t1, Operand(at)); |
| 1996 | __ LoadRoot(a2, Heap::kUndefinedValueRootIndex); |
| 1997 | __ bind(&feedback_register_initialized); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1998 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1999 | __ AssertUndefinedOrAllocationSite(a2, t1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2000 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2001 | // Pass function as new target. |
| 2002 | __ mov(a3, a1); |
| 2003 | |
| 2004 | // Tail call to the function-specific construct stub (still in the caller |
| 2005 | // context at this point). |
| 2006 | __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 2007 | __ lw(t0, FieldMemOperand(t0, SharedFunctionInfo::kConstructStubOffset)); |
| 2008 | __ Addu(at, t0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2009 | __ Jump(at); |
| 2010 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2011 | __ bind(&non_function); |
| 2012 | __ mov(a3, a1); |
| 2013 | __ Jump(isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2017 | void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2018 | // a1 - function |
| 2019 | // a3 - slot id |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2020 | // a2 - vector |
| 2021 | // t0 - loaded from vector[slot] |
| 2022 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, at); |
| 2023 | __ Branch(miss, ne, a1, Operand(at)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2024 | |
| 2025 | __ li(a0, Operand(arg_count())); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2026 | |
| 2027 | // Increment the call count for monomorphic function calls. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2028 | __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2029 | __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 2030 | __ Addu(a3, a3, Operand(Smi::FromInt(1))); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2031 | __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2032 | |
| 2033 | __ mov(a2, t0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2034 | __ mov(a3, a1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2035 | ArrayConstructorStub stub(masm->isolate(), arg_count()); |
| 2036 | __ TailCallStub(&stub); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | |
| 2040 | void CallICStub::Generate(MacroAssembler* masm) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2041 | // a1 - function |
| 2042 | // a3 - slot id (Smi) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2043 | // a2 - vector |
| 2044 | Label extra_checks_or_miss, call, call_function; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2045 | int argc = arg_count(); |
| 2046 | ParameterCount actual(argc); |
| 2047 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2048 | // The checks. First, does r1 match the recorded monomorphic target? |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2049 | __ Lsa(t0, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2050 | __ lw(t0, FieldMemOperand(t0, FixedArray::kHeaderSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2051 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2052 | // We don't know that we have a weak cell. We might have a private symbol |
| 2053 | // or an AllocationSite, but the memory is safe to examine. |
| 2054 | // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to |
| 2055 | // FixedArray. |
| 2056 | // WeakCell::kValueOffset - contains a JSFunction or Smi(0) |
| 2057 | // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not |
| 2058 | // computed, meaning that it can't appear to be a pointer. If the low bit is |
| 2059 | // 0, then hash is computed, but the 0 bit prevents the field from appearing |
| 2060 | // to be a pointer. |
| 2061 | STATIC_ASSERT(WeakCell::kSize >= kPointerSize); |
| 2062 | STATIC_ASSERT(AllocationSite::kTransitionInfoOffset == |
| 2063 | WeakCell::kValueOffset && |
| 2064 | WeakCell::kValueOffset == Symbol::kHashFieldSlot); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2065 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2066 | __ lw(t1, FieldMemOperand(t0, WeakCell::kValueOffset)); |
| 2067 | __ Branch(&extra_checks_or_miss, ne, a1, Operand(t1)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2068 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2069 | // The compare above could have been a SMI/SMI comparison. Guard against this |
| 2070 | // convincing us that we have a monomorphic JSFunction. |
| 2071 | __ JumpIfSmi(a1, &extra_checks_or_miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2072 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2073 | // Increment the call count for monomorphic function calls. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2074 | __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2075 | __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 2076 | __ Addu(a3, a3, Operand(Smi::FromInt(1))); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2077 | __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2078 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2079 | __ bind(&call_function); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2080 | __ Jump(masm->isolate()->builtins()->CallFunction(convert_mode(), |
| 2081 | tail_call_mode()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2082 | RelocInfo::CODE_TARGET, al, zero_reg, Operand(zero_reg), |
| 2083 | USE_DELAY_SLOT); |
| 2084 | __ li(a0, Operand(argc)); // In delay slot. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2085 | |
| 2086 | __ bind(&extra_checks_or_miss); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2087 | Label uninitialized, miss, not_allocation_site; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2088 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2089 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2090 | __ Branch(&call, eq, t0, Operand(at)); |
| 2091 | |
| 2092 | // Verify that t0 contains an AllocationSite |
| 2093 | __ lw(t1, FieldMemOperand(t0, HeapObject::kMapOffset)); |
| 2094 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 2095 | __ Branch(¬_allocation_site, ne, t1, Operand(at)); |
| 2096 | |
| 2097 | HandleArrayCase(masm, &miss); |
| 2098 | |
| 2099 | __ bind(¬_allocation_site); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2100 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2101 | // The following cases attempt to handle MISS cases without going to the |
| 2102 | // runtime. |
| 2103 | if (FLAG_trace_ic) { |
| 2104 | __ Branch(&miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2105 | } |
| 2106 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2107 | __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex); |
| 2108 | __ Branch(&uninitialized, eq, t0, Operand(at)); |
| 2109 | |
| 2110 | // We are going megamorphic. If the feedback is a JSFunction, it is fine |
| 2111 | // to handle it here. More complex cases are dealt with in the runtime. |
| 2112 | __ AssertNotSmi(t0); |
| 2113 | __ GetObjectType(t0, t1, t1); |
| 2114 | __ Branch(&miss, ne, t1, Operand(JS_FUNCTION_TYPE)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2115 | __ Lsa(t0, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2116 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 2117 | __ sw(at, FieldMemOperand(t0, FixedArray::kHeaderSize)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2118 | |
| 2119 | __ bind(&call); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2120 | __ Jump(masm->isolate()->builtins()->Call(convert_mode(), tail_call_mode()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2121 | RelocInfo::CODE_TARGET, al, zero_reg, Operand(zero_reg), |
| 2122 | USE_DELAY_SLOT); |
| 2123 | __ li(a0, Operand(argc)); // In delay slot. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2124 | |
| 2125 | __ bind(&uninitialized); |
| 2126 | |
| 2127 | // We are going monomorphic, provided we actually have a JSFunction. |
| 2128 | __ JumpIfSmi(a1, &miss); |
| 2129 | |
| 2130 | // Goto miss case if we do not have a function. |
| 2131 | __ GetObjectType(a1, t0, t0); |
| 2132 | __ Branch(&miss, ne, t0, Operand(JS_FUNCTION_TYPE)); |
| 2133 | |
| 2134 | // Make sure the function is not the Array() function, which requires special |
| 2135 | // behavior on MISS. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2136 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, t0); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2137 | __ Branch(&miss, eq, a1, Operand(t0)); |
| 2138 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2139 | // Make sure the function belongs to the same native context. |
| 2140 | __ lw(t0, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 2141 | __ lw(t0, ContextMemOperand(t0, Context::NATIVE_CONTEXT_INDEX)); |
| 2142 | __ lw(t1, NativeContextMemOperand()); |
| 2143 | __ Branch(&miss, ne, t0, Operand(t1)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2144 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2145 | // Initialize the call counter. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2146 | __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 2147 | __ li(t0, Operand(Smi::FromInt(1))); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2148 | __ sw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2149 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2150 | // Store the function. Use a stub since we need a frame for allocation. |
| 2151 | // a2 - vector |
| 2152 | // a3 - slot |
| 2153 | // a1 - function |
| 2154 | { |
| 2155 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2156 | CreateWeakCellStub create_stub(masm->isolate()); |
| 2157 | __ Push(a1); |
| 2158 | __ CallStub(&create_stub); |
| 2159 | __ Pop(a1); |
| 2160 | } |
| 2161 | |
| 2162 | __ Branch(&call_function); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2163 | |
| 2164 | // We are here because tracing is on or we encountered a MISS case we can't |
| 2165 | // handle here. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2166 | __ bind(&miss); |
| 2167 | GenerateMiss(masm); |
| 2168 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2169 | __ Branch(&call); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2173 | void CallICStub::GenerateMiss(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2174 | FrameScope scope(masm, StackFrame::INTERNAL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2175 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2176 | // Push the receiver and the function and feedback info. |
| 2177 | __ Push(a1, a2, a3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2178 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2179 | // Call the entry. |
| 2180 | __ CallRuntime(Runtime::kCallIC_Miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2181 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2182 | // Move result to a1 and exit the internal frame. |
| 2183 | __ mov(a1, v0); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2184 | } |
| 2185 | |
| 2186 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2187 | // StringCharCodeAtGenerator. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2188 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2189 | DCHECK(!t0.is(index_)); |
| 2190 | DCHECK(!t0.is(result_)); |
| 2191 | DCHECK(!t0.is(object_)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2192 | if (check_mode_ == RECEIVER_IS_UNKNOWN) { |
| 2193 | // If the receiver is a smi trigger the non-string case. |
| 2194 | __ JumpIfSmi(object_, receiver_not_string_); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2195 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2196 | // Fetch the instance type of the receiver into result register. |
| 2197 | __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 2198 | __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 2199 | // If the receiver is not a string trigger the non-string case. |
| 2200 | __ And(t0, result_, Operand(kIsNotStringMask)); |
| 2201 | __ Branch(receiver_not_string_, ne, t0, Operand(zero_reg)); |
| 2202 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2203 | |
| 2204 | // If the index is non-smi trigger the non-smi case. |
| 2205 | __ JumpIfNotSmi(index_, &index_not_smi_); |
| 2206 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2207 | __ bind(&got_smi_index_); |
| 2208 | |
| 2209 | // Check for index out of range. |
| 2210 | __ lw(t0, FieldMemOperand(object_, String::kLengthOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2211 | __ Branch(index_out_of_range_, ls, t0, Operand(index_)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2212 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2213 | __ sra(index_, index_, kSmiTagSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2214 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2215 | StringCharLoadGenerator::Generate(masm, |
| 2216 | object_, |
| 2217 | index_, |
| 2218 | result_, |
| 2219 | &call_runtime_); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2220 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2221 | __ sll(result_, result_, kSmiTagSize); |
| 2222 | __ bind(&exit_); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | |
| 2226 | void StringCharCodeAtGenerator::GenerateSlow( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2227 | MacroAssembler* masm, EmbedMode embed_mode, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2228 | const RuntimeCallHelper& call_helper) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2229 | __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2230 | |
| 2231 | // Index is not a smi. |
| 2232 | __ bind(&index_not_smi_); |
| 2233 | // If index is a heap number, try converting it to an integer. |
| 2234 | __ CheckMap(index_, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2235 | result_, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2236 | Heap::kHeapNumberMapRootIndex, |
| 2237 | index_not_number_, |
| 2238 | DONT_DO_SMI_CHECK); |
| 2239 | call_helper.BeforeCall(masm); |
| 2240 | // Consumed by runtime conversion function: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2241 | if (embed_mode == PART_OF_IC_HANDLER) { |
| 2242 | __ Push(LoadWithVectorDescriptor::VectorRegister(), |
| 2243 | LoadWithVectorDescriptor::SlotRegister(), object_, index_); |
| 2244 | } else { |
| 2245 | __ Push(object_, index_); |
| 2246 | } |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 2247 | __ CallRuntime(Runtime::kNumberToSmi); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2248 | |
| 2249 | // Save the conversion result before the pop instructions below |
| 2250 | // have a chance to overwrite it. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2251 | __ Move(index_, v0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2252 | if (embed_mode == PART_OF_IC_HANDLER) { |
| 2253 | __ Pop(LoadWithVectorDescriptor::VectorRegister(), |
| 2254 | LoadWithVectorDescriptor::SlotRegister(), object_); |
| 2255 | } else { |
| 2256 | __ pop(object_); |
| 2257 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2258 | // Reload the instance type. |
| 2259 | __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 2260 | __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 2261 | call_helper.AfterCall(masm); |
| 2262 | // If index is still not a smi, it must be out of range. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2263 | __ JumpIfNotSmi(index_, index_out_of_range_); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2264 | // Otherwise, return to the fast path. |
| 2265 | __ Branch(&got_smi_index_); |
| 2266 | |
| 2267 | // Call runtime. We get here when the receiver is a string and the |
| 2268 | // index is a number, but the code of getting the actual character |
| 2269 | // is too complex (e.g., when the string needs to be flattened). |
| 2270 | __ bind(&call_runtime_); |
| 2271 | call_helper.BeforeCall(masm); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2272 | __ sll(index_, index_, kSmiTagSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2273 | __ Push(object_, index_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2274 | __ CallRuntime(Runtime::kStringCharCodeAtRT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2275 | |
| 2276 | __ Move(result_, v0); |
| 2277 | |
| 2278 | call_helper.AfterCall(masm); |
| 2279 | __ jmp(&exit_); |
| 2280 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2281 | __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | |
| 2285 | // ------------------------------------------------------------------------- |
| 2286 | // StringCharFromCodeGenerator |
| 2287 | |
| 2288 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2289 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 2290 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2291 | DCHECK(!t0.is(result_)); |
| 2292 | DCHECK(!t0.is(code_)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2293 | |
| 2294 | STATIC_ASSERT(kSmiTag == 0); |
| 2295 | STATIC_ASSERT(kSmiShiftSize == 0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2296 | DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1)); |
| 2297 | __ And(t0, code_, Operand(kSmiTagMask | |
| 2298 | ((~String::kMaxOneByteCharCodeU) << kSmiTagSize))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2299 | __ Branch(&slow_case_, ne, t0, Operand(zero_reg)); |
| 2300 | |
| 2301 | __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2302 | // At this point code register contains smi tagged one-byte char code. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2303 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2304 | __ Lsa(result_, result_, code_, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2305 | __ lw(result_, FieldMemOperand(result_, FixedArray::kHeaderSize)); |
| 2306 | __ LoadRoot(t0, Heap::kUndefinedValueRootIndex); |
| 2307 | __ Branch(&slow_case_, eq, result_, Operand(t0)); |
| 2308 | __ bind(&exit_); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | |
| 2312 | void StringCharFromCodeGenerator::GenerateSlow( |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2313 | MacroAssembler* masm, |
| 2314 | const RuntimeCallHelper& call_helper) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2315 | __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2316 | |
| 2317 | __ bind(&slow_case_); |
| 2318 | call_helper.BeforeCall(masm); |
| 2319 | __ push(code_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2320 | __ CallRuntime(Runtime::kStringCharFromCode); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2321 | __ Move(result_, v0); |
| 2322 | |
| 2323 | call_helper.AfterCall(masm); |
| 2324 | __ Branch(&exit_); |
| 2325 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2326 | __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2330 | enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2331 | |
| 2332 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2333 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 2334 | Register dest, |
| 2335 | Register src, |
| 2336 | Register count, |
| 2337 | Register scratch, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2338 | String::Encoding encoding) { |
| 2339 | if (FLAG_debug_code) { |
| 2340 | // Check that destination is word aligned. |
| 2341 | __ And(scratch, dest, Operand(kPointerAlignmentMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2342 | __ Check(eq, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2343 | kDestinationOfCopyNotAligned, |
| 2344 | scratch, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2345 | Operand(zero_reg)); |
| 2346 | } |
| 2347 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2348 | // Assumes word reads and writes are little endian. |
| 2349 | // Nothing to do for zero characters. |
| 2350 | Label done; |
| 2351 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2352 | if (encoding == String::TWO_BYTE_ENCODING) { |
| 2353 | __ Addu(count, count, count); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2356 | Register limit = count; // Read until dest equals this. |
| 2357 | __ Addu(limit, dest, Operand(count)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2358 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2359 | Label loop_entry, loop; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2360 | // Copy bytes from src to dest until dest hits limit. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2361 | __ Branch(&loop_entry); |
| 2362 | __ bind(&loop); |
| 2363 | __ lbu(scratch, MemOperand(src)); |
| 2364 | __ Addu(src, src, Operand(1)); |
| 2365 | __ sb(scratch, MemOperand(dest)); |
| 2366 | __ Addu(dest, dest, Operand(1)); |
| 2367 | __ bind(&loop_entry); |
| 2368 | __ Branch(&loop, lt, dest, Operand(limit)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2369 | |
| 2370 | __ bind(&done); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2374 | void SubStringStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2375 | Label runtime; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2376 | // Stack frame on entry. |
| 2377 | // ra: return address |
| 2378 | // sp[0]: to |
| 2379 | // sp[4]: from |
| 2380 | // sp[8]: string |
| 2381 | |
| 2382 | // This stub is called from the native-call %_SubString(...), so |
| 2383 | // nothing can be assumed about the arguments. It is tested that: |
| 2384 | // "string" is a sequential string, |
| 2385 | // both "from" and "to" are smis, and |
| 2386 | // 0 <= from <= to <= string.length. |
| 2387 | // If any of these assumptions fail, we call the runtime system. |
| 2388 | |
Ben Murdoch | db1b438 | 2012-04-26 19:03:50 +0100 | [diff] [blame] | 2389 | const int kToOffset = 0 * kPointerSize; |
| 2390 | const int kFromOffset = 1 * kPointerSize; |
| 2391 | const int kStringOffset = 2 * kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2392 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2393 | __ lw(a2, MemOperand(sp, kToOffset)); |
| 2394 | __ lw(a3, MemOperand(sp, kFromOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2395 | STATIC_ASSERT(kFromOffset == kToOffset + 4); |
| 2396 | STATIC_ASSERT(kSmiTag == 0); |
| 2397 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 2398 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2399 | // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is |
| 2400 | // safe in this case. |
| 2401 | __ UntagAndJumpIfNotSmi(a2, a2, &runtime); |
| 2402 | __ UntagAndJumpIfNotSmi(a3, a3, &runtime); |
| 2403 | // Both a2 and a3 are untagged integers. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2404 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2405 | __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2406 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2407 | __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to. |
| 2408 | __ Subu(a2, a2, a3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2409 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2410 | // Make sure first argument is a string. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2411 | __ lw(v0, MemOperand(sp, kStringOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2412 | __ JumpIfSmi(v0, &runtime); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2413 | __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2414 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2415 | __ And(t0, a1, Operand(kIsNotStringMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2416 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2417 | __ Branch(&runtime, ne, t0, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2418 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2419 | Label single_char; |
| 2420 | __ Branch(&single_char, eq, a2, Operand(1)); |
| 2421 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2422 | // Short-cut for the case of trivial substring. |
| 2423 | Label return_v0; |
| 2424 | // v0: original string |
| 2425 | // a2: result string length |
| 2426 | __ lw(t0, FieldMemOperand(v0, String::kLengthOffset)); |
| 2427 | __ sra(t0, t0, 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2428 | // Return original string. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2429 | __ Branch(&return_v0, eq, a2, Operand(t0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2430 | // Longer than original string's length or negative: unsafe arguments. |
| 2431 | __ Branch(&runtime, hi, a2, Operand(t0)); |
| 2432 | // Shorter than original string's length: an actual substring. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2433 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2434 | // Deal with different string types: update the index if necessary |
| 2435 | // and put the underlying string into t1. |
| 2436 | // v0: original string |
| 2437 | // a1: instance type |
| 2438 | // a2: length |
| 2439 | // a3: from index (untagged) |
| 2440 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 2441 | // If the string is not indirect, it can only be sequential or external. |
| 2442 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 2443 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 2444 | __ And(t0, a1, Operand(kIsIndirectStringMask)); |
| 2445 | __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, t0, Operand(zero_reg)); |
| 2446 | // t0 is used as a scratch register and can be overwritten in either case. |
| 2447 | __ And(t0, a1, Operand(kSlicedNotConsMask)); |
| 2448 | __ Branch(&sliced_string, ne, t0, Operand(zero_reg)); |
| 2449 | // Cons string. Check whether it is flat, then fetch first part. |
| 2450 | __ lw(t1, FieldMemOperand(v0, ConsString::kSecondOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2451 | __ LoadRoot(t0, Heap::kempty_stringRootIndex); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2452 | __ Branch(&runtime, ne, t1, Operand(t0)); |
| 2453 | __ lw(t1, FieldMemOperand(v0, ConsString::kFirstOffset)); |
| 2454 | // Update instance type. |
| 2455 | __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset)); |
| 2456 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
| 2457 | __ jmp(&underlying_unpacked); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2458 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2459 | __ bind(&sliced_string); |
| 2460 | // Sliced string. Fetch parent and correct start index by offset. |
| 2461 | __ lw(t1, FieldMemOperand(v0, SlicedString::kParentOffset)); |
| 2462 | __ lw(t0, FieldMemOperand(v0, SlicedString::kOffsetOffset)); |
| 2463 | __ sra(t0, t0, 1); // Add offset to index. |
| 2464 | __ Addu(a3, a3, t0); |
| 2465 | // Update instance type. |
| 2466 | __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset)); |
| 2467 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
| 2468 | __ jmp(&underlying_unpacked); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2469 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2470 | __ bind(&seq_or_external_string); |
| 2471 | // Sequential or external string. Just move string to the expected register. |
| 2472 | __ mov(t1, v0); |
| 2473 | |
| 2474 | __ bind(&underlying_unpacked); |
| 2475 | |
| 2476 | if (FLAG_string_slices) { |
| 2477 | Label copy_routine; |
| 2478 | // t1: underlying subject string |
| 2479 | // a1: instance type of underlying subject string |
| 2480 | // a2: length |
| 2481 | // a3: adjusted start index (untagged) |
| 2482 | // Short slice. Copy instead of slicing. |
| 2483 | __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength)); |
| 2484 | // Allocate new sliced string. At this point we do not reload the instance |
| 2485 | // type including the string encoding because we simply rely on the info |
| 2486 | // provided by the original string. It does not matter if the original |
| 2487 | // string's encoding is wrong because we always have to recheck encoding of |
| 2488 | // the newly created string's parent anyways due to externalized strings. |
| 2489 | Label two_byte_slice, set_slice_header; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2490 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2491 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 2492 | __ And(t0, a1, Operand(kStringEncodingMask)); |
| 2493 | __ Branch(&two_byte_slice, eq, t0, Operand(zero_reg)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2494 | __ AllocateOneByteSlicedString(v0, a2, t2, t3, &runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2495 | __ jmp(&set_slice_header); |
| 2496 | __ bind(&two_byte_slice); |
| 2497 | __ AllocateTwoByteSlicedString(v0, a2, t2, t3, &runtime); |
| 2498 | __ bind(&set_slice_header); |
| 2499 | __ sll(a3, a3, 1); |
| 2500 | __ sw(t1, FieldMemOperand(v0, SlicedString::kParentOffset)); |
| 2501 | __ sw(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset)); |
| 2502 | __ jmp(&return_v0); |
| 2503 | |
| 2504 | __ bind(©_routine); |
| 2505 | } |
| 2506 | |
| 2507 | // t1: underlying subject string |
| 2508 | // a1: instance type of underlying subject string |
| 2509 | // a2: length |
| 2510 | // a3: adjusted start index (untagged) |
| 2511 | Label two_byte_sequential, sequential_string, allocate_result; |
| 2512 | STATIC_ASSERT(kExternalStringTag != 0); |
| 2513 | STATIC_ASSERT(kSeqStringTag == 0); |
| 2514 | __ And(t0, a1, Operand(kExternalStringTag)); |
| 2515 | __ Branch(&sequential_string, eq, t0, Operand(zero_reg)); |
| 2516 | |
| 2517 | // Handle external string. |
| 2518 | // Rule out short external strings. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2519 | STATIC_ASSERT(kShortExternalStringTag != 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2520 | __ And(t0, a1, Operand(kShortExternalStringTag)); |
| 2521 | __ Branch(&runtime, ne, t0, Operand(zero_reg)); |
| 2522 | __ lw(t1, FieldMemOperand(t1, ExternalString::kResourceDataOffset)); |
| 2523 | // t1 already points to the first character of underlying string. |
| 2524 | __ jmp(&allocate_result); |
| 2525 | |
| 2526 | __ bind(&sequential_string); |
| 2527 | // Locate first character of underlying subject string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2528 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
| 2529 | __ Addu(t1, t1, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2530 | |
| 2531 | __ bind(&allocate_result); |
| 2532 | // Sequential acii string. Allocate the result. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2533 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2534 | __ And(t0, a1, Operand(kStringEncodingMask)); |
| 2535 | __ Branch(&two_byte_sequential, eq, t0, Operand(zero_reg)); |
| 2536 | |
| 2537 | // Allocate and copy the resulting ASCII string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2538 | __ AllocateOneByteString(v0, a2, t0, t2, t3, &runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2539 | |
| 2540 | // Locate first character of substring to copy. |
| 2541 | __ Addu(t1, t1, a3); |
| 2542 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2543 | // Locate first character of result. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2544 | __ Addu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2545 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2546 | // v0: result string |
| 2547 | // a1: first character of result string |
| 2548 | // a2: result string length |
| 2549 | // t1: first character of substring to copy |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2550 | STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 2551 | StringHelper::GenerateCopyCharacters( |
| 2552 | masm, a1, t1, a2, a3, String::ONE_BYTE_ENCODING); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2553 | __ jmp(&return_v0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2554 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2555 | // Allocate and copy the resulting two-byte string. |
| 2556 | __ bind(&two_byte_sequential); |
| 2557 | __ AllocateTwoByteString(v0, a2, t0, t2, t3, &runtime); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2558 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2559 | // Locate first character of substring to copy. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2560 | STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2561 | __ Lsa(t1, t1, a3, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2562 | // Locate first character of result. |
| 2563 | __ Addu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2564 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2565 | // v0: result string. |
| 2566 | // a1: first character of result. |
| 2567 | // a2: result length. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2568 | // t1: first character of substring to copy. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2569 | STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2570 | StringHelper::GenerateCopyCharacters( |
| 2571 | masm, a1, t1, a2, a3, String::TWO_BYTE_ENCODING); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2572 | |
| 2573 | __ bind(&return_v0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2574 | Counters* counters = isolate()->counters(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2575 | __ IncrementCounter(counters->sub_string_native(), 1, a3, t0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2576 | __ DropAndRet(3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2577 | |
| 2578 | // Just jump to runtime to create the sub string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2579 | __ bind(&runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2580 | __ TailCallRuntime(Runtime::kSubString); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2581 | |
| 2582 | __ bind(&single_char); |
| 2583 | // v0: original string |
| 2584 | // a1: instance type |
| 2585 | // a2: length |
| 2586 | // a3: from index (untagged) |
| 2587 | __ SmiTag(a3, a3); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2588 | StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime, |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 2589 | RECEIVER_IS_STRING); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2590 | generator.GenerateFast(masm); |
| 2591 | __ DropAndRet(3); |
| 2592 | generator.SkipSlow(masm, &runtime); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2596 | void ToStringStub::Generate(MacroAssembler* masm) { |
| 2597 | // The ToString stub takes on argument in a0. |
| 2598 | Label is_number; |
| 2599 | __ JumpIfSmi(a0, &is_number); |
| 2600 | |
| 2601 | Label not_string; |
| 2602 | __ GetObjectType(a0, a1, a1); |
| 2603 | // a0: receiver |
| 2604 | // a1: receiver instance type |
| 2605 | __ Branch(¬_string, ge, a1, Operand(FIRST_NONSTRING_TYPE)); |
| 2606 | __ Ret(USE_DELAY_SLOT); |
| 2607 | __ mov(v0, a0); |
| 2608 | __ bind(¬_string); |
| 2609 | |
| 2610 | Label not_heap_number; |
| 2611 | __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE)); |
| 2612 | __ bind(&is_number); |
| 2613 | NumberToStringStub stub(isolate()); |
| 2614 | __ TailCallStub(&stub); |
| 2615 | __ bind(¬_heap_number); |
| 2616 | |
| 2617 | Label not_oddball; |
| 2618 | __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE)); |
| 2619 | __ Ret(USE_DELAY_SLOT); |
| 2620 | __ lw(v0, FieldMemOperand(a0, Oddball::kToStringOffset)); |
| 2621 | __ bind(¬_oddball); |
| 2622 | |
| 2623 | __ push(a0); // Push argument. |
| 2624 | __ TailCallRuntime(Runtime::kToString); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2628 | void ToNameStub::Generate(MacroAssembler* masm) { |
| 2629 | // The ToName stub takes on argument in a0. |
| 2630 | Label is_number; |
| 2631 | __ JumpIfSmi(a0, &is_number); |
| 2632 | |
| 2633 | Label not_name; |
| 2634 | STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE); |
| 2635 | __ GetObjectType(a0, a1, a1); |
| 2636 | // a0: receiver |
| 2637 | // a1: receiver instance type |
| 2638 | __ Branch(¬_name, gt, a1, Operand(LAST_NAME_TYPE)); |
| 2639 | __ Ret(USE_DELAY_SLOT); |
| 2640 | __ mov(v0, a0); |
| 2641 | __ bind(¬_name); |
| 2642 | |
| 2643 | Label not_heap_number; |
| 2644 | __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE)); |
| 2645 | __ bind(&is_number); |
| 2646 | NumberToStringStub stub(isolate()); |
| 2647 | __ TailCallStub(&stub); |
| 2648 | __ bind(¬_heap_number); |
| 2649 | |
| 2650 | Label not_oddball; |
| 2651 | __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE)); |
| 2652 | __ Ret(USE_DELAY_SLOT); |
| 2653 | __ lw(v0, FieldMemOperand(a0, Oddball::kToStringOffset)); |
| 2654 | __ bind(¬_oddball); |
| 2655 | |
| 2656 | __ push(a0); // Push argument. |
| 2657 | __ TailCallRuntime(Runtime::kToName); |
| 2658 | } |
| 2659 | |
| 2660 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2661 | void StringHelper::GenerateFlatOneByteStringEquals( |
| 2662 | MacroAssembler* masm, Register left, Register right, Register scratch1, |
| 2663 | Register scratch2, Register scratch3) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2664 | Register length = scratch1; |
| 2665 | |
| 2666 | // Compare lengths. |
| 2667 | Label strings_not_equal, check_zero_length; |
| 2668 | __ lw(length, FieldMemOperand(left, String::kLengthOffset)); |
| 2669 | __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 2670 | __ Branch(&check_zero_length, eq, length, Operand(scratch2)); |
| 2671 | __ bind(&strings_not_equal); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2672 | DCHECK(is_int16(NOT_EQUAL)); |
| 2673 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2674 | __ li(v0, Operand(Smi::FromInt(NOT_EQUAL))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2675 | |
| 2676 | // Check if the length is zero. |
| 2677 | Label compare_chars; |
| 2678 | __ bind(&check_zero_length); |
| 2679 | STATIC_ASSERT(kSmiTag == 0); |
| 2680 | __ Branch(&compare_chars, ne, length, Operand(zero_reg)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2681 | DCHECK(is_int16(EQUAL)); |
| 2682 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2683 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2684 | |
| 2685 | // Compare characters. |
| 2686 | __ bind(&compare_chars); |
| 2687 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2688 | GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3, |
| 2689 | v0, &strings_not_equal); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2690 | |
| 2691 | // Characters are equal. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2692 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2693 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2697 | void StringHelper::GenerateCompareFlatOneByteStrings( |
| 2698 | MacroAssembler* masm, Register left, Register right, Register scratch1, |
| 2699 | Register scratch2, Register scratch3, Register scratch4) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2700 | Label result_not_equal, compare_lengths; |
| 2701 | // Find minimum length and length difference. |
| 2702 | __ lw(scratch1, FieldMemOperand(left, String::kLengthOffset)); |
| 2703 | __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 2704 | __ Subu(scratch3, scratch1, Operand(scratch2)); |
| 2705 | Register length_delta = scratch3; |
| 2706 | __ slt(scratch4, scratch2, scratch1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2707 | __ Movn(scratch1, scratch2, scratch4); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2708 | Register min_length = scratch1; |
| 2709 | STATIC_ASSERT(kSmiTag == 0); |
| 2710 | __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg)); |
| 2711 | |
| 2712 | // Compare loop. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2713 | GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2, |
| 2714 | scratch4, v0, &result_not_equal); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2715 | |
| 2716 | // Compare lengths - strings up to min-length are equal. |
| 2717 | __ bind(&compare_lengths); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2718 | DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2719 | // Use length_delta as result if it's zero. |
| 2720 | __ mov(scratch2, length_delta); |
| 2721 | __ mov(scratch4, zero_reg); |
| 2722 | __ mov(v0, zero_reg); |
| 2723 | |
| 2724 | __ bind(&result_not_equal); |
| 2725 | // Conditionally update the result based either on length_delta or |
| 2726 | // the last comparion performed in the loop above. |
| 2727 | Label ret; |
| 2728 | __ Branch(&ret, eq, scratch2, Operand(scratch4)); |
| 2729 | __ li(v0, Operand(Smi::FromInt(GREATER))); |
| 2730 | __ Branch(&ret, gt, scratch2, Operand(scratch4)); |
| 2731 | __ li(v0, Operand(Smi::FromInt(LESS))); |
| 2732 | __ bind(&ret); |
| 2733 | __ Ret(); |
| 2734 | } |
| 2735 | |
| 2736 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2737 | void StringHelper::GenerateOneByteCharsCompareLoop( |
| 2738 | MacroAssembler* masm, Register left, Register right, Register length, |
| 2739 | Register scratch1, Register scratch2, Register scratch3, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2740 | Label* chars_not_equal) { |
| 2741 | // Change index to run from -length to -1 by adding length to string |
| 2742 | // start. This means that loop ends when index reaches zero, which |
| 2743 | // doesn't need an additional compare. |
| 2744 | __ SmiUntag(length); |
| 2745 | __ Addu(scratch1, length, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2746 | Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2747 | __ Addu(left, left, Operand(scratch1)); |
| 2748 | __ Addu(right, right, Operand(scratch1)); |
| 2749 | __ Subu(length, zero_reg, length); |
| 2750 | Register index = length; // index = -length; |
| 2751 | |
| 2752 | |
| 2753 | // Compare loop. |
| 2754 | Label loop; |
| 2755 | __ bind(&loop); |
| 2756 | __ Addu(scratch3, left, index); |
| 2757 | __ lbu(scratch1, MemOperand(scratch3)); |
| 2758 | __ Addu(scratch3, right, index); |
| 2759 | __ lbu(scratch2, MemOperand(scratch3)); |
| 2760 | __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2)); |
| 2761 | __ Addu(index, index, 1); |
| 2762 | __ Branch(&loop, ne, index, Operand(zero_reg)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2763 | } |
| 2764 | |
| 2765 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2766 | void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) { |
| 2767 | // ----------- S t a t e ------------- |
| 2768 | // -- a1 : left |
| 2769 | // -- a0 : right |
| 2770 | // -- ra : return address |
| 2771 | // ----------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2772 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2773 | // Load a2 with the allocation site. We stick an undefined dummy value here |
| 2774 | // and replace it with the real allocation site later when we instantiate this |
| 2775 | // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate(). |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 2776 | __ li(a2, isolate()->factory()->undefined_value()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2777 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2778 | // Make sure that we actually patched the allocation site. |
| 2779 | if (FLAG_debug_code) { |
| 2780 | __ And(at, a2, Operand(kSmiTagMask)); |
| 2781 | __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg)); |
| 2782 | __ lw(t0, FieldMemOperand(a2, HeapObject::kMapOffset)); |
| 2783 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 2784 | __ Assert(eq, kExpectedAllocationSite, t0, Operand(at)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2785 | } |
| 2786 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2787 | // Tail call into the stub that handles binary operations with allocation |
| 2788 | // sites. |
| 2789 | BinaryOpWithAllocationSiteStub stub(isolate(), state()); |
| 2790 | __ TailCallStub(&stub); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2791 | } |
| 2792 | |
| 2793 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2794 | void CompareICStub::GenerateBooleans(MacroAssembler* masm) { |
| 2795 | DCHECK_EQ(CompareICState::BOOLEAN, state()); |
| 2796 | Label miss; |
| 2797 | |
| 2798 | __ CheckMap(a1, a2, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK); |
| 2799 | __ CheckMap(a0, a3, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2800 | if (!Token::IsEqualityOp(op())) { |
| 2801 | __ lw(a1, FieldMemOperand(a1, Oddball::kToNumberOffset)); |
| 2802 | __ AssertSmi(a1); |
| 2803 | __ lw(a0, FieldMemOperand(a0, Oddball::kToNumberOffset)); |
| 2804 | __ AssertSmi(a0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2805 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2806 | __ Ret(USE_DELAY_SLOT); |
| 2807 | __ Subu(v0, a1, a0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2808 | |
| 2809 | __ bind(&miss); |
| 2810 | GenerateMiss(masm); |
| 2811 | } |
| 2812 | |
| 2813 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2814 | void CompareICStub::GenerateSmis(MacroAssembler* masm) { |
| 2815 | DCHECK(state() == CompareICState::SMI); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2816 | Label miss; |
| 2817 | __ Or(a2, a1, a0); |
| 2818 | __ JumpIfNotSmi(a2, &miss); |
| 2819 | |
| 2820 | if (GetCondition() == eq) { |
| 2821 | // For equality we do not care about the sign of the result. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2822 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2823 | __ Subu(v0, a0, a1); |
| 2824 | } else { |
| 2825 | // Untag before subtracting to avoid handling overflow. |
| 2826 | __ SmiUntag(a1); |
| 2827 | __ SmiUntag(a0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2828 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2829 | __ Subu(v0, a1, a0); |
| 2830 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2831 | |
| 2832 | __ bind(&miss); |
| 2833 | GenerateMiss(masm); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2837 | void CompareICStub::GenerateNumbers(MacroAssembler* masm) { |
| 2838 | DCHECK(state() == CompareICState::NUMBER); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2839 | |
| 2840 | Label generic_stub; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2841 | Label unordered, maybe_undefined1, maybe_undefined2; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2842 | Label miss; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2843 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2844 | if (left() == CompareICState::SMI) { |
| 2845 | __ JumpIfNotSmi(a1, &miss); |
| 2846 | } |
| 2847 | if (right() == CompareICState::SMI) { |
| 2848 | __ JumpIfNotSmi(a0, &miss); |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 2849 | } |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 2850 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2851 | // Inlining the double comparison and falling back to the general compare |
| 2852 | // stub if NaN is involved. |
| 2853 | // Load left and right operand. |
| 2854 | Label done, left, left_smi, right_smi; |
| 2855 | __ JumpIfSmi(a0, &right_smi); |
| 2856 | __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1, |
| 2857 | DONT_DO_SMI_CHECK); |
| 2858 | __ Subu(a2, a0, Operand(kHeapObjectTag)); |
| 2859 | __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset)); |
| 2860 | __ Branch(&left); |
| 2861 | __ bind(&right_smi); |
| 2862 | __ SmiUntag(a2, a0); // Can't clobber a0 yet. |
| 2863 | FPURegister single_scratch = f6; |
| 2864 | __ mtc1(a2, single_scratch); |
| 2865 | __ cvt_d_w(f2, single_scratch); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2866 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2867 | __ bind(&left); |
| 2868 | __ JumpIfSmi(a1, &left_smi); |
| 2869 | __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2, |
| 2870 | DONT_DO_SMI_CHECK); |
| 2871 | __ Subu(a2, a1, Operand(kHeapObjectTag)); |
| 2872 | __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset)); |
| 2873 | __ Branch(&done); |
| 2874 | __ bind(&left_smi); |
| 2875 | __ SmiUntag(a2, a1); // Can't clobber a1 yet. |
| 2876 | single_scratch = f8; |
| 2877 | __ mtc1(a2, single_scratch); |
| 2878 | __ cvt_d_w(f0, single_scratch); |
| 2879 | |
| 2880 | __ bind(&done); |
| 2881 | |
| 2882 | // Return a result of -1, 0, or 1, or use CompareStub for NaNs. |
| 2883 | Label fpu_eq, fpu_lt; |
| 2884 | // Test if equal, and also handle the unordered/NaN case. |
| 2885 | __ BranchF(&fpu_eq, &unordered, eq, f0, f2); |
| 2886 | |
| 2887 | // Test if less (unordered case is already handled). |
| 2888 | __ BranchF(&fpu_lt, NULL, lt, f0, f2); |
| 2889 | |
| 2890 | // Otherwise it's greater, so just fall thru, and return. |
| 2891 | DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS)); |
| 2892 | __ Ret(USE_DELAY_SLOT); |
| 2893 | __ li(v0, Operand(GREATER)); |
| 2894 | |
| 2895 | __ bind(&fpu_eq); |
| 2896 | __ Ret(USE_DELAY_SLOT); |
| 2897 | __ li(v0, Operand(EQUAL)); |
| 2898 | |
| 2899 | __ bind(&fpu_lt); |
| 2900 | __ Ret(USE_DELAY_SLOT); |
| 2901 | __ li(v0, Operand(LESS)); |
| 2902 | |
| 2903 | __ bind(&unordered); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2904 | __ bind(&generic_stub); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2905 | CompareICStub stub(isolate(), op(), CompareICState::GENERIC, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2906 | CompareICState::GENERIC, CompareICState::GENERIC); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2907 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 2908 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2909 | __ bind(&maybe_undefined1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2910 | if (Token::IsOrderedRelationalCompareOp(op())) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2911 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 2912 | __ Branch(&miss, ne, a0, Operand(at)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2913 | __ JumpIfSmi(a1, &unordered); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2914 | __ GetObjectType(a1, a2, a2); |
| 2915 | __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE)); |
| 2916 | __ jmp(&unordered); |
| 2917 | } |
| 2918 | |
| 2919 | __ bind(&maybe_undefined2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2920 | if (Token::IsOrderedRelationalCompareOp(op())) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2921 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 2922 | __ Branch(&unordered, eq, a1, Operand(at)); |
| 2923 | } |
| 2924 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2925 | __ bind(&miss); |
| 2926 | GenerateMiss(masm); |
| 2927 | } |
| 2928 | |
| 2929 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2930 | void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 2931 | DCHECK(state() == CompareICState::INTERNALIZED_STRING); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2932 | Label miss; |
| 2933 | |
| 2934 | // Registers containing left and right operands respectively. |
| 2935 | Register left = a1; |
| 2936 | Register right = a0; |
| 2937 | Register tmp1 = a2; |
| 2938 | Register tmp2 = a3; |
| 2939 | |
| 2940 | // Check that both operands are heap objects. |
| 2941 | __ JumpIfEitherSmi(left, right, &miss); |
| 2942 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2943 | // Check that both operands are internalized strings. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2944 | __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 2945 | __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 2946 | __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 2947 | __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2948 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 2949 | __ Or(tmp1, tmp1, Operand(tmp2)); |
| 2950 | __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask)); |
| 2951 | __ Branch(&miss, ne, at, Operand(zero_reg)); |
| 2952 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2953 | // Make sure a0 is non-zero. At this point input operands are |
| 2954 | // guaranteed to be non-zero. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2955 | DCHECK(right.is(a0)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2956 | STATIC_ASSERT(EQUAL == 0); |
| 2957 | STATIC_ASSERT(kSmiTag == 0); |
| 2958 | __ mov(v0, right); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2959 | // Internalized strings are compared by identity. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2960 | __ Ret(ne, left, Operand(right)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2961 | DCHECK(is_int16(EQUAL)); |
| 2962 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2963 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2964 | |
| 2965 | __ bind(&miss); |
| 2966 | GenerateMiss(masm); |
| 2967 | } |
| 2968 | |
| 2969 | |
| 2970 | void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 2971 | DCHECK(state() == CompareICState::UNIQUE_NAME); |
| 2972 | DCHECK(GetCondition() == eq); |
| 2973 | Label miss; |
| 2974 | |
| 2975 | // Registers containing left and right operands respectively. |
| 2976 | Register left = a1; |
| 2977 | Register right = a0; |
| 2978 | Register tmp1 = a2; |
| 2979 | Register tmp2 = a3; |
| 2980 | |
| 2981 | // Check that both operands are heap objects. |
| 2982 | __ JumpIfEitherSmi(left, right, &miss); |
| 2983 | |
| 2984 | // Check that both operands are unique names. This leaves the instance |
| 2985 | // types loaded in tmp1 and tmp2. |
| 2986 | __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 2987 | __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 2988 | __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 2989 | __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 2990 | |
| 2991 | __ JumpIfNotUniqueNameInstanceType(tmp1, &miss); |
| 2992 | __ JumpIfNotUniqueNameInstanceType(tmp2, &miss); |
| 2993 | |
| 2994 | // Use a0 as result |
| 2995 | __ mov(v0, a0); |
| 2996 | |
| 2997 | // Unique names are compared by identity. |
| 2998 | Label done; |
| 2999 | __ Branch(&done, ne, left, Operand(right)); |
| 3000 | // Make sure a0 is non-zero. At this point input operands are |
| 3001 | // guaranteed to be non-zero. |
| 3002 | DCHECK(right.is(a0)); |
| 3003 | STATIC_ASSERT(EQUAL == 0); |
| 3004 | STATIC_ASSERT(kSmiTag == 0); |
| 3005 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
| 3006 | __ bind(&done); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3007 | __ Ret(); |
| 3008 | |
| 3009 | __ bind(&miss); |
| 3010 | GenerateMiss(masm); |
| 3011 | } |
| 3012 | |
| 3013 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3014 | void CompareICStub::GenerateStrings(MacroAssembler* masm) { |
| 3015 | DCHECK(state() == CompareICState::STRING); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3016 | Label miss; |
| 3017 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3018 | bool equality = Token::IsEqualityOp(op()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3019 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3020 | // Registers containing left and right operands respectively. |
| 3021 | Register left = a1; |
| 3022 | Register right = a0; |
| 3023 | Register tmp1 = a2; |
| 3024 | Register tmp2 = a3; |
| 3025 | Register tmp3 = t0; |
| 3026 | Register tmp4 = t1; |
| 3027 | Register tmp5 = t2; |
| 3028 | |
| 3029 | // Check that both operands are heap objects. |
| 3030 | __ JumpIfEitherSmi(left, right, &miss); |
| 3031 | |
| 3032 | // Check that both operands are strings. This leaves the instance |
| 3033 | // types loaded in tmp1 and tmp2. |
| 3034 | __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 3035 | __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 3036 | __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3037 | __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 3038 | STATIC_ASSERT(kNotStringTag != 0); |
| 3039 | __ Or(tmp3, tmp1, tmp2); |
| 3040 | __ And(tmp5, tmp3, Operand(kIsNotStringMask)); |
| 3041 | __ Branch(&miss, ne, tmp5, Operand(zero_reg)); |
| 3042 | |
| 3043 | // Fast check for identical strings. |
| 3044 | Label left_ne_right; |
| 3045 | STATIC_ASSERT(EQUAL == 0); |
| 3046 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3047 | __ Branch(&left_ne_right, ne, left, Operand(right)); |
| 3048 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3049 | __ mov(v0, zero_reg); // In the delay slot. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3050 | __ bind(&left_ne_right); |
| 3051 | |
| 3052 | // Handle not identical strings. |
| 3053 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3054 | // Check that both strings are internalized strings. If they are, we're done |
| 3055 | // because we already know they are not identical. We know they are both |
| 3056 | // strings. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3057 | if (equality) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3058 | DCHECK(GetCondition() == eq); |
| 3059 | STATIC_ASSERT(kInternalizedTag == 0); |
| 3060 | __ Or(tmp3, tmp1, Operand(tmp2)); |
| 3061 | __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3062 | Label is_symbol; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3063 | __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3064 | // Make sure a0 is non-zero. At this point input operands are |
| 3065 | // guaranteed to be non-zero. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3066 | DCHECK(right.is(a0)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3067 | __ Ret(USE_DELAY_SLOT); |
| 3068 | __ mov(v0, a0); // In the delay slot. |
| 3069 | __ bind(&is_symbol); |
| 3070 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3071 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3072 | // Check that both strings are sequential one-byte. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3073 | Label runtime; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3074 | __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4, |
| 3075 | &runtime); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3076 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3077 | // Compare flat one-byte strings. Returns when done. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3078 | if (equality) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3079 | StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2, |
| 3080 | tmp3); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3081 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3082 | StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1, |
| 3083 | tmp2, tmp3, tmp4); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3084 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3085 | |
| 3086 | // Handle more complex cases in runtime. |
| 3087 | __ bind(&runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3088 | if (equality) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 3089 | { |
| 3090 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3091 | __ Push(left, right); |
| 3092 | __ CallRuntime(Runtime::kStringEqual); |
| 3093 | } |
| 3094 | __ LoadRoot(a0, Heap::kTrueValueRootIndex); |
| 3095 | __ Ret(USE_DELAY_SLOT); |
| 3096 | __ Subu(v0, v0, a0); // In delay slot. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3097 | } else { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 3098 | __ Push(left, right); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3099 | __ TailCallRuntime(Runtime::kStringCompare); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3100 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3101 | |
| 3102 | __ bind(&miss); |
| 3103 | GenerateMiss(masm); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3107 | void CompareICStub::GenerateReceivers(MacroAssembler* masm) { |
| 3108 | DCHECK_EQ(CompareICState::RECEIVER, state()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3109 | Label miss; |
| 3110 | __ And(a2, a1, Operand(a0)); |
| 3111 | __ JumpIfSmi(a2, &miss); |
| 3112 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3113 | STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3114 | __ GetObjectType(a0, a2, a2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3115 | __ Branch(&miss, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3116 | __ GetObjectType(a1, a2, a2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3117 | __ Branch(&miss, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3118 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3119 | DCHECK_EQ(eq, GetCondition()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3120 | __ Ret(USE_DELAY_SLOT); |
| 3121 | __ subu(v0, a0, a1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3122 | |
| 3123 | __ bind(&miss); |
| 3124 | GenerateMiss(masm); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3125 | } |
| 3126 | |
| 3127 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3128 | void CompareICStub::GenerateKnownReceivers(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3129 | Label miss; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3130 | Handle<WeakCell> cell = Map::WeakCellForMap(known_map_); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3131 | __ And(a2, a1, a0); |
| 3132 | __ JumpIfSmi(a2, &miss); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3133 | __ GetWeakValue(t0, cell); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3134 | __ lw(a2, FieldMemOperand(a0, HeapObject::kMapOffset)); |
| 3135 | __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3136 | __ Branch(&miss, ne, a2, Operand(t0)); |
| 3137 | __ Branch(&miss, ne, a3, Operand(t0)); |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 3138 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3139 | if (Token::IsEqualityOp(op())) { |
| 3140 | __ Ret(USE_DELAY_SLOT); |
| 3141 | __ subu(v0, a0, a1); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3142 | } else { |
| 3143 | if (op() == Token::LT || op() == Token::LTE) { |
| 3144 | __ li(a2, Operand(Smi::FromInt(GREATER))); |
| 3145 | } else { |
| 3146 | __ li(a2, Operand(Smi::FromInt(LESS))); |
| 3147 | } |
| 3148 | __ Push(a1, a0, a2); |
| 3149 | __ TailCallRuntime(Runtime::kCompare); |
| 3150 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3151 | |
| 3152 | __ bind(&miss); |
| 3153 | GenerateMiss(masm); |
| 3154 | } |
| 3155 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3156 | |
| 3157 | void CompareICStub::GenerateMiss(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3158 | { |
| 3159 | // Call the runtime system in a fresh internal frame. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3160 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3161 | __ Push(a1, a0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3162 | __ Push(ra, a1, a0); |
| 3163 | __ li(t0, Operand(Smi::FromInt(op()))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3164 | __ addiu(sp, sp, -kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3165 | __ CallRuntime(Runtime::kCompareIC_Miss, 3, kDontSaveFPRegs, |
| 3166 | USE_DELAY_SLOT); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3167 | __ sw(t0, MemOperand(sp)); // In the delay slot. |
| 3168 | // Compute the entry point of the rewritten stub. |
| 3169 | __ Addu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3170 | // Restore registers. |
| 3171 | __ Pop(a1, a0, ra); |
| 3172 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3173 | __ Jump(a2); |
| 3174 | } |
| 3175 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3176 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3177 | void DirectCEntryStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3178 | // Make place for arguments to fit C calling convention. Most of the callers |
| 3179 | // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame |
| 3180 | // so they handle stack restoring and we don't have to do that here. |
| 3181 | // Any caller of DirectCEntryStub::GenerateCall must take care of dropping |
| 3182 | // kCArgsSlotsSize stack space after the call. |
| 3183 | __ Subu(sp, sp, Operand(kCArgsSlotsSize)); |
| 3184 | // Place the return address on the stack, making the call |
| 3185 | // GC safe. The RegExp backend also relies on this. |
| 3186 | __ sw(ra, MemOperand(sp, kCArgsSlotsSize)); |
| 3187 | __ Call(t9); // Call the C++ function. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3188 | __ lw(t9, MemOperand(sp, kCArgsSlotsSize)); |
| 3189 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3190 | if (FLAG_debug_code && FLAG_enable_slow_asserts) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3191 | // In case of an error the return address may point to a memory area |
| 3192 | // filled with kZapValue by the GC. |
| 3193 | // Dereference the address and check for this. |
| 3194 | __ lw(t0, MemOperand(t9)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3195 | __ Assert(ne, kReceivedInvalidReturnAddress, t0, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3196 | Operand(reinterpret_cast<uint32_t>(kZapValue))); |
| 3197 | } |
| 3198 | __ Jump(t9); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3199 | } |
| 3200 | |
| 3201 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3202 | void DirectCEntryStub::GenerateCall(MacroAssembler* masm, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3203 | Register target) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3204 | intptr_t loc = |
| 3205 | reinterpret_cast<intptr_t>(GetCode().location()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3206 | __ Move(t9, target); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3207 | __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE); |
| 3208 | __ Call(at); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3212 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 3213 | Label* miss, |
| 3214 | Label* done, |
| 3215 | Register receiver, |
| 3216 | Register properties, |
| 3217 | Handle<Name> name, |
| 3218 | Register scratch0) { |
| 3219 | DCHECK(name->IsUniqueName()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3220 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3221 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 3222 | // undefined value), it guarantees the hash table doesn't contain the |
| 3223 | // property. It's true even if some slots represent deleted properties |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3224 | // (their names are the hole value). |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3225 | for (int i = 0; i < kInlinedProbes; i++) { |
| 3226 | // scratch0 points to properties hash. |
| 3227 | // Compute the masked index: (hash + i + i * i) & mask. |
| 3228 | Register index = scratch0; |
| 3229 | // Capacity is smi 2^n. |
| 3230 | __ lw(index, FieldMemOperand(properties, kCapacityOffset)); |
| 3231 | __ Subu(index, index, Operand(1)); |
| 3232 | __ And(index, index, Operand( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3233 | Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i)))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3234 | |
| 3235 | // Scale the index by multiplying by the entry size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3236 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3237 | __ Lsa(index, index, index, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3238 | |
| 3239 | Register entity_name = scratch0; |
| 3240 | // Having undefined at this place means the name is not contained. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3241 | STATIC_ASSERT(kSmiTagSize == 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3242 | Register tmp = properties; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3243 | __ Lsa(tmp, properties, index, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3244 | __ lw(entity_name, FieldMemOperand(tmp, kElementsStartOffset)); |
| 3245 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3246 | DCHECK(!tmp.is(entity_name)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3247 | __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex); |
| 3248 | __ Branch(done, eq, entity_name, Operand(tmp)); |
| 3249 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3250 | // Load the hole ready for use below: |
| 3251 | __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3252 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3253 | // Stop if found the property. |
| 3254 | __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3255 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3256 | Label good; |
| 3257 | __ Branch(&good, eq, entity_name, Operand(tmp)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3258 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3259 | // Check if the entry name is not a unique name. |
| 3260 | __ lw(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset)); |
| 3261 | __ lbu(entity_name, |
| 3262 | FieldMemOperand(entity_name, Map::kInstanceTypeOffset)); |
| 3263 | __ JumpIfNotUniqueNameInstanceType(entity_name, miss); |
| 3264 | __ bind(&good); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3265 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3266 | // Restore the properties. |
| 3267 | __ lw(properties, |
| 3268 | FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3269 | } |
| 3270 | |
| 3271 | const int spill_mask = |
| 3272 | (ra.bit() | t2.bit() | t1.bit() | t0.bit() | a3.bit() | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3273 | a2.bit() | a1.bit() | a0.bit() | v0.bit()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3274 | |
| 3275 | __ MultiPush(spill_mask); |
| 3276 | __ lw(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3277 | __ li(a1, Operand(Handle<Name>(name))); |
| 3278 | NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3279 | __ CallStub(&stub); |
| 3280 | __ mov(at, v0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3281 | __ MultiPop(spill_mask); |
| 3282 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3283 | __ Branch(done, eq, at, Operand(zero_reg)); |
| 3284 | __ Branch(miss, ne, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3285 | } |
| 3286 | |
| 3287 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3288 | // Probe the name dictionary in the |elements| register. Jump to the |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3289 | // |done| label if a property with the given name is found. Jump to |
| 3290 | // the |miss| label otherwise. |
| 3291 | // If lookup was successful |scratch2| will be equal to elements + 4 * index. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3292 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 3293 | Label* miss, |
| 3294 | Label* done, |
| 3295 | Register elements, |
| 3296 | Register name, |
| 3297 | Register scratch1, |
| 3298 | Register scratch2) { |
| 3299 | DCHECK(!elements.is(scratch1)); |
| 3300 | DCHECK(!elements.is(scratch2)); |
| 3301 | DCHECK(!name.is(scratch1)); |
| 3302 | DCHECK(!name.is(scratch2)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3303 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3304 | __ AssertName(name); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3305 | |
| 3306 | // Compute the capacity mask. |
| 3307 | __ lw(scratch1, FieldMemOperand(elements, kCapacityOffset)); |
| 3308 | __ sra(scratch1, scratch1, kSmiTagSize); // convert smi to int |
| 3309 | __ Subu(scratch1, scratch1, Operand(1)); |
| 3310 | |
| 3311 | // Generate an unrolled loop that performs a few probes before |
| 3312 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 3313 | // cover ~93% of loads from dictionaries. |
| 3314 | for (int i = 0; i < kInlinedProbes; i++) { |
| 3315 | // Compute the masked index: (hash + i + i * i) & mask. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3316 | __ lw(scratch2, FieldMemOperand(name, Name::kHashFieldOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3317 | if (i > 0) { |
| 3318 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 3319 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 3320 | // shifted in the following and instruction. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3321 | DCHECK(NameDictionary::GetProbeOffset(i) < |
| 3322 | 1 << (32 - Name::kHashFieldOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3323 | __ Addu(scratch2, scratch2, Operand( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3324 | NameDictionary::GetProbeOffset(i) << Name::kHashShift)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3325 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3326 | __ srl(scratch2, scratch2, Name::kHashShift); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3327 | __ And(scratch2, scratch1, scratch2); |
| 3328 | |
| 3329 | // Scale the index by multiplying by the element size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3330 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3331 | // scratch2 = scratch2 * 3. |
| 3332 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3333 | __ Lsa(scratch2, scratch2, scratch2, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3334 | |
| 3335 | // Check if the key is identical to the name. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3336 | __ Lsa(scratch2, elements, scratch2, 2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3337 | __ lw(at, FieldMemOperand(scratch2, kElementsStartOffset)); |
| 3338 | __ Branch(done, eq, name, Operand(at)); |
| 3339 | } |
| 3340 | |
| 3341 | const int spill_mask = |
| 3342 | (ra.bit() | t2.bit() | t1.bit() | t0.bit() | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3343 | a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) & |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3344 | ~(scratch1.bit() | scratch2.bit()); |
| 3345 | |
| 3346 | __ MultiPush(spill_mask); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3347 | if (name.is(a0)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3348 | DCHECK(!elements.is(a1)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3349 | __ Move(a1, name); |
| 3350 | __ Move(a0, elements); |
| 3351 | } else { |
| 3352 | __ Move(a0, elements); |
| 3353 | __ Move(a1, name); |
| 3354 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3355 | NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3356 | __ CallStub(&stub); |
| 3357 | __ mov(scratch2, a2); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3358 | __ mov(at, v0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3359 | __ MultiPop(spill_mask); |
| 3360 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3361 | __ Branch(done, ne, at, Operand(zero_reg)); |
| 3362 | __ Branch(miss, eq, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3363 | } |
| 3364 | |
| 3365 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3366 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3367 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 3368 | // we cannot call anything that could cause a GC from this stub. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3369 | // Registers: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3370 | // result: NameDictionary to probe |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3371 | // a1: key |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3372 | // dictionary: NameDictionary to probe. |
| 3373 | // index: will hold an index of entry if lookup is successful. |
| 3374 | // might alias with result_. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3375 | // Returns: |
| 3376 | // result_ is zero if lookup failed, non zero otherwise. |
| 3377 | |
| 3378 | Register result = v0; |
| 3379 | Register dictionary = a0; |
| 3380 | Register key = a1; |
| 3381 | Register index = a2; |
| 3382 | Register mask = a3; |
| 3383 | Register hash = t0; |
| 3384 | Register undefined = t1; |
| 3385 | Register entry_key = t2; |
| 3386 | |
| 3387 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 3388 | |
| 3389 | __ lw(mask, FieldMemOperand(dictionary, kCapacityOffset)); |
| 3390 | __ sra(mask, mask, kSmiTagSize); |
| 3391 | __ Subu(mask, mask, Operand(1)); |
| 3392 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3393 | __ lw(hash, FieldMemOperand(key, Name::kHashFieldOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3394 | |
| 3395 | __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex); |
| 3396 | |
| 3397 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 3398 | // Compute the masked index: (hash + i + i * i) & mask. |
| 3399 | // Capacity is smi 2^n. |
| 3400 | if (i > 0) { |
| 3401 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 3402 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 3403 | // shifted in the following and instruction. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3404 | DCHECK(NameDictionary::GetProbeOffset(i) < |
| 3405 | 1 << (32 - Name::kHashFieldOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3406 | __ Addu(index, hash, Operand( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3407 | NameDictionary::GetProbeOffset(i) << Name::kHashShift)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3408 | } else { |
| 3409 | __ mov(index, hash); |
| 3410 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3411 | __ srl(index, index, Name::kHashShift); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3412 | __ And(index, mask, index); |
| 3413 | |
| 3414 | // Scale the index by multiplying by the entry size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3415 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3416 | // index *= 3. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3417 | __ Lsa(index, index, index, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3418 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3419 | STATIC_ASSERT(kSmiTagSize == 1); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3420 | __ Lsa(index, dictionary, index, 2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3421 | __ lw(entry_key, FieldMemOperand(index, kElementsStartOffset)); |
| 3422 | |
| 3423 | // Having undefined at this place means the name is not contained. |
| 3424 | __ Branch(¬_in_dictionary, eq, entry_key, Operand(undefined)); |
| 3425 | |
| 3426 | // Stop if found the property. |
| 3427 | __ Branch(&in_dictionary, eq, entry_key, Operand(key)); |
| 3428 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3429 | if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) { |
| 3430 | // Check if the entry name is not a unique name. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3431 | __ lw(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset)); |
| 3432 | __ lbu(entry_key, |
| 3433 | FieldMemOperand(entry_key, Map::kInstanceTypeOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3434 | __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3435 | } |
| 3436 | } |
| 3437 | |
| 3438 | __ bind(&maybe_in_dictionary); |
| 3439 | // If we are doing negative lookup then probing failure should be |
| 3440 | // treated as a lookup success. For positive lookup probing failure |
| 3441 | // should be treated as lookup failure. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3442 | if (mode() == POSITIVE_LOOKUP) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3443 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3444 | __ mov(result, zero_reg); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3445 | } |
| 3446 | |
| 3447 | __ bind(&in_dictionary); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3448 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3449 | __ li(result, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3450 | |
| 3451 | __ bind(¬_in_dictionary); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3452 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3453 | __ mov(result, zero_reg); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3454 | } |
| 3455 | |
| 3456 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3457 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 3458 | Isolate* isolate) { |
| 3459 | StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs); |
| 3460 | stub1.GetCode(); |
| 3461 | // Hydrogen code stubs need stub2 at snapshot time. |
| 3462 | StoreBufferOverflowStub stub2(isolate, kSaveFPRegs); |
| 3463 | stub2.GetCode(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3464 | } |
| 3465 | |
| 3466 | |
| 3467 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 3468 | // the value has just been written into the object, now this stub makes sure |
| 3469 | // we keep the GC informed. The word in the object where the value has been |
| 3470 | // written is in the address register. |
| 3471 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 3472 | Label skip_to_incremental_noncompacting; |
| 3473 | Label skip_to_incremental_compacting; |
| 3474 | |
| 3475 | // The first two branch+nop instructions are generated with labels so as to |
| 3476 | // get the offset fixed up correctly by the bind(Label*) call. We patch it |
| 3477 | // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this |
| 3478 | // position) and the "beq zero_reg, zero_reg, ..." when we start and stop |
| 3479 | // incremental heap marking. |
| 3480 | // See RecordWriteStub::Patch for details. |
| 3481 | __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting); |
| 3482 | __ nop(); |
| 3483 | __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting); |
| 3484 | __ nop(); |
| 3485 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3486 | if (remembered_set_action() == EMIT_REMEMBERED_SET) { |
| 3487 | __ RememberedSetHelper(object(), |
| 3488 | address(), |
| 3489 | value(), |
| 3490 | save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3491 | MacroAssembler::kReturnAtEnd); |
| 3492 | } |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3493 | __ Ret(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3494 | |
| 3495 | __ bind(&skip_to_incremental_noncompacting); |
| 3496 | GenerateIncremental(masm, INCREMENTAL); |
| 3497 | |
| 3498 | __ bind(&skip_to_incremental_compacting); |
| 3499 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 3500 | |
| 3501 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 3502 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 3503 | |
| 3504 | PatchBranchIntoNop(masm, 0); |
| 3505 | PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize); |
| 3506 | } |
| 3507 | |
| 3508 | |
| 3509 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 3510 | regs_.Save(masm); |
| 3511 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3512 | if (remembered_set_action() == EMIT_REMEMBERED_SET) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3513 | Label dont_need_remembered_set; |
| 3514 | |
| 3515 | __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0)); |
| 3516 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 3517 | regs_.scratch0(), |
| 3518 | &dont_need_remembered_set); |
| 3519 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3520 | __ JumpIfInNewSpace(regs_.object(), regs_.scratch0(), |
| 3521 | &dont_need_remembered_set); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3522 | |
| 3523 | // First notify the incremental marker if necessary, then update the |
| 3524 | // remembered set. |
| 3525 | CheckNeedsToInformIncrementalMarker( |
| 3526 | masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3527 | InformIncrementalMarker(masm); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3528 | regs_.Restore(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3529 | __ RememberedSetHelper(object(), |
| 3530 | address(), |
| 3531 | value(), |
| 3532 | save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3533 | MacroAssembler::kReturnAtEnd); |
| 3534 | |
| 3535 | __ bind(&dont_need_remembered_set); |
| 3536 | } |
| 3537 | |
| 3538 | CheckNeedsToInformIncrementalMarker( |
| 3539 | masm, kReturnOnNoNeedToInformIncrementalMarker, mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3540 | InformIncrementalMarker(masm); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3541 | regs_.Restore(masm); |
| 3542 | __ Ret(); |
| 3543 | } |
| 3544 | |
| 3545 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3546 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) { |
| 3547 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3548 | int argument_count = 3; |
| 3549 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 3550 | Register address = |
| 3551 | a0.is(regs_.address()) ? regs_.scratch0() : regs_.address(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3552 | DCHECK(!address.is(regs_.object())); |
| 3553 | DCHECK(!address.is(a0)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3554 | __ Move(address, regs_.address()); |
| 3555 | __ Move(a0, regs_.object()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3556 | __ Move(a1, address); |
| 3557 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3558 | |
| 3559 | AllowExternalCallThatCantCauseGC scope(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3560 | __ CallCFunction( |
| 3561 | ExternalReference::incremental_marking_record_write_function(isolate()), |
| 3562 | argument_count); |
| 3563 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | |
| 3567 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 3568 | MacroAssembler* masm, |
| 3569 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 3570 | Mode mode) { |
| 3571 | Label on_black; |
| 3572 | Label need_incremental; |
| 3573 | Label need_incremental_pop_scratch; |
| 3574 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3575 | __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask)); |
| 3576 | __ lw(regs_.scratch1(), |
| 3577 | MemOperand(regs_.scratch0(), |
| 3578 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 3579 | __ Subu(regs_.scratch1(), regs_.scratch1(), Operand(1)); |
| 3580 | __ sw(regs_.scratch1(), |
| 3581 | MemOperand(regs_.scratch0(), |
| 3582 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 3583 | __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg)); |
| 3584 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3585 | // Let's look at the color of the object: If it is not black we don't have |
| 3586 | // to inform the incremental marker. |
| 3587 | __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black); |
| 3588 | |
| 3589 | regs_.Restore(masm); |
| 3590 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3591 | __ RememberedSetHelper(object(), |
| 3592 | address(), |
| 3593 | value(), |
| 3594 | save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3595 | MacroAssembler::kReturnAtEnd); |
| 3596 | } else { |
| 3597 | __ Ret(); |
| 3598 | } |
| 3599 | |
| 3600 | __ bind(&on_black); |
| 3601 | |
| 3602 | // Get the value from the slot. |
| 3603 | __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0)); |
| 3604 | |
| 3605 | if (mode == INCREMENTAL_COMPACTION) { |
| 3606 | Label ensure_not_white; |
| 3607 | |
| 3608 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 3609 | regs_.scratch1(), // Scratch. |
| 3610 | MemoryChunk::kEvacuationCandidateMask, |
| 3611 | eq, |
| 3612 | &ensure_not_white); |
| 3613 | |
| 3614 | __ CheckPageFlag(regs_.object(), |
| 3615 | regs_.scratch1(), // Scratch. |
| 3616 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 3617 | eq, |
| 3618 | &need_incremental); |
| 3619 | |
| 3620 | __ bind(&ensure_not_white); |
| 3621 | } |
| 3622 | |
| 3623 | // We need extra registers for this, so we push the object and the address |
| 3624 | // register temporarily. |
| 3625 | __ Push(regs_.object(), regs_.address()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3626 | __ JumpIfWhite(regs_.scratch0(), // The value. |
| 3627 | regs_.scratch1(), // Scratch. |
| 3628 | regs_.object(), // Scratch. |
| 3629 | regs_.address(), // Scratch. |
| 3630 | &need_incremental_pop_scratch); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3631 | __ Pop(regs_.object(), regs_.address()); |
| 3632 | |
| 3633 | regs_.Restore(masm); |
| 3634 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3635 | __ RememberedSetHelper(object(), |
| 3636 | address(), |
| 3637 | value(), |
| 3638 | save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3639 | MacroAssembler::kReturnAtEnd); |
| 3640 | } else { |
| 3641 | __ Ret(); |
| 3642 | } |
| 3643 | |
| 3644 | __ bind(&need_incremental_pop_scratch); |
| 3645 | __ Pop(regs_.object(), regs_.address()); |
| 3646 | |
| 3647 | __ bind(&need_incremental); |
| 3648 | |
| 3649 | // Fall through when we need to inform the incremental marker. |
| 3650 | } |
| 3651 | |
| 3652 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3653 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
| 3654 | CEntryStub ces(isolate(), 1, kSaveFPRegs); |
| 3655 | __ Call(ces.GetCode(), RelocInfo::CODE_TARGET); |
| 3656 | int parameter_count_offset = |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 3657 | StubFailureTrampolineFrameConstants::kArgumentsLengthOffset; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3658 | __ lw(a1, MemOperand(fp, parameter_count_offset)); |
| 3659 | if (function_mode() == JS_FUNCTION_STUB_MODE) { |
| 3660 | __ Addu(a1, a1, Operand(1)); |
| 3661 | } |
| 3662 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 3663 | __ sll(a1, a1, kPointerSizeLog2); |
| 3664 | __ Ret(USE_DELAY_SLOT); |
| 3665 | __ Addu(sp, sp, a1); |
| 3666 | } |
| 3667 | |
| 3668 | |
| 3669 | void LoadICTrampolineStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3670 | __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister()); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 3671 | LoadICStub stub(isolate()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3672 | stub.GenerateForTrampoline(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | |
| 3676 | void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3677 | __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister()); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 3678 | KeyedLoadICStub stub(isolate()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3679 | stub.GenerateForTrampoline(masm); |
| 3680 | } |
| 3681 | |
| 3682 | |
| 3683 | void CallICTrampolineStub::Generate(MacroAssembler* masm) { |
| 3684 | __ EmitLoadTypeFeedbackVector(a2); |
| 3685 | CallICStub stub(isolate(), state()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3686 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 3687 | } |
| 3688 | |
| 3689 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3690 | void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); } |
| 3691 | |
| 3692 | |
| 3693 | void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 3694 | GenerateImpl(masm, true); |
| 3695 | } |
| 3696 | |
| 3697 | |
| 3698 | static void HandleArrayCases(MacroAssembler* masm, Register feedback, |
| 3699 | Register receiver_map, Register scratch1, |
| 3700 | Register scratch2, bool is_polymorphic, |
| 3701 | Label* miss) { |
| 3702 | // feedback initially contains the feedback array |
| 3703 | Label next_loop, prepare_next; |
| 3704 | Label start_polymorphic; |
| 3705 | |
| 3706 | Register cached_map = scratch1; |
| 3707 | |
| 3708 | __ lw(cached_map, |
| 3709 | FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0))); |
| 3710 | __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset)); |
| 3711 | __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map)); |
| 3712 | // found, now call handler. |
| 3713 | Register handler = feedback; |
| 3714 | __ lw(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1))); |
| 3715 | __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3716 | __ Jump(t9); |
| 3717 | |
| 3718 | |
| 3719 | Register length = scratch2; |
| 3720 | __ bind(&start_polymorphic); |
| 3721 | __ lw(length, FieldMemOperand(feedback, FixedArray::kLengthOffset)); |
| 3722 | if (!is_polymorphic) { |
| 3723 | // If the IC could be monomorphic we have to make sure we don't go past the |
| 3724 | // end of the feedback array. |
| 3725 | __ Branch(miss, eq, length, Operand(Smi::FromInt(2))); |
| 3726 | } |
| 3727 | |
| 3728 | Register too_far = length; |
| 3729 | Register pointer_reg = feedback; |
| 3730 | |
| 3731 | // +-----+------+------+-----+-----+ ... ----+ |
| 3732 | // | map | len | wm0 | h0 | wm1 | hN | |
| 3733 | // +-----+------+------+-----+-----+ ... ----+ |
| 3734 | // 0 1 2 len-1 |
| 3735 | // ^ ^ |
| 3736 | // | | |
| 3737 | // pointer_reg too_far |
| 3738 | // aka feedback scratch2 |
| 3739 | // also need receiver_map |
| 3740 | // use cached_map (scratch1) to look in the weak map values. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3741 | __ Lsa(too_far, feedback, length, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3742 | __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 3743 | __ Addu(pointer_reg, feedback, |
| 3744 | Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag)); |
| 3745 | |
| 3746 | __ bind(&next_loop); |
| 3747 | __ lw(cached_map, MemOperand(pointer_reg)); |
| 3748 | __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset)); |
| 3749 | __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map)); |
| 3750 | __ lw(handler, MemOperand(pointer_reg, kPointerSize)); |
| 3751 | __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3752 | __ Jump(t9); |
| 3753 | |
| 3754 | __ bind(&prepare_next); |
| 3755 | __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 2)); |
| 3756 | __ Branch(&next_loop, lt, pointer_reg, Operand(too_far)); |
| 3757 | |
| 3758 | // We exhausted our array of map handler pairs. |
| 3759 | __ jmp(miss); |
| 3760 | } |
| 3761 | |
| 3762 | |
| 3763 | static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver, |
| 3764 | Register receiver_map, Register feedback, |
| 3765 | Register vector, Register slot, |
| 3766 | Register scratch, Label* compare_map, |
| 3767 | Label* load_smi_map, Label* try_array) { |
| 3768 | __ JumpIfSmi(receiver, load_smi_map); |
| 3769 | __ lw(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 3770 | __ bind(compare_map); |
| 3771 | Register cached_map = scratch; |
| 3772 | // Move the weak map into the weak_cell register. |
| 3773 | __ lw(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset)); |
| 3774 | __ Branch(try_array, ne, cached_map, Operand(receiver_map)); |
| 3775 | Register handler = feedback; |
| 3776 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3777 | __ Lsa(handler, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3778 | __ lw(handler, |
| 3779 | FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize)); |
| 3780 | __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3781 | __ Jump(t9); |
| 3782 | } |
| 3783 | |
| 3784 | |
| 3785 | void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 3786 | Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1 |
| 3787 | Register name = LoadWithVectorDescriptor::NameRegister(); // a2 |
| 3788 | Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3 |
| 3789 | Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0 |
| 3790 | Register feedback = t0; |
| 3791 | Register receiver_map = t1; |
| 3792 | Register scratch1 = t4; |
| 3793 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3794 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3795 | __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 3796 | |
| 3797 | // Try to quickly handle the monomorphic case without knowing for sure |
| 3798 | // if we have a weak cell in feedback. We do know it's safe to look |
| 3799 | // at WeakCell::kValueOffset. |
| 3800 | Label try_array, load_smi_map, compare_map; |
| 3801 | Label not_array, miss; |
| 3802 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 3803 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 3804 | |
| 3805 | // Is it a fixed array? |
| 3806 | __ bind(&try_array); |
| 3807 | __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 3808 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 3809 | __ Branch(¬_array, ne, at, Operand(scratch1)); |
| 3810 | HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, true, &miss); |
| 3811 | |
| 3812 | __ bind(¬_array); |
| 3813 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 3814 | __ Branch(&miss, ne, at, Operand(feedback)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 3815 | Code::Flags code_flags = |
| 3816 | Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(Code::LOAD_IC)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3817 | masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags, |
| 3818 | receiver, name, feedback, |
| 3819 | receiver_map, scratch1, t5); |
| 3820 | |
| 3821 | __ bind(&miss); |
| 3822 | LoadIC::GenerateMiss(masm); |
| 3823 | |
| 3824 | __ bind(&load_smi_map); |
| 3825 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 3826 | __ jmp(&compare_map); |
| 3827 | } |
| 3828 | |
| 3829 | |
| 3830 | void KeyedLoadICStub::Generate(MacroAssembler* masm) { |
| 3831 | GenerateImpl(masm, false); |
| 3832 | } |
| 3833 | |
| 3834 | |
| 3835 | void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 3836 | GenerateImpl(masm, true); |
| 3837 | } |
| 3838 | |
| 3839 | |
| 3840 | void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 3841 | Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1 |
| 3842 | Register key = LoadWithVectorDescriptor::NameRegister(); // a2 |
| 3843 | Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3 |
| 3844 | Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0 |
| 3845 | Register feedback = t0; |
| 3846 | Register receiver_map = t1; |
| 3847 | Register scratch1 = t4; |
| 3848 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3849 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3850 | __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 3851 | |
| 3852 | // Try to quickly handle the monomorphic case without knowing for sure |
| 3853 | // if we have a weak cell in feedback. We do know it's safe to look |
| 3854 | // at WeakCell::kValueOffset. |
| 3855 | Label try_array, load_smi_map, compare_map; |
| 3856 | Label not_array, miss; |
| 3857 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 3858 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 3859 | |
| 3860 | __ bind(&try_array); |
| 3861 | // Is it a fixed array? |
| 3862 | __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 3863 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 3864 | __ Branch(¬_array, ne, at, Operand(scratch1)); |
| 3865 | // We have a polymorphic element handler. |
| 3866 | __ JumpIfNotSmi(key, &miss); |
| 3867 | |
| 3868 | Label polymorphic, try_poly_name; |
| 3869 | __ bind(&polymorphic); |
| 3870 | HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, true, &miss); |
| 3871 | |
| 3872 | __ bind(¬_array); |
| 3873 | // Is it generic? |
| 3874 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 3875 | __ Branch(&try_poly_name, ne, at, Operand(feedback)); |
| 3876 | Handle<Code> megamorphic_stub = |
| 3877 | KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState()); |
| 3878 | __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET); |
| 3879 | |
| 3880 | __ bind(&try_poly_name); |
| 3881 | // We might have a name in feedback, and a fixed array in the next slot. |
| 3882 | __ Branch(&miss, ne, key, Operand(feedback)); |
| 3883 | // If the name comparison succeeded, we know we have a fixed array with |
| 3884 | // at least one map/handler pair. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3885 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3886 | __ lw(feedback, |
| 3887 | FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize)); |
| 3888 | HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, false, &miss); |
| 3889 | |
| 3890 | __ bind(&miss); |
| 3891 | KeyedLoadIC::GenerateMiss(masm); |
| 3892 | |
| 3893 | __ bind(&load_smi_map); |
| 3894 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 3895 | __ jmp(&compare_map); |
| 3896 | } |
| 3897 | |
| 3898 | |
| 3899 | void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) { |
| 3900 | __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister()); |
| 3901 | VectorStoreICStub stub(isolate(), state()); |
| 3902 | stub.GenerateForTrampoline(masm); |
| 3903 | } |
| 3904 | |
| 3905 | |
| 3906 | void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) { |
| 3907 | __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister()); |
| 3908 | VectorKeyedStoreICStub stub(isolate(), state()); |
| 3909 | stub.GenerateForTrampoline(masm); |
| 3910 | } |
| 3911 | |
| 3912 | |
| 3913 | void VectorStoreICStub::Generate(MacroAssembler* masm) { |
| 3914 | GenerateImpl(masm, false); |
| 3915 | } |
| 3916 | |
| 3917 | |
| 3918 | void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 3919 | GenerateImpl(masm, true); |
| 3920 | } |
| 3921 | |
| 3922 | |
| 3923 | void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 3924 | Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1 |
| 3925 | Register key = VectorStoreICDescriptor::NameRegister(); // a2 |
| 3926 | Register vector = VectorStoreICDescriptor::VectorRegister(); // a3 |
| 3927 | Register slot = VectorStoreICDescriptor::SlotRegister(); // t0 |
| 3928 | DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0 |
| 3929 | Register feedback = t1; |
| 3930 | Register receiver_map = t2; |
| 3931 | Register scratch1 = t5; |
| 3932 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3933 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3934 | __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 3935 | |
| 3936 | // Try to quickly handle the monomorphic case without knowing for sure |
| 3937 | // if we have a weak cell in feedback. We do know it's safe to look |
| 3938 | // at WeakCell::kValueOffset. |
| 3939 | Label try_array, load_smi_map, compare_map; |
| 3940 | Label not_array, miss; |
| 3941 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 3942 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 3943 | |
| 3944 | // Is it a fixed array? |
| 3945 | __ bind(&try_array); |
| 3946 | __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 3947 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 3948 | __ Branch(¬_array, ne, scratch1, Operand(at)); |
| 3949 | |
| 3950 | Register scratch2 = t4; |
| 3951 | HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true, |
| 3952 | &miss); |
| 3953 | |
| 3954 | __ bind(¬_array); |
| 3955 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 3956 | __ Branch(&miss, ne, feedback, Operand(at)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 3957 | Code::Flags code_flags = |
| 3958 | Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(Code::STORE_IC)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3959 | masm->isolate()->stub_cache()->GenerateProbe( |
| 3960 | masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map, |
| 3961 | scratch1, scratch2); |
| 3962 | |
| 3963 | __ bind(&miss); |
| 3964 | StoreIC::GenerateMiss(masm); |
| 3965 | |
| 3966 | __ bind(&load_smi_map); |
| 3967 | __ Branch(USE_DELAY_SLOT, &compare_map); |
| 3968 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot. |
| 3969 | } |
| 3970 | |
| 3971 | |
| 3972 | void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) { |
| 3973 | GenerateImpl(masm, false); |
| 3974 | } |
| 3975 | |
| 3976 | |
| 3977 | void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 3978 | GenerateImpl(masm, true); |
| 3979 | } |
| 3980 | |
| 3981 | |
| 3982 | static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback, |
| 3983 | Register receiver_map, Register scratch1, |
| 3984 | Register scratch2, Label* miss) { |
| 3985 | // feedback initially contains the feedback array |
| 3986 | Label next_loop, prepare_next; |
| 3987 | Label start_polymorphic; |
| 3988 | Label transition_call; |
| 3989 | |
| 3990 | Register cached_map = scratch1; |
| 3991 | Register too_far = scratch2; |
| 3992 | Register pointer_reg = feedback; |
| 3993 | __ lw(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset)); |
| 3994 | |
| 3995 | // +-----+------+------+-----+-----+-----+ ... ----+ |
| 3996 | // | map | len | wm0 | wt0 | h0 | wm1 | hN | |
| 3997 | // +-----+------+------+-----+-----+ ----+ ... ----+ |
| 3998 | // 0 1 2 len-1 |
| 3999 | // ^ ^ |
| 4000 | // | | |
| 4001 | // pointer_reg too_far |
| 4002 | // aka feedback scratch2 |
| 4003 | // also need receiver_map |
| 4004 | // use cached_map (scratch1) to look in the weak map values. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4005 | __ Lsa(too_far, feedback, too_far, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4006 | __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 4007 | __ Addu(pointer_reg, feedback, |
| 4008 | Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag)); |
| 4009 | |
| 4010 | __ bind(&next_loop); |
| 4011 | __ lw(cached_map, MemOperand(pointer_reg)); |
| 4012 | __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset)); |
| 4013 | __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map)); |
| 4014 | // Is it a transitioning store? |
| 4015 | __ lw(too_far, MemOperand(pointer_reg, kPointerSize)); |
| 4016 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 4017 | __ Branch(&transition_call, ne, too_far, Operand(at)); |
| 4018 | __ lw(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2)); |
| 4019 | __ Addu(t9, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4020 | __ Jump(t9); |
| 4021 | |
| 4022 | __ bind(&transition_call); |
| 4023 | __ lw(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset)); |
| 4024 | __ JumpIfSmi(too_far, miss); |
| 4025 | |
| 4026 | __ lw(receiver_map, MemOperand(pointer_reg, kPointerSize * 2)); |
| 4027 | |
| 4028 | // Load the map into the correct register. |
| 4029 | DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister())); |
| 4030 | __ mov(feedback, too_far); |
| 4031 | |
| 4032 | __ Addu(t9, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4033 | __ Jump(t9); |
| 4034 | |
| 4035 | __ bind(&prepare_next); |
| 4036 | __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 3)); |
| 4037 | __ Branch(&next_loop, lt, pointer_reg, Operand(too_far)); |
| 4038 | |
| 4039 | // We exhausted our array of map handler pairs. |
| 4040 | __ jmp(miss); |
| 4041 | } |
| 4042 | |
| 4043 | |
| 4044 | void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4045 | Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1 |
| 4046 | Register key = VectorStoreICDescriptor::NameRegister(); // a2 |
| 4047 | Register vector = VectorStoreICDescriptor::VectorRegister(); // a3 |
| 4048 | Register slot = VectorStoreICDescriptor::SlotRegister(); // t0 |
| 4049 | DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0 |
| 4050 | Register feedback = t1; |
| 4051 | Register receiver_map = t2; |
| 4052 | Register scratch1 = t5; |
| 4053 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4054 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4055 | __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 4056 | |
| 4057 | // Try to quickly handle the monomorphic case without knowing for sure |
| 4058 | // if we have a weak cell in feedback. We do know it's safe to look |
| 4059 | // at WeakCell::kValueOffset. |
| 4060 | Label try_array, load_smi_map, compare_map; |
| 4061 | Label not_array, miss; |
| 4062 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 4063 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 4064 | |
| 4065 | __ bind(&try_array); |
| 4066 | // Is it a fixed array? |
| 4067 | __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 4068 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 4069 | __ Branch(¬_array, ne, scratch1, Operand(at)); |
| 4070 | |
| 4071 | // We have a polymorphic element handler. |
| 4072 | Label polymorphic, try_poly_name; |
| 4073 | __ bind(&polymorphic); |
| 4074 | |
| 4075 | Register scratch2 = t4; |
| 4076 | |
| 4077 | HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2, |
| 4078 | &miss); |
| 4079 | |
| 4080 | __ bind(¬_array); |
| 4081 | // Is it generic? |
| 4082 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 4083 | __ Branch(&try_poly_name, ne, feedback, Operand(at)); |
| 4084 | Handle<Code> megamorphic_stub = |
| 4085 | KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState()); |
| 4086 | __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET); |
| 4087 | |
| 4088 | __ bind(&try_poly_name); |
| 4089 | // We might have a name in feedback, and a fixed array in the next slot. |
| 4090 | __ Branch(&miss, ne, key, Operand(feedback)); |
| 4091 | // If the name comparison succeeded, we know we have a fixed array with |
| 4092 | // at least one map/handler pair. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4093 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4094 | __ lw(feedback, |
| 4095 | FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize)); |
| 4096 | HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false, |
| 4097 | &miss); |
| 4098 | |
| 4099 | __ bind(&miss); |
| 4100 | KeyedStoreIC::GenerateMiss(masm); |
| 4101 | |
| 4102 | __ bind(&load_smi_map); |
| 4103 | __ Branch(USE_DELAY_SLOT, &compare_map); |
| 4104 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot. |
| 4105 | } |
| 4106 | |
| 4107 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4108 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 4109 | if (masm->isolate()->function_entry_hook() != NULL) { |
| 4110 | ProfileEntryHookStub stub(masm->isolate()); |
| 4111 | __ push(ra); |
| 4112 | __ CallStub(&stub); |
| 4113 | __ pop(ra); |
| 4114 | } |
| 4115 | } |
| 4116 | |
| 4117 | |
| 4118 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 4119 | // The entry hook is a "push ra" instruction, followed by a call. |
| 4120 | // Note: on MIPS "push" is 2 instruction |
| 4121 | const int32_t kReturnAddressDistanceFromFunctionStart = |
| 4122 | Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize); |
| 4123 | |
| 4124 | // This should contain all kJSCallerSaved registers. |
| 4125 | const RegList kSavedRegs = |
| 4126 | kJSCallerSaved | // Caller saved registers. |
| 4127 | s5.bit(); // Saved stack pointer. |
| 4128 | |
| 4129 | // We also save ra, so the count here is one higher than the mask indicates. |
| 4130 | const int32_t kNumSavedRegs = kNumJSCallerSaved + 2; |
| 4131 | |
| 4132 | // Save all caller-save registers as this may be called from anywhere. |
| 4133 | __ MultiPush(kSavedRegs | ra.bit()); |
| 4134 | |
| 4135 | // Compute the function's address for the first argument. |
| 4136 | __ Subu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart)); |
| 4137 | |
| 4138 | // The caller's return address is above the saved temporaries. |
| 4139 | // Grab that for the second argument to the hook. |
| 4140 | __ Addu(a1, sp, Operand(kNumSavedRegs * kPointerSize)); |
| 4141 | |
| 4142 | // Align the stack if necessary. |
| 4143 | int frame_alignment = masm->ActivationFrameAlignment(); |
| 4144 | if (frame_alignment > kPointerSize) { |
| 4145 | __ mov(s5, sp); |
| 4146 | DCHECK(base::bits::IsPowerOfTwo32(frame_alignment)); |
| 4147 | __ And(sp, sp, Operand(-frame_alignment)); |
| 4148 | } |
| 4149 | __ Subu(sp, sp, kCArgsSlotsSize); |
| 4150 | #if defined(V8_HOST_ARCH_MIPS) |
| 4151 | int32_t entry_hook = |
| 4152 | reinterpret_cast<int32_t>(isolate()->function_entry_hook()); |
| 4153 | __ li(t9, Operand(entry_hook)); |
| 4154 | #else |
| 4155 | // Under the simulator we need to indirect the entry hook through a |
| 4156 | // trampoline function at a known address. |
| 4157 | // It additionally takes an isolate as a third parameter. |
| 4158 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
| 4159 | |
| 4160 | ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline)); |
| 4161 | __ li(t9, Operand(ExternalReference(&dispatcher, |
| 4162 | ExternalReference::BUILTIN_CALL, |
| 4163 | isolate()))); |
| 4164 | #endif |
| 4165 | // Call C function through t9 to conform ABI for PIC. |
| 4166 | __ Call(t9); |
| 4167 | |
| 4168 | // Restore the stack pointer if needed. |
| 4169 | if (frame_alignment > kPointerSize) { |
| 4170 | __ mov(sp, s5); |
| 4171 | } else { |
| 4172 | __ Addu(sp, sp, kCArgsSlotsSize); |
| 4173 | } |
| 4174 | |
| 4175 | // Also pop ra to get Ret(0). |
| 4176 | __ MultiPop(kSavedRegs | ra.bit()); |
| 4177 | __ Ret(); |
| 4178 | } |
| 4179 | |
| 4180 | |
| 4181 | template<class T> |
| 4182 | static void CreateArrayDispatch(MacroAssembler* masm, |
| 4183 | AllocationSiteOverrideMode mode) { |
| 4184 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 4185 | T stub(masm->isolate(), GetInitialFastElementsKind(), mode); |
| 4186 | __ TailCallStub(&stub); |
| 4187 | } else if (mode == DONT_OVERRIDE) { |
| 4188 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 4189 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4190 | for (int i = 0; i <= last_index; ++i) { |
| 4191 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4192 | T stub(masm->isolate(), kind); |
| 4193 | __ TailCallStub(&stub, eq, a3, Operand(kind)); |
| 4194 | } |
| 4195 | |
| 4196 | // If we reached this point there is a problem. |
| 4197 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 4198 | } else { |
| 4199 | UNREACHABLE(); |
| 4200 | } |
| 4201 | } |
| 4202 | |
| 4203 | |
| 4204 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm, |
| 4205 | AllocationSiteOverrideMode mode) { |
| 4206 | // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES) |
| 4207 | // a3 - kind (if mode != DISABLE_ALLOCATION_SITES) |
| 4208 | // a0 - number of arguments |
| 4209 | // a1 - constructor? |
| 4210 | // sp[0] - last argument |
| 4211 | Label normal_sequence; |
| 4212 | if (mode == DONT_OVERRIDE) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4213 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 4214 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 4215 | STATIC_ASSERT(FAST_ELEMENTS == 2); |
| 4216 | STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 4217 | STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 4218 | STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4219 | |
| 4220 | // is the low bit set? If so, we are holey and that is good. |
| 4221 | __ And(at, a3, Operand(1)); |
| 4222 | __ Branch(&normal_sequence, ne, at, Operand(zero_reg)); |
| 4223 | } |
| 4224 | |
| 4225 | // look at the first argument |
| 4226 | __ lw(t1, MemOperand(sp, 0)); |
| 4227 | __ Branch(&normal_sequence, eq, t1, Operand(zero_reg)); |
| 4228 | |
| 4229 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 4230 | ElementsKind initial = GetInitialFastElementsKind(); |
| 4231 | ElementsKind holey_initial = GetHoleyElementsKind(initial); |
| 4232 | |
| 4233 | ArraySingleArgumentConstructorStub stub_holey(masm->isolate(), |
| 4234 | holey_initial, |
| 4235 | DISABLE_ALLOCATION_SITES); |
| 4236 | __ TailCallStub(&stub_holey); |
| 4237 | |
| 4238 | __ bind(&normal_sequence); |
| 4239 | ArraySingleArgumentConstructorStub stub(masm->isolate(), |
| 4240 | initial, |
| 4241 | DISABLE_ALLOCATION_SITES); |
| 4242 | __ TailCallStub(&stub); |
| 4243 | } else if (mode == DONT_OVERRIDE) { |
| 4244 | // We are going to create a holey array, but our kind is non-holey. |
| 4245 | // Fix kind and retry (only if we have an allocation site in the slot). |
| 4246 | __ Addu(a3, a3, Operand(1)); |
| 4247 | |
| 4248 | if (FLAG_debug_code) { |
| 4249 | __ lw(t1, FieldMemOperand(a2, 0)); |
| 4250 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 4251 | __ Assert(eq, kExpectedAllocationSite, t1, Operand(at)); |
| 4252 | } |
| 4253 | |
| 4254 | // Save the resulting elements kind in type info. We can't just store a3 |
| 4255 | // in the AllocationSite::transition_info field because elements kind is |
| 4256 | // restricted to a portion of the field...upper bits need to be left alone. |
| 4257 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 4258 | __ lw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset)); |
| 4259 | __ Addu(t0, t0, Operand(Smi::FromInt(kFastElementsKindPackedToHoley))); |
| 4260 | __ sw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset)); |
| 4261 | |
| 4262 | |
| 4263 | __ bind(&normal_sequence); |
| 4264 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 4265 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4266 | for (int i = 0; i <= last_index; ++i) { |
| 4267 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4268 | ArraySingleArgumentConstructorStub stub(masm->isolate(), kind); |
| 4269 | __ TailCallStub(&stub, eq, a3, Operand(kind)); |
| 4270 | } |
| 4271 | |
| 4272 | // If we reached this point there is a problem. |
| 4273 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 4274 | } else { |
| 4275 | UNREACHABLE(); |
| 4276 | } |
| 4277 | } |
| 4278 | |
| 4279 | |
| 4280 | template<class T> |
| 4281 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 4282 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 4283 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4284 | for (int i = 0; i <= to_index; ++i) { |
| 4285 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4286 | T stub(isolate, kind); |
| 4287 | stub.GetCode(); |
| 4288 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
| 4289 | T stub1(isolate, kind, DISABLE_ALLOCATION_SITES); |
| 4290 | stub1.GetCode(); |
| 4291 | } |
| 4292 | } |
| 4293 | } |
| 4294 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 4295 | void CommonArrayConstructorStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4296 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 4297 | isolate); |
| 4298 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 4299 | isolate); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 4300 | ArrayNArgumentsConstructorStub stub(isolate); |
| 4301 | stub.GetCode(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4302 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 4303 | for (int i = 0; i < 2; i++) { |
| 4304 | // For internal arrays we only need a few things. |
| 4305 | InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]); |
| 4306 | stubh1.GetCode(); |
| 4307 | InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]); |
| 4308 | stubh2.GetCode(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4309 | } |
| 4310 | } |
| 4311 | |
| 4312 | |
| 4313 | void ArrayConstructorStub::GenerateDispatchToArrayStub( |
| 4314 | MacroAssembler* masm, |
| 4315 | AllocationSiteOverrideMode mode) { |
| 4316 | if (argument_count() == ANY) { |
| 4317 | Label not_zero_case, not_one_case; |
| 4318 | __ And(at, a0, a0); |
| 4319 | __ Branch(¬_zero_case, ne, at, Operand(zero_reg)); |
| 4320 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 4321 | |
| 4322 | __ bind(¬_zero_case); |
| 4323 | __ Branch(¬_one_case, gt, a0, Operand(1)); |
| 4324 | CreateArrayDispatchOneArgument(masm, mode); |
| 4325 | |
| 4326 | __ bind(¬_one_case); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 4327 | ArrayNArgumentsConstructorStub stub(masm->isolate()); |
| 4328 | __ TailCallStub(&stub); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4329 | } else if (argument_count() == NONE) { |
| 4330 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 4331 | } else if (argument_count() == ONE) { |
| 4332 | CreateArrayDispatchOneArgument(masm, mode); |
| 4333 | } else if (argument_count() == MORE_THAN_ONE) { |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 4334 | ArrayNArgumentsConstructorStub stub(masm->isolate()); |
| 4335 | __ TailCallStub(&stub); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4336 | } else { |
| 4337 | UNREACHABLE(); |
| 4338 | } |
| 4339 | } |
| 4340 | |
| 4341 | |
| 4342 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 4343 | // ----------- S t a t e ------------- |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4344 | // -- a0 : argc (only if argument_count() is ANY or MORE_THAN_ONE) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4345 | // -- a1 : constructor |
| 4346 | // -- a2 : AllocationSite or undefined |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4347 | // -- a3 : Original constructor |
| 4348 | // -- sp[0] : last argument |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4349 | // ----------------------------------- |
| 4350 | |
| 4351 | if (FLAG_debug_code) { |
| 4352 | // The array construct code is only set for the global and natives |
| 4353 | // builtin Array functions which always have maps. |
| 4354 | |
| 4355 | // Initial map for the builtin Array function should be a map. |
| 4356 | __ lw(t0, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4357 | // Will both indicate a NULL and a Smi. |
| 4358 | __ SmiTst(t0, at); |
| 4359 | __ Assert(ne, kUnexpectedInitialMapForArrayFunction, |
| 4360 | at, Operand(zero_reg)); |
| 4361 | __ GetObjectType(t0, t0, t1); |
| 4362 | __ Assert(eq, kUnexpectedInitialMapForArrayFunction, |
| 4363 | t1, Operand(MAP_TYPE)); |
| 4364 | |
| 4365 | // We should either have undefined in a2 or a valid AllocationSite |
| 4366 | __ AssertUndefinedOrAllocationSite(a2, t0); |
| 4367 | } |
| 4368 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4369 | // Enter the context of the Array function. |
| 4370 | __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 4371 | |
| 4372 | Label subclassing; |
| 4373 | __ Branch(&subclassing, ne, a1, Operand(a3)); |
| 4374 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4375 | Label no_info; |
| 4376 | // Get the elements kind and case on that. |
| 4377 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 4378 | __ Branch(&no_info, eq, a2, Operand(at)); |
| 4379 | |
| 4380 | __ lw(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset)); |
| 4381 | __ SmiUntag(a3); |
| 4382 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 4383 | __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask)); |
| 4384 | GenerateDispatchToArrayStub(masm, DONT_OVERRIDE); |
| 4385 | |
| 4386 | __ bind(&no_info); |
| 4387 | GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4388 | |
| 4389 | // Subclassing. |
| 4390 | __ bind(&subclassing); |
| 4391 | switch (argument_count()) { |
| 4392 | case ANY: |
| 4393 | case MORE_THAN_ONE: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4394 | __ Lsa(at, sp, a0, kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4395 | __ sw(a1, MemOperand(at)); |
| 4396 | __ li(at, Operand(3)); |
| 4397 | __ addu(a0, a0, at); |
| 4398 | break; |
| 4399 | case NONE: |
| 4400 | __ sw(a1, MemOperand(sp, 0 * kPointerSize)); |
| 4401 | __ li(a0, Operand(3)); |
| 4402 | break; |
| 4403 | case ONE: |
| 4404 | __ sw(a1, MemOperand(sp, 1 * kPointerSize)); |
| 4405 | __ li(a0, Operand(4)); |
| 4406 | break; |
| 4407 | } |
| 4408 | __ Push(a3, a2); |
| 4409 | __ JumpToExternalReference(ExternalReference(Runtime::kNewArray, isolate())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4410 | } |
| 4411 | |
| 4412 | |
| 4413 | void InternalArrayConstructorStub::GenerateCase( |
| 4414 | MacroAssembler* masm, ElementsKind kind) { |
| 4415 | |
| 4416 | InternalArrayNoArgumentConstructorStub stub0(isolate(), kind); |
| 4417 | __ TailCallStub(&stub0, lo, a0, Operand(1)); |
| 4418 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 4419 | ArrayNArgumentsConstructorStub stubN(isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4420 | __ TailCallStub(&stubN, hi, a0, Operand(1)); |
| 4421 | |
| 4422 | if (IsFastPackedElementsKind(kind)) { |
| 4423 | // We might need to create a holey array |
| 4424 | // look at the first argument. |
| 4425 | __ lw(at, MemOperand(sp, 0)); |
| 4426 | |
| 4427 | InternalArraySingleArgumentConstructorStub |
| 4428 | stub1_holey(isolate(), GetHoleyElementsKind(kind)); |
| 4429 | __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg)); |
| 4430 | } |
| 4431 | |
| 4432 | InternalArraySingleArgumentConstructorStub stub1(isolate(), kind); |
| 4433 | __ TailCallStub(&stub1); |
| 4434 | } |
| 4435 | |
| 4436 | |
| 4437 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 4438 | // ----------- S t a t e ------------- |
| 4439 | // -- a0 : argc |
| 4440 | // -- a1 : constructor |
| 4441 | // -- sp[0] : return address |
| 4442 | // -- sp[4] : last argument |
| 4443 | // ----------------------------------- |
| 4444 | |
| 4445 | if (FLAG_debug_code) { |
| 4446 | // The array construct code is only set for the global and natives |
| 4447 | // builtin Array functions which always have maps. |
| 4448 | |
| 4449 | // Initial map for the builtin Array function should be a map. |
| 4450 | __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4451 | // Will both indicate a NULL and a Smi. |
| 4452 | __ SmiTst(a3, at); |
| 4453 | __ Assert(ne, kUnexpectedInitialMapForArrayFunction, |
| 4454 | at, Operand(zero_reg)); |
| 4455 | __ GetObjectType(a3, a3, t0); |
| 4456 | __ Assert(eq, kUnexpectedInitialMapForArrayFunction, |
| 4457 | t0, Operand(MAP_TYPE)); |
| 4458 | } |
| 4459 | |
| 4460 | // Figure out the right elements kind. |
| 4461 | __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4462 | |
| 4463 | // Load the map's "bit field 2" into a3. We only need the first byte, |
| 4464 | // but the following bit field extraction takes care of that anyway. |
| 4465 | __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset)); |
| 4466 | // Retrieve elements_kind from bit field 2. |
| 4467 | __ DecodeField<Map::ElementsKindBits>(a3); |
| 4468 | |
| 4469 | if (FLAG_debug_code) { |
| 4470 | Label done; |
| 4471 | __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS)); |
| 4472 | __ Assert( |
| 4473 | eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray, |
| 4474 | a3, Operand(FAST_HOLEY_ELEMENTS)); |
| 4475 | __ bind(&done); |
| 4476 | } |
| 4477 | |
| 4478 | Label fast_elements_case; |
| 4479 | __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS)); |
| 4480 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 4481 | |
| 4482 | __ bind(&fast_elements_case); |
| 4483 | GenerateCase(masm, FAST_ELEMENTS); |
| 4484 | } |
| 4485 | |
| 4486 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4487 | void FastNewObjectStub::Generate(MacroAssembler* masm) { |
| 4488 | // ----------- S t a t e ------------- |
| 4489 | // -- a1 : target |
| 4490 | // -- a3 : new target |
| 4491 | // -- cp : context |
| 4492 | // -- ra : return address |
| 4493 | // ----------------------------------- |
| 4494 | __ AssertFunction(a1); |
| 4495 | __ AssertReceiver(a3); |
| 4496 | |
| 4497 | // Verify that the new target is a JSFunction. |
| 4498 | Label new_object; |
| 4499 | __ GetObjectType(a3, a2, a2); |
| 4500 | __ Branch(&new_object, ne, a2, Operand(JS_FUNCTION_TYPE)); |
| 4501 | |
| 4502 | // Load the initial map and verify that it's in fact a map. |
| 4503 | __ lw(a2, FieldMemOperand(a3, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4504 | __ JumpIfSmi(a2, &new_object); |
| 4505 | __ GetObjectType(a2, a0, a0); |
| 4506 | __ Branch(&new_object, ne, a0, Operand(MAP_TYPE)); |
| 4507 | |
| 4508 | // Fall back to runtime if the target differs from the new target's |
| 4509 | // initial map constructor. |
| 4510 | __ lw(a0, FieldMemOperand(a2, Map::kConstructorOrBackPointerOffset)); |
| 4511 | __ Branch(&new_object, ne, a0, Operand(a1)); |
| 4512 | |
| 4513 | // Allocate the JSObject on the heap. |
| 4514 | Label allocate, done_allocate; |
| 4515 | __ lbu(t0, FieldMemOperand(a2, Map::kInstanceSizeOffset)); |
| 4516 | __ Allocate(t0, v0, t1, a0, &allocate, SIZE_IN_WORDS); |
| 4517 | __ bind(&done_allocate); |
| 4518 | |
| 4519 | // Initialize the JSObject fields. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4520 | __ sw(a2, FieldMemOperand(v0, JSObject::kMapOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4521 | __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4522 | __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset)); |
| 4523 | __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4524 | STATIC_ASSERT(JSObject::kHeaderSize == 3 * kPointerSize); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4525 | __ Addu(a1, v0, Operand(JSObject::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4526 | |
| 4527 | // ----------- S t a t e ------------- |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4528 | // -- v0 : result (tagged) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4529 | // -- a1 : result fields (untagged) |
| 4530 | // -- t1 : result end (untagged) |
| 4531 | // -- a2 : initial map |
| 4532 | // -- cp : context |
| 4533 | // -- ra : return address |
| 4534 | // ----------------------------------- |
| 4535 | |
| 4536 | // Perform in-object slack tracking if requested. |
| 4537 | Label slack_tracking; |
| 4538 | STATIC_ASSERT(Map::kNoSlackTracking == 0); |
| 4539 | __ lw(a3, FieldMemOperand(a2, Map::kBitField3Offset)); |
| 4540 | __ And(at, a3, Operand(Map::ConstructionCounter::kMask)); |
| 4541 | __ Branch(USE_DELAY_SLOT, &slack_tracking, ne, at, Operand(0)); |
| 4542 | __ LoadRoot(a0, Heap::kUndefinedValueRootIndex); // In delay slot. |
| 4543 | { |
| 4544 | // Initialize all in-object fields with undefined. |
| 4545 | __ InitializeFieldsWithFiller(a1, t1, a0); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4546 | __ Ret(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4547 | } |
| 4548 | __ bind(&slack_tracking); |
| 4549 | { |
| 4550 | // Decrease generous allocation count. |
| 4551 | STATIC_ASSERT(Map::ConstructionCounter::kNext == 32); |
| 4552 | __ Subu(a3, a3, Operand(1 << Map::ConstructionCounter::kShift)); |
| 4553 | __ sw(a3, FieldMemOperand(a2, Map::kBitField3Offset)); |
| 4554 | |
| 4555 | // Initialize the in-object fields with undefined. |
| 4556 | __ lbu(t0, FieldMemOperand(a2, Map::kUnusedPropertyFieldsOffset)); |
| 4557 | __ sll(t0, t0, kPointerSizeLog2); |
| 4558 | __ subu(t0, t1, t0); |
| 4559 | __ InitializeFieldsWithFiller(a1, t0, a0); |
| 4560 | |
| 4561 | // Initialize the remaining (reserved) fields with one pointer filler map. |
| 4562 | __ LoadRoot(a0, Heap::kOnePointerFillerMapRootIndex); |
| 4563 | __ InitializeFieldsWithFiller(a1, t1, a0); |
| 4564 | |
| 4565 | // Check if we can finalize the instance size. |
| 4566 | Label finalize; |
| 4567 | STATIC_ASSERT(Map::kSlackTrackingCounterEnd == 1); |
| 4568 | __ And(a3, a3, Operand(Map::ConstructionCounter::kMask)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4569 | __ Branch(&finalize, eq, a3, Operand(zero_reg)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4570 | __ Ret(); |
| 4571 | |
| 4572 | // Finalize the instance size. |
| 4573 | __ bind(&finalize); |
| 4574 | { |
| 4575 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4576 | __ Push(v0, a2); |
| 4577 | __ CallRuntime(Runtime::kFinalizeInstanceSize); |
| 4578 | __ Pop(v0); |
| 4579 | } |
| 4580 | __ Ret(); |
| 4581 | } |
| 4582 | |
| 4583 | // Fall back to %AllocateInNewSpace. |
| 4584 | __ bind(&allocate); |
| 4585 | { |
| 4586 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4587 | STATIC_ASSERT(kSmiTag == 0); |
| 4588 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4589 | __ sll(t0, t0, kPointerSizeLog2 + kSmiTagSize); |
| 4590 | __ Push(a2, t0); |
| 4591 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 4592 | __ Pop(a2); |
| 4593 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4594 | __ lbu(t1, FieldMemOperand(a2, Map::kInstanceSizeOffset)); |
| 4595 | __ Lsa(t1, v0, t1, kPointerSizeLog2); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4596 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4597 | __ Subu(t1, t1, Operand(kHeapObjectTag)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4598 | __ jmp(&done_allocate); |
| 4599 | |
| 4600 | // Fall back to %NewObject. |
| 4601 | __ bind(&new_object); |
| 4602 | __ Push(a1, a3); |
| 4603 | __ TailCallRuntime(Runtime::kNewObject); |
| 4604 | } |
| 4605 | |
| 4606 | |
| 4607 | void FastNewRestParameterStub::Generate(MacroAssembler* masm) { |
| 4608 | // ----------- S t a t e ------------- |
| 4609 | // -- a1 : function |
| 4610 | // -- cp : context |
| 4611 | // -- fp : frame pointer |
| 4612 | // -- ra : return address |
| 4613 | // ----------------------------------- |
| 4614 | __ AssertFunction(a1); |
| 4615 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4616 | // Make a2 point to the JavaScript frame. |
| 4617 | __ mov(a2, fp); |
| 4618 | if (skip_stub_frame()) { |
| 4619 | // For Ignition we need to skip the handler/stub frame to reach the |
| 4620 | // JavaScript frame for the function. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4621 | __ lw(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4622 | } |
| 4623 | if (FLAG_debug_code) { |
| 4624 | Label ok; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 4625 | __ lw(a3, MemOperand(a2, StandardFrameConstants::kFunctionOffset)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4626 | __ Branch(&ok, eq, a1, Operand(a3)); |
| 4627 | __ Abort(kInvalidFrameForFastNewRestArgumentsStub); |
| 4628 | __ bind(&ok); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4629 | } |
| 4630 | |
| 4631 | // Check if we have rest parameters (only possible if we have an |
| 4632 | // arguments adaptor frame below the function frame). |
| 4633 | Label no_rest_parameters; |
| 4634 | __ lw(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 4635 | __ lw(a3, MemOperand(a2, CommonFrameConstants::kContextOrFrameTypeOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4636 | __ Branch(&no_rest_parameters, ne, a3, |
| 4637 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4638 | |
| 4639 | // Check if the arguments adaptor frame contains more arguments than |
| 4640 | // specified by the function's internal formal parameter count. |
| 4641 | Label rest_parameters; |
| 4642 | __ lw(a0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 4643 | __ lw(a3, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 4644 | __ lw(a3, |
| 4645 | FieldMemOperand(a3, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 4646 | __ Subu(a0, a0, Operand(a3)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4647 | __ Branch(&rest_parameters, gt, a0, Operand(zero_reg)); |
| 4648 | |
| 4649 | // Return an empty rest parameter array. |
| 4650 | __ bind(&no_rest_parameters); |
| 4651 | { |
| 4652 | // ----------- S t a t e ------------- |
| 4653 | // -- cp : context |
| 4654 | // -- ra : return address |
| 4655 | // ----------------------------------- |
| 4656 | |
| 4657 | // Allocate an empty rest parameter array. |
| 4658 | Label allocate, done_allocate; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4659 | __ Allocate(JSArray::kSize, v0, a0, a1, &allocate, NO_ALLOCATION_FLAGS); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4660 | __ bind(&done_allocate); |
| 4661 | |
| 4662 | // Setup the rest parameter array in v0. |
| 4663 | __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, a1); |
| 4664 | __ sw(a1, FieldMemOperand(v0, JSArray::kMapOffset)); |
| 4665 | __ LoadRoot(a1, Heap::kEmptyFixedArrayRootIndex); |
| 4666 | __ sw(a1, FieldMemOperand(v0, JSArray::kPropertiesOffset)); |
| 4667 | __ sw(a1, FieldMemOperand(v0, JSArray::kElementsOffset)); |
| 4668 | __ Move(a1, Smi::FromInt(0)); |
| 4669 | __ Ret(USE_DELAY_SLOT); |
| 4670 | __ sw(a1, FieldMemOperand(v0, JSArray::kLengthOffset)); // In delay slot |
| 4671 | STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize); |
| 4672 | |
| 4673 | // Fall back to %AllocateInNewSpace. |
| 4674 | __ bind(&allocate); |
| 4675 | { |
| 4676 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4677 | __ Push(Smi::FromInt(JSArray::kSize)); |
| 4678 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 4679 | } |
| 4680 | __ jmp(&done_allocate); |
| 4681 | } |
| 4682 | |
| 4683 | __ bind(&rest_parameters); |
| 4684 | { |
| 4685 | // Compute the pointer to the first rest parameter (skippping the receiver). |
| 4686 | __ Lsa(a2, a2, a0, kPointerSizeLog2 - 1); |
| 4687 | __ Addu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset - |
| 4688 | 1 * kPointerSize)); |
| 4689 | |
| 4690 | // ----------- S t a t e ------------- |
| 4691 | // -- cp : context |
| 4692 | // -- a0 : number of rest parameters (tagged) |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 4693 | // -- a1 : function |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4694 | // -- a2 : pointer to first rest parameters |
| 4695 | // -- ra : return address |
| 4696 | // ----------------------------------- |
| 4697 | |
| 4698 | // Allocate space for the rest parameter array plus the backing store. |
| 4699 | Label allocate, done_allocate; |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 4700 | __ li(t0, Operand(JSArray::kSize + FixedArray::kHeaderSize)); |
| 4701 | __ Lsa(t0, t0, a0, kPointerSizeLog2 - 1); |
| 4702 | __ Allocate(t0, v0, a3, t1, &allocate, NO_ALLOCATION_FLAGS); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4703 | __ bind(&done_allocate); |
| 4704 | |
| 4705 | // Setup the elements array in v0. |
| 4706 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 4707 | __ sw(at, FieldMemOperand(v0, FixedArray::kMapOffset)); |
| 4708 | __ sw(a0, FieldMemOperand(v0, FixedArray::kLengthOffset)); |
| 4709 | __ Addu(a3, v0, Operand(FixedArray::kHeaderSize)); |
| 4710 | { |
| 4711 | Label loop, done_loop; |
| 4712 | __ sll(at, a0, kPointerSizeLog2 - 1); |
| 4713 | __ Addu(a1, a3, at); |
| 4714 | __ bind(&loop); |
| 4715 | __ Branch(&done_loop, eq, a1, Operand(a3)); |
| 4716 | __ lw(at, MemOperand(a2, 0 * kPointerSize)); |
| 4717 | __ sw(at, FieldMemOperand(a3, 0 * kPointerSize)); |
| 4718 | __ Subu(a2, a2, Operand(1 * kPointerSize)); |
| 4719 | __ Addu(a3, a3, Operand(1 * kPointerSize)); |
| 4720 | __ jmp(&loop); |
| 4721 | __ bind(&done_loop); |
| 4722 | } |
| 4723 | |
| 4724 | // Setup the rest parameter array in a3. |
| 4725 | __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, at); |
| 4726 | __ sw(at, FieldMemOperand(a3, JSArray::kMapOffset)); |
| 4727 | __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex); |
| 4728 | __ sw(at, FieldMemOperand(a3, JSArray::kPropertiesOffset)); |
| 4729 | __ sw(v0, FieldMemOperand(a3, JSArray::kElementsOffset)); |
| 4730 | __ sw(a0, FieldMemOperand(a3, JSArray::kLengthOffset)); |
| 4731 | STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize); |
| 4732 | __ Ret(USE_DELAY_SLOT); |
| 4733 | __ mov(v0, a3); // In delay slot |
| 4734 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 4735 | // Fall back to %AllocateInNewSpace (if not too big). |
| 4736 | Label too_big_for_new_space; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4737 | __ bind(&allocate); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 4738 | __ Branch(&too_big_for_new_space, gt, t0, |
| 4739 | Operand(Page::kMaxRegularHeapObjectSize)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4740 | { |
| 4741 | FrameScope scope(masm, StackFrame::INTERNAL); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 4742 | __ SmiTag(t0); |
| 4743 | __ Push(a0, a2, t0); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4744 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 4745 | __ Pop(a0, a2); |
| 4746 | } |
| 4747 | __ jmp(&done_allocate); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 4748 | |
| 4749 | // Fall back to %NewStrictArguments. |
| 4750 | __ bind(&too_big_for_new_space); |
| 4751 | __ Push(a1); |
| 4752 | __ TailCallRuntime(Runtime::kNewStrictArguments); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4753 | } |
| 4754 | } |
| 4755 | |
| 4756 | |
| 4757 | void FastNewSloppyArgumentsStub::Generate(MacroAssembler* masm) { |
| 4758 | // ----------- S t a t e ------------- |
| 4759 | // -- a1 : function |
| 4760 | // -- cp : context |
| 4761 | // -- fp : frame pointer |
| 4762 | // -- ra : return address |
| 4763 | // ----------------------------------- |
| 4764 | __ AssertFunction(a1); |
| 4765 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4766 | // Make t0 point to the JavaScript frame. |
| 4767 | __ mov(t0, fp); |
| 4768 | if (skip_stub_frame()) { |
| 4769 | // For Ignition we need to skip the handler/stub frame to reach the |
| 4770 | // JavaScript frame for the function. |
| 4771 | __ lw(t0, MemOperand(t0, StandardFrameConstants::kCallerFPOffset)); |
| 4772 | } |
| 4773 | if (FLAG_debug_code) { |
| 4774 | Label ok; |
| 4775 | __ lw(a3, MemOperand(t0, StandardFrameConstants::kFunctionOffset)); |
| 4776 | __ Branch(&ok, eq, a1, Operand(a3)); |
| 4777 | __ Abort(kInvalidFrameForFastNewRestArgumentsStub); |
| 4778 | __ bind(&ok); |
| 4779 | } |
| 4780 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4781 | // TODO(bmeurer): Cleanup to match the FastNewStrictArgumentsStub. |
| 4782 | __ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 4783 | __ lw(a2, |
| 4784 | FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4785 | __ Lsa(a3, t0, a2, kPointerSizeLog2 - 1); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4786 | __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 4787 | |
| 4788 | // a1 : function |
| 4789 | // a2 : number of parameters (tagged) |
| 4790 | // a3 : parameters pointer |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4791 | // t0 : Javascript frame pointer |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4792 | // Registers used over whole function: |
| 4793 | // t1 : arguments count (tagged) |
| 4794 | // t2 : mapped parameter count (tagged) |
| 4795 | |
| 4796 | // Check if the calling frame is an arguments adaptor frame. |
| 4797 | Label adaptor_frame, try_allocate, runtime; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4798 | __ lw(t0, MemOperand(t0, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 4799 | __ lw(a0, MemOperand(t0, CommonFrameConstants::kContextOrFrameTypeOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4800 | __ Branch(&adaptor_frame, eq, a0, |
| 4801 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4802 | |
| 4803 | // No adaptor, parameter count = argument count. |
| 4804 | __ mov(t1, a2); |
| 4805 | __ Branch(USE_DELAY_SLOT, &try_allocate); |
| 4806 | __ mov(t2, a2); // In delay slot. |
| 4807 | |
| 4808 | // We have an adaptor frame. Patch the parameters pointer. |
| 4809 | __ bind(&adaptor_frame); |
| 4810 | __ lw(t1, MemOperand(t0, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4811 | __ Lsa(t0, t0, t1, 1); |
| 4812 | __ Addu(a3, t0, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 4813 | |
| 4814 | // t1 = argument count (tagged) |
| 4815 | // t2 = parameter count (tagged) |
| 4816 | // Compute the mapped parameter count = min(t2, t1) in t2. |
| 4817 | __ mov(t2, a2); |
| 4818 | __ Branch(&try_allocate, le, t2, Operand(t1)); |
| 4819 | __ mov(t2, t1); |
| 4820 | |
| 4821 | __ bind(&try_allocate); |
| 4822 | |
| 4823 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 4824 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 4825 | const int kParameterMapHeaderSize = |
| 4826 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 4827 | // If there are no mapped parameters, we do not need the parameter_map. |
| 4828 | Label param_map_size; |
| 4829 | DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0)); |
| 4830 | __ Branch(USE_DELAY_SLOT, ¶m_map_size, eq, t2, Operand(zero_reg)); |
| 4831 | __ mov(t5, zero_reg); // In delay slot: param map size = 0 when t2 == 0. |
| 4832 | __ sll(t5, t2, 1); |
| 4833 | __ addiu(t5, t5, kParameterMapHeaderSize); |
| 4834 | __ bind(¶m_map_size); |
| 4835 | |
| 4836 | // 2. Backing store. |
| 4837 | __ Lsa(t5, t5, t1, 1); |
| 4838 | __ Addu(t5, t5, Operand(FixedArray::kHeaderSize)); |
| 4839 | |
| 4840 | // 3. Arguments object. |
| 4841 | __ Addu(t5, t5, Operand(JSSloppyArgumentsObject::kSize)); |
| 4842 | |
| 4843 | // Do the allocation of all three objects in one go. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4844 | __ Allocate(t5, v0, t5, t0, &runtime, NO_ALLOCATION_FLAGS); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4845 | |
| 4846 | // v0 = address of new object(s) (tagged) |
| 4847 | // a2 = argument count (smi-tagged) |
| 4848 | // Get the arguments boilerplate from the current native context into t0. |
| 4849 | const int kNormalOffset = |
| 4850 | Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX); |
| 4851 | const int kAliasedOffset = |
| 4852 | Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX); |
| 4853 | |
| 4854 | __ lw(t0, NativeContextMemOperand()); |
| 4855 | Label skip2_ne, skip2_eq; |
| 4856 | __ Branch(&skip2_ne, ne, t2, Operand(zero_reg)); |
| 4857 | __ lw(t0, MemOperand(t0, kNormalOffset)); |
| 4858 | __ bind(&skip2_ne); |
| 4859 | |
| 4860 | __ Branch(&skip2_eq, eq, t2, Operand(zero_reg)); |
| 4861 | __ lw(t0, MemOperand(t0, kAliasedOffset)); |
| 4862 | __ bind(&skip2_eq); |
| 4863 | |
| 4864 | // v0 = address of new object (tagged) |
| 4865 | // a2 = argument count (smi-tagged) |
| 4866 | // t0 = address of arguments map (tagged) |
| 4867 | // t2 = mapped parameter count (tagged) |
| 4868 | __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset)); |
| 4869 | __ LoadRoot(t5, Heap::kEmptyFixedArrayRootIndex); |
| 4870 | __ sw(t5, FieldMemOperand(v0, JSObject::kPropertiesOffset)); |
| 4871 | __ sw(t5, FieldMemOperand(v0, JSObject::kElementsOffset)); |
| 4872 | |
| 4873 | // Set up the callee in-object property. |
| 4874 | __ AssertNotSmi(a1); |
| 4875 | __ sw(a1, FieldMemOperand(v0, JSSloppyArgumentsObject::kCalleeOffset)); |
| 4876 | |
| 4877 | // Use the length (smi tagged) and set that as an in-object property too. |
| 4878 | __ AssertSmi(t1); |
| 4879 | __ sw(t1, FieldMemOperand(v0, JSSloppyArgumentsObject::kLengthOffset)); |
| 4880 | |
| 4881 | // Set up the elements pointer in the allocated arguments object. |
| 4882 | // If we allocated a parameter map, t0 will point there, otherwise |
| 4883 | // it will point to the backing store. |
| 4884 | __ Addu(t0, v0, Operand(JSSloppyArgumentsObject::kSize)); |
| 4885 | __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset)); |
| 4886 | |
| 4887 | // v0 = address of new object (tagged) |
| 4888 | // a2 = argument count (tagged) |
| 4889 | // t0 = address of parameter map or backing store (tagged) |
| 4890 | // t2 = mapped parameter count (tagged) |
| 4891 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 4892 | Label skip_parameter_map; |
| 4893 | Label skip3; |
| 4894 | __ Branch(&skip3, ne, t2, Operand(Smi::FromInt(0))); |
| 4895 | // Move backing store address to a1, because it is |
| 4896 | // expected there when filling in the unmapped arguments. |
| 4897 | __ mov(a1, t0); |
| 4898 | __ bind(&skip3); |
| 4899 | |
| 4900 | __ Branch(&skip_parameter_map, eq, t2, Operand(Smi::FromInt(0))); |
| 4901 | |
| 4902 | __ LoadRoot(t1, Heap::kSloppyArgumentsElementsMapRootIndex); |
| 4903 | __ sw(t1, FieldMemOperand(t0, FixedArray::kMapOffset)); |
| 4904 | __ Addu(t1, t2, Operand(Smi::FromInt(2))); |
| 4905 | __ sw(t1, FieldMemOperand(t0, FixedArray::kLengthOffset)); |
| 4906 | __ sw(cp, FieldMemOperand(t0, FixedArray::kHeaderSize + 0 * kPointerSize)); |
| 4907 | __ Lsa(t1, t0, t2, 1); |
| 4908 | __ Addu(t1, t1, Operand(kParameterMapHeaderSize)); |
| 4909 | __ sw(t1, FieldMemOperand(t0, FixedArray::kHeaderSize + 1 * kPointerSize)); |
| 4910 | |
| 4911 | // Copy the parameter slots and the holes in the arguments. |
| 4912 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 4913 | // where parameters are stored in reverse order, at |
| 4914 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 4915 | // The mapped parameter thus need to get indices |
| 4916 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 4917 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 4918 | // We loop from right to left. |
| 4919 | Label parameters_loop, parameters_test; |
| 4920 | __ mov(t1, t2); |
| 4921 | __ Addu(t5, a2, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 4922 | __ Subu(t5, t5, Operand(t2)); |
| 4923 | __ LoadRoot(t3, Heap::kTheHoleValueRootIndex); |
| 4924 | __ Lsa(a1, t0, t1, 1); |
| 4925 | __ Addu(a1, a1, Operand(kParameterMapHeaderSize)); |
| 4926 | |
| 4927 | // a1 = address of backing store (tagged) |
| 4928 | // t0 = address of parameter map (tagged) |
| 4929 | // a0 = temporary scratch (a.o., for address calculation) |
| 4930 | // t1 = loop variable (tagged) |
| 4931 | // t3 = the hole value |
| 4932 | __ jmp(¶meters_test); |
| 4933 | |
| 4934 | __ bind(¶meters_loop); |
| 4935 | __ Subu(t1, t1, Operand(Smi::FromInt(1))); |
| 4936 | __ sll(a0, t1, 1); |
| 4937 | __ Addu(a0, a0, Operand(kParameterMapHeaderSize - kHeapObjectTag)); |
| 4938 | __ Addu(t6, t0, a0); |
| 4939 | __ sw(t5, MemOperand(t6)); |
| 4940 | __ Subu(a0, a0, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize)); |
| 4941 | __ Addu(t6, a1, a0); |
| 4942 | __ sw(t3, MemOperand(t6)); |
| 4943 | __ Addu(t5, t5, Operand(Smi::FromInt(1))); |
| 4944 | __ bind(¶meters_test); |
| 4945 | __ Branch(¶meters_loop, ne, t1, Operand(Smi::FromInt(0))); |
| 4946 | |
| 4947 | // t1 = argument count (tagged). |
| 4948 | __ lw(t1, FieldMemOperand(v0, JSSloppyArgumentsObject::kLengthOffset)); |
| 4949 | |
| 4950 | __ bind(&skip_parameter_map); |
| 4951 | // v0 = address of new object (tagged) |
| 4952 | // a1 = address of backing store (tagged) |
| 4953 | // t1 = argument count (tagged) |
| 4954 | // t2 = mapped parameter count (tagged) |
| 4955 | // t5 = scratch |
| 4956 | // Copy arguments header and remaining slots (if there are any). |
| 4957 | __ LoadRoot(t5, Heap::kFixedArrayMapRootIndex); |
| 4958 | __ sw(t5, FieldMemOperand(a1, FixedArray::kMapOffset)); |
| 4959 | __ sw(t1, FieldMemOperand(a1, FixedArray::kLengthOffset)); |
| 4960 | |
| 4961 | Label arguments_loop, arguments_test; |
| 4962 | __ sll(t6, t2, 1); |
| 4963 | __ Subu(a3, a3, Operand(t6)); |
| 4964 | __ jmp(&arguments_test); |
| 4965 | |
| 4966 | __ bind(&arguments_loop); |
| 4967 | __ Subu(a3, a3, Operand(kPointerSize)); |
| 4968 | __ lw(t0, MemOperand(a3, 0)); |
| 4969 | __ Lsa(t5, a1, t2, 1); |
| 4970 | __ sw(t0, FieldMemOperand(t5, FixedArray::kHeaderSize)); |
| 4971 | __ Addu(t2, t2, Operand(Smi::FromInt(1))); |
| 4972 | |
| 4973 | __ bind(&arguments_test); |
| 4974 | __ Branch(&arguments_loop, lt, t2, Operand(t1)); |
| 4975 | |
| 4976 | // Return. |
| 4977 | __ Ret(); |
| 4978 | |
| 4979 | // Do the runtime call to allocate the arguments object. |
| 4980 | // t1 = argument count (tagged) |
| 4981 | __ bind(&runtime); |
| 4982 | __ Push(a1, a3, t1); |
| 4983 | __ TailCallRuntime(Runtime::kNewSloppyArguments); |
| 4984 | } |
| 4985 | |
| 4986 | |
| 4987 | void FastNewStrictArgumentsStub::Generate(MacroAssembler* masm) { |
| 4988 | // ----------- S t a t e ------------- |
| 4989 | // -- a1 : function |
| 4990 | // -- cp : context |
| 4991 | // -- fp : frame pointer |
| 4992 | // -- ra : return address |
| 4993 | // ----------------------------------- |
| 4994 | __ AssertFunction(a1); |
| 4995 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 4996 | // Make a2 point to the JavaScript frame. |
| 4997 | __ mov(a2, fp); |
| 4998 | if (skip_stub_frame()) { |
| 4999 | // For Ignition we need to skip the handler/stub frame to reach the |
| 5000 | // JavaScript frame for the function. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5001 | __ lw(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 5002 | } |
| 5003 | if (FLAG_debug_code) { |
| 5004 | Label ok; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5005 | __ lw(a3, MemOperand(a2, StandardFrameConstants::kFunctionOffset)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 5006 | __ Branch(&ok, eq, a1, Operand(a3)); |
| 5007 | __ Abort(kInvalidFrameForFastNewRestArgumentsStub); |
| 5008 | __ bind(&ok); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5009 | } |
| 5010 | |
| 5011 | // Check if we have an arguments adaptor frame below the function frame. |
| 5012 | Label arguments_adaptor, arguments_done; |
| 5013 | __ lw(a3, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5014 | __ lw(a0, MemOperand(a3, CommonFrameConstants::kContextOrFrameTypeOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5015 | __ Branch(&arguments_adaptor, eq, a0, |
| 5016 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5017 | { |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 5018 | __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5019 | __ lw(a0, |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 5020 | FieldMemOperand(t0, SharedFunctionInfo::kFormalParameterCountOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5021 | __ Lsa(a2, a2, a0, kPointerSizeLog2 - 1); |
| 5022 | __ Addu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset - |
| 5023 | 1 * kPointerSize)); |
| 5024 | } |
| 5025 | __ Branch(&arguments_done); |
| 5026 | __ bind(&arguments_adaptor); |
| 5027 | { |
| 5028 | __ lw(a0, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 5029 | __ Lsa(a2, a3, a0, kPointerSizeLog2 - 1); |
| 5030 | __ Addu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset - |
| 5031 | 1 * kPointerSize)); |
| 5032 | } |
| 5033 | __ bind(&arguments_done); |
| 5034 | |
| 5035 | // ----------- S t a t e ------------- |
| 5036 | // -- cp : context |
| 5037 | // -- a0 : number of rest parameters (tagged) |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 5038 | // -- a1 : function |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5039 | // -- a2 : pointer to first rest parameters |
| 5040 | // -- ra : return address |
| 5041 | // ----------------------------------- |
| 5042 | |
| 5043 | // Allocate space for the strict arguments object plus the backing store. |
| 5044 | Label allocate, done_allocate; |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 5045 | __ li(t0, Operand(JSStrictArgumentsObject::kSize + FixedArray::kHeaderSize)); |
| 5046 | __ Lsa(t0, t0, a0, kPointerSizeLog2 - 1); |
| 5047 | __ Allocate(t0, v0, a3, t1, &allocate, NO_ALLOCATION_FLAGS); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5048 | __ bind(&done_allocate); |
| 5049 | |
| 5050 | // Setup the elements array in v0. |
| 5051 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 5052 | __ sw(at, FieldMemOperand(v0, FixedArray::kMapOffset)); |
| 5053 | __ sw(a0, FieldMemOperand(v0, FixedArray::kLengthOffset)); |
| 5054 | __ Addu(a3, v0, Operand(FixedArray::kHeaderSize)); |
| 5055 | { |
| 5056 | Label loop, done_loop; |
| 5057 | __ sll(at, a0, kPointerSizeLog2 - 1); |
| 5058 | __ Addu(a1, a3, at); |
| 5059 | __ bind(&loop); |
| 5060 | __ Branch(&done_loop, eq, a1, Operand(a3)); |
| 5061 | __ lw(at, MemOperand(a2, 0 * kPointerSize)); |
| 5062 | __ sw(at, FieldMemOperand(a3, 0 * kPointerSize)); |
| 5063 | __ Subu(a2, a2, Operand(1 * kPointerSize)); |
| 5064 | __ Addu(a3, a3, Operand(1 * kPointerSize)); |
| 5065 | __ Branch(&loop); |
| 5066 | __ bind(&done_loop); |
| 5067 | } |
| 5068 | |
| 5069 | // Setup the strict arguments object in a3. |
| 5070 | __ LoadNativeContextSlot(Context::STRICT_ARGUMENTS_MAP_INDEX, at); |
| 5071 | __ sw(at, FieldMemOperand(a3, JSStrictArgumentsObject::kMapOffset)); |
| 5072 | __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex); |
| 5073 | __ sw(at, FieldMemOperand(a3, JSStrictArgumentsObject::kPropertiesOffset)); |
| 5074 | __ sw(v0, FieldMemOperand(a3, JSStrictArgumentsObject::kElementsOffset)); |
| 5075 | __ sw(a0, FieldMemOperand(a3, JSStrictArgumentsObject::kLengthOffset)); |
| 5076 | STATIC_ASSERT(JSStrictArgumentsObject::kSize == 4 * kPointerSize); |
| 5077 | __ Ret(USE_DELAY_SLOT); |
| 5078 | __ mov(v0, a3); // In delay slot |
| 5079 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 5080 | // Fall back to %AllocateInNewSpace (if not too big). |
| 5081 | Label too_big_for_new_space; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5082 | __ bind(&allocate); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 5083 | __ Branch(&too_big_for_new_space, gt, t0, |
| 5084 | Operand(Page::kMaxRegularHeapObjectSize)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5085 | { |
| 5086 | FrameScope scope(masm, StackFrame::INTERNAL); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 5087 | __ SmiTag(t0); |
| 5088 | __ Push(a0, a2, t0); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5089 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 5090 | __ Pop(a0, a2); |
| 5091 | } |
| 5092 | __ jmp(&done_allocate); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5093 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 5094 | // Fall back to %NewStrictArguments. |
| 5095 | __ bind(&too_big_for_new_space); |
| 5096 | __ Push(a1); |
| 5097 | __ TailCallRuntime(Runtime::kNewStrictArguments); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5098 | } |
| 5099 | |
| 5100 | |
| 5101 | void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) { |
| 5102 | Register context_reg = cp; |
| 5103 | Register slot_reg = a2; |
| 5104 | Register value_reg = a0; |
| 5105 | Register cell_reg = t0; |
| 5106 | Register cell_value_reg = t1; |
| 5107 | Register cell_details_reg = t2; |
| 5108 | Label fast_heapobject_case, fast_smi_case, slow_case; |
| 5109 | |
| 5110 | if (FLAG_debug_code) { |
| 5111 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 5112 | __ Check(ne, kUnexpectedValue, value_reg, Operand(at)); |
| 5113 | } |
| 5114 | |
| 5115 | // Go up context chain to the script context. |
| 5116 | for (int i = 0; i < depth(); ++i) { |
| 5117 | __ lw(cell_reg, ContextMemOperand(context_reg, Context::PREVIOUS_INDEX)); |
| 5118 | context_reg = cell_reg; |
| 5119 | } |
| 5120 | |
| 5121 | // Load the PropertyCell at the specified slot. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5122 | __ Lsa(at, context_reg, slot_reg, kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5123 | __ lw(cell_reg, ContextMemOperand(at, 0)); |
| 5124 | |
| 5125 | // Load PropertyDetails for the cell (actually only the cell_type and kind). |
| 5126 | __ lw(cell_details_reg, |
| 5127 | FieldMemOperand(cell_reg, PropertyCell::kDetailsOffset)); |
| 5128 | __ SmiUntag(cell_details_reg); |
| 5129 | __ And(cell_details_reg, cell_details_reg, |
| 5130 | PropertyDetails::PropertyCellTypeField::kMask | |
| 5131 | PropertyDetails::KindField::kMask | |
| 5132 | PropertyDetails::kAttributesReadOnlyMask); |
| 5133 | |
| 5134 | // Check if PropertyCell holds mutable data. |
| 5135 | Label not_mutable_data; |
| 5136 | __ Branch(¬_mutable_data, ne, cell_details_reg, |
| 5137 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5138 | PropertyCellType::kMutable) | |
| 5139 | PropertyDetails::KindField::encode(kData))); |
| 5140 | __ JumpIfSmi(value_reg, &fast_smi_case); |
| 5141 | __ bind(&fast_heapobject_case); |
| 5142 | __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5143 | __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg, |
| 5144 | cell_details_reg, kRAHasNotBeenSaved, kDontSaveFPRegs, |
| 5145 | EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); |
| 5146 | // RecordWriteField clobbers the value register, so we need to reload. |
| 5147 | __ Ret(USE_DELAY_SLOT); |
| 5148 | __ lw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5149 | __ bind(¬_mutable_data); |
| 5150 | |
| 5151 | // Check if PropertyCell value matches the new value (relevant for Constant, |
| 5152 | // ConstantType and Undefined cells). |
| 5153 | Label not_same_value; |
| 5154 | __ lw(cell_value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5155 | __ Branch(¬_same_value, ne, value_reg, Operand(cell_value_reg)); |
| 5156 | // Make sure the PropertyCell is not marked READ_ONLY. |
| 5157 | __ And(at, cell_details_reg, PropertyDetails::kAttributesReadOnlyMask); |
| 5158 | __ Branch(&slow_case, ne, at, Operand(zero_reg)); |
| 5159 | if (FLAG_debug_code) { |
| 5160 | Label done; |
| 5161 | // This can only be true for Constant, ConstantType and Undefined cells, |
| 5162 | // because we never store the_hole via this stub. |
| 5163 | __ Branch(&done, eq, cell_details_reg, |
| 5164 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5165 | PropertyCellType::kConstant) | |
| 5166 | PropertyDetails::KindField::encode(kData))); |
| 5167 | __ Branch(&done, eq, cell_details_reg, |
| 5168 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5169 | PropertyCellType::kConstantType) | |
| 5170 | PropertyDetails::KindField::encode(kData))); |
| 5171 | __ Check(eq, kUnexpectedValue, cell_details_reg, |
| 5172 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5173 | PropertyCellType::kUndefined) | |
| 5174 | PropertyDetails::KindField::encode(kData))); |
| 5175 | __ bind(&done); |
| 5176 | } |
| 5177 | __ Ret(); |
| 5178 | __ bind(¬_same_value); |
| 5179 | |
| 5180 | // Check if PropertyCell contains data with constant type (and is not |
| 5181 | // READ_ONLY). |
| 5182 | __ Branch(&slow_case, ne, cell_details_reg, |
| 5183 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5184 | PropertyCellType::kConstantType) | |
| 5185 | PropertyDetails::KindField::encode(kData))); |
| 5186 | |
| 5187 | // Now either both old and new values must be SMIs or both must be heap |
| 5188 | // objects with same map. |
| 5189 | Label value_is_heap_object; |
| 5190 | __ JumpIfNotSmi(value_reg, &value_is_heap_object); |
| 5191 | __ JumpIfNotSmi(cell_value_reg, &slow_case); |
| 5192 | // Old and new values are SMIs, no need for a write barrier here. |
| 5193 | __ bind(&fast_smi_case); |
| 5194 | __ Ret(USE_DELAY_SLOT); |
| 5195 | __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5196 | __ bind(&value_is_heap_object); |
| 5197 | __ JumpIfSmi(cell_value_reg, &slow_case); |
| 5198 | Register cell_value_map_reg = cell_value_reg; |
| 5199 | __ lw(cell_value_map_reg, |
| 5200 | FieldMemOperand(cell_value_reg, HeapObject::kMapOffset)); |
| 5201 | __ Branch(&fast_heapobject_case, eq, cell_value_map_reg, |
| 5202 | FieldMemOperand(value_reg, HeapObject::kMapOffset)); |
| 5203 | |
| 5204 | // Fallback to the runtime. |
| 5205 | __ bind(&slow_case); |
| 5206 | __ SmiTag(slot_reg); |
| 5207 | __ Push(slot_reg, value_reg); |
| 5208 | __ TailCallRuntime(is_strict(language_mode()) |
| 5209 | ? Runtime::kStoreGlobalViaContext_Strict |
| 5210 | : Runtime::kStoreGlobalViaContext_Sloppy); |
| 5211 | } |
| 5212 | |
| 5213 | |
| 5214 | static int AddressOffset(ExternalReference ref0, ExternalReference ref1) { |
| 5215 | return ref0.address() - ref1.address(); |
| 5216 | } |
| 5217 | |
| 5218 | |
| 5219 | // Calls an API function. Allocates HandleScope, extracts returned value |
| 5220 | // from handle and propagates exceptions. Restores context. stack_space |
| 5221 | // - space to be unwound on exit (includes the call JS arguments space and |
| 5222 | // the additional space allocated for the fast call). |
| 5223 | static void CallApiFunctionAndReturn( |
| 5224 | MacroAssembler* masm, Register function_address, |
| 5225 | ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset, |
| 5226 | MemOperand return_value_operand, MemOperand* context_restore_operand) { |
| 5227 | Isolate* isolate = masm->isolate(); |
| 5228 | ExternalReference next_address = |
| 5229 | ExternalReference::handle_scope_next_address(isolate); |
| 5230 | const int kNextOffset = 0; |
| 5231 | const int kLimitOffset = AddressOffset( |
| 5232 | ExternalReference::handle_scope_limit_address(isolate), next_address); |
| 5233 | const int kLevelOffset = AddressOffset( |
| 5234 | ExternalReference::handle_scope_level_address(isolate), next_address); |
| 5235 | |
| 5236 | DCHECK(function_address.is(a1) || function_address.is(a2)); |
| 5237 | |
| 5238 | Label profiler_disabled; |
| 5239 | Label end_profiler_check; |
| 5240 | __ li(t9, Operand(ExternalReference::is_profiling_address(isolate))); |
| 5241 | __ lb(t9, MemOperand(t9, 0)); |
| 5242 | __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg)); |
| 5243 | |
| 5244 | // Additional parameter is the address of the actual callback. |
| 5245 | __ li(t9, Operand(thunk_ref)); |
| 5246 | __ jmp(&end_profiler_check); |
| 5247 | |
| 5248 | __ bind(&profiler_disabled); |
| 5249 | __ mov(t9, function_address); |
| 5250 | __ bind(&end_profiler_check); |
| 5251 | |
| 5252 | // Allocate HandleScope in callee-save registers. |
| 5253 | __ li(s3, Operand(next_address)); |
| 5254 | __ lw(s0, MemOperand(s3, kNextOffset)); |
| 5255 | __ lw(s1, MemOperand(s3, kLimitOffset)); |
| 5256 | __ lw(s2, MemOperand(s3, kLevelOffset)); |
| 5257 | __ Addu(s2, s2, Operand(1)); |
| 5258 | __ sw(s2, MemOperand(s3, kLevelOffset)); |
| 5259 | |
| 5260 | if (FLAG_log_timer_events) { |
| 5261 | FrameScope frame(masm, StackFrame::MANUAL); |
| 5262 | __ PushSafepointRegisters(); |
| 5263 | __ PrepareCallCFunction(1, a0); |
| 5264 | __ li(a0, Operand(ExternalReference::isolate_address(isolate))); |
| 5265 | __ CallCFunction(ExternalReference::log_enter_external_function(isolate), |
| 5266 | 1); |
| 5267 | __ PopSafepointRegisters(); |
| 5268 | } |
| 5269 | |
| 5270 | // Native call returns to the DirectCEntry stub which redirects to the |
| 5271 | // return address pushed on stack (could have moved after GC). |
| 5272 | // DirectCEntry stub itself is generated early and never moves. |
| 5273 | DirectCEntryStub stub(isolate); |
| 5274 | stub.GenerateCall(masm, t9); |
| 5275 | |
| 5276 | if (FLAG_log_timer_events) { |
| 5277 | FrameScope frame(masm, StackFrame::MANUAL); |
| 5278 | __ PushSafepointRegisters(); |
| 5279 | __ PrepareCallCFunction(1, a0); |
| 5280 | __ li(a0, Operand(ExternalReference::isolate_address(isolate))); |
| 5281 | __ CallCFunction(ExternalReference::log_leave_external_function(isolate), |
| 5282 | 1); |
| 5283 | __ PopSafepointRegisters(); |
| 5284 | } |
| 5285 | |
| 5286 | Label promote_scheduled_exception; |
| 5287 | Label delete_allocated_handles; |
| 5288 | Label leave_exit_frame; |
| 5289 | Label return_value_loaded; |
| 5290 | |
| 5291 | // Load value from ReturnValue. |
| 5292 | __ lw(v0, return_value_operand); |
| 5293 | __ bind(&return_value_loaded); |
| 5294 | |
| 5295 | // No more valid handles (the result handle was the last one). Restore |
| 5296 | // previous handle scope. |
| 5297 | __ sw(s0, MemOperand(s3, kNextOffset)); |
| 5298 | if (__ emit_debug_code()) { |
| 5299 | __ lw(a1, MemOperand(s3, kLevelOffset)); |
| 5300 | __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2)); |
| 5301 | } |
| 5302 | __ Subu(s2, s2, Operand(1)); |
| 5303 | __ sw(s2, MemOperand(s3, kLevelOffset)); |
| 5304 | __ lw(at, MemOperand(s3, kLimitOffset)); |
| 5305 | __ Branch(&delete_allocated_handles, ne, s1, Operand(at)); |
| 5306 | |
| 5307 | // Leave the API exit frame. |
| 5308 | __ bind(&leave_exit_frame); |
| 5309 | |
| 5310 | bool restore_context = context_restore_operand != NULL; |
| 5311 | if (restore_context) { |
| 5312 | __ lw(cp, *context_restore_operand); |
| 5313 | } |
| 5314 | if (stack_space_offset != kInvalidStackOffset) { |
| 5315 | // ExitFrame contains four MIPS argument slots after DirectCEntryStub call |
| 5316 | // so this must be accounted for. |
| 5317 | __ lw(s0, MemOperand(sp, stack_space_offset + kCArgsSlotsSize)); |
| 5318 | } else { |
| 5319 | __ li(s0, Operand(stack_space)); |
| 5320 | } |
| 5321 | __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN, |
| 5322 | stack_space_offset != kInvalidStackOffset); |
| 5323 | |
| 5324 | // Check if the function scheduled an exception. |
| 5325 | __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); |
| 5326 | __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate))); |
| 5327 | __ lw(t1, MemOperand(at)); |
| 5328 | __ Branch(&promote_scheduled_exception, ne, t0, Operand(t1)); |
| 5329 | |
| 5330 | __ Ret(); |
| 5331 | |
| 5332 | // Re-throw by promoting a scheduled exception. |
| 5333 | __ bind(&promote_scheduled_exception); |
| 5334 | __ TailCallRuntime(Runtime::kPromoteScheduledException); |
| 5335 | |
| 5336 | // HandleScope limit has changed. Delete allocated extensions. |
| 5337 | __ bind(&delete_allocated_handles); |
| 5338 | __ sw(s1, MemOperand(s3, kLimitOffset)); |
| 5339 | __ mov(s0, v0); |
| 5340 | __ mov(a0, v0); |
| 5341 | __ PrepareCallCFunction(1, s1); |
| 5342 | __ li(a0, Operand(ExternalReference::isolate_address(isolate))); |
| 5343 | __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate), |
| 5344 | 1); |
| 5345 | __ mov(v0, s0); |
| 5346 | __ jmp(&leave_exit_frame); |
| 5347 | } |
| 5348 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5349 | void CallApiCallbackStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5350 | // ----------- S t a t e ------------- |
| 5351 | // -- a0 : callee |
| 5352 | // -- t0 : call_data |
| 5353 | // -- a2 : holder |
| 5354 | // -- a1 : api_function_address |
| 5355 | // -- cp : context |
| 5356 | // -- |
| 5357 | // -- sp[0] : last argument |
| 5358 | // -- ... |
| 5359 | // -- sp[(argc - 1)* 4] : first argument |
| 5360 | // -- sp[argc * 4] : receiver |
| 5361 | // ----------------------------------- |
| 5362 | |
| 5363 | Register callee = a0; |
| 5364 | Register call_data = t0; |
| 5365 | Register holder = a2; |
| 5366 | Register api_function_address = a1; |
| 5367 | Register context = cp; |
| 5368 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5369 | typedef FunctionCallbackArguments FCA; |
| 5370 | |
| 5371 | STATIC_ASSERT(FCA::kContextSaveIndex == 6); |
| 5372 | STATIC_ASSERT(FCA::kCalleeIndex == 5); |
| 5373 | STATIC_ASSERT(FCA::kDataIndex == 4); |
| 5374 | STATIC_ASSERT(FCA::kReturnValueOffset == 3); |
| 5375 | STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); |
| 5376 | STATIC_ASSERT(FCA::kIsolateIndex == 1); |
| 5377 | STATIC_ASSERT(FCA::kHolderIndex == 0); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 5378 | STATIC_ASSERT(FCA::kNewTargetIndex == 7); |
| 5379 | STATIC_ASSERT(FCA::kArgsLength == 8); |
| 5380 | |
| 5381 | // new target |
| 5382 | __ PushRoot(Heap::kUndefinedValueRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5383 | |
| 5384 | // Save context, callee and call data. |
| 5385 | __ Push(context, callee, call_data); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5386 | if (!is_lazy()) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5387 | // Load context from callee. |
| 5388 | __ lw(context, FieldMemOperand(callee, JSFunction::kContextOffset)); |
| 5389 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5390 | |
| 5391 | Register scratch = call_data; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5392 | if (!call_data_undefined()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5393 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 5394 | } |
| 5395 | // Push return value and default return value. |
| 5396 | __ Push(scratch, scratch); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5397 | __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5398 | // Push isolate and holder. |
| 5399 | __ Push(scratch, holder); |
| 5400 | |
| 5401 | // Prepare arguments. |
| 5402 | __ mov(scratch, sp); |
| 5403 | |
| 5404 | // Allocate the v8::Arguments structure in the arguments' space since |
| 5405 | // it's not controlled by GC. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 5406 | const int kApiStackSpace = 3; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5407 | |
| 5408 | FrameScope frame_scope(masm, StackFrame::MANUAL); |
| 5409 | __ EnterExitFrame(false, kApiStackSpace); |
| 5410 | |
| 5411 | DCHECK(!api_function_address.is(a0) && !scratch.is(a0)); |
| 5412 | // a0 = FunctionCallbackInfo& |
| 5413 | // Arguments is after the return address. |
| 5414 | __ Addu(a0, sp, Operand(1 * kPointerSize)); |
| 5415 | // FunctionCallbackInfo::implicit_args_ |
| 5416 | __ sw(scratch, MemOperand(a0, 0 * kPointerSize)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5417 | // FunctionCallbackInfo::values_ |
| 5418 | __ Addu(at, scratch, Operand((FCA::kArgsLength - 1 + argc()) * kPointerSize)); |
| 5419 | __ sw(at, MemOperand(a0, 1 * kPointerSize)); |
| 5420 | // FunctionCallbackInfo::length_ = argc |
| 5421 | __ li(at, Operand(argc())); |
| 5422 | __ sw(at, MemOperand(a0, 2 * kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5423 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5424 | ExternalReference thunk_ref = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5425 | ExternalReference::invoke_function_callback(masm->isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5426 | |
| 5427 | AllowExternalCallThatCantCauseGC scope(masm); |
| 5428 | MemOperand context_restore_operand( |
| 5429 | fp, (2 + FCA::kContextSaveIndex) * kPointerSize); |
| 5430 | // Stores return the first js argument. |
| 5431 | int return_value_offset = 0; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5432 | if (is_store()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5433 | return_value_offset = 2 + FCA::kArgsLength; |
| 5434 | } else { |
| 5435 | return_value_offset = 2 + FCA::kReturnValueOffset; |
| 5436 | } |
| 5437 | MemOperand return_value_operand(fp, return_value_offset * kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5438 | int stack_space = 0; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 5439 | int32_t stack_space_offset = 3 * kPointerSize; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5440 | stack_space = argc() + FCA::kArgsLength + 1; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 5441 | // TODO(adamk): Why are we clobbering this immediately? |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5442 | stack_space_offset = kInvalidStackOffset; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5443 | CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space, |
| 5444 | stack_space_offset, return_value_operand, |
| 5445 | &context_restore_operand); |
| 5446 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5447 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5448 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5449 | void CallApiGetterStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 5450 | // Build v8::PropertyCallbackInfo::args_ array on the stack and push property |
| 5451 | // name below the exit frame to make GC aware of them. |
| 5452 | STATIC_ASSERT(PropertyCallbackArguments::kShouldThrowOnErrorIndex == 0); |
| 5453 | STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 1); |
| 5454 | STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 2); |
| 5455 | STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 3); |
| 5456 | STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 4); |
| 5457 | STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 5); |
| 5458 | STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 6); |
| 5459 | STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 7); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5460 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 5461 | Register receiver = ApiGetterDescriptor::ReceiverRegister(); |
| 5462 | Register holder = ApiGetterDescriptor::HolderRegister(); |
| 5463 | Register callback = ApiGetterDescriptor::CallbackRegister(); |
| 5464 | Register scratch = t0; |
| 5465 | DCHECK(!AreAliased(receiver, holder, callback, scratch)); |
| 5466 | |
| 5467 | Register api_function_address = a2; |
| 5468 | |
| 5469 | // Here and below +1 is for name() pushed after the args_ array. |
| 5470 | typedef PropertyCallbackArguments PCA; |
| 5471 | __ Subu(sp, sp, (PCA::kArgsLength + 1) * kPointerSize); |
| 5472 | __ sw(receiver, MemOperand(sp, (PCA::kThisIndex + 1) * kPointerSize)); |
| 5473 | __ lw(scratch, FieldMemOperand(callback, AccessorInfo::kDataOffset)); |
| 5474 | __ sw(scratch, MemOperand(sp, (PCA::kDataIndex + 1) * kPointerSize)); |
| 5475 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 5476 | __ sw(scratch, MemOperand(sp, (PCA::kReturnValueOffset + 1) * kPointerSize)); |
| 5477 | __ sw(scratch, MemOperand(sp, (PCA::kReturnValueDefaultValueIndex + 1) * |
| 5478 | kPointerSize)); |
| 5479 | __ li(scratch, Operand(ExternalReference::isolate_address(isolate()))); |
| 5480 | __ sw(scratch, MemOperand(sp, (PCA::kIsolateIndex + 1) * kPointerSize)); |
| 5481 | __ sw(holder, MemOperand(sp, (PCA::kHolderIndex + 1) * kPointerSize)); |
| 5482 | // should_throw_on_error -> false |
| 5483 | DCHECK(Smi::FromInt(0) == nullptr); |
| 5484 | __ sw(zero_reg, |
| 5485 | MemOperand(sp, (PCA::kShouldThrowOnErrorIndex + 1) * kPointerSize)); |
| 5486 | __ lw(scratch, FieldMemOperand(callback, AccessorInfo::kNameOffset)); |
| 5487 | __ sw(scratch, MemOperand(sp, 0 * kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5488 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5489 | // v8::PropertyCallbackInfo::args_ array and name handle. |
| 5490 | const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1; |
| 5491 | |
| 5492 | // Load address of v8::PropertyAccessorInfo::args_ array and name handle. |
| 5493 | __ mov(a0, sp); // a0 = Handle<Name> |
| 5494 | __ Addu(a1, a0, Operand(1 * kPointerSize)); // a1 = v8::PCI::args_ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5495 | |
| 5496 | const int kApiStackSpace = 1; |
| 5497 | FrameScope frame_scope(masm, StackFrame::MANUAL); |
| 5498 | __ EnterExitFrame(false, kApiStackSpace); |
| 5499 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5500 | // Create v8::PropertyCallbackInfo object on the stack and initialize |
| 5501 | // it's args_ field. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5502 | __ sw(a1, MemOperand(sp, 1 * kPointerSize)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5503 | __ Addu(a1, sp, Operand(1 * kPointerSize)); // a1 = v8::PropertyCallbackInfo& |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5504 | |
| 5505 | ExternalReference thunk_ref = |
| 5506 | ExternalReference::invoke_accessor_getter_callback(isolate()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5507 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 5508 | __ lw(scratch, FieldMemOperand(callback, AccessorInfo::kJsGetterOffset)); |
| 5509 | __ lw(api_function_address, |
| 5510 | FieldMemOperand(scratch, Foreign::kForeignAddressOffset)); |
| 5511 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5512 | // +3 is to skip prolog, return address and name handle. |
| 5513 | MemOperand return_value_operand( |
| 5514 | fp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5515 | CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, |
| 5516 | kStackUnwindSpace, kInvalidStackOffset, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5517 | return_value_operand, NULL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5518 | } |
| 5519 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5520 | #undef __ |
| 5521 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5522 | } // namespace internal |
| 5523 | } // namespace v8 |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5524 | |
| 5525 | #endif // V8_TARGET_ARCH_MIPS |