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 | |
| 24 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 25 | static void InitializeArrayConstructorDescriptor( |
| 26 | Isolate* isolate, CodeStubDescriptor* descriptor, |
| 27 | int constant_stack_parameter_count) { |
| 28 | Address deopt_handler = Runtime::FunctionForId( |
| 29 | Runtime::kArrayConstructor)->entry; |
| 30 | |
| 31 | if (constant_stack_parameter_count == 0) { |
| 32 | descriptor->Initialize(deopt_handler, constant_stack_parameter_count, |
| 33 | JS_FUNCTION_STUB_MODE); |
| 34 | } else { |
| 35 | descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 36 | JS_FUNCTION_STUB_MODE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | |
| 40 | |
| 41 | static void InitializeInternalArrayConstructorDescriptor( |
| 42 | Isolate* isolate, CodeStubDescriptor* descriptor, |
| 43 | int constant_stack_parameter_count) { |
| 44 | Address deopt_handler = Runtime::FunctionForId( |
| 45 | Runtime::kInternalArrayConstructor)->entry; |
| 46 | |
| 47 | if (constant_stack_parameter_count == 0) { |
| 48 | descriptor->Initialize(deopt_handler, constant_stack_parameter_count, |
| 49 | JS_FUNCTION_STUB_MODE); |
| 50 | } else { |
| 51 | descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 52 | JS_FUNCTION_STUB_MODE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | |
| 56 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 57 | void ArraySingleArgumentConstructorStub::InitializeDescriptor( |
| 58 | CodeStubDescriptor* descriptor) { |
| 59 | InitializeArrayConstructorDescriptor(isolate(), descriptor, 1); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | void ArrayNArgumentsConstructorStub::InitializeDescriptor( |
| 64 | CodeStubDescriptor* descriptor) { |
| 65 | InitializeArrayConstructorDescriptor(isolate(), descriptor, -1); |
| 66 | } |
| 67 | |
| 68 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 69 | void FastArrayPushStub::InitializeDescriptor(CodeStubDescriptor* descriptor) { |
| 70 | Address deopt_handler = Runtime::FunctionForId(Runtime::kArrayPush)->entry; |
| 71 | descriptor->Initialize(a0, deopt_handler, -1, JS_FUNCTION_STUB_MODE); |
| 72 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 73 | |
| 74 | void InternalArraySingleArgumentConstructorStub::InitializeDescriptor( |
| 75 | CodeStubDescriptor* descriptor) { |
| 76 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | void InternalArrayNArgumentsConstructorStub::InitializeDescriptor( |
| 81 | CodeStubDescriptor* descriptor) { |
| 82 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1); |
| 83 | } |
| 84 | |
| 85 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 86 | #define __ ACCESS_MASM(masm) |
| 87 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 88 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 89 | Condition cc); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 90 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 91 | Register lhs, |
| 92 | Register rhs, |
| 93 | Label* rhs_not_nan, |
| 94 | Label* slow, |
| 95 | bool strict); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 96 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 97 | Register lhs, |
| 98 | Register rhs); |
| 99 | |
| 100 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 101 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm, |
| 102 | ExternalReference miss) { |
| 103 | // Update the static counter each time a new code stub is generated. |
| 104 | isolate()->counters()->code_stubs()->Increment(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 105 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 106 | CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 107 | int param_count = descriptor.GetRegisterParameterCount(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 108 | { |
| 109 | // Call the runtime system in a fresh internal frame. |
| 110 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 111 | DCHECK(param_count == 0 || |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 112 | a0.is(descriptor.GetRegisterParameter(param_count - 1))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 113 | // Push arguments, adjust sp. |
| 114 | __ Subu(sp, sp, Operand(param_count * kPointerSize)); |
| 115 | for (int i = 0; i < param_count; ++i) { |
| 116 | // Store argument to stack. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 117 | __ sw(descriptor.GetRegisterParameter(i), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 118 | MemOperand(sp, (param_count - 1 - i) * kPointerSize)); |
| 119 | } |
| 120 | __ CallExternalReference(miss, param_count); |
| 121 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 122 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 123 | __ Ret(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 127 | void DoubleToIStub::Generate(MacroAssembler* masm) { |
| 128 | Label out_of_range, only_low, negate, done; |
| 129 | Register input_reg = source(); |
| 130 | Register result_reg = destination(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 131 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 132 | int double_offset = offset(); |
| 133 | // Account for saved regs if input is sp. |
| 134 | if (input_reg.is(sp)) double_offset += 3 * kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 135 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 136 | Register scratch = |
| 137 | GetRegisterThatIsNotOneOf(input_reg, result_reg); |
| 138 | Register scratch2 = |
| 139 | GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch); |
| 140 | Register scratch3 = |
| 141 | GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch2); |
| 142 | DoubleRegister double_scratch = kLithiumScratchDouble; |
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 | __ Push(scratch, scratch2, scratch3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 145 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 146 | if (!skip_fastpath()) { |
| 147 | // Load double input. |
| 148 | __ ldc1(double_scratch, MemOperand(input_reg, double_offset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 149 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 150 | // Clear cumulative exception flags and save the FCSR. |
| 151 | __ cfc1(scratch2, FCSR); |
| 152 | __ ctc1(zero_reg, FCSR); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 153 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 154 | // Try a conversion to a signed integer. |
| 155 | __ Trunc_w_d(double_scratch, double_scratch); |
| 156 | // Move the converted value into the result register. |
| 157 | __ mfc1(scratch3, double_scratch); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 158 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 159 | // Retrieve and restore the FCSR. |
| 160 | __ cfc1(scratch, FCSR); |
| 161 | __ ctc1(scratch2, FCSR); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 162 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 163 | // Check for overflow and NaNs. |
| 164 | __ And( |
| 165 | scratch, scratch, |
| 166 | kFCSROverflowFlagMask | kFCSRUnderflowFlagMask |
| 167 | | kFCSRInvalidOpFlagMask); |
| 168 | // If we had no exceptions then set result_reg and we are done. |
| 169 | Label error; |
| 170 | __ Branch(&error, ne, scratch, Operand(zero_reg)); |
| 171 | __ Move(result_reg, scratch3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 172 | __ Branch(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 173 | __ bind(&error); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 176 | // Load the double value and perform a manual truncation. |
| 177 | Register input_high = scratch2; |
| 178 | Register input_low = scratch3; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 179 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 180 | __ lw(input_low, |
| 181 | MemOperand(input_reg, double_offset + Register::kMantissaOffset)); |
| 182 | __ lw(input_high, |
| 183 | MemOperand(input_reg, double_offset + Register::kExponentOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 184 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 185 | Label normal_exponent, restore_sign; |
| 186 | // Extract the biased exponent in result. |
| 187 | __ Ext(result_reg, |
| 188 | input_high, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 189 | HeapNumber::kExponentShift, |
| 190 | HeapNumber::kExponentBits); |
| 191 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 192 | // Check for Infinity and NaNs, which should return 0. |
| 193 | __ Subu(scratch, result_reg, HeapNumber::kExponentMask); |
| 194 | __ Movz(result_reg, zero_reg, scratch); |
| 195 | __ Branch(&done, eq, scratch, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 196 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 197 | // Express exponent as delta to (number of mantissa bits + 31). |
| 198 | __ Subu(result_reg, |
| 199 | result_reg, |
| 200 | Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 201 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 202 | // If the delta is strictly positive, all bits would be shifted away, |
| 203 | // which means that we can return 0. |
| 204 | __ Branch(&normal_exponent, le, result_reg, Operand(zero_reg)); |
| 205 | __ mov(result_reg, zero_reg); |
| 206 | __ Branch(&done); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 207 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 208 | __ bind(&normal_exponent); |
| 209 | const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 210 | // Calculate shift. |
| 211 | __ Addu(scratch, result_reg, Operand(kShiftBase + HeapNumber::kMantissaBits)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 212 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 213 | // Save the sign. |
| 214 | Register sign = result_reg; |
| 215 | result_reg = no_reg; |
| 216 | __ And(sign, input_high, Operand(HeapNumber::kSignMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 217 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 218 | // On ARM shifts > 31 bits are valid and will result in zero. On MIPS we need |
| 219 | // to check for this specific case. |
| 220 | Label high_shift_needed, high_shift_done; |
| 221 | __ Branch(&high_shift_needed, lt, scratch, Operand(32)); |
| 222 | __ mov(input_high, zero_reg); |
| 223 | __ Branch(&high_shift_done); |
| 224 | __ bind(&high_shift_needed); |
| 225 | |
| 226 | // Set the implicit 1 before the mantissa part in input_high. |
| 227 | __ Or(input_high, |
| 228 | input_high, |
| 229 | Operand(1 << HeapNumber::kMantissaBitsInTopWord)); |
| 230 | // Shift the mantissa bits to the correct position. |
| 231 | // We don't need to clear non-mantissa bits as they will be shifted away. |
| 232 | // If they weren't, it would mean that the answer is in the 32bit range. |
| 233 | __ sllv(input_high, input_high, scratch); |
| 234 | |
| 235 | __ bind(&high_shift_done); |
| 236 | |
| 237 | // Replace the shifted bits with bits from the lower mantissa word. |
| 238 | Label pos_shift, shift_done; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 239 | __ li(at, 32); |
| 240 | __ subu(scratch, at, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 241 | __ Branch(&pos_shift, ge, scratch, Operand(zero_reg)); |
| 242 | |
| 243 | // Negate scratch. |
| 244 | __ Subu(scratch, zero_reg, scratch); |
| 245 | __ sllv(input_low, input_low, scratch); |
| 246 | __ Branch(&shift_done); |
| 247 | |
| 248 | __ bind(&pos_shift); |
| 249 | __ srlv(input_low, input_low, scratch); |
| 250 | |
| 251 | __ bind(&shift_done); |
| 252 | __ Or(input_high, input_high, Operand(input_low)); |
| 253 | // Restore sign if necessary. |
| 254 | __ mov(scratch, sign); |
| 255 | result_reg = sign; |
| 256 | sign = no_reg; |
| 257 | __ Subu(result_reg, zero_reg, input_high); |
| 258 | __ Movz(result_reg, input_high, scratch); |
| 259 | |
| 260 | __ bind(&done); |
| 261 | |
| 262 | __ Pop(scratch, scratch2, scratch3); |
| 263 | __ Ret(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 267 | // Handle the case where the lhs and rhs are the same object. |
| 268 | // Equality is almost reflexive (everything but NaN), so this is a test |
| 269 | // for "identity and not NaN". |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 270 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 271 | Condition cc) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 272 | Label not_identical; |
| 273 | Label heap_number, return_equal; |
| 274 | Register exp_mask_reg = t5; |
| 275 | |
| 276 | __ Branch(¬_identical, ne, a0, Operand(a1)); |
| 277 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 278 | __ li(exp_mask_reg, Operand(HeapNumber::kExponentMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 279 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 280 | // Test for NaN. Sadly, we can't just compare to Factory::nan_value(), |
| 281 | // so we do the second best thing - test it ourselves. |
| 282 | // They are both equal and they are not both Smis so both of them are not |
| 283 | // Smis. If it's not a heap number, then return equal. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 284 | __ GetObjectType(a0, t4, t4); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 285 | if (cc == less || cc == greater) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 286 | // Call runtime on identical JSObjects. |
| 287 | __ Branch(slow, greater, t4, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 288 | // Call runtime on identical symbols since we need to throw a TypeError. |
| 289 | __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE)); |
| 290 | // Call runtime on identical SIMD values since we must throw a TypeError. |
| 291 | __ Branch(slow, eq, t4, Operand(SIMD128_VALUE_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 292 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 293 | __ Branch(&heap_number, eq, t4, Operand(HEAP_NUMBER_TYPE)); |
| 294 | // Comparing JS objects with <=, >= is complicated. |
| 295 | if (cc != eq) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 296 | __ Branch(slow, greater, t4, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 297 | // Call runtime on identical symbols since we need to throw a TypeError. |
| 298 | __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE)); |
| 299 | // Call runtime on identical SIMD values since we must throw a TypeError. |
| 300 | __ Branch(slow, eq, t4, Operand(SIMD128_VALUE_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 301 | // Normally here we fall through to return_equal, but undefined is |
| 302 | // special: (undefined == undefined) == true, but |
| 303 | // (undefined <= undefined) == false! See ECMAScript 11.8.5. |
| 304 | if (cc == less_equal || cc == greater_equal) { |
| 305 | __ Branch(&return_equal, ne, t4, Operand(ODDBALL_TYPE)); |
| 306 | __ LoadRoot(t2, Heap::kUndefinedValueRootIndex); |
| 307 | __ Branch(&return_equal, ne, a0, Operand(t2)); |
| 308 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 309 | __ Ret(USE_DELAY_SLOT); |
| 310 | if (cc == le) { |
| 311 | // undefined <= undefined should fail. |
| 312 | __ li(v0, Operand(GREATER)); |
| 313 | } else { |
| 314 | // undefined >= undefined should fail. |
| 315 | __ li(v0, Operand(LESS)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | __ bind(&return_equal); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 322 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 323 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 324 | if (cc == less) { |
| 325 | __ li(v0, Operand(GREATER)); // Things aren't less than themselves. |
| 326 | } else if (cc == greater) { |
| 327 | __ li(v0, Operand(LESS)); // Things aren't greater than themselves. |
| 328 | } else { |
| 329 | __ mov(v0, zero_reg); // Things are <=, >=, ==, === themselves. |
| 330 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 331 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 332 | // For less and greater we don't have to check for NaN since the result of |
| 333 | // x < x is false regardless. For the others here is some code to check |
| 334 | // for NaN. |
| 335 | if (cc != lt && cc != gt) { |
| 336 | __ bind(&heap_number); |
| 337 | // It is a heap number, so return non-equal if it's NaN and equal if it's |
| 338 | // not NaN. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 339 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 340 | // The representation of NaN values has all exponent bits (52..62) set, |
| 341 | // and not all mantissa bits (0..51) clear. |
| 342 | // Read top bits of double representation (second word of value). |
| 343 | __ lw(t2, FieldMemOperand(a0, HeapNumber::kExponentOffset)); |
| 344 | // Test that exponent bits are all set. |
| 345 | __ And(t3, t2, Operand(exp_mask_reg)); |
| 346 | // If all bits not set (ne cond), then not a NaN, objects are equal. |
| 347 | __ Branch(&return_equal, ne, t3, Operand(exp_mask_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 348 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 349 | // Shift out flag and all exponent bits, retaining only mantissa. |
| 350 | __ sll(t2, t2, HeapNumber::kNonMantissaBitsInTopWord); |
| 351 | // Or with all low-bits of mantissa. |
| 352 | __ lw(t3, FieldMemOperand(a0, HeapNumber::kMantissaOffset)); |
| 353 | __ Or(v0, t3, Operand(t2)); |
| 354 | // For equal we already have the right value in v0: Return zero (equal) |
| 355 | // if all bits in mantissa are zero (it's an Infinity) and non-zero if |
| 356 | // not (it's a NaN). For <= and >= we need to load v0 with the failing |
| 357 | // value if it's a NaN. |
| 358 | if (cc != eq) { |
| 359 | // All-zero means Infinity means equal. |
| 360 | __ Ret(eq, v0, Operand(zero_reg)); |
| 361 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 362 | __ Ret(USE_DELAY_SLOT); |
| 363 | if (cc == le) { |
| 364 | __ li(v0, Operand(GREATER)); // NaN <= NaN should fail. |
| 365 | } else { |
| 366 | __ li(v0, Operand(LESS)); // NaN >= NaN should fail. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 367 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 368 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 369 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 370 | // No fall through here. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 371 | |
| 372 | __ bind(¬_identical); |
| 373 | } |
| 374 | |
| 375 | |
| 376 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 377 | Register lhs, |
| 378 | Register rhs, |
| 379 | Label* both_loaded_as_doubles, |
| 380 | Label* slow, |
| 381 | bool strict) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 382 | DCHECK((lhs.is(a0) && rhs.is(a1)) || |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 383 | (lhs.is(a1) && rhs.is(a0))); |
| 384 | |
| 385 | Label lhs_is_smi; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 386 | __ JumpIfSmi(lhs, &lhs_is_smi); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 387 | // Rhs is a Smi. |
| 388 | // Check whether the non-smi is a heap number. |
| 389 | __ GetObjectType(lhs, t4, t4); |
| 390 | if (strict) { |
| 391 | // If lhs was not a number and rhs was a Smi then strict equality cannot |
| 392 | // succeed. Return non-equal (lhs is already not zero). |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 393 | __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 394 | __ mov(v0, lhs); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 395 | } else { |
| 396 | // Smi compared non-strictly with a non-Smi non-heap-number. Call |
| 397 | // the runtime. |
| 398 | __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE)); |
| 399 | } |
| 400 | |
| 401 | // Rhs is a smi, lhs is a number. |
| 402 | // Convert smi rhs to double. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 403 | __ sra(at, rhs, kSmiTagSize); |
| 404 | __ mtc1(at, f14); |
| 405 | __ cvt_d_w(f14, f14); |
| 406 | __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 407 | |
| 408 | // We now have both loaded as doubles. |
| 409 | __ jmp(both_loaded_as_doubles); |
| 410 | |
| 411 | __ bind(&lhs_is_smi); |
| 412 | // Lhs is a Smi. Check whether the non-smi is a heap number. |
| 413 | __ GetObjectType(rhs, t4, t4); |
| 414 | if (strict) { |
| 415 | // If lhs was not a number and rhs was a Smi then strict equality cannot |
| 416 | // succeed. Return non-equal. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 417 | __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 418 | __ li(v0, Operand(1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 419 | } else { |
| 420 | // Smi compared non-strictly with a non-Smi non-heap-number. Call |
| 421 | // the runtime. |
| 422 | __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE)); |
| 423 | } |
| 424 | |
| 425 | // Lhs is a smi, rhs is a number. |
| 426 | // Convert smi lhs to double. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 427 | __ sra(at, lhs, kSmiTagSize); |
| 428 | __ mtc1(at, f12); |
| 429 | __ cvt_d_w(f12, f12); |
| 430 | __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 431 | // Fall through to both_loaded_as_doubles. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 435 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 436 | Register lhs, |
| 437 | Register rhs) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 438 | // 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] | 439 | // not equal since their pointers are different. |
| 440 | // There is no test for undetectability in strict equality. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 441 | STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 442 | Label first_non_object; |
| 443 | // 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] | 444 | // FIRST_JS_RECEIVER_TYPE. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 445 | __ GetObjectType(lhs, a2, a2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 446 | __ Branch(&first_non_object, less, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 447 | |
| 448 | // Return non-zero. |
| 449 | Label return_not_equal; |
| 450 | __ bind(&return_not_equal); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 451 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 452 | __ li(v0, Operand(1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 453 | |
| 454 | __ bind(&first_non_object); |
| 455 | // Check for oddballs: true, false, null, undefined. |
| 456 | __ Branch(&return_not_equal, eq, a2, Operand(ODDBALL_TYPE)); |
| 457 | |
| 458 | __ GetObjectType(rhs, a3, a3); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 459 | __ Branch(&return_not_equal, greater, a3, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 460 | |
| 461 | // Check for oddballs: true, false, null, undefined. |
| 462 | __ Branch(&return_not_equal, eq, a3, Operand(ODDBALL_TYPE)); |
| 463 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 464 | // Now that we have the types we might as well check for |
| 465 | // internalized-internalized. |
| 466 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 467 | __ Or(a2, a2, Operand(a3)); |
| 468 | __ And(at, a2, Operand(kIsNotStringMask | kIsNotInternalizedMask)); |
| 469 | __ Branch(&return_not_equal, eq, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | |
| 473 | static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm, |
| 474 | Register lhs, |
| 475 | Register rhs, |
| 476 | Label* both_loaded_as_doubles, |
| 477 | Label* not_heap_numbers, |
| 478 | Label* slow) { |
| 479 | __ GetObjectType(lhs, a3, a2); |
| 480 | __ Branch(not_heap_numbers, ne, a2, Operand(HEAP_NUMBER_TYPE)); |
| 481 | __ lw(a2, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 482 | // If first was a heap number & second wasn't, go to slow case. |
| 483 | __ Branch(slow, ne, a3, Operand(a2)); |
| 484 | |
| 485 | // Both are heap numbers. Load them up then jump to the code we have |
| 486 | // for that. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 487 | __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 488 | __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 489 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 490 | __ jmp(both_loaded_as_doubles); |
| 491 | } |
| 492 | |
| 493 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 494 | // Fast negative check for internalized-to-internalized equality. |
| 495 | static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 496 | Register lhs, Register rhs, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 497 | Label* possible_strings, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 498 | Label* runtime_call) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 499 | DCHECK((lhs.is(a0) && rhs.is(a1)) || |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 500 | (lhs.is(a1) && rhs.is(a0))); |
| 501 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 502 | // a2 is object type of rhs. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 503 | Label object_test, return_equal, return_unequal, undetectable; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 504 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 505 | __ And(at, a2, Operand(kIsNotStringMask)); |
| 506 | __ Branch(&object_test, ne, at, Operand(zero_reg)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 507 | __ And(at, a2, Operand(kIsNotInternalizedMask)); |
| 508 | __ Branch(possible_strings, ne, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 509 | __ GetObjectType(rhs, a3, a3); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 510 | __ Branch(runtime_call, ge, a3, Operand(FIRST_NONSTRING_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 511 | __ And(at, a3, Operand(kIsNotInternalizedMask)); |
| 512 | __ Branch(possible_strings, ne, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 513 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 514 | // Both are internalized. We already checked they weren't the same pointer so |
| 515 | // they are not equal. Return non-equal by returning the non-zero object |
| 516 | // pointer in v0. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 517 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 518 | __ mov(v0, a0); // In delay slot. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 519 | |
| 520 | __ bind(&object_test); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 521 | __ lw(a2, FieldMemOperand(lhs, HeapObject::kMapOffset)); |
| 522 | __ lw(a3, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 523 | __ lbu(t0, FieldMemOperand(a2, Map::kBitFieldOffset)); |
| 524 | __ lbu(t1, FieldMemOperand(a3, Map::kBitFieldOffset)); |
| 525 | __ And(at, t0, Operand(1 << Map::kIsUndetectable)); |
| 526 | __ Branch(&undetectable, ne, at, Operand(zero_reg)); |
| 527 | __ And(at, t1, Operand(1 << Map::kIsUndetectable)); |
| 528 | __ Branch(&return_unequal, ne, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 529 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 530 | __ GetInstanceType(a2, a2); |
| 531 | __ Branch(runtime_call, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 532 | __ GetInstanceType(a3, a3); |
| 533 | __ Branch(runtime_call, lt, a3, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 534 | |
| 535 | __ bind(&return_unequal); |
| 536 | // Return non-equal by returning the non-zero object pointer in v0. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 537 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 538 | __ mov(v0, a0); // In delay slot. |
| 539 | |
| 540 | __ bind(&undetectable); |
| 541 | __ And(at, t1, Operand(1 << Map::kIsUndetectable)); |
| 542 | __ Branch(&return_unequal, eq, at, Operand(zero_reg)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 543 | |
| 544 | // If both sides are JSReceivers, then the result is false according to |
| 545 | // the HTML specification, which says that only comparisons with null or |
| 546 | // undefined are affected by special casing for document.all. |
| 547 | __ GetInstanceType(a2, a2); |
| 548 | __ Branch(&return_equal, eq, a2, Operand(ODDBALL_TYPE)); |
| 549 | __ GetInstanceType(a3, a3); |
| 550 | __ Branch(&return_unequal, ne, a3, Operand(ODDBALL_TYPE)); |
| 551 | |
| 552 | __ bind(&return_equal); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 553 | __ Ret(USE_DELAY_SLOT); |
| 554 | __ li(v0, Operand(EQUAL)); // In delay slot. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 558 | static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input, |
| 559 | Register scratch, |
| 560 | CompareICState::State expected, |
| 561 | Label* fail) { |
| 562 | Label ok; |
| 563 | if (expected == CompareICState::SMI) { |
| 564 | __ JumpIfNotSmi(input, fail); |
| 565 | } else if (expected == CompareICState::NUMBER) { |
| 566 | __ JumpIfSmi(input, &ok); |
| 567 | __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail, |
| 568 | DONT_DO_SMI_CHECK); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 569 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 570 | // We could be strict about internalized/string here, but as long as |
| 571 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 572 | __ bind(&ok); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 576 | // On entry a1 and a2 are the values to be compared. |
| 577 | // On exit a0 is 0, positive or negative to indicate the result of |
| 578 | // the comparison. |
| 579 | void CompareICStub::GenerateGeneric(MacroAssembler* masm) { |
| 580 | Register lhs = a1; |
| 581 | Register rhs = a0; |
| 582 | Condition cc = GetCondition(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 583 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 584 | Label miss; |
| 585 | CompareICStub_CheckInputType(masm, lhs, a2, left(), &miss); |
| 586 | CompareICStub_CheckInputType(masm, rhs, a3, right(), &miss); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 587 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 588 | Label slow; // Call builtin. |
| 589 | Label not_smis, both_loaded_as_doubles; |
| 590 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 591 | Label not_two_smis, smi_done; |
| 592 | __ Or(a2, a1, a0); |
| 593 | __ JumpIfNotSmi(a2, ¬_two_smis); |
| 594 | __ sra(a1, a1, 1); |
| 595 | __ sra(a0, a0, 1); |
| 596 | __ Ret(USE_DELAY_SLOT); |
| 597 | __ subu(v0, a1, a0); |
| 598 | __ bind(¬_two_smis); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 599 | |
| 600 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 601 | // it is certain that at least one operand isn't a smi. |
| 602 | |
| 603 | // Handle the case where the objects are identical. Either returns the answer |
| 604 | // 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] | 605 | EmitIdenticalObjectComparison(masm, &slow, cc); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 606 | |
| 607 | // If either is a Smi (we know that not both are), then they can only |
| 608 | // be strictly equal if the other is a HeapNumber. |
| 609 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 610 | DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 611 | __ And(t2, lhs, Operand(rhs)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 612 | __ JumpIfNotSmi(t2, ¬_smis, t0); |
| 613 | // One operand is a smi. EmitSmiNonsmiComparison generates code that can: |
| 614 | // 1) Return the answer. |
| 615 | // 2) Go to slow. |
| 616 | // 3) Fall through to both_loaded_as_doubles. |
| 617 | // 4) Jump to rhs_not_nan. |
| 618 | // In cases 3 and 4 we have found out we were dealing with a number-number |
| 619 | // comparison and the numbers have been loaded into f12 and f14 as doubles, |
| 620 | // 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] | 621 | EmitSmiNonsmiComparison(masm, lhs, rhs, |
| 622 | &both_loaded_as_doubles, &slow, strict()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 623 | |
| 624 | __ bind(&both_loaded_as_doubles); |
| 625 | // f12, f14 are the double representations of the left hand side |
| 626 | // and the right hand side if we have FPU. Otherwise a2, a3 represent |
| 627 | // left hand side and a0, a1 represent right hand side. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 628 | Label nan; |
| 629 | __ li(t0, Operand(LESS)); |
| 630 | __ li(t1, Operand(GREATER)); |
| 631 | __ li(t2, Operand(EQUAL)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 632 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 633 | // Check if either rhs or lhs is NaN. |
| 634 | __ BranchF(NULL, &nan, eq, f12, f14); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 635 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 636 | // Check if LESS condition is satisfied. If true, move conditionally |
| 637 | // result to v0. |
| 638 | if (!IsMipsArchVariant(kMips32r6)) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 639 | __ c(OLT, D, f12, f14); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 640 | __ Movt(v0, t0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 641 | // Use previous check to store conditionally to v0 oposite condition |
| 642 | // (GREATER). If rhs is equal to lhs, this will be corrected in next |
| 643 | // check. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 644 | __ Movf(v0, t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 645 | // Check if EQUAL condition is satisfied. If true, move conditionally |
| 646 | // result to v0. |
| 647 | __ c(EQ, D, f12, f14); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 648 | __ Movt(v0, t2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 649 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 650 | Label skip; |
| 651 | __ BranchF(USE_DELAY_SLOT, &skip, NULL, lt, f12, f14); |
| 652 | __ mov(v0, t0); // Return LESS as result. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 653 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 654 | __ BranchF(USE_DELAY_SLOT, &skip, NULL, eq, f12, f14); |
| 655 | __ mov(v0, t2); // Return EQUAL as result. |
| 656 | |
| 657 | __ mov(v0, t1); // Return GREATER as result. |
| 658 | __ bind(&skip); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 661 | __ Ret(); |
| 662 | |
| 663 | __ bind(&nan); |
| 664 | // NaN comparisons always fail. |
| 665 | // Load whatever we need in v0 to make the comparison fail. |
| 666 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 667 | __ Ret(USE_DELAY_SLOT); |
| 668 | if (cc == lt || cc == le) { |
| 669 | __ li(v0, Operand(GREATER)); |
| 670 | } else { |
| 671 | __ li(v0, Operand(LESS)); |
| 672 | } |
| 673 | |
| 674 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 675 | __ bind(¬_smis); |
| 676 | // At this point we know we are dealing with two different objects, |
| 677 | // 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] | 678 | if (strict()) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 679 | // This returns non-equal for some object types, or falls through if it |
| 680 | // was not lucky. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 681 | EmitStrictTwoHeapObjectCompare(masm, lhs, rhs); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 684 | Label check_for_internalized_strings; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 685 | Label flat_string_check; |
| 686 | // Check for heap-number-heap-number comparison. Can jump to slow case, |
| 687 | // or load both doubles and jump to the code that handles |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 688 | // that case. If the inputs are not doubles then jumps to |
| 689 | // check_for_internalized_strings. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 690 | // In this case a2 will contain the type of lhs_. |
| 691 | EmitCheckForTwoHeapNumbers(masm, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 692 | lhs, |
| 693 | rhs, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 694 | &both_loaded_as_doubles, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 695 | &check_for_internalized_strings, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 696 | &flat_string_check); |
| 697 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 698 | __ bind(&check_for_internalized_strings); |
| 699 | if (cc == eq && !strict()) { |
| 700 | // Returns an answer for two internalized strings or two |
| 701 | // detectable objects. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 702 | // Otherwise jumps to string case or not both strings case. |
| 703 | // Assumes that a2 is the type of lhs_ on entry. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 704 | EmitCheckForInternalizedStringsOrObjects( |
| 705 | masm, lhs, rhs, &flat_string_check, &slow); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 708 | // Check for both being sequential one-byte strings, |
| 709 | // and inline if that is the case. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 710 | __ bind(&flat_string_check); |
| 711 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 712 | __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, a2, a3, &slow); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 713 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 714 | __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2, |
| 715 | a3); |
| 716 | if (cc == eq) { |
| 717 | StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, a2, a3, t0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 718 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 719 | StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, a2, a3, t0, |
| 720 | t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 721 | } |
| 722 | // Never falls through to here. |
| 723 | |
| 724 | __ bind(&slow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 725 | if (cc == eq) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 726 | { |
| 727 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 728 | __ Push(lhs, rhs); |
| 729 | __ CallRuntime(strict() ? Runtime::kStrictEqual : Runtime::kEqual); |
| 730 | } |
| 731 | // Turn true into 0 and false into some non-zero value. |
| 732 | STATIC_ASSERT(EQUAL == 0); |
| 733 | __ LoadRoot(a0, Heap::kTrueValueRootIndex); |
| 734 | __ Ret(USE_DELAY_SLOT); |
| 735 | __ subu(v0, v0, a0); // In delay slot. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 736 | } else { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 737 | // Prepare for call to builtin. Push object pointers, a0 (lhs) first, |
| 738 | // a1 (rhs) second. |
| 739 | __ Push(lhs, rhs); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 740 | int ncr; // NaN compare result. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 741 | if (cc == lt || cc == le) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 742 | ncr = GREATER; |
| 743 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 744 | DCHECK(cc == gt || cc == ge); // Remaining cases. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 745 | ncr = LESS; |
| 746 | } |
| 747 | __ li(a0, Operand(Smi::FromInt(ncr))); |
| 748 | __ push(a0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 749 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 750 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 751 | // tagged as a small integer. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 752 | __ TailCallRuntime(Runtime::kCompare); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 753 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 754 | |
| 755 | __ bind(&miss); |
| 756 | GenerateMiss(masm); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 760 | void StoreRegistersStateStub::Generate(MacroAssembler* masm) { |
| 761 | __ mov(t9, ra); |
| 762 | __ pop(ra); |
| 763 | __ PushSafepointRegisters(); |
| 764 | __ Jump(t9); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 765 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 766 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 767 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 768 | void RestoreRegistersStateStub::Generate(MacroAssembler* masm) { |
| 769 | __ mov(t9, ra); |
| 770 | __ pop(ra); |
| 771 | __ PopSafepointRegisters(); |
| 772 | __ Jump(t9); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | |
| 776 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 777 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 778 | // store the registers in any particular way, but we do have to store and |
| 779 | // restore them. |
| 780 | __ MultiPush(kJSCallerSaved | ra.bit()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 781 | if (save_doubles()) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 782 | __ MultiPushFPU(kCallerSavedFPU); |
| 783 | } |
| 784 | const int argument_count = 1; |
| 785 | const int fp_argument_count = 0; |
| 786 | const Register scratch = a1; |
| 787 | |
| 788 | AllowExternalCallThatCantCauseGC scope(masm); |
| 789 | __ PrepareCallCFunction(argument_count, fp_argument_count, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 790 | __ li(a0, Operand(ExternalReference::isolate_address(isolate()))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 791 | __ CallCFunction( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 792 | ExternalReference::store_buffer_overflow_function(isolate()), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 793 | argument_count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 794 | if (save_doubles()) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 795 | __ MultiPopFPU(kCallerSavedFPU); |
| 796 | } |
| 797 | |
| 798 | __ MultiPop(kJSCallerSaved | ra.bit()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 799 | __ Ret(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 803 | void MathPowStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 804 | const Register base = a1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 805 | const Register exponent = MathPowTaggedDescriptor::exponent(); |
| 806 | DCHECK(exponent.is(a2)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 807 | const Register heapnumbermap = t1; |
| 808 | const Register heapnumber = v0; |
| 809 | const DoubleRegister double_base = f2; |
| 810 | const DoubleRegister double_exponent = f4; |
| 811 | const DoubleRegister double_result = f0; |
| 812 | const DoubleRegister double_scratch = f6; |
| 813 | const FPURegister single_scratch = f8; |
| 814 | const Register scratch = t5; |
| 815 | const Register scratch2 = t3; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 816 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 817 | Label call_runtime, done, int_exponent; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 818 | if (exponent_type() == ON_STACK) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 819 | Label base_is_smi, unpack_exponent; |
| 820 | // The exponent and base are supplied as arguments on the stack. |
| 821 | // This can only happen if the stub is called from non-optimized code. |
| 822 | // Load input parameters from stack to double registers. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 823 | __ lw(base, MemOperand(sp, 1 * kPointerSize)); |
| 824 | __ lw(exponent, MemOperand(sp, 0 * kPointerSize)); |
| 825 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 826 | __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 827 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 828 | __ UntagAndJumpIfSmi(scratch, base, &base_is_smi); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 829 | __ lw(scratch, FieldMemOperand(base, JSObject::kMapOffset)); |
| 830 | __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 831 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 832 | __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 833 | __ jmp(&unpack_exponent); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 834 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 835 | __ bind(&base_is_smi); |
| 836 | __ mtc1(scratch, single_scratch); |
| 837 | __ cvt_d_w(double_base, single_scratch); |
| 838 | __ bind(&unpack_exponent); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 839 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 840 | __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent); |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 841 | |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 842 | __ lw(scratch, FieldMemOperand(exponent, JSObject::kMapOffset)); |
| 843 | __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap)); |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 844 | __ ldc1(double_exponent, |
| 845 | FieldMemOperand(exponent, HeapNumber::kValueOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 846 | } else if (exponent_type() == TAGGED) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 847 | // Base is already in double_base. |
| 848 | __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent); |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 849 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 850 | __ ldc1(double_exponent, |
| 851 | FieldMemOperand(exponent, HeapNumber::kValueOffset)); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 852 | } |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 853 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 854 | if (exponent_type() != INTEGER) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 855 | Label int_exponent_convert; |
| 856 | // Detect integer exponents stored as double. |
| 857 | __ EmitFPUTruncate(kRoundToMinusInf, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 858 | scratch, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 859 | double_exponent, |
| 860 | at, |
| 861 | double_scratch, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 862 | scratch2, |
| 863 | kCheckForInexactConversion); |
| 864 | // scratch2 == 0 means there was no conversion error. |
| 865 | __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg)); |
| 866 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 867 | if (exponent_type() == ON_STACK) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 868 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 869 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 870 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 871 | Label not_plus_half; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 872 | // Test for 0.5. |
| 873 | __ Move(double_scratch, 0.5); |
| 874 | __ BranchF(USE_DELAY_SLOT, |
| 875 | ¬_plus_half, |
| 876 | NULL, |
| 877 | ne, |
| 878 | double_exponent, |
| 879 | double_scratch); |
| 880 | // double_scratch can be overwritten in the delay slot. |
| 881 | // Calculates square root of base. Check for the special case of |
| 882 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 883 | __ Move(double_scratch, static_cast<double>(-V8_INFINITY)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 884 | __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch); |
| 885 | __ neg_d(double_result, double_scratch); |
| 886 | |
| 887 | // Add +0 to convert -0 to +0. |
| 888 | __ add_d(double_scratch, double_base, kDoubleRegZero); |
| 889 | __ sqrt_d(double_result, double_scratch); |
| 890 | __ jmp(&done); |
| 891 | |
| 892 | __ bind(¬_plus_half); |
| 893 | __ Move(double_scratch, -0.5); |
| 894 | __ BranchF(USE_DELAY_SLOT, |
| 895 | &call_runtime, |
| 896 | NULL, |
| 897 | ne, |
| 898 | double_exponent, |
| 899 | double_scratch); |
| 900 | // double_scratch can be overwritten in the delay slot. |
| 901 | // Calculates square root of base. Check for the special case of |
| 902 | // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 903 | __ Move(double_scratch, static_cast<double>(-V8_INFINITY)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 904 | __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch); |
| 905 | __ Move(double_result, kDoubleRegZero); |
| 906 | |
| 907 | // Add +0 to convert -0 to +0. |
| 908 | __ add_d(double_scratch, double_base, kDoubleRegZero); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 909 | __ Move(double_result, 1.); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 910 | __ sqrt_d(double_scratch, double_scratch); |
| 911 | __ div_d(double_result, double_result, double_scratch); |
| 912 | __ jmp(&done); |
| 913 | } |
| 914 | |
| 915 | __ push(ra); |
| 916 | { |
| 917 | AllowExternalCallThatCantCauseGC scope(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 918 | __ PrepareCallCFunction(0, 2, scratch2); |
| 919 | __ MovToFloatParameters(double_base, double_exponent); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 920 | __ CallCFunction( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 921 | ExternalReference::power_double_double_function(isolate()), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 922 | 0, 2); |
| 923 | } |
| 924 | __ pop(ra); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 925 | __ MovFromFloatResult(double_result); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 926 | __ jmp(&done); |
| 927 | |
| 928 | __ bind(&int_exponent_convert); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | // Calculate power with integer exponent. |
| 932 | __ bind(&int_exponent); |
| 933 | |
| 934 | // Get two copies of exponent in the registers scratch and exponent. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 935 | if (exponent_type() == INTEGER) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 936 | __ mov(scratch, exponent); |
| 937 | } else { |
| 938 | // Exponent has previously been stored into scratch as untagged integer. |
| 939 | __ mov(exponent, scratch); |
| 940 | } |
| 941 | |
| 942 | __ mov_d(double_scratch, double_base); // Back up base. |
| 943 | __ Move(double_result, 1.0); |
| 944 | |
| 945 | // Get absolute value of exponent. |
| 946 | Label positive_exponent; |
| 947 | __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg)); |
| 948 | __ Subu(scratch, zero_reg, scratch); |
| 949 | __ bind(&positive_exponent); |
| 950 | |
| 951 | Label while_true, no_carry, loop_end; |
| 952 | __ bind(&while_true); |
| 953 | |
| 954 | __ And(scratch2, scratch, 1); |
| 955 | |
| 956 | __ Branch(&no_carry, eq, scratch2, Operand(zero_reg)); |
| 957 | __ mul_d(double_result, double_result, double_scratch); |
| 958 | __ bind(&no_carry); |
| 959 | |
| 960 | __ sra(scratch, scratch, 1); |
| 961 | |
| 962 | __ Branch(&loop_end, eq, scratch, Operand(zero_reg)); |
| 963 | __ mul_d(double_scratch, double_scratch, double_scratch); |
| 964 | |
| 965 | __ Branch(&while_true); |
| 966 | |
| 967 | __ bind(&loop_end); |
| 968 | |
| 969 | __ Branch(&done, ge, exponent, Operand(zero_reg)); |
| 970 | __ Move(double_scratch, 1.0); |
| 971 | __ div_d(double_result, double_scratch, double_result); |
| 972 | // Test whether result is zero. Bail out to check for subnormal result. |
| 973 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 974 | __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero); |
| 975 | |
| 976 | // double_exponent may not contain the exponent value if the input was a |
| 977 | // smi. We set it with exponent value before bailing out. |
| 978 | __ mtc1(exponent, single_scratch); |
| 979 | __ cvt_d_w(double_exponent, single_scratch); |
| 980 | |
| 981 | // Returning or bailing out. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 982 | if (exponent_type() == ON_STACK) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 983 | // The arguments are still on the stack. |
| 984 | __ bind(&call_runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 985 | __ TailCallRuntime(Runtime::kMathPowRT); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 986 | |
| 987 | // The stub is called from non-optimized code, which expects the result |
| 988 | // as heap number in exponent. |
| 989 | __ bind(&done); |
| 990 | __ AllocateHeapNumber( |
| 991 | heapnumber, scratch, scratch2, heapnumbermap, &call_runtime); |
| 992 | __ sdc1(double_result, |
| 993 | FieldMemOperand(heapnumber, HeapNumber::kValueOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 994 | DCHECK(heapnumber.is(v0)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 995 | __ DropAndRet(2); |
| 996 | } else { |
| 997 | __ push(ra); |
| 998 | { |
| 999 | AllowExternalCallThatCantCauseGC scope(masm); |
| 1000 | __ PrepareCallCFunction(0, 2, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1001 | __ MovToFloatParameters(double_base, double_exponent); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1002 | __ CallCFunction( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1003 | ExternalReference::power_double_double_function(isolate()), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1004 | 0, 2); |
| 1005 | } |
| 1006 | __ pop(ra); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1007 | __ MovFromFloatResult(double_result); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1008 | |
| 1009 | __ bind(&done); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1010 | __ Ret(); |
| 1011 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | |
| 1015 | bool CEntryStub::NeedsImmovableCode() { |
| 1016 | return true; |
| 1017 | } |
| 1018 | |
| 1019 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1020 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 1021 | CEntryStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1022 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
| 1023 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
| 1024 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
| 1025 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1026 | CreateWeakCellStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1027 | BinaryOpICStub::GenerateAheadOfTime(isolate); |
| 1028 | StoreRegistersStateStub::GenerateAheadOfTime(isolate); |
| 1029 | RestoreRegistersStateStub::GenerateAheadOfTime(isolate); |
| 1030 | BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1031 | StoreFastElementStub::GenerateAheadOfTime(isolate); |
| 1032 | TypeofStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1036 | void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) { |
| 1037 | StoreRegistersStateStub stub(isolate); |
| 1038 | stub.GetCode(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1042 | void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) { |
| 1043 | RestoreRegistersStateStub stub(isolate); |
| 1044 | stub.GetCode(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1048 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
| 1049 | // Generate if not already in cache. |
| 1050 | SaveFPRegsMode mode = kSaveFPRegs; |
| 1051 | CEntryStub(isolate, 1, mode).GetCode(); |
| 1052 | StoreBufferOverflowStub(isolate, mode).GetCode(); |
| 1053 | isolate->set_fp_stubs_generated(true); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1057 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
| 1058 | CEntryStub stub(isolate, 1, kDontSaveFPRegs); |
| 1059 | stub.GetCode(); |
| 1060 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1061 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1062 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1063 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 1064 | // Called from JavaScript; parameters are on stack as if calling JS function |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1065 | // a0: number of arguments including receiver |
| 1066 | // a1: pointer to builtin function |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1067 | // fp: frame pointer (restored after C call) |
| 1068 | // sp: stack pointer (restored as callee's sp after C call) |
| 1069 | // cp: current context (C callee-saved) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1070 | // |
| 1071 | // If argv_in_register(): |
| 1072 | // a2: pointer to the first argument |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1073 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1074 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 1075 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1076 | if (argv_in_register()) { |
| 1077 | // Move argv into the correct register. |
| 1078 | __ mov(s1, a2); |
| 1079 | } else { |
| 1080 | // Compute the argv pointer in a callee-saved register. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1081 | __ Lsa(s1, sp, a0, kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1082 | __ Subu(s1, s1, kPointerSize); |
| 1083 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1084 | |
| 1085 | // Enter the exit frame that transitions from JavaScript to C++. |
| 1086 | FrameScope scope(masm, StackFrame::MANUAL); |
| 1087 | __ EnterExitFrame(save_doubles()); |
| 1088 | |
| 1089 | // s0: number of arguments including receiver (C callee-saved) |
| 1090 | // s1: pointer to first argument (C callee-saved) |
| 1091 | // s2: pointer to builtin function (C callee-saved) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1092 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1093 | // Prepare arguments for C routine. |
| 1094 | // a0 = argc |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1095 | __ mov(s0, a0); |
| 1096 | __ mov(s2, a1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1097 | |
| 1098 | // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We |
| 1099 | // also need to reserve the 4 argument slots on the stack. |
| 1100 | |
| 1101 | __ AssertStackIsAligned(); |
| 1102 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1103 | int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
| 1104 | int frame_alignment_mask = frame_alignment - 1; |
| 1105 | int result_stack_size; |
| 1106 | if (result_size() <= 2) { |
| 1107 | // a0 = argc, a1 = argv, a2 = isolate |
| 1108 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
| 1109 | __ mov(a1, s1); |
| 1110 | result_stack_size = 0; |
| 1111 | } else { |
| 1112 | DCHECK_EQ(3, result_size()); |
| 1113 | // Allocate additional space for the result. |
| 1114 | result_stack_size = |
| 1115 | ((result_size() * kPointerSize) + frame_alignment_mask) & |
| 1116 | ~frame_alignment_mask; |
| 1117 | __ Subu(sp, sp, Operand(result_stack_size)); |
| 1118 | |
| 1119 | // a0 = hidden result argument, a1 = argc, a2 = argv, a3 = isolate. |
| 1120 | __ li(a3, Operand(ExternalReference::isolate_address(isolate()))); |
| 1121 | __ mov(a2, s1); |
| 1122 | __ mov(a1, a0); |
| 1123 | __ mov(a0, sp); |
| 1124 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1125 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1126 | // To let the GC traverse the return address of the exit frames, we need to |
| 1127 | // know where the return address is. The CEntryStub is unmovable, so |
| 1128 | // we can store the address on the stack to be able to find it again and |
| 1129 | // we never have to restore it, because it will not change. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1130 | { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1131 | int kNumInstructionsToJump = 4; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1132 | Label find_ra; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1133 | // Adjust the value in ra to point to the correct return location, 2nd |
| 1134 | // instruction past the real call into C code (the jalr(t9)), and push it. |
| 1135 | // This is the return address of the exit frame. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1136 | if (kArchVariant >= kMips32r6) { |
| 1137 | __ addiupc(ra, kNumInstructionsToJump + 1); |
| 1138 | } else { |
| 1139 | // This branch-and-link sequence is needed to find the current PC on mips |
| 1140 | // before r6, saved to the ra register. |
| 1141 | __ bal(&find_ra); // bal exposes branch delay slot. |
| 1142 | __ Addu(ra, ra, kNumInstructionsToJump * Instruction::kInstrSize); |
| 1143 | } |
| 1144 | __ bind(&find_ra); |
| 1145 | |
| 1146 | // This spot was reserved in EnterExitFrame. |
| 1147 | __ sw(ra, MemOperand(sp, result_stack_size)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1148 | // Stack space reservation moved to the branch delay slot below. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1149 | // Stack is still aligned. |
| 1150 | |
| 1151 | // Call the C routine. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1152 | __ mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC. |
| 1153 | __ jalr(t9); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1154 | // Set up sp in the delay slot. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1155 | __ addiu(sp, sp, -kCArgsSlotsSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1156 | // Make sure the stored 'ra' points to this position. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1157 | DCHECK_EQ(kNumInstructionsToJump, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1158 | masm->InstructionsGeneratedSince(&find_ra)); |
| 1159 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1160 | if (result_size() > 2) { |
| 1161 | DCHECK_EQ(3, result_size()); |
| 1162 | // Read result values stored on stack. |
| 1163 | __ lw(a0, MemOperand(v0, 2 * kPointerSize)); |
| 1164 | __ lw(v1, MemOperand(v0, 1 * kPointerSize)); |
| 1165 | __ lw(v0, MemOperand(v0, 0 * kPointerSize)); |
| 1166 | } |
| 1167 | // 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] | 1168 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1169 | // Check result for exception sentinel. |
| 1170 | Label exception_returned; |
| 1171 | __ LoadRoot(t0, Heap::kExceptionRootIndex); |
| 1172 | __ Branch(&exception_returned, eq, t0, Operand(v0)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1173 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1174 | // Check that there is no pending exception, otherwise we |
| 1175 | // should have returned the exception sentinel. |
| 1176 | if (FLAG_debug_code) { |
| 1177 | Label okay; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1178 | ExternalReference pending_exception_address( |
| 1179 | Isolate::kPendingExceptionAddress, isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1180 | __ li(a2, Operand(pending_exception_address)); |
| 1181 | __ lw(a2, MemOperand(a2)); |
| 1182 | __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); |
| 1183 | // Cannot use check here as it attempts to generate call into runtime. |
| 1184 | __ Branch(&okay, eq, t0, Operand(a2)); |
| 1185 | __ stop("Unexpected pending exception"); |
| 1186 | __ bind(&okay); |
| 1187 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1188 | |
| 1189 | // Exit C frame and return. |
| 1190 | // v0:v1: result |
| 1191 | // sp: stack pointer |
| 1192 | // fp: frame pointer |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1193 | Register argc; |
| 1194 | if (argv_in_register()) { |
| 1195 | // We don't want to pop arguments so set argc to no_reg. |
| 1196 | argc = no_reg; |
| 1197 | } else { |
| 1198 | // s0: still holds argc (callee-saved). |
| 1199 | argc = s0; |
| 1200 | } |
| 1201 | __ LeaveExitFrame(save_doubles(), argc, true, EMIT_RETURN); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1202 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1203 | // Handling of exception. |
| 1204 | __ bind(&exception_returned); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1205 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1206 | ExternalReference pending_handler_context_address( |
| 1207 | Isolate::kPendingHandlerContextAddress, isolate()); |
| 1208 | ExternalReference pending_handler_code_address( |
| 1209 | Isolate::kPendingHandlerCodeAddress, isolate()); |
| 1210 | ExternalReference pending_handler_offset_address( |
| 1211 | Isolate::kPendingHandlerOffsetAddress, isolate()); |
| 1212 | ExternalReference pending_handler_fp_address( |
| 1213 | Isolate::kPendingHandlerFPAddress, isolate()); |
| 1214 | ExternalReference pending_handler_sp_address( |
| 1215 | Isolate::kPendingHandlerSPAddress, isolate()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1216 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1217 | // Ask the runtime for help to determine the handler. This will set v0 to |
| 1218 | // contain the current pending exception, don't clobber it. |
| 1219 | ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler, |
| 1220 | isolate()); |
| 1221 | { |
| 1222 | FrameScope scope(masm, StackFrame::MANUAL); |
| 1223 | __ PrepareCallCFunction(3, 0, a0); |
| 1224 | __ mov(a0, zero_reg); |
| 1225 | __ mov(a1, zero_reg); |
| 1226 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
| 1227 | __ CallCFunction(find_handler, 3); |
| 1228 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1229 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1230 | // Retrieve the handler context, SP and FP. |
| 1231 | __ li(cp, Operand(pending_handler_context_address)); |
| 1232 | __ lw(cp, MemOperand(cp)); |
| 1233 | __ li(sp, Operand(pending_handler_sp_address)); |
| 1234 | __ lw(sp, MemOperand(sp)); |
| 1235 | __ li(fp, Operand(pending_handler_fp_address)); |
| 1236 | __ lw(fp, MemOperand(fp)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1237 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1238 | // If the handler is a JS frame, restore the context to the frame. Note that |
| 1239 | // the context will be set to (cp == 0) for non-JS frames. |
| 1240 | Label zero; |
| 1241 | __ Branch(&zero, eq, cp, Operand(zero_reg)); |
| 1242 | __ sw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 1243 | __ bind(&zero); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1244 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1245 | // Compute the handler entry address and jump to it. |
| 1246 | __ li(a1, Operand(pending_handler_code_address)); |
| 1247 | __ lw(a1, MemOperand(a1)); |
| 1248 | __ li(a2, Operand(pending_handler_offset_address)); |
| 1249 | __ lw(a2, MemOperand(a2)); |
| 1250 | __ Addu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 1251 | __ Addu(t9, a1, a2); |
| 1252 | __ Jump(t9); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1256 | void JSEntryStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1257 | Label invoke, handler_entry, exit; |
| 1258 | Isolate* isolate = masm->isolate(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1259 | |
| 1260 | // Registers: |
| 1261 | // a0: entry address |
| 1262 | // a1: function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1263 | // a2: receiver |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1264 | // a3: argc |
| 1265 | // |
| 1266 | // Stack: |
| 1267 | // 4 args slots |
| 1268 | // args |
| 1269 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1270 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 1271 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1272 | // Save callee saved registers on the stack. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1273 | __ MultiPush(kCalleeSaved | ra.bit()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1274 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1275 | // Save callee-saved FPU registers. |
| 1276 | __ MultiPushFPU(kCalleeSavedFPU); |
| 1277 | // Set up the reserved register for 0.0. |
| 1278 | __ Move(kDoubleRegZero, 0.0); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1279 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1280 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1281 | // Load argv in s0 register. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1282 | int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1283 | offset_to_argv += kNumCalleeSavedFPU * kDoubleSize; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1284 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1285 | __ InitializeRootRegister(); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1286 | __ lw(s0, MemOperand(sp, offset_to_argv + kCArgsSlotsSize)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1287 | |
| 1288 | // We build an EntryFrame. |
| 1289 | __ 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] | 1290 | int marker = type(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1291 | __ li(t2, Operand(Smi::FromInt(marker))); |
| 1292 | __ li(t1, Operand(Smi::FromInt(marker))); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1293 | __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1294 | isolate))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1295 | __ lw(t0, MemOperand(t0)); |
| 1296 | __ Push(t3, t2, t1, t0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1297 | // Set up frame pointer for the frame to be pushed. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1298 | __ addiu(fp, sp, -EntryFrameConstants::kCallerFPOffset); |
| 1299 | |
| 1300 | // Registers: |
| 1301 | // a0: entry_address |
| 1302 | // a1: function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1303 | // a2: receiver_pointer |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1304 | // a3: argc |
| 1305 | // s0: argv |
| 1306 | // |
| 1307 | // Stack: |
| 1308 | // caller fp | |
| 1309 | // function slot | entry frame |
| 1310 | // context slot | |
| 1311 | // bad fp (0xff...f) | |
| 1312 | // callee saved registers + ra |
| 1313 | // 4 args slots |
| 1314 | // args |
| 1315 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1316 | // If this is the outermost JS call, set js_entry_sp value. |
| 1317 | Label non_outermost_js; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1318 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1319 | __ li(t1, Operand(ExternalReference(js_entry_sp))); |
| 1320 | __ lw(t2, MemOperand(t1)); |
| 1321 | __ Branch(&non_outermost_js, ne, t2, Operand(zero_reg)); |
| 1322 | __ sw(fp, MemOperand(t1)); |
| 1323 | __ li(t0, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 1324 | Label cont; |
| 1325 | __ b(&cont); |
| 1326 | __ nop(); // Branch delay slot nop. |
| 1327 | __ bind(&non_outermost_js); |
| 1328 | __ li(t0, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
| 1329 | __ bind(&cont); |
| 1330 | __ push(t0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1331 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1332 | // Jump to a faked try block that does the invoke, with a faked catch |
| 1333 | // block that sets the pending exception. |
| 1334 | __ jmp(&invoke); |
| 1335 | __ bind(&handler_entry); |
| 1336 | handler_offset_ = handler_entry.pos(); |
| 1337 | // Caught exception: Store result (exception) in the pending exception |
| 1338 | // 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] | 1339 | // 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] | 1340 | // signal the existence of the JSEntry frame. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1341 | __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1342 | isolate))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1343 | __ 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] | 1344 | __ LoadRoot(v0, Heap::kExceptionRootIndex); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1345 | __ b(&exit); // b exposes branch delay slot. |
| 1346 | __ nop(); // Branch delay slot nop. |
| 1347 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1348 | // Invoke: Link this frame into the handler chain. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1349 | __ bind(&invoke); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1350 | __ PushStackHandler(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1351 | // If an exception not caught by another handler occurs, this handler |
| 1352 | // returns control to the code after the bal(&invoke) above, which |
| 1353 | // restores all kCalleeSaved registers (including cp and fp) to their |
| 1354 | // saved values before returning a failure to C. |
| 1355 | |
| 1356 | // Clear any pending exceptions. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1357 | __ LoadRoot(t1, Heap::kTheHoleValueRootIndex); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1358 | __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1359 | isolate))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1360 | __ sw(t1, MemOperand(t0)); |
| 1361 | |
| 1362 | // Invoke the function by calling through JS entry trampoline builtin. |
| 1363 | // Notice that we cannot store a reference to the trampoline code directly in |
| 1364 | // this stub, because runtime stubs are not traversed when doing GC. |
| 1365 | |
| 1366 | // Registers: |
| 1367 | // a0: entry_address |
| 1368 | // a1: function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1369 | // a2: receiver_pointer |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1370 | // a3: argc |
| 1371 | // s0: argv |
| 1372 | // |
| 1373 | // Stack: |
| 1374 | // handler frame |
| 1375 | // entry frame |
| 1376 | // callee saved registers + ra |
| 1377 | // 4 args slots |
| 1378 | // args |
| 1379 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1380 | if (type() == StackFrame::ENTRY_CONSTRUCT) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1381 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1382 | isolate); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1383 | __ li(t0, Operand(construct_entry)); |
| 1384 | } else { |
| 1385 | ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate()); |
| 1386 | __ li(t0, Operand(entry)); |
| 1387 | } |
| 1388 | __ lw(t9, MemOperand(t0)); // Deref address. |
| 1389 | |
| 1390 | // Call JSEntryTrampoline. |
| 1391 | __ addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag); |
| 1392 | __ Call(t9); |
| 1393 | |
| 1394 | // Unlink this frame from the handler chain. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1395 | __ PopStackHandler(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1396 | |
| 1397 | __ bind(&exit); // v0 holds result |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1398 | // Check if the current stack frame is marked as the outermost JS frame. |
| 1399 | Label non_outermost_js_2; |
| 1400 | __ pop(t1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1401 | __ Branch(&non_outermost_js_2, |
| 1402 | ne, |
| 1403 | t1, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1404 | Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 1405 | __ li(t1, Operand(ExternalReference(js_entry_sp))); |
| 1406 | __ sw(zero_reg, MemOperand(t1)); |
| 1407 | __ bind(&non_outermost_js_2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1408 | |
| 1409 | // Restore the top frame descriptors from the stack. |
| 1410 | __ pop(t1); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1411 | __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1412 | isolate))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1413 | __ sw(t1, MemOperand(t0)); |
| 1414 | |
| 1415 | // Reset the stack to the callee saved registers. |
| 1416 | __ addiu(sp, sp, -EntryFrameConstants::kCallerFPOffset); |
| 1417 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1418 | // Restore callee-saved fpu registers. |
| 1419 | __ MultiPopFPU(kCalleeSavedFPU); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1420 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1421 | // Restore callee saved registers from the stack. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1422 | __ MultiPop(kCalleeSaved | ra.bit()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1423 | // Return. |
| 1424 | __ Jump(ra); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1428 | void LoadIndexedStringStub::Generate(MacroAssembler* masm) { |
| 1429 | // Return address is in ra. |
| 1430 | Label miss; |
| 1431 | |
| 1432 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 1433 | Register index = LoadDescriptor::NameRegister(); |
| 1434 | Register scratch = t1; |
| 1435 | Register result = v0; |
| 1436 | DCHECK(!scratch.is(receiver) && !scratch.is(index)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1437 | DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1438 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1439 | StringCharAtGenerator char_at_generator(receiver, index, scratch, result, |
| 1440 | &miss, // When not a string. |
| 1441 | &miss, // When not a number. |
| 1442 | &miss, // When index out of range. |
| 1443 | STRING_INDEX_IS_ARRAY_INDEX, |
| 1444 | RECEIVER_IS_STRING); |
| 1445 | char_at_generator.GenerateFast(masm); |
| 1446 | __ Ret(); |
| 1447 | |
| 1448 | StubRuntimeCallHelper call_helper; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1449 | char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1450 | |
| 1451 | __ bind(&miss); |
| 1452 | PropertyAccessCompiler::TailCallBuiltin( |
| 1453 | masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC)); |
| 1454 | } |
| 1455 | |
| 1456 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1457 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 1458 | Label miss; |
| 1459 | Register receiver = LoadDescriptor::ReceiverRegister(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1460 | // Ensure that the vector and slot registers won't be clobbered before |
| 1461 | // calling the miss handler. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1462 | DCHECK(!AreAliased(t0, t1, LoadWithVectorDescriptor::VectorRegister(), |
| 1463 | LoadWithVectorDescriptor::SlotRegister())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1464 | |
| 1465 | NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, t0, |
| 1466 | t1, &miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1467 | __ bind(&miss); |
| 1468 | PropertyAccessCompiler::TailCallBuiltin( |
| 1469 | masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC)); |
| 1470 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1471 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1472 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1473 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 1474 | // time or if regexp entry in generated code is turned off runtime switch or |
| 1475 | // at compilation. |
| 1476 | #ifdef V8_INTERPRETED_REGEXP |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1477 | __ TailCallRuntime(Runtime::kRegExpExec); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1478 | #else // V8_INTERPRETED_REGEXP |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1479 | |
| 1480 | // Stack frame on entry. |
| 1481 | // sp[0]: last_match_info (expected JSArray) |
| 1482 | // sp[4]: previous index |
| 1483 | // sp[8]: subject string |
| 1484 | // sp[12]: JSRegExp object |
| 1485 | |
Ben Murdoch | db1b438 | 2012-04-26 19:03:50 +0100 | [diff] [blame] | 1486 | const int kLastMatchInfoOffset = 0 * kPointerSize; |
| 1487 | const int kPreviousIndexOffset = 1 * kPointerSize; |
| 1488 | const int kSubjectOffset = 2 * kPointerSize; |
| 1489 | const int kJSRegExpOffset = 3 * kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1490 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1491 | Label runtime; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1492 | // Allocation of registers for this function. These are in callee save |
| 1493 | // registers and will be preserved by the call to the native RegExp code, as |
| 1494 | // this code is called using the normal C calling convention. When calling |
| 1495 | // directly from generated code the native RegExp code will not do a GC and |
| 1496 | // therefore the content of these registers are safe to use after the call. |
| 1497 | // MIPS - using s0..s2, since we are not using CEntry Stub. |
| 1498 | Register subject = s0; |
| 1499 | Register regexp_data = s1; |
| 1500 | Register last_match_info_elements = s2; |
| 1501 | |
| 1502 | // Ensure that a RegExp stack is allocated. |
| 1503 | ExternalReference address_of_regexp_stack_memory_address = |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1504 | ExternalReference::address_of_regexp_stack_memory_address(isolate()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1505 | ExternalReference address_of_regexp_stack_memory_size = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1506 | ExternalReference::address_of_regexp_stack_memory_size(isolate()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1507 | __ li(a0, Operand(address_of_regexp_stack_memory_size)); |
| 1508 | __ lw(a0, MemOperand(a0, 0)); |
| 1509 | __ Branch(&runtime, eq, a0, Operand(zero_reg)); |
| 1510 | |
| 1511 | // Check that the first argument is a JSRegExp object. |
| 1512 | __ lw(a0, MemOperand(sp, kJSRegExpOffset)); |
| 1513 | STATIC_ASSERT(kSmiTag == 0); |
| 1514 | __ JumpIfSmi(a0, &runtime); |
| 1515 | __ GetObjectType(a0, a1, a1); |
| 1516 | __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE)); |
| 1517 | |
| 1518 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 1519 | __ lw(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset)); |
| 1520 | if (FLAG_debug_code) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1521 | __ SmiTst(regexp_data, t0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1522 | __ Check(nz, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1523 | kUnexpectedTypeForRegExpDataFixedArrayExpected, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1524 | t0, |
| 1525 | Operand(zero_reg)); |
| 1526 | __ GetObjectType(regexp_data, a0, a0); |
| 1527 | __ Check(eq, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1528 | kUnexpectedTypeForRegExpDataFixedArrayExpected, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1529 | a0, |
| 1530 | Operand(FIXED_ARRAY_TYPE)); |
| 1531 | } |
| 1532 | |
| 1533 | // regexp_data: RegExp data (FixedArray) |
| 1534 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 1535 | __ lw(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset)); |
| 1536 | __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP))); |
| 1537 | |
| 1538 | // regexp_data: RegExp data (FixedArray) |
| 1539 | // Check that the number of captures fit in the static offsets vector buffer. |
| 1540 | __ lw(a2, |
| 1541 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1542 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 1543 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 1544 | // Multiplying by 2 comes for free since a2 is smi-tagged. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1545 | STATIC_ASSERT(kSmiTag == 0); |
| 1546 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1547 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 1548 | __ Branch( |
| 1549 | &runtime, hi, a2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1550 | |
| 1551 | // Reset offset for possibly sliced string. |
| 1552 | __ mov(t0, zero_reg); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1553 | __ lw(subject, MemOperand(sp, kSubjectOffset)); |
| 1554 | __ JumpIfSmi(subject, &runtime); |
| 1555 | __ mov(a3, subject); // Make a copy of the original subject string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1556 | // subject: subject string |
| 1557 | // a3: subject string |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1558 | // regexp_data: RegExp data (FixedArray) |
| 1559 | // Handle subject string according to its encoding and representation: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1560 | // (1) Sequential string? If yes, go to (4). |
| 1561 | // (2) Sequential or cons? If not, go to (5). |
| 1562 | // (3) Cons string. If the string is flat, replace subject with first string |
| 1563 | // and go to (1). Otherwise bail out to runtime. |
| 1564 | // (4) Sequential string. Load regexp code according to encoding. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1565 | // (E) Carry on. |
| 1566 | /// [...] |
| 1567 | |
| 1568 | // Deferred code at the end of the stub: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1569 | // (5) Long external string? If not, go to (7). |
| 1570 | // (6) External string. Make it, offset-wise, look like a sequential string. |
| 1571 | // Go to (4). |
| 1572 | // (7) Short external string or not a string? If yes, bail out to runtime. |
| 1573 | // (8) Sliced string. Replace subject with parent. Go to (1). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1574 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1575 | Label seq_string /* 4 */, external_string /* 6 */, check_underlying /* 1 */, |
| 1576 | not_seq_nor_cons /* 5 */, not_long_external /* 7 */; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1577 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1578 | __ bind(&check_underlying); |
| 1579 | __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 1580 | __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset)); |
| 1581 | |
| 1582 | // (1) Sequential string? If yes, go to (4). |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1583 | __ And(a1, |
| 1584 | a0, |
| 1585 | Operand(kIsNotStringMask | |
| 1586 | kStringRepresentationMask | |
| 1587 | kShortExternalStringMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1588 | STATIC_ASSERT((kStringTag | kSeqStringTag) == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1589 | __ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (5). |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1590 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1591 | // (2) Sequential or cons? If not, go to (5). |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1592 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 1593 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1594 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 1595 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1596 | // Go to (5). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1597 | __ Branch(¬_seq_nor_cons, ge, a1, Operand(kExternalStringTag)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1598 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1599 | // (3) Cons string. Check that it's flat. |
| 1600 | // Replace subject with first string and reload instance type. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1601 | __ lw(a0, FieldMemOperand(subject, ConsString::kSecondOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1602 | __ LoadRoot(a1, Heap::kempty_stringRootIndex); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1603 | __ Branch(&runtime, ne, a0, Operand(a1)); |
| 1604 | __ lw(subject, FieldMemOperand(subject, ConsString::kFirstOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1605 | __ jmp(&check_underlying); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1606 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1607 | // (4) Sequential string. Load regexp code according to encoding. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1608 | __ bind(&seq_string); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1609 | // subject: sequential subject string (or look-alike, external string) |
| 1610 | // a3: original subject string |
| 1611 | // Load previous index and check range before a3 is overwritten. We have to |
| 1612 | // use a3 instead of subject here because subject might have been only made |
| 1613 | // to look like a sequential string when it actually is an external string. |
| 1614 | __ lw(a1, MemOperand(sp, kPreviousIndexOffset)); |
| 1615 | __ JumpIfNotSmi(a1, &runtime); |
| 1616 | __ lw(a3, FieldMemOperand(a3, String::kLengthOffset)); |
| 1617 | __ Branch(&runtime, ls, a3, Operand(a1)); |
| 1618 | __ sra(a1, a1, kSmiTagSize); // Untag the Smi. |
| 1619 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1620 | STATIC_ASSERT(kStringEncodingMask == 4); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1621 | STATIC_ASSERT(kOneByteStringTag == 4); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1622 | STATIC_ASSERT(kTwoByteStringTag == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1623 | __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for one-byte. |
| 1624 | __ lw(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1625 | __ 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] | 1626 | __ lw(t1, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1627 | __ 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] | 1628 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1629 | // (E) Carry on. String handling is done. |
| 1630 | // t9: irregexp code |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1631 | // Check that the irregexp code has been generated for the actual string |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1632 | // encoding. If it has, the field contains a code object otherwise it contains |
| 1633 | // a smi (code flushing support). |
| 1634 | __ JumpIfSmi(t9, &runtime); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1635 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1636 | // a1: previous index |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1637 | // 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] | 1638 | // t9: code |
| 1639 | // subject: Subject string |
| 1640 | // regexp_data: RegExp data (FixedArray) |
| 1641 | // All checks done. Now push arguments for native regexp code. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1642 | __ IncrementCounter(isolate()->counters()->regexp_entry_native(), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1643 | 1, a0, a2); |
| 1644 | |
| 1645 | // Isolates: note we add an additional parameter here (isolate pointer). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1646 | const int kRegExpExecuteArguments = 9; |
Ben Murdoch | db1b438 | 2012-04-26 19:03:50 +0100 | [diff] [blame] | 1647 | const int kParameterRegisters = 4; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1648 | __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters); |
| 1649 | |
| 1650 | // Stack pointer now points to cell where return address is to be written. |
| 1651 | // Arguments are before that on the stack or in registers, meaning we |
| 1652 | // treat the return address as argument 5. Thus every argument after that |
| 1653 | // needs to be shifted back by 1. Since DirectCEntryStub will handle |
| 1654 | // allocating space for the c argument slots, we don't need to calculate |
| 1655 | // that into the argument positions on the stack. This is how the stack will |
| 1656 | // look (sp meaning the value of sp at this moment): |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1657 | // [sp + 5] - Argument 9 |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1658 | // [sp + 4] - Argument 8 |
| 1659 | // [sp + 3] - Argument 7 |
| 1660 | // [sp + 2] - Argument 6 |
| 1661 | // [sp + 1] - Argument 5 |
| 1662 | // [sp + 0] - saved ra |
| 1663 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1664 | // Argument 9: Pass current isolate address. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1665 | // CFunctionArgumentOperand handles MIPS stack argument slots. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1666 | __ li(a0, Operand(ExternalReference::isolate_address(isolate()))); |
| 1667 | __ sw(a0, MemOperand(sp, 5 * kPointerSize)); |
| 1668 | |
| 1669 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 1670 | __ li(a0, Operand(1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1671 | __ sw(a0, MemOperand(sp, 4 * kPointerSize)); |
| 1672 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1673 | // Argument 7: Start (high end) of backtracking stack memory area. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1674 | __ li(a0, Operand(address_of_regexp_stack_memory_address)); |
| 1675 | __ lw(a0, MemOperand(a0, 0)); |
| 1676 | __ li(a2, Operand(address_of_regexp_stack_memory_size)); |
| 1677 | __ lw(a2, MemOperand(a2, 0)); |
| 1678 | __ addu(a0, a0, a2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1679 | __ sw(a0, MemOperand(sp, 3 * kPointerSize)); |
| 1680 | |
| 1681 | // Argument 6: Set the number of capture registers to zero to force global |
| 1682 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 1683 | __ mov(a0, zero_reg); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1684 | __ sw(a0, MemOperand(sp, 2 * kPointerSize)); |
| 1685 | |
| 1686 | // Argument 5: static offsets vector buffer. |
| 1687 | __ li(a0, Operand( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1688 | ExternalReference::address_of_static_offsets_vector(isolate()))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1689 | __ sw(a0, MemOperand(sp, 1 * kPointerSize)); |
| 1690 | |
| 1691 | // 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] | 1692 | // 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] | 1693 | __ Addu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1694 | __ 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] | 1695 | // Load the length from the original subject string from the previous stack |
| 1696 | // frame. Therefore we have to use fp, which points exactly to two pointer |
| 1697 | // sizes below the previous sp. (Because creating a new stack frame pushes |
| 1698 | // 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] | 1699 | __ lw(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1700 | // If slice offset is not 0, load the length from the original sliced string. |
| 1701 | // Argument 4, a3: End of string data |
| 1702 | // Argument 3, a2: Start of string data |
| 1703 | // Prepare start and end index of the input. |
| 1704 | __ sllv(t1, t0, a3); |
| 1705 | __ addu(t0, t2, t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1706 | __ sllv(t1, a1, a3); |
| 1707 | __ addu(a2, t0, t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1708 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1709 | __ lw(t2, FieldMemOperand(subject, String::kLengthOffset)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1710 | __ sra(t2, t2, kSmiTagSize); |
| 1711 | __ sllv(t1, t2, a3); |
| 1712 | __ addu(a3, t0, t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1713 | // Argument 2 (a1): Previous index. |
| 1714 | // Already there |
| 1715 | |
| 1716 | // Argument 1 (a0): Subject string. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1717 | __ mov(a0, subject); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1718 | |
| 1719 | // Locate the code entry and call it. |
| 1720 | __ Addu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1721 | DirectCEntryStub stub(isolate()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1722 | stub.GenerateCall(masm, t9); |
| 1723 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1724 | __ LeaveExitFrame(false, no_reg, true); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1725 | |
| 1726 | // v0: result |
| 1727 | // subject: subject string (callee saved) |
| 1728 | // regexp_data: RegExp data (callee saved) |
| 1729 | // last_match_info_elements: Last match info elements (callee saved) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1730 | // Check the result. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1731 | Label success; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1732 | __ Branch(&success, eq, v0, Operand(1)); |
| 1733 | // We expect exactly one result since we force the called regexp to behave |
| 1734 | // as non-global. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1735 | Label failure; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1736 | __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1737 | // 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] | 1738 | __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1739 | // Result must now be exception. If there is no pending exception already a |
| 1740 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 1741 | // haven't created the exception yet. Handle that in the runtime system. |
| 1742 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1743 | __ li(a1, Operand(isolate()->factory()->the_hole_value())); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1744 | __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1745 | isolate()))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1746 | __ lw(v0, MemOperand(a2, 0)); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1747 | __ Branch(&runtime, eq, v0, Operand(a1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1748 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1749 | // For exception, throw the exception again. |
| 1750 | __ TailCallRuntime(Runtime::kRegExpExecReThrow); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1751 | |
| 1752 | __ bind(&failure); |
| 1753 | // For failure and exception return null. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1754 | __ li(v0, Operand(isolate()->factory()->null_value())); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1755 | __ DropAndRet(4); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1756 | |
| 1757 | // Process the result from the native regexp code. |
| 1758 | __ bind(&success); |
| 1759 | __ lw(a1, |
| 1760 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
| 1761 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1762 | // Multiplying by 2 comes for free since r1 is smi-tagged. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1763 | STATIC_ASSERT(kSmiTag == 0); |
| 1764 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 1765 | __ Addu(a1, a1, Operand(2)); // a1 was a smi. |
| 1766 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1767 | __ lw(a0, MemOperand(sp, kLastMatchInfoOffset)); |
| 1768 | __ JumpIfSmi(a0, &runtime); |
| 1769 | __ GetObjectType(a0, a2, a2); |
| 1770 | __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE)); |
| 1771 | // Check that the JSArray is in fast case. |
| 1772 | __ lw(last_match_info_elements, |
| 1773 | FieldMemOperand(a0, JSArray::kElementsOffset)); |
| 1774 | __ lw(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset)); |
| 1775 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 1776 | __ Branch(&runtime, ne, a0, Operand(at)); |
| 1777 | // Check that the last match info has space for the capture registers and the |
| 1778 | // additional information. |
| 1779 | __ lw(a0, |
| 1780 | FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset)); |
| 1781 | __ Addu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead)); |
| 1782 | __ sra(at, a0, kSmiTagSize); |
| 1783 | __ Branch(&runtime, gt, a2, Operand(at)); |
| 1784 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1785 | // a1: number of capture registers |
| 1786 | // subject: subject string |
| 1787 | // Store the capture count. |
| 1788 | __ sll(a2, a1, kSmiTagSize + kSmiShiftSize); // To smi. |
| 1789 | __ sw(a2, FieldMemOperand(last_match_info_elements, |
| 1790 | RegExpImpl::kLastCaptureCountOffset)); |
| 1791 | // Store last subject and last input. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1792 | __ sw(subject, |
| 1793 | FieldMemOperand(last_match_info_elements, |
| 1794 | RegExpImpl::kLastSubjectOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1795 | __ mov(a2, subject); |
| 1796 | __ RecordWriteField(last_match_info_elements, |
| 1797 | RegExpImpl::kLastSubjectOffset, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1798 | subject, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1799 | t3, |
| 1800 | kRAHasNotBeenSaved, |
| 1801 | kDontSaveFPRegs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1802 | __ mov(subject, a2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1803 | __ sw(subject, |
| 1804 | FieldMemOperand(last_match_info_elements, |
| 1805 | RegExpImpl::kLastInputOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1806 | __ RecordWriteField(last_match_info_elements, |
| 1807 | RegExpImpl::kLastInputOffset, |
| 1808 | subject, |
| 1809 | t3, |
| 1810 | kRAHasNotBeenSaved, |
| 1811 | kDontSaveFPRegs); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1812 | |
| 1813 | // Get the static offsets vector filled by the native regexp code. |
| 1814 | ExternalReference address_of_static_offsets_vector = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1815 | ExternalReference::address_of_static_offsets_vector(isolate()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1816 | __ li(a2, Operand(address_of_static_offsets_vector)); |
| 1817 | |
| 1818 | // a1: number of capture registers |
| 1819 | // a2: offsets vector |
| 1820 | Label next_capture, done; |
| 1821 | // Capture register counter starts from number of capture registers and |
| 1822 | // counts down until wrapping after zero. |
| 1823 | __ Addu(a0, |
| 1824 | last_match_info_elements, |
| 1825 | Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag)); |
| 1826 | __ bind(&next_capture); |
| 1827 | __ Subu(a1, a1, Operand(1)); |
| 1828 | __ Branch(&done, lt, a1, Operand(zero_reg)); |
| 1829 | // Read the value from the static offsets vector buffer. |
| 1830 | __ lw(a3, MemOperand(a2, 0)); |
| 1831 | __ addiu(a2, a2, kPointerSize); |
| 1832 | // Store the smi value in the last match info. |
| 1833 | __ sll(a3, a3, kSmiTagSize); // Convert to Smi. |
| 1834 | __ sw(a3, MemOperand(a0, 0)); |
| 1835 | __ Branch(&next_capture, USE_DELAY_SLOT); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1836 | __ addiu(a0, a0, kPointerSize); // In branch delay slot. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1837 | |
| 1838 | __ bind(&done); |
| 1839 | |
| 1840 | // Return last match info. |
| 1841 | __ lw(v0, MemOperand(sp, kLastMatchInfoOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1842 | __ DropAndRet(4); |
| 1843 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1844 | // Do the runtime call to execute the regexp. |
| 1845 | __ bind(&runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1846 | __ TailCallRuntime(Runtime::kRegExpExec); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1847 | |
| 1848 | // Deferred code for string handling. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1849 | // (5) Long external string? If not, go to (7). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1850 | __ bind(¬_seq_nor_cons); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1851 | // Go to (7). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1852 | __ Branch(¬_long_external, gt, a1, Operand(kExternalStringTag)); |
| 1853 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1854 | // (6) External string. Make it, offset-wise, look like a sequential string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1855 | __ bind(&external_string); |
| 1856 | __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 1857 | __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset)); |
| 1858 | if (FLAG_debug_code) { |
| 1859 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 1860 | // Sequential strings have already been ruled out. |
| 1861 | __ And(at, a0, Operand(kIsIndirectStringMask)); |
| 1862 | __ Assert(eq, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1863 | kExternalStringExpectedButNotFound, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1864 | at, |
| 1865 | Operand(zero_reg)); |
| 1866 | } |
| 1867 | __ lw(subject, |
| 1868 | FieldMemOperand(subject, ExternalString::kResourceDataOffset)); |
| 1869 | // 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] | 1870 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1871 | __ Subu(subject, |
| 1872 | subject, |
| 1873 | SeqTwoByteString::kHeaderSize - kHeapObjectTag); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1874 | __ jmp(&seq_string); // Go to (5). |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1875 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1876 | // (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] | 1877 | __ bind(¬_long_external); |
| 1878 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 1879 | __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask)); |
| 1880 | __ Branch(&runtime, ne, at, Operand(zero_reg)); |
| 1881 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1882 | // (8) Sliced string. Replace subject with parent. Go to (4). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1883 | // Load offset into t0 and replace subject string with parent. |
| 1884 | __ lw(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset)); |
| 1885 | __ sra(t0, t0, kSmiTagSize); |
| 1886 | __ lw(subject, FieldMemOperand(subject, SlicedString::kParentOffset)); |
| 1887 | __ jmp(&check_underlying); // Go to (4). |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1888 | #endif // V8_INTERPRETED_REGEXP |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1892 | static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) { |
| 1893 | // a0 : number of arguments to the construct function |
| 1894 | // a2 : feedback vector |
| 1895 | // a3 : slot in feedback vector (Smi) |
| 1896 | // a1 : the function to call |
| 1897 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1898 | const RegList kSavedRegs = 1 << 4 | // a0 |
| 1899 | 1 << 5 | // a1 |
| 1900 | 1 << 6 | // a2 |
| 1901 | 1 << 7; // a3 |
| 1902 | |
| 1903 | // Number-of-arguments register must be smi-tagged to call out. |
| 1904 | __ SmiTag(a0); |
| 1905 | __ MultiPush(kSavedRegs); |
| 1906 | |
| 1907 | __ CallStub(stub); |
| 1908 | |
| 1909 | __ MultiPop(kSavedRegs); |
| 1910 | __ SmiUntag(a0); |
| 1911 | } |
| 1912 | |
| 1913 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1914 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1915 | // Cache the called function in a feedback vector slot. Cache states |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1916 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 1917 | // megamorphic. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1918 | // a0 : number of arguments to the construct function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1919 | // a1 : the function to call |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1920 | // a2 : feedback vector |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1921 | // a3 : slot in feedback vector (Smi) |
| 1922 | Label initialize, done, miss, megamorphic, not_array_function; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1923 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1924 | DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()), |
| 1925 | masm->isolate()->heap()->megamorphic_symbol()); |
| 1926 | DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()), |
| 1927 | masm->isolate()->heap()->uninitialized_symbol()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1928 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1929 | // Load the cache state into t2. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1930 | __ Lsa(t2, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1931 | __ lw(t2, FieldMemOperand(t2, FixedArray::kHeaderSize)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1932 | |
| 1933 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 1934 | // function without changing the state. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1935 | // We don't know if t2 is a WeakCell or a Symbol, but it's harmless to read at |
| 1936 | // this position in a symbol (see static asserts in type-feedback-vector.h). |
| 1937 | Label check_allocation_site; |
| 1938 | Register feedback_map = t1; |
| 1939 | Register weak_value = t4; |
| 1940 | __ lw(weak_value, FieldMemOperand(t2, WeakCell::kValueOffset)); |
| 1941 | __ Branch(&done, eq, a1, Operand(weak_value)); |
| 1942 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 1943 | __ Branch(&done, eq, t2, Operand(at)); |
| 1944 | __ lw(feedback_map, FieldMemOperand(t2, HeapObject::kMapOffset)); |
| 1945 | __ LoadRoot(at, Heap::kWeakCellMapRootIndex); |
| 1946 | __ Branch(&check_allocation_site, ne, feedback_map, Operand(at)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1947 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1948 | // If the weak cell is cleared, we have a new chance to become monomorphic. |
| 1949 | __ JumpIfSmi(weak_value, &initialize); |
| 1950 | __ jmp(&megamorphic); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1951 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1952 | __ bind(&check_allocation_site); |
| 1953 | // If we came here, we need to see if we are the array function. |
| 1954 | // If we didn't have a matching function, and we didn't find the megamorph |
| 1955 | // sentinel, then we have in the slot either some other function or an |
| 1956 | // AllocationSite. |
| 1957 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 1958 | __ Branch(&miss, ne, feedback_map, Operand(at)); |
| 1959 | |
| 1960 | // Make sure the function is the Array() function |
| 1961 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, t2); |
| 1962 | __ Branch(&megamorphic, ne, a1, Operand(t2)); |
| 1963 | __ jmp(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1964 | |
| 1965 | __ bind(&miss); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1966 | |
| 1967 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 1968 | // megamorphic. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1969 | __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1970 | __ Branch(&initialize, eq, t2, Operand(at)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1971 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 1972 | // write-barrier is needed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1973 | __ bind(&megamorphic); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1974 | __ Lsa(t2, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1975 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1976 | __ sw(at, FieldMemOperand(t2, FixedArray::kHeaderSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1977 | __ jmp(&done); |
| 1978 | |
| 1979 | // An uninitialized cache is patched with the function. |
| 1980 | __ bind(&initialize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1981 | // Make sure the function is the Array() function. |
| 1982 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, t2); |
| 1983 | __ Branch(¬_array_function, ne, a1, Operand(t2)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1984 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1985 | // The target function is the Array constructor, |
| 1986 | // Create an AllocationSite if we don't already have it, store it in the |
| 1987 | // slot. |
| 1988 | CreateAllocationSiteStub create_stub(masm->isolate()); |
| 1989 | CallStubInRecordCallTarget(masm, &create_stub); |
| 1990 | __ Branch(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1991 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1992 | __ bind(¬_array_function); |
| 1993 | CreateWeakCellStub weak_cell_stub(masm->isolate()); |
| 1994 | CallStubInRecordCallTarget(masm, &weak_cell_stub); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1995 | __ bind(&done); |
| 1996 | } |
| 1997 | |
| 1998 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1999 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 2000 | // a0 : number of arguments |
| 2001 | // a1 : the function to call |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2002 | // a2 : feedback vector |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2003 | // a3 : slot in feedback vector (Smi, for RecordCallTarget) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2004 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2005 | Label non_function; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2006 | // Check that the function is not a smi. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2007 | __ JumpIfSmi(a1, &non_function); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2008 | // Check that the function is a JSFunction. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2009 | __ GetObjectType(a1, t1, t1); |
| 2010 | __ Branch(&non_function, ne, t1, Operand(JS_FUNCTION_TYPE)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2011 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2012 | GenerateRecordCallTarget(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2013 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2014 | __ Lsa(t1, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2015 | Label feedback_register_initialized; |
| 2016 | // Put the AllocationSite from the feedback vector into a2, or undefined. |
| 2017 | __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize)); |
| 2018 | __ lw(t1, FieldMemOperand(a2, AllocationSite::kMapOffset)); |
| 2019 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 2020 | __ Branch(&feedback_register_initialized, eq, t1, Operand(at)); |
| 2021 | __ LoadRoot(a2, Heap::kUndefinedValueRootIndex); |
| 2022 | __ bind(&feedback_register_initialized); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2023 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2024 | __ AssertUndefinedOrAllocationSite(a2, t1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2025 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2026 | // Pass function as new target. |
| 2027 | __ mov(a3, a1); |
| 2028 | |
| 2029 | // Tail call to the function-specific construct stub (still in the caller |
| 2030 | // context at this point). |
| 2031 | __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 2032 | __ lw(t0, FieldMemOperand(t0, SharedFunctionInfo::kConstructStubOffset)); |
| 2033 | __ Addu(at, t0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2034 | __ Jump(at); |
| 2035 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2036 | __ bind(&non_function); |
| 2037 | __ mov(a3, a1); |
| 2038 | __ Jump(isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2042 | void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2043 | // a1 - function |
| 2044 | // a3 - slot id |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2045 | // a2 - vector |
| 2046 | // t0 - loaded from vector[slot] |
| 2047 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, at); |
| 2048 | __ Branch(miss, ne, a1, Operand(at)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2049 | |
| 2050 | __ li(a0, Operand(arg_count())); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2051 | |
| 2052 | // Increment the call count for monomorphic function calls. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2053 | __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2054 | __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
| 2055 | __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement))); |
| 2056 | __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2057 | |
| 2058 | __ mov(a2, t0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2059 | __ mov(a3, a1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2060 | ArrayConstructorStub stub(masm->isolate(), arg_count()); |
| 2061 | __ TailCallStub(&stub); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | |
| 2065 | void CallICStub::Generate(MacroAssembler* masm) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2066 | // a1 - function |
| 2067 | // a3 - slot id (Smi) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2068 | // a2 - vector |
| 2069 | Label extra_checks_or_miss, call, call_function; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2070 | int argc = arg_count(); |
| 2071 | ParameterCount actual(argc); |
| 2072 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2073 | // The checks. First, does r1 match the recorded monomorphic target? |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2074 | __ Lsa(t0, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2075 | __ lw(t0, FieldMemOperand(t0, FixedArray::kHeaderSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2076 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2077 | // We don't know that we have a weak cell. We might have a private symbol |
| 2078 | // or an AllocationSite, but the memory is safe to examine. |
| 2079 | // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to |
| 2080 | // FixedArray. |
| 2081 | // WeakCell::kValueOffset - contains a JSFunction or Smi(0) |
| 2082 | // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not |
| 2083 | // computed, meaning that it can't appear to be a pointer. If the low bit is |
| 2084 | // 0, then hash is computed, but the 0 bit prevents the field from appearing |
| 2085 | // to be a pointer. |
| 2086 | STATIC_ASSERT(WeakCell::kSize >= kPointerSize); |
| 2087 | STATIC_ASSERT(AllocationSite::kTransitionInfoOffset == |
| 2088 | WeakCell::kValueOffset && |
| 2089 | WeakCell::kValueOffset == Symbol::kHashFieldSlot); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2090 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2091 | __ lw(t1, FieldMemOperand(t0, WeakCell::kValueOffset)); |
| 2092 | __ Branch(&extra_checks_or_miss, ne, a1, Operand(t1)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2093 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2094 | // The compare above could have been a SMI/SMI comparison. Guard against this |
| 2095 | // convincing us that we have a monomorphic JSFunction. |
| 2096 | __ JumpIfSmi(a1, &extra_checks_or_miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2097 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2098 | // Increment the call count for monomorphic function calls. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2099 | __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2100 | __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
| 2101 | __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement))); |
| 2102 | __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2103 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2104 | __ bind(&call_function); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2105 | __ Jump(masm->isolate()->builtins()->CallFunction(convert_mode(), |
| 2106 | tail_call_mode()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2107 | RelocInfo::CODE_TARGET, al, zero_reg, Operand(zero_reg), |
| 2108 | USE_DELAY_SLOT); |
| 2109 | __ li(a0, Operand(argc)); // In delay slot. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2110 | |
| 2111 | __ bind(&extra_checks_or_miss); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2112 | Label uninitialized, miss, not_allocation_site; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2113 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2114 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2115 | __ Branch(&call, eq, t0, Operand(at)); |
| 2116 | |
| 2117 | // Verify that t0 contains an AllocationSite |
| 2118 | __ lw(t1, FieldMemOperand(t0, HeapObject::kMapOffset)); |
| 2119 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 2120 | __ Branch(¬_allocation_site, ne, t1, Operand(at)); |
| 2121 | |
| 2122 | HandleArrayCase(masm, &miss); |
| 2123 | |
| 2124 | __ bind(¬_allocation_site); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2125 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2126 | // The following cases attempt to handle MISS cases without going to the |
| 2127 | // runtime. |
| 2128 | if (FLAG_trace_ic) { |
| 2129 | __ Branch(&miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2130 | } |
| 2131 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2132 | __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex); |
| 2133 | __ Branch(&uninitialized, eq, t0, Operand(at)); |
| 2134 | |
| 2135 | // We are going megamorphic. If the feedback is a JSFunction, it is fine |
| 2136 | // to handle it here. More complex cases are dealt with in the runtime. |
| 2137 | __ AssertNotSmi(t0); |
| 2138 | __ GetObjectType(t0, t1, t1); |
| 2139 | __ Branch(&miss, ne, t1, Operand(JS_FUNCTION_TYPE)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2140 | __ Lsa(t0, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2141 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 2142 | __ sw(at, FieldMemOperand(t0, FixedArray::kHeaderSize)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2143 | |
| 2144 | __ bind(&call); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2145 | __ Jump(masm->isolate()->builtins()->Call(convert_mode(), tail_call_mode()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2146 | RelocInfo::CODE_TARGET, al, zero_reg, Operand(zero_reg), |
| 2147 | USE_DELAY_SLOT); |
| 2148 | __ li(a0, Operand(argc)); // In delay slot. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2149 | |
| 2150 | __ bind(&uninitialized); |
| 2151 | |
| 2152 | // We are going monomorphic, provided we actually have a JSFunction. |
| 2153 | __ JumpIfSmi(a1, &miss); |
| 2154 | |
| 2155 | // Goto miss case if we do not have a function. |
| 2156 | __ GetObjectType(a1, t0, t0); |
| 2157 | __ Branch(&miss, ne, t0, Operand(JS_FUNCTION_TYPE)); |
| 2158 | |
| 2159 | // Make sure the function is not the Array() function, which requires special |
| 2160 | // behavior on MISS. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2161 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, t0); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2162 | __ Branch(&miss, eq, a1, Operand(t0)); |
| 2163 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2164 | // Make sure the function belongs to the same native context. |
| 2165 | __ lw(t0, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 2166 | __ lw(t0, ContextMemOperand(t0, Context::NATIVE_CONTEXT_INDEX)); |
| 2167 | __ lw(t1, NativeContextMemOperand()); |
| 2168 | __ Branch(&miss, ne, t0, Operand(t1)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2169 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2170 | // Initialize the call counter. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2171 | __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2172 | __ li(t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement))); |
| 2173 | __ sw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2174 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2175 | // Store the function. Use a stub since we need a frame for allocation. |
| 2176 | // a2 - vector |
| 2177 | // a3 - slot |
| 2178 | // a1 - function |
| 2179 | { |
| 2180 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2181 | CreateWeakCellStub create_stub(masm->isolate()); |
| 2182 | __ Push(a1); |
| 2183 | __ CallStub(&create_stub); |
| 2184 | __ Pop(a1); |
| 2185 | } |
| 2186 | |
| 2187 | __ Branch(&call_function); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2188 | |
| 2189 | // We are here because tracing is on or we encountered a MISS case we can't |
| 2190 | // handle here. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2191 | __ bind(&miss); |
| 2192 | GenerateMiss(masm); |
| 2193 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2194 | __ Branch(&call); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2198 | void CallICStub::GenerateMiss(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2199 | FrameScope scope(masm, StackFrame::INTERNAL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2200 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2201 | // Push the receiver and the function and feedback info. |
| 2202 | __ Push(a1, a2, a3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2203 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2204 | // Call the entry. |
| 2205 | __ CallRuntime(Runtime::kCallIC_Miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2206 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2207 | // Move result to a1 and exit the internal frame. |
| 2208 | __ mov(a1, v0); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2209 | } |
| 2210 | |
| 2211 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2212 | // StringCharCodeAtGenerator. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2213 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2214 | DCHECK(!t0.is(index_)); |
| 2215 | DCHECK(!t0.is(result_)); |
| 2216 | DCHECK(!t0.is(object_)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2217 | if (check_mode_ == RECEIVER_IS_UNKNOWN) { |
| 2218 | // If the receiver is a smi trigger the non-string case. |
| 2219 | __ JumpIfSmi(object_, receiver_not_string_); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2220 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2221 | // Fetch the instance type of the receiver into result register. |
| 2222 | __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 2223 | __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 2224 | // If the receiver is not a string trigger the non-string case. |
| 2225 | __ And(t0, result_, Operand(kIsNotStringMask)); |
| 2226 | __ Branch(receiver_not_string_, ne, t0, Operand(zero_reg)); |
| 2227 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2228 | |
| 2229 | // If the index is non-smi trigger the non-smi case. |
| 2230 | __ JumpIfNotSmi(index_, &index_not_smi_); |
| 2231 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2232 | __ bind(&got_smi_index_); |
| 2233 | |
| 2234 | // Check for index out of range. |
| 2235 | __ lw(t0, FieldMemOperand(object_, String::kLengthOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2236 | __ Branch(index_out_of_range_, ls, t0, Operand(index_)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2237 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2238 | __ sra(index_, index_, kSmiTagSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2239 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2240 | StringCharLoadGenerator::Generate(masm, |
| 2241 | object_, |
| 2242 | index_, |
| 2243 | result_, |
| 2244 | &call_runtime_); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2245 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2246 | __ sll(result_, result_, kSmiTagSize); |
| 2247 | __ bind(&exit_); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | |
| 2251 | void StringCharCodeAtGenerator::GenerateSlow( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2252 | MacroAssembler* masm, EmbedMode embed_mode, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2253 | const RuntimeCallHelper& call_helper) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2254 | __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2255 | |
| 2256 | // Index is not a smi. |
| 2257 | __ bind(&index_not_smi_); |
| 2258 | // If index is a heap number, try converting it to an integer. |
| 2259 | __ CheckMap(index_, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2260 | result_, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2261 | Heap::kHeapNumberMapRootIndex, |
| 2262 | index_not_number_, |
| 2263 | DONT_DO_SMI_CHECK); |
| 2264 | call_helper.BeforeCall(masm); |
| 2265 | // Consumed by runtime conversion function: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2266 | if (embed_mode == PART_OF_IC_HANDLER) { |
| 2267 | __ Push(LoadWithVectorDescriptor::VectorRegister(), |
| 2268 | LoadWithVectorDescriptor::SlotRegister(), object_, index_); |
| 2269 | } else { |
| 2270 | __ Push(object_, index_); |
| 2271 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2272 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2273 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2274 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2275 | DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2276 | // NumberToSmi discards numbers that are not exact integers. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2277 | __ CallRuntime(Runtime::kNumberToSmi); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | // Save the conversion result before the pop instructions below |
| 2281 | // have a chance to overwrite it. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2282 | __ Move(index_, v0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2283 | if (embed_mode == PART_OF_IC_HANDLER) { |
| 2284 | __ Pop(LoadWithVectorDescriptor::VectorRegister(), |
| 2285 | LoadWithVectorDescriptor::SlotRegister(), object_); |
| 2286 | } else { |
| 2287 | __ pop(object_); |
| 2288 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2289 | // Reload the instance type. |
| 2290 | __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 2291 | __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 2292 | call_helper.AfterCall(masm); |
| 2293 | // 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] | 2294 | __ JumpIfNotSmi(index_, index_out_of_range_); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2295 | // Otherwise, return to the fast path. |
| 2296 | __ Branch(&got_smi_index_); |
| 2297 | |
| 2298 | // Call runtime. We get here when the receiver is a string and the |
| 2299 | // index is a number, but the code of getting the actual character |
| 2300 | // is too complex (e.g., when the string needs to be flattened). |
| 2301 | __ bind(&call_runtime_); |
| 2302 | call_helper.BeforeCall(masm); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2303 | __ sll(index_, index_, kSmiTagSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2304 | __ Push(object_, index_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2305 | __ CallRuntime(Runtime::kStringCharCodeAtRT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2306 | |
| 2307 | __ Move(result_, v0); |
| 2308 | |
| 2309 | call_helper.AfterCall(masm); |
| 2310 | __ jmp(&exit_); |
| 2311 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2312 | __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | |
| 2316 | // ------------------------------------------------------------------------- |
| 2317 | // StringCharFromCodeGenerator |
| 2318 | |
| 2319 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2320 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 2321 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2322 | DCHECK(!t0.is(result_)); |
| 2323 | DCHECK(!t0.is(code_)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2324 | |
| 2325 | STATIC_ASSERT(kSmiTag == 0); |
| 2326 | STATIC_ASSERT(kSmiShiftSize == 0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2327 | DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1)); |
| 2328 | __ And(t0, code_, Operand(kSmiTagMask | |
| 2329 | ((~String::kMaxOneByteCharCodeU) << kSmiTagSize))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2330 | __ Branch(&slow_case_, ne, t0, Operand(zero_reg)); |
| 2331 | |
| 2332 | __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2333 | // At this point code register contains smi tagged one-byte char code. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2334 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2335 | __ Lsa(result_, result_, code_, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2336 | __ lw(result_, FieldMemOperand(result_, FixedArray::kHeaderSize)); |
| 2337 | __ LoadRoot(t0, Heap::kUndefinedValueRootIndex); |
| 2338 | __ Branch(&slow_case_, eq, result_, Operand(t0)); |
| 2339 | __ bind(&exit_); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | |
| 2343 | void StringCharFromCodeGenerator::GenerateSlow( |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2344 | MacroAssembler* masm, |
| 2345 | const RuntimeCallHelper& call_helper) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2346 | __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2347 | |
| 2348 | __ bind(&slow_case_); |
| 2349 | call_helper.BeforeCall(masm); |
| 2350 | __ push(code_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2351 | __ CallRuntime(Runtime::kStringCharFromCode); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2352 | __ Move(result_, v0); |
| 2353 | |
| 2354 | call_helper.AfterCall(masm); |
| 2355 | __ Branch(&exit_); |
| 2356 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2357 | __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2361 | enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2362 | |
| 2363 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2364 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 2365 | Register dest, |
| 2366 | Register src, |
| 2367 | Register count, |
| 2368 | Register scratch, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2369 | String::Encoding encoding) { |
| 2370 | if (FLAG_debug_code) { |
| 2371 | // Check that destination is word aligned. |
| 2372 | __ And(scratch, dest, Operand(kPointerAlignmentMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2373 | __ Check(eq, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2374 | kDestinationOfCopyNotAligned, |
| 2375 | scratch, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2376 | Operand(zero_reg)); |
| 2377 | } |
| 2378 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2379 | // Assumes word reads and writes are little endian. |
| 2380 | // Nothing to do for zero characters. |
| 2381 | Label done; |
| 2382 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2383 | if (encoding == String::TWO_BYTE_ENCODING) { |
| 2384 | __ Addu(count, count, count); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2385 | } |
| 2386 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2387 | Register limit = count; // Read until dest equals this. |
| 2388 | __ Addu(limit, dest, Operand(count)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2389 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2390 | Label loop_entry, loop; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2391 | // Copy bytes from src to dest until dest hits limit. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2392 | __ Branch(&loop_entry); |
| 2393 | __ bind(&loop); |
| 2394 | __ lbu(scratch, MemOperand(src)); |
| 2395 | __ Addu(src, src, Operand(1)); |
| 2396 | __ sb(scratch, MemOperand(dest)); |
| 2397 | __ Addu(dest, dest, Operand(1)); |
| 2398 | __ bind(&loop_entry); |
| 2399 | __ Branch(&loop, lt, dest, Operand(limit)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2400 | |
| 2401 | __ bind(&done); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2405 | void SubStringStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2406 | Label runtime; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2407 | // Stack frame on entry. |
| 2408 | // ra: return address |
| 2409 | // sp[0]: to |
| 2410 | // sp[4]: from |
| 2411 | // sp[8]: string |
| 2412 | |
| 2413 | // This stub is called from the native-call %_SubString(...), so |
| 2414 | // nothing can be assumed about the arguments. It is tested that: |
| 2415 | // "string" is a sequential string, |
| 2416 | // both "from" and "to" are smis, and |
| 2417 | // 0 <= from <= to <= string.length. |
| 2418 | // If any of these assumptions fail, we call the runtime system. |
| 2419 | |
Ben Murdoch | db1b438 | 2012-04-26 19:03:50 +0100 | [diff] [blame] | 2420 | const int kToOffset = 0 * kPointerSize; |
| 2421 | const int kFromOffset = 1 * kPointerSize; |
| 2422 | const int kStringOffset = 2 * kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2423 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2424 | __ lw(a2, MemOperand(sp, kToOffset)); |
| 2425 | __ lw(a3, MemOperand(sp, kFromOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2426 | STATIC_ASSERT(kFromOffset == kToOffset + 4); |
| 2427 | STATIC_ASSERT(kSmiTag == 0); |
| 2428 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 2429 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2430 | // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is |
| 2431 | // safe in this case. |
| 2432 | __ UntagAndJumpIfNotSmi(a2, a2, &runtime); |
| 2433 | __ UntagAndJumpIfNotSmi(a3, a3, &runtime); |
| 2434 | // Both a2 and a3 are untagged integers. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2435 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2436 | __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2437 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2438 | __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to. |
| 2439 | __ Subu(a2, a2, a3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2440 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2441 | // Make sure first argument is a string. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2442 | __ lw(v0, MemOperand(sp, kStringOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2443 | __ JumpIfSmi(v0, &runtime); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2444 | __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2445 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2446 | __ And(t0, a1, Operand(kIsNotStringMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2447 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2448 | __ Branch(&runtime, ne, t0, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2449 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2450 | Label single_char; |
| 2451 | __ Branch(&single_char, eq, a2, Operand(1)); |
| 2452 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2453 | // Short-cut for the case of trivial substring. |
| 2454 | Label return_v0; |
| 2455 | // v0: original string |
| 2456 | // a2: result string length |
| 2457 | __ lw(t0, FieldMemOperand(v0, String::kLengthOffset)); |
| 2458 | __ sra(t0, t0, 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2459 | // Return original string. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2460 | __ Branch(&return_v0, eq, a2, Operand(t0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2461 | // Longer than original string's length or negative: unsafe arguments. |
| 2462 | __ Branch(&runtime, hi, a2, Operand(t0)); |
| 2463 | // Shorter than original string's length: an actual substring. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2464 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2465 | // Deal with different string types: update the index if necessary |
| 2466 | // and put the underlying string into t1. |
| 2467 | // v0: original string |
| 2468 | // a1: instance type |
| 2469 | // a2: length |
| 2470 | // a3: from index (untagged) |
| 2471 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 2472 | // If the string is not indirect, it can only be sequential or external. |
| 2473 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 2474 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 2475 | __ And(t0, a1, Operand(kIsIndirectStringMask)); |
| 2476 | __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, t0, Operand(zero_reg)); |
| 2477 | // t0 is used as a scratch register and can be overwritten in either case. |
| 2478 | __ And(t0, a1, Operand(kSlicedNotConsMask)); |
| 2479 | __ Branch(&sliced_string, ne, t0, Operand(zero_reg)); |
| 2480 | // Cons string. Check whether it is flat, then fetch first part. |
| 2481 | __ lw(t1, FieldMemOperand(v0, ConsString::kSecondOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2482 | __ LoadRoot(t0, Heap::kempty_stringRootIndex); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2483 | __ Branch(&runtime, ne, t1, Operand(t0)); |
| 2484 | __ lw(t1, FieldMemOperand(v0, ConsString::kFirstOffset)); |
| 2485 | // Update instance type. |
| 2486 | __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset)); |
| 2487 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
| 2488 | __ jmp(&underlying_unpacked); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2489 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2490 | __ bind(&sliced_string); |
| 2491 | // Sliced string. Fetch parent and correct start index by offset. |
| 2492 | __ lw(t1, FieldMemOperand(v0, SlicedString::kParentOffset)); |
| 2493 | __ lw(t0, FieldMemOperand(v0, SlicedString::kOffsetOffset)); |
| 2494 | __ sra(t0, t0, 1); // Add offset to index. |
| 2495 | __ Addu(a3, a3, t0); |
| 2496 | // Update instance type. |
| 2497 | __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset)); |
| 2498 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
| 2499 | __ jmp(&underlying_unpacked); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2500 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2501 | __ bind(&seq_or_external_string); |
| 2502 | // Sequential or external string. Just move string to the expected register. |
| 2503 | __ mov(t1, v0); |
| 2504 | |
| 2505 | __ bind(&underlying_unpacked); |
| 2506 | |
| 2507 | if (FLAG_string_slices) { |
| 2508 | Label copy_routine; |
| 2509 | // t1: underlying subject string |
| 2510 | // a1: instance type of underlying subject string |
| 2511 | // a2: length |
| 2512 | // a3: adjusted start index (untagged) |
| 2513 | // Short slice. Copy instead of slicing. |
| 2514 | __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength)); |
| 2515 | // Allocate new sliced string. At this point we do not reload the instance |
| 2516 | // type including the string encoding because we simply rely on the info |
| 2517 | // provided by the original string. It does not matter if the original |
| 2518 | // string's encoding is wrong because we always have to recheck encoding of |
| 2519 | // the newly created string's parent anyways due to externalized strings. |
| 2520 | Label two_byte_slice, set_slice_header; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2521 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2522 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 2523 | __ And(t0, a1, Operand(kStringEncodingMask)); |
| 2524 | __ Branch(&two_byte_slice, eq, t0, Operand(zero_reg)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2525 | __ AllocateOneByteSlicedString(v0, a2, t2, t3, &runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2526 | __ jmp(&set_slice_header); |
| 2527 | __ bind(&two_byte_slice); |
| 2528 | __ AllocateTwoByteSlicedString(v0, a2, t2, t3, &runtime); |
| 2529 | __ bind(&set_slice_header); |
| 2530 | __ sll(a3, a3, 1); |
| 2531 | __ sw(t1, FieldMemOperand(v0, SlicedString::kParentOffset)); |
| 2532 | __ sw(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset)); |
| 2533 | __ jmp(&return_v0); |
| 2534 | |
| 2535 | __ bind(©_routine); |
| 2536 | } |
| 2537 | |
| 2538 | // t1: underlying subject string |
| 2539 | // a1: instance type of underlying subject string |
| 2540 | // a2: length |
| 2541 | // a3: adjusted start index (untagged) |
| 2542 | Label two_byte_sequential, sequential_string, allocate_result; |
| 2543 | STATIC_ASSERT(kExternalStringTag != 0); |
| 2544 | STATIC_ASSERT(kSeqStringTag == 0); |
| 2545 | __ And(t0, a1, Operand(kExternalStringTag)); |
| 2546 | __ Branch(&sequential_string, eq, t0, Operand(zero_reg)); |
| 2547 | |
| 2548 | // Handle external string. |
| 2549 | // Rule out short external strings. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2550 | STATIC_ASSERT(kShortExternalStringTag != 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2551 | __ And(t0, a1, Operand(kShortExternalStringTag)); |
| 2552 | __ Branch(&runtime, ne, t0, Operand(zero_reg)); |
| 2553 | __ lw(t1, FieldMemOperand(t1, ExternalString::kResourceDataOffset)); |
| 2554 | // t1 already points to the first character of underlying string. |
| 2555 | __ jmp(&allocate_result); |
| 2556 | |
| 2557 | __ bind(&sequential_string); |
| 2558 | // Locate first character of underlying subject string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2559 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
| 2560 | __ Addu(t1, t1, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2561 | |
| 2562 | __ bind(&allocate_result); |
| 2563 | // Sequential acii string. Allocate the result. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2564 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2565 | __ And(t0, a1, Operand(kStringEncodingMask)); |
| 2566 | __ Branch(&two_byte_sequential, eq, t0, Operand(zero_reg)); |
| 2567 | |
| 2568 | // Allocate and copy the resulting ASCII string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2569 | __ AllocateOneByteString(v0, a2, t0, t2, t3, &runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2570 | |
| 2571 | // Locate first character of substring to copy. |
| 2572 | __ Addu(t1, t1, a3); |
| 2573 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2574 | // Locate first character of result. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2575 | __ Addu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2576 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2577 | // v0: result string |
| 2578 | // a1: first character of result string |
| 2579 | // a2: result string length |
| 2580 | // t1: first character of substring to copy |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2581 | STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 2582 | StringHelper::GenerateCopyCharacters( |
| 2583 | masm, a1, t1, a2, a3, String::ONE_BYTE_ENCODING); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2584 | __ jmp(&return_v0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2585 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2586 | // Allocate and copy the resulting two-byte string. |
| 2587 | __ bind(&two_byte_sequential); |
| 2588 | __ AllocateTwoByteString(v0, a2, t0, t2, t3, &runtime); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2589 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2590 | // Locate first character of substring to copy. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2591 | STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2592 | __ Lsa(t1, t1, a3, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2593 | // Locate first character of result. |
| 2594 | __ Addu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2595 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2596 | // v0: result string. |
| 2597 | // a1: first character of result. |
| 2598 | // a2: result length. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2599 | // t1: first character of substring to copy. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2600 | STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2601 | StringHelper::GenerateCopyCharacters( |
| 2602 | masm, a1, t1, a2, a3, String::TWO_BYTE_ENCODING); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2603 | |
| 2604 | __ bind(&return_v0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2605 | Counters* counters = isolate()->counters(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2606 | __ IncrementCounter(counters->sub_string_native(), 1, a3, t0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2607 | __ DropAndRet(3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2608 | |
| 2609 | // Just jump to runtime to create the sub string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2610 | __ bind(&runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2611 | __ TailCallRuntime(Runtime::kSubString); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2612 | |
| 2613 | __ bind(&single_char); |
| 2614 | // v0: original string |
| 2615 | // a1: instance type |
| 2616 | // a2: length |
| 2617 | // a3: from index (untagged) |
| 2618 | __ SmiTag(a3, a3); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2619 | StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime, |
| 2620 | STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2621 | generator.GenerateFast(masm); |
| 2622 | __ DropAndRet(3); |
| 2623 | generator.SkipSlow(masm, &runtime); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2627 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 2628 | // The ToNumber stub takes one argument in a0. |
| 2629 | Label not_smi; |
| 2630 | __ JumpIfNotSmi(a0, ¬_smi); |
| 2631 | __ Ret(USE_DELAY_SLOT); |
| 2632 | __ mov(v0, a0); |
| 2633 | __ bind(¬_smi); |
| 2634 | |
| 2635 | Label not_heap_number; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2636 | __ GetObjectType(a0, a1, a1); |
| 2637 | // a0: receiver |
| 2638 | // a1: receiver instance type |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2639 | __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE)); |
| 2640 | __ Ret(USE_DELAY_SLOT); |
| 2641 | __ mov(v0, a0); |
| 2642 | __ bind(¬_heap_number); |
| 2643 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2644 | NonNumberToNumberStub stub(masm->isolate()); |
| 2645 | __ TailCallStub(&stub); |
| 2646 | } |
| 2647 | |
| 2648 | void NonNumberToNumberStub::Generate(MacroAssembler* masm) { |
| 2649 | // The NonNumberToNumber stub takes on argument in a0. |
| 2650 | __ AssertNotNumber(a0); |
| 2651 | |
| 2652 | Label not_string; |
| 2653 | __ GetObjectType(a0, a1, a1); |
| 2654 | // a0: receiver |
| 2655 | // a1: receiver instance type |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2656 | __ Branch(¬_string, hs, a1, Operand(FIRST_NONSTRING_TYPE)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2657 | StringToNumberStub stub(masm->isolate()); |
| 2658 | __ TailCallStub(&stub); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2659 | __ bind(¬_string); |
| 2660 | |
| 2661 | Label not_oddball; |
| 2662 | __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE)); |
| 2663 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2664 | __ lw(v0, FieldMemOperand(a0, Oddball::kToNumberOffset)); // In delay slot. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2665 | __ bind(¬_oddball); |
| 2666 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2667 | __ Push(a0); // Push argument. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2668 | __ TailCallRuntime(Runtime::kToNumber); |
| 2669 | } |
| 2670 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2671 | void StringToNumberStub::Generate(MacroAssembler* masm) { |
| 2672 | // The StringToNumber stub takes on argument in a0. |
| 2673 | __ AssertString(a0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2674 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2675 | // Check if string has a cached array index. |
| 2676 | Label runtime; |
| 2677 | __ lw(a2, FieldMemOperand(a0, String::kHashFieldOffset)); |
| 2678 | __ And(at, a2, Operand(String::kContainsCachedArrayIndexMask)); |
| 2679 | __ Branch(&runtime, ne, at, Operand(zero_reg)); |
| 2680 | __ IndexFromHash(a2, v0); |
| 2681 | __ Ret(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2682 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2683 | __ bind(&runtime); |
| 2684 | __ Push(a0); // Push argument. |
| 2685 | __ TailCallRuntime(Runtime::kStringToNumber); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2686 | } |
| 2687 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2688 | void ToStringStub::Generate(MacroAssembler* masm) { |
| 2689 | // The ToString stub takes on argument in a0. |
| 2690 | Label is_number; |
| 2691 | __ JumpIfSmi(a0, &is_number); |
| 2692 | |
| 2693 | Label not_string; |
| 2694 | __ GetObjectType(a0, a1, a1); |
| 2695 | // a0: receiver |
| 2696 | // a1: receiver instance type |
| 2697 | __ Branch(¬_string, ge, a1, Operand(FIRST_NONSTRING_TYPE)); |
| 2698 | __ Ret(USE_DELAY_SLOT); |
| 2699 | __ mov(v0, a0); |
| 2700 | __ bind(¬_string); |
| 2701 | |
| 2702 | Label not_heap_number; |
| 2703 | __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE)); |
| 2704 | __ bind(&is_number); |
| 2705 | NumberToStringStub stub(isolate()); |
| 2706 | __ TailCallStub(&stub); |
| 2707 | __ bind(¬_heap_number); |
| 2708 | |
| 2709 | Label not_oddball; |
| 2710 | __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE)); |
| 2711 | __ Ret(USE_DELAY_SLOT); |
| 2712 | __ lw(v0, FieldMemOperand(a0, Oddball::kToStringOffset)); |
| 2713 | __ bind(¬_oddball); |
| 2714 | |
| 2715 | __ push(a0); // Push argument. |
| 2716 | __ TailCallRuntime(Runtime::kToString); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2717 | } |
| 2718 | |
| 2719 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2720 | void ToNameStub::Generate(MacroAssembler* masm) { |
| 2721 | // The ToName stub takes on argument in a0. |
| 2722 | Label is_number; |
| 2723 | __ JumpIfSmi(a0, &is_number); |
| 2724 | |
| 2725 | Label not_name; |
| 2726 | STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE); |
| 2727 | __ GetObjectType(a0, a1, a1); |
| 2728 | // a0: receiver |
| 2729 | // a1: receiver instance type |
| 2730 | __ Branch(¬_name, gt, a1, Operand(LAST_NAME_TYPE)); |
| 2731 | __ Ret(USE_DELAY_SLOT); |
| 2732 | __ mov(v0, a0); |
| 2733 | __ bind(¬_name); |
| 2734 | |
| 2735 | Label not_heap_number; |
| 2736 | __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE)); |
| 2737 | __ bind(&is_number); |
| 2738 | NumberToStringStub stub(isolate()); |
| 2739 | __ TailCallStub(&stub); |
| 2740 | __ bind(¬_heap_number); |
| 2741 | |
| 2742 | Label not_oddball; |
| 2743 | __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE)); |
| 2744 | __ Ret(USE_DELAY_SLOT); |
| 2745 | __ lw(v0, FieldMemOperand(a0, Oddball::kToStringOffset)); |
| 2746 | __ bind(¬_oddball); |
| 2747 | |
| 2748 | __ push(a0); // Push argument. |
| 2749 | __ TailCallRuntime(Runtime::kToName); |
| 2750 | } |
| 2751 | |
| 2752 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2753 | void StringHelper::GenerateFlatOneByteStringEquals( |
| 2754 | MacroAssembler* masm, Register left, Register right, Register scratch1, |
| 2755 | Register scratch2, Register scratch3) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2756 | Register length = scratch1; |
| 2757 | |
| 2758 | // Compare lengths. |
| 2759 | Label strings_not_equal, check_zero_length; |
| 2760 | __ lw(length, FieldMemOperand(left, String::kLengthOffset)); |
| 2761 | __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 2762 | __ Branch(&check_zero_length, eq, length, Operand(scratch2)); |
| 2763 | __ bind(&strings_not_equal); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2764 | DCHECK(is_int16(NOT_EQUAL)); |
| 2765 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2766 | __ li(v0, Operand(Smi::FromInt(NOT_EQUAL))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2767 | |
| 2768 | // Check if the length is zero. |
| 2769 | Label compare_chars; |
| 2770 | __ bind(&check_zero_length); |
| 2771 | STATIC_ASSERT(kSmiTag == 0); |
| 2772 | __ Branch(&compare_chars, ne, length, Operand(zero_reg)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2773 | DCHECK(is_int16(EQUAL)); |
| 2774 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2775 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2776 | |
| 2777 | // Compare characters. |
| 2778 | __ bind(&compare_chars); |
| 2779 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2780 | GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3, |
| 2781 | v0, &strings_not_equal); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2782 | |
| 2783 | // Characters are equal. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2784 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2785 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2789 | void StringHelper::GenerateCompareFlatOneByteStrings( |
| 2790 | MacroAssembler* masm, Register left, Register right, Register scratch1, |
| 2791 | Register scratch2, Register scratch3, Register scratch4) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2792 | Label result_not_equal, compare_lengths; |
| 2793 | // Find minimum length and length difference. |
| 2794 | __ lw(scratch1, FieldMemOperand(left, String::kLengthOffset)); |
| 2795 | __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 2796 | __ Subu(scratch3, scratch1, Operand(scratch2)); |
| 2797 | Register length_delta = scratch3; |
| 2798 | __ slt(scratch4, scratch2, scratch1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2799 | __ Movn(scratch1, scratch2, scratch4); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2800 | Register min_length = scratch1; |
| 2801 | STATIC_ASSERT(kSmiTag == 0); |
| 2802 | __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg)); |
| 2803 | |
| 2804 | // Compare loop. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2805 | GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2, |
| 2806 | scratch4, v0, &result_not_equal); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2807 | |
| 2808 | // Compare lengths - strings up to min-length are equal. |
| 2809 | __ bind(&compare_lengths); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2810 | DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2811 | // Use length_delta as result if it's zero. |
| 2812 | __ mov(scratch2, length_delta); |
| 2813 | __ mov(scratch4, zero_reg); |
| 2814 | __ mov(v0, zero_reg); |
| 2815 | |
| 2816 | __ bind(&result_not_equal); |
| 2817 | // Conditionally update the result based either on length_delta or |
| 2818 | // the last comparion performed in the loop above. |
| 2819 | Label ret; |
| 2820 | __ Branch(&ret, eq, scratch2, Operand(scratch4)); |
| 2821 | __ li(v0, Operand(Smi::FromInt(GREATER))); |
| 2822 | __ Branch(&ret, gt, scratch2, Operand(scratch4)); |
| 2823 | __ li(v0, Operand(Smi::FromInt(LESS))); |
| 2824 | __ bind(&ret); |
| 2825 | __ Ret(); |
| 2826 | } |
| 2827 | |
| 2828 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2829 | void StringHelper::GenerateOneByteCharsCompareLoop( |
| 2830 | MacroAssembler* masm, Register left, Register right, Register length, |
| 2831 | Register scratch1, Register scratch2, Register scratch3, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2832 | Label* chars_not_equal) { |
| 2833 | // Change index to run from -length to -1 by adding length to string |
| 2834 | // start. This means that loop ends when index reaches zero, which |
| 2835 | // doesn't need an additional compare. |
| 2836 | __ SmiUntag(length); |
| 2837 | __ Addu(scratch1, length, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2838 | Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2839 | __ Addu(left, left, Operand(scratch1)); |
| 2840 | __ Addu(right, right, Operand(scratch1)); |
| 2841 | __ Subu(length, zero_reg, length); |
| 2842 | Register index = length; // index = -length; |
| 2843 | |
| 2844 | |
| 2845 | // Compare loop. |
| 2846 | Label loop; |
| 2847 | __ bind(&loop); |
| 2848 | __ Addu(scratch3, left, index); |
| 2849 | __ lbu(scratch1, MemOperand(scratch3)); |
| 2850 | __ Addu(scratch3, right, index); |
| 2851 | __ lbu(scratch2, MemOperand(scratch3)); |
| 2852 | __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2)); |
| 2853 | __ Addu(index, index, 1); |
| 2854 | __ Branch(&loop, ne, index, Operand(zero_reg)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2858 | void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) { |
| 2859 | // ----------- S t a t e ------------- |
| 2860 | // -- a1 : left |
| 2861 | // -- a0 : right |
| 2862 | // -- ra : return address |
| 2863 | // ----------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2864 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2865 | // Load a2 with the allocation site. We stick an undefined dummy value here |
| 2866 | // and replace it with the real allocation site later when we instantiate this |
| 2867 | // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate(). |
| 2868 | __ li(a2, handle(isolate()->heap()->undefined_value())); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2869 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2870 | // Make sure that we actually patched the allocation site. |
| 2871 | if (FLAG_debug_code) { |
| 2872 | __ And(at, a2, Operand(kSmiTagMask)); |
| 2873 | __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg)); |
| 2874 | __ lw(t0, FieldMemOperand(a2, HeapObject::kMapOffset)); |
| 2875 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 2876 | __ Assert(eq, kExpectedAllocationSite, t0, Operand(at)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2877 | } |
| 2878 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2879 | // Tail call into the stub that handles binary operations with allocation |
| 2880 | // sites. |
| 2881 | BinaryOpWithAllocationSiteStub stub(isolate(), state()); |
| 2882 | __ TailCallStub(&stub); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2886 | void CompareICStub::GenerateBooleans(MacroAssembler* masm) { |
| 2887 | DCHECK_EQ(CompareICState::BOOLEAN, state()); |
| 2888 | Label miss; |
| 2889 | |
| 2890 | __ CheckMap(a1, a2, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK); |
| 2891 | __ CheckMap(a0, a3, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2892 | if (!Token::IsEqualityOp(op())) { |
| 2893 | __ lw(a1, FieldMemOperand(a1, Oddball::kToNumberOffset)); |
| 2894 | __ AssertSmi(a1); |
| 2895 | __ lw(a0, FieldMemOperand(a0, Oddball::kToNumberOffset)); |
| 2896 | __ AssertSmi(a0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2897 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2898 | __ Ret(USE_DELAY_SLOT); |
| 2899 | __ Subu(v0, a1, a0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2900 | |
| 2901 | __ bind(&miss); |
| 2902 | GenerateMiss(masm); |
| 2903 | } |
| 2904 | |
| 2905 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2906 | void CompareICStub::GenerateSmis(MacroAssembler* masm) { |
| 2907 | DCHECK(state() == CompareICState::SMI); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2908 | Label miss; |
| 2909 | __ Or(a2, a1, a0); |
| 2910 | __ JumpIfNotSmi(a2, &miss); |
| 2911 | |
| 2912 | if (GetCondition() == eq) { |
| 2913 | // For equality we do not care about the sign of the result. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2914 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2915 | __ Subu(v0, a0, a1); |
| 2916 | } else { |
| 2917 | // Untag before subtracting to avoid handling overflow. |
| 2918 | __ SmiUntag(a1); |
| 2919 | __ SmiUntag(a0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2920 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2921 | __ Subu(v0, a1, a0); |
| 2922 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2923 | |
| 2924 | __ bind(&miss); |
| 2925 | GenerateMiss(masm); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2926 | } |
| 2927 | |
| 2928 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2929 | void CompareICStub::GenerateNumbers(MacroAssembler* masm) { |
| 2930 | DCHECK(state() == CompareICState::NUMBER); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2931 | |
| 2932 | Label generic_stub; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2933 | Label unordered, maybe_undefined1, maybe_undefined2; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2934 | Label miss; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2935 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2936 | if (left() == CompareICState::SMI) { |
| 2937 | __ JumpIfNotSmi(a1, &miss); |
| 2938 | } |
| 2939 | if (right() == CompareICState::SMI) { |
| 2940 | __ JumpIfNotSmi(a0, &miss); |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 2941 | } |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 2942 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2943 | // Inlining the double comparison and falling back to the general compare |
| 2944 | // stub if NaN is involved. |
| 2945 | // Load left and right operand. |
| 2946 | Label done, left, left_smi, right_smi; |
| 2947 | __ JumpIfSmi(a0, &right_smi); |
| 2948 | __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1, |
| 2949 | DONT_DO_SMI_CHECK); |
| 2950 | __ Subu(a2, a0, Operand(kHeapObjectTag)); |
| 2951 | __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset)); |
| 2952 | __ Branch(&left); |
| 2953 | __ bind(&right_smi); |
| 2954 | __ SmiUntag(a2, a0); // Can't clobber a0 yet. |
| 2955 | FPURegister single_scratch = f6; |
| 2956 | __ mtc1(a2, single_scratch); |
| 2957 | __ cvt_d_w(f2, single_scratch); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2958 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2959 | __ bind(&left); |
| 2960 | __ JumpIfSmi(a1, &left_smi); |
| 2961 | __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2, |
| 2962 | DONT_DO_SMI_CHECK); |
| 2963 | __ Subu(a2, a1, Operand(kHeapObjectTag)); |
| 2964 | __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset)); |
| 2965 | __ Branch(&done); |
| 2966 | __ bind(&left_smi); |
| 2967 | __ SmiUntag(a2, a1); // Can't clobber a1 yet. |
| 2968 | single_scratch = f8; |
| 2969 | __ mtc1(a2, single_scratch); |
| 2970 | __ cvt_d_w(f0, single_scratch); |
| 2971 | |
| 2972 | __ bind(&done); |
| 2973 | |
| 2974 | // Return a result of -1, 0, or 1, or use CompareStub for NaNs. |
| 2975 | Label fpu_eq, fpu_lt; |
| 2976 | // Test if equal, and also handle the unordered/NaN case. |
| 2977 | __ BranchF(&fpu_eq, &unordered, eq, f0, f2); |
| 2978 | |
| 2979 | // Test if less (unordered case is already handled). |
| 2980 | __ BranchF(&fpu_lt, NULL, lt, f0, f2); |
| 2981 | |
| 2982 | // Otherwise it's greater, so just fall thru, and return. |
| 2983 | DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS)); |
| 2984 | __ Ret(USE_DELAY_SLOT); |
| 2985 | __ li(v0, Operand(GREATER)); |
| 2986 | |
| 2987 | __ bind(&fpu_eq); |
| 2988 | __ Ret(USE_DELAY_SLOT); |
| 2989 | __ li(v0, Operand(EQUAL)); |
| 2990 | |
| 2991 | __ bind(&fpu_lt); |
| 2992 | __ Ret(USE_DELAY_SLOT); |
| 2993 | __ li(v0, Operand(LESS)); |
| 2994 | |
| 2995 | __ bind(&unordered); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2996 | __ bind(&generic_stub); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2997 | CompareICStub stub(isolate(), op(), CompareICState::GENERIC, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2998 | CompareICState::GENERIC, CompareICState::GENERIC); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2999 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 3000 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3001 | __ bind(&maybe_undefined1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3002 | if (Token::IsOrderedRelationalCompareOp(op())) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3003 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 3004 | __ Branch(&miss, ne, a0, Operand(at)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3005 | __ JumpIfSmi(a1, &unordered); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3006 | __ GetObjectType(a1, a2, a2); |
| 3007 | __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE)); |
| 3008 | __ jmp(&unordered); |
| 3009 | } |
| 3010 | |
| 3011 | __ bind(&maybe_undefined2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3012 | if (Token::IsOrderedRelationalCompareOp(op())) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3013 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 3014 | __ Branch(&unordered, eq, a1, Operand(at)); |
| 3015 | } |
| 3016 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3017 | __ bind(&miss); |
| 3018 | GenerateMiss(masm); |
| 3019 | } |
| 3020 | |
| 3021 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3022 | void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 3023 | DCHECK(state() == CompareICState::INTERNALIZED_STRING); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3024 | Label miss; |
| 3025 | |
| 3026 | // Registers containing left and right operands respectively. |
| 3027 | Register left = a1; |
| 3028 | Register right = a0; |
| 3029 | Register tmp1 = a2; |
| 3030 | Register tmp2 = a3; |
| 3031 | |
| 3032 | // Check that both operands are heap objects. |
| 3033 | __ JumpIfEitherSmi(left, right, &miss); |
| 3034 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3035 | // Check that both operands are internalized strings. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3036 | __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 3037 | __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 3038 | __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3039 | __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3040 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 3041 | __ Or(tmp1, tmp1, Operand(tmp2)); |
| 3042 | __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask)); |
| 3043 | __ Branch(&miss, ne, at, Operand(zero_reg)); |
| 3044 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3045 | // Make sure a0 is non-zero. At this point input operands are |
| 3046 | // guaranteed to be non-zero. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3047 | DCHECK(right.is(a0)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3048 | STATIC_ASSERT(EQUAL == 0); |
| 3049 | STATIC_ASSERT(kSmiTag == 0); |
| 3050 | __ mov(v0, right); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3051 | // Internalized strings are compared by identity. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3052 | __ Ret(ne, left, Operand(right)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3053 | DCHECK(is_int16(EQUAL)); |
| 3054 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3055 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3056 | |
| 3057 | __ bind(&miss); |
| 3058 | GenerateMiss(masm); |
| 3059 | } |
| 3060 | |
| 3061 | |
| 3062 | void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 3063 | DCHECK(state() == CompareICState::UNIQUE_NAME); |
| 3064 | DCHECK(GetCondition() == eq); |
| 3065 | Label miss; |
| 3066 | |
| 3067 | // Registers containing left and right operands respectively. |
| 3068 | Register left = a1; |
| 3069 | Register right = a0; |
| 3070 | Register tmp1 = a2; |
| 3071 | Register tmp2 = a3; |
| 3072 | |
| 3073 | // Check that both operands are heap objects. |
| 3074 | __ JumpIfEitherSmi(left, right, &miss); |
| 3075 | |
| 3076 | // Check that both operands are unique names. This leaves the instance |
| 3077 | // types loaded in tmp1 and tmp2. |
| 3078 | __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 3079 | __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 3080 | __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3081 | __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 3082 | |
| 3083 | __ JumpIfNotUniqueNameInstanceType(tmp1, &miss); |
| 3084 | __ JumpIfNotUniqueNameInstanceType(tmp2, &miss); |
| 3085 | |
| 3086 | // Use a0 as result |
| 3087 | __ mov(v0, a0); |
| 3088 | |
| 3089 | // Unique names are compared by identity. |
| 3090 | Label done; |
| 3091 | __ Branch(&done, ne, left, Operand(right)); |
| 3092 | // Make sure a0 is non-zero. At this point input operands are |
| 3093 | // guaranteed to be non-zero. |
| 3094 | DCHECK(right.is(a0)); |
| 3095 | STATIC_ASSERT(EQUAL == 0); |
| 3096 | STATIC_ASSERT(kSmiTag == 0); |
| 3097 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
| 3098 | __ bind(&done); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3099 | __ Ret(); |
| 3100 | |
| 3101 | __ bind(&miss); |
| 3102 | GenerateMiss(masm); |
| 3103 | } |
| 3104 | |
| 3105 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3106 | void CompareICStub::GenerateStrings(MacroAssembler* masm) { |
| 3107 | DCHECK(state() == CompareICState::STRING); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3108 | Label miss; |
| 3109 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3110 | bool equality = Token::IsEqualityOp(op()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3111 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3112 | // Registers containing left and right operands respectively. |
| 3113 | Register left = a1; |
| 3114 | Register right = a0; |
| 3115 | Register tmp1 = a2; |
| 3116 | Register tmp2 = a3; |
| 3117 | Register tmp3 = t0; |
| 3118 | Register tmp4 = t1; |
| 3119 | Register tmp5 = t2; |
| 3120 | |
| 3121 | // Check that both operands are heap objects. |
| 3122 | __ JumpIfEitherSmi(left, right, &miss); |
| 3123 | |
| 3124 | // Check that both operands are strings. This leaves the instance |
| 3125 | // types loaded in tmp1 and tmp2. |
| 3126 | __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 3127 | __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 3128 | __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3129 | __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 3130 | STATIC_ASSERT(kNotStringTag != 0); |
| 3131 | __ Or(tmp3, tmp1, tmp2); |
| 3132 | __ And(tmp5, tmp3, Operand(kIsNotStringMask)); |
| 3133 | __ Branch(&miss, ne, tmp5, Operand(zero_reg)); |
| 3134 | |
| 3135 | // Fast check for identical strings. |
| 3136 | Label left_ne_right; |
| 3137 | STATIC_ASSERT(EQUAL == 0); |
| 3138 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3139 | __ Branch(&left_ne_right, ne, left, Operand(right)); |
| 3140 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3141 | __ mov(v0, zero_reg); // In the delay slot. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3142 | __ bind(&left_ne_right); |
| 3143 | |
| 3144 | // Handle not identical strings. |
| 3145 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3146 | // Check that both strings are internalized strings. If they are, we're done |
| 3147 | // because we already know they are not identical. We know they are both |
| 3148 | // strings. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3149 | if (equality) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3150 | DCHECK(GetCondition() == eq); |
| 3151 | STATIC_ASSERT(kInternalizedTag == 0); |
| 3152 | __ Or(tmp3, tmp1, Operand(tmp2)); |
| 3153 | __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3154 | Label is_symbol; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3155 | __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3156 | // Make sure a0 is non-zero. At this point input operands are |
| 3157 | // guaranteed to be non-zero. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3158 | DCHECK(right.is(a0)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3159 | __ Ret(USE_DELAY_SLOT); |
| 3160 | __ mov(v0, a0); // In the delay slot. |
| 3161 | __ bind(&is_symbol); |
| 3162 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3163 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3164 | // Check that both strings are sequential one-byte. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3165 | Label runtime; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3166 | __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4, |
| 3167 | &runtime); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3168 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3169 | // Compare flat one-byte strings. Returns when done. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3170 | if (equality) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3171 | StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2, |
| 3172 | tmp3); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3173 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3174 | StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1, |
| 3175 | tmp2, tmp3, tmp4); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3176 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3177 | |
| 3178 | // Handle more complex cases in runtime. |
| 3179 | __ bind(&runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3180 | if (equality) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 3181 | { |
| 3182 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3183 | __ Push(left, right); |
| 3184 | __ CallRuntime(Runtime::kStringEqual); |
| 3185 | } |
| 3186 | __ LoadRoot(a0, Heap::kTrueValueRootIndex); |
| 3187 | __ Ret(USE_DELAY_SLOT); |
| 3188 | __ Subu(v0, v0, a0); // In delay slot. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3189 | } else { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 3190 | __ Push(left, right); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3191 | __ TailCallRuntime(Runtime::kStringCompare); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3192 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3193 | |
| 3194 | __ bind(&miss); |
| 3195 | GenerateMiss(masm); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3199 | void CompareICStub::GenerateReceivers(MacroAssembler* masm) { |
| 3200 | DCHECK_EQ(CompareICState::RECEIVER, state()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3201 | Label miss; |
| 3202 | __ And(a2, a1, Operand(a0)); |
| 3203 | __ JumpIfSmi(a2, &miss); |
| 3204 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3205 | STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3206 | __ GetObjectType(a0, a2, a2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3207 | __ Branch(&miss, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3208 | __ GetObjectType(a1, a2, a2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3209 | __ Branch(&miss, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3210 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3211 | DCHECK_EQ(eq, GetCondition()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3212 | __ Ret(USE_DELAY_SLOT); |
| 3213 | __ subu(v0, a0, a1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3214 | |
| 3215 | __ bind(&miss); |
| 3216 | GenerateMiss(masm); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3220 | void CompareICStub::GenerateKnownReceivers(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3221 | Label miss; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3222 | Handle<WeakCell> cell = Map::WeakCellForMap(known_map_); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3223 | __ And(a2, a1, a0); |
| 3224 | __ JumpIfSmi(a2, &miss); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3225 | __ GetWeakValue(t0, cell); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3226 | __ lw(a2, FieldMemOperand(a0, HeapObject::kMapOffset)); |
| 3227 | __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3228 | __ Branch(&miss, ne, a2, Operand(t0)); |
| 3229 | __ Branch(&miss, ne, a3, Operand(t0)); |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 3230 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3231 | if (Token::IsEqualityOp(op())) { |
| 3232 | __ Ret(USE_DELAY_SLOT); |
| 3233 | __ subu(v0, a0, a1); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3234 | } else { |
| 3235 | if (op() == Token::LT || op() == Token::LTE) { |
| 3236 | __ li(a2, Operand(Smi::FromInt(GREATER))); |
| 3237 | } else { |
| 3238 | __ li(a2, Operand(Smi::FromInt(LESS))); |
| 3239 | } |
| 3240 | __ Push(a1, a0, a2); |
| 3241 | __ TailCallRuntime(Runtime::kCompare); |
| 3242 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3243 | |
| 3244 | __ bind(&miss); |
| 3245 | GenerateMiss(masm); |
| 3246 | } |
| 3247 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3248 | |
| 3249 | void CompareICStub::GenerateMiss(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3250 | { |
| 3251 | // Call the runtime system in a fresh internal frame. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3252 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3253 | __ Push(a1, a0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3254 | __ Push(ra, a1, a0); |
| 3255 | __ li(t0, Operand(Smi::FromInt(op()))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3256 | __ addiu(sp, sp, -kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3257 | __ CallRuntime(Runtime::kCompareIC_Miss, 3, kDontSaveFPRegs, |
| 3258 | USE_DELAY_SLOT); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3259 | __ sw(t0, MemOperand(sp)); // In the delay slot. |
| 3260 | // Compute the entry point of the rewritten stub. |
| 3261 | __ Addu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3262 | // Restore registers. |
| 3263 | __ Pop(a1, a0, ra); |
| 3264 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3265 | __ Jump(a2); |
| 3266 | } |
| 3267 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3268 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3269 | void DirectCEntryStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3270 | // Make place for arguments to fit C calling convention. Most of the callers |
| 3271 | // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame |
| 3272 | // so they handle stack restoring and we don't have to do that here. |
| 3273 | // Any caller of DirectCEntryStub::GenerateCall must take care of dropping |
| 3274 | // kCArgsSlotsSize stack space after the call. |
| 3275 | __ Subu(sp, sp, Operand(kCArgsSlotsSize)); |
| 3276 | // Place the return address on the stack, making the call |
| 3277 | // GC safe. The RegExp backend also relies on this. |
| 3278 | __ sw(ra, MemOperand(sp, kCArgsSlotsSize)); |
| 3279 | __ Call(t9); // Call the C++ function. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3280 | __ lw(t9, MemOperand(sp, kCArgsSlotsSize)); |
| 3281 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3282 | if (FLAG_debug_code && FLAG_enable_slow_asserts) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3283 | // In case of an error the return address may point to a memory area |
| 3284 | // filled with kZapValue by the GC. |
| 3285 | // Dereference the address and check for this. |
| 3286 | __ lw(t0, MemOperand(t9)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3287 | __ Assert(ne, kReceivedInvalidReturnAddress, t0, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3288 | Operand(reinterpret_cast<uint32_t>(kZapValue))); |
| 3289 | } |
| 3290 | __ Jump(t9); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3291 | } |
| 3292 | |
| 3293 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3294 | void DirectCEntryStub::GenerateCall(MacroAssembler* masm, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3295 | Register target) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3296 | intptr_t loc = |
| 3297 | reinterpret_cast<intptr_t>(GetCode().location()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3298 | __ Move(t9, target); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3299 | __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE); |
| 3300 | __ Call(at); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3301 | } |
| 3302 | |
| 3303 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3304 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 3305 | Label* miss, |
| 3306 | Label* done, |
| 3307 | Register receiver, |
| 3308 | Register properties, |
| 3309 | Handle<Name> name, |
| 3310 | Register scratch0) { |
| 3311 | DCHECK(name->IsUniqueName()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3312 | // 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] | 3313 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 3314 | // undefined value), it guarantees the hash table doesn't contain the |
| 3315 | // property. It's true even if some slots represent deleted properties |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3316 | // (their names are the hole value). |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3317 | for (int i = 0; i < kInlinedProbes; i++) { |
| 3318 | // scratch0 points to properties hash. |
| 3319 | // Compute the masked index: (hash + i + i * i) & mask. |
| 3320 | Register index = scratch0; |
| 3321 | // Capacity is smi 2^n. |
| 3322 | __ lw(index, FieldMemOperand(properties, kCapacityOffset)); |
| 3323 | __ Subu(index, index, Operand(1)); |
| 3324 | __ And(index, index, Operand( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3325 | Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i)))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3326 | |
| 3327 | // Scale the index by multiplying by the entry size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3328 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3329 | __ Lsa(index, index, index, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3330 | |
| 3331 | Register entity_name = scratch0; |
| 3332 | // Having undefined at this place means the name is not contained. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3333 | STATIC_ASSERT(kSmiTagSize == 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3334 | Register tmp = properties; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3335 | __ Lsa(tmp, properties, index, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3336 | __ lw(entity_name, FieldMemOperand(tmp, kElementsStartOffset)); |
| 3337 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3338 | DCHECK(!tmp.is(entity_name)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3339 | __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex); |
| 3340 | __ Branch(done, eq, entity_name, Operand(tmp)); |
| 3341 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3342 | // Load the hole ready for use below: |
| 3343 | __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3344 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3345 | // Stop if found the property. |
| 3346 | __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3347 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3348 | Label good; |
| 3349 | __ Branch(&good, eq, entity_name, Operand(tmp)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3350 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3351 | // Check if the entry name is not a unique name. |
| 3352 | __ lw(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset)); |
| 3353 | __ lbu(entity_name, |
| 3354 | FieldMemOperand(entity_name, Map::kInstanceTypeOffset)); |
| 3355 | __ JumpIfNotUniqueNameInstanceType(entity_name, miss); |
| 3356 | __ bind(&good); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3357 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3358 | // Restore the properties. |
| 3359 | __ lw(properties, |
| 3360 | FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | const int spill_mask = |
| 3364 | (ra.bit() | t2.bit() | t1.bit() | t0.bit() | a3.bit() | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3365 | a2.bit() | a1.bit() | a0.bit() | v0.bit()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3366 | |
| 3367 | __ MultiPush(spill_mask); |
| 3368 | __ lw(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3369 | __ li(a1, Operand(Handle<Name>(name))); |
| 3370 | NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3371 | __ CallStub(&stub); |
| 3372 | __ mov(at, v0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3373 | __ MultiPop(spill_mask); |
| 3374 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3375 | __ Branch(done, eq, at, Operand(zero_reg)); |
| 3376 | __ Branch(miss, ne, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3380 | // Probe the name dictionary in the |elements| register. Jump to the |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3381 | // |done| label if a property with the given name is found. Jump to |
| 3382 | // the |miss| label otherwise. |
| 3383 | // If lookup was successful |scratch2| will be equal to elements + 4 * index. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3384 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 3385 | Label* miss, |
| 3386 | Label* done, |
| 3387 | Register elements, |
| 3388 | Register name, |
| 3389 | Register scratch1, |
| 3390 | Register scratch2) { |
| 3391 | DCHECK(!elements.is(scratch1)); |
| 3392 | DCHECK(!elements.is(scratch2)); |
| 3393 | DCHECK(!name.is(scratch1)); |
| 3394 | DCHECK(!name.is(scratch2)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3395 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3396 | __ AssertName(name); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3397 | |
| 3398 | // Compute the capacity mask. |
| 3399 | __ lw(scratch1, FieldMemOperand(elements, kCapacityOffset)); |
| 3400 | __ sra(scratch1, scratch1, kSmiTagSize); // convert smi to int |
| 3401 | __ Subu(scratch1, scratch1, Operand(1)); |
| 3402 | |
| 3403 | // Generate an unrolled loop that performs a few probes before |
| 3404 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 3405 | // cover ~93% of loads from dictionaries. |
| 3406 | for (int i = 0; i < kInlinedProbes; i++) { |
| 3407 | // Compute the masked index: (hash + i + i * i) & mask. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3408 | __ lw(scratch2, FieldMemOperand(name, Name::kHashFieldOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3409 | if (i > 0) { |
| 3410 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 3411 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 3412 | // shifted in the following and instruction. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3413 | DCHECK(NameDictionary::GetProbeOffset(i) < |
| 3414 | 1 << (32 - Name::kHashFieldOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3415 | __ Addu(scratch2, scratch2, Operand( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3416 | NameDictionary::GetProbeOffset(i) << Name::kHashShift)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3417 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3418 | __ srl(scratch2, scratch2, Name::kHashShift); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3419 | __ And(scratch2, scratch1, scratch2); |
| 3420 | |
| 3421 | // Scale the index by multiplying by the element size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3422 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3423 | // scratch2 = scratch2 * 3. |
| 3424 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3425 | __ Lsa(scratch2, scratch2, scratch2, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3426 | |
| 3427 | // Check if the key is identical to the name. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3428 | __ Lsa(scratch2, elements, scratch2, 2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3429 | __ lw(at, FieldMemOperand(scratch2, kElementsStartOffset)); |
| 3430 | __ Branch(done, eq, name, Operand(at)); |
| 3431 | } |
| 3432 | |
| 3433 | const int spill_mask = |
| 3434 | (ra.bit() | t2.bit() | t1.bit() | t0.bit() | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3435 | a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) & |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3436 | ~(scratch1.bit() | scratch2.bit()); |
| 3437 | |
| 3438 | __ MultiPush(spill_mask); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3439 | if (name.is(a0)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3440 | DCHECK(!elements.is(a1)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3441 | __ Move(a1, name); |
| 3442 | __ Move(a0, elements); |
| 3443 | } else { |
| 3444 | __ Move(a0, elements); |
| 3445 | __ Move(a1, name); |
| 3446 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3447 | NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3448 | __ CallStub(&stub); |
| 3449 | __ mov(scratch2, a2); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3450 | __ mov(at, v0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3451 | __ MultiPop(spill_mask); |
| 3452 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3453 | __ Branch(done, ne, at, Operand(zero_reg)); |
| 3454 | __ Branch(miss, eq, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3455 | } |
| 3456 | |
| 3457 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3458 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3459 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 3460 | // we cannot call anything that could cause a GC from this stub. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3461 | // Registers: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3462 | // result: NameDictionary to probe |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3463 | // a1: key |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3464 | // dictionary: NameDictionary to probe. |
| 3465 | // index: will hold an index of entry if lookup is successful. |
| 3466 | // might alias with result_. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3467 | // Returns: |
| 3468 | // result_ is zero if lookup failed, non zero otherwise. |
| 3469 | |
| 3470 | Register result = v0; |
| 3471 | Register dictionary = a0; |
| 3472 | Register key = a1; |
| 3473 | Register index = a2; |
| 3474 | Register mask = a3; |
| 3475 | Register hash = t0; |
| 3476 | Register undefined = t1; |
| 3477 | Register entry_key = t2; |
| 3478 | |
| 3479 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 3480 | |
| 3481 | __ lw(mask, FieldMemOperand(dictionary, kCapacityOffset)); |
| 3482 | __ sra(mask, mask, kSmiTagSize); |
| 3483 | __ Subu(mask, mask, Operand(1)); |
| 3484 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3485 | __ lw(hash, FieldMemOperand(key, Name::kHashFieldOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3486 | |
| 3487 | __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex); |
| 3488 | |
| 3489 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 3490 | // Compute the masked index: (hash + i + i * i) & mask. |
| 3491 | // Capacity is smi 2^n. |
| 3492 | if (i > 0) { |
| 3493 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 3494 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 3495 | // shifted in the following and instruction. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3496 | DCHECK(NameDictionary::GetProbeOffset(i) < |
| 3497 | 1 << (32 - Name::kHashFieldOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3498 | __ Addu(index, hash, Operand( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3499 | NameDictionary::GetProbeOffset(i) << Name::kHashShift)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3500 | } else { |
| 3501 | __ mov(index, hash); |
| 3502 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3503 | __ srl(index, index, Name::kHashShift); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3504 | __ And(index, mask, index); |
| 3505 | |
| 3506 | // Scale the index by multiplying by the entry size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3507 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3508 | // index *= 3. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3509 | __ Lsa(index, index, index, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3510 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3511 | STATIC_ASSERT(kSmiTagSize == 1); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3512 | __ Lsa(index, dictionary, index, 2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3513 | __ lw(entry_key, FieldMemOperand(index, kElementsStartOffset)); |
| 3514 | |
| 3515 | // Having undefined at this place means the name is not contained. |
| 3516 | __ Branch(¬_in_dictionary, eq, entry_key, Operand(undefined)); |
| 3517 | |
| 3518 | // Stop if found the property. |
| 3519 | __ Branch(&in_dictionary, eq, entry_key, Operand(key)); |
| 3520 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3521 | if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) { |
| 3522 | // Check if the entry name is not a unique name. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3523 | __ lw(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset)); |
| 3524 | __ lbu(entry_key, |
| 3525 | FieldMemOperand(entry_key, Map::kInstanceTypeOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3526 | __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3527 | } |
| 3528 | } |
| 3529 | |
| 3530 | __ bind(&maybe_in_dictionary); |
| 3531 | // If we are doing negative lookup then probing failure should be |
| 3532 | // treated as a lookup success. For positive lookup probing failure |
| 3533 | // should be treated as lookup failure. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3534 | if (mode() == POSITIVE_LOOKUP) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3535 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3536 | __ mov(result, zero_reg); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3537 | } |
| 3538 | |
| 3539 | __ bind(&in_dictionary); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3540 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3541 | __ li(result, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3542 | |
| 3543 | __ bind(¬_in_dictionary); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3544 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3545 | __ mov(result, zero_reg); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3546 | } |
| 3547 | |
| 3548 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3549 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 3550 | Isolate* isolate) { |
| 3551 | StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs); |
| 3552 | stub1.GetCode(); |
| 3553 | // Hydrogen code stubs need stub2 at snapshot time. |
| 3554 | StoreBufferOverflowStub stub2(isolate, kSaveFPRegs); |
| 3555 | stub2.GetCode(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3556 | } |
| 3557 | |
| 3558 | |
| 3559 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 3560 | // the value has just been written into the object, now this stub makes sure |
| 3561 | // we keep the GC informed. The word in the object where the value has been |
| 3562 | // written is in the address register. |
| 3563 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 3564 | Label skip_to_incremental_noncompacting; |
| 3565 | Label skip_to_incremental_compacting; |
| 3566 | |
| 3567 | // The first two branch+nop instructions are generated with labels so as to |
| 3568 | // get the offset fixed up correctly by the bind(Label*) call. We patch it |
| 3569 | // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this |
| 3570 | // position) and the "beq zero_reg, zero_reg, ..." when we start and stop |
| 3571 | // incremental heap marking. |
| 3572 | // See RecordWriteStub::Patch for details. |
| 3573 | __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting); |
| 3574 | __ nop(); |
| 3575 | __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting); |
| 3576 | __ nop(); |
| 3577 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3578 | if (remembered_set_action() == EMIT_REMEMBERED_SET) { |
| 3579 | __ RememberedSetHelper(object(), |
| 3580 | address(), |
| 3581 | value(), |
| 3582 | save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3583 | MacroAssembler::kReturnAtEnd); |
| 3584 | } |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3585 | __ Ret(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3586 | |
| 3587 | __ bind(&skip_to_incremental_noncompacting); |
| 3588 | GenerateIncremental(masm, INCREMENTAL); |
| 3589 | |
| 3590 | __ bind(&skip_to_incremental_compacting); |
| 3591 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 3592 | |
| 3593 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 3594 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 3595 | |
| 3596 | PatchBranchIntoNop(masm, 0); |
| 3597 | PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize); |
| 3598 | } |
| 3599 | |
| 3600 | |
| 3601 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 3602 | regs_.Save(masm); |
| 3603 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3604 | if (remembered_set_action() == EMIT_REMEMBERED_SET) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3605 | Label dont_need_remembered_set; |
| 3606 | |
| 3607 | __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0)); |
| 3608 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 3609 | regs_.scratch0(), |
| 3610 | &dont_need_remembered_set); |
| 3611 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3612 | __ JumpIfInNewSpace(regs_.object(), regs_.scratch0(), |
| 3613 | &dont_need_remembered_set); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3614 | |
| 3615 | // First notify the incremental marker if necessary, then update the |
| 3616 | // remembered set. |
| 3617 | CheckNeedsToInformIncrementalMarker( |
| 3618 | masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3619 | InformIncrementalMarker(masm); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3620 | regs_.Restore(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3621 | __ RememberedSetHelper(object(), |
| 3622 | address(), |
| 3623 | value(), |
| 3624 | save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3625 | MacroAssembler::kReturnAtEnd); |
| 3626 | |
| 3627 | __ bind(&dont_need_remembered_set); |
| 3628 | } |
| 3629 | |
| 3630 | CheckNeedsToInformIncrementalMarker( |
| 3631 | masm, kReturnOnNoNeedToInformIncrementalMarker, mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3632 | InformIncrementalMarker(masm); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3633 | regs_.Restore(masm); |
| 3634 | __ Ret(); |
| 3635 | } |
| 3636 | |
| 3637 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3638 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) { |
| 3639 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3640 | int argument_count = 3; |
| 3641 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 3642 | Register address = |
| 3643 | a0.is(regs_.address()) ? regs_.scratch0() : regs_.address(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3644 | DCHECK(!address.is(regs_.object())); |
| 3645 | DCHECK(!address.is(a0)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3646 | __ Move(address, regs_.address()); |
| 3647 | __ Move(a0, regs_.object()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3648 | __ Move(a1, address); |
| 3649 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3650 | |
| 3651 | AllowExternalCallThatCantCauseGC scope(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3652 | __ CallCFunction( |
| 3653 | ExternalReference::incremental_marking_record_write_function(isolate()), |
| 3654 | argument_count); |
| 3655 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3656 | } |
| 3657 | |
| 3658 | |
| 3659 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 3660 | MacroAssembler* masm, |
| 3661 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 3662 | Mode mode) { |
| 3663 | Label on_black; |
| 3664 | Label need_incremental; |
| 3665 | Label need_incremental_pop_scratch; |
| 3666 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3667 | __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask)); |
| 3668 | __ lw(regs_.scratch1(), |
| 3669 | MemOperand(regs_.scratch0(), |
| 3670 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 3671 | __ Subu(regs_.scratch1(), regs_.scratch1(), Operand(1)); |
| 3672 | __ sw(regs_.scratch1(), |
| 3673 | MemOperand(regs_.scratch0(), |
| 3674 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 3675 | __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg)); |
| 3676 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3677 | // Let's look at the color of the object: If it is not black we don't have |
| 3678 | // to inform the incremental marker. |
| 3679 | __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black); |
| 3680 | |
| 3681 | regs_.Restore(masm); |
| 3682 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3683 | __ RememberedSetHelper(object(), |
| 3684 | address(), |
| 3685 | value(), |
| 3686 | save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3687 | MacroAssembler::kReturnAtEnd); |
| 3688 | } else { |
| 3689 | __ Ret(); |
| 3690 | } |
| 3691 | |
| 3692 | __ bind(&on_black); |
| 3693 | |
| 3694 | // Get the value from the slot. |
| 3695 | __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0)); |
| 3696 | |
| 3697 | if (mode == INCREMENTAL_COMPACTION) { |
| 3698 | Label ensure_not_white; |
| 3699 | |
| 3700 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 3701 | regs_.scratch1(), // Scratch. |
| 3702 | MemoryChunk::kEvacuationCandidateMask, |
| 3703 | eq, |
| 3704 | &ensure_not_white); |
| 3705 | |
| 3706 | __ CheckPageFlag(regs_.object(), |
| 3707 | regs_.scratch1(), // Scratch. |
| 3708 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 3709 | eq, |
| 3710 | &need_incremental); |
| 3711 | |
| 3712 | __ bind(&ensure_not_white); |
| 3713 | } |
| 3714 | |
| 3715 | // We need extra registers for this, so we push the object and the address |
| 3716 | // register temporarily. |
| 3717 | __ Push(regs_.object(), regs_.address()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3718 | __ JumpIfWhite(regs_.scratch0(), // The value. |
| 3719 | regs_.scratch1(), // Scratch. |
| 3720 | regs_.object(), // Scratch. |
| 3721 | regs_.address(), // Scratch. |
| 3722 | &need_incremental_pop_scratch); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3723 | __ Pop(regs_.object(), regs_.address()); |
| 3724 | |
| 3725 | regs_.Restore(masm); |
| 3726 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3727 | __ RememberedSetHelper(object(), |
| 3728 | address(), |
| 3729 | value(), |
| 3730 | save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3731 | MacroAssembler::kReturnAtEnd); |
| 3732 | } else { |
| 3733 | __ Ret(); |
| 3734 | } |
| 3735 | |
| 3736 | __ bind(&need_incremental_pop_scratch); |
| 3737 | __ Pop(regs_.object(), regs_.address()); |
| 3738 | |
| 3739 | __ bind(&need_incremental); |
| 3740 | |
| 3741 | // Fall through when we need to inform the incremental marker. |
| 3742 | } |
| 3743 | |
| 3744 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3745 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
| 3746 | CEntryStub ces(isolate(), 1, kSaveFPRegs); |
| 3747 | __ Call(ces.GetCode(), RelocInfo::CODE_TARGET); |
| 3748 | int parameter_count_offset = |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 3749 | StubFailureTrampolineFrameConstants::kArgumentsLengthOffset; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3750 | __ lw(a1, MemOperand(fp, parameter_count_offset)); |
| 3751 | if (function_mode() == JS_FUNCTION_STUB_MODE) { |
| 3752 | __ Addu(a1, a1, Operand(1)); |
| 3753 | } |
| 3754 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 3755 | __ sll(a1, a1, kPointerSizeLog2); |
| 3756 | __ Ret(USE_DELAY_SLOT); |
| 3757 | __ Addu(sp, sp, a1); |
| 3758 | } |
| 3759 | |
| 3760 | |
| 3761 | void LoadICTrampolineStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3762 | __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister()); |
| 3763 | LoadICStub stub(isolate(), state()); |
| 3764 | stub.GenerateForTrampoline(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3765 | } |
| 3766 | |
| 3767 | |
| 3768 | void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3769 | __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister()); |
| 3770 | KeyedLoadICStub stub(isolate(), state()); |
| 3771 | stub.GenerateForTrampoline(masm); |
| 3772 | } |
| 3773 | |
| 3774 | |
| 3775 | void CallICTrampolineStub::Generate(MacroAssembler* masm) { |
| 3776 | __ EmitLoadTypeFeedbackVector(a2); |
| 3777 | CallICStub stub(isolate(), state()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3778 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 3779 | } |
| 3780 | |
| 3781 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3782 | void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); } |
| 3783 | |
| 3784 | |
| 3785 | void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 3786 | GenerateImpl(masm, true); |
| 3787 | } |
| 3788 | |
| 3789 | |
| 3790 | static void HandleArrayCases(MacroAssembler* masm, Register feedback, |
| 3791 | Register receiver_map, Register scratch1, |
| 3792 | Register scratch2, bool is_polymorphic, |
| 3793 | Label* miss) { |
| 3794 | // feedback initially contains the feedback array |
| 3795 | Label next_loop, prepare_next; |
| 3796 | Label start_polymorphic; |
| 3797 | |
| 3798 | Register cached_map = scratch1; |
| 3799 | |
| 3800 | __ lw(cached_map, |
| 3801 | FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0))); |
| 3802 | __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset)); |
| 3803 | __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map)); |
| 3804 | // found, now call handler. |
| 3805 | Register handler = feedback; |
| 3806 | __ lw(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1))); |
| 3807 | __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3808 | __ Jump(t9); |
| 3809 | |
| 3810 | |
| 3811 | Register length = scratch2; |
| 3812 | __ bind(&start_polymorphic); |
| 3813 | __ lw(length, FieldMemOperand(feedback, FixedArray::kLengthOffset)); |
| 3814 | if (!is_polymorphic) { |
| 3815 | // If the IC could be monomorphic we have to make sure we don't go past the |
| 3816 | // end of the feedback array. |
| 3817 | __ Branch(miss, eq, length, Operand(Smi::FromInt(2))); |
| 3818 | } |
| 3819 | |
| 3820 | Register too_far = length; |
| 3821 | Register pointer_reg = feedback; |
| 3822 | |
| 3823 | // +-----+------+------+-----+-----+ ... ----+ |
| 3824 | // | map | len | wm0 | h0 | wm1 | hN | |
| 3825 | // +-----+------+------+-----+-----+ ... ----+ |
| 3826 | // 0 1 2 len-1 |
| 3827 | // ^ ^ |
| 3828 | // | | |
| 3829 | // pointer_reg too_far |
| 3830 | // aka feedback scratch2 |
| 3831 | // also need receiver_map |
| 3832 | // use cached_map (scratch1) to look in the weak map values. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3833 | __ Lsa(too_far, feedback, length, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3834 | __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 3835 | __ Addu(pointer_reg, feedback, |
| 3836 | Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag)); |
| 3837 | |
| 3838 | __ bind(&next_loop); |
| 3839 | __ lw(cached_map, MemOperand(pointer_reg)); |
| 3840 | __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset)); |
| 3841 | __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map)); |
| 3842 | __ lw(handler, MemOperand(pointer_reg, kPointerSize)); |
| 3843 | __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3844 | __ Jump(t9); |
| 3845 | |
| 3846 | __ bind(&prepare_next); |
| 3847 | __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 2)); |
| 3848 | __ Branch(&next_loop, lt, pointer_reg, Operand(too_far)); |
| 3849 | |
| 3850 | // We exhausted our array of map handler pairs. |
| 3851 | __ jmp(miss); |
| 3852 | } |
| 3853 | |
| 3854 | |
| 3855 | static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver, |
| 3856 | Register receiver_map, Register feedback, |
| 3857 | Register vector, Register slot, |
| 3858 | Register scratch, Label* compare_map, |
| 3859 | Label* load_smi_map, Label* try_array) { |
| 3860 | __ JumpIfSmi(receiver, load_smi_map); |
| 3861 | __ lw(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 3862 | __ bind(compare_map); |
| 3863 | Register cached_map = scratch; |
| 3864 | // Move the weak map into the weak_cell register. |
| 3865 | __ lw(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset)); |
| 3866 | __ Branch(try_array, ne, cached_map, Operand(receiver_map)); |
| 3867 | Register handler = feedback; |
| 3868 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3869 | __ Lsa(handler, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3870 | __ lw(handler, |
| 3871 | FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize)); |
| 3872 | __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3873 | __ Jump(t9); |
| 3874 | } |
| 3875 | |
| 3876 | |
| 3877 | void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 3878 | Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1 |
| 3879 | Register name = LoadWithVectorDescriptor::NameRegister(); // a2 |
| 3880 | Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3 |
| 3881 | Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0 |
| 3882 | Register feedback = t0; |
| 3883 | Register receiver_map = t1; |
| 3884 | Register scratch1 = t4; |
| 3885 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3886 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3887 | __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 3888 | |
| 3889 | // Try to quickly handle the monomorphic case without knowing for sure |
| 3890 | // if we have a weak cell in feedback. We do know it's safe to look |
| 3891 | // at WeakCell::kValueOffset. |
| 3892 | Label try_array, load_smi_map, compare_map; |
| 3893 | Label not_array, miss; |
| 3894 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 3895 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 3896 | |
| 3897 | // Is it a fixed array? |
| 3898 | __ bind(&try_array); |
| 3899 | __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 3900 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 3901 | __ Branch(¬_array, ne, at, Operand(scratch1)); |
| 3902 | HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, true, &miss); |
| 3903 | |
| 3904 | __ bind(¬_array); |
| 3905 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 3906 | __ Branch(&miss, ne, at, Operand(feedback)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 3907 | Code::Flags code_flags = |
| 3908 | Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(Code::LOAD_IC)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3909 | masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags, |
| 3910 | receiver, name, feedback, |
| 3911 | receiver_map, scratch1, t5); |
| 3912 | |
| 3913 | __ bind(&miss); |
| 3914 | LoadIC::GenerateMiss(masm); |
| 3915 | |
| 3916 | __ bind(&load_smi_map); |
| 3917 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 3918 | __ jmp(&compare_map); |
| 3919 | } |
| 3920 | |
| 3921 | |
| 3922 | void KeyedLoadICStub::Generate(MacroAssembler* masm) { |
| 3923 | GenerateImpl(masm, false); |
| 3924 | } |
| 3925 | |
| 3926 | |
| 3927 | void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 3928 | GenerateImpl(masm, true); |
| 3929 | } |
| 3930 | |
| 3931 | |
| 3932 | void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 3933 | Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1 |
| 3934 | Register key = LoadWithVectorDescriptor::NameRegister(); // a2 |
| 3935 | Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3 |
| 3936 | Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0 |
| 3937 | Register feedback = t0; |
| 3938 | Register receiver_map = t1; |
| 3939 | Register scratch1 = t4; |
| 3940 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3941 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3942 | __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 3943 | |
| 3944 | // Try to quickly handle the monomorphic case without knowing for sure |
| 3945 | // if we have a weak cell in feedback. We do know it's safe to look |
| 3946 | // at WeakCell::kValueOffset. |
| 3947 | Label try_array, load_smi_map, compare_map; |
| 3948 | Label not_array, miss; |
| 3949 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 3950 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 3951 | |
| 3952 | __ bind(&try_array); |
| 3953 | // Is it a fixed array? |
| 3954 | __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 3955 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 3956 | __ Branch(¬_array, ne, at, Operand(scratch1)); |
| 3957 | // We have a polymorphic element handler. |
| 3958 | __ JumpIfNotSmi(key, &miss); |
| 3959 | |
| 3960 | Label polymorphic, try_poly_name; |
| 3961 | __ bind(&polymorphic); |
| 3962 | HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, true, &miss); |
| 3963 | |
| 3964 | __ bind(¬_array); |
| 3965 | // Is it generic? |
| 3966 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 3967 | __ Branch(&try_poly_name, ne, at, Operand(feedback)); |
| 3968 | Handle<Code> megamorphic_stub = |
| 3969 | KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState()); |
| 3970 | __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET); |
| 3971 | |
| 3972 | __ bind(&try_poly_name); |
| 3973 | // We might have a name in feedback, and a fixed array in the next slot. |
| 3974 | __ Branch(&miss, ne, key, Operand(feedback)); |
| 3975 | // If the name comparison succeeded, we know we have a fixed array with |
| 3976 | // at least one map/handler pair. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3977 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3978 | __ lw(feedback, |
| 3979 | FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize)); |
| 3980 | HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, false, &miss); |
| 3981 | |
| 3982 | __ bind(&miss); |
| 3983 | KeyedLoadIC::GenerateMiss(masm); |
| 3984 | |
| 3985 | __ bind(&load_smi_map); |
| 3986 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 3987 | __ jmp(&compare_map); |
| 3988 | } |
| 3989 | |
| 3990 | |
| 3991 | void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) { |
| 3992 | __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister()); |
| 3993 | VectorStoreICStub stub(isolate(), state()); |
| 3994 | stub.GenerateForTrampoline(masm); |
| 3995 | } |
| 3996 | |
| 3997 | |
| 3998 | void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) { |
| 3999 | __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister()); |
| 4000 | VectorKeyedStoreICStub stub(isolate(), state()); |
| 4001 | stub.GenerateForTrampoline(masm); |
| 4002 | } |
| 4003 | |
| 4004 | |
| 4005 | void VectorStoreICStub::Generate(MacroAssembler* masm) { |
| 4006 | GenerateImpl(masm, false); |
| 4007 | } |
| 4008 | |
| 4009 | |
| 4010 | void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 4011 | GenerateImpl(masm, true); |
| 4012 | } |
| 4013 | |
| 4014 | |
| 4015 | void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4016 | Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1 |
| 4017 | Register key = VectorStoreICDescriptor::NameRegister(); // a2 |
| 4018 | Register vector = VectorStoreICDescriptor::VectorRegister(); // a3 |
| 4019 | Register slot = VectorStoreICDescriptor::SlotRegister(); // t0 |
| 4020 | DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0 |
| 4021 | Register feedback = t1; |
| 4022 | Register receiver_map = t2; |
| 4023 | Register scratch1 = t5; |
| 4024 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4025 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4026 | __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 4027 | |
| 4028 | // Try to quickly handle the monomorphic case without knowing for sure |
| 4029 | // if we have a weak cell in feedback. We do know it's safe to look |
| 4030 | // at WeakCell::kValueOffset. |
| 4031 | Label try_array, load_smi_map, compare_map; |
| 4032 | Label not_array, miss; |
| 4033 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 4034 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 4035 | |
| 4036 | // Is it a fixed array? |
| 4037 | __ bind(&try_array); |
| 4038 | __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 4039 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 4040 | __ Branch(¬_array, ne, scratch1, Operand(at)); |
| 4041 | |
| 4042 | Register scratch2 = t4; |
| 4043 | HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true, |
| 4044 | &miss); |
| 4045 | |
| 4046 | __ bind(¬_array); |
| 4047 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 4048 | __ Branch(&miss, ne, feedback, Operand(at)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4049 | Code::Flags code_flags = |
| 4050 | Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(Code::STORE_IC)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4051 | masm->isolate()->stub_cache()->GenerateProbe( |
| 4052 | masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map, |
| 4053 | scratch1, scratch2); |
| 4054 | |
| 4055 | __ bind(&miss); |
| 4056 | StoreIC::GenerateMiss(masm); |
| 4057 | |
| 4058 | __ bind(&load_smi_map); |
| 4059 | __ Branch(USE_DELAY_SLOT, &compare_map); |
| 4060 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot. |
| 4061 | } |
| 4062 | |
| 4063 | |
| 4064 | void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) { |
| 4065 | GenerateImpl(masm, false); |
| 4066 | } |
| 4067 | |
| 4068 | |
| 4069 | void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 4070 | GenerateImpl(masm, true); |
| 4071 | } |
| 4072 | |
| 4073 | |
| 4074 | static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback, |
| 4075 | Register receiver_map, Register scratch1, |
| 4076 | Register scratch2, Label* miss) { |
| 4077 | // feedback initially contains the feedback array |
| 4078 | Label next_loop, prepare_next; |
| 4079 | Label start_polymorphic; |
| 4080 | Label transition_call; |
| 4081 | |
| 4082 | Register cached_map = scratch1; |
| 4083 | Register too_far = scratch2; |
| 4084 | Register pointer_reg = feedback; |
| 4085 | __ lw(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset)); |
| 4086 | |
| 4087 | // +-----+------+------+-----+-----+-----+ ... ----+ |
| 4088 | // | map | len | wm0 | wt0 | h0 | wm1 | hN | |
| 4089 | // +-----+------+------+-----+-----+ ----+ ... ----+ |
| 4090 | // 0 1 2 len-1 |
| 4091 | // ^ ^ |
| 4092 | // | | |
| 4093 | // pointer_reg too_far |
| 4094 | // aka feedback scratch2 |
| 4095 | // also need receiver_map |
| 4096 | // use cached_map (scratch1) to look in the weak map values. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4097 | __ Lsa(too_far, feedback, too_far, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4098 | __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 4099 | __ Addu(pointer_reg, feedback, |
| 4100 | Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag)); |
| 4101 | |
| 4102 | __ bind(&next_loop); |
| 4103 | __ lw(cached_map, MemOperand(pointer_reg)); |
| 4104 | __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset)); |
| 4105 | __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map)); |
| 4106 | // Is it a transitioning store? |
| 4107 | __ lw(too_far, MemOperand(pointer_reg, kPointerSize)); |
| 4108 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 4109 | __ Branch(&transition_call, ne, too_far, Operand(at)); |
| 4110 | __ lw(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2)); |
| 4111 | __ Addu(t9, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4112 | __ Jump(t9); |
| 4113 | |
| 4114 | __ bind(&transition_call); |
| 4115 | __ lw(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset)); |
| 4116 | __ JumpIfSmi(too_far, miss); |
| 4117 | |
| 4118 | __ lw(receiver_map, MemOperand(pointer_reg, kPointerSize * 2)); |
| 4119 | |
| 4120 | // Load the map into the correct register. |
| 4121 | DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister())); |
| 4122 | __ mov(feedback, too_far); |
| 4123 | |
| 4124 | __ Addu(t9, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4125 | __ Jump(t9); |
| 4126 | |
| 4127 | __ bind(&prepare_next); |
| 4128 | __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 3)); |
| 4129 | __ Branch(&next_loop, lt, pointer_reg, Operand(too_far)); |
| 4130 | |
| 4131 | // We exhausted our array of map handler pairs. |
| 4132 | __ jmp(miss); |
| 4133 | } |
| 4134 | |
| 4135 | |
| 4136 | void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4137 | Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1 |
| 4138 | Register key = VectorStoreICDescriptor::NameRegister(); // a2 |
| 4139 | Register vector = VectorStoreICDescriptor::VectorRegister(); // a3 |
| 4140 | Register slot = VectorStoreICDescriptor::SlotRegister(); // t0 |
| 4141 | DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0 |
| 4142 | Register feedback = t1; |
| 4143 | Register receiver_map = t2; |
| 4144 | Register scratch1 = t5; |
| 4145 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4146 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4147 | __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 4148 | |
| 4149 | // Try to quickly handle the monomorphic case without knowing for sure |
| 4150 | // if we have a weak cell in feedback. We do know it's safe to look |
| 4151 | // at WeakCell::kValueOffset. |
| 4152 | Label try_array, load_smi_map, compare_map; |
| 4153 | Label not_array, miss; |
| 4154 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 4155 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 4156 | |
| 4157 | __ bind(&try_array); |
| 4158 | // Is it a fixed array? |
| 4159 | __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 4160 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 4161 | __ Branch(¬_array, ne, scratch1, Operand(at)); |
| 4162 | |
| 4163 | // We have a polymorphic element handler. |
| 4164 | Label polymorphic, try_poly_name; |
| 4165 | __ bind(&polymorphic); |
| 4166 | |
| 4167 | Register scratch2 = t4; |
| 4168 | |
| 4169 | HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2, |
| 4170 | &miss); |
| 4171 | |
| 4172 | __ bind(¬_array); |
| 4173 | // Is it generic? |
| 4174 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 4175 | __ Branch(&try_poly_name, ne, feedback, Operand(at)); |
| 4176 | Handle<Code> megamorphic_stub = |
| 4177 | KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState()); |
| 4178 | __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET); |
| 4179 | |
| 4180 | __ bind(&try_poly_name); |
| 4181 | // We might have a name in feedback, and a fixed array in the next slot. |
| 4182 | __ Branch(&miss, ne, key, Operand(feedback)); |
| 4183 | // If the name comparison succeeded, we know we have a fixed array with |
| 4184 | // at least one map/handler pair. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4185 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4186 | __ lw(feedback, |
| 4187 | FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize)); |
| 4188 | HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false, |
| 4189 | &miss); |
| 4190 | |
| 4191 | __ bind(&miss); |
| 4192 | KeyedStoreIC::GenerateMiss(masm); |
| 4193 | |
| 4194 | __ bind(&load_smi_map); |
| 4195 | __ Branch(USE_DELAY_SLOT, &compare_map); |
| 4196 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot. |
| 4197 | } |
| 4198 | |
| 4199 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4200 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 4201 | if (masm->isolate()->function_entry_hook() != NULL) { |
| 4202 | ProfileEntryHookStub stub(masm->isolate()); |
| 4203 | __ push(ra); |
| 4204 | __ CallStub(&stub); |
| 4205 | __ pop(ra); |
| 4206 | } |
| 4207 | } |
| 4208 | |
| 4209 | |
| 4210 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 4211 | // The entry hook is a "push ra" instruction, followed by a call. |
| 4212 | // Note: on MIPS "push" is 2 instruction |
| 4213 | const int32_t kReturnAddressDistanceFromFunctionStart = |
| 4214 | Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize); |
| 4215 | |
| 4216 | // This should contain all kJSCallerSaved registers. |
| 4217 | const RegList kSavedRegs = |
| 4218 | kJSCallerSaved | // Caller saved registers. |
| 4219 | s5.bit(); // Saved stack pointer. |
| 4220 | |
| 4221 | // We also save ra, so the count here is one higher than the mask indicates. |
| 4222 | const int32_t kNumSavedRegs = kNumJSCallerSaved + 2; |
| 4223 | |
| 4224 | // Save all caller-save registers as this may be called from anywhere. |
| 4225 | __ MultiPush(kSavedRegs | ra.bit()); |
| 4226 | |
| 4227 | // Compute the function's address for the first argument. |
| 4228 | __ Subu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart)); |
| 4229 | |
| 4230 | // The caller's return address is above the saved temporaries. |
| 4231 | // Grab that for the second argument to the hook. |
| 4232 | __ Addu(a1, sp, Operand(kNumSavedRegs * kPointerSize)); |
| 4233 | |
| 4234 | // Align the stack if necessary. |
| 4235 | int frame_alignment = masm->ActivationFrameAlignment(); |
| 4236 | if (frame_alignment > kPointerSize) { |
| 4237 | __ mov(s5, sp); |
| 4238 | DCHECK(base::bits::IsPowerOfTwo32(frame_alignment)); |
| 4239 | __ And(sp, sp, Operand(-frame_alignment)); |
| 4240 | } |
| 4241 | __ Subu(sp, sp, kCArgsSlotsSize); |
| 4242 | #if defined(V8_HOST_ARCH_MIPS) |
| 4243 | int32_t entry_hook = |
| 4244 | reinterpret_cast<int32_t>(isolate()->function_entry_hook()); |
| 4245 | __ li(t9, Operand(entry_hook)); |
| 4246 | #else |
| 4247 | // Under the simulator we need to indirect the entry hook through a |
| 4248 | // trampoline function at a known address. |
| 4249 | // It additionally takes an isolate as a third parameter. |
| 4250 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
| 4251 | |
| 4252 | ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline)); |
| 4253 | __ li(t9, Operand(ExternalReference(&dispatcher, |
| 4254 | ExternalReference::BUILTIN_CALL, |
| 4255 | isolate()))); |
| 4256 | #endif |
| 4257 | // Call C function through t9 to conform ABI for PIC. |
| 4258 | __ Call(t9); |
| 4259 | |
| 4260 | // Restore the stack pointer if needed. |
| 4261 | if (frame_alignment > kPointerSize) { |
| 4262 | __ mov(sp, s5); |
| 4263 | } else { |
| 4264 | __ Addu(sp, sp, kCArgsSlotsSize); |
| 4265 | } |
| 4266 | |
| 4267 | // Also pop ra to get Ret(0). |
| 4268 | __ MultiPop(kSavedRegs | ra.bit()); |
| 4269 | __ Ret(); |
| 4270 | } |
| 4271 | |
| 4272 | |
| 4273 | template<class T> |
| 4274 | static void CreateArrayDispatch(MacroAssembler* masm, |
| 4275 | AllocationSiteOverrideMode mode) { |
| 4276 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 4277 | T stub(masm->isolate(), GetInitialFastElementsKind(), mode); |
| 4278 | __ TailCallStub(&stub); |
| 4279 | } else if (mode == DONT_OVERRIDE) { |
| 4280 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 4281 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4282 | for (int i = 0; i <= last_index; ++i) { |
| 4283 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4284 | T stub(masm->isolate(), kind); |
| 4285 | __ TailCallStub(&stub, eq, a3, Operand(kind)); |
| 4286 | } |
| 4287 | |
| 4288 | // If we reached this point there is a problem. |
| 4289 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 4290 | } else { |
| 4291 | UNREACHABLE(); |
| 4292 | } |
| 4293 | } |
| 4294 | |
| 4295 | |
| 4296 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm, |
| 4297 | AllocationSiteOverrideMode mode) { |
| 4298 | // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES) |
| 4299 | // a3 - kind (if mode != DISABLE_ALLOCATION_SITES) |
| 4300 | // a0 - number of arguments |
| 4301 | // a1 - constructor? |
| 4302 | // sp[0] - last argument |
| 4303 | Label normal_sequence; |
| 4304 | if (mode == DONT_OVERRIDE) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4305 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 4306 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 4307 | STATIC_ASSERT(FAST_ELEMENTS == 2); |
| 4308 | STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 4309 | STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 4310 | STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4311 | |
| 4312 | // is the low bit set? If so, we are holey and that is good. |
| 4313 | __ And(at, a3, Operand(1)); |
| 4314 | __ Branch(&normal_sequence, ne, at, Operand(zero_reg)); |
| 4315 | } |
| 4316 | |
| 4317 | // look at the first argument |
| 4318 | __ lw(t1, MemOperand(sp, 0)); |
| 4319 | __ Branch(&normal_sequence, eq, t1, Operand(zero_reg)); |
| 4320 | |
| 4321 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 4322 | ElementsKind initial = GetInitialFastElementsKind(); |
| 4323 | ElementsKind holey_initial = GetHoleyElementsKind(initial); |
| 4324 | |
| 4325 | ArraySingleArgumentConstructorStub stub_holey(masm->isolate(), |
| 4326 | holey_initial, |
| 4327 | DISABLE_ALLOCATION_SITES); |
| 4328 | __ TailCallStub(&stub_holey); |
| 4329 | |
| 4330 | __ bind(&normal_sequence); |
| 4331 | ArraySingleArgumentConstructorStub stub(masm->isolate(), |
| 4332 | initial, |
| 4333 | DISABLE_ALLOCATION_SITES); |
| 4334 | __ TailCallStub(&stub); |
| 4335 | } else if (mode == DONT_OVERRIDE) { |
| 4336 | // We are going to create a holey array, but our kind is non-holey. |
| 4337 | // Fix kind and retry (only if we have an allocation site in the slot). |
| 4338 | __ Addu(a3, a3, Operand(1)); |
| 4339 | |
| 4340 | if (FLAG_debug_code) { |
| 4341 | __ lw(t1, FieldMemOperand(a2, 0)); |
| 4342 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 4343 | __ Assert(eq, kExpectedAllocationSite, t1, Operand(at)); |
| 4344 | } |
| 4345 | |
| 4346 | // Save the resulting elements kind in type info. We can't just store a3 |
| 4347 | // in the AllocationSite::transition_info field because elements kind is |
| 4348 | // restricted to a portion of the field...upper bits need to be left alone. |
| 4349 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 4350 | __ lw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset)); |
| 4351 | __ Addu(t0, t0, Operand(Smi::FromInt(kFastElementsKindPackedToHoley))); |
| 4352 | __ sw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset)); |
| 4353 | |
| 4354 | |
| 4355 | __ bind(&normal_sequence); |
| 4356 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 4357 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4358 | for (int i = 0; i <= last_index; ++i) { |
| 4359 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4360 | ArraySingleArgumentConstructorStub stub(masm->isolate(), kind); |
| 4361 | __ TailCallStub(&stub, eq, a3, Operand(kind)); |
| 4362 | } |
| 4363 | |
| 4364 | // If we reached this point there is a problem. |
| 4365 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 4366 | } else { |
| 4367 | UNREACHABLE(); |
| 4368 | } |
| 4369 | } |
| 4370 | |
| 4371 | |
| 4372 | template<class T> |
| 4373 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 4374 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 4375 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4376 | for (int i = 0; i <= to_index; ++i) { |
| 4377 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4378 | T stub(isolate, kind); |
| 4379 | stub.GetCode(); |
| 4380 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
| 4381 | T stub1(isolate, kind, DISABLE_ALLOCATION_SITES); |
| 4382 | stub1.GetCode(); |
| 4383 | } |
| 4384 | } |
| 4385 | } |
| 4386 | |
| 4387 | |
| 4388 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 4389 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 4390 | isolate); |
| 4391 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 4392 | isolate); |
| 4393 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 4394 | isolate); |
| 4395 | } |
| 4396 | |
| 4397 | |
| 4398 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 4399 | Isolate* isolate) { |
| 4400 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 4401 | for (int i = 0; i < 2; i++) { |
| 4402 | // For internal arrays we only need a few things. |
| 4403 | InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]); |
| 4404 | stubh1.GetCode(); |
| 4405 | InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]); |
| 4406 | stubh2.GetCode(); |
| 4407 | InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]); |
| 4408 | stubh3.GetCode(); |
| 4409 | } |
| 4410 | } |
| 4411 | |
| 4412 | |
| 4413 | void ArrayConstructorStub::GenerateDispatchToArrayStub( |
| 4414 | MacroAssembler* masm, |
| 4415 | AllocationSiteOverrideMode mode) { |
| 4416 | if (argument_count() == ANY) { |
| 4417 | Label not_zero_case, not_one_case; |
| 4418 | __ And(at, a0, a0); |
| 4419 | __ Branch(¬_zero_case, ne, at, Operand(zero_reg)); |
| 4420 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 4421 | |
| 4422 | __ bind(¬_zero_case); |
| 4423 | __ Branch(¬_one_case, gt, a0, Operand(1)); |
| 4424 | CreateArrayDispatchOneArgument(masm, mode); |
| 4425 | |
| 4426 | __ bind(¬_one_case); |
| 4427 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 4428 | } else if (argument_count() == NONE) { |
| 4429 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 4430 | } else if (argument_count() == ONE) { |
| 4431 | CreateArrayDispatchOneArgument(masm, mode); |
| 4432 | } else if (argument_count() == MORE_THAN_ONE) { |
| 4433 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 4434 | } else { |
| 4435 | UNREACHABLE(); |
| 4436 | } |
| 4437 | } |
| 4438 | |
| 4439 | |
| 4440 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 4441 | // ----------- S t a t e ------------- |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4442 | // -- a0 : argc (only if argument_count() is ANY or MORE_THAN_ONE) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4443 | // -- a1 : constructor |
| 4444 | // -- a2 : AllocationSite or undefined |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4445 | // -- a3 : Original constructor |
| 4446 | // -- sp[0] : last argument |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4447 | // ----------------------------------- |
| 4448 | |
| 4449 | if (FLAG_debug_code) { |
| 4450 | // The array construct code is only set for the global and natives |
| 4451 | // builtin Array functions which always have maps. |
| 4452 | |
| 4453 | // Initial map for the builtin Array function should be a map. |
| 4454 | __ lw(t0, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4455 | // Will both indicate a NULL and a Smi. |
| 4456 | __ SmiTst(t0, at); |
| 4457 | __ Assert(ne, kUnexpectedInitialMapForArrayFunction, |
| 4458 | at, Operand(zero_reg)); |
| 4459 | __ GetObjectType(t0, t0, t1); |
| 4460 | __ Assert(eq, kUnexpectedInitialMapForArrayFunction, |
| 4461 | t1, Operand(MAP_TYPE)); |
| 4462 | |
| 4463 | // We should either have undefined in a2 or a valid AllocationSite |
| 4464 | __ AssertUndefinedOrAllocationSite(a2, t0); |
| 4465 | } |
| 4466 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4467 | // Enter the context of the Array function. |
| 4468 | __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 4469 | |
| 4470 | Label subclassing; |
| 4471 | __ Branch(&subclassing, ne, a1, Operand(a3)); |
| 4472 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4473 | Label no_info; |
| 4474 | // Get the elements kind and case on that. |
| 4475 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 4476 | __ Branch(&no_info, eq, a2, Operand(at)); |
| 4477 | |
| 4478 | __ lw(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset)); |
| 4479 | __ SmiUntag(a3); |
| 4480 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 4481 | __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask)); |
| 4482 | GenerateDispatchToArrayStub(masm, DONT_OVERRIDE); |
| 4483 | |
| 4484 | __ bind(&no_info); |
| 4485 | GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4486 | |
| 4487 | // Subclassing. |
| 4488 | __ bind(&subclassing); |
| 4489 | switch (argument_count()) { |
| 4490 | case ANY: |
| 4491 | case MORE_THAN_ONE: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4492 | __ Lsa(at, sp, a0, kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4493 | __ sw(a1, MemOperand(at)); |
| 4494 | __ li(at, Operand(3)); |
| 4495 | __ addu(a0, a0, at); |
| 4496 | break; |
| 4497 | case NONE: |
| 4498 | __ sw(a1, MemOperand(sp, 0 * kPointerSize)); |
| 4499 | __ li(a0, Operand(3)); |
| 4500 | break; |
| 4501 | case ONE: |
| 4502 | __ sw(a1, MemOperand(sp, 1 * kPointerSize)); |
| 4503 | __ li(a0, Operand(4)); |
| 4504 | break; |
| 4505 | } |
| 4506 | __ Push(a3, a2); |
| 4507 | __ JumpToExternalReference(ExternalReference(Runtime::kNewArray, isolate())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4508 | } |
| 4509 | |
| 4510 | |
| 4511 | void InternalArrayConstructorStub::GenerateCase( |
| 4512 | MacroAssembler* masm, ElementsKind kind) { |
| 4513 | |
| 4514 | InternalArrayNoArgumentConstructorStub stub0(isolate(), kind); |
| 4515 | __ TailCallStub(&stub0, lo, a0, Operand(1)); |
| 4516 | |
| 4517 | InternalArrayNArgumentsConstructorStub stubN(isolate(), kind); |
| 4518 | __ TailCallStub(&stubN, hi, a0, Operand(1)); |
| 4519 | |
| 4520 | if (IsFastPackedElementsKind(kind)) { |
| 4521 | // We might need to create a holey array |
| 4522 | // look at the first argument. |
| 4523 | __ lw(at, MemOperand(sp, 0)); |
| 4524 | |
| 4525 | InternalArraySingleArgumentConstructorStub |
| 4526 | stub1_holey(isolate(), GetHoleyElementsKind(kind)); |
| 4527 | __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg)); |
| 4528 | } |
| 4529 | |
| 4530 | InternalArraySingleArgumentConstructorStub stub1(isolate(), kind); |
| 4531 | __ TailCallStub(&stub1); |
| 4532 | } |
| 4533 | |
| 4534 | |
| 4535 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 4536 | // ----------- S t a t e ------------- |
| 4537 | // -- a0 : argc |
| 4538 | // -- a1 : constructor |
| 4539 | // -- sp[0] : return address |
| 4540 | // -- sp[4] : last argument |
| 4541 | // ----------------------------------- |
| 4542 | |
| 4543 | if (FLAG_debug_code) { |
| 4544 | // The array construct code is only set for the global and natives |
| 4545 | // builtin Array functions which always have maps. |
| 4546 | |
| 4547 | // Initial map for the builtin Array function should be a map. |
| 4548 | __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4549 | // Will both indicate a NULL and a Smi. |
| 4550 | __ SmiTst(a3, at); |
| 4551 | __ Assert(ne, kUnexpectedInitialMapForArrayFunction, |
| 4552 | at, Operand(zero_reg)); |
| 4553 | __ GetObjectType(a3, a3, t0); |
| 4554 | __ Assert(eq, kUnexpectedInitialMapForArrayFunction, |
| 4555 | t0, Operand(MAP_TYPE)); |
| 4556 | } |
| 4557 | |
| 4558 | // Figure out the right elements kind. |
| 4559 | __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4560 | |
| 4561 | // Load the map's "bit field 2" into a3. We only need the first byte, |
| 4562 | // but the following bit field extraction takes care of that anyway. |
| 4563 | __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset)); |
| 4564 | // Retrieve elements_kind from bit field 2. |
| 4565 | __ DecodeField<Map::ElementsKindBits>(a3); |
| 4566 | |
| 4567 | if (FLAG_debug_code) { |
| 4568 | Label done; |
| 4569 | __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS)); |
| 4570 | __ Assert( |
| 4571 | eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray, |
| 4572 | a3, Operand(FAST_HOLEY_ELEMENTS)); |
| 4573 | __ bind(&done); |
| 4574 | } |
| 4575 | |
| 4576 | Label fast_elements_case; |
| 4577 | __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS)); |
| 4578 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 4579 | |
| 4580 | __ bind(&fast_elements_case); |
| 4581 | GenerateCase(masm, FAST_ELEMENTS); |
| 4582 | } |
| 4583 | |
| 4584 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4585 | void FastNewObjectStub::Generate(MacroAssembler* masm) { |
| 4586 | // ----------- S t a t e ------------- |
| 4587 | // -- a1 : target |
| 4588 | // -- a3 : new target |
| 4589 | // -- cp : context |
| 4590 | // -- ra : return address |
| 4591 | // ----------------------------------- |
| 4592 | __ AssertFunction(a1); |
| 4593 | __ AssertReceiver(a3); |
| 4594 | |
| 4595 | // Verify that the new target is a JSFunction. |
| 4596 | Label new_object; |
| 4597 | __ GetObjectType(a3, a2, a2); |
| 4598 | __ Branch(&new_object, ne, a2, Operand(JS_FUNCTION_TYPE)); |
| 4599 | |
| 4600 | // Load the initial map and verify that it's in fact a map. |
| 4601 | __ lw(a2, FieldMemOperand(a3, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4602 | __ JumpIfSmi(a2, &new_object); |
| 4603 | __ GetObjectType(a2, a0, a0); |
| 4604 | __ Branch(&new_object, ne, a0, Operand(MAP_TYPE)); |
| 4605 | |
| 4606 | // Fall back to runtime if the target differs from the new target's |
| 4607 | // initial map constructor. |
| 4608 | __ lw(a0, FieldMemOperand(a2, Map::kConstructorOrBackPointerOffset)); |
| 4609 | __ Branch(&new_object, ne, a0, Operand(a1)); |
| 4610 | |
| 4611 | // Allocate the JSObject on the heap. |
| 4612 | Label allocate, done_allocate; |
| 4613 | __ lbu(t0, FieldMemOperand(a2, Map::kInstanceSizeOffset)); |
| 4614 | __ Allocate(t0, v0, t1, a0, &allocate, SIZE_IN_WORDS); |
| 4615 | __ bind(&done_allocate); |
| 4616 | |
| 4617 | // Initialize the JSObject fields. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4618 | __ sw(a2, FieldMemOperand(v0, JSObject::kMapOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4619 | __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4620 | __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset)); |
| 4621 | __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4622 | STATIC_ASSERT(JSObject::kHeaderSize == 3 * kPointerSize); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4623 | __ Addu(a1, v0, Operand(JSObject::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4624 | |
| 4625 | // ----------- S t a t e ------------- |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4626 | // -- v0 : result (tagged) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4627 | // -- a1 : result fields (untagged) |
| 4628 | // -- t1 : result end (untagged) |
| 4629 | // -- a2 : initial map |
| 4630 | // -- cp : context |
| 4631 | // -- ra : return address |
| 4632 | // ----------------------------------- |
| 4633 | |
| 4634 | // Perform in-object slack tracking if requested. |
| 4635 | Label slack_tracking; |
| 4636 | STATIC_ASSERT(Map::kNoSlackTracking == 0); |
| 4637 | __ lw(a3, FieldMemOperand(a2, Map::kBitField3Offset)); |
| 4638 | __ And(at, a3, Operand(Map::ConstructionCounter::kMask)); |
| 4639 | __ Branch(USE_DELAY_SLOT, &slack_tracking, ne, at, Operand(0)); |
| 4640 | __ LoadRoot(a0, Heap::kUndefinedValueRootIndex); // In delay slot. |
| 4641 | { |
| 4642 | // Initialize all in-object fields with undefined. |
| 4643 | __ InitializeFieldsWithFiller(a1, t1, a0); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4644 | __ Ret(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4645 | } |
| 4646 | __ bind(&slack_tracking); |
| 4647 | { |
| 4648 | // Decrease generous allocation count. |
| 4649 | STATIC_ASSERT(Map::ConstructionCounter::kNext == 32); |
| 4650 | __ Subu(a3, a3, Operand(1 << Map::ConstructionCounter::kShift)); |
| 4651 | __ sw(a3, FieldMemOperand(a2, Map::kBitField3Offset)); |
| 4652 | |
| 4653 | // Initialize the in-object fields with undefined. |
| 4654 | __ lbu(t0, FieldMemOperand(a2, Map::kUnusedPropertyFieldsOffset)); |
| 4655 | __ sll(t0, t0, kPointerSizeLog2); |
| 4656 | __ subu(t0, t1, t0); |
| 4657 | __ InitializeFieldsWithFiller(a1, t0, a0); |
| 4658 | |
| 4659 | // Initialize the remaining (reserved) fields with one pointer filler map. |
| 4660 | __ LoadRoot(a0, Heap::kOnePointerFillerMapRootIndex); |
| 4661 | __ InitializeFieldsWithFiller(a1, t1, a0); |
| 4662 | |
| 4663 | // Check if we can finalize the instance size. |
| 4664 | Label finalize; |
| 4665 | STATIC_ASSERT(Map::kSlackTrackingCounterEnd == 1); |
| 4666 | __ And(a3, a3, Operand(Map::ConstructionCounter::kMask)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4667 | __ Branch(&finalize, eq, a3, Operand(zero_reg)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4668 | __ Ret(); |
| 4669 | |
| 4670 | // Finalize the instance size. |
| 4671 | __ bind(&finalize); |
| 4672 | { |
| 4673 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4674 | __ Push(v0, a2); |
| 4675 | __ CallRuntime(Runtime::kFinalizeInstanceSize); |
| 4676 | __ Pop(v0); |
| 4677 | } |
| 4678 | __ Ret(); |
| 4679 | } |
| 4680 | |
| 4681 | // Fall back to %AllocateInNewSpace. |
| 4682 | __ bind(&allocate); |
| 4683 | { |
| 4684 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4685 | STATIC_ASSERT(kSmiTag == 0); |
| 4686 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4687 | __ sll(t0, t0, kPointerSizeLog2 + kSmiTagSize); |
| 4688 | __ Push(a2, t0); |
| 4689 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 4690 | __ Pop(a2); |
| 4691 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4692 | __ lbu(t1, FieldMemOperand(a2, Map::kInstanceSizeOffset)); |
| 4693 | __ Lsa(t1, v0, t1, kPointerSizeLog2); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4694 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4695 | __ Subu(t1, t1, Operand(kHeapObjectTag)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4696 | __ jmp(&done_allocate); |
| 4697 | |
| 4698 | // Fall back to %NewObject. |
| 4699 | __ bind(&new_object); |
| 4700 | __ Push(a1, a3); |
| 4701 | __ TailCallRuntime(Runtime::kNewObject); |
| 4702 | } |
| 4703 | |
| 4704 | |
| 4705 | void FastNewRestParameterStub::Generate(MacroAssembler* masm) { |
| 4706 | // ----------- S t a t e ------------- |
| 4707 | // -- a1 : function |
| 4708 | // -- cp : context |
| 4709 | // -- fp : frame pointer |
| 4710 | // -- ra : return address |
| 4711 | // ----------------------------------- |
| 4712 | __ AssertFunction(a1); |
| 4713 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4714 | // Make a2 point to the JavaScript frame. |
| 4715 | __ mov(a2, fp); |
| 4716 | if (skip_stub_frame()) { |
| 4717 | // For Ignition we need to skip the handler/stub frame to reach the |
| 4718 | // JavaScript frame for the function. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4719 | __ lw(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4720 | } |
| 4721 | if (FLAG_debug_code) { |
| 4722 | Label ok; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 4723 | __ lw(a3, MemOperand(a2, StandardFrameConstants::kFunctionOffset)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4724 | __ Branch(&ok, eq, a1, Operand(a3)); |
| 4725 | __ Abort(kInvalidFrameForFastNewRestArgumentsStub); |
| 4726 | __ bind(&ok); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4727 | } |
| 4728 | |
| 4729 | // Check if we have rest parameters (only possible if we have an |
| 4730 | // arguments adaptor frame below the function frame). |
| 4731 | Label no_rest_parameters; |
| 4732 | __ lw(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 4733 | __ lw(a3, MemOperand(a2, CommonFrameConstants::kContextOrFrameTypeOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4734 | __ Branch(&no_rest_parameters, ne, a3, |
| 4735 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4736 | |
| 4737 | // Check if the arguments adaptor frame contains more arguments than |
| 4738 | // specified by the function's internal formal parameter count. |
| 4739 | Label rest_parameters; |
| 4740 | __ lw(a0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4741 | __ lw(a1, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 4742 | __ lw(a1, |
| 4743 | FieldMemOperand(a1, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 4744 | __ Subu(a0, a0, Operand(a1)); |
| 4745 | __ Branch(&rest_parameters, gt, a0, Operand(zero_reg)); |
| 4746 | |
| 4747 | // Return an empty rest parameter array. |
| 4748 | __ bind(&no_rest_parameters); |
| 4749 | { |
| 4750 | // ----------- S t a t e ------------- |
| 4751 | // -- cp : context |
| 4752 | // -- ra : return address |
| 4753 | // ----------------------------------- |
| 4754 | |
| 4755 | // Allocate an empty rest parameter array. |
| 4756 | Label allocate, done_allocate; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4757 | __ Allocate(JSArray::kSize, v0, a0, a1, &allocate, NO_ALLOCATION_FLAGS); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4758 | __ bind(&done_allocate); |
| 4759 | |
| 4760 | // Setup the rest parameter array in v0. |
| 4761 | __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, a1); |
| 4762 | __ sw(a1, FieldMemOperand(v0, JSArray::kMapOffset)); |
| 4763 | __ LoadRoot(a1, Heap::kEmptyFixedArrayRootIndex); |
| 4764 | __ sw(a1, FieldMemOperand(v0, JSArray::kPropertiesOffset)); |
| 4765 | __ sw(a1, FieldMemOperand(v0, JSArray::kElementsOffset)); |
| 4766 | __ Move(a1, Smi::FromInt(0)); |
| 4767 | __ Ret(USE_DELAY_SLOT); |
| 4768 | __ sw(a1, FieldMemOperand(v0, JSArray::kLengthOffset)); // In delay slot |
| 4769 | STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize); |
| 4770 | |
| 4771 | // Fall back to %AllocateInNewSpace. |
| 4772 | __ bind(&allocate); |
| 4773 | { |
| 4774 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4775 | __ Push(Smi::FromInt(JSArray::kSize)); |
| 4776 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 4777 | } |
| 4778 | __ jmp(&done_allocate); |
| 4779 | } |
| 4780 | |
| 4781 | __ bind(&rest_parameters); |
| 4782 | { |
| 4783 | // Compute the pointer to the first rest parameter (skippping the receiver). |
| 4784 | __ Lsa(a2, a2, a0, kPointerSizeLog2 - 1); |
| 4785 | __ Addu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset - |
| 4786 | 1 * kPointerSize)); |
| 4787 | |
| 4788 | // ----------- S t a t e ------------- |
| 4789 | // -- cp : context |
| 4790 | // -- a0 : number of rest parameters (tagged) |
| 4791 | // -- a2 : pointer to first rest parameters |
| 4792 | // -- ra : return address |
| 4793 | // ----------------------------------- |
| 4794 | |
| 4795 | // Allocate space for the rest parameter array plus the backing store. |
| 4796 | Label allocate, done_allocate; |
| 4797 | __ li(a1, Operand(JSArray::kSize + FixedArray::kHeaderSize)); |
| 4798 | __ Lsa(a1, a1, a0, kPointerSizeLog2 - 1); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4799 | __ Allocate(a1, v0, a3, t0, &allocate, NO_ALLOCATION_FLAGS); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4800 | __ bind(&done_allocate); |
| 4801 | |
| 4802 | // Setup the elements array in v0. |
| 4803 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 4804 | __ sw(at, FieldMemOperand(v0, FixedArray::kMapOffset)); |
| 4805 | __ sw(a0, FieldMemOperand(v0, FixedArray::kLengthOffset)); |
| 4806 | __ Addu(a3, v0, Operand(FixedArray::kHeaderSize)); |
| 4807 | { |
| 4808 | Label loop, done_loop; |
| 4809 | __ sll(at, a0, kPointerSizeLog2 - 1); |
| 4810 | __ Addu(a1, a3, at); |
| 4811 | __ bind(&loop); |
| 4812 | __ Branch(&done_loop, eq, a1, Operand(a3)); |
| 4813 | __ lw(at, MemOperand(a2, 0 * kPointerSize)); |
| 4814 | __ sw(at, FieldMemOperand(a3, 0 * kPointerSize)); |
| 4815 | __ Subu(a2, a2, Operand(1 * kPointerSize)); |
| 4816 | __ Addu(a3, a3, Operand(1 * kPointerSize)); |
| 4817 | __ jmp(&loop); |
| 4818 | __ bind(&done_loop); |
| 4819 | } |
| 4820 | |
| 4821 | // Setup the rest parameter array in a3. |
| 4822 | __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, at); |
| 4823 | __ sw(at, FieldMemOperand(a3, JSArray::kMapOffset)); |
| 4824 | __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex); |
| 4825 | __ sw(at, FieldMemOperand(a3, JSArray::kPropertiesOffset)); |
| 4826 | __ sw(v0, FieldMemOperand(a3, JSArray::kElementsOffset)); |
| 4827 | __ sw(a0, FieldMemOperand(a3, JSArray::kLengthOffset)); |
| 4828 | STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize); |
| 4829 | __ Ret(USE_DELAY_SLOT); |
| 4830 | __ mov(v0, a3); // In delay slot |
| 4831 | |
| 4832 | // Fall back to %AllocateInNewSpace. |
| 4833 | __ bind(&allocate); |
| 4834 | { |
| 4835 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4836 | __ SmiTag(a1); |
| 4837 | __ Push(a0, a2, a1); |
| 4838 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 4839 | __ Pop(a0, a2); |
| 4840 | } |
| 4841 | __ jmp(&done_allocate); |
| 4842 | } |
| 4843 | } |
| 4844 | |
| 4845 | |
| 4846 | void FastNewSloppyArgumentsStub::Generate(MacroAssembler* masm) { |
| 4847 | // ----------- S t a t e ------------- |
| 4848 | // -- a1 : function |
| 4849 | // -- cp : context |
| 4850 | // -- fp : frame pointer |
| 4851 | // -- ra : return address |
| 4852 | // ----------------------------------- |
| 4853 | __ AssertFunction(a1); |
| 4854 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4855 | // Make t0 point to the JavaScript frame. |
| 4856 | __ mov(t0, fp); |
| 4857 | if (skip_stub_frame()) { |
| 4858 | // For Ignition we need to skip the handler/stub frame to reach the |
| 4859 | // JavaScript frame for the function. |
| 4860 | __ lw(t0, MemOperand(t0, StandardFrameConstants::kCallerFPOffset)); |
| 4861 | } |
| 4862 | if (FLAG_debug_code) { |
| 4863 | Label ok; |
| 4864 | __ lw(a3, MemOperand(t0, StandardFrameConstants::kFunctionOffset)); |
| 4865 | __ Branch(&ok, eq, a1, Operand(a3)); |
| 4866 | __ Abort(kInvalidFrameForFastNewRestArgumentsStub); |
| 4867 | __ bind(&ok); |
| 4868 | } |
| 4869 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4870 | // TODO(bmeurer): Cleanup to match the FastNewStrictArgumentsStub. |
| 4871 | __ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 4872 | __ lw(a2, |
| 4873 | FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4874 | __ Lsa(a3, t0, a2, kPointerSizeLog2 - 1); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4875 | __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 4876 | |
| 4877 | // a1 : function |
| 4878 | // a2 : number of parameters (tagged) |
| 4879 | // a3 : parameters pointer |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4880 | // t0 : Javascript frame pointer |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4881 | // Registers used over whole function: |
| 4882 | // t1 : arguments count (tagged) |
| 4883 | // t2 : mapped parameter count (tagged) |
| 4884 | |
| 4885 | // Check if the calling frame is an arguments adaptor frame. |
| 4886 | Label adaptor_frame, try_allocate, runtime; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4887 | __ lw(t0, MemOperand(t0, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 4888 | __ lw(a0, MemOperand(t0, CommonFrameConstants::kContextOrFrameTypeOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4889 | __ Branch(&adaptor_frame, eq, a0, |
| 4890 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4891 | |
| 4892 | // No adaptor, parameter count = argument count. |
| 4893 | __ mov(t1, a2); |
| 4894 | __ Branch(USE_DELAY_SLOT, &try_allocate); |
| 4895 | __ mov(t2, a2); // In delay slot. |
| 4896 | |
| 4897 | // We have an adaptor frame. Patch the parameters pointer. |
| 4898 | __ bind(&adaptor_frame); |
| 4899 | __ lw(t1, MemOperand(t0, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4900 | __ Lsa(t0, t0, t1, 1); |
| 4901 | __ Addu(a3, t0, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 4902 | |
| 4903 | // t1 = argument count (tagged) |
| 4904 | // t2 = parameter count (tagged) |
| 4905 | // Compute the mapped parameter count = min(t2, t1) in t2. |
| 4906 | __ mov(t2, a2); |
| 4907 | __ Branch(&try_allocate, le, t2, Operand(t1)); |
| 4908 | __ mov(t2, t1); |
| 4909 | |
| 4910 | __ bind(&try_allocate); |
| 4911 | |
| 4912 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 4913 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 4914 | const int kParameterMapHeaderSize = |
| 4915 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 4916 | // If there are no mapped parameters, we do not need the parameter_map. |
| 4917 | Label param_map_size; |
| 4918 | DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0)); |
| 4919 | __ Branch(USE_DELAY_SLOT, ¶m_map_size, eq, t2, Operand(zero_reg)); |
| 4920 | __ mov(t5, zero_reg); // In delay slot: param map size = 0 when t2 == 0. |
| 4921 | __ sll(t5, t2, 1); |
| 4922 | __ addiu(t5, t5, kParameterMapHeaderSize); |
| 4923 | __ bind(¶m_map_size); |
| 4924 | |
| 4925 | // 2. Backing store. |
| 4926 | __ Lsa(t5, t5, t1, 1); |
| 4927 | __ Addu(t5, t5, Operand(FixedArray::kHeaderSize)); |
| 4928 | |
| 4929 | // 3. Arguments object. |
| 4930 | __ Addu(t5, t5, Operand(JSSloppyArgumentsObject::kSize)); |
| 4931 | |
| 4932 | // Do the allocation of all three objects in one go. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4933 | __ Allocate(t5, v0, t5, t0, &runtime, NO_ALLOCATION_FLAGS); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4934 | |
| 4935 | // v0 = address of new object(s) (tagged) |
| 4936 | // a2 = argument count (smi-tagged) |
| 4937 | // Get the arguments boilerplate from the current native context into t0. |
| 4938 | const int kNormalOffset = |
| 4939 | Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX); |
| 4940 | const int kAliasedOffset = |
| 4941 | Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX); |
| 4942 | |
| 4943 | __ lw(t0, NativeContextMemOperand()); |
| 4944 | Label skip2_ne, skip2_eq; |
| 4945 | __ Branch(&skip2_ne, ne, t2, Operand(zero_reg)); |
| 4946 | __ lw(t0, MemOperand(t0, kNormalOffset)); |
| 4947 | __ bind(&skip2_ne); |
| 4948 | |
| 4949 | __ Branch(&skip2_eq, eq, t2, Operand(zero_reg)); |
| 4950 | __ lw(t0, MemOperand(t0, kAliasedOffset)); |
| 4951 | __ bind(&skip2_eq); |
| 4952 | |
| 4953 | // v0 = address of new object (tagged) |
| 4954 | // a2 = argument count (smi-tagged) |
| 4955 | // t0 = address of arguments map (tagged) |
| 4956 | // t2 = mapped parameter count (tagged) |
| 4957 | __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset)); |
| 4958 | __ LoadRoot(t5, Heap::kEmptyFixedArrayRootIndex); |
| 4959 | __ sw(t5, FieldMemOperand(v0, JSObject::kPropertiesOffset)); |
| 4960 | __ sw(t5, FieldMemOperand(v0, JSObject::kElementsOffset)); |
| 4961 | |
| 4962 | // Set up the callee in-object property. |
| 4963 | __ AssertNotSmi(a1); |
| 4964 | __ sw(a1, FieldMemOperand(v0, JSSloppyArgumentsObject::kCalleeOffset)); |
| 4965 | |
| 4966 | // Use the length (smi tagged) and set that as an in-object property too. |
| 4967 | __ AssertSmi(t1); |
| 4968 | __ sw(t1, FieldMemOperand(v0, JSSloppyArgumentsObject::kLengthOffset)); |
| 4969 | |
| 4970 | // Set up the elements pointer in the allocated arguments object. |
| 4971 | // If we allocated a parameter map, t0 will point there, otherwise |
| 4972 | // it will point to the backing store. |
| 4973 | __ Addu(t0, v0, Operand(JSSloppyArgumentsObject::kSize)); |
| 4974 | __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset)); |
| 4975 | |
| 4976 | // v0 = address of new object (tagged) |
| 4977 | // a2 = argument count (tagged) |
| 4978 | // t0 = address of parameter map or backing store (tagged) |
| 4979 | // t2 = mapped parameter count (tagged) |
| 4980 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 4981 | Label skip_parameter_map; |
| 4982 | Label skip3; |
| 4983 | __ Branch(&skip3, ne, t2, Operand(Smi::FromInt(0))); |
| 4984 | // Move backing store address to a1, because it is |
| 4985 | // expected there when filling in the unmapped arguments. |
| 4986 | __ mov(a1, t0); |
| 4987 | __ bind(&skip3); |
| 4988 | |
| 4989 | __ Branch(&skip_parameter_map, eq, t2, Operand(Smi::FromInt(0))); |
| 4990 | |
| 4991 | __ LoadRoot(t1, Heap::kSloppyArgumentsElementsMapRootIndex); |
| 4992 | __ sw(t1, FieldMemOperand(t0, FixedArray::kMapOffset)); |
| 4993 | __ Addu(t1, t2, Operand(Smi::FromInt(2))); |
| 4994 | __ sw(t1, FieldMemOperand(t0, FixedArray::kLengthOffset)); |
| 4995 | __ sw(cp, FieldMemOperand(t0, FixedArray::kHeaderSize + 0 * kPointerSize)); |
| 4996 | __ Lsa(t1, t0, t2, 1); |
| 4997 | __ Addu(t1, t1, Operand(kParameterMapHeaderSize)); |
| 4998 | __ sw(t1, FieldMemOperand(t0, FixedArray::kHeaderSize + 1 * kPointerSize)); |
| 4999 | |
| 5000 | // Copy the parameter slots and the holes in the arguments. |
| 5001 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 5002 | // where parameters are stored in reverse order, at |
| 5003 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 5004 | // The mapped parameter thus need to get indices |
| 5005 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 5006 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 5007 | // We loop from right to left. |
| 5008 | Label parameters_loop, parameters_test; |
| 5009 | __ mov(t1, t2); |
| 5010 | __ Addu(t5, a2, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 5011 | __ Subu(t5, t5, Operand(t2)); |
| 5012 | __ LoadRoot(t3, Heap::kTheHoleValueRootIndex); |
| 5013 | __ Lsa(a1, t0, t1, 1); |
| 5014 | __ Addu(a1, a1, Operand(kParameterMapHeaderSize)); |
| 5015 | |
| 5016 | // a1 = address of backing store (tagged) |
| 5017 | // t0 = address of parameter map (tagged) |
| 5018 | // a0 = temporary scratch (a.o., for address calculation) |
| 5019 | // t1 = loop variable (tagged) |
| 5020 | // t3 = the hole value |
| 5021 | __ jmp(¶meters_test); |
| 5022 | |
| 5023 | __ bind(¶meters_loop); |
| 5024 | __ Subu(t1, t1, Operand(Smi::FromInt(1))); |
| 5025 | __ sll(a0, t1, 1); |
| 5026 | __ Addu(a0, a0, Operand(kParameterMapHeaderSize - kHeapObjectTag)); |
| 5027 | __ Addu(t6, t0, a0); |
| 5028 | __ sw(t5, MemOperand(t6)); |
| 5029 | __ Subu(a0, a0, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize)); |
| 5030 | __ Addu(t6, a1, a0); |
| 5031 | __ sw(t3, MemOperand(t6)); |
| 5032 | __ Addu(t5, t5, Operand(Smi::FromInt(1))); |
| 5033 | __ bind(¶meters_test); |
| 5034 | __ Branch(¶meters_loop, ne, t1, Operand(Smi::FromInt(0))); |
| 5035 | |
| 5036 | // t1 = argument count (tagged). |
| 5037 | __ lw(t1, FieldMemOperand(v0, JSSloppyArgumentsObject::kLengthOffset)); |
| 5038 | |
| 5039 | __ bind(&skip_parameter_map); |
| 5040 | // v0 = address of new object (tagged) |
| 5041 | // a1 = address of backing store (tagged) |
| 5042 | // t1 = argument count (tagged) |
| 5043 | // t2 = mapped parameter count (tagged) |
| 5044 | // t5 = scratch |
| 5045 | // Copy arguments header and remaining slots (if there are any). |
| 5046 | __ LoadRoot(t5, Heap::kFixedArrayMapRootIndex); |
| 5047 | __ sw(t5, FieldMemOperand(a1, FixedArray::kMapOffset)); |
| 5048 | __ sw(t1, FieldMemOperand(a1, FixedArray::kLengthOffset)); |
| 5049 | |
| 5050 | Label arguments_loop, arguments_test; |
| 5051 | __ sll(t6, t2, 1); |
| 5052 | __ Subu(a3, a3, Operand(t6)); |
| 5053 | __ jmp(&arguments_test); |
| 5054 | |
| 5055 | __ bind(&arguments_loop); |
| 5056 | __ Subu(a3, a3, Operand(kPointerSize)); |
| 5057 | __ lw(t0, MemOperand(a3, 0)); |
| 5058 | __ Lsa(t5, a1, t2, 1); |
| 5059 | __ sw(t0, FieldMemOperand(t5, FixedArray::kHeaderSize)); |
| 5060 | __ Addu(t2, t2, Operand(Smi::FromInt(1))); |
| 5061 | |
| 5062 | __ bind(&arguments_test); |
| 5063 | __ Branch(&arguments_loop, lt, t2, Operand(t1)); |
| 5064 | |
| 5065 | // Return. |
| 5066 | __ Ret(); |
| 5067 | |
| 5068 | // Do the runtime call to allocate the arguments object. |
| 5069 | // t1 = argument count (tagged) |
| 5070 | __ bind(&runtime); |
| 5071 | __ Push(a1, a3, t1); |
| 5072 | __ TailCallRuntime(Runtime::kNewSloppyArguments); |
| 5073 | } |
| 5074 | |
| 5075 | |
| 5076 | void FastNewStrictArgumentsStub::Generate(MacroAssembler* masm) { |
| 5077 | // ----------- S t a t e ------------- |
| 5078 | // -- a1 : function |
| 5079 | // -- cp : context |
| 5080 | // -- fp : frame pointer |
| 5081 | // -- ra : return address |
| 5082 | // ----------------------------------- |
| 5083 | __ AssertFunction(a1); |
| 5084 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5085 | // Make a2 point to the JavaScript frame. |
| 5086 | __ mov(a2, fp); |
| 5087 | if (skip_stub_frame()) { |
| 5088 | // For Ignition we need to skip the handler/stub frame to reach the |
| 5089 | // JavaScript frame for the function. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5090 | __ lw(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5091 | } |
| 5092 | if (FLAG_debug_code) { |
| 5093 | Label ok; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5094 | __ lw(a3, MemOperand(a2, StandardFrameConstants::kFunctionOffset)); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5095 | __ Branch(&ok, eq, a1, Operand(a3)); |
| 5096 | __ Abort(kInvalidFrameForFastNewRestArgumentsStub); |
| 5097 | __ bind(&ok); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5098 | } |
| 5099 | |
| 5100 | // Check if we have an arguments adaptor frame below the function frame. |
| 5101 | Label arguments_adaptor, arguments_done; |
| 5102 | __ lw(a3, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5103 | __ lw(a0, MemOperand(a3, CommonFrameConstants::kContextOrFrameTypeOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5104 | __ Branch(&arguments_adaptor, eq, a0, |
| 5105 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5106 | { |
| 5107 | __ lw(a1, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 5108 | __ lw(a0, |
| 5109 | FieldMemOperand(a1, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 5110 | __ Lsa(a2, a2, a0, kPointerSizeLog2 - 1); |
| 5111 | __ Addu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset - |
| 5112 | 1 * kPointerSize)); |
| 5113 | } |
| 5114 | __ Branch(&arguments_done); |
| 5115 | __ bind(&arguments_adaptor); |
| 5116 | { |
| 5117 | __ lw(a0, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 5118 | __ Lsa(a2, a3, a0, kPointerSizeLog2 - 1); |
| 5119 | __ Addu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset - |
| 5120 | 1 * kPointerSize)); |
| 5121 | } |
| 5122 | __ bind(&arguments_done); |
| 5123 | |
| 5124 | // ----------- S t a t e ------------- |
| 5125 | // -- cp : context |
| 5126 | // -- a0 : number of rest parameters (tagged) |
| 5127 | // -- a2 : pointer to first rest parameters |
| 5128 | // -- ra : return address |
| 5129 | // ----------------------------------- |
| 5130 | |
| 5131 | // Allocate space for the strict arguments object plus the backing store. |
| 5132 | Label allocate, done_allocate; |
| 5133 | __ li(a1, Operand(JSStrictArgumentsObject::kSize + FixedArray::kHeaderSize)); |
| 5134 | __ Lsa(a1, a1, a0, kPointerSizeLog2 - 1); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5135 | __ Allocate(a1, v0, a3, t0, &allocate, NO_ALLOCATION_FLAGS); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5136 | __ bind(&done_allocate); |
| 5137 | |
| 5138 | // Setup the elements array in v0. |
| 5139 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 5140 | __ sw(at, FieldMemOperand(v0, FixedArray::kMapOffset)); |
| 5141 | __ sw(a0, FieldMemOperand(v0, FixedArray::kLengthOffset)); |
| 5142 | __ Addu(a3, v0, Operand(FixedArray::kHeaderSize)); |
| 5143 | { |
| 5144 | Label loop, done_loop; |
| 5145 | __ sll(at, a0, kPointerSizeLog2 - 1); |
| 5146 | __ Addu(a1, a3, at); |
| 5147 | __ bind(&loop); |
| 5148 | __ Branch(&done_loop, eq, a1, Operand(a3)); |
| 5149 | __ lw(at, MemOperand(a2, 0 * kPointerSize)); |
| 5150 | __ sw(at, FieldMemOperand(a3, 0 * kPointerSize)); |
| 5151 | __ Subu(a2, a2, Operand(1 * kPointerSize)); |
| 5152 | __ Addu(a3, a3, Operand(1 * kPointerSize)); |
| 5153 | __ Branch(&loop); |
| 5154 | __ bind(&done_loop); |
| 5155 | } |
| 5156 | |
| 5157 | // Setup the strict arguments object in a3. |
| 5158 | __ LoadNativeContextSlot(Context::STRICT_ARGUMENTS_MAP_INDEX, at); |
| 5159 | __ sw(at, FieldMemOperand(a3, JSStrictArgumentsObject::kMapOffset)); |
| 5160 | __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex); |
| 5161 | __ sw(at, FieldMemOperand(a3, JSStrictArgumentsObject::kPropertiesOffset)); |
| 5162 | __ sw(v0, FieldMemOperand(a3, JSStrictArgumentsObject::kElementsOffset)); |
| 5163 | __ sw(a0, FieldMemOperand(a3, JSStrictArgumentsObject::kLengthOffset)); |
| 5164 | STATIC_ASSERT(JSStrictArgumentsObject::kSize == 4 * kPointerSize); |
| 5165 | __ Ret(USE_DELAY_SLOT); |
| 5166 | __ mov(v0, a3); // In delay slot |
| 5167 | |
| 5168 | // Fall back to %AllocateInNewSpace. |
| 5169 | __ bind(&allocate); |
| 5170 | { |
| 5171 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5172 | __ SmiTag(a1); |
| 5173 | __ Push(a0, a2, a1); |
| 5174 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 5175 | __ Pop(a0, a2); |
| 5176 | } |
| 5177 | __ jmp(&done_allocate); |
| 5178 | } |
| 5179 | |
| 5180 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5181 | void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) { |
| 5182 | Register context_reg = cp; |
| 5183 | Register slot_reg = a2; |
| 5184 | Register result_reg = v0; |
| 5185 | Label slow_case; |
| 5186 | |
| 5187 | // Go up context chain to the script context. |
| 5188 | for (int i = 0; i < depth(); ++i) { |
| 5189 | __ lw(result_reg, ContextMemOperand(context_reg, Context::PREVIOUS_INDEX)); |
| 5190 | context_reg = result_reg; |
| 5191 | } |
| 5192 | |
| 5193 | // Load the PropertyCell value at the specified slot. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5194 | __ Lsa(at, context_reg, slot_reg, kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5195 | __ lw(result_reg, ContextMemOperand(at, 0)); |
| 5196 | __ lw(result_reg, FieldMemOperand(result_reg, PropertyCell::kValueOffset)); |
| 5197 | |
| 5198 | // Check that value is not the_hole. |
| 5199 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 5200 | __ Branch(&slow_case, eq, result_reg, Operand(at)); |
| 5201 | __ Ret(); |
| 5202 | |
| 5203 | // Fallback to the runtime. |
| 5204 | __ bind(&slow_case); |
| 5205 | __ SmiTag(slot_reg); |
| 5206 | __ Push(slot_reg); |
| 5207 | __ TailCallRuntime(Runtime::kLoadGlobalViaContext); |
| 5208 | } |
| 5209 | |
| 5210 | |
| 5211 | void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) { |
| 5212 | Register context_reg = cp; |
| 5213 | Register slot_reg = a2; |
| 5214 | Register value_reg = a0; |
| 5215 | Register cell_reg = t0; |
| 5216 | Register cell_value_reg = t1; |
| 5217 | Register cell_details_reg = t2; |
| 5218 | Label fast_heapobject_case, fast_smi_case, slow_case; |
| 5219 | |
| 5220 | if (FLAG_debug_code) { |
| 5221 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 5222 | __ Check(ne, kUnexpectedValue, value_reg, Operand(at)); |
| 5223 | } |
| 5224 | |
| 5225 | // Go up context chain to the script context. |
| 5226 | for (int i = 0; i < depth(); ++i) { |
| 5227 | __ lw(cell_reg, ContextMemOperand(context_reg, Context::PREVIOUS_INDEX)); |
| 5228 | context_reg = cell_reg; |
| 5229 | } |
| 5230 | |
| 5231 | // Load the PropertyCell at the specified slot. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5232 | __ Lsa(at, context_reg, slot_reg, kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5233 | __ lw(cell_reg, ContextMemOperand(at, 0)); |
| 5234 | |
| 5235 | // Load PropertyDetails for the cell (actually only the cell_type and kind). |
| 5236 | __ lw(cell_details_reg, |
| 5237 | FieldMemOperand(cell_reg, PropertyCell::kDetailsOffset)); |
| 5238 | __ SmiUntag(cell_details_reg); |
| 5239 | __ And(cell_details_reg, cell_details_reg, |
| 5240 | PropertyDetails::PropertyCellTypeField::kMask | |
| 5241 | PropertyDetails::KindField::kMask | |
| 5242 | PropertyDetails::kAttributesReadOnlyMask); |
| 5243 | |
| 5244 | // Check if PropertyCell holds mutable data. |
| 5245 | Label not_mutable_data; |
| 5246 | __ Branch(¬_mutable_data, ne, cell_details_reg, |
| 5247 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5248 | PropertyCellType::kMutable) | |
| 5249 | PropertyDetails::KindField::encode(kData))); |
| 5250 | __ JumpIfSmi(value_reg, &fast_smi_case); |
| 5251 | __ bind(&fast_heapobject_case); |
| 5252 | __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5253 | __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg, |
| 5254 | cell_details_reg, kRAHasNotBeenSaved, kDontSaveFPRegs, |
| 5255 | EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); |
| 5256 | // RecordWriteField clobbers the value register, so we need to reload. |
| 5257 | __ Ret(USE_DELAY_SLOT); |
| 5258 | __ lw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5259 | __ bind(¬_mutable_data); |
| 5260 | |
| 5261 | // Check if PropertyCell value matches the new value (relevant for Constant, |
| 5262 | // ConstantType and Undefined cells). |
| 5263 | Label not_same_value; |
| 5264 | __ lw(cell_value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5265 | __ Branch(¬_same_value, ne, value_reg, Operand(cell_value_reg)); |
| 5266 | // Make sure the PropertyCell is not marked READ_ONLY. |
| 5267 | __ And(at, cell_details_reg, PropertyDetails::kAttributesReadOnlyMask); |
| 5268 | __ Branch(&slow_case, ne, at, Operand(zero_reg)); |
| 5269 | if (FLAG_debug_code) { |
| 5270 | Label done; |
| 5271 | // This can only be true for Constant, ConstantType and Undefined cells, |
| 5272 | // because we never store the_hole via this stub. |
| 5273 | __ Branch(&done, eq, cell_details_reg, |
| 5274 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5275 | PropertyCellType::kConstant) | |
| 5276 | PropertyDetails::KindField::encode(kData))); |
| 5277 | __ Branch(&done, eq, cell_details_reg, |
| 5278 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5279 | PropertyCellType::kConstantType) | |
| 5280 | PropertyDetails::KindField::encode(kData))); |
| 5281 | __ Check(eq, kUnexpectedValue, cell_details_reg, |
| 5282 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5283 | PropertyCellType::kUndefined) | |
| 5284 | PropertyDetails::KindField::encode(kData))); |
| 5285 | __ bind(&done); |
| 5286 | } |
| 5287 | __ Ret(); |
| 5288 | __ bind(¬_same_value); |
| 5289 | |
| 5290 | // Check if PropertyCell contains data with constant type (and is not |
| 5291 | // READ_ONLY). |
| 5292 | __ Branch(&slow_case, ne, cell_details_reg, |
| 5293 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5294 | PropertyCellType::kConstantType) | |
| 5295 | PropertyDetails::KindField::encode(kData))); |
| 5296 | |
| 5297 | // Now either both old and new values must be SMIs or both must be heap |
| 5298 | // objects with same map. |
| 5299 | Label value_is_heap_object; |
| 5300 | __ JumpIfNotSmi(value_reg, &value_is_heap_object); |
| 5301 | __ JumpIfNotSmi(cell_value_reg, &slow_case); |
| 5302 | // Old and new values are SMIs, no need for a write barrier here. |
| 5303 | __ bind(&fast_smi_case); |
| 5304 | __ Ret(USE_DELAY_SLOT); |
| 5305 | __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5306 | __ bind(&value_is_heap_object); |
| 5307 | __ JumpIfSmi(cell_value_reg, &slow_case); |
| 5308 | Register cell_value_map_reg = cell_value_reg; |
| 5309 | __ lw(cell_value_map_reg, |
| 5310 | FieldMemOperand(cell_value_reg, HeapObject::kMapOffset)); |
| 5311 | __ Branch(&fast_heapobject_case, eq, cell_value_map_reg, |
| 5312 | FieldMemOperand(value_reg, HeapObject::kMapOffset)); |
| 5313 | |
| 5314 | // Fallback to the runtime. |
| 5315 | __ bind(&slow_case); |
| 5316 | __ SmiTag(slot_reg); |
| 5317 | __ Push(slot_reg, value_reg); |
| 5318 | __ TailCallRuntime(is_strict(language_mode()) |
| 5319 | ? Runtime::kStoreGlobalViaContext_Strict |
| 5320 | : Runtime::kStoreGlobalViaContext_Sloppy); |
| 5321 | } |
| 5322 | |
| 5323 | |
| 5324 | static int AddressOffset(ExternalReference ref0, ExternalReference ref1) { |
| 5325 | return ref0.address() - ref1.address(); |
| 5326 | } |
| 5327 | |
| 5328 | |
| 5329 | // Calls an API function. Allocates HandleScope, extracts returned value |
| 5330 | // from handle and propagates exceptions. Restores context. stack_space |
| 5331 | // - space to be unwound on exit (includes the call JS arguments space and |
| 5332 | // the additional space allocated for the fast call). |
| 5333 | static void CallApiFunctionAndReturn( |
| 5334 | MacroAssembler* masm, Register function_address, |
| 5335 | ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset, |
| 5336 | MemOperand return_value_operand, MemOperand* context_restore_operand) { |
| 5337 | Isolate* isolate = masm->isolate(); |
| 5338 | ExternalReference next_address = |
| 5339 | ExternalReference::handle_scope_next_address(isolate); |
| 5340 | const int kNextOffset = 0; |
| 5341 | const int kLimitOffset = AddressOffset( |
| 5342 | ExternalReference::handle_scope_limit_address(isolate), next_address); |
| 5343 | const int kLevelOffset = AddressOffset( |
| 5344 | ExternalReference::handle_scope_level_address(isolate), next_address); |
| 5345 | |
| 5346 | DCHECK(function_address.is(a1) || function_address.is(a2)); |
| 5347 | |
| 5348 | Label profiler_disabled; |
| 5349 | Label end_profiler_check; |
| 5350 | __ li(t9, Operand(ExternalReference::is_profiling_address(isolate))); |
| 5351 | __ lb(t9, MemOperand(t9, 0)); |
| 5352 | __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg)); |
| 5353 | |
| 5354 | // Additional parameter is the address of the actual callback. |
| 5355 | __ li(t9, Operand(thunk_ref)); |
| 5356 | __ jmp(&end_profiler_check); |
| 5357 | |
| 5358 | __ bind(&profiler_disabled); |
| 5359 | __ mov(t9, function_address); |
| 5360 | __ bind(&end_profiler_check); |
| 5361 | |
| 5362 | // Allocate HandleScope in callee-save registers. |
| 5363 | __ li(s3, Operand(next_address)); |
| 5364 | __ lw(s0, MemOperand(s3, kNextOffset)); |
| 5365 | __ lw(s1, MemOperand(s3, kLimitOffset)); |
| 5366 | __ lw(s2, MemOperand(s3, kLevelOffset)); |
| 5367 | __ Addu(s2, s2, Operand(1)); |
| 5368 | __ sw(s2, MemOperand(s3, kLevelOffset)); |
| 5369 | |
| 5370 | if (FLAG_log_timer_events) { |
| 5371 | FrameScope frame(masm, StackFrame::MANUAL); |
| 5372 | __ PushSafepointRegisters(); |
| 5373 | __ PrepareCallCFunction(1, a0); |
| 5374 | __ li(a0, Operand(ExternalReference::isolate_address(isolate))); |
| 5375 | __ CallCFunction(ExternalReference::log_enter_external_function(isolate), |
| 5376 | 1); |
| 5377 | __ PopSafepointRegisters(); |
| 5378 | } |
| 5379 | |
| 5380 | // Native call returns to the DirectCEntry stub which redirects to the |
| 5381 | // return address pushed on stack (could have moved after GC). |
| 5382 | // DirectCEntry stub itself is generated early and never moves. |
| 5383 | DirectCEntryStub stub(isolate); |
| 5384 | stub.GenerateCall(masm, t9); |
| 5385 | |
| 5386 | if (FLAG_log_timer_events) { |
| 5387 | FrameScope frame(masm, StackFrame::MANUAL); |
| 5388 | __ PushSafepointRegisters(); |
| 5389 | __ PrepareCallCFunction(1, a0); |
| 5390 | __ li(a0, Operand(ExternalReference::isolate_address(isolate))); |
| 5391 | __ CallCFunction(ExternalReference::log_leave_external_function(isolate), |
| 5392 | 1); |
| 5393 | __ PopSafepointRegisters(); |
| 5394 | } |
| 5395 | |
| 5396 | Label promote_scheduled_exception; |
| 5397 | Label delete_allocated_handles; |
| 5398 | Label leave_exit_frame; |
| 5399 | Label return_value_loaded; |
| 5400 | |
| 5401 | // Load value from ReturnValue. |
| 5402 | __ lw(v0, return_value_operand); |
| 5403 | __ bind(&return_value_loaded); |
| 5404 | |
| 5405 | // No more valid handles (the result handle was the last one). Restore |
| 5406 | // previous handle scope. |
| 5407 | __ sw(s0, MemOperand(s3, kNextOffset)); |
| 5408 | if (__ emit_debug_code()) { |
| 5409 | __ lw(a1, MemOperand(s3, kLevelOffset)); |
| 5410 | __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2)); |
| 5411 | } |
| 5412 | __ Subu(s2, s2, Operand(1)); |
| 5413 | __ sw(s2, MemOperand(s3, kLevelOffset)); |
| 5414 | __ lw(at, MemOperand(s3, kLimitOffset)); |
| 5415 | __ Branch(&delete_allocated_handles, ne, s1, Operand(at)); |
| 5416 | |
| 5417 | // Leave the API exit frame. |
| 5418 | __ bind(&leave_exit_frame); |
| 5419 | |
| 5420 | bool restore_context = context_restore_operand != NULL; |
| 5421 | if (restore_context) { |
| 5422 | __ lw(cp, *context_restore_operand); |
| 5423 | } |
| 5424 | if (stack_space_offset != kInvalidStackOffset) { |
| 5425 | // ExitFrame contains four MIPS argument slots after DirectCEntryStub call |
| 5426 | // so this must be accounted for. |
| 5427 | __ lw(s0, MemOperand(sp, stack_space_offset + kCArgsSlotsSize)); |
| 5428 | } else { |
| 5429 | __ li(s0, Operand(stack_space)); |
| 5430 | } |
| 5431 | __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN, |
| 5432 | stack_space_offset != kInvalidStackOffset); |
| 5433 | |
| 5434 | // Check if the function scheduled an exception. |
| 5435 | __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); |
| 5436 | __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate))); |
| 5437 | __ lw(t1, MemOperand(at)); |
| 5438 | __ Branch(&promote_scheduled_exception, ne, t0, Operand(t1)); |
| 5439 | |
| 5440 | __ Ret(); |
| 5441 | |
| 5442 | // Re-throw by promoting a scheduled exception. |
| 5443 | __ bind(&promote_scheduled_exception); |
| 5444 | __ TailCallRuntime(Runtime::kPromoteScheduledException); |
| 5445 | |
| 5446 | // HandleScope limit has changed. Delete allocated extensions. |
| 5447 | __ bind(&delete_allocated_handles); |
| 5448 | __ sw(s1, MemOperand(s3, kLimitOffset)); |
| 5449 | __ mov(s0, v0); |
| 5450 | __ mov(a0, v0); |
| 5451 | __ PrepareCallCFunction(1, s1); |
| 5452 | __ li(a0, Operand(ExternalReference::isolate_address(isolate))); |
| 5453 | __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate), |
| 5454 | 1); |
| 5455 | __ mov(v0, s0); |
| 5456 | __ jmp(&leave_exit_frame); |
| 5457 | } |
| 5458 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5459 | void CallApiCallbackStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5460 | // ----------- S t a t e ------------- |
| 5461 | // -- a0 : callee |
| 5462 | // -- t0 : call_data |
| 5463 | // -- a2 : holder |
| 5464 | // -- a1 : api_function_address |
| 5465 | // -- cp : context |
| 5466 | // -- |
| 5467 | // -- sp[0] : last argument |
| 5468 | // -- ... |
| 5469 | // -- sp[(argc - 1)* 4] : first argument |
| 5470 | // -- sp[argc * 4] : receiver |
| 5471 | // ----------------------------------- |
| 5472 | |
| 5473 | Register callee = a0; |
| 5474 | Register call_data = t0; |
| 5475 | Register holder = a2; |
| 5476 | Register api_function_address = a1; |
| 5477 | Register context = cp; |
| 5478 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5479 | typedef FunctionCallbackArguments FCA; |
| 5480 | |
| 5481 | STATIC_ASSERT(FCA::kContextSaveIndex == 6); |
| 5482 | STATIC_ASSERT(FCA::kCalleeIndex == 5); |
| 5483 | STATIC_ASSERT(FCA::kDataIndex == 4); |
| 5484 | STATIC_ASSERT(FCA::kReturnValueOffset == 3); |
| 5485 | STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); |
| 5486 | STATIC_ASSERT(FCA::kIsolateIndex == 1); |
| 5487 | STATIC_ASSERT(FCA::kHolderIndex == 0); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5488 | STATIC_ASSERT(FCA::kNewTargetIndex == 7); |
| 5489 | STATIC_ASSERT(FCA::kArgsLength == 8); |
| 5490 | |
| 5491 | // new target |
| 5492 | __ PushRoot(Heap::kUndefinedValueRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5493 | |
| 5494 | // Save context, callee and call data. |
| 5495 | __ Push(context, callee, call_data); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5496 | if (!is_lazy()) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5497 | // Load context from callee. |
| 5498 | __ lw(context, FieldMemOperand(callee, JSFunction::kContextOffset)); |
| 5499 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5500 | |
| 5501 | Register scratch = call_data; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5502 | if (!call_data_undefined()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5503 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 5504 | } |
| 5505 | // Push return value and default return value. |
| 5506 | __ Push(scratch, scratch); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5507 | __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5508 | // Push isolate and holder. |
| 5509 | __ Push(scratch, holder); |
| 5510 | |
| 5511 | // Prepare arguments. |
| 5512 | __ mov(scratch, sp); |
| 5513 | |
| 5514 | // Allocate the v8::Arguments structure in the arguments' space since |
| 5515 | // it's not controlled by GC. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5516 | const int kApiStackSpace = 3; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5517 | |
| 5518 | FrameScope frame_scope(masm, StackFrame::MANUAL); |
| 5519 | __ EnterExitFrame(false, kApiStackSpace); |
| 5520 | |
| 5521 | DCHECK(!api_function_address.is(a0) && !scratch.is(a0)); |
| 5522 | // a0 = FunctionCallbackInfo& |
| 5523 | // Arguments is after the return address. |
| 5524 | __ Addu(a0, sp, Operand(1 * kPointerSize)); |
| 5525 | // FunctionCallbackInfo::implicit_args_ |
| 5526 | __ sw(scratch, MemOperand(a0, 0 * kPointerSize)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5527 | // FunctionCallbackInfo::values_ |
| 5528 | __ Addu(at, scratch, Operand((FCA::kArgsLength - 1 + argc()) * kPointerSize)); |
| 5529 | __ sw(at, MemOperand(a0, 1 * kPointerSize)); |
| 5530 | // FunctionCallbackInfo::length_ = argc |
| 5531 | __ li(at, Operand(argc())); |
| 5532 | __ sw(at, MemOperand(a0, 2 * kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5533 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5534 | ExternalReference thunk_ref = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5535 | ExternalReference::invoke_function_callback(masm->isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5536 | |
| 5537 | AllowExternalCallThatCantCauseGC scope(masm); |
| 5538 | MemOperand context_restore_operand( |
| 5539 | fp, (2 + FCA::kContextSaveIndex) * kPointerSize); |
| 5540 | // Stores return the first js argument. |
| 5541 | int return_value_offset = 0; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5542 | if (is_store()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5543 | return_value_offset = 2 + FCA::kArgsLength; |
| 5544 | } else { |
| 5545 | return_value_offset = 2 + FCA::kReturnValueOffset; |
| 5546 | } |
| 5547 | MemOperand return_value_operand(fp, return_value_offset * kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5548 | int stack_space = 0; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5549 | int32_t stack_space_offset = 3 * kPointerSize; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5550 | stack_space = argc() + FCA::kArgsLength + 1; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5551 | // TODO(adamk): Why are we clobbering this immediately? |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5552 | stack_space_offset = kInvalidStackOffset; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5553 | CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space, |
| 5554 | stack_space_offset, return_value_operand, |
| 5555 | &context_restore_operand); |
| 5556 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5557 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5558 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5559 | void CallApiGetterStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5560 | // Build v8::PropertyCallbackInfo::args_ array on the stack and push property |
| 5561 | // name below the exit frame to make GC aware of them. |
| 5562 | STATIC_ASSERT(PropertyCallbackArguments::kShouldThrowOnErrorIndex == 0); |
| 5563 | STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 1); |
| 5564 | STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 2); |
| 5565 | STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 3); |
| 5566 | STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 4); |
| 5567 | STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 5); |
| 5568 | STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 6); |
| 5569 | STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 7); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5570 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5571 | Register receiver = ApiGetterDescriptor::ReceiverRegister(); |
| 5572 | Register holder = ApiGetterDescriptor::HolderRegister(); |
| 5573 | Register callback = ApiGetterDescriptor::CallbackRegister(); |
| 5574 | Register scratch = t0; |
| 5575 | DCHECK(!AreAliased(receiver, holder, callback, scratch)); |
| 5576 | |
| 5577 | Register api_function_address = a2; |
| 5578 | |
| 5579 | // Here and below +1 is for name() pushed after the args_ array. |
| 5580 | typedef PropertyCallbackArguments PCA; |
| 5581 | __ Subu(sp, sp, (PCA::kArgsLength + 1) * kPointerSize); |
| 5582 | __ sw(receiver, MemOperand(sp, (PCA::kThisIndex + 1) * kPointerSize)); |
| 5583 | __ lw(scratch, FieldMemOperand(callback, AccessorInfo::kDataOffset)); |
| 5584 | __ sw(scratch, MemOperand(sp, (PCA::kDataIndex + 1) * kPointerSize)); |
| 5585 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 5586 | __ sw(scratch, MemOperand(sp, (PCA::kReturnValueOffset + 1) * kPointerSize)); |
| 5587 | __ sw(scratch, MemOperand(sp, (PCA::kReturnValueDefaultValueIndex + 1) * |
| 5588 | kPointerSize)); |
| 5589 | __ li(scratch, Operand(ExternalReference::isolate_address(isolate()))); |
| 5590 | __ sw(scratch, MemOperand(sp, (PCA::kIsolateIndex + 1) * kPointerSize)); |
| 5591 | __ sw(holder, MemOperand(sp, (PCA::kHolderIndex + 1) * kPointerSize)); |
| 5592 | // should_throw_on_error -> false |
| 5593 | DCHECK(Smi::FromInt(0) == nullptr); |
| 5594 | __ sw(zero_reg, |
| 5595 | MemOperand(sp, (PCA::kShouldThrowOnErrorIndex + 1) * kPointerSize)); |
| 5596 | __ lw(scratch, FieldMemOperand(callback, AccessorInfo::kNameOffset)); |
| 5597 | __ sw(scratch, MemOperand(sp, 0 * kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5598 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5599 | // v8::PropertyCallbackInfo::args_ array and name handle. |
| 5600 | const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1; |
| 5601 | |
| 5602 | // Load address of v8::PropertyAccessorInfo::args_ array and name handle. |
| 5603 | __ mov(a0, sp); // a0 = Handle<Name> |
| 5604 | __ Addu(a1, a0, Operand(1 * kPointerSize)); // a1 = v8::PCI::args_ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5605 | |
| 5606 | const int kApiStackSpace = 1; |
| 5607 | FrameScope frame_scope(masm, StackFrame::MANUAL); |
| 5608 | __ EnterExitFrame(false, kApiStackSpace); |
| 5609 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5610 | // Create v8::PropertyCallbackInfo object on the stack and initialize |
| 5611 | // it's args_ field. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5612 | __ sw(a1, MemOperand(sp, 1 * kPointerSize)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5613 | __ Addu(a1, sp, Operand(1 * kPointerSize)); // a1 = v8::PropertyCallbackInfo& |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5614 | |
| 5615 | ExternalReference thunk_ref = |
| 5616 | ExternalReference::invoke_accessor_getter_callback(isolate()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5617 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5618 | __ lw(scratch, FieldMemOperand(callback, AccessorInfo::kJsGetterOffset)); |
| 5619 | __ lw(api_function_address, |
| 5620 | FieldMemOperand(scratch, Foreign::kForeignAddressOffset)); |
| 5621 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5622 | // +3 is to skip prolog, return address and name handle. |
| 5623 | MemOperand return_value_operand( |
| 5624 | fp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5625 | CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, |
| 5626 | kStackUnwindSpace, kInvalidStackOffset, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5627 | return_value_operand, NULL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5628 | } |
| 5629 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5630 | #undef __ |
| 5631 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5632 | } // namespace internal |
| 5633 | } // namespace v8 |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5634 | |
| 5635 | #endif // V8_TARGET_ARCH_MIPS |