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 | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7 | #include "src/base/bits.h" |
| 8 | #include "src/bootstrapper.h" |
| 9 | #include "src/code-stubs.h" |
| 10 | #include "src/codegen.h" |
| 11 | #include "src/ic/handler-compiler.h" |
| 12 | #include "src/ic/ic.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 13 | #include "src/ic/stub-cache.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 14 | #include "src/isolate.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 15 | #include "src/mips/code-stubs-mips.h" |
| 16 | #include "src/regexp/jsregexp.h" |
| 17 | #include "src/regexp/regexp-macro-assembler.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 18 | #include "src/runtime/runtime.h" |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 19 | |
| 20 | namespace v8 { |
| 21 | namespace internal { |
| 22 | |
| 23 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 24 | static void InitializeArrayConstructorDescriptor( |
| 25 | Isolate* isolate, CodeStubDescriptor* descriptor, |
| 26 | int constant_stack_parameter_count) { |
| 27 | Address deopt_handler = Runtime::FunctionForId( |
| 28 | Runtime::kArrayConstructor)->entry; |
| 29 | |
| 30 | if (constant_stack_parameter_count == 0) { |
| 31 | descriptor->Initialize(deopt_handler, constant_stack_parameter_count, |
| 32 | JS_FUNCTION_STUB_MODE); |
| 33 | } else { |
| 34 | descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 35 | JS_FUNCTION_STUB_MODE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
| 39 | |
| 40 | static void InitializeInternalArrayConstructorDescriptor( |
| 41 | Isolate* isolate, CodeStubDescriptor* descriptor, |
| 42 | int constant_stack_parameter_count) { |
| 43 | Address deopt_handler = Runtime::FunctionForId( |
| 44 | Runtime::kInternalArrayConstructor)->entry; |
| 45 | |
| 46 | if (constant_stack_parameter_count == 0) { |
| 47 | descriptor->Initialize(deopt_handler, constant_stack_parameter_count, |
| 48 | JS_FUNCTION_STUB_MODE); |
| 49 | } else { |
| 50 | descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 51 | JS_FUNCTION_STUB_MODE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 52 | } |
| 53 | } |
| 54 | |
| 55 | |
| 56 | void ArrayNoArgumentConstructorStub::InitializeDescriptor( |
| 57 | CodeStubDescriptor* descriptor) { |
| 58 | InitializeArrayConstructorDescriptor(isolate(), descriptor, 0); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | void ArraySingleArgumentConstructorStub::InitializeDescriptor( |
| 63 | CodeStubDescriptor* descriptor) { |
| 64 | InitializeArrayConstructorDescriptor(isolate(), descriptor, 1); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | void ArrayNArgumentsConstructorStub::InitializeDescriptor( |
| 69 | CodeStubDescriptor* descriptor) { |
| 70 | InitializeArrayConstructorDescriptor(isolate(), descriptor, -1); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | void InternalArrayNoArgumentConstructorStub::InitializeDescriptor( |
| 75 | CodeStubDescriptor* descriptor) { |
| 76 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | void InternalArraySingleArgumentConstructorStub::InitializeDescriptor( |
| 81 | CodeStubDescriptor* descriptor) { |
| 82 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | void InternalArrayNArgumentsConstructorStub::InitializeDescriptor( |
| 87 | CodeStubDescriptor* descriptor) { |
| 88 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1); |
| 89 | } |
| 90 | |
| 91 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 92 | #define __ ACCESS_MASM(masm) |
| 93 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 94 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 95 | Condition cc); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 96 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 97 | Register lhs, |
| 98 | Register rhs, |
| 99 | Label* rhs_not_nan, |
| 100 | Label* slow, |
| 101 | bool strict); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 102 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 103 | Register lhs, |
| 104 | Register rhs); |
| 105 | |
| 106 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 107 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm, |
| 108 | ExternalReference miss) { |
| 109 | // Update the static counter each time a new code stub is generated. |
| 110 | isolate()->counters()->code_stubs()->Increment(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 111 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 112 | CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 113 | int param_count = descriptor.GetRegisterParameterCount(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 114 | { |
| 115 | // Call the runtime system in a fresh internal frame. |
| 116 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 117 | DCHECK(param_count == 0 || |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 118 | a0.is(descriptor.GetRegisterParameter(param_count - 1))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 119 | // Push arguments, adjust sp. |
| 120 | __ Subu(sp, sp, Operand(param_count * kPointerSize)); |
| 121 | for (int i = 0; i < param_count; ++i) { |
| 122 | // Store argument to stack. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 123 | __ sw(descriptor.GetRegisterParameter(i), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 124 | MemOperand(sp, (param_count - 1 - i) * kPointerSize)); |
| 125 | } |
| 126 | __ CallExternalReference(miss, param_count); |
| 127 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 128 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 129 | __ Ret(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 133 | void DoubleToIStub::Generate(MacroAssembler* masm) { |
| 134 | Label out_of_range, only_low, negate, done; |
| 135 | Register input_reg = source(); |
| 136 | Register result_reg = destination(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 137 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 138 | int double_offset = offset(); |
| 139 | // Account for saved regs if input is sp. |
| 140 | if (input_reg.is(sp)) double_offset += 3 * kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 141 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 142 | Register scratch = |
| 143 | GetRegisterThatIsNotOneOf(input_reg, result_reg); |
| 144 | Register scratch2 = |
| 145 | GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch); |
| 146 | Register scratch3 = |
| 147 | GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch2); |
| 148 | DoubleRegister double_scratch = kLithiumScratchDouble; |
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 | __ Push(scratch, scratch2, scratch3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 151 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 152 | if (!skip_fastpath()) { |
| 153 | // Load double input. |
| 154 | __ ldc1(double_scratch, MemOperand(input_reg, double_offset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 155 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 156 | // Clear cumulative exception flags and save the FCSR. |
| 157 | __ cfc1(scratch2, FCSR); |
| 158 | __ ctc1(zero_reg, FCSR); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 159 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 160 | // Try a conversion to a signed integer. |
| 161 | __ Trunc_w_d(double_scratch, double_scratch); |
| 162 | // Move the converted value into the result register. |
| 163 | __ mfc1(scratch3, double_scratch); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 164 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 165 | // Retrieve and restore the FCSR. |
| 166 | __ cfc1(scratch, FCSR); |
| 167 | __ ctc1(scratch2, FCSR); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 168 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 169 | // Check for overflow and NaNs. |
| 170 | __ And( |
| 171 | scratch, scratch, |
| 172 | kFCSROverflowFlagMask | kFCSRUnderflowFlagMask |
| 173 | | kFCSRInvalidOpFlagMask); |
| 174 | // If we had no exceptions then set result_reg and we are done. |
| 175 | Label error; |
| 176 | __ Branch(&error, ne, scratch, Operand(zero_reg)); |
| 177 | __ Move(result_reg, scratch3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 178 | __ Branch(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 179 | __ bind(&error); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 182 | // Load the double value and perform a manual truncation. |
| 183 | Register input_high = scratch2; |
| 184 | Register input_low = scratch3; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 185 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 186 | __ lw(input_low, |
| 187 | MemOperand(input_reg, double_offset + Register::kMantissaOffset)); |
| 188 | __ lw(input_high, |
| 189 | MemOperand(input_reg, double_offset + Register::kExponentOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 190 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 191 | Label normal_exponent, restore_sign; |
| 192 | // Extract the biased exponent in result. |
| 193 | __ Ext(result_reg, |
| 194 | input_high, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 195 | HeapNumber::kExponentShift, |
| 196 | HeapNumber::kExponentBits); |
| 197 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 198 | // Check for Infinity and NaNs, which should return 0. |
| 199 | __ Subu(scratch, result_reg, HeapNumber::kExponentMask); |
| 200 | __ Movz(result_reg, zero_reg, scratch); |
| 201 | __ Branch(&done, eq, scratch, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 202 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 203 | // Express exponent as delta to (number of mantissa bits + 31). |
| 204 | __ Subu(result_reg, |
| 205 | result_reg, |
| 206 | Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31)); |
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 | // If the delta is strictly positive, all bits would be shifted away, |
| 209 | // which means that we can return 0. |
| 210 | __ Branch(&normal_exponent, le, result_reg, Operand(zero_reg)); |
| 211 | __ mov(result_reg, zero_reg); |
| 212 | __ Branch(&done); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 213 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 214 | __ bind(&normal_exponent); |
| 215 | const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 216 | // Calculate shift. |
| 217 | __ Addu(scratch, result_reg, Operand(kShiftBase + HeapNumber::kMantissaBits)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 218 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 219 | // Save the sign. |
| 220 | Register sign = result_reg; |
| 221 | result_reg = no_reg; |
| 222 | __ And(sign, input_high, Operand(HeapNumber::kSignMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 223 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 224 | // On ARM shifts > 31 bits are valid and will result in zero. On MIPS we need |
| 225 | // to check for this specific case. |
| 226 | Label high_shift_needed, high_shift_done; |
| 227 | __ Branch(&high_shift_needed, lt, scratch, Operand(32)); |
| 228 | __ mov(input_high, zero_reg); |
| 229 | __ Branch(&high_shift_done); |
| 230 | __ bind(&high_shift_needed); |
| 231 | |
| 232 | // Set the implicit 1 before the mantissa part in input_high. |
| 233 | __ Or(input_high, |
| 234 | input_high, |
| 235 | Operand(1 << HeapNumber::kMantissaBitsInTopWord)); |
| 236 | // Shift the mantissa bits to the correct position. |
| 237 | // We don't need to clear non-mantissa bits as they will be shifted away. |
| 238 | // If they weren't, it would mean that the answer is in the 32bit range. |
| 239 | __ sllv(input_high, input_high, scratch); |
| 240 | |
| 241 | __ bind(&high_shift_done); |
| 242 | |
| 243 | // Replace the shifted bits with bits from the lower mantissa word. |
| 244 | Label pos_shift, shift_done; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 245 | __ li(at, 32); |
| 246 | __ subu(scratch, at, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 247 | __ Branch(&pos_shift, ge, scratch, Operand(zero_reg)); |
| 248 | |
| 249 | // Negate scratch. |
| 250 | __ Subu(scratch, zero_reg, scratch); |
| 251 | __ sllv(input_low, input_low, scratch); |
| 252 | __ Branch(&shift_done); |
| 253 | |
| 254 | __ bind(&pos_shift); |
| 255 | __ srlv(input_low, input_low, scratch); |
| 256 | |
| 257 | __ bind(&shift_done); |
| 258 | __ Or(input_high, input_high, Operand(input_low)); |
| 259 | // Restore sign if necessary. |
| 260 | __ mov(scratch, sign); |
| 261 | result_reg = sign; |
| 262 | sign = no_reg; |
| 263 | __ Subu(result_reg, zero_reg, input_high); |
| 264 | __ Movz(result_reg, input_high, scratch); |
| 265 | |
| 266 | __ bind(&done); |
| 267 | |
| 268 | __ Pop(scratch, scratch2, scratch3); |
| 269 | __ Ret(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 273 | // Handle the case where the lhs and rhs are the same object. |
| 274 | // Equality is almost reflexive (everything but NaN), so this is a test |
| 275 | // for "identity and not NaN". |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 276 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 277 | Condition cc) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 278 | Label not_identical; |
| 279 | Label heap_number, return_equal; |
| 280 | Register exp_mask_reg = t5; |
| 281 | |
| 282 | __ Branch(¬_identical, ne, a0, Operand(a1)); |
| 283 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 284 | __ li(exp_mask_reg, Operand(HeapNumber::kExponentMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 285 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 286 | // Test for NaN. Sadly, we can't just compare to Factory::nan_value(), |
| 287 | // so we do the second best thing - test it ourselves. |
| 288 | // They are both equal and they are not both Smis so both of them are not |
| 289 | // Smis. If it's not a heap number, then return equal. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 290 | __ GetObjectType(a0, t4, t4); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 291 | if (cc == less || cc == greater) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 292 | // Call runtime on identical JSObjects. |
| 293 | __ Branch(slow, greater, t4, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 294 | // Call runtime on identical symbols since we need to throw a TypeError. |
| 295 | __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE)); |
| 296 | // Call runtime on identical SIMD values since we must throw a TypeError. |
| 297 | __ Branch(slow, eq, t4, Operand(SIMD128_VALUE_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 298 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 299 | __ Branch(&heap_number, eq, t4, Operand(HEAP_NUMBER_TYPE)); |
| 300 | // Comparing JS objects with <=, >= is complicated. |
| 301 | if (cc != eq) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 302 | __ Branch(slow, greater, t4, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 303 | // Call runtime on identical symbols since we need to throw a TypeError. |
| 304 | __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE)); |
| 305 | // Call runtime on identical SIMD values since we must throw a TypeError. |
| 306 | __ Branch(slow, eq, t4, Operand(SIMD128_VALUE_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 307 | // Normally here we fall through to return_equal, but undefined is |
| 308 | // special: (undefined == undefined) == true, but |
| 309 | // (undefined <= undefined) == false! See ECMAScript 11.8.5. |
| 310 | if (cc == less_equal || cc == greater_equal) { |
| 311 | __ Branch(&return_equal, ne, t4, Operand(ODDBALL_TYPE)); |
| 312 | __ LoadRoot(t2, Heap::kUndefinedValueRootIndex); |
| 313 | __ Branch(&return_equal, ne, a0, Operand(t2)); |
| 314 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 315 | __ Ret(USE_DELAY_SLOT); |
| 316 | if (cc == le) { |
| 317 | // undefined <= undefined should fail. |
| 318 | __ li(v0, Operand(GREATER)); |
| 319 | } else { |
| 320 | // undefined >= undefined should fail. |
| 321 | __ li(v0, Operand(LESS)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | __ bind(&return_equal); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 328 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 329 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 330 | if (cc == less) { |
| 331 | __ li(v0, Operand(GREATER)); // Things aren't less than themselves. |
| 332 | } else if (cc == greater) { |
| 333 | __ li(v0, Operand(LESS)); // Things aren't greater than themselves. |
| 334 | } else { |
| 335 | __ mov(v0, zero_reg); // Things are <=, >=, ==, === themselves. |
| 336 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 337 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 338 | // For less and greater we don't have to check for NaN since the result of |
| 339 | // x < x is false regardless. For the others here is some code to check |
| 340 | // for NaN. |
| 341 | if (cc != lt && cc != gt) { |
| 342 | __ bind(&heap_number); |
| 343 | // It is a heap number, so return non-equal if it's NaN and equal if it's |
| 344 | // not NaN. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 345 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 346 | // The representation of NaN values has all exponent bits (52..62) set, |
| 347 | // and not all mantissa bits (0..51) clear. |
| 348 | // Read top bits of double representation (second word of value). |
| 349 | __ lw(t2, FieldMemOperand(a0, HeapNumber::kExponentOffset)); |
| 350 | // Test that exponent bits are all set. |
| 351 | __ And(t3, t2, Operand(exp_mask_reg)); |
| 352 | // If all bits not set (ne cond), then not a NaN, objects are equal. |
| 353 | __ Branch(&return_equal, ne, t3, Operand(exp_mask_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 354 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 355 | // Shift out flag and all exponent bits, retaining only mantissa. |
| 356 | __ sll(t2, t2, HeapNumber::kNonMantissaBitsInTopWord); |
| 357 | // Or with all low-bits of mantissa. |
| 358 | __ lw(t3, FieldMemOperand(a0, HeapNumber::kMantissaOffset)); |
| 359 | __ Or(v0, t3, Operand(t2)); |
| 360 | // For equal we already have the right value in v0: Return zero (equal) |
| 361 | // if all bits in mantissa are zero (it's an Infinity) and non-zero if |
| 362 | // not (it's a NaN). For <= and >= we need to load v0 with the failing |
| 363 | // value if it's a NaN. |
| 364 | if (cc != eq) { |
| 365 | // All-zero means Infinity means equal. |
| 366 | __ Ret(eq, v0, Operand(zero_reg)); |
| 367 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 368 | __ Ret(USE_DELAY_SLOT); |
| 369 | if (cc == le) { |
| 370 | __ li(v0, Operand(GREATER)); // NaN <= NaN should fail. |
| 371 | } else { |
| 372 | __ li(v0, Operand(LESS)); // NaN >= NaN should fail. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 373 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 374 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 375 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 376 | // No fall through here. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 377 | |
| 378 | __ bind(¬_identical); |
| 379 | } |
| 380 | |
| 381 | |
| 382 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 383 | Register lhs, |
| 384 | Register rhs, |
| 385 | Label* both_loaded_as_doubles, |
| 386 | Label* slow, |
| 387 | bool strict) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 388 | DCHECK((lhs.is(a0) && rhs.is(a1)) || |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 389 | (lhs.is(a1) && rhs.is(a0))); |
| 390 | |
| 391 | Label lhs_is_smi; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 392 | __ JumpIfSmi(lhs, &lhs_is_smi); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 393 | // Rhs is a Smi. |
| 394 | // Check whether the non-smi is a heap number. |
| 395 | __ GetObjectType(lhs, t4, t4); |
| 396 | if (strict) { |
| 397 | // If lhs was not a number and rhs was a Smi then strict equality cannot |
| 398 | // succeed. Return non-equal (lhs is already not zero). |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 399 | __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 400 | __ mov(v0, lhs); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 401 | } else { |
| 402 | // Smi compared non-strictly with a non-Smi non-heap-number. Call |
| 403 | // the runtime. |
| 404 | __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE)); |
| 405 | } |
| 406 | |
| 407 | // Rhs is a smi, lhs is a number. |
| 408 | // Convert smi rhs to double. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 409 | __ sra(at, rhs, kSmiTagSize); |
| 410 | __ mtc1(at, f14); |
| 411 | __ cvt_d_w(f14, f14); |
| 412 | __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 413 | |
| 414 | // We now have both loaded as doubles. |
| 415 | __ jmp(both_loaded_as_doubles); |
| 416 | |
| 417 | __ bind(&lhs_is_smi); |
| 418 | // Lhs is a Smi. Check whether the non-smi is a heap number. |
| 419 | __ GetObjectType(rhs, t4, t4); |
| 420 | if (strict) { |
| 421 | // If lhs was not a number and rhs was a Smi then strict equality cannot |
| 422 | // succeed. Return non-equal. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 423 | __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 424 | __ li(v0, Operand(1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 425 | } else { |
| 426 | // Smi compared non-strictly with a non-Smi non-heap-number. Call |
| 427 | // the runtime. |
| 428 | __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE)); |
| 429 | } |
| 430 | |
| 431 | // Lhs is a smi, rhs is a number. |
| 432 | // Convert smi lhs to double. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 433 | __ sra(at, lhs, kSmiTagSize); |
| 434 | __ mtc1(at, f12); |
| 435 | __ cvt_d_w(f12, f12); |
| 436 | __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 437 | // Fall through to both_loaded_as_doubles. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 441 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 442 | Register lhs, |
| 443 | Register rhs) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 444 | // 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] | 445 | // not equal since their pointers are different. |
| 446 | // There is no test for undetectability in strict equality. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 447 | STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 448 | Label first_non_object; |
| 449 | // 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] | 450 | // FIRST_JS_RECEIVER_TYPE. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 451 | __ GetObjectType(lhs, a2, a2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 452 | __ Branch(&first_non_object, less, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 453 | |
| 454 | // Return non-zero. |
| 455 | Label return_not_equal; |
| 456 | __ bind(&return_not_equal); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 457 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 458 | __ li(v0, Operand(1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 459 | |
| 460 | __ bind(&first_non_object); |
| 461 | // Check for oddballs: true, false, null, undefined. |
| 462 | __ Branch(&return_not_equal, eq, a2, Operand(ODDBALL_TYPE)); |
| 463 | |
| 464 | __ GetObjectType(rhs, a3, a3); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 465 | __ Branch(&return_not_equal, greater, a3, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 466 | |
| 467 | // Check for oddballs: true, false, null, undefined. |
| 468 | __ Branch(&return_not_equal, eq, a3, Operand(ODDBALL_TYPE)); |
| 469 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 470 | // Now that we have the types we might as well check for |
| 471 | // internalized-internalized. |
| 472 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 473 | __ Or(a2, a2, Operand(a3)); |
| 474 | __ And(at, a2, Operand(kIsNotStringMask | kIsNotInternalizedMask)); |
| 475 | __ Branch(&return_not_equal, eq, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | |
| 479 | static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm, |
| 480 | Register lhs, |
| 481 | Register rhs, |
| 482 | Label* both_loaded_as_doubles, |
| 483 | Label* not_heap_numbers, |
| 484 | Label* slow) { |
| 485 | __ GetObjectType(lhs, a3, a2); |
| 486 | __ Branch(not_heap_numbers, ne, a2, Operand(HEAP_NUMBER_TYPE)); |
| 487 | __ lw(a2, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 488 | // If first was a heap number & second wasn't, go to slow case. |
| 489 | __ Branch(slow, ne, a3, Operand(a2)); |
| 490 | |
| 491 | // Both are heap numbers. Load them up then jump to the code we have |
| 492 | // for that. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 493 | __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 494 | __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 495 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 496 | __ jmp(both_loaded_as_doubles); |
| 497 | } |
| 498 | |
| 499 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 500 | // Fast negative check for internalized-to-internalized equality. |
| 501 | static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 502 | Register lhs, Register rhs, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 503 | Label* possible_strings, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 504 | Label* runtime_call) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 505 | DCHECK((lhs.is(a0) && rhs.is(a1)) || |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 506 | (lhs.is(a1) && rhs.is(a0))); |
| 507 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 508 | // a2 is object type of rhs. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 509 | Label object_test, return_unequal, undetectable; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 510 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 511 | __ And(at, a2, Operand(kIsNotStringMask)); |
| 512 | __ Branch(&object_test, ne, at, Operand(zero_reg)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 513 | __ And(at, a2, Operand(kIsNotInternalizedMask)); |
| 514 | __ Branch(possible_strings, ne, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 515 | __ GetObjectType(rhs, a3, a3); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 516 | __ Branch(runtime_call, ge, a3, Operand(FIRST_NONSTRING_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 517 | __ And(at, a3, Operand(kIsNotInternalizedMask)); |
| 518 | __ Branch(possible_strings, ne, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 519 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 520 | // Both are internalized. We already checked they weren't the same pointer so |
| 521 | // they are not equal. Return non-equal by returning the non-zero object |
| 522 | // pointer in v0. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 523 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 524 | __ mov(v0, a0); // In delay slot. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 525 | |
| 526 | __ bind(&object_test); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 527 | __ lw(a2, FieldMemOperand(lhs, HeapObject::kMapOffset)); |
| 528 | __ lw(a3, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 529 | __ lbu(t0, FieldMemOperand(a2, Map::kBitFieldOffset)); |
| 530 | __ lbu(t1, FieldMemOperand(a3, Map::kBitFieldOffset)); |
| 531 | __ And(at, t0, Operand(1 << Map::kIsUndetectable)); |
| 532 | __ Branch(&undetectable, ne, at, Operand(zero_reg)); |
| 533 | __ And(at, t1, Operand(1 << Map::kIsUndetectable)); |
| 534 | __ Branch(&return_unequal, ne, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 535 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 536 | __ GetInstanceType(a2, a2); |
| 537 | __ Branch(runtime_call, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 538 | __ GetInstanceType(a3, a3); |
| 539 | __ Branch(runtime_call, lt, a3, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 540 | |
| 541 | __ bind(&return_unequal); |
| 542 | // Return non-equal by returning the non-zero object pointer in v0. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 543 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 544 | __ mov(v0, a0); // In delay slot. |
| 545 | |
| 546 | __ bind(&undetectable); |
| 547 | __ And(at, t1, Operand(1 << Map::kIsUndetectable)); |
| 548 | __ Branch(&return_unequal, eq, at, Operand(zero_reg)); |
| 549 | __ Ret(USE_DELAY_SLOT); |
| 550 | __ li(v0, Operand(EQUAL)); // In delay slot. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 554 | static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input, |
| 555 | Register scratch, |
| 556 | CompareICState::State expected, |
| 557 | Label* fail) { |
| 558 | Label ok; |
| 559 | if (expected == CompareICState::SMI) { |
| 560 | __ JumpIfNotSmi(input, fail); |
| 561 | } else if (expected == CompareICState::NUMBER) { |
| 562 | __ JumpIfSmi(input, &ok); |
| 563 | __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail, |
| 564 | DONT_DO_SMI_CHECK); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 565 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 566 | // We could be strict about internalized/string here, but as long as |
| 567 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 568 | __ bind(&ok); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 572 | // On entry a1 and a2 are the values to be compared. |
| 573 | // On exit a0 is 0, positive or negative to indicate the result of |
| 574 | // the comparison. |
| 575 | void CompareICStub::GenerateGeneric(MacroAssembler* masm) { |
| 576 | Register lhs = a1; |
| 577 | Register rhs = a0; |
| 578 | Condition cc = GetCondition(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 579 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 580 | Label miss; |
| 581 | CompareICStub_CheckInputType(masm, lhs, a2, left(), &miss); |
| 582 | CompareICStub_CheckInputType(masm, rhs, a3, right(), &miss); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 583 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 584 | Label slow; // Call builtin. |
| 585 | Label not_smis, both_loaded_as_doubles; |
| 586 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 587 | Label not_two_smis, smi_done; |
| 588 | __ Or(a2, a1, a0); |
| 589 | __ JumpIfNotSmi(a2, ¬_two_smis); |
| 590 | __ sra(a1, a1, 1); |
| 591 | __ sra(a0, a0, 1); |
| 592 | __ Ret(USE_DELAY_SLOT); |
| 593 | __ subu(v0, a1, a0); |
| 594 | __ bind(¬_two_smis); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 595 | |
| 596 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 597 | // it is certain that at least one operand isn't a smi. |
| 598 | |
| 599 | // Handle the case where the objects are identical. Either returns the answer |
| 600 | // 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^] | 601 | EmitIdenticalObjectComparison(masm, &slow, cc); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 602 | |
| 603 | // If either is a Smi (we know that not both are), then they can only |
| 604 | // be strictly equal if the other is a HeapNumber. |
| 605 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 606 | DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 607 | __ And(t2, lhs, Operand(rhs)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 608 | __ JumpIfNotSmi(t2, ¬_smis, t0); |
| 609 | // One operand is a smi. EmitSmiNonsmiComparison generates code that can: |
| 610 | // 1) Return the answer. |
| 611 | // 2) Go to slow. |
| 612 | // 3) Fall through to both_loaded_as_doubles. |
| 613 | // 4) Jump to rhs_not_nan. |
| 614 | // In cases 3 and 4 we have found out we were dealing with a number-number |
| 615 | // comparison and the numbers have been loaded into f12 and f14 as doubles, |
| 616 | // 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] | 617 | EmitSmiNonsmiComparison(masm, lhs, rhs, |
| 618 | &both_loaded_as_doubles, &slow, strict()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 619 | |
| 620 | __ bind(&both_loaded_as_doubles); |
| 621 | // f12, f14 are the double representations of the left hand side |
| 622 | // and the right hand side if we have FPU. Otherwise a2, a3 represent |
| 623 | // left hand side and a0, a1 represent right hand side. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 624 | Label nan; |
| 625 | __ li(t0, Operand(LESS)); |
| 626 | __ li(t1, Operand(GREATER)); |
| 627 | __ li(t2, Operand(EQUAL)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 628 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 629 | // Check if either rhs or lhs is NaN. |
| 630 | __ BranchF(NULL, &nan, eq, f12, f14); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 631 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 632 | // Check if LESS condition is satisfied. If true, move conditionally |
| 633 | // result to v0. |
| 634 | if (!IsMipsArchVariant(kMips32r6)) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 635 | __ c(OLT, D, f12, f14); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 636 | __ Movt(v0, t0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 637 | // Use previous check to store conditionally to v0 oposite condition |
| 638 | // (GREATER). If rhs is equal to lhs, this will be corrected in next |
| 639 | // check. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 640 | __ Movf(v0, t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 641 | // Check if EQUAL condition is satisfied. If true, move conditionally |
| 642 | // result to v0. |
| 643 | __ c(EQ, D, f12, f14); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 644 | __ Movt(v0, t2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 645 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 646 | Label skip; |
| 647 | __ BranchF(USE_DELAY_SLOT, &skip, NULL, lt, f12, f14); |
| 648 | __ mov(v0, t0); // Return LESS as result. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 649 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 650 | __ BranchF(USE_DELAY_SLOT, &skip, NULL, eq, f12, f14); |
| 651 | __ mov(v0, t2); // Return EQUAL as result. |
| 652 | |
| 653 | __ mov(v0, t1); // Return GREATER as result. |
| 654 | __ bind(&skip); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 655 | } |
| 656 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 657 | __ Ret(); |
| 658 | |
| 659 | __ bind(&nan); |
| 660 | // NaN comparisons always fail. |
| 661 | // Load whatever we need in v0 to make the comparison fail. |
| 662 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 663 | __ Ret(USE_DELAY_SLOT); |
| 664 | if (cc == lt || cc == le) { |
| 665 | __ li(v0, Operand(GREATER)); |
| 666 | } else { |
| 667 | __ li(v0, Operand(LESS)); |
| 668 | } |
| 669 | |
| 670 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 671 | __ bind(¬_smis); |
| 672 | // At this point we know we are dealing with two different objects, |
| 673 | // 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] | 674 | if (strict()) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 675 | // This returns non-equal for some object types, or falls through if it |
| 676 | // was not lucky. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 677 | EmitStrictTwoHeapObjectCompare(masm, lhs, rhs); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 680 | Label check_for_internalized_strings; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 681 | Label flat_string_check; |
| 682 | // Check for heap-number-heap-number comparison. Can jump to slow case, |
| 683 | // or load both doubles and jump to the code that handles |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 684 | // that case. If the inputs are not doubles then jumps to |
| 685 | // check_for_internalized_strings. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 686 | // In this case a2 will contain the type of lhs_. |
| 687 | EmitCheckForTwoHeapNumbers(masm, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 688 | lhs, |
| 689 | rhs, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 690 | &both_loaded_as_doubles, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 691 | &check_for_internalized_strings, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 692 | &flat_string_check); |
| 693 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 694 | __ bind(&check_for_internalized_strings); |
| 695 | if (cc == eq && !strict()) { |
| 696 | // Returns an answer for two internalized strings or two |
| 697 | // detectable objects. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 698 | // Otherwise jumps to string case or not both strings case. |
| 699 | // Assumes that a2 is the type of lhs_ on entry. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 700 | EmitCheckForInternalizedStringsOrObjects( |
| 701 | masm, lhs, rhs, &flat_string_check, &slow); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 704 | // Check for both being sequential one-byte strings, |
| 705 | // and inline if that is the case. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 706 | __ bind(&flat_string_check); |
| 707 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 708 | __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, a2, a3, &slow); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 709 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 710 | __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2, |
| 711 | a3); |
| 712 | if (cc == eq) { |
| 713 | StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, a2, a3, t0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 714 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 715 | StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, a2, a3, t0, |
| 716 | t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 717 | } |
| 718 | // Never falls through to here. |
| 719 | |
| 720 | __ bind(&slow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 721 | if (cc == eq) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 722 | { |
| 723 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 724 | __ Push(lhs, rhs); |
| 725 | __ CallRuntime(strict() ? Runtime::kStrictEqual : Runtime::kEqual); |
| 726 | } |
| 727 | // Turn true into 0 and false into some non-zero value. |
| 728 | STATIC_ASSERT(EQUAL == 0); |
| 729 | __ LoadRoot(a0, Heap::kTrueValueRootIndex); |
| 730 | __ Ret(USE_DELAY_SLOT); |
| 731 | __ subu(v0, v0, a0); // In delay slot. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 732 | } else { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 733 | // Prepare for call to builtin. Push object pointers, a0 (lhs) first, |
| 734 | // a1 (rhs) second. |
| 735 | __ Push(lhs, rhs); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 736 | int ncr; // NaN compare result. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 737 | if (cc == lt || cc == le) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 738 | ncr = GREATER; |
| 739 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 740 | DCHECK(cc == gt || cc == ge); // Remaining cases. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 741 | ncr = LESS; |
| 742 | } |
| 743 | __ li(a0, Operand(Smi::FromInt(ncr))); |
| 744 | __ push(a0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 745 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 746 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 747 | // tagged as a small integer. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 748 | __ TailCallRuntime(Runtime::kCompare); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 749 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 750 | |
| 751 | __ bind(&miss); |
| 752 | GenerateMiss(masm); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 756 | void StoreRegistersStateStub::Generate(MacroAssembler* masm) { |
| 757 | __ mov(t9, ra); |
| 758 | __ pop(ra); |
| 759 | __ PushSafepointRegisters(); |
| 760 | __ Jump(t9); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 761 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 762 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 763 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 764 | void RestoreRegistersStateStub::Generate(MacroAssembler* masm) { |
| 765 | __ mov(t9, ra); |
| 766 | __ pop(ra); |
| 767 | __ PopSafepointRegisters(); |
| 768 | __ Jump(t9); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | |
| 772 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 773 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 774 | // store the registers in any particular way, but we do have to store and |
| 775 | // restore them. |
| 776 | __ MultiPush(kJSCallerSaved | ra.bit()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 777 | if (save_doubles()) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 778 | __ MultiPushFPU(kCallerSavedFPU); |
| 779 | } |
| 780 | const int argument_count = 1; |
| 781 | const int fp_argument_count = 0; |
| 782 | const Register scratch = a1; |
| 783 | |
| 784 | AllowExternalCallThatCantCauseGC scope(masm); |
| 785 | __ PrepareCallCFunction(argument_count, fp_argument_count, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 786 | __ li(a0, Operand(ExternalReference::isolate_address(isolate()))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 787 | __ CallCFunction( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 788 | ExternalReference::store_buffer_overflow_function(isolate()), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 789 | argument_count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 790 | if (save_doubles()) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 791 | __ MultiPopFPU(kCallerSavedFPU); |
| 792 | } |
| 793 | |
| 794 | __ MultiPop(kJSCallerSaved | ra.bit()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 795 | __ Ret(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 799 | void MathPowStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 800 | const Register base = a1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 801 | const Register exponent = MathPowTaggedDescriptor::exponent(); |
| 802 | DCHECK(exponent.is(a2)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 803 | const Register heapnumbermap = t1; |
| 804 | const Register heapnumber = v0; |
| 805 | const DoubleRegister double_base = f2; |
| 806 | const DoubleRegister double_exponent = f4; |
| 807 | const DoubleRegister double_result = f0; |
| 808 | const DoubleRegister double_scratch = f6; |
| 809 | const FPURegister single_scratch = f8; |
| 810 | const Register scratch = t5; |
| 811 | const Register scratch2 = t3; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 812 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 813 | Label call_runtime, done, int_exponent; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 814 | if (exponent_type() == ON_STACK) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 815 | Label base_is_smi, unpack_exponent; |
| 816 | // The exponent and base are supplied as arguments on the stack. |
| 817 | // This can only happen if the stub is called from non-optimized code. |
| 818 | // Load input parameters from stack to double registers. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 819 | __ lw(base, MemOperand(sp, 1 * kPointerSize)); |
| 820 | __ lw(exponent, MemOperand(sp, 0 * kPointerSize)); |
| 821 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 822 | __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 823 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 824 | __ UntagAndJumpIfSmi(scratch, base, &base_is_smi); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 825 | __ lw(scratch, FieldMemOperand(base, JSObject::kMapOffset)); |
| 826 | __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 827 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 828 | __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 829 | __ jmp(&unpack_exponent); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 830 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 831 | __ bind(&base_is_smi); |
| 832 | __ mtc1(scratch, single_scratch); |
| 833 | __ cvt_d_w(double_base, single_scratch); |
| 834 | __ bind(&unpack_exponent); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 835 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 836 | __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent); |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 837 | |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 838 | __ lw(scratch, FieldMemOperand(exponent, JSObject::kMapOffset)); |
| 839 | __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap)); |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 840 | __ ldc1(double_exponent, |
| 841 | FieldMemOperand(exponent, HeapNumber::kValueOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 842 | } else if (exponent_type() == TAGGED) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 843 | // Base is already in double_base. |
| 844 | __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent); |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 845 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 846 | __ ldc1(double_exponent, |
| 847 | FieldMemOperand(exponent, HeapNumber::kValueOffset)); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 848 | } |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 849 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 850 | if (exponent_type() != INTEGER) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 851 | Label int_exponent_convert; |
| 852 | // Detect integer exponents stored as double. |
| 853 | __ EmitFPUTruncate(kRoundToMinusInf, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 854 | scratch, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 855 | double_exponent, |
| 856 | at, |
| 857 | double_scratch, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 858 | scratch2, |
| 859 | kCheckForInexactConversion); |
| 860 | // scratch2 == 0 means there was no conversion error. |
| 861 | __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg)); |
| 862 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 863 | if (exponent_type() == ON_STACK) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 864 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 865 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 866 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 867 | Label not_plus_half; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 868 | // Test for 0.5. |
| 869 | __ Move(double_scratch, 0.5); |
| 870 | __ BranchF(USE_DELAY_SLOT, |
| 871 | ¬_plus_half, |
| 872 | NULL, |
| 873 | ne, |
| 874 | double_exponent, |
| 875 | double_scratch); |
| 876 | // double_scratch can be overwritten in the delay slot. |
| 877 | // Calculates square root of base. Check for the special case of |
| 878 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 879 | __ Move(double_scratch, static_cast<double>(-V8_INFINITY)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 880 | __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch); |
| 881 | __ neg_d(double_result, double_scratch); |
| 882 | |
| 883 | // Add +0 to convert -0 to +0. |
| 884 | __ add_d(double_scratch, double_base, kDoubleRegZero); |
| 885 | __ sqrt_d(double_result, double_scratch); |
| 886 | __ jmp(&done); |
| 887 | |
| 888 | __ bind(¬_plus_half); |
| 889 | __ Move(double_scratch, -0.5); |
| 890 | __ BranchF(USE_DELAY_SLOT, |
| 891 | &call_runtime, |
| 892 | NULL, |
| 893 | ne, |
| 894 | double_exponent, |
| 895 | double_scratch); |
| 896 | // double_scratch can be overwritten in the delay slot. |
| 897 | // Calculates square root of base. Check for the special case of |
| 898 | // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 899 | __ Move(double_scratch, static_cast<double>(-V8_INFINITY)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 900 | __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch); |
| 901 | __ Move(double_result, kDoubleRegZero); |
| 902 | |
| 903 | // Add +0 to convert -0 to +0. |
| 904 | __ add_d(double_scratch, double_base, kDoubleRegZero); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 905 | __ Move(double_result, 1.); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 906 | __ sqrt_d(double_scratch, double_scratch); |
| 907 | __ div_d(double_result, double_result, double_scratch); |
| 908 | __ jmp(&done); |
| 909 | } |
| 910 | |
| 911 | __ push(ra); |
| 912 | { |
| 913 | AllowExternalCallThatCantCauseGC scope(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 914 | __ PrepareCallCFunction(0, 2, scratch2); |
| 915 | __ MovToFloatParameters(double_base, double_exponent); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 916 | __ CallCFunction( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 917 | ExternalReference::power_double_double_function(isolate()), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 918 | 0, 2); |
| 919 | } |
| 920 | __ pop(ra); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 921 | __ MovFromFloatResult(double_result); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 922 | __ jmp(&done); |
| 923 | |
| 924 | __ bind(&int_exponent_convert); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | // Calculate power with integer exponent. |
| 928 | __ bind(&int_exponent); |
| 929 | |
| 930 | // Get two copies of exponent in the registers scratch and exponent. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 931 | if (exponent_type() == INTEGER) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 932 | __ mov(scratch, exponent); |
| 933 | } else { |
| 934 | // Exponent has previously been stored into scratch as untagged integer. |
| 935 | __ mov(exponent, scratch); |
| 936 | } |
| 937 | |
| 938 | __ mov_d(double_scratch, double_base); // Back up base. |
| 939 | __ Move(double_result, 1.0); |
| 940 | |
| 941 | // Get absolute value of exponent. |
| 942 | Label positive_exponent; |
| 943 | __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg)); |
| 944 | __ Subu(scratch, zero_reg, scratch); |
| 945 | __ bind(&positive_exponent); |
| 946 | |
| 947 | Label while_true, no_carry, loop_end; |
| 948 | __ bind(&while_true); |
| 949 | |
| 950 | __ And(scratch2, scratch, 1); |
| 951 | |
| 952 | __ Branch(&no_carry, eq, scratch2, Operand(zero_reg)); |
| 953 | __ mul_d(double_result, double_result, double_scratch); |
| 954 | __ bind(&no_carry); |
| 955 | |
| 956 | __ sra(scratch, scratch, 1); |
| 957 | |
| 958 | __ Branch(&loop_end, eq, scratch, Operand(zero_reg)); |
| 959 | __ mul_d(double_scratch, double_scratch, double_scratch); |
| 960 | |
| 961 | __ Branch(&while_true); |
| 962 | |
| 963 | __ bind(&loop_end); |
| 964 | |
| 965 | __ Branch(&done, ge, exponent, Operand(zero_reg)); |
| 966 | __ Move(double_scratch, 1.0); |
| 967 | __ div_d(double_result, double_scratch, double_result); |
| 968 | // Test whether result is zero. Bail out to check for subnormal result. |
| 969 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 970 | __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero); |
| 971 | |
| 972 | // double_exponent may not contain the exponent value if the input was a |
| 973 | // smi. We set it with exponent value before bailing out. |
| 974 | __ mtc1(exponent, single_scratch); |
| 975 | __ cvt_d_w(double_exponent, single_scratch); |
| 976 | |
| 977 | // Returning or bailing out. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 978 | if (exponent_type() == ON_STACK) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 979 | // The arguments are still on the stack. |
| 980 | __ bind(&call_runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 981 | __ TailCallRuntime(Runtime::kMathPowRT); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 982 | |
| 983 | // The stub is called from non-optimized code, which expects the result |
| 984 | // as heap number in exponent. |
| 985 | __ bind(&done); |
| 986 | __ AllocateHeapNumber( |
| 987 | heapnumber, scratch, scratch2, heapnumbermap, &call_runtime); |
| 988 | __ sdc1(double_result, |
| 989 | FieldMemOperand(heapnumber, HeapNumber::kValueOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 990 | DCHECK(heapnumber.is(v0)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 991 | __ DropAndRet(2); |
| 992 | } else { |
| 993 | __ push(ra); |
| 994 | { |
| 995 | AllowExternalCallThatCantCauseGC scope(masm); |
| 996 | __ PrepareCallCFunction(0, 2, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 997 | __ MovToFloatParameters(double_base, double_exponent); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 998 | __ CallCFunction( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 999 | ExternalReference::power_double_double_function(isolate()), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1000 | 0, 2); |
| 1001 | } |
| 1002 | __ pop(ra); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1003 | __ MovFromFloatResult(double_result); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1004 | |
| 1005 | __ bind(&done); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1006 | __ Ret(); |
| 1007 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | |
| 1011 | bool CEntryStub::NeedsImmovableCode() { |
| 1012 | return true; |
| 1013 | } |
| 1014 | |
| 1015 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1016 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 1017 | CEntryStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1018 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
| 1019 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
| 1020 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
| 1021 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1022 | CreateWeakCellStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1023 | BinaryOpICStub::GenerateAheadOfTime(isolate); |
| 1024 | StoreRegistersStateStub::GenerateAheadOfTime(isolate); |
| 1025 | RestoreRegistersStateStub::GenerateAheadOfTime(isolate); |
| 1026 | BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1027 | StoreFastElementStub::GenerateAheadOfTime(isolate); |
| 1028 | TypeofStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1032 | void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) { |
| 1033 | StoreRegistersStateStub stub(isolate); |
| 1034 | stub.GetCode(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1038 | void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) { |
| 1039 | RestoreRegistersStateStub stub(isolate); |
| 1040 | stub.GetCode(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1044 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
| 1045 | // Generate if not already in cache. |
| 1046 | SaveFPRegsMode mode = kSaveFPRegs; |
| 1047 | CEntryStub(isolate, 1, mode).GetCode(); |
| 1048 | StoreBufferOverflowStub(isolate, mode).GetCode(); |
| 1049 | isolate->set_fp_stubs_generated(true); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1053 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
| 1054 | CEntryStub stub(isolate, 1, kDontSaveFPRegs); |
| 1055 | stub.GetCode(); |
| 1056 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1057 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1058 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1059 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 1060 | // Called from JavaScript; parameters are on stack as if calling JS function |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1061 | // a0: number of arguments including receiver |
| 1062 | // a1: pointer to builtin function |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1063 | // fp: frame pointer (restored after C call) |
| 1064 | // sp: stack pointer (restored as callee's sp after C call) |
| 1065 | // cp: current context (C callee-saved) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1066 | // |
| 1067 | // If argv_in_register(): |
| 1068 | // a2: pointer to the first argument |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1069 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1070 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 1071 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1072 | if (argv_in_register()) { |
| 1073 | // Move argv into the correct register. |
| 1074 | __ mov(s1, a2); |
| 1075 | } else { |
| 1076 | // Compute the argv pointer in a callee-saved register. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1077 | __ Lsa(s1, sp, a0, kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1078 | __ Subu(s1, s1, kPointerSize); |
| 1079 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1080 | |
| 1081 | // Enter the exit frame that transitions from JavaScript to C++. |
| 1082 | FrameScope scope(masm, StackFrame::MANUAL); |
| 1083 | __ EnterExitFrame(save_doubles()); |
| 1084 | |
| 1085 | // s0: number of arguments including receiver (C callee-saved) |
| 1086 | // s1: pointer to first argument (C callee-saved) |
| 1087 | // s2: pointer to builtin function (C callee-saved) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1088 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1089 | // Prepare arguments for C routine. |
| 1090 | // a0 = argc |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1091 | __ mov(s0, a0); |
| 1092 | __ mov(s2, a1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1093 | |
| 1094 | // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We |
| 1095 | // also need to reserve the 4 argument slots on the stack. |
| 1096 | |
| 1097 | __ AssertStackIsAligned(); |
| 1098 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1099 | int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
| 1100 | int frame_alignment_mask = frame_alignment - 1; |
| 1101 | int result_stack_size; |
| 1102 | if (result_size() <= 2) { |
| 1103 | // a0 = argc, a1 = argv, a2 = isolate |
| 1104 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
| 1105 | __ mov(a1, s1); |
| 1106 | result_stack_size = 0; |
| 1107 | } else { |
| 1108 | DCHECK_EQ(3, result_size()); |
| 1109 | // Allocate additional space for the result. |
| 1110 | result_stack_size = |
| 1111 | ((result_size() * kPointerSize) + frame_alignment_mask) & |
| 1112 | ~frame_alignment_mask; |
| 1113 | __ Subu(sp, sp, Operand(result_stack_size)); |
| 1114 | |
| 1115 | // a0 = hidden result argument, a1 = argc, a2 = argv, a3 = isolate. |
| 1116 | __ li(a3, Operand(ExternalReference::isolate_address(isolate()))); |
| 1117 | __ mov(a2, s1); |
| 1118 | __ mov(a1, a0); |
| 1119 | __ mov(a0, sp); |
| 1120 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1121 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1122 | // To let the GC traverse the return address of the exit frames, we need to |
| 1123 | // know where the return address is. The CEntryStub is unmovable, so |
| 1124 | // we can store the address on the stack to be able to find it again and |
| 1125 | // we never have to restore it, because it will not change. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1126 | { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1127 | int kNumInstructionsToJump = 4; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1128 | Label find_ra; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1129 | // Adjust the value in ra to point to the correct return location, 2nd |
| 1130 | // instruction past the real call into C code (the jalr(t9)), and push it. |
| 1131 | // This is the return address of the exit frame. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1132 | if (kArchVariant >= kMips32r6) { |
| 1133 | __ addiupc(ra, kNumInstructionsToJump + 1); |
| 1134 | } else { |
| 1135 | // This branch-and-link sequence is needed to find the current PC on mips |
| 1136 | // before r6, saved to the ra register. |
| 1137 | __ bal(&find_ra); // bal exposes branch delay slot. |
| 1138 | __ Addu(ra, ra, kNumInstructionsToJump * Instruction::kInstrSize); |
| 1139 | } |
| 1140 | __ bind(&find_ra); |
| 1141 | |
| 1142 | // This spot was reserved in EnterExitFrame. |
| 1143 | __ sw(ra, MemOperand(sp, result_stack_size)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1144 | // Stack space reservation moved to the branch delay slot below. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1145 | // Stack is still aligned. |
| 1146 | |
| 1147 | // Call the C routine. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1148 | __ mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC. |
| 1149 | __ jalr(t9); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1150 | // Set up sp in the delay slot. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1151 | __ addiu(sp, sp, -kCArgsSlotsSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1152 | // Make sure the stored 'ra' points to this position. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1153 | DCHECK_EQ(kNumInstructionsToJump, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1154 | masm->InstructionsGeneratedSince(&find_ra)); |
| 1155 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1156 | if (result_size() > 2) { |
| 1157 | DCHECK_EQ(3, result_size()); |
| 1158 | // Read result values stored on stack. |
| 1159 | __ lw(a0, MemOperand(v0, 2 * kPointerSize)); |
| 1160 | __ lw(v1, MemOperand(v0, 1 * kPointerSize)); |
| 1161 | __ lw(v0, MemOperand(v0, 0 * kPointerSize)); |
| 1162 | } |
| 1163 | // 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] | 1164 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1165 | // Check result for exception sentinel. |
| 1166 | Label exception_returned; |
| 1167 | __ LoadRoot(t0, Heap::kExceptionRootIndex); |
| 1168 | __ Branch(&exception_returned, eq, t0, Operand(v0)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1169 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1170 | // Check that there is no pending exception, otherwise we |
| 1171 | // should have returned the exception sentinel. |
| 1172 | if (FLAG_debug_code) { |
| 1173 | Label okay; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1174 | ExternalReference pending_exception_address( |
| 1175 | Isolate::kPendingExceptionAddress, isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1176 | __ li(a2, Operand(pending_exception_address)); |
| 1177 | __ lw(a2, MemOperand(a2)); |
| 1178 | __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); |
| 1179 | // Cannot use check here as it attempts to generate call into runtime. |
| 1180 | __ Branch(&okay, eq, t0, Operand(a2)); |
| 1181 | __ stop("Unexpected pending exception"); |
| 1182 | __ bind(&okay); |
| 1183 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1184 | |
| 1185 | // Exit C frame and return. |
| 1186 | // v0:v1: result |
| 1187 | // sp: stack pointer |
| 1188 | // fp: frame pointer |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1189 | Register argc; |
| 1190 | if (argv_in_register()) { |
| 1191 | // We don't want to pop arguments so set argc to no_reg. |
| 1192 | argc = no_reg; |
| 1193 | } else { |
| 1194 | // s0: still holds argc (callee-saved). |
| 1195 | argc = s0; |
| 1196 | } |
| 1197 | __ LeaveExitFrame(save_doubles(), argc, true, EMIT_RETURN); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1198 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1199 | // Handling of exception. |
| 1200 | __ bind(&exception_returned); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1201 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1202 | ExternalReference pending_handler_context_address( |
| 1203 | Isolate::kPendingHandlerContextAddress, isolate()); |
| 1204 | ExternalReference pending_handler_code_address( |
| 1205 | Isolate::kPendingHandlerCodeAddress, isolate()); |
| 1206 | ExternalReference pending_handler_offset_address( |
| 1207 | Isolate::kPendingHandlerOffsetAddress, isolate()); |
| 1208 | ExternalReference pending_handler_fp_address( |
| 1209 | Isolate::kPendingHandlerFPAddress, isolate()); |
| 1210 | ExternalReference pending_handler_sp_address( |
| 1211 | Isolate::kPendingHandlerSPAddress, isolate()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1212 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1213 | // Ask the runtime for help to determine the handler. This will set v0 to |
| 1214 | // contain the current pending exception, don't clobber it. |
| 1215 | ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler, |
| 1216 | isolate()); |
| 1217 | { |
| 1218 | FrameScope scope(masm, StackFrame::MANUAL); |
| 1219 | __ PrepareCallCFunction(3, 0, a0); |
| 1220 | __ mov(a0, zero_reg); |
| 1221 | __ mov(a1, zero_reg); |
| 1222 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
| 1223 | __ CallCFunction(find_handler, 3); |
| 1224 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1225 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1226 | // Retrieve the handler context, SP and FP. |
| 1227 | __ li(cp, Operand(pending_handler_context_address)); |
| 1228 | __ lw(cp, MemOperand(cp)); |
| 1229 | __ li(sp, Operand(pending_handler_sp_address)); |
| 1230 | __ lw(sp, MemOperand(sp)); |
| 1231 | __ li(fp, Operand(pending_handler_fp_address)); |
| 1232 | __ lw(fp, MemOperand(fp)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1233 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1234 | // If the handler is a JS frame, restore the context to the frame. Note that |
| 1235 | // the context will be set to (cp == 0) for non-JS frames. |
| 1236 | Label zero; |
| 1237 | __ Branch(&zero, eq, cp, Operand(zero_reg)); |
| 1238 | __ sw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 1239 | __ bind(&zero); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1240 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1241 | // Compute the handler entry address and jump to it. |
| 1242 | __ li(a1, Operand(pending_handler_code_address)); |
| 1243 | __ lw(a1, MemOperand(a1)); |
| 1244 | __ li(a2, Operand(pending_handler_offset_address)); |
| 1245 | __ lw(a2, MemOperand(a2)); |
| 1246 | __ Addu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 1247 | __ Addu(t9, a1, a2); |
| 1248 | __ Jump(t9); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1252 | void JSEntryStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1253 | Label invoke, handler_entry, exit; |
| 1254 | Isolate* isolate = masm->isolate(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1255 | |
| 1256 | // Registers: |
| 1257 | // a0: entry address |
| 1258 | // a1: function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1259 | // a2: receiver |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1260 | // a3: argc |
| 1261 | // |
| 1262 | // Stack: |
| 1263 | // 4 args slots |
| 1264 | // args |
| 1265 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1266 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 1267 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1268 | // Save callee saved registers on the stack. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1269 | __ MultiPush(kCalleeSaved | ra.bit()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1270 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1271 | // Save callee-saved FPU registers. |
| 1272 | __ MultiPushFPU(kCalleeSavedFPU); |
| 1273 | // Set up the reserved register for 0.0. |
| 1274 | __ Move(kDoubleRegZero, 0.0); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1275 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1276 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1277 | // Load argv in s0 register. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1278 | int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1279 | offset_to_argv += kNumCalleeSavedFPU * kDoubleSize; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1280 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1281 | __ InitializeRootRegister(); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1282 | __ lw(s0, MemOperand(sp, offset_to_argv + kCArgsSlotsSize)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1283 | |
| 1284 | // We build an EntryFrame. |
| 1285 | __ 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] | 1286 | int marker = type(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1287 | __ li(t2, Operand(Smi::FromInt(marker))); |
| 1288 | __ li(t1, Operand(Smi::FromInt(marker))); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1289 | __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1290 | isolate))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1291 | __ lw(t0, MemOperand(t0)); |
| 1292 | __ Push(t3, t2, t1, t0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1293 | // Set up frame pointer for the frame to be pushed. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1294 | __ addiu(fp, sp, -EntryFrameConstants::kCallerFPOffset); |
| 1295 | |
| 1296 | // Registers: |
| 1297 | // a0: entry_address |
| 1298 | // a1: function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1299 | // a2: receiver_pointer |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1300 | // a3: argc |
| 1301 | // s0: argv |
| 1302 | // |
| 1303 | // Stack: |
| 1304 | // caller fp | |
| 1305 | // function slot | entry frame |
| 1306 | // context slot | |
| 1307 | // bad fp (0xff...f) | |
| 1308 | // callee saved registers + ra |
| 1309 | // 4 args slots |
| 1310 | // args |
| 1311 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1312 | // If this is the outermost JS call, set js_entry_sp value. |
| 1313 | Label non_outermost_js; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1314 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1315 | __ li(t1, Operand(ExternalReference(js_entry_sp))); |
| 1316 | __ lw(t2, MemOperand(t1)); |
| 1317 | __ Branch(&non_outermost_js, ne, t2, Operand(zero_reg)); |
| 1318 | __ sw(fp, MemOperand(t1)); |
| 1319 | __ li(t0, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 1320 | Label cont; |
| 1321 | __ b(&cont); |
| 1322 | __ nop(); // Branch delay slot nop. |
| 1323 | __ bind(&non_outermost_js); |
| 1324 | __ li(t0, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
| 1325 | __ bind(&cont); |
| 1326 | __ push(t0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1327 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1328 | // Jump to a faked try block that does the invoke, with a faked catch |
| 1329 | // block that sets the pending exception. |
| 1330 | __ jmp(&invoke); |
| 1331 | __ bind(&handler_entry); |
| 1332 | handler_offset_ = handler_entry.pos(); |
| 1333 | // Caught exception: Store result (exception) in the pending exception |
| 1334 | // 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] | 1335 | // 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] | 1336 | // signal the existence of the JSEntry frame. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1337 | __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1338 | isolate))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1339 | __ 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] | 1340 | __ LoadRoot(v0, Heap::kExceptionRootIndex); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1341 | __ b(&exit); // b exposes branch delay slot. |
| 1342 | __ nop(); // Branch delay slot nop. |
| 1343 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1344 | // Invoke: Link this frame into the handler chain. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1345 | __ bind(&invoke); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1346 | __ PushStackHandler(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1347 | // If an exception not caught by another handler occurs, this handler |
| 1348 | // returns control to the code after the bal(&invoke) above, which |
| 1349 | // restores all kCalleeSaved registers (including cp and fp) to their |
| 1350 | // saved values before returning a failure to C. |
| 1351 | |
| 1352 | // Clear any pending exceptions. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1353 | __ LoadRoot(t1, Heap::kTheHoleValueRootIndex); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1354 | __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1355 | isolate))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1356 | __ sw(t1, MemOperand(t0)); |
| 1357 | |
| 1358 | // Invoke the function by calling through JS entry trampoline builtin. |
| 1359 | // Notice that we cannot store a reference to the trampoline code directly in |
| 1360 | // this stub, because runtime stubs are not traversed when doing GC. |
| 1361 | |
| 1362 | // Registers: |
| 1363 | // a0: entry_address |
| 1364 | // a1: function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1365 | // a2: receiver_pointer |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1366 | // a3: argc |
| 1367 | // s0: argv |
| 1368 | // |
| 1369 | // Stack: |
| 1370 | // handler frame |
| 1371 | // entry frame |
| 1372 | // callee saved registers + ra |
| 1373 | // 4 args slots |
| 1374 | // args |
| 1375 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1376 | if (type() == StackFrame::ENTRY_CONSTRUCT) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1377 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1378 | isolate); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1379 | __ li(t0, Operand(construct_entry)); |
| 1380 | } else { |
| 1381 | ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate()); |
| 1382 | __ li(t0, Operand(entry)); |
| 1383 | } |
| 1384 | __ lw(t9, MemOperand(t0)); // Deref address. |
| 1385 | |
| 1386 | // Call JSEntryTrampoline. |
| 1387 | __ addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag); |
| 1388 | __ Call(t9); |
| 1389 | |
| 1390 | // Unlink this frame from the handler chain. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1391 | __ PopStackHandler(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1392 | |
| 1393 | __ bind(&exit); // v0 holds result |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1394 | // Check if the current stack frame is marked as the outermost JS frame. |
| 1395 | Label non_outermost_js_2; |
| 1396 | __ pop(t1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1397 | __ Branch(&non_outermost_js_2, |
| 1398 | ne, |
| 1399 | t1, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1400 | Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 1401 | __ li(t1, Operand(ExternalReference(js_entry_sp))); |
| 1402 | __ sw(zero_reg, MemOperand(t1)); |
| 1403 | __ bind(&non_outermost_js_2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1404 | |
| 1405 | // Restore the top frame descriptors from the stack. |
| 1406 | __ pop(t1); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1407 | __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1408 | isolate))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1409 | __ sw(t1, MemOperand(t0)); |
| 1410 | |
| 1411 | // Reset the stack to the callee saved registers. |
| 1412 | __ addiu(sp, sp, -EntryFrameConstants::kCallerFPOffset); |
| 1413 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1414 | // Restore callee-saved fpu registers. |
| 1415 | __ MultiPopFPU(kCalleeSavedFPU); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1416 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1417 | // Restore callee saved registers from the stack. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1418 | __ MultiPop(kCalleeSaved | ra.bit()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1419 | // Return. |
| 1420 | __ Jump(ra); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1424 | void LoadIndexedStringStub::Generate(MacroAssembler* masm) { |
| 1425 | // Return address is in ra. |
| 1426 | Label miss; |
| 1427 | |
| 1428 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 1429 | Register index = LoadDescriptor::NameRegister(); |
| 1430 | Register scratch = t1; |
| 1431 | Register result = v0; |
| 1432 | DCHECK(!scratch.is(receiver) && !scratch.is(index)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1433 | DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1434 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1435 | StringCharAtGenerator char_at_generator(receiver, index, scratch, result, |
| 1436 | &miss, // When not a string. |
| 1437 | &miss, // When not a number. |
| 1438 | &miss, // When index out of range. |
| 1439 | STRING_INDEX_IS_ARRAY_INDEX, |
| 1440 | RECEIVER_IS_STRING); |
| 1441 | char_at_generator.GenerateFast(masm); |
| 1442 | __ Ret(); |
| 1443 | |
| 1444 | StubRuntimeCallHelper call_helper; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1445 | char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1446 | |
| 1447 | __ bind(&miss); |
| 1448 | PropertyAccessCompiler::TailCallBuiltin( |
| 1449 | masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC)); |
| 1450 | } |
| 1451 | |
| 1452 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1453 | void InstanceOfStub::Generate(MacroAssembler* masm) { |
| 1454 | Register const object = a1; // Object (lhs). |
| 1455 | Register const function = a0; // Function (rhs). |
| 1456 | Register const object_map = a2; // Map of {object}. |
| 1457 | Register const function_map = a3; // Map of {function}. |
| 1458 | Register const function_prototype = t0; // Prototype of {function}. |
| 1459 | Register const scratch = t1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1460 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1461 | DCHECK(object.is(InstanceOfDescriptor::LeftRegister())); |
| 1462 | DCHECK(function.is(InstanceOfDescriptor::RightRegister())); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1463 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1464 | // Check if {object} is a smi. |
| 1465 | Label object_is_smi; |
| 1466 | __ JumpIfSmi(object, &object_is_smi); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1467 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1468 | // Lookup the {function} and the {object} map in the global instanceof cache. |
| 1469 | // Note: This is safe because we clear the global instanceof cache whenever |
| 1470 | // we change the prototype of any object. |
| 1471 | Label fast_case, slow_case; |
| 1472 | __ lw(object_map, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1473 | __ LoadRoot(at, Heap::kInstanceofCacheFunctionRootIndex); |
| 1474 | __ Branch(&fast_case, ne, function, Operand(at)); |
| 1475 | __ LoadRoot(at, Heap::kInstanceofCacheMapRootIndex); |
| 1476 | __ Branch(&fast_case, ne, object_map, Operand(at)); |
| 1477 | __ Ret(USE_DELAY_SLOT); |
| 1478 | __ LoadRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1479 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1480 | // If {object} is a smi we can safely return false if {function} is a JS |
| 1481 | // function, otherwise we have to miss to the runtime and throw an exception. |
| 1482 | __ bind(&object_is_smi); |
| 1483 | __ JumpIfSmi(function, &slow_case); |
| 1484 | __ GetObjectType(function, function_map, scratch); |
| 1485 | __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE)); |
| 1486 | __ Ret(USE_DELAY_SLOT); |
| 1487 | __ LoadRoot(v0, Heap::kFalseValueRootIndex); // In delay slot. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1488 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1489 | // Fast-case: The {function} must be a valid JSFunction. |
| 1490 | __ bind(&fast_case); |
| 1491 | __ JumpIfSmi(function, &slow_case); |
| 1492 | __ GetObjectType(function, function_map, scratch); |
| 1493 | __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1494 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1495 | // Ensure that {function} has an instance prototype. |
| 1496 | __ lbu(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset)); |
| 1497 | __ And(at, scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
| 1498 | __ Branch(&slow_case, ne, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1499 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1500 | // Get the "prototype" (or initial map) of the {function}. |
| 1501 | __ lw(function_prototype, |
| 1502 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1503 | __ AssertNotSmi(function_prototype); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1504 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1505 | // Resolve the prototype if the {function} has an initial map. Afterwards the |
| 1506 | // {function_prototype} will be either the JSReceiver prototype object or the |
| 1507 | // hole value, which means that no instances of the {function} were created so |
| 1508 | // far and hence we should return false. |
| 1509 | Label function_prototype_valid; |
| 1510 | __ GetObjectType(function_prototype, scratch, scratch); |
| 1511 | __ Branch(&function_prototype_valid, ne, scratch, Operand(MAP_TYPE)); |
| 1512 | __ lw(function_prototype, |
| 1513 | FieldMemOperand(function_prototype, Map::kPrototypeOffset)); |
| 1514 | __ bind(&function_prototype_valid); |
| 1515 | __ AssertNotSmi(function_prototype); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1516 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1517 | // Update the global instanceof cache with the current {object} map and |
| 1518 | // {function}. The cached answer will be set when it is known below. |
| 1519 | __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex); |
| 1520 | __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1521 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1522 | // Loop through the prototype chain looking for the {function} prototype. |
| 1523 | // Assume true, and change to false if not found. |
| 1524 | Register const object_instance_type = function_map; |
| 1525 | Register const map_bit_field = function_map; |
| 1526 | Register const null = scratch; |
| 1527 | Register const result = v0; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1528 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1529 | Label done, loop, fast_runtime_fallback; |
| 1530 | __ LoadRoot(result, Heap::kTrueValueRootIndex); |
| 1531 | __ LoadRoot(null, Heap::kNullValueRootIndex); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1532 | __ bind(&loop); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1533 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1534 | // Check if the object needs to be access checked. |
| 1535 | __ lbu(map_bit_field, FieldMemOperand(object_map, Map::kBitFieldOffset)); |
| 1536 | __ And(map_bit_field, map_bit_field, Operand(1 << Map::kIsAccessCheckNeeded)); |
| 1537 | __ Branch(&fast_runtime_fallback, ne, map_bit_field, Operand(zero_reg)); |
| 1538 | // Check if the current object is a Proxy. |
| 1539 | __ lbu(object_instance_type, |
| 1540 | FieldMemOperand(object_map, Map::kInstanceTypeOffset)); |
| 1541 | __ Branch(&fast_runtime_fallback, eq, object_instance_type, |
| 1542 | Operand(JS_PROXY_TYPE)); |
| 1543 | |
| 1544 | __ lw(object, FieldMemOperand(object_map, Map::kPrototypeOffset)); |
| 1545 | __ Branch(&done, eq, object, Operand(function_prototype)); |
| 1546 | __ Branch(USE_DELAY_SLOT, &loop, ne, object, Operand(null)); |
| 1547 | __ lw(object_map, |
| 1548 | FieldMemOperand(object, HeapObject::kMapOffset)); // In delay slot. |
| 1549 | __ LoadRoot(result, Heap::kFalseValueRootIndex); |
| 1550 | __ bind(&done); |
| 1551 | __ Ret(USE_DELAY_SLOT); |
| 1552 | __ StoreRoot(result, |
| 1553 | Heap::kInstanceofCacheAnswerRootIndex); // In delay slot. |
| 1554 | |
| 1555 | // Found Proxy or access check needed: Call the runtime |
| 1556 | __ bind(&fast_runtime_fallback); |
| 1557 | __ Push(object, function_prototype); |
| 1558 | // Invalidate the instanceof cache. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1559 | DCHECK(Smi::FromInt(0) == 0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1560 | __ StoreRoot(zero_reg, Heap::kInstanceofCacheFunctionRootIndex); |
| 1561 | __ TailCallRuntime(Runtime::kHasInPrototypeChain); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1562 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1563 | // Slow-case: Call the %InstanceOf runtime function. |
| 1564 | __ bind(&slow_case); |
| 1565 | __ Push(object, function); |
| 1566 | __ TailCallRuntime(Runtime::kInstanceOf); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1570 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 1571 | Label miss; |
| 1572 | Register receiver = LoadDescriptor::ReceiverRegister(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1573 | // Ensure that the vector and slot registers won't be clobbered before |
| 1574 | // calling the miss handler. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1575 | DCHECK(!AreAliased(t0, t1, LoadWithVectorDescriptor::VectorRegister(), |
| 1576 | LoadWithVectorDescriptor::SlotRegister())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1577 | |
| 1578 | NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, t0, |
| 1579 | t1, &miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1580 | __ bind(&miss); |
| 1581 | PropertyAccessCompiler::TailCallBuiltin( |
| 1582 | masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC)); |
| 1583 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1584 | |
| 1585 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1586 | void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) { |
| 1587 | // Return address is in ra. |
| 1588 | Label slow; |
| 1589 | |
| 1590 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 1591 | Register key = LoadDescriptor::NameRegister(); |
| 1592 | |
| 1593 | // Check that the key is an array index, that is Uint32. |
| 1594 | __ And(t0, key, Operand(kSmiTagMask | kSmiSignMask)); |
| 1595 | __ Branch(&slow, ne, t0, Operand(zero_reg)); |
| 1596 | |
| 1597 | // Everything is fine, call runtime. |
| 1598 | __ Push(receiver, key); // Receiver, key. |
| 1599 | |
| 1600 | // Perform tail call to the entry. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1601 | __ TailCallRuntime(Runtime::kLoadElementWithInterceptor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1602 | |
| 1603 | __ bind(&slow); |
| 1604 | PropertyAccessCompiler::TailCallBuiltin( |
| 1605 | masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1608 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1609 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 1610 | // time or if regexp entry in generated code is turned off runtime switch or |
| 1611 | // at compilation. |
| 1612 | #ifdef V8_INTERPRETED_REGEXP |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1613 | __ TailCallRuntime(Runtime::kRegExpExec); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1614 | #else // V8_INTERPRETED_REGEXP |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1615 | |
| 1616 | // Stack frame on entry. |
| 1617 | // sp[0]: last_match_info (expected JSArray) |
| 1618 | // sp[4]: previous index |
| 1619 | // sp[8]: subject string |
| 1620 | // sp[12]: JSRegExp object |
| 1621 | |
Ben Murdoch | db1b438 | 2012-04-26 19:03:50 +0100 | [diff] [blame] | 1622 | const int kLastMatchInfoOffset = 0 * kPointerSize; |
| 1623 | const int kPreviousIndexOffset = 1 * kPointerSize; |
| 1624 | const int kSubjectOffset = 2 * kPointerSize; |
| 1625 | const int kJSRegExpOffset = 3 * kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1626 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1627 | Label runtime; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1628 | // Allocation of registers for this function. These are in callee save |
| 1629 | // registers and will be preserved by the call to the native RegExp code, as |
| 1630 | // this code is called using the normal C calling convention. When calling |
| 1631 | // directly from generated code the native RegExp code will not do a GC and |
| 1632 | // therefore the content of these registers are safe to use after the call. |
| 1633 | // MIPS - using s0..s2, since we are not using CEntry Stub. |
| 1634 | Register subject = s0; |
| 1635 | Register regexp_data = s1; |
| 1636 | Register last_match_info_elements = s2; |
| 1637 | |
| 1638 | // Ensure that a RegExp stack is allocated. |
| 1639 | ExternalReference address_of_regexp_stack_memory_address = |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1640 | ExternalReference::address_of_regexp_stack_memory_address(isolate()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1641 | ExternalReference address_of_regexp_stack_memory_size = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1642 | ExternalReference::address_of_regexp_stack_memory_size(isolate()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1643 | __ li(a0, Operand(address_of_regexp_stack_memory_size)); |
| 1644 | __ lw(a0, MemOperand(a0, 0)); |
| 1645 | __ Branch(&runtime, eq, a0, Operand(zero_reg)); |
| 1646 | |
| 1647 | // Check that the first argument is a JSRegExp object. |
| 1648 | __ lw(a0, MemOperand(sp, kJSRegExpOffset)); |
| 1649 | STATIC_ASSERT(kSmiTag == 0); |
| 1650 | __ JumpIfSmi(a0, &runtime); |
| 1651 | __ GetObjectType(a0, a1, a1); |
| 1652 | __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE)); |
| 1653 | |
| 1654 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 1655 | __ lw(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset)); |
| 1656 | if (FLAG_debug_code) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1657 | __ SmiTst(regexp_data, t0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1658 | __ Check(nz, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1659 | kUnexpectedTypeForRegExpDataFixedArrayExpected, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1660 | t0, |
| 1661 | Operand(zero_reg)); |
| 1662 | __ GetObjectType(regexp_data, a0, a0); |
| 1663 | __ Check(eq, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1664 | kUnexpectedTypeForRegExpDataFixedArrayExpected, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1665 | a0, |
| 1666 | Operand(FIXED_ARRAY_TYPE)); |
| 1667 | } |
| 1668 | |
| 1669 | // regexp_data: RegExp data (FixedArray) |
| 1670 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 1671 | __ lw(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset)); |
| 1672 | __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP))); |
| 1673 | |
| 1674 | // regexp_data: RegExp data (FixedArray) |
| 1675 | // Check that the number of captures fit in the static offsets vector buffer. |
| 1676 | __ lw(a2, |
| 1677 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1678 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 1679 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 1680 | // Multiplying by 2 comes for free since a2 is smi-tagged. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1681 | STATIC_ASSERT(kSmiTag == 0); |
| 1682 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1683 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 1684 | __ Branch( |
| 1685 | &runtime, hi, a2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1686 | |
| 1687 | // Reset offset for possibly sliced string. |
| 1688 | __ mov(t0, zero_reg); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1689 | __ lw(subject, MemOperand(sp, kSubjectOffset)); |
| 1690 | __ JumpIfSmi(subject, &runtime); |
| 1691 | __ mov(a3, subject); // Make a copy of the original subject string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1692 | // subject: subject string |
| 1693 | // a3: subject string |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1694 | // regexp_data: RegExp data (FixedArray) |
| 1695 | // Handle subject string according to its encoding and representation: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1696 | // (1) Sequential string? If yes, go to (4). |
| 1697 | // (2) Sequential or cons? If not, go to (5). |
| 1698 | // (3) Cons string. If the string is flat, replace subject with first string |
| 1699 | // and go to (1). Otherwise bail out to runtime. |
| 1700 | // (4) Sequential string. Load regexp code according to encoding. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1701 | // (E) Carry on. |
| 1702 | /// [...] |
| 1703 | |
| 1704 | // Deferred code at the end of the stub: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1705 | // (5) Long external string? If not, go to (7). |
| 1706 | // (6) External string. Make it, offset-wise, look like a sequential string. |
| 1707 | // Go to (4). |
| 1708 | // (7) Short external string or not a string? If yes, bail out to runtime. |
| 1709 | // (8) Sliced string. Replace subject with parent. Go to (1). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1710 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1711 | Label seq_string /* 4 */, external_string /* 6 */, check_underlying /* 1 */, |
| 1712 | not_seq_nor_cons /* 5 */, not_long_external /* 7 */; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1713 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1714 | __ bind(&check_underlying); |
| 1715 | __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 1716 | __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset)); |
| 1717 | |
| 1718 | // (1) Sequential string? If yes, go to (4). |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1719 | __ And(a1, |
| 1720 | a0, |
| 1721 | Operand(kIsNotStringMask | |
| 1722 | kStringRepresentationMask | |
| 1723 | kShortExternalStringMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1724 | STATIC_ASSERT((kStringTag | kSeqStringTag) == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1725 | __ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (5). |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1726 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1727 | // (2) Sequential or cons? If not, go to (5). |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1728 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 1729 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1730 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 1731 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1732 | // Go to (5). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1733 | __ Branch(¬_seq_nor_cons, ge, a1, Operand(kExternalStringTag)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1734 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1735 | // (3) Cons string. Check that it's flat. |
| 1736 | // Replace subject with first string and reload instance type. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1737 | __ lw(a0, FieldMemOperand(subject, ConsString::kSecondOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1738 | __ LoadRoot(a1, Heap::kempty_stringRootIndex); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1739 | __ Branch(&runtime, ne, a0, Operand(a1)); |
| 1740 | __ lw(subject, FieldMemOperand(subject, ConsString::kFirstOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1741 | __ jmp(&check_underlying); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1742 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1743 | // (4) Sequential string. Load regexp code according to encoding. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1744 | __ bind(&seq_string); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1745 | // subject: sequential subject string (or look-alike, external string) |
| 1746 | // a3: original subject string |
| 1747 | // Load previous index and check range before a3 is overwritten. We have to |
| 1748 | // use a3 instead of subject here because subject might have been only made |
| 1749 | // to look like a sequential string when it actually is an external string. |
| 1750 | __ lw(a1, MemOperand(sp, kPreviousIndexOffset)); |
| 1751 | __ JumpIfNotSmi(a1, &runtime); |
| 1752 | __ lw(a3, FieldMemOperand(a3, String::kLengthOffset)); |
| 1753 | __ Branch(&runtime, ls, a3, Operand(a1)); |
| 1754 | __ sra(a1, a1, kSmiTagSize); // Untag the Smi. |
| 1755 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1756 | STATIC_ASSERT(kStringEncodingMask == 4); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1757 | STATIC_ASSERT(kOneByteStringTag == 4); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1758 | STATIC_ASSERT(kTwoByteStringTag == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1759 | __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for one-byte. |
| 1760 | __ lw(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1761 | __ 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] | 1762 | __ lw(t1, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1763 | __ 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] | 1764 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1765 | // (E) Carry on. String handling is done. |
| 1766 | // t9: irregexp code |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1767 | // Check that the irregexp code has been generated for the actual string |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1768 | // encoding. If it has, the field contains a code object otherwise it contains |
| 1769 | // a smi (code flushing support). |
| 1770 | __ JumpIfSmi(t9, &runtime); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1771 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1772 | // a1: previous index |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1773 | // 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] | 1774 | // t9: code |
| 1775 | // subject: Subject string |
| 1776 | // regexp_data: RegExp data (FixedArray) |
| 1777 | // All checks done. Now push arguments for native regexp code. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1778 | __ IncrementCounter(isolate()->counters()->regexp_entry_native(), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1779 | 1, a0, a2); |
| 1780 | |
| 1781 | // Isolates: note we add an additional parameter here (isolate pointer). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1782 | const int kRegExpExecuteArguments = 9; |
Ben Murdoch | db1b438 | 2012-04-26 19:03:50 +0100 | [diff] [blame] | 1783 | const int kParameterRegisters = 4; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1784 | __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters); |
| 1785 | |
| 1786 | // Stack pointer now points to cell where return address is to be written. |
| 1787 | // Arguments are before that on the stack or in registers, meaning we |
| 1788 | // treat the return address as argument 5. Thus every argument after that |
| 1789 | // needs to be shifted back by 1. Since DirectCEntryStub will handle |
| 1790 | // allocating space for the c argument slots, we don't need to calculate |
| 1791 | // that into the argument positions on the stack. This is how the stack will |
| 1792 | // look (sp meaning the value of sp at this moment): |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1793 | // [sp + 5] - Argument 9 |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1794 | // [sp + 4] - Argument 8 |
| 1795 | // [sp + 3] - Argument 7 |
| 1796 | // [sp + 2] - Argument 6 |
| 1797 | // [sp + 1] - Argument 5 |
| 1798 | // [sp + 0] - saved ra |
| 1799 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1800 | // Argument 9: Pass current isolate address. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1801 | // CFunctionArgumentOperand handles MIPS stack argument slots. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1802 | __ li(a0, Operand(ExternalReference::isolate_address(isolate()))); |
| 1803 | __ sw(a0, MemOperand(sp, 5 * kPointerSize)); |
| 1804 | |
| 1805 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 1806 | __ li(a0, Operand(1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1807 | __ sw(a0, MemOperand(sp, 4 * kPointerSize)); |
| 1808 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1809 | // Argument 7: Start (high end) of backtracking stack memory area. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1810 | __ li(a0, Operand(address_of_regexp_stack_memory_address)); |
| 1811 | __ lw(a0, MemOperand(a0, 0)); |
| 1812 | __ li(a2, Operand(address_of_regexp_stack_memory_size)); |
| 1813 | __ lw(a2, MemOperand(a2, 0)); |
| 1814 | __ addu(a0, a0, a2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1815 | __ sw(a0, MemOperand(sp, 3 * kPointerSize)); |
| 1816 | |
| 1817 | // Argument 6: Set the number of capture registers to zero to force global |
| 1818 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 1819 | __ mov(a0, zero_reg); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1820 | __ sw(a0, MemOperand(sp, 2 * kPointerSize)); |
| 1821 | |
| 1822 | // Argument 5: static offsets vector buffer. |
| 1823 | __ li(a0, Operand( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1824 | ExternalReference::address_of_static_offsets_vector(isolate()))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1825 | __ sw(a0, MemOperand(sp, 1 * kPointerSize)); |
| 1826 | |
| 1827 | // 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] | 1828 | // 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] | 1829 | __ Addu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1830 | __ 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] | 1831 | // Load the length from the original subject string from the previous stack |
| 1832 | // frame. Therefore we have to use fp, which points exactly to two pointer |
| 1833 | // sizes below the previous sp. (Because creating a new stack frame pushes |
| 1834 | // 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] | 1835 | __ lw(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1836 | // If slice offset is not 0, load the length from the original sliced string. |
| 1837 | // Argument 4, a3: End of string data |
| 1838 | // Argument 3, a2: Start of string data |
| 1839 | // Prepare start and end index of the input. |
| 1840 | __ sllv(t1, t0, a3); |
| 1841 | __ addu(t0, t2, t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1842 | __ sllv(t1, a1, a3); |
| 1843 | __ addu(a2, t0, t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1844 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1845 | __ lw(t2, FieldMemOperand(subject, String::kLengthOffset)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1846 | __ sra(t2, t2, kSmiTagSize); |
| 1847 | __ sllv(t1, t2, a3); |
| 1848 | __ addu(a3, t0, t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1849 | // Argument 2 (a1): Previous index. |
| 1850 | // Already there |
| 1851 | |
| 1852 | // Argument 1 (a0): Subject string. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1853 | __ mov(a0, subject); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1854 | |
| 1855 | // Locate the code entry and call it. |
| 1856 | __ Addu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1857 | DirectCEntryStub stub(isolate()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1858 | stub.GenerateCall(masm, t9); |
| 1859 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1860 | __ LeaveExitFrame(false, no_reg, true); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1861 | |
| 1862 | // v0: result |
| 1863 | // subject: subject string (callee saved) |
| 1864 | // regexp_data: RegExp data (callee saved) |
| 1865 | // last_match_info_elements: Last match info elements (callee saved) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1866 | // Check the result. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1867 | Label success; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1868 | __ Branch(&success, eq, v0, Operand(1)); |
| 1869 | // We expect exactly one result since we force the called regexp to behave |
| 1870 | // as non-global. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1871 | Label failure; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1872 | __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1873 | // 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] | 1874 | __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1875 | // Result must now be exception. If there is no pending exception already a |
| 1876 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 1877 | // haven't created the exception yet. Handle that in the runtime system. |
| 1878 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1879 | __ li(a1, Operand(isolate()->factory()->the_hole_value())); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1880 | __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1881 | isolate()))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1882 | __ lw(v0, MemOperand(a2, 0)); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1883 | __ Branch(&runtime, eq, v0, Operand(a1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1884 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1885 | // For exception, throw the exception again. |
| 1886 | __ TailCallRuntime(Runtime::kRegExpExecReThrow); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1887 | |
| 1888 | __ bind(&failure); |
| 1889 | // For failure and exception return null. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1890 | __ li(v0, Operand(isolate()->factory()->null_value())); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1891 | __ DropAndRet(4); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1892 | |
| 1893 | // Process the result from the native regexp code. |
| 1894 | __ bind(&success); |
| 1895 | __ lw(a1, |
| 1896 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
| 1897 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1898 | // Multiplying by 2 comes for free since r1 is smi-tagged. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1899 | STATIC_ASSERT(kSmiTag == 0); |
| 1900 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 1901 | __ Addu(a1, a1, Operand(2)); // a1 was a smi. |
| 1902 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1903 | __ lw(a0, MemOperand(sp, kLastMatchInfoOffset)); |
| 1904 | __ JumpIfSmi(a0, &runtime); |
| 1905 | __ GetObjectType(a0, a2, a2); |
| 1906 | __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE)); |
| 1907 | // Check that the JSArray is in fast case. |
| 1908 | __ lw(last_match_info_elements, |
| 1909 | FieldMemOperand(a0, JSArray::kElementsOffset)); |
| 1910 | __ lw(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset)); |
| 1911 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 1912 | __ Branch(&runtime, ne, a0, Operand(at)); |
| 1913 | // Check that the last match info has space for the capture registers and the |
| 1914 | // additional information. |
| 1915 | __ lw(a0, |
| 1916 | FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset)); |
| 1917 | __ Addu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead)); |
| 1918 | __ sra(at, a0, kSmiTagSize); |
| 1919 | __ Branch(&runtime, gt, a2, Operand(at)); |
| 1920 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1921 | // a1: number of capture registers |
| 1922 | // subject: subject string |
| 1923 | // Store the capture count. |
| 1924 | __ sll(a2, a1, kSmiTagSize + kSmiShiftSize); // To smi. |
| 1925 | __ sw(a2, FieldMemOperand(last_match_info_elements, |
| 1926 | RegExpImpl::kLastCaptureCountOffset)); |
| 1927 | // Store last subject and last input. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1928 | __ sw(subject, |
| 1929 | FieldMemOperand(last_match_info_elements, |
| 1930 | RegExpImpl::kLastSubjectOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1931 | __ mov(a2, subject); |
| 1932 | __ RecordWriteField(last_match_info_elements, |
| 1933 | RegExpImpl::kLastSubjectOffset, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1934 | subject, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1935 | t3, |
| 1936 | kRAHasNotBeenSaved, |
| 1937 | kDontSaveFPRegs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1938 | __ mov(subject, a2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1939 | __ sw(subject, |
| 1940 | FieldMemOperand(last_match_info_elements, |
| 1941 | RegExpImpl::kLastInputOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1942 | __ RecordWriteField(last_match_info_elements, |
| 1943 | RegExpImpl::kLastInputOffset, |
| 1944 | subject, |
| 1945 | t3, |
| 1946 | kRAHasNotBeenSaved, |
| 1947 | kDontSaveFPRegs); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1948 | |
| 1949 | // Get the static offsets vector filled by the native regexp code. |
| 1950 | ExternalReference address_of_static_offsets_vector = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1951 | ExternalReference::address_of_static_offsets_vector(isolate()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1952 | __ li(a2, Operand(address_of_static_offsets_vector)); |
| 1953 | |
| 1954 | // a1: number of capture registers |
| 1955 | // a2: offsets vector |
| 1956 | Label next_capture, done; |
| 1957 | // Capture register counter starts from number of capture registers and |
| 1958 | // counts down until wrapping after zero. |
| 1959 | __ Addu(a0, |
| 1960 | last_match_info_elements, |
| 1961 | Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag)); |
| 1962 | __ bind(&next_capture); |
| 1963 | __ Subu(a1, a1, Operand(1)); |
| 1964 | __ Branch(&done, lt, a1, Operand(zero_reg)); |
| 1965 | // Read the value from the static offsets vector buffer. |
| 1966 | __ lw(a3, MemOperand(a2, 0)); |
| 1967 | __ addiu(a2, a2, kPointerSize); |
| 1968 | // Store the smi value in the last match info. |
| 1969 | __ sll(a3, a3, kSmiTagSize); // Convert to Smi. |
| 1970 | __ sw(a3, MemOperand(a0, 0)); |
| 1971 | __ Branch(&next_capture, USE_DELAY_SLOT); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1972 | __ addiu(a0, a0, kPointerSize); // In branch delay slot. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1973 | |
| 1974 | __ bind(&done); |
| 1975 | |
| 1976 | // Return last match info. |
| 1977 | __ lw(v0, MemOperand(sp, kLastMatchInfoOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1978 | __ DropAndRet(4); |
| 1979 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1980 | // Do the runtime call to execute the regexp. |
| 1981 | __ bind(&runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1982 | __ TailCallRuntime(Runtime::kRegExpExec); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1983 | |
| 1984 | // Deferred code for string handling. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1985 | // (5) Long external string? If not, go to (7). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1986 | __ bind(¬_seq_nor_cons); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1987 | // Go to (7). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1988 | __ Branch(¬_long_external, gt, a1, Operand(kExternalStringTag)); |
| 1989 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1990 | // (6) External string. Make it, offset-wise, look like a sequential string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1991 | __ bind(&external_string); |
| 1992 | __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 1993 | __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset)); |
| 1994 | if (FLAG_debug_code) { |
| 1995 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 1996 | // Sequential strings have already been ruled out. |
| 1997 | __ And(at, a0, Operand(kIsIndirectStringMask)); |
| 1998 | __ Assert(eq, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1999 | kExternalStringExpectedButNotFound, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2000 | at, |
| 2001 | Operand(zero_reg)); |
| 2002 | } |
| 2003 | __ lw(subject, |
| 2004 | FieldMemOperand(subject, ExternalString::kResourceDataOffset)); |
| 2005 | // 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] | 2006 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2007 | __ Subu(subject, |
| 2008 | subject, |
| 2009 | SeqTwoByteString::kHeaderSize - kHeapObjectTag); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2010 | __ jmp(&seq_string); // Go to (5). |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2011 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2012 | // (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] | 2013 | __ bind(¬_long_external); |
| 2014 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 2015 | __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask)); |
| 2016 | __ Branch(&runtime, ne, at, Operand(zero_reg)); |
| 2017 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2018 | // (8) Sliced string. Replace subject with parent. Go to (4). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2019 | // Load offset into t0 and replace subject string with parent. |
| 2020 | __ lw(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset)); |
| 2021 | __ sra(t0, t0, kSmiTagSize); |
| 2022 | __ lw(subject, FieldMemOperand(subject, SlicedString::kParentOffset)); |
| 2023 | __ jmp(&check_underlying); // Go to (4). |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2024 | #endif // V8_INTERPRETED_REGEXP |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2028 | static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) { |
| 2029 | // a0 : number of arguments to the construct function |
| 2030 | // a2 : feedback vector |
| 2031 | // a3 : slot in feedback vector (Smi) |
| 2032 | // a1 : the function to call |
| 2033 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2034 | const RegList kSavedRegs = 1 << 4 | // a0 |
| 2035 | 1 << 5 | // a1 |
| 2036 | 1 << 6 | // a2 |
| 2037 | 1 << 7; // a3 |
| 2038 | |
| 2039 | // Number-of-arguments register must be smi-tagged to call out. |
| 2040 | __ SmiTag(a0); |
| 2041 | __ MultiPush(kSavedRegs); |
| 2042 | |
| 2043 | __ CallStub(stub); |
| 2044 | |
| 2045 | __ MultiPop(kSavedRegs); |
| 2046 | __ SmiUntag(a0); |
| 2047 | } |
| 2048 | |
| 2049 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2050 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2051 | // Cache the called function in a feedback vector slot. Cache states |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2052 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 2053 | // megamorphic. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2054 | // a0 : number of arguments to the construct function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2055 | // a1 : the function to call |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2056 | // a2 : feedback vector |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2057 | // a3 : slot in feedback vector (Smi) |
| 2058 | Label initialize, done, miss, megamorphic, not_array_function; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2059 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2060 | DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()), |
| 2061 | masm->isolate()->heap()->megamorphic_symbol()); |
| 2062 | DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()), |
| 2063 | masm->isolate()->heap()->uninitialized_symbol()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2064 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2065 | // Load the cache state into t2. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2066 | __ Lsa(t2, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2067 | __ lw(t2, FieldMemOperand(t2, FixedArray::kHeaderSize)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2068 | |
| 2069 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 2070 | // function without changing the state. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2071 | // We don't know if t2 is a WeakCell or a Symbol, but it's harmless to read at |
| 2072 | // this position in a symbol (see static asserts in type-feedback-vector.h). |
| 2073 | Label check_allocation_site; |
| 2074 | Register feedback_map = t1; |
| 2075 | Register weak_value = t4; |
| 2076 | __ lw(weak_value, FieldMemOperand(t2, WeakCell::kValueOffset)); |
| 2077 | __ Branch(&done, eq, a1, Operand(weak_value)); |
| 2078 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 2079 | __ Branch(&done, eq, t2, Operand(at)); |
| 2080 | __ lw(feedback_map, FieldMemOperand(t2, HeapObject::kMapOffset)); |
| 2081 | __ LoadRoot(at, Heap::kWeakCellMapRootIndex); |
| 2082 | __ Branch(&check_allocation_site, ne, feedback_map, Operand(at)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2083 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2084 | // If the weak cell is cleared, we have a new chance to become monomorphic. |
| 2085 | __ JumpIfSmi(weak_value, &initialize); |
| 2086 | __ jmp(&megamorphic); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2087 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2088 | __ bind(&check_allocation_site); |
| 2089 | // If we came here, we need to see if we are the array function. |
| 2090 | // If we didn't have a matching function, and we didn't find the megamorph |
| 2091 | // sentinel, then we have in the slot either some other function or an |
| 2092 | // AllocationSite. |
| 2093 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 2094 | __ Branch(&miss, ne, feedback_map, Operand(at)); |
| 2095 | |
| 2096 | // Make sure the function is the Array() function |
| 2097 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, t2); |
| 2098 | __ Branch(&megamorphic, ne, a1, Operand(t2)); |
| 2099 | __ jmp(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2100 | |
| 2101 | __ bind(&miss); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2102 | |
| 2103 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 2104 | // megamorphic. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2105 | __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2106 | __ Branch(&initialize, eq, t2, Operand(at)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2107 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 2108 | // write-barrier is needed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2109 | __ bind(&megamorphic); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2110 | __ Lsa(t2, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2111 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2112 | __ sw(at, FieldMemOperand(t2, FixedArray::kHeaderSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2113 | __ jmp(&done); |
| 2114 | |
| 2115 | // An uninitialized cache is patched with the function. |
| 2116 | __ bind(&initialize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2117 | // Make sure the function is the Array() function. |
| 2118 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, t2); |
| 2119 | __ Branch(¬_array_function, ne, a1, Operand(t2)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2120 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2121 | // The target function is the Array constructor, |
| 2122 | // Create an AllocationSite if we don't already have it, store it in the |
| 2123 | // slot. |
| 2124 | CreateAllocationSiteStub create_stub(masm->isolate()); |
| 2125 | CallStubInRecordCallTarget(masm, &create_stub); |
| 2126 | __ Branch(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2127 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2128 | __ bind(¬_array_function); |
| 2129 | CreateWeakCellStub weak_cell_stub(masm->isolate()); |
| 2130 | CallStubInRecordCallTarget(masm, &weak_cell_stub); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2131 | __ bind(&done); |
| 2132 | } |
| 2133 | |
| 2134 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2135 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 2136 | // a0 : number of arguments |
| 2137 | // a1 : the function to call |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2138 | // a2 : feedback vector |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2139 | // a3 : slot in feedback vector (Smi, for RecordCallTarget) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2140 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2141 | Label non_function; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2142 | // Check that the function is not a smi. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2143 | __ JumpIfSmi(a1, &non_function); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2144 | // Check that the function is a JSFunction. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2145 | __ GetObjectType(a1, t1, t1); |
| 2146 | __ Branch(&non_function, ne, t1, Operand(JS_FUNCTION_TYPE)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2147 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2148 | GenerateRecordCallTarget(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2149 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2150 | __ Lsa(t1, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2151 | Label feedback_register_initialized; |
| 2152 | // Put the AllocationSite from the feedback vector into a2, or undefined. |
| 2153 | __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize)); |
| 2154 | __ lw(t1, FieldMemOperand(a2, AllocationSite::kMapOffset)); |
| 2155 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 2156 | __ Branch(&feedback_register_initialized, eq, t1, Operand(at)); |
| 2157 | __ LoadRoot(a2, Heap::kUndefinedValueRootIndex); |
| 2158 | __ bind(&feedback_register_initialized); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2159 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2160 | __ AssertUndefinedOrAllocationSite(a2, t1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2161 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2162 | // Pass function as new target. |
| 2163 | __ mov(a3, a1); |
| 2164 | |
| 2165 | // Tail call to the function-specific construct stub (still in the caller |
| 2166 | // context at this point). |
| 2167 | __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 2168 | __ lw(t0, FieldMemOperand(t0, SharedFunctionInfo::kConstructStubOffset)); |
| 2169 | __ Addu(at, t0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2170 | __ Jump(at); |
| 2171 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2172 | __ bind(&non_function); |
| 2173 | __ mov(a3, a1); |
| 2174 | __ Jump(isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2178 | void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2179 | // a1 - function |
| 2180 | // a3 - slot id |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2181 | // a2 - vector |
| 2182 | // t0 - loaded from vector[slot] |
| 2183 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, at); |
| 2184 | __ Branch(miss, ne, a1, Operand(at)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2185 | |
| 2186 | __ li(a0, Operand(arg_count())); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2187 | |
| 2188 | // Increment the call count for monomorphic function calls. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2189 | __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2190 | __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
| 2191 | __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement))); |
| 2192 | __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2193 | |
| 2194 | __ mov(a2, t0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2195 | __ mov(a3, a1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2196 | ArrayConstructorStub stub(masm->isolate(), arg_count()); |
| 2197 | __ TailCallStub(&stub); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | |
| 2201 | void CallICStub::Generate(MacroAssembler* masm) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2202 | // a1 - function |
| 2203 | // a3 - slot id (Smi) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2204 | // a2 - vector |
| 2205 | Label extra_checks_or_miss, call, call_function; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2206 | int argc = arg_count(); |
| 2207 | ParameterCount actual(argc); |
| 2208 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2209 | // The checks. First, does r1 match the recorded monomorphic target? |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2210 | __ Lsa(t0, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2211 | __ lw(t0, FieldMemOperand(t0, FixedArray::kHeaderSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2212 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2213 | // We don't know that we have a weak cell. We might have a private symbol |
| 2214 | // or an AllocationSite, but the memory is safe to examine. |
| 2215 | // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to |
| 2216 | // FixedArray. |
| 2217 | // WeakCell::kValueOffset - contains a JSFunction or Smi(0) |
| 2218 | // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not |
| 2219 | // computed, meaning that it can't appear to be a pointer. If the low bit is |
| 2220 | // 0, then hash is computed, but the 0 bit prevents the field from appearing |
| 2221 | // to be a pointer. |
| 2222 | STATIC_ASSERT(WeakCell::kSize >= kPointerSize); |
| 2223 | STATIC_ASSERT(AllocationSite::kTransitionInfoOffset == |
| 2224 | WeakCell::kValueOffset && |
| 2225 | WeakCell::kValueOffset == Symbol::kHashFieldSlot); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2226 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2227 | __ lw(t1, FieldMemOperand(t0, WeakCell::kValueOffset)); |
| 2228 | __ Branch(&extra_checks_or_miss, ne, a1, Operand(t1)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2229 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2230 | // The compare above could have been a SMI/SMI comparison. Guard against this |
| 2231 | // convincing us that we have a monomorphic JSFunction. |
| 2232 | __ JumpIfSmi(a1, &extra_checks_or_miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2233 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2234 | // Increment the call count for monomorphic function calls. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2235 | __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2236 | __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
| 2237 | __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement))); |
| 2238 | __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2239 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2240 | __ bind(&call_function); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2241 | __ Jump(masm->isolate()->builtins()->CallFunction(convert_mode(), |
| 2242 | tail_call_mode()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2243 | RelocInfo::CODE_TARGET, al, zero_reg, Operand(zero_reg), |
| 2244 | USE_DELAY_SLOT); |
| 2245 | __ li(a0, Operand(argc)); // In delay slot. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2246 | |
| 2247 | __ bind(&extra_checks_or_miss); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2248 | Label uninitialized, miss, not_allocation_site; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2249 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2250 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2251 | __ Branch(&call, eq, t0, Operand(at)); |
| 2252 | |
| 2253 | // Verify that t0 contains an AllocationSite |
| 2254 | __ lw(t1, FieldMemOperand(t0, HeapObject::kMapOffset)); |
| 2255 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 2256 | __ Branch(¬_allocation_site, ne, t1, Operand(at)); |
| 2257 | |
| 2258 | HandleArrayCase(masm, &miss); |
| 2259 | |
| 2260 | __ bind(¬_allocation_site); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2261 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2262 | // The following cases attempt to handle MISS cases without going to the |
| 2263 | // runtime. |
| 2264 | if (FLAG_trace_ic) { |
| 2265 | __ Branch(&miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2266 | } |
| 2267 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2268 | __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex); |
| 2269 | __ Branch(&uninitialized, eq, t0, Operand(at)); |
| 2270 | |
| 2271 | // We are going megamorphic. If the feedback is a JSFunction, it is fine |
| 2272 | // to handle it here. More complex cases are dealt with in the runtime. |
| 2273 | __ AssertNotSmi(t0); |
| 2274 | __ GetObjectType(t0, t1, t1); |
| 2275 | __ Branch(&miss, ne, t1, Operand(JS_FUNCTION_TYPE)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2276 | __ Lsa(t0, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2277 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 2278 | __ sw(at, FieldMemOperand(t0, FixedArray::kHeaderSize)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2279 | |
| 2280 | __ bind(&call); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2281 | __ Jump(masm->isolate()->builtins()->Call(convert_mode(), tail_call_mode()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2282 | RelocInfo::CODE_TARGET, al, zero_reg, Operand(zero_reg), |
| 2283 | USE_DELAY_SLOT); |
| 2284 | __ li(a0, Operand(argc)); // In delay slot. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2285 | |
| 2286 | __ bind(&uninitialized); |
| 2287 | |
| 2288 | // We are going monomorphic, provided we actually have a JSFunction. |
| 2289 | __ JumpIfSmi(a1, &miss); |
| 2290 | |
| 2291 | // Goto miss case if we do not have a function. |
| 2292 | __ GetObjectType(a1, t0, t0); |
| 2293 | __ Branch(&miss, ne, t0, Operand(JS_FUNCTION_TYPE)); |
| 2294 | |
| 2295 | // Make sure the function is not the Array() function, which requires special |
| 2296 | // behavior on MISS. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2297 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, t0); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2298 | __ Branch(&miss, eq, a1, Operand(t0)); |
| 2299 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2300 | // Make sure the function belongs to the same native context. |
| 2301 | __ lw(t0, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 2302 | __ lw(t0, ContextMemOperand(t0, Context::NATIVE_CONTEXT_INDEX)); |
| 2303 | __ lw(t1, NativeContextMemOperand()); |
| 2304 | __ Branch(&miss, ne, t0, Operand(t1)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2305 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2306 | // Initialize the call counter. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2307 | __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2308 | __ li(t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement))); |
| 2309 | __ sw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2310 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2311 | // Store the function. Use a stub since we need a frame for allocation. |
| 2312 | // a2 - vector |
| 2313 | // a3 - slot |
| 2314 | // a1 - function |
| 2315 | { |
| 2316 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2317 | CreateWeakCellStub create_stub(masm->isolate()); |
| 2318 | __ Push(a1); |
| 2319 | __ CallStub(&create_stub); |
| 2320 | __ Pop(a1); |
| 2321 | } |
| 2322 | |
| 2323 | __ Branch(&call_function); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2324 | |
| 2325 | // We are here because tracing is on or we encountered a MISS case we can't |
| 2326 | // handle here. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2327 | __ bind(&miss); |
| 2328 | GenerateMiss(masm); |
| 2329 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2330 | __ Branch(&call); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2334 | void CallICStub::GenerateMiss(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2335 | FrameScope scope(masm, StackFrame::INTERNAL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2336 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2337 | // Push the receiver and the function and feedback info. |
| 2338 | __ Push(a1, a2, a3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2339 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2340 | // Call the entry. |
| 2341 | __ CallRuntime(Runtime::kCallIC_Miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2342 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2343 | // Move result to a1 and exit the internal frame. |
| 2344 | __ mov(a1, v0); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2348 | // StringCharCodeAtGenerator. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2349 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2350 | DCHECK(!t0.is(index_)); |
| 2351 | DCHECK(!t0.is(result_)); |
| 2352 | DCHECK(!t0.is(object_)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2353 | if (check_mode_ == RECEIVER_IS_UNKNOWN) { |
| 2354 | // If the receiver is a smi trigger the non-string case. |
| 2355 | __ JumpIfSmi(object_, receiver_not_string_); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2356 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2357 | // Fetch the instance type of the receiver into result register. |
| 2358 | __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 2359 | __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 2360 | // If the receiver is not a string trigger the non-string case. |
| 2361 | __ And(t0, result_, Operand(kIsNotStringMask)); |
| 2362 | __ Branch(receiver_not_string_, ne, t0, Operand(zero_reg)); |
| 2363 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2364 | |
| 2365 | // If the index is non-smi trigger the non-smi case. |
| 2366 | __ JumpIfNotSmi(index_, &index_not_smi_); |
| 2367 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2368 | __ bind(&got_smi_index_); |
| 2369 | |
| 2370 | // Check for index out of range. |
| 2371 | __ lw(t0, FieldMemOperand(object_, String::kLengthOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2372 | __ Branch(index_out_of_range_, ls, t0, Operand(index_)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2373 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2374 | __ sra(index_, index_, kSmiTagSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2375 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2376 | StringCharLoadGenerator::Generate(masm, |
| 2377 | object_, |
| 2378 | index_, |
| 2379 | result_, |
| 2380 | &call_runtime_); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2381 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2382 | __ sll(result_, result_, kSmiTagSize); |
| 2383 | __ bind(&exit_); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | |
| 2387 | void StringCharCodeAtGenerator::GenerateSlow( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2388 | MacroAssembler* masm, EmbedMode embed_mode, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2389 | const RuntimeCallHelper& call_helper) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2390 | __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2391 | |
| 2392 | // Index is not a smi. |
| 2393 | __ bind(&index_not_smi_); |
| 2394 | // If index is a heap number, try converting it to an integer. |
| 2395 | __ CheckMap(index_, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2396 | result_, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2397 | Heap::kHeapNumberMapRootIndex, |
| 2398 | index_not_number_, |
| 2399 | DONT_DO_SMI_CHECK); |
| 2400 | call_helper.BeforeCall(masm); |
| 2401 | // Consumed by runtime conversion function: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2402 | if (embed_mode == PART_OF_IC_HANDLER) { |
| 2403 | __ Push(LoadWithVectorDescriptor::VectorRegister(), |
| 2404 | LoadWithVectorDescriptor::SlotRegister(), object_, index_); |
| 2405 | } else { |
| 2406 | __ Push(object_, index_); |
| 2407 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2408 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2409 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2410 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2411 | DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2412 | // NumberToSmi discards numbers that are not exact integers. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2413 | __ CallRuntime(Runtime::kNumberToSmi); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | // Save the conversion result before the pop instructions below |
| 2417 | // have a chance to overwrite it. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2418 | __ Move(index_, v0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2419 | if (embed_mode == PART_OF_IC_HANDLER) { |
| 2420 | __ Pop(LoadWithVectorDescriptor::VectorRegister(), |
| 2421 | LoadWithVectorDescriptor::SlotRegister(), object_); |
| 2422 | } else { |
| 2423 | __ pop(object_); |
| 2424 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2425 | // Reload the instance type. |
| 2426 | __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 2427 | __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 2428 | call_helper.AfterCall(masm); |
| 2429 | // 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] | 2430 | __ JumpIfNotSmi(index_, index_out_of_range_); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2431 | // Otherwise, return to the fast path. |
| 2432 | __ Branch(&got_smi_index_); |
| 2433 | |
| 2434 | // Call runtime. We get here when the receiver is a string and the |
| 2435 | // index is a number, but the code of getting the actual character |
| 2436 | // is too complex (e.g., when the string needs to be flattened). |
| 2437 | __ bind(&call_runtime_); |
| 2438 | call_helper.BeforeCall(masm); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2439 | __ sll(index_, index_, kSmiTagSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2440 | __ Push(object_, index_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2441 | __ CallRuntime(Runtime::kStringCharCodeAtRT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2442 | |
| 2443 | __ Move(result_, v0); |
| 2444 | |
| 2445 | call_helper.AfterCall(masm); |
| 2446 | __ jmp(&exit_); |
| 2447 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2448 | __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | |
| 2452 | // ------------------------------------------------------------------------- |
| 2453 | // StringCharFromCodeGenerator |
| 2454 | |
| 2455 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2456 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 2457 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2458 | DCHECK(!t0.is(result_)); |
| 2459 | DCHECK(!t0.is(code_)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2460 | |
| 2461 | STATIC_ASSERT(kSmiTag == 0); |
| 2462 | STATIC_ASSERT(kSmiShiftSize == 0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2463 | DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1)); |
| 2464 | __ And(t0, code_, Operand(kSmiTagMask | |
| 2465 | ((~String::kMaxOneByteCharCodeU) << kSmiTagSize))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2466 | __ Branch(&slow_case_, ne, t0, Operand(zero_reg)); |
| 2467 | |
| 2468 | __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2469 | // At this point code register contains smi tagged one-byte char code. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2470 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2471 | __ Lsa(result_, result_, code_, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2472 | __ lw(result_, FieldMemOperand(result_, FixedArray::kHeaderSize)); |
| 2473 | __ LoadRoot(t0, Heap::kUndefinedValueRootIndex); |
| 2474 | __ Branch(&slow_case_, eq, result_, Operand(t0)); |
| 2475 | __ bind(&exit_); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | |
| 2479 | void StringCharFromCodeGenerator::GenerateSlow( |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2480 | MacroAssembler* masm, |
| 2481 | const RuntimeCallHelper& call_helper) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2482 | __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2483 | |
| 2484 | __ bind(&slow_case_); |
| 2485 | call_helper.BeforeCall(masm); |
| 2486 | __ push(code_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2487 | __ CallRuntime(Runtime::kStringCharFromCode); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2488 | __ Move(result_, v0); |
| 2489 | |
| 2490 | call_helper.AfterCall(masm); |
| 2491 | __ Branch(&exit_); |
| 2492 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2493 | __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2497 | enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2498 | |
| 2499 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2500 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 2501 | Register dest, |
| 2502 | Register src, |
| 2503 | Register count, |
| 2504 | Register scratch, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2505 | String::Encoding encoding) { |
| 2506 | if (FLAG_debug_code) { |
| 2507 | // Check that destination is word aligned. |
| 2508 | __ And(scratch, dest, Operand(kPointerAlignmentMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2509 | __ Check(eq, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2510 | kDestinationOfCopyNotAligned, |
| 2511 | scratch, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2512 | Operand(zero_reg)); |
| 2513 | } |
| 2514 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2515 | // Assumes word reads and writes are little endian. |
| 2516 | // Nothing to do for zero characters. |
| 2517 | Label done; |
| 2518 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2519 | if (encoding == String::TWO_BYTE_ENCODING) { |
| 2520 | __ Addu(count, count, count); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2521 | } |
| 2522 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2523 | Register limit = count; // Read until dest equals this. |
| 2524 | __ Addu(limit, dest, Operand(count)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2525 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2526 | Label loop_entry, loop; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2527 | // Copy bytes from src to dest until dest hits limit. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2528 | __ Branch(&loop_entry); |
| 2529 | __ bind(&loop); |
| 2530 | __ lbu(scratch, MemOperand(src)); |
| 2531 | __ Addu(src, src, Operand(1)); |
| 2532 | __ sb(scratch, MemOperand(dest)); |
| 2533 | __ Addu(dest, dest, Operand(1)); |
| 2534 | __ bind(&loop_entry); |
| 2535 | __ Branch(&loop, lt, dest, Operand(limit)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2536 | |
| 2537 | __ bind(&done); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2541 | void SubStringStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2542 | Label runtime; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2543 | // Stack frame on entry. |
| 2544 | // ra: return address |
| 2545 | // sp[0]: to |
| 2546 | // sp[4]: from |
| 2547 | // sp[8]: string |
| 2548 | |
| 2549 | // This stub is called from the native-call %_SubString(...), so |
| 2550 | // nothing can be assumed about the arguments. It is tested that: |
| 2551 | // "string" is a sequential string, |
| 2552 | // both "from" and "to" are smis, and |
| 2553 | // 0 <= from <= to <= string.length. |
| 2554 | // If any of these assumptions fail, we call the runtime system. |
| 2555 | |
Ben Murdoch | db1b438 | 2012-04-26 19:03:50 +0100 | [diff] [blame] | 2556 | const int kToOffset = 0 * kPointerSize; |
| 2557 | const int kFromOffset = 1 * kPointerSize; |
| 2558 | const int kStringOffset = 2 * kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2559 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2560 | __ lw(a2, MemOperand(sp, kToOffset)); |
| 2561 | __ lw(a3, MemOperand(sp, kFromOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2562 | STATIC_ASSERT(kFromOffset == kToOffset + 4); |
| 2563 | STATIC_ASSERT(kSmiTag == 0); |
| 2564 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 2565 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2566 | // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is |
| 2567 | // safe in this case. |
| 2568 | __ UntagAndJumpIfNotSmi(a2, a2, &runtime); |
| 2569 | __ UntagAndJumpIfNotSmi(a3, a3, &runtime); |
| 2570 | // Both a2 and a3 are untagged integers. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2571 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2572 | __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2573 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2574 | __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to. |
| 2575 | __ Subu(a2, a2, a3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2576 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2577 | // Make sure first argument is a string. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2578 | __ lw(v0, MemOperand(sp, kStringOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2579 | __ JumpIfSmi(v0, &runtime); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2580 | __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2581 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2582 | __ And(t0, a1, Operand(kIsNotStringMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2583 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2584 | __ Branch(&runtime, ne, t0, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2585 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2586 | Label single_char; |
| 2587 | __ Branch(&single_char, eq, a2, Operand(1)); |
| 2588 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2589 | // Short-cut for the case of trivial substring. |
| 2590 | Label return_v0; |
| 2591 | // v0: original string |
| 2592 | // a2: result string length |
| 2593 | __ lw(t0, FieldMemOperand(v0, String::kLengthOffset)); |
| 2594 | __ sra(t0, t0, 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2595 | // Return original string. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2596 | __ Branch(&return_v0, eq, a2, Operand(t0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2597 | // Longer than original string's length or negative: unsafe arguments. |
| 2598 | __ Branch(&runtime, hi, a2, Operand(t0)); |
| 2599 | // Shorter than original string's length: an actual substring. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2600 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2601 | // Deal with different string types: update the index if necessary |
| 2602 | // and put the underlying string into t1. |
| 2603 | // v0: original string |
| 2604 | // a1: instance type |
| 2605 | // a2: length |
| 2606 | // a3: from index (untagged) |
| 2607 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 2608 | // If the string is not indirect, it can only be sequential or external. |
| 2609 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 2610 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 2611 | __ And(t0, a1, Operand(kIsIndirectStringMask)); |
| 2612 | __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, t0, Operand(zero_reg)); |
| 2613 | // t0 is used as a scratch register and can be overwritten in either case. |
| 2614 | __ And(t0, a1, Operand(kSlicedNotConsMask)); |
| 2615 | __ Branch(&sliced_string, ne, t0, Operand(zero_reg)); |
| 2616 | // Cons string. Check whether it is flat, then fetch first part. |
| 2617 | __ lw(t1, FieldMemOperand(v0, ConsString::kSecondOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2618 | __ LoadRoot(t0, Heap::kempty_stringRootIndex); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2619 | __ Branch(&runtime, ne, t1, Operand(t0)); |
| 2620 | __ lw(t1, FieldMemOperand(v0, ConsString::kFirstOffset)); |
| 2621 | // Update instance type. |
| 2622 | __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset)); |
| 2623 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
| 2624 | __ jmp(&underlying_unpacked); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2625 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2626 | __ bind(&sliced_string); |
| 2627 | // Sliced string. Fetch parent and correct start index by offset. |
| 2628 | __ lw(t1, FieldMemOperand(v0, SlicedString::kParentOffset)); |
| 2629 | __ lw(t0, FieldMemOperand(v0, SlicedString::kOffsetOffset)); |
| 2630 | __ sra(t0, t0, 1); // Add offset to index. |
| 2631 | __ Addu(a3, a3, t0); |
| 2632 | // Update instance type. |
| 2633 | __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset)); |
| 2634 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
| 2635 | __ jmp(&underlying_unpacked); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2636 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2637 | __ bind(&seq_or_external_string); |
| 2638 | // Sequential or external string. Just move string to the expected register. |
| 2639 | __ mov(t1, v0); |
| 2640 | |
| 2641 | __ bind(&underlying_unpacked); |
| 2642 | |
| 2643 | if (FLAG_string_slices) { |
| 2644 | Label copy_routine; |
| 2645 | // t1: underlying subject string |
| 2646 | // a1: instance type of underlying subject string |
| 2647 | // a2: length |
| 2648 | // a3: adjusted start index (untagged) |
| 2649 | // Short slice. Copy instead of slicing. |
| 2650 | __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength)); |
| 2651 | // Allocate new sliced string. At this point we do not reload the instance |
| 2652 | // type including the string encoding because we simply rely on the info |
| 2653 | // provided by the original string. It does not matter if the original |
| 2654 | // string's encoding is wrong because we always have to recheck encoding of |
| 2655 | // the newly created string's parent anyways due to externalized strings. |
| 2656 | Label two_byte_slice, set_slice_header; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2657 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2658 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 2659 | __ And(t0, a1, Operand(kStringEncodingMask)); |
| 2660 | __ Branch(&two_byte_slice, eq, t0, Operand(zero_reg)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2661 | __ AllocateOneByteSlicedString(v0, a2, t2, t3, &runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2662 | __ jmp(&set_slice_header); |
| 2663 | __ bind(&two_byte_slice); |
| 2664 | __ AllocateTwoByteSlicedString(v0, a2, t2, t3, &runtime); |
| 2665 | __ bind(&set_slice_header); |
| 2666 | __ sll(a3, a3, 1); |
| 2667 | __ sw(t1, FieldMemOperand(v0, SlicedString::kParentOffset)); |
| 2668 | __ sw(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset)); |
| 2669 | __ jmp(&return_v0); |
| 2670 | |
| 2671 | __ bind(©_routine); |
| 2672 | } |
| 2673 | |
| 2674 | // t1: underlying subject string |
| 2675 | // a1: instance type of underlying subject string |
| 2676 | // a2: length |
| 2677 | // a3: adjusted start index (untagged) |
| 2678 | Label two_byte_sequential, sequential_string, allocate_result; |
| 2679 | STATIC_ASSERT(kExternalStringTag != 0); |
| 2680 | STATIC_ASSERT(kSeqStringTag == 0); |
| 2681 | __ And(t0, a1, Operand(kExternalStringTag)); |
| 2682 | __ Branch(&sequential_string, eq, t0, Operand(zero_reg)); |
| 2683 | |
| 2684 | // Handle external string. |
| 2685 | // Rule out short external strings. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2686 | STATIC_ASSERT(kShortExternalStringTag != 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2687 | __ And(t0, a1, Operand(kShortExternalStringTag)); |
| 2688 | __ Branch(&runtime, ne, t0, Operand(zero_reg)); |
| 2689 | __ lw(t1, FieldMemOperand(t1, ExternalString::kResourceDataOffset)); |
| 2690 | // t1 already points to the first character of underlying string. |
| 2691 | __ jmp(&allocate_result); |
| 2692 | |
| 2693 | __ bind(&sequential_string); |
| 2694 | // Locate first character of underlying subject string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2695 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
| 2696 | __ Addu(t1, t1, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2697 | |
| 2698 | __ bind(&allocate_result); |
| 2699 | // Sequential acii string. Allocate the result. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2700 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2701 | __ And(t0, a1, Operand(kStringEncodingMask)); |
| 2702 | __ Branch(&two_byte_sequential, eq, t0, Operand(zero_reg)); |
| 2703 | |
| 2704 | // Allocate and copy the resulting ASCII string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2705 | __ AllocateOneByteString(v0, a2, t0, t2, t3, &runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2706 | |
| 2707 | // Locate first character of substring to copy. |
| 2708 | __ Addu(t1, t1, a3); |
| 2709 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2710 | // Locate first character of result. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2711 | __ Addu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2712 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2713 | // v0: result string |
| 2714 | // a1: first character of result string |
| 2715 | // a2: result string length |
| 2716 | // t1: first character of substring to copy |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2717 | STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 2718 | StringHelper::GenerateCopyCharacters( |
| 2719 | masm, a1, t1, a2, a3, String::ONE_BYTE_ENCODING); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2720 | __ jmp(&return_v0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2721 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2722 | // Allocate and copy the resulting two-byte string. |
| 2723 | __ bind(&two_byte_sequential); |
| 2724 | __ AllocateTwoByteString(v0, a2, t0, t2, t3, &runtime); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2725 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2726 | // Locate first character of substring to copy. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2727 | STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2728 | __ Lsa(t1, t1, a3, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2729 | // Locate first character of result. |
| 2730 | __ Addu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2731 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2732 | // v0: result string. |
| 2733 | // a1: first character of result. |
| 2734 | // a2: result length. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2735 | // t1: first character of substring to copy. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2736 | STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2737 | StringHelper::GenerateCopyCharacters( |
| 2738 | masm, a1, t1, a2, a3, String::TWO_BYTE_ENCODING); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2739 | |
| 2740 | __ bind(&return_v0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2741 | Counters* counters = isolate()->counters(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2742 | __ IncrementCounter(counters->sub_string_native(), 1, a3, t0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2743 | __ DropAndRet(3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2744 | |
| 2745 | // Just jump to runtime to create the sub string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2746 | __ bind(&runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2747 | __ TailCallRuntime(Runtime::kSubString); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2748 | |
| 2749 | __ bind(&single_char); |
| 2750 | // v0: original string |
| 2751 | // a1: instance type |
| 2752 | // a2: length |
| 2753 | // a3: from index (untagged) |
| 2754 | __ SmiTag(a3, a3); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2755 | StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime, |
| 2756 | STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2757 | generator.GenerateFast(masm); |
| 2758 | __ DropAndRet(3); |
| 2759 | generator.SkipSlow(masm, &runtime); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2763 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 2764 | // The ToNumber stub takes one argument in a0. |
| 2765 | Label not_smi; |
| 2766 | __ JumpIfNotSmi(a0, ¬_smi); |
| 2767 | __ Ret(USE_DELAY_SLOT); |
| 2768 | __ mov(v0, a0); |
| 2769 | __ bind(¬_smi); |
| 2770 | |
| 2771 | Label not_heap_number; |
| 2772 | __ lw(a1, FieldMemOperand(a0, HeapObject::kMapOffset)); |
| 2773 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
| 2774 | // a0: object |
| 2775 | // a1: instance type. |
| 2776 | __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE)); |
| 2777 | __ Ret(USE_DELAY_SLOT); |
| 2778 | __ mov(v0, a0); |
| 2779 | __ bind(¬_heap_number); |
| 2780 | |
| 2781 | Label not_string, slow_string; |
| 2782 | __ Branch(¬_string, hs, a1, Operand(FIRST_NONSTRING_TYPE)); |
| 2783 | // Check if string has a cached array index. |
| 2784 | __ lw(a2, FieldMemOperand(a0, String::kHashFieldOffset)); |
| 2785 | __ And(at, a2, Operand(String::kContainsCachedArrayIndexMask)); |
| 2786 | __ Branch(&slow_string, ne, at, Operand(zero_reg)); |
| 2787 | __ IndexFromHash(a2, a0); |
| 2788 | __ Ret(USE_DELAY_SLOT); |
| 2789 | __ mov(v0, a0); |
| 2790 | __ bind(&slow_string); |
| 2791 | __ push(a0); // Push argument. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2792 | __ TailCallRuntime(Runtime::kStringToNumber); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2793 | __ bind(¬_string); |
| 2794 | |
| 2795 | Label not_oddball; |
| 2796 | __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE)); |
| 2797 | __ Ret(USE_DELAY_SLOT); |
| 2798 | __ lw(v0, FieldMemOperand(a0, Oddball::kToNumberOffset)); |
| 2799 | __ bind(¬_oddball); |
| 2800 | |
| 2801 | __ push(a0); // Push argument. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2802 | __ TailCallRuntime(Runtime::kToNumber); |
| 2803 | } |
| 2804 | |
| 2805 | |
| 2806 | void ToLengthStub::Generate(MacroAssembler* masm) { |
| 2807 | // The ToLength stub takes on argument in a0. |
| 2808 | Label not_smi, positive_smi; |
| 2809 | __ JumpIfNotSmi(a0, ¬_smi); |
| 2810 | STATIC_ASSERT(kSmiTag == 0); |
| 2811 | __ Branch(&positive_smi, ge, a0, Operand(zero_reg)); |
| 2812 | __ mov(a0, zero_reg); |
| 2813 | __ bind(&positive_smi); |
| 2814 | __ Ret(USE_DELAY_SLOT); |
| 2815 | __ mov(v0, a0); |
| 2816 | __ bind(¬_smi); |
| 2817 | |
| 2818 | __ push(a0); // Push argument. |
| 2819 | __ TailCallRuntime(Runtime::kToLength); |
| 2820 | } |
| 2821 | |
| 2822 | |
| 2823 | void ToStringStub::Generate(MacroAssembler* masm) { |
| 2824 | // The ToString stub takes on argument in a0. |
| 2825 | Label is_number; |
| 2826 | __ JumpIfSmi(a0, &is_number); |
| 2827 | |
| 2828 | Label not_string; |
| 2829 | __ GetObjectType(a0, a1, a1); |
| 2830 | // a0: receiver |
| 2831 | // a1: receiver instance type |
| 2832 | __ Branch(¬_string, ge, a1, Operand(FIRST_NONSTRING_TYPE)); |
| 2833 | __ Ret(USE_DELAY_SLOT); |
| 2834 | __ mov(v0, a0); |
| 2835 | __ bind(¬_string); |
| 2836 | |
| 2837 | Label not_heap_number; |
| 2838 | __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE)); |
| 2839 | __ bind(&is_number); |
| 2840 | NumberToStringStub stub(isolate()); |
| 2841 | __ TailCallStub(&stub); |
| 2842 | __ bind(¬_heap_number); |
| 2843 | |
| 2844 | Label not_oddball; |
| 2845 | __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE)); |
| 2846 | __ Ret(USE_DELAY_SLOT); |
| 2847 | __ lw(v0, FieldMemOperand(a0, Oddball::kToStringOffset)); |
| 2848 | __ bind(¬_oddball); |
| 2849 | |
| 2850 | __ push(a0); // Push argument. |
| 2851 | __ TailCallRuntime(Runtime::kToString); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2855 | void ToNameStub::Generate(MacroAssembler* masm) { |
| 2856 | // The ToName stub takes on argument in a0. |
| 2857 | Label is_number; |
| 2858 | __ JumpIfSmi(a0, &is_number); |
| 2859 | |
| 2860 | Label not_name; |
| 2861 | STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE); |
| 2862 | __ GetObjectType(a0, a1, a1); |
| 2863 | // a0: receiver |
| 2864 | // a1: receiver instance type |
| 2865 | __ Branch(¬_name, gt, a1, Operand(LAST_NAME_TYPE)); |
| 2866 | __ Ret(USE_DELAY_SLOT); |
| 2867 | __ mov(v0, a0); |
| 2868 | __ bind(¬_name); |
| 2869 | |
| 2870 | Label not_heap_number; |
| 2871 | __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE)); |
| 2872 | __ bind(&is_number); |
| 2873 | NumberToStringStub stub(isolate()); |
| 2874 | __ TailCallStub(&stub); |
| 2875 | __ bind(¬_heap_number); |
| 2876 | |
| 2877 | Label not_oddball; |
| 2878 | __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE)); |
| 2879 | __ Ret(USE_DELAY_SLOT); |
| 2880 | __ lw(v0, FieldMemOperand(a0, Oddball::kToStringOffset)); |
| 2881 | __ bind(¬_oddball); |
| 2882 | |
| 2883 | __ push(a0); // Push argument. |
| 2884 | __ TailCallRuntime(Runtime::kToName); |
| 2885 | } |
| 2886 | |
| 2887 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2888 | void StringHelper::GenerateFlatOneByteStringEquals( |
| 2889 | MacroAssembler* masm, Register left, Register right, Register scratch1, |
| 2890 | Register scratch2, Register scratch3) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2891 | Register length = scratch1; |
| 2892 | |
| 2893 | // Compare lengths. |
| 2894 | Label strings_not_equal, check_zero_length; |
| 2895 | __ lw(length, FieldMemOperand(left, String::kLengthOffset)); |
| 2896 | __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 2897 | __ Branch(&check_zero_length, eq, length, Operand(scratch2)); |
| 2898 | __ bind(&strings_not_equal); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2899 | DCHECK(is_int16(NOT_EQUAL)); |
| 2900 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2901 | __ li(v0, Operand(Smi::FromInt(NOT_EQUAL))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2902 | |
| 2903 | // Check if the length is zero. |
| 2904 | Label compare_chars; |
| 2905 | __ bind(&check_zero_length); |
| 2906 | STATIC_ASSERT(kSmiTag == 0); |
| 2907 | __ Branch(&compare_chars, ne, length, Operand(zero_reg)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2908 | DCHECK(is_int16(EQUAL)); |
| 2909 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2910 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2911 | |
| 2912 | // Compare characters. |
| 2913 | __ bind(&compare_chars); |
| 2914 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2915 | GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3, |
| 2916 | v0, &strings_not_equal); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2917 | |
| 2918 | // Characters are equal. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2919 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2920 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2924 | void StringHelper::GenerateCompareFlatOneByteStrings( |
| 2925 | MacroAssembler* masm, Register left, Register right, Register scratch1, |
| 2926 | Register scratch2, Register scratch3, Register scratch4) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2927 | Label result_not_equal, compare_lengths; |
| 2928 | // Find minimum length and length difference. |
| 2929 | __ lw(scratch1, FieldMemOperand(left, String::kLengthOffset)); |
| 2930 | __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 2931 | __ Subu(scratch3, scratch1, Operand(scratch2)); |
| 2932 | Register length_delta = scratch3; |
| 2933 | __ slt(scratch4, scratch2, scratch1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2934 | __ Movn(scratch1, scratch2, scratch4); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2935 | Register min_length = scratch1; |
| 2936 | STATIC_ASSERT(kSmiTag == 0); |
| 2937 | __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg)); |
| 2938 | |
| 2939 | // Compare loop. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2940 | GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2, |
| 2941 | scratch4, v0, &result_not_equal); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2942 | |
| 2943 | // Compare lengths - strings up to min-length are equal. |
| 2944 | __ bind(&compare_lengths); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2945 | DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2946 | // Use length_delta as result if it's zero. |
| 2947 | __ mov(scratch2, length_delta); |
| 2948 | __ mov(scratch4, zero_reg); |
| 2949 | __ mov(v0, zero_reg); |
| 2950 | |
| 2951 | __ bind(&result_not_equal); |
| 2952 | // Conditionally update the result based either on length_delta or |
| 2953 | // the last comparion performed in the loop above. |
| 2954 | Label ret; |
| 2955 | __ Branch(&ret, eq, scratch2, Operand(scratch4)); |
| 2956 | __ li(v0, Operand(Smi::FromInt(GREATER))); |
| 2957 | __ Branch(&ret, gt, scratch2, Operand(scratch4)); |
| 2958 | __ li(v0, Operand(Smi::FromInt(LESS))); |
| 2959 | __ bind(&ret); |
| 2960 | __ Ret(); |
| 2961 | } |
| 2962 | |
| 2963 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2964 | void StringHelper::GenerateOneByteCharsCompareLoop( |
| 2965 | MacroAssembler* masm, Register left, Register right, Register length, |
| 2966 | Register scratch1, Register scratch2, Register scratch3, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2967 | Label* chars_not_equal) { |
| 2968 | // Change index to run from -length to -1 by adding length to string |
| 2969 | // start. This means that loop ends when index reaches zero, which |
| 2970 | // doesn't need an additional compare. |
| 2971 | __ SmiUntag(length); |
| 2972 | __ Addu(scratch1, length, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2973 | Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2974 | __ Addu(left, left, Operand(scratch1)); |
| 2975 | __ Addu(right, right, Operand(scratch1)); |
| 2976 | __ Subu(length, zero_reg, length); |
| 2977 | Register index = length; // index = -length; |
| 2978 | |
| 2979 | |
| 2980 | // Compare loop. |
| 2981 | Label loop; |
| 2982 | __ bind(&loop); |
| 2983 | __ Addu(scratch3, left, index); |
| 2984 | __ lbu(scratch1, MemOperand(scratch3)); |
| 2985 | __ Addu(scratch3, right, index); |
| 2986 | __ lbu(scratch2, MemOperand(scratch3)); |
| 2987 | __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2)); |
| 2988 | __ Addu(index, index, 1); |
| 2989 | __ Branch(&loop, ne, index, Operand(zero_reg)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2990 | } |
| 2991 | |
| 2992 | |
| 2993 | void StringCompareStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2994 | // ----------- S t a t e ------------- |
| 2995 | // -- a1 : left |
| 2996 | // -- a0 : right |
| 2997 | // -- ra : return address |
| 2998 | // ----------------------------------- |
| 2999 | __ AssertString(a1); |
| 3000 | __ AssertString(a0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3001 | |
| 3002 | Label not_same; |
| 3003 | __ Branch(¬_same, ne, a0, Operand(a1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3004 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3005 | __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a1, |
| 3006 | a2); |
| 3007 | __ Ret(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3008 | |
| 3009 | __ bind(¬_same); |
| 3010 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3011 | // Check that both objects are sequential one-byte strings. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3012 | Label runtime; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3013 | __ JumpIfNotBothSequentialOneByteStrings(a1, a0, a2, a3, &runtime); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3014 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3015 | // Compare flat ASCII strings natively. |
| 3016 | __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2, |
| 3017 | a3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3018 | StringHelper::GenerateCompareFlatOneByteStrings(masm, a1, a0, a2, a3, t0, t1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3019 | |
| 3020 | __ bind(&runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3021 | __ Push(a1, a0); |
| 3022 | __ TailCallRuntime(Runtime::kStringCompare); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3023 | } |
| 3024 | |
| 3025 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3026 | void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) { |
| 3027 | // ----------- S t a t e ------------- |
| 3028 | // -- a1 : left |
| 3029 | // -- a0 : right |
| 3030 | // -- ra : return address |
| 3031 | // ----------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3032 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3033 | // Load a2 with the allocation site. We stick an undefined dummy value here |
| 3034 | // and replace it with the real allocation site later when we instantiate this |
| 3035 | // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate(). |
| 3036 | __ li(a2, handle(isolate()->heap()->undefined_value())); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3037 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3038 | // Make sure that we actually patched the allocation site. |
| 3039 | if (FLAG_debug_code) { |
| 3040 | __ And(at, a2, Operand(kSmiTagMask)); |
| 3041 | __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg)); |
| 3042 | __ lw(t0, FieldMemOperand(a2, HeapObject::kMapOffset)); |
| 3043 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 3044 | __ Assert(eq, kExpectedAllocationSite, t0, Operand(at)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3045 | } |
| 3046 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3047 | // Tail call into the stub that handles binary operations with allocation |
| 3048 | // sites. |
| 3049 | BinaryOpWithAllocationSiteStub stub(isolate(), state()); |
| 3050 | __ TailCallStub(&stub); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3051 | } |
| 3052 | |
| 3053 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3054 | void CompareICStub::GenerateBooleans(MacroAssembler* masm) { |
| 3055 | DCHECK_EQ(CompareICState::BOOLEAN, state()); |
| 3056 | Label miss; |
| 3057 | |
| 3058 | __ CheckMap(a1, a2, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK); |
| 3059 | __ CheckMap(a0, a3, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3060 | if (!Token::IsEqualityOp(op())) { |
| 3061 | __ lw(a1, FieldMemOperand(a1, Oddball::kToNumberOffset)); |
| 3062 | __ AssertSmi(a1); |
| 3063 | __ lw(a0, FieldMemOperand(a0, Oddball::kToNumberOffset)); |
| 3064 | __ AssertSmi(a0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3065 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3066 | __ Ret(USE_DELAY_SLOT); |
| 3067 | __ Subu(v0, a1, a0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3068 | |
| 3069 | __ bind(&miss); |
| 3070 | GenerateMiss(masm); |
| 3071 | } |
| 3072 | |
| 3073 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3074 | void CompareICStub::GenerateSmis(MacroAssembler* masm) { |
| 3075 | DCHECK(state() == CompareICState::SMI); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3076 | Label miss; |
| 3077 | __ Or(a2, a1, a0); |
| 3078 | __ JumpIfNotSmi(a2, &miss); |
| 3079 | |
| 3080 | if (GetCondition() == eq) { |
| 3081 | // For equality we do not care about the sign of the result. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3082 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3083 | __ Subu(v0, a0, a1); |
| 3084 | } else { |
| 3085 | // Untag before subtracting to avoid handling overflow. |
| 3086 | __ SmiUntag(a1); |
| 3087 | __ SmiUntag(a0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3088 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3089 | __ Subu(v0, a1, a0); |
| 3090 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3091 | |
| 3092 | __ bind(&miss); |
| 3093 | GenerateMiss(masm); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3094 | } |
| 3095 | |
| 3096 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3097 | void CompareICStub::GenerateNumbers(MacroAssembler* masm) { |
| 3098 | DCHECK(state() == CompareICState::NUMBER); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3099 | |
| 3100 | Label generic_stub; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3101 | Label unordered, maybe_undefined1, maybe_undefined2; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3102 | Label miss; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3103 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3104 | if (left() == CompareICState::SMI) { |
| 3105 | __ JumpIfNotSmi(a1, &miss); |
| 3106 | } |
| 3107 | if (right() == CompareICState::SMI) { |
| 3108 | __ JumpIfNotSmi(a0, &miss); |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 3109 | } |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 3110 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3111 | // Inlining the double comparison and falling back to the general compare |
| 3112 | // stub if NaN is involved. |
| 3113 | // Load left and right operand. |
| 3114 | Label done, left, left_smi, right_smi; |
| 3115 | __ JumpIfSmi(a0, &right_smi); |
| 3116 | __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1, |
| 3117 | DONT_DO_SMI_CHECK); |
| 3118 | __ Subu(a2, a0, Operand(kHeapObjectTag)); |
| 3119 | __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset)); |
| 3120 | __ Branch(&left); |
| 3121 | __ bind(&right_smi); |
| 3122 | __ SmiUntag(a2, a0); // Can't clobber a0 yet. |
| 3123 | FPURegister single_scratch = f6; |
| 3124 | __ mtc1(a2, single_scratch); |
| 3125 | __ cvt_d_w(f2, single_scratch); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3126 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3127 | __ bind(&left); |
| 3128 | __ JumpIfSmi(a1, &left_smi); |
| 3129 | __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2, |
| 3130 | DONT_DO_SMI_CHECK); |
| 3131 | __ Subu(a2, a1, Operand(kHeapObjectTag)); |
| 3132 | __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset)); |
| 3133 | __ Branch(&done); |
| 3134 | __ bind(&left_smi); |
| 3135 | __ SmiUntag(a2, a1); // Can't clobber a1 yet. |
| 3136 | single_scratch = f8; |
| 3137 | __ mtc1(a2, single_scratch); |
| 3138 | __ cvt_d_w(f0, single_scratch); |
| 3139 | |
| 3140 | __ bind(&done); |
| 3141 | |
| 3142 | // Return a result of -1, 0, or 1, or use CompareStub for NaNs. |
| 3143 | Label fpu_eq, fpu_lt; |
| 3144 | // Test if equal, and also handle the unordered/NaN case. |
| 3145 | __ BranchF(&fpu_eq, &unordered, eq, f0, f2); |
| 3146 | |
| 3147 | // Test if less (unordered case is already handled). |
| 3148 | __ BranchF(&fpu_lt, NULL, lt, f0, f2); |
| 3149 | |
| 3150 | // Otherwise it's greater, so just fall thru, and return. |
| 3151 | DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS)); |
| 3152 | __ Ret(USE_DELAY_SLOT); |
| 3153 | __ li(v0, Operand(GREATER)); |
| 3154 | |
| 3155 | __ bind(&fpu_eq); |
| 3156 | __ Ret(USE_DELAY_SLOT); |
| 3157 | __ li(v0, Operand(EQUAL)); |
| 3158 | |
| 3159 | __ bind(&fpu_lt); |
| 3160 | __ Ret(USE_DELAY_SLOT); |
| 3161 | __ li(v0, Operand(LESS)); |
| 3162 | |
| 3163 | __ bind(&unordered); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3164 | __ bind(&generic_stub); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3165 | CompareICStub stub(isolate(), op(), CompareICState::GENERIC, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3166 | CompareICState::GENERIC, CompareICState::GENERIC); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3167 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 3168 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3169 | __ bind(&maybe_undefined1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3170 | if (Token::IsOrderedRelationalCompareOp(op())) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3171 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 3172 | __ Branch(&miss, ne, a0, Operand(at)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3173 | __ JumpIfSmi(a1, &unordered); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3174 | __ GetObjectType(a1, a2, a2); |
| 3175 | __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE)); |
| 3176 | __ jmp(&unordered); |
| 3177 | } |
| 3178 | |
| 3179 | __ bind(&maybe_undefined2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3180 | if (Token::IsOrderedRelationalCompareOp(op())) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3181 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 3182 | __ Branch(&unordered, eq, a1, Operand(at)); |
| 3183 | } |
| 3184 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3185 | __ bind(&miss); |
| 3186 | GenerateMiss(masm); |
| 3187 | } |
| 3188 | |
| 3189 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3190 | void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 3191 | DCHECK(state() == CompareICState::INTERNALIZED_STRING); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3192 | Label miss; |
| 3193 | |
| 3194 | // Registers containing left and right operands respectively. |
| 3195 | Register left = a1; |
| 3196 | Register right = a0; |
| 3197 | Register tmp1 = a2; |
| 3198 | Register tmp2 = a3; |
| 3199 | |
| 3200 | // Check that both operands are heap objects. |
| 3201 | __ JumpIfEitherSmi(left, right, &miss); |
| 3202 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3203 | // Check that both operands are internalized strings. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3204 | __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 3205 | __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 3206 | __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3207 | __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3208 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 3209 | __ Or(tmp1, tmp1, Operand(tmp2)); |
| 3210 | __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask)); |
| 3211 | __ Branch(&miss, ne, at, Operand(zero_reg)); |
| 3212 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3213 | // Make sure a0 is non-zero. At this point input operands are |
| 3214 | // guaranteed to be non-zero. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3215 | DCHECK(right.is(a0)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3216 | STATIC_ASSERT(EQUAL == 0); |
| 3217 | STATIC_ASSERT(kSmiTag == 0); |
| 3218 | __ mov(v0, right); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3219 | // Internalized strings are compared by identity. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3220 | __ Ret(ne, left, Operand(right)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3221 | DCHECK(is_int16(EQUAL)); |
| 3222 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3223 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3224 | |
| 3225 | __ bind(&miss); |
| 3226 | GenerateMiss(masm); |
| 3227 | } |
| 3228 | |
| 3229 | |
| 3230 | void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 3231 | DCHECK(state() == CompareICState::UNIQUE_NAME); |
| 3232 | DCHECK(GetCondition() == eq); |
| 3233 | Label miss; |
| 3234 | |
| 3235 | // Registers containing left and right operands respectively. |
| 3236 | Register left = a1; |
| 3237 | Register right = a0; |
| 3238 | Register tmp1 = a2; |
| 3239 | Register tmp2 = a3; |
| 3240 | |
| 3241 | // Check that both operands are heap objects. |
| 3242 | __ JumpIfEitherSmi(left, right, &miss); |
| 3243 | |
| 3244 | // Check that both operands are unique names. This leaves the instance |
| 3245 | // types loaded in tmp1 and tmp2. |
| 3246 | __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 3247 | __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 3248 | __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3249 | __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 3250 | |
| 3251 | __ JumpIfNotUniqueNameInstanceType(tmp1, &miss); |
| 3252 | __ JumpIfNotUniqueNameInstanceType(tmp2, &miss); |
| 3253 | |
| 3254 | // Use a0 as result |
| 3255 | __ mov(v0, a0); |
| 3256 | |
| 3257 | // Unique names are compared by identity. |
| 3258 | Label done; |
| 3259 | __ Branch(&done, ne, left, Operand(right)); |
| 3260 | // Make sure a0 is non-zero. At this point input operands are |
| 3261 | // guaranteed to be non-zero. |
| 3262 | DCHECK(right.is(a0)); |
| 3263 | STATIC_ASSERT(EQUAL == 0); |
| 3264 | STATIC_ASSERT(kSmiTag == 0); |
| 3265 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
| 3266 | __ bind(&done); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3267 | __ Ret(); |
| 3268 | |
| 3269 | __ bind(&miss); |
| 3270 | GenerateMiss(masm); |
| 3271 | } |
| 3272 | |
| 3273 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3274 | void CompareICStub::GenerateStrings(MacroAssembler* masm) { |
| 3275 | DCHECK(state() == CompareICState::STRING); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3276 | Label miss; |
| 3277 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3278 | bool equality = Token::IsEqualityOp(op()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3279 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3280 | // Registers containing left and right operands respectively. |
| 3281 | Register left = a1; |
| 3282 | Register right = a0; |
| 3283 | Register tmp1 = a2; |
| 3284 | Register tmp2 = a3; |
| 3285 | Register tmp3 = t0; |
| 3286 | Register tmp4 = t1; |
| 3287 | Register tmp5 = t2; |
| 3288 | |
| 3289 | // Check that both operands are heap objects. |
| 3290 | __ JumpIfEitherSmi(left, right, &miss); |
| 3291 | |
| 3292 | // Check that both operands are strings. This leaves the instance |
| 3293 | // types loaded in tmp1 and tmp2. |
| 3294 | __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 3295 | __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 3296 | __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3297 | __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 3298 | STATIC_ASSERT(kNotStringTag != 0); |
| 3299 | __ Or(tmp3, tmp1, tmp2); |
| 3300 | __ And(tmp5, tmp3, Operand(kIsNotStringMask)); |
| 3301 | __ Branch(&miss, ne, tmp5, Operand(zero_reg)); |
| 3302 | |
| 3303 | // Fast check for identical strings. |
| 3304 | Label left_ne_right; |
| 3305 | STATIC_ASSERT(EQUAL == 0); |
| 3306 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3307 | __ Branch(&left_ne_right, ne, left, Operand(right)); |
| 3308 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3309 | __ mov(v0, zero_reg); // In the delay slot. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3310 | __ bind(&left_ne_right); |
| 3311 | |
| 3312 | // Handle not identical strings. |
| 3313 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3314 | // Check that both strings are internalized strings. If they are, we're done |
| 3315 | // because we already know they are not identical. We know they are both |
| 3316 | // strings. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3317 | if (equality) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3318 | DCHECK(GetCondition() == eq); |
| 3319 | STATIC_ASSERT(kInternalizedTag == 0); |
| 3320 | __ Or(tmp3, tmp1, Operand(tmp2)); |
| 3321 | __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3322 | Label is_symbol; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3323 | __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3324 | // Make sure a0 is non-zero. At this point input operands are |
| 3325 | // guaranteed to be non-zero. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3326 | DCHECK(right.is(a0)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3327 | __ Ret(USE_DELAY_SLOT); |
| 3328 | __ mov(v0, a0); // In the delay slot. |
| 3329 | __ bind(&is_symbol); |
| 3330 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3331 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3332 | // Check that both strings are sequential one-byte. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3333 | Label runtime; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3334 | __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4, |
| 3335 | &runtime); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3336 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3337 | // Compare flat one-byte strings. Returns when done. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3338 | if (equality) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3339 | StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2, |
| 3340 | tmp3); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3341 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3342 | StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1, |
| 3343 | tmp2, tmp3, tmp4); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3344 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3345 | |
| 3346 | // Handle more complex cases in runtime. |
| 3347 | __ bind(&runtime); |
| 3348 | __ Push(left, right); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3349 | if (equality) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3350 | __ TailCallRuntime(Runtime::kStringEquals); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3351 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3352 | __ TailCallRuntime(Runtime::kStringCompare); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3353 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3354 | |
| 3355 | __ bind(&miss); |
| 3356 | GenerateMiss(masm); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3357 | } |
| 3358 | |
| 3359 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3360 | void CompareICStub::GenerateReceivers(MacroAssembler* masm) { |
| 3361 | DCHECK_EQ(CompareICState::RECEIVER, state()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3362 | Label miss; |
| 3363 | __ And(a2, a1, Operand(a0)); |
| 3364 | __ JumpIfSmi(a2, &miss); |
| 3365 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3366 | STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3367 | __ GetObjectType(a0, a2, a2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3368 | __ Branch(&miss, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3369 | __ GetObjectType(a1, a2, a2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3370 | __ Branch(&miss, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3371 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3372 | DCHECK_EQ(eq, GetCondition()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3373 | __ Ret(USE_DELAY_SLOT); |
| 3374 | __ subu(v0, a0, a1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3375 | |
| 3376 | __ bind(&miss); |
| 3377 | GenerateMiss(masm); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3378 | } |
| 3379 | |
| 3380 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3381 | void CompareICStub::GenerateKnownReceivers(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3382 | Label miss; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3383 | Handle<WeakCell> cell = Map::WeakCellForMap(known_map_); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3384 | __ And(a2, a1, a0); |
| 3385 | __ JumpIfSmi(a2, &miss); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3386 | __ GetWeakValue(t0, cell); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3387 | __ lw(a2, FieldMemOperand(a0, HeapObject::kMapOffset)); |
| 3388 | __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3389 | __ Branch(&miss, ne, a2, Operand(t0)); |
| 3390 | __ Branch(&miss, ne, a3, Operand(t0)); |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 3391 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3392 | if (Token::IsEqualityOp(op())) { |
| 3393 | __ Ret(USE_DELAY_SLOT); |
| 3394 | __ subu(v0, a0, a1); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3395 | } else { |
| 3396 | if (op() == Token::LT || op() == Token::LTE) { |
| 3397 | __ li(a2, Operand(Smi::FromInt(GREATER))); |
| 3398 | } else { |
| 3399 | __ li(a2, Operand(Smi::FromInt(LESS))); |
| 3400 | } |
| 3401 | __ Push(a1, a0, a2); |
| 3402 | __ TailCallRuntime(Runtime::kCompare); |
| 3403 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3404 | |
| 3405 | __ bind(&miss); |
| 3406 | GenerateMiss(masm); |
| 3407 | } |
| 3408 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3409 | |
| 3410 | void CompareICStub::GenerateMiss(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3411 | { |
| 3412 | // Call the runtime system in a fresh internal frame. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3413 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3414 | __ Push(a1, a0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3415 | __ Push(ra, a1, a0); |
| 3416 | __ li(t0, Operand(Smi::FromInt(op()))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3417 | __ addiu(sp, sp, -kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3418 | __ CallRuntime(Runtime::kCompareIC_Miss, 3, kDontSaveFPRegs, |
| 3419 | USE_DELAY_SLOT); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3420 | __ sw(t0, MemOperand(sp)); // In the delay slot. |
| 3421 | // Compute the entry point of the rewritten stub. |
| 3422 | __ Addu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3423 | // Restore registers. |
| 3424 | __ Pop(a1, a0, ra); |
| 3425 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3426 | __ Jump(a2); |
| 3427 | } |
| 3428 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3429 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3430 | void DirectCEntryStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3431 | // Make place for arguments to fit C calling convention. Most of the callers |
| 3432 | // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame |
| 3433 | // so they handle stack restoring and we don't have to do that here. |
| 3434 | // Any caller of DirectCEntryStub::GenerateCall must take care of dropping |
| 3435 | // kCArgsSlotsSize stack space after the call. |
| 3436 | __ Subu(sp, sp, Operand(kCArgsSlotsSize)); |
| 3437 | // Place the return address on the stack, making the call |
| 3438 | // GC safe. The RegExp backend also relies on this. |
| 3439 | __ sw(ra, MemOperand(sp, kCArgsSlotsSize)); |
| 3440 | __ Call(t9); // Call the C++ function. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3441 | __ lw(t9, MemOperand(sp, kCArgsSlotsSize)); |
| 3442 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3443 | if (FLAG_debug_code && FLAG_enable_slow_asserts) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3444 | // In case of an error the return address may point to a memory area |
| 3445 | // filled with kZapValue by the GC. |
| 3446 | // Dereference the address and check for this. |
| 3447 | __ lw(t0, MemOperand(t9)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3448 | __ Assert(ne, kReceivedInvalidReturnAddress, t0, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3449 | Operand(reinterpret_cast<uint32_t>(kZapValue))); |
| 3450 | } |
| 3451 | __ Jump(t9); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3452 | } |
| 3453 | |
| 3454 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3455 | void DirectCEntryStub::GenerateCall(MacroAssembler* masm, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3456 | Register target) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3457 | intptr_t loc = |
| 3458 | reinterpret_cast<intptr_t>(GetCode().location()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3459 | __ Move(t9, target); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3460 | __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE); |
| 3461 | __ Call(at); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3462 | } |
| 3463 | |
| 3464 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3465 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 3466 | Label* miss, |
| 3467 | Label* done, |
| 3468 | Register receiver, |
| 3469 | Register properties, |
| 3470 | Handle<Name> name, |
| 3471 | Register scratch0) { |
| 3472 | DCHECK(name->IsUniqueName()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3473 | // 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] | 3474 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 3475 | // undefined value), it guarantees the hash table doesn't contain the |
| 3476 | // property. It's true even if some slots represent deleted properties |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3477 | // (their names are the hole value). |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3478 | for (int i = 0; i < kInlinedProbes; i++) { |
| 3479 | // scratch0 points to properties hash. |
| 3480 | // Compute the masked index: (hash + i + i * i) & mask. |
| 3481 | Register index = scratch0; |
| 3482 | // Capacity is smi 2^n. |
| 3483 | __ lw(index, FieldMemOperand(properties, kCapacityOffset)); |
| 3484 | __ Subu(index, index, Operand(1)); |
| 3485 | __ And(index, index, Operand( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3486 | Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i)))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3487 | |
| 3488 | // Scale the index by multiplying by the entry size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3489 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3490 | __ Lsa(index, index, index, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3491 | |
| 3492 | Register entity_name = scratch0; |
| 3493 | // Having undefined at this place means the name is not contained. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3494 | STATIC_ASSERT(kSmiTagSize == 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3495 | Register tmp = properties; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3496 | __ Lsa(tmp, properties, index, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3497 | __ lw(entity_name, FieldMemOperand(tmp, kElementsStartOffset)); |
| 3498 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3499 | DCHECK(!tmp.is(entity_name)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3500 | __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex); |
| 3501 | __ Branch(done, eq, entity_name, Operand(tmp)); |
| 3502 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3503 | // Load the hole ready for use below: |
| 3504 | __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3505 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3506 | // Stop if found the property. |
| 3507 | __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3508 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3509 | Label good; |
| 3510 | __ Branch(&good, eq, entity_name, Operand(tmp)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3511 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3512 | // Check if the entry name is not a unique name. |
| 3513 | __ lw(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset)); |
| 3514 | __ lbu(entity_name, |
| 3515 | FieldMemOperand(entity_name, Map::kInstanceTypeOffset)); |
| 3516 | __ JumpIfNotUniqueNameInstanceType(entity_name, miss); |
| 3517 | __ bind(&good); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3518 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3519 | // Restore the properties. |
| 3520 | __ lw(properties, |
| 3521 | FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | const int spill_mask = |
| 3525 | (ra.bit() | t2.bit() | t1.bit() | t0.bit() | a3.bit() | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3526 | a2.bit() | a1.bit() | a0.bit() | v0.bit()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3527 | |
| 3528 | __ MultiPush(spill_mask); |
| 3529 | __ lw(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3530 | __ li(a1, Operand(Handle<Name>(name))); |
| 3531 | NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3532 | __ CallStub(&stub); |
| 3533 | __ mov(at, v0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3534 | __ MultiPop(spill_mask); |
| 3535 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3536 | __ Branch(done, eq, at, Operand(zero_reg)); |
| 3537 | __ Branch(miss, ne, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3541 | // Probe the name dictionary in the |elements| register. Jump to the |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3542 | // |done| label if a property with the given name is found. Jump to |
| 3543 | // the |miss| label otherwise. |
| 3544 | // If lookup was successful |scratch2| will be equal to elements + 4 * index. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3545 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 3546 | Label* miss, |
| 3547 | Label* done, |
| 3548 | Register elements, |
| 3549 | Register name, |
| 3550 | Register scratch1, |
| 3551 | Register scratch2) { |
| 3552 | DCHECK(!elements.is(scratch1)); |
| 3553 | DCHECK(!elements.is(scratch2)); |
| 3554 | DCHECK(!name.is(scratch1)); |
| 3555 | DCHECK(!name.is(scratch2)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3556 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3557 | __ AssertName(name); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3558 | |
| 3559 | // Compute the capacity mask. |
| 3560 | __ lw(scratch1, FieldMemOperand(elements, kCapacityOffset)); |
| 3561 | __ sra(scratch1, scratch1, kSmiTagSize); // convert smi to int |
| 3562 | __ Subu(scratch1, scratch1, Operand(1)); |
| 3563 | |
| 3564 | // Generate an unrolled loop that performs a few probes before |
| 3565 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 3566 | // cover ~93% of loads from dictionaries. |
| 3567 | for (int i = 0; i < kInlinedProbes; i++) { |
| 3568 | // Compute the masked index: (hash + i + i * i) & mask. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3569 | __ lw(scratch2, FieldMemOperand(name, Name::kHashFieldOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3570 | if (i > 0) { |
| 3571 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 3572 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 3573 | // shifted in the following and instruction. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3574 | DCHECK(NameDictionary::GetProbeOffset(i) < |
| 3575 | 1 << (32 - Name::kHashFieldOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3576 | __ Addu(scratch2, scratch2, Operand( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3577 | NameDictionary::GetProbeOffset(i) << Name::kHashShift)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3578 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3579 | __ srl(scratch2, scratch2, Name::kHashShift); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3580 | __ And(scratch2, scratch1, scratch2); |
| 3581 | |
| 3582 | // Scale the index by multiplying by the element size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3583 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3584 | // scratch2 = scratch2 * 3. |
| 3585 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3586 | __ Lsa(scratch2, scratch2, scratch2, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3587 | |
| 3588 | // Check if the key is identical to the name. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3589 | __ Lsa(scratch2, elements, scratch2, 2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3590 | __ lw(at, FieldMemOperand(scratch2, kElementsStartOffset)); |
| 3591 | __ Branch(done, eq, name, Operand(at)); |
| 3592 | } |
| 3593 | |
| 3594 | const int spill_mask = |
| 3595 | (ra.bit() | t2.bit() | t1.bit() | t0.bit() | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3596 | a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) & |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3597 | ~(scratch1.bit() | scratch2.bit()); |
| 3598 | |
| 3599 | __ MultiPush(spill_mask); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3600 | if (name.is(a0)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3601 | DCHECK(!elements.is(a1)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3602 | __ Move(a1, name); |
| 3603 | __ Move(a0, elements); |
| 3604 | } else { |
| 3605 | __ Move(a0, elements); |
| 3606 | __ Move(a1, name); |
| 3607 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3608 | NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3609 | __ CallStub(&stub); |
| 3610 | __ mov(scratch2, a2); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3611 | __ mov(at, v0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3612 | __ MultiPop(spill_mask); |
| 3613 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3614 | __ Branch(done, ne, at, Operand(zero_reg)); |
| 3615 | __ Branch(miss, eq, at, Operand(zero_reg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3619 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3620 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 3621 | // we cannot call anything that could cause a GC from this stub. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3622 | // Registers: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3623 | // result: NameDictionary to probe |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3624 | // a1: key |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3625 | // dictionary: NameDictionary to probe. |
| 3626 | // index: will hold an index of entry if lookup is successful. |
| 3627 | // might alias with result_. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3628 | // Returns: |
| 3629 | // result_ is zero if lookup failed, non zero otherwise. |
| 3630 | |
| 3631 | Register result = v0; |
| 3632 | Register dictionary = a0; |
| 3633 | Register key = a1; |
| 3634 | Register index = a2; |
| 3635 | Register mask = a3; |
| 3636 | Register hash = t0; |
| 3637 | Register undefined = t1; |
| 3638 | Register entry_key = t2; |
| 3639 | |
| 3640 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 3641 | |
| 3642 | __ lw(mask, FieldMemOperand(dictionary, kCapacityOffset)); |
| 3643 | __ sra(mask, mask, kSmiTagSize); |
| 3644 | __ Subu(mask, mask, Operand(1)); |
| 3645 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3646 | __ lw(hash, FieldMemOperand(key, Name::kHashFieldOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3647 | |
| 3648 | __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex); |
| 3649 | |
| 3650 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 3651 | // Compute the masked index: (hash + i + i * i) & mask. |
| 3652 | // Capacity is smi 2^n. |
| 3653 | if (i > 0) { |
| 3654 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 3655 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 3656 | // shifted in the following and instruction. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3657 | DCHECK(NameDictionary::GetProbeOffset(i) < |
| 3658 | 1 << (32 - Name::kHashFieldOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3659 | __ Addu(index, hash, Operand( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3660 | NameDictionary::GetProbeOffset(i) << Name::kHashShift)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3661 | } else { |
| 3662 | __ mov(index, hash); |
| 3663 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3664 | __ srl(index, index, Name::kHashShift); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3665 | __ And(index, mask, index); |
| 3666 | |
| 3667 | // Scale the index by multiplying by the entry size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3668 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3669 | // index *= 3. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3670 | __ Lsa(index, index, index, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3671 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3672 | STATIC_ASSERT(kSmiTagSize == 1); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3673 | __ Lsa(index, dictionary, index, 2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3674 | __ lw(entry_key, FieldMemOperand(index, kElementsStartOffset)); |
| 3675 | |
| 3676 | // Having undefined at this place means the name is not contained. |
| 3677 | __ Branch(¬_in_dictionary, eq, entry_key, Operand(undefined)); |
| 3678 | |
| 3679 | // Stop if found the property. |
| 3680 | __ Branch(&in_dictionary, eq, entry_key, Operand(key)); |
| 3681 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3682 | if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) { |
| 3683 | // Check if the entry name is not a unique name. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3684 | __ lw(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset)); |
| 3685 | __ lbu(entry_key, |
| 3686 | FieldMemOperand(entry_key, Map::kInstanceTypeOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3687 | __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3688 | } |
| 3689 | } |
| 3690 | |
| 3691 | __ bind(&maybe_in_dictionary); |
| 3692 | // If we are doing negative lookup then probing failure should be |
| 3693 | // treated as a lookup success. For positive lookup probing failure |
| 3694 | // should be treated as lookup failure. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3695 | if (mode() == POSITIVE_LOOKUP) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3696 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3697 | __ mov(result, zero_reg); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3698 | } |
| 3699 | |
| 3700 | __ bind(&in_dictionary); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3701 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3702 | __ li(result, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3703 | |
| 3704 | __ bind(¬_in_dictionary); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3705 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3706 | __ mov(result, zero_reg); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3707 | } |
| 3708 | |
| 3709 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3710 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 3711 | Isolate* isolate) { |
| 3712 | StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs); |
| 3713 | stub1.GetCode(); |
| 3714 | // Hydrogen code stubs need stub2 at snapshot time. |
| 3715 | StoreBufferOverflowStub stub2(isolate, kSaveFPRegs); |
| 3716 | stub2.GetCode(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3717 | } |
| 3718 | |
| 3719 | |
| 3720 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 3721 | // the value has just been written into the object, now this stub makes sure |
| 3722 | // we keep the GC informed. The word in the object where the value has been |
| 3723 | // written is in the address register. |
| 3724 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 3725 | Label skip_to_incremental_noncompacting; |
| 3726 | Label skip_to_incremental_compacting; |
| 3727 | |
| 3728 | // The first two branch+nop instructions are generated with labels so as to |
| 3729 | // get the offset fixed up correctly by the bind(Label*) call. We patch it |
| 3730 | // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this |
| 3731 | // position) and the "beq zero_reg, zero_reg, ..." when we start and stop |
| 3732 | // incremental heap marking. |
| 3733 | // See RecordWriteStub::Patch for details. |
| 3734 | __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting); |
| 3735 | __ nop(); |
| 3736 | __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting); |
| 3737 | __ nop(); |
| 3738 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3739 | if (remembered_set_action() == EMIT_REMEMBERED_SET) { |
| 3740 | __ RememberedSetHelper(object(), |
| 3741 | address(), |
| 3742 | value(), |
| 3743 | save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3744 | MacroAssembler::kReturnAtEnd); |
| 3745 | } |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3746 | __ Ret(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3747 | |
| 3748 | __ bind(&skip_to_incremental_noncompacting); |
| 3749 | GenerateIncremental(masm, INCREMENTAL); |
| 3750 | |
| 3751 | __ bind(&skip_to_incremental_compacting); |
| 3752 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 3753 | |
| 3754 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 3755 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 3756 | |
| 3757 | PatchBranchIntoNop(masm, 0); |
| 3758 | PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize); |
| 3759 | } |
| 3760 | |
| 3761 | |
| 3762 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 3763 | regs_.Save(masm); |
| 3764 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3765 | if (remembered_set_action() == EMIT_REMEMBERED_SET) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3766 | Label dont_need_remembered_set; |
| 3767 | |
| 3768 | __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0)); |
| 3769 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 3770 | regs_.scratch0(), |
| 3771 | &dont_need_remembered_set); |
| 3772 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3773 | __ JumpIfInNewSpace(regs_.object(), regs_.scratch0(), |
| 3774 | &dont_need_remembered_set); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3775 | |
| 3776 | // First notify the incremental marker if necessary, then update the |
| 3777 | // remembered set. |
| 3778 | CheckNeedsToInformIncrementalMarker( |
| 3779 | masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3780 | InformIncrementalMarker(masm); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3781 | regs_.Restore(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3782 | __ RememberedSetHelper(object(), |
| 3783 | address(), |
| 3784 | value(), |
| 3785 | save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3786 | MacroAssembler::kReturnAtEnd); |
| 3787 | |
| 3788 | __ bind(&dont_need_remembered_set); |
| 3789 | } |
| 3790 | |
| 3791 | CheckNeedsToInformIncrementalMarker( |
| 3792 | masm, kReturnOnNoNeedToInformIncrementalMarker, mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3793 | InformIncrementalMarker(masm); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3794 | regs_.Restore(masm); |
| 3795 | __ Ret(); |
| 3796 | } |
| 3797 | |
| 3798 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3799 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) { |
| 3800 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3801 | int argument_count = 3; |
| 3802 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 3803 | Register address = |
| 3804 | a0.is(regs_.address()) ? regs_.scratch0() : regs_.address(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3805 | DCHECK(!address.is(regs_.object())); |
| 3806 | DCHECK(!address.is(a0)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3807 | __ Move(address, regs_.address()); |
| 3808 | __ Move(a0, regs_.object()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3809 | __ Move(a1, address); |
| 3810 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3811 | |
| 3812 | AllowExternalCallThatCantCauseGC scope(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3813 | __ CallCFunction( |
| 3814 | ExternalReference::incremental_marking_record_write_function(isolate()), |
| 3815 | argument_count); |
| 3816 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | |
| 3820 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 3821 | MacroAssembler* masm, |
| 3822 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 3823 | Mode mode) { |
| 3824 | Label on_black; |
| 3825 | Label need_incremental; |
| 3826 | Label need_incremental_pop_scratch; |
| 3827 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3828 | __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask)); |
| 3829 | __ lw(regs_.scratch1(), |
| 3830 | MemOperand(regs_.scratch0(), |
| 3831 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 3832 | __ Subu(regs_.scratch1(), regs_.scratch1(), Operand(1)); |
| 3833 | __ sw(regs_.scratch1(), |
| 3834 | MemOperand(regs_.scratch0(), |
| 3835 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 3836 | __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg)); |
| 3837 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3838 | // Let's look at the color of the object: If it is not black we don't have |
| 3839 | // to inform the incremental marker. |
| 3840 | __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black); |
| 3841 | |
| 3842 | regs_.Restore(masm); |
| 3843 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3844 | __ RememberedSetHelper(object(), |
| 3845 | address(), |
| 3846 | value(), |
| 3847 | save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3848 | MacroAssembler::kReturnAtEnd); |
| 3849 | } else { |
| 3850 | __ Ret(); |
| 3851 | } |
| 3852 | |
| 3853 | __ bind(&on_black); |
| 3854 | |
| 3855 | // Get the value from the slot. |
| 3856 | __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0)); |
| 3857 | |
| 3858 | if (mode == INCREMENTAL_COMPACTION) { |
| 3859 | Label ensure_not_white; |
| 3860 | |
| 3861 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 3862 | regs_.scratch1(), // Scratch. |
| 3863 | MemoryChunk::kEvacuationCandidateMask, |
| 3864 | eq, |
| 3865 | &ensure_not_white); |
| 3866 | |
| 3867 | __ CheckPageFlag(regs_.object(), |
| 3868 | regs_.scratch1(), // Scratch. |
| 3869 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 3870 | eq, |
| 3871 | &need_incremental); |
| 3872 | |
| 3873 | __ bind(&ensure_not_white); |
| 3874 | } |
| 3875 | |
| 3876 | // We need extra registers for this, so we push the object and the address |
| 3877 | // register temporarily. |
| 3878 | __ Push(regs_.object(), regs_.address()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3879 | __ JumpIfWhite(regs_.scratch0(), // The value. |
| 3880 | regs_.scratch1(), // Scratch. |
| 3881 | regs_.object(), // Scratch. |
| 3882 | regs_.address(), // Scratch. |
| 3883 | &need_incremental_pop_scratch); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3884 | __ Pop(regs_.object(), regs_.address()); |
| 3885 | |
| 3886 | regs_.Restore(masm); |
| 3887 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3888 | __ RememberedSetHelper(object(), |
| 3889 | address(), |
| 3890 | value(), |
| 3891 | save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3892 | MacroAssembler::kReturnAtEnd); |
| 3893 | } else { |
| 3894 | __ Ret(); |
| 3895 | } |
| 3896 | |
| 3897 | __ bind(&need_incremental_pop_scratch); |
| 3898 | __ Pop(regs_.object(), regs_.address()); |
| 3899 | |
| 3900 | __ bind(&need_incremental); |
| 3901 | |
| 3902 | // Fall through when we need to inform the incremental marker. |
| 3903 | } |
| 3904 | |
| 3905 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3906 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
| 3907 | CEntryStub ces(isolate(), 1, kSaveFPRegs); |
| 3908 | __ Call(ces.GetCode(), RelocInfo::CODE_TARGET); |
| 3909 | int parameter_count_offset = |
| 3910 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 3911 | __ lw(a1, MemOperand(fp, parameter_count_offset)); |
| 3912 | if (function_mode() == JS_FUNCTION_STUB_MODE) { |
| 3913 | __ Addu(a1, a1, Operand(1)); |
| 3914 | } |
| 3915 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 3916 | __ sll(a1, a1, kPointerSizeLog2); |
| 3917 | __ Ret(USE_DELAY_SLOT); |
| 3918 | __ Addu(sp, sp, a1); |
| 3919 | } |
| 3920 | |
| 3921 | |
| 3922 | void LoadICTrampolineStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3923 | __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister()); |
| 3924 | LoadICStub stub(isolate(), state()); |
| 3925 | stub.GenerateForTrampoline(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3926 | } |
| 3927 | |
| 3928 | |
| 3929 | void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3930 | __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister()); |
| 3931 | KeyedLoadICStub stub(isolate(), state()); |
| 3932 | stub.GenerateForTrampoline(masm); |
| 3933 | } |
| 3934 | |
| 3935 | |
| 3936 | void CallICTrampolineStub::Generate(MacroAssembler* masm) { |
| 3937 | __ EmitLoadTypeFeedbackVector(a2); |
| 3938 | CallICStub stub(isolate(), state()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3939 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 3940 | } |
| 3941 | |
| 3942 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3943 | void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); } |
| 3944 | |
| 3945 | |
| 3946 | void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 3947 | GenerateImpl(masm, true); |
| 3948 | } |
| 3949 | |
| 3950 | |
| 3951 | static void HandleArrayCases(MacroAssembler* masm, Register feedback, |
| 3952 | Register receiver_map, Register scratch1, |
| 3953 | Register scratch2, bool is_polymorphic, |
| 3954 | Label* miss) { |
| 3955 | // feedback initially contains the feedback array |
| 3956 | Label next_loop, prepare_next; |
| 3957 | Label start_polymorphic; |
| 3958 | |
| 3959 | Register cached_map = scratch1; |
| 3960 | |
| 3961 | __ lw(cached_map, |
| 3962 | FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0))); |
| 3963 | __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset)); |
| 3964 | __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map)); |
| 3965 | // found, now call handler. |
| 3966 | Register handler = feedback; |
| 3967 | __ lw(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1))); |
| 3968 | __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3969 | __ Jump(t9); |
| 3970 | |
| 3971 | |
| 3972 | Register length = scratch2; |
| 3973 | __ bind(&start_polymorphic); |
| 3974 | __ lw(length, FieldMemOperand(feedback, FixedArray::kLengthOffset)); |
| 3975 | if (!is_polymorphic) { |
| 3976 | // If the IC could be monomorphic we have to make sure we don't go past the |
| 3977 | // end of the feedback array. |
| 3978 | __ Branch(miss, eq, length, Operand(Smi::FromInt(2))); |
| 3979 | } |
| 3980 | |
| 3981 | Register too_far = length; |
| 3982 | Register pointer_reg = feedback; |
| 3983 | |
| 3984 | // +-----+------+------+-----+-----+ ... ----+ |
| 3985 | // | map | len | wm0 | h0 | wm1 | hN | |
| 3986 | // +-----+------+------+-----+-----+ ... ----+ |
| 3987 | // 0 1 2 len-1 |
| 3988 | // ^ ^ |
| 3989 | // | | |
| 3990 | // pointer_reg too_far |
| 3991 | // aka feedback scratch2 |
| 3992 | // also need receiver_map |
| 3993 | // use cached_map (scratch1) to look in the weak map values. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3994 | __ Lsa(too_far, feedback, length, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3995 | __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 3996 | __ Addu(pointer_reg, feedback, |
| 3997 | Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag)); |
| 3998 | |
| 3999 | __ bind(&next_loop); |
| 4000 | __ lw(cached_map, MemOperand(pointer_reg)); |
| 4001 | __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset)); |
| 4002 | __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map)); |
| 4003 | __ lw(handler, MemOperand(pointer_reg, kPointerSize)); |
| 4004 | __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4005 | __ Jump(t9); |
| 4006 | |
| 4007 | __ bind(&prepare_next); |
| 4008 | __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 2)); |
| 4009 | __ Branch(&next_loop, lt, pointer_reg, Operand(too_far)); |
| 4010 | |
| 4011 | // We exhausted our array of map handler pairs. |
| 4012 | __ jmp(miss); |
| 4013 | } |
| 4014 | |
| 4015 | |
| 4016 | static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver, |
| 4017 | Register receiver_map, Register feedback, |
| 4018 | Register vector, Register slot, |
| 4019 | Register scratch, Label* compare_map, |
| 4020 | Label* load_smi_map, Label* try_array) { |
| 4021 | __ JumpIfSmi(receiver, load_smi_map); |
| 4022 | __ lw(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 4023 | __ bind(compare_map); |
| 4024 | Register cached_map = scratch; |
| 4025 | // Move the weak map into the weak_cell register. |
| 4026 | __ lw(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset)); |
| 4027 | __ Branch(try_array, ne, cached_map, Operand(receiver_map)); |
| 4028 | Register handler = feedback; |
| 4029 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4030 | __ Lsa(handler, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4031 | __ lw(handler, |
| 4032 | FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize)); |
| 4033 | __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4034 | __ Jump(t9); |
| 4035 | } |
| 4036 | |
| 4037 | |
| 4038 | void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4039 | Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1 |
| 4040 | Register name = LoadWithVectorDescriptor::NameRegister(); // a2 |
| 4041 | Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3 |
| 4042 | Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0 |
| 4043 | Register feedback = t0; |
| 4044 | Register receiver_map = t1; |
| 4045 | Register scratch1 = t4; |
| 4046 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4047 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4048 | __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 4049 | |
| 4050 | // Try to quickly handle the monomorphic case without knowing for sure |
| 4051 | // if we have a weak cell in feedback. We do know it's safe to look |
| 4052 | // at WeakCell::kValueOffset. |
| 4053 | Label try_array, load_smi_map, compare_map; |
| 4054 | Label not_array, miss; |
| 4055 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 4056 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 4057 | |
| 4058 | // Is it a fixed array? |
| 4059 | __ bind(&try_array); |
| 4060 | __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 4061 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 4062 | __ Branch(¬_array, ne, at, Operand(scratch1)); |
| 4063 | HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, true, &miss); |
| 4064 | |
| 4065 | __ bind(¬_array); |
| 4066 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 4067 | __ Branch(&miss, ne, at, Operand(feedback)); |
| 4068 | Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags( |
| 4069 | Code::ComputeHandlerFlags(Code::LOAD_IC)); |
| 4070 | masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags, |
| 4071 | receiver, name, feedback, |
| 4072 | receiver_map, scratch1, t5); |
| 4073 | |
| 4074 | __ bind(&miss); |
| 4075 | LoadIC::GenerateMiss(masm); |
| 4076 | |
| 4077 | __ bind(&load_smi_map); |
| 4078 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 4079 | __ jmp(&compare_map); |
| 4080 | } |
| 4081 | |
| 4082 | |
| 4083 | void KeyedLoadICStub::Generate(MacroAssembler* masm) { |
| 4084 | GenerateImpl(masm, false); |
| 4085 | } |
| 4086 | |
| 4087 | |
| 4088 | void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 4089 | GenerateImpl(masm, true); |
| 4090 | } |
| 4091 | |
| 4092 | |
| 4093 | void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4094 | Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1 |
| 4095 | Register key = LoadWithVectorDescriptor::NameRegister(); // a2 |
| 4096 | Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3 |
| 4097 | Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0 |
| 4098 | Register feedback = t0; |
| 4099 | Register receiver_map = t1; |
| 4100 | Register scratch1 = t4; |
| 4101 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4102 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4103 | __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 4104 | |
| 4105 | // Try to quickly handle the monomorphic case without knowing for sure |
| 4106 | // if we have a weak cell in feedback. We do know it's safe to look |
| 4107 | // at WeakCell::kValueOffset. |
| 4108 | Label try_array, load_smi_map, compare_map; |
| 4109 | Label not_array, miss; |
| 4110 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 4111 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 4112 | |
| 4113 | __ bind(&try_array); |
| 4114 | // Is it a fixed array? |
| 4115 | __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 4116 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 4117 | __ Branch(¬_array, ne, at, Operand(scratch1)); |
| 4118 | // We have a polymorphic element handler. |
| 4119 | __ JumpIfNotSmi(key, &miss); |
| 4120 | |
| 4121 | Label polymorphic, try_poly_name; |
| 4122 | __ bind(&polymorphic); |
| 4123 | HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, true, &miss); |
| 4124 | |
| 4125 | __ bind(¬_array); |
| 4126 | // Is it generic? |
| 4127 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 4128 | __ Branch(&try_poly_name, ne, at, Operand(feedback)); |
| 4129 | Handle<Code> megamorphic_stub = |
| 4130 | KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState()); |
| 4131 | __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET); |
| 4132 | |
| 4133 | __ bind(&try_poly_name); |
| 4134 | // We might have a name in feedback, and a fixed array in the next slot. |
| 4135 | __ Branch(&miss, ne, key, Operand(feedback)); |
| 4136 | // If the name comparison succeeded, we know we have a fixed array with |
| 4137 | // at least one map/handler pair. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4138 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4139 | __ lw(feedback, |
| 4140 | FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize)); |
| 4141 | HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, false, &miss); |
| 4142 | |
| 4143 | __ bind(&miss); |
| 4144 | KeyedLoadIC::GenerateMiss(masm); |
| 4145 | |
| 4146 | __ bind(&load_smi_map); |
| 4147 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 4148 | __ jmp(&compare_map); |
| 4149 | } |
| 4150 | |
| 4151 | |
| 4152 | void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) { |
| 4153 | __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister()); |
| 4154 | VectorStoreICStub stub(isolate(), state()); |
| 4155 | stub.GenerateForTrampoline(masm); |
| 4156 | } |
| 4157 | |
| 4158 | |
| 4159 | void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) { |
| 4160 | __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister()); |
| 4161 | VectorKeyedStoreICStub stub(isolate(), state()); |
| 4162 | stub.GenerateForTrampoline(masm); |
| 4163 | } |
| 4164 | |
| 4165 | |
| 4166 | void VectorStoreICStub::Generate(MacroAssembler* masm) { |
| 4167 | GenerateImpl(masm, false); |
| 4168 | } |
| 4169 | |
| 4170 | |
| 4171 | void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 4172 | GenerateImpl(masm, true); |
| 4173 | } |
| 4174 | |
| 4175 | |
| 4176 | void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4177 | Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1 |
| 4178 | Register key = VectorStoreICDescriptor::NameRegister(); // a2 |
| 4179 | Register vector = VectorStoreICDescriptor::VectorRegister(); // a3 |
| 4180 | Register slot = VectorStoreICDescriptor::SlotRegister(); // t0 |
| 4181 | DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0 |
| 4182 | Register feedback = t1; |
| 4183 | Register receiver_map = t2; |
| 4184 | Register scratch1 = t5; |
| 4185 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4186 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4187 | __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 4188 | |
| 4189 | // Try to quickly handle the monomorphic case without knowing for sure |
| 4190 | // if we have a weak cell in feedback. We do know it's safe to look |
| 4191 | // at WeakCell::kValueOffset. |
| 4192 | Label try_array, load_smi_map, compare_map; |
| 4193 | Label not_array, miss; |
| 4194 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 4195 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 4196 | |
| 4197 | // Is it a fixed array? |
| 4198 | __ bind(&try_array); |
| 4199 | __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 4200 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 4201 | __ Branch(¬_array, ne, scratch1, Operand(at)); |
| 4202 | |
| 4203 | Register scratch2 = t4; |
| 4204 | HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true, |
| 4205 | &miss); |
| 4206 | |
| 4207 | __ bind(¬_array); |
| 4208 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 4209 | __ Branch(&miss, ne, feedback, Operand(at)); |
| 4210 | Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags( |
| 4211 | Code::ComputeHandlerFlags(Code::STORE_IC)); |
| 4212 | masm->isolate()->stub_cache()->GenerateProbe( |
| 4213 | masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map, |
| 4214 | scratch1, scratch2); |
| 4215 | |
| 4216 | __ bind(&miss); |
| 4217 | StoreIC::GenerateMiss(masm); |
| 4218 | |
| 4219 | __ bind(&load_smi_map); |
| 4220 | __ Branch(USE_DELAY_SLOT, &compare_map); |
| 4221 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot. |
| 4222 | } |
| 4223 | |
| 4224 | |
| 4225 | void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) { |
| 4226 | GenerateImpl(masm, false); |
| 4227 | } |
| 4228 | |
| 4229 | |
| 4230 | void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 4231 | GenerateImpl(masm, true); |
| 4232 | } |
| 4233 | |
| 4234 | |
| 4235 | static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback, |
| 4236 | Register receiver_map, Register scratch1, |
| 4237 | Register scratch2, Label* miss) { |
| 4238 | // feedback initially contains the feedback array |
| 4239 | Label next_loop, prepare_next; |
| 4240 | Label start_polymorphic; |
| 4241 | Label transition_call; |
| 4242 | |
| 4243 | Register cached_map = scratch1; |
| 4244 | Register too_far = scratch2; |
| 4245 | Register pointer_reg = feedback; |
| 4246 | __ lw(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset)); |
| 4247 | |
| 4248 | // +-----+------+------+-----+-----+-----+ ... ----+ |
| 4249 | // | map | len | wm0 | wt0 | h0 | wm1 | hN | |
| 4250 | // +-----+------+------+-----+-----+ ----+ ... ----+ |
| 4251 | // 0 1 2 len-1 |
| 4252 | // ^ ^ |
| 4253 | // | | |
| 4254 | // pointer_reg too_far |
| 4255 | // aka feedback scratch2 |
| 4256 | // also need receiver_map |
| 4257 | // use cached_map (scratch1) to look in the weak map values. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4258 | __ Lsa(too_far, feedback, too_far, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4259 | __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 4260 | __ Addu(pointer_reg, feedback, |
| 4261 | Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag)); |
| 4262 | |
| 4263 | __ bind(&next_loop); |
| 4264 | __ lw(cached_map, MemOperand(pointer_reg)); |
| 4265 | __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset)); |
| 4266 | __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map)); |
| 4267 | // Is it a transitioning store? |
| 4268 | __ lw(too_far, MemOperand(pointer_reg, kPointerSize)); |
| 4269 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 4270 | __ Branch(&transition_call, ne, too_far, Operand(at)); |
| 4271 | __ lw(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2)); |
| 4272 | __ Addu(t9, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4273 | __ Jump(t9); |
| 4274 | |
| 4275 | __ bind(&transition_call); |
| 4276 | __ lw(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset)); |
| 4277 | __ JumpIfSmi(too_far, miss); |
| 4278 | |
| 4279 | __ lw(receiver_map, MemOperand(pointer_reg, kPointerSize * 2)); |
| 4280 | |
| 4281 | // Load the map into the correct register. |
| 4282 | DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister())); |
| 4283 | __ mov(feedback, too_far); |
| 4284 | |
| 4285 | __ Addu(t9, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4286 | __ Jump(t9); |
| 4287 | |
| 4288 | __ bind(&prepare_next); |
| 4289 | __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 3)); |
| 4290 | __ Branch(&next_loop, lt, pointer_reg, Operand(too_far)); |
| 4291 | |
| 4292 | // We exhausted our array of map handler pairs. |
| 4293 | __ jmp(miss); |
| 4294 | } |
| 4295 | |
| 4296 | |
| 4297 | void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4298 | Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1 |
| 4299 | Register key = VectorStoreICDescriptor::NameRegister(); // a2 |
| 4300 | Register vector = VectorStoreICDescriptor::VectorRegister(); // a3 |
| 4301 | Register slot = VectorStoreICDescriptor::SlotRegister(); // t0 |
| 4302 | DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0 |
| 4303 | Register feedback = t1; |
| 4304 | Register receiver_map = t2; |
| 4305 | Register scratch1 = t5; |
| 4306 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4307 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4308 | __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 4309 | |
| 4310 | // Try to quickly handle the monomorphic case without knowing for sure |
| 4311 | // if we have a weak cell in feedback. We do know it's safe to look |
| 4312 | // at WeakCell::kValueOffset. |
| 4313 | Label try_array, load_smi_map, compare_map; |
| 4314 | Label not_array, miss; |
| 4315 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 4316 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 4317 | |
| 4318 | __ bind(&try_array); |
| 4319 | // Is it a fixed array? |
| 4320 | __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 4321 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 4322 | __ Branch(¬_array, ne, scratch1, Operand(at)); |
| 4323 | |
| 4324 | // We have a polymorphic element handler. |
| 4325 | Label polymorphic, try_poly_name; |
| 4326 | __ bind(&polymorphic); |
| 4327 | |
| 4328 | Register scratch2 = t4; |
| 4329 | |
| 4330 | HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2, |
| 4331 | &miss); |
| 4332 | |
| 4333 | __ bind(¬_array); |
| 4334 | // Is it generic? |
| 4335 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 4336 | __ Branch(&try_poly_name, ne, feedback, Operand(at)); |
| 4337 | Handle<Code> megamorphic_stub = |
| 4338 | KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState()); |
| 4339 | __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET); |
| 4340 | |
| 4341 | __ bind(&try_poly_name); |
| 4342 | // We might have a name in feedback, and a fixed array in the next slot. |
| 4343 | __ Branch(&miss, ne, key, Operand(feedback)); |
| 4344 | // If the name comparison succeeded, we know we have a fixed array with |
| 4345 | // at least one map/handler pair. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4346 | __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4347 | __ lw(feedback, |
| 4348 | FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize)); |
| 4349 | HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false, |
| 4350 | &miss); |
| 4351 | |
| 4352 | __ bind(&miss); |
| 4353 | KeyedStoreIC::GenerateMiss(masm); |
| 4354 | |
| 4355 | __ bind(&load_smi_map); |
| 4356 | __ Branch(USE_DELAY_SLOT, &compare_map); |
| 4357 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot. |
| 4358 | } |
| 4359 | |
| 4360 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4361 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 4362 | if (masm->isolate()->function_entry_hook() != NULL) { |
| 4363 | ProfileEntryHookStub stub(masm->isolate()); |
| 4364 | __ push(ra); |
| 4365 | __ CallStub(&stub); |
| 4366 | __ pop(ra); |
| 4367 | } |
| 4368 | } |
| 4369 | |
| 4370 | |
| 4371 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 4372 | // The entry hook is a "push ra" instruction, followed by a call. |
| 4373 | // Note: on MIPS "push" is 2 instruction |
| 4374 | const int32_t kReturnAddressDistanceFromFunctionStart = |
| 4375 | Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize); |
| 4376 | |
| 4377 | // This should contain all kJSCallerSaved registers. |
| 4378 | const RegList kSavedRegs = |
| 4379 | kJSCallerSaved | // Caller saved registers. |
| 4380 | s5.bit(); // Saved stack pointer. |
| 4381 | |
| 4382 | // We also save ra, so the count here is one higher than the mask indicates. |
| 4383 | const int32_t kNumSavedRegs = kNumJSCallerSaved + 2; |
| 4384 | |
| 4385 | // Save all caller-save registers as this may be called from anywhere. |
| 4386 | __ MultiPush(kSavedRegs | ra.bit()); |
| 4387 | |
| 4388 | // Compute the function's address for the first argument. |
| 4389 | __ Subu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart)); |
| 4390 | |
| 4391 | // The caller's return address is above the saved temporaries. |
| 4392 | // Grab that for the second argument to the hook. |
| 4393 | __ Addu(a1, sp, Operand(kNumSavedRegs * kPointerSize)); |
| 4394 | |
| 4395 | // Align the stack if necessary. |
| 4396 | int frame_alignment = masm->ActivationFrameAlignment(); |
| 4397 | if (frame_alignment > kPointerSize) { |
| 4398 | __ mov(s5, sp); |
| 4399 | DCHECK(base::bits::IsPowerOfTwo32(frame_alignment)); |
| 4400 | __ And(sp, sp, Operand(-frame_alignment)); |
| 4401 | } |
| 4402 | __ Subu(sp, sp, kCArgsSlotsSize); |
| 4403 | #if defined(V8_HOST_ARCH_MIPS) |
| 4404 | int32_t entry_hook = |
| 4405 | reinterpret_cast<int32_t>(isolate()->function_entry_hook()); |
| 4406 | __ li(t9, Operand(entry_hook)); |
| 4407 | #else |
| 4408 | // Under the simulator we need to indirect the entry hook through a |
| 4409 | // trampoline function at a known address. |
| 4410 | // It additionally takes an isolate as a third parameter. |
| 4411 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
| 4412 | |
| 4413 | ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline)); |
| 4414 | __ li(t9, Operand(ExternalReference(&dispatcher, |
| 4415 | ExternalReference::BUILTIN_CALL, |
| 4416 | isolate()))); |
| 4417 | #endif |
| 4418 | // Call C function through t9 to conform ABI for PIC. |
| 4419 | __ Call(t9); |
| 4420 | |
| 4421 | // Restore the stack pointer if needed. |
| 4422 | if (frame_alignment > kPointerSize) { |
| 4423 | __ mov(sp, s5); |
| 4424 | } else { |
| 4425 | __ Addu(sp, sp, kCArgsSlotsSize); |
| 4426 | } |
| 4427 | |
| 4428 | // Also pop ra to get Ret(0). |
| 4429 | __ MultiPop(kSavedRegs | ra.bit()); |
| 4430 | __ Ret(); |
| 4431 | } |
| 4432 | |
| 4433 | |
| 4434 | template<class T> |
| 4435 | static void CreateArrayDispatch(MacroAssembler* masm, |
| 4436 | AllocationSiteOverrideMode mode) { |
| 4437 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 4438 | T stub(masm->isolate(), GetInitialFastElementsKind(), mode); |
| 4439 | __ TailCallStub(&stub); |
| 4440 | } else if (mode == DONT_OVERRIDE) { |
| 4441 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 4442 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4443 | for (int i = 0; i <= last_index; ++i) { |
| 4444 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4445 | T stub(masm->isolate(), kind); |
| 4446 | __ TailCallStub(&stub, eq, a3, Operand(kind)); |
| 4447 | } |
| 4448 | |
| 4449 | // If we reached this point there is a problem. |
| 4450 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 4451 | } else { |
| 4452 | UNREACHABLE(); |
| 4453 | } |
| 4454 | } |
| 4455 | |
| 4456 | |
| 4457 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm, |
| 4458 | AllocationSiteOverrideMode mode) { |
| 4459 | // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES) |
| 4460 | // a3 - kind (if mode != DISABLE_ALLOCATION_SITES) |
| 4461 | // a0 - number of arguments |
| 4462 | // a1 - constructor? |
| 4463 | // sp[0] - last argument |
| 4464 | Label normal_sequence; |
| 4465 | if (mode == DONT_OVERRIDE) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4466 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 4467 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 4468 | STATIC_ASSERT(FAST_ELEMENTS == 2); |
| 4469 | STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 4470 | STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 4471 | STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4472 | |
| 4473 | // is the low bit set? If so, we are holey and that is good. |
| 4474 | __ And(at, a3, Operand(1)); |
| 4475 | __ Branch(&normal_sequence, ne, at, Operand(zero_reg)); |
| 4476 | } |
| 4477 | |
| 4478 | // look at the first argument |
| 4479 | __ lw(t1, MemOperand(sp, 0)); |
| 4480 | __ Branch(&normal_sequence, eq, t1, Operand(zero_reg)); |
| 4481 | |
| 4482 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 4483 | ElementsKind initial = GetInitialFastElementsKind(); |
| 4484 | ElementsKind holey_initial = GetHoleyElementsKind(initial); |
| 4485 | |
| 4486 | ArraySingleArgumentConstructorStub stub_holey(masm->isolate(), |
| 4487 | holey_initial, |
| 4488 | DISABLE_ALLOCATION_SITES); |
| 4489 | __ TailCallStub(&stub_holey); |
| 4490 | |
| 4491 | __ bind(&normal_sequence); |
| 4492 | ArraySingleArgumentConstructorStub stub(masm->isolate(), |
| 4493 | initial, |
| 4494 | DISABLE_ALLOCATION_SITES); |
| 4495 | __ TailCallStub(&stub); |
| 4496 | } else if (mode == DONT_OVERRIDE) { |
| 4497 | // We are going to create a holey array, but our kind is non-holey. |
| 4498 | // Fix kind and retry (only if we have an allocation site in the slot). |
| 4499 | __ Addu(a3, a3, Operand(1)); |
| 4500 | |
| 4501 | if (FLAG_debug_code) { |
| 4502 | __ lw(t1, FieldMemOperand(a2, 0)); |
| 4503 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 4504 | __ Assert(eq, kExpectedAllocationSite, t1, Operand(at)); |
| 4505 | } |
| 4506 | |
| 4507 | // Save the resulting elements kind in type info. We can't just store a3 |
| 4508 | // in the AllocationSite::transition_info field because elements kind is |
| 4509 | // restricted to a portion of the field...upper bits need to be left alone. |
| 4510 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 4511 | __ lw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset)); |
| 4512 | __ Addu(t0, t0, Operand(Smi::FromInt(kFastElementsKindPackedToHoley))); |
| 4513 | __ sw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset)); |
| 4514 | |
| 4515 | |
| 4516 | __ bind(&normal_sequence); |
| 4517 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 4518 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4519 | for (int i = 0; i <= last_index; ++i) { |
| 4520 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4521 | ArraySingleArgumentConstructorStub stub(masm->isolate(), kind); |
| 4522 | __ TailCallStub(&stub, eq, a3, Operand(kind)); |
| 4523 | } |
| 4524 | |
| 4525 | // If we reached this point there is a problem. |
| 4526 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 4527 | } else { |
| 4528 | UNREACHABLE(); |
| 4529 | } |
| 4530 | } |
| 4531 | |
| 4532 | |
| 4533 | template<class T> |
| 4534 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 4535 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 4536 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4537 | for (int i = 0; i <= to_index; ++i) { |
| 4538 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4539 | T stub(isolate, kind); |
| 4540 | stub.GetCode(); |
| 4541 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
| 4542 | T stub1(isolate, kind, DISABLE_ALLOCATION_SITES); |
| 4543 | stub1.GetCode(); |
| 4544 | } |
| 4545 | } |
| 4546 | } |
| 4547 | |
| 4548 | |
| 4549 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 4550 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 4551 | isolate); |
| 4552 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 4553 | isolate); |
| 4554 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 4555 | isolate); |
| 4556 | } |
| 4557 | |
| 4558 | |
| 4559 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 4560 | Isolate* isolate) { |
| 4561 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 4562 | for (int i = 0; i < 2; i++) { |
| 4563 | // For internal arrays we only need a few things. |
| 4564 | InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]); |
| 4565 | stubh1.GetCode(); |
| 4566 | InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]); |
| 4567 | stubh2.GetCode(); |
| 4568 | InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]); |
| 4569 | stubh3.GetCode(); |
| 4570 | } |
| 4571 | } |
| 4572 | |
| 4573 | |
| 4574 | void ArrayConstructorStub::GenerateDispatchToArrayStub( |
| 4575 | MacroAssembler* masm, |
| 4576 | AllocationSiteOverrideMode mode) { |
| 4577 | if (argument_count() == ANY) { |
| 4578 | Label not_zero_case, not_one_case; |
| 4579 | __ And(at, a0, a0); |
| 4580 | __ Branch(¬_zero_case, ne, at, Operand(zero_reg)); |
| 4581 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 4582 | |
| 4583 | __ bind(¬_zero_case); |
| 4584 | __ Branch(¬_one_case, gt, a0, Operand(1)); |
| 4585 | CreateArrayDispatchOneArgument(masm, mode); |
| 4586 | |
| 4587 | __ bind(¬_one_case); |
| 4588 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 4589 | } else if (argument_count() == NONE) { |
| 4590 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 4591 | } else if (argument_count() == ONE) { |
| 4592 | CreateArrayDispatchOneArgument(masm, mode); |
| 4593 | } else if (argument_count() == MORE_THAN_ONE) { |
| 4594 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 4595 | } else { |
| 4596 | UNREACHABLE(); |
| 4597 | } |
| 4598 | } |
| 4599 | |
| 4600 | |
| 4601 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 4602 | // ----------- S t a t e ------------- |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4603 | // -- a0 : argc (only if argument_count() is ANY or MORE_THAN_ONE) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4604 | // -- a1 : constructor |
| 4605 | // -- a2 : AllocationSite or undefined |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4606 | // -- a3 : Original constructor |
| 4607 | // -- sp[0] : last argument |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4608 | // ----------------------------------- |
| 4609 | |
| 4610 | if (FLAG_debug_code) { |
| 4611 | // The array construct code is only set for the global and natives |
| 4612 | // builtin Array functions which always have maps. |
| 4613 | |
| 4614 | // Initial map for the builtin Array function should be a map. |
| 4615 | __ lw(t0, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4616 | // Will both indicate a NULL and a Smi. |
| 4617 | __ SmiTst(t0, at); |
| 4618 | __ Assert(ne, kUnexpectedInitialMapForArrayFunction, |
| 4619 | at, Operand(zero_reg)); |
| 4620 | __ GetObjectType(t0, t0, t1); |
| 4621 | __ Assert(eq, kUnexpectedInitialMapForArrayFunction, |
| 4622 | t1, Operand(MAP_TYPE)); |
| 4623 | |
| 4624 | // We should either have undefined in a2 or a valid AllocationSite |
| 4625 | __ AssertUndefinedOrAllocationSite(a2, t0); |
| 4626 | } |
| 4627 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4628 | // Enter the context of the Array function. |
| 4629 | __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 4630 | |
| 4631 | Label subclassing; |
| 4632 | __ Branch(&subclassing, ne, a1, Operand(a3)); |
| 4633 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4634 | Label no_info; |
| 4635 | // Get the elements kind and case on that. |
| 4636 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 4637 | __ Branch(&no_info, eq, a2, Operand(at)); |
| 4638 | |
| 4639 | __ lw(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset)); |
| 4640 | __ SmiUntag(a3); |
| 4641 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 4642 | __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask)); |
| 4643 | GenerateDispatchToArrayStub(masm, DONT_OVERRIDE); |
| 4644 | |
| 4645 | __ bind(&no_info); |
| 4646 | GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4647 | |
| 4648 | // Subclassing. |
| 4649 | __ bind(&subclassing); |
| 4650 | switch (argument_count()) { |
| 4651 | case ANY: |
| 4652 | case MORE_THAN_ONE: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4653 | __ Lsa(at, sp, a0, kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4654 | __ sw(a1, MemOperand(at)); |
| 4655 | __ li(at, Operand(3)); |
| 4656 | __ addu(a0, a0, at); |
| 4657 | break; |
| 4658 | case NONE: |
| 4659 | __ sw(a1, MemOperand(sp, 0 * kPointerSize)); |
| 4660 | __ li(a0, Operand(3)); |
| 4661 | break; |
| 4662 | case ONE: |
| 4663 | __ sw(a1, MemOperand(sp, 1 * kPointerSize)); |
| 4664 | __ li(a0, Operand(4)); |
| 4665 | break; |
| 4666 | } |
| 4667 | __ Push(a3, a2); |
| 4668 | __ JumpToExternalReference(ExternalReference(Runtime::kNewArray, isolate())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4669 | } |
| 4670 | |
| 4671 | |
| 4672 | void InternalArrayConstructorStub::GenerateCase( |
| 4673 | MacroAssembler* masm, ElementsKind kind) { |
| 4674 | |
| 4675 | InternalArrayNoArgumentConstructorStub stub0(isolate(), kind); |
| 4676 | __ TailCallStub(&stub0, lo, a0, Operand(1)); |
| 4677 | |
| 4678 | InternalArrayNArgumentsConstructorStub stubN(isolate(), kind); |
| 4679 | __ TailCallStub(&stubN, hi, a0, Operand(1)); |
| 4680 | |
| 4681 | if (IsFastPackedElementsKind(kind)) { |
| 4682 | // We might need to create a holey array |
| 4683 | // look at the first argument. |
| 4684 | __ lw(at, MemOperand(sp, 0)); |
| 4685 | |
| 4686 | InternalArraySingleArgumentConstructorStub |
| 4687 | stub1_holey(isolate(), GetHoleyElementsKind(kind)); |
| 4688 | __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg)); |
| 4689 | } |
| 4690 | |
| 4691 | InternalArraySingleArgumentConstructorStub stub1(isolate(), kind); |
| 4692 | __ TailCallStub(&stub1); |
| 4693 | } |
| 4694 | |
| 4695 | |
| 4696 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 4697 | // ----------- S t a t e ------------- |
| 4698 | // -- a0 : argc |
| 4699 | // -- a1 : constructor |
| 4700 | // -- sp[0] : return address |
| 4701 | // -- sp[4] : last argument |
| 4702 | // ----------------------------------- |
| 4703 | |
| 4704 | if (FLAG_debug_code) { |
| 4705 | // The array construct code is only set for the global and natives |
| 4706 | // builtin Array functions which always have maps. |
| 4707 | |
| 4708 | // Initial map for the builtin Array function should be a map. |
| 4709 | __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4710 | // Will both indicate a NULL and a Smi. |
| 4711 | __ SmiTst(a3, at); |
| 4712 | __ Assert(ne, kUnexpectedInitialMapForArrayFunction, |
| 4713 | at, Operand(zero_reg)); |
| 4714 | __ GetObjectType(a3, a3, t0); |
| 4715 | __ Assert(eq, kUnexpectedInitialMapForArrayFunction, |
| 4716 | t0, Operand(MAP_TYPE)); |
| 4717 | } |
| 4718 | |
| 4719 | // Figure out the right elements kind. |
| 4720 | __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4721 | |
| 4722 | // Load the map's "bit field 2" into a3. We only need the first byte, |
| 4723 | // but the following bit field extraction takes care of that anyway. |
| 4724 | __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset)); |
| 4725 | // Retrieve elements_kind from bit field 2. |
| 4726 | __ DecodeField<Map::ElementsKindBits>(a3); |
| 4727 | |
| 4728 | if (FLAG_debug_code) { |
| 4729 | Label done; |
| 4730 | __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS)); |
| 4731 | __ Assert( |
| 4732 | eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray, |
| 4733 | a3, Operand(FAST_HOLEY_ELEMENTS)); |
| 4734 | __ bind(&done); |
| 4735 | } |
| 4736 | |
| 4737 | Label fast_elements_case; |
| 4738 | __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS)); |
| 4739 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 4740 | |
| 4741 | __ bind(&fast_elements_case); |
| 4742 | GenerateCase(masm, FAST_ELEMENTS); |
| 4743 | } |
| 4744 | |
| 4745 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4746 | void FastNewObjectStub::Generate(MacroAssembler* masm) { |
| 4747 | // ----------- S t a t e ------------- |
| 4748 | // -- a1 : target |
| 4749 | // -- a3 : new target |
| 4750 | // -- cp : context |
| 4751 | // -- ra : return address |
| 4752 | // ----------------------------------- |
| 4753 | __ AssertFunction(a1); |
| 4754 | __ AssertReceiver(a3); |
| 4755 | |
| 4756 | // Verify that the new target is a JSFunction. |
| 4757 | Label new_object; |
| 4758 | __ GetObjectType(a3, a2, a2); |
| 4759 | __ Branch(&new_object, ne, a2, Operand(JS_FUNCTION_TYPE)); |
| 4760 | |
| 4761 | // Load the initial map and verify that it's in fact a map. |
| 4762 | __ lw(a2, FieldMemOperand(a3, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4763 | __ JumpIfSmi(a2, &new_object); |
| 4764 | __ GetObjectType(a2, a0, a0); |
| 4765 | __ Branch(&new_object, ne, a0, Operand(MAP_TYPE)); |
| 4766 | |
| 4767 | // Fall back to runtime if the target differs from the new target's |
| 4768 | // initial map constructor. |
| 4769 | __ lw(a0, FieldMemOperand(a2, Map::kConstructorOrBackPointerOffset)); |
| 4770 | __ Branch(&new_object, ne, a0, Operand(a1)); |
| 4771 | |
| 4772 | // Allocate the JSObject on the heap. |
| 4773 | Label allocate, done_allocate; |
| 4774 | __ lbu(t0, FieldMemOperand(a2, Map::kInstanceSizeOffset)); |
| 4775 | __ Allocate(t0, v0, t1, a0, &allocate, SIZE_IN_WORDS); |
| 4776 | __ bind(&done_allocate); |
| 4777 | |
| 4778 | // Initialize the JSObject fields. |
| 4779 | __ sw(a2, MemOperand(v0, JSObject::kMapOffset)); |
| 4780 | __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex); |
| 4781 | __ sw(a3, MemOperand(v0, JSObject::kPropertiesOffset)); |
| 4782 | __ sw(a3, MemOperand(v0, JSObject::kElementsOffset)); |
| 4783 | STATIC_ASSERT(JSObject::kHeaderSize == 3 * kPointerSize); |
| 4784 | __ Addu(a1, v0, Operand(JSObject::kHeaderSize)); |
| 4785 | |
| 4786 | // ----------- S t a t e ------------- |
| 4787 | // -- v0 : result (untagged) |
| 4788 | // -- a1 : result fields (untagged) |
| 4789 | // -- t1 : result end (untagged) |
| 4790 | // -- a2 : initial map |
| 4791 | // -- cp : context |
| 4792 | // -- ra : return address |
| 4793 | // ----------------------------------- |
| 4794 | |
| 4795 | // Perform in-object slack tracking if requested. |
| 4796 | Label slack_tracking; |
| 4797 | STATIC_ASSERT(Map::kNoSlackTracking == 0); |
| 4798 | __ lw(a3, FieldMemOperand(a2, Map::kBitField3Offset)); |
| 4799 | __ And(at, a3, Operand(Map::ConstructionCounter::kMask)); |
| 4800 | __ Branch(USE_DELAY_SLOT, &slack_tracking, ne, at, Operand(0)); |
| 4801 | __ LoadRoot(a0, Heap::kUndefinedValueRootIndex); // In delay slot. |
| 4802 | { |
| 4803 | // Initialize all in-object fields with undefined. |
| 4804 | __ InitializeFieldsWithFiller(a1, t1, a0); |
| 4805 | |
| 4806 | // Add the object tag to make the JSObject real. |
| 4807 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4808 | __ Ret(USE_DELAY_SLOT); |
| 4809 | __ Addu(v0, v0, Operand(kHeapObjectTag)); // In delay slot. |
| 4810 | } |
| 4811 | __ bind(&slack_tracking); |
| 4812 | { |
| 4813 | // Decrease generous allocation count. |
| 4814 | STATIC_ASSERT(Map::ConstructionCounter::kNext == 32); |
| 4815 | __ Subu(a3, a3, Operand(1 << Map::ConstructionCounter::kShift)); |
| 4816 | __ sw(a3, FieldMemOperand(a2, Map::kBitField3Offset)); |
| 4817 | |
| 4818 | // Initialize the in-object fields with undefined. |
| 4819 | __ lbu(t0, FieldMemOperand(a2, Map::kUnusedPropertyFieldsOffset)); |
| 4820 | __ sll(t0, t0, kPointerSizeLog2); |
| 4821 | __ subu(t0, t1, t0); |
| 4822 | __ InitializeFieldsWithFiller(a1, t0, a0); |
| 4823 | |
| 4824 | // Initialize the remaining (reserved) fields with one pointer filler map. |
| 4825 | __ LoadRoot(a0, Heap::kOnePointerFillerMapRootIndex); |
| 4826 | __ InitializeFieldsWithFiller(a1, t1, a0); |
| 4827 | |
| 4828 | // Check if we can finalize the instance size. |
| 4829 | Label finalize; |
| 4830 | STATIC_ASSERT(Map::kSlackTrackingCounterEnd == 1); |
| 4831 | __ And(a3, a3, Operand(Map::ConstructionCounter::kMask)); |
| 4832 | __ Branch(USE_DELAY_SLOT, &finalize, eq, a3, Operand(zero_reg)); |
| 4833 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4834 | __ Addu(v0, v0, Operand(kHeapObjectTag)); // In delay slot. |
| 4835 | __ Ret(); |
| 4836 | |
| 4837 | // Finalize the instance size. |
| 4838 | __ bind(&finalize); |
| 4839 | { |
| 4840 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4841 | __ Push(v0, a2); |
| 4842 | __ CallRuntime(Runtime::kFinalizeInstanceSize); |
| 4843 | __ Pop(v0); |
| 4844 | } |
| 4845 | __ Ret(); |
| 4846 | } |
| 4847 | |
| 4848 | // Fall back to %AllocateInNewSpace. |
| 4849 | __ bind(&allocate); |
| 4850 | { |
| 4851 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4852 | STATIC_ASSERT(kSmiTag == 0); |
| 4853 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4854 | __ sll(t0, t0, kPointerSizeLog2 + kSmiTagSize); |
| 4855 | __ Push(a2, t0); |
| 4856 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 4857 | __ Pop(a2); |
| 4858 | } |
| 4859 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4860 | __ Subu(v0, v0, Operand(kHeapObjectTag)); |
| 4861 | __ lbu(t1, FieldMemOperand(a2, Map::kInstanceSizeOffset)); |
| 4862 | __ Lsa(t1, v0, t1, kPointerSizeLog2); |
| 4863 | __ jmp(&done_allocate); |
| 4864 | |
| 4865 | // Fall back to %NewObject. |
| 4866 | __ bind(&new_object); |
| 4867 | __ Push(a1, a3); |
| 4868 | __ TailCallRuntime(Runtime::kNewObject); |
| 4869 | } |
| 4870 | |
| 4871 | |
| 4872 | void FastNewRestParameterStub::Generate(MacroAssembler* masm) { |
| 4873 | // ----------- S t a t e ------------- |
| 4874 | // -- a1 : function |
| 4875 | // -- cp : context |
| 4876 | // -- fp : frame pointer |
| 4877 | // -- ra : return address |
| 4878 | // ----------------------------------- |
| 4879 | __ AssertFunction(a1); |
| 4880 | |
| 4881 | // For Ignition we need to skip all possible handler/stub frames until |
| 4882 | // we reach the JavaScript frame for the function (similar to what the |
| 4883 | // runtime fallback implementation does). So make a2 point to that |
| 4884 | // JavaScript frame. |
| 4885 | { |
| 4886 | Label loop, loop_entry; |
| 4887 | __ Branch(USE_DELAY_SLOT, &loop_entry); |
| 4888 | __ mov(a2, fp); // In delay slot. |
| 4889 | __ bind(&loop); |
| 4890 | __ lw(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
| 4891 | __ bind(&loop_entry); |
| 4892 | __ lw(a3, MemOperand(a2, StandardFrameConstants::kMarkerOffset)); |
| 4893 | __ Branch(&loop, ne, a1, Operand(a3)); |
| 4894 | } |
| 4895 | |
| 4896 | // Check if we have rest parameters (only possible if we have an |
| 4897 | // arguments adaptor frame below the function frame). |
| 4898 | Label no_rest_parameters; |
| 4899 | __ lw(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
| 4900 | __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset)); |
| 4901 | __ Branch(&no_rest_parameters, ne, a3, |
| 4902 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4903 | |
| 4904 | // Check if the arguments adaptor frame contains more arguments than |
| 4905 | // specified by the function's internal formal parameter count. |
| 4906 | Label rest_parameters; |
| 4907 | __ lw(a0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4908 | __ lw(a1, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 4909 | __ lw(a1, |
| 4910 | FieldMemOperand(a1, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 4911 | __ Subu(a0, a0, Operand(a1)); |
| 4912 | __ Branch(&rest_parameters, gt, a0, Operand(zero_reg)); |
| 4913 | |
| 4914 | // Return an empty rest parameter array. |
| 4915 | __ bind(&no_rest_parameters); |
| 4916 | { |
| 4917 | // ----------- S t a t e ------------- |
| 4918 | // -- cp : context |
| 4919 | // -- ra : return address |
| 4920 | // ----------------------------------- |
| 4921 | |
| 4922 | // Allocate an empty rest parameter array. |
| 4923 | Label allocate, done_allocate; |
| 4924 | __ Allocate(JSArray::kSize, v0, a0, a1, &allocate, TAG_OBJECT); |
| 4925 | __ bind(&done_allocate); |
| 4926 | |
| 4927 | // Setup the rest parameter array in v0. |
| 4928 | __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, a1); |
| 4929 | __ sw(a1, FieldMemOperand(v0, JSArray::kMapOffset)); |
| 4930 | __ LoadRoot(a1, Heap::kEmptyFixedArrayRootIndex); |
| 4931 | __ sw(a1, FieldMemOperand(v0, JSArray::kPropertiesOffset)); |
| 4932 | __ sw(a1, FieldMemOperand(v0, JSArray::kElementsOffset)); |
| 4933 | __ Move(a1, Smi::FromInt(0)); |
| 4934 | __ Ret(USE_DELAY_SLOT); |
| 4935 | __ sw(a1, FieldMemOperand(v0, JSArray::kLengthOffset)); // In delay slot |
| 4936 | STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize); |
| 4937 | |
| 4938 | // Fall back to %AllocateInNewSpace. |
| 4939 | __ bind(&allocate); |
| 4940 | { |
| 4941 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4942 | __ Push(Smi::FromInt(JSArray::kSize)); |
| 4943 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 4944 | } |
| 4945 | __ jmp(&done_allocate); |
| 4946 | } |
| 4947 | |
| 4948 | __ bind(&rest_parameters); |
| 4949 | { |
| 4950 | // Compute the pointer to the first rest parameter (skippping the receiver). |
| 4951 | __ Lsa(a2, a2, a0, kPointerSizeLog2 - 1); |
| 4952 | __ Addu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset - |
| 4953 | 1 * kPointerSize)); |
| 4954 | |
| 4955 | // ----------- S t a t e ------------- |
| 4956 | // -- cp : context |
| 4957 | // -- a0 : number of rest parameters (tagged) |
| 4958 | // -- a2 : pointer to first rest parameters |
| 4959 | // -- ra : return address |
| 4960 | // ----------------------------------- |
| 4961 | |
| 4962 | // Allocate space for the rest parameter array plus the backing store. |
| 4963 | Label allocate, done_allocate; |
| 4964 | __ li(a1, Operand(JSArray::kSize + FixedArray::kHeaderSize)); |
| 4965 | __ Lsa(a1, a1, a0, kPointerSizeLog2 - 1); |
| 4966 | __ Allocate(a1, v0, a3, t0, &allocate, TAG_OBJECT); |
| 4967 | __ bind(&done_allocate); |
| 4968 | |
| 4969 | // Setup the elements array in v0. |
| 4970 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 4971 | __ sw(at, FieldMemOperand(v0, FixedArray::kMapOffset)); |
| 4972 | __ sw(a0, FieldMemOperand(v0, FixedArray::kLengthOffset)); |
| 4973 | __ Addu(a3, v0, Operand(FixedArray::kHeaderSize)); |
| 4974 | { |
| 4975 | Label loop, done_loop; |
| 4976 | __ sll(at, a0, kPointerSizeLog2 - 1); |
| 4977 | __ Addu(a1, a3, at); |
| 4978 | __ bind(&loop); |
| 4979 | __ Branch(&done_loop, eq, a1, Operand(a3)); |
| 4980 | __ lw(at, MemOperand(a2, 0 * kPointerSize)); |
| 4981 | __ sw(at, FieldMemOperand(a3, 0 * kPointerSize)); |
| 4982 | __ Subu(a2, a2, Operand(1 * kPointerSize)); |
| 4983 | __ Addu(a3, a3, Operand(1 * kPointerSize)); |
| 4984 | __ jmp(&loop); |
| 4985 | __ bind(&done_loop); |
| 4986 | } |
| 4987 | |
| 4988 | // Setup the rest parameter array in a3. |
| 4989 | __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, at); |
| 4990 | __ sw(at, FieldMemOperand(a3, JSArray::kMapOffset)); |
| 4991 | __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex); |
| 4992 | __ sw(at, FieldMemOperand(a3, JSArray::kPropertiesOffset)); |
| 4993 | __ sw(v0, FieldMemOperand(a3, JSArray::kElementsOffset)); |
| 4994 | __ sw(a0, FieldMemOperand(a3, JSArray::kLengthOffset)); |
| 4995 | STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize); |
| 4996 | __ Ret(USE_DELAY_SLOT); |
| 4997 | __ mov(v0, a3); // In delay slot |
| 4998 | |
| 4999 | // Fall back to %AllocateInNewSpace. |
| 5000 | __ bind(&allocate); |
| 5001 | { |
| 5002 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5003 | __ SmiTag(a1); |
| 5004 | __ Push(a0, a2, a1); |
| 5005 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 5006 | __ Pop(a0, a2); |
| 5007 | } |
| 5008 | __ jmp(&done_allocate); |
| 5009 | } |
| 5010 | } |
| 5011 | |
| 5012 | |
| 5013 | void FastNewSloppyArgumentsStub::Generate(MacroAssembler* masm) { |
| 5014 | // ----------- S t a t e ------------- |
| 5015 | // -- a1 : function |
| 5016 | // -- cp : context |
| 5017 | // -- fp : frame pointer |
| 5018 | // -- ra : return address |
| 5019 | // ----------------------------------- |
| 5020 | __ AssertFunction(a1); |
| 5021 | |
| 5022 | // TODO(bmeurer): Cleanup to match the FastNewStrictArgumentsStub. |
| 5023 | __ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 5024 | __ lw(a2, |
| 5025 | FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 5026 | __ Lsa(a3, fp, a2, kPointerSizeLog2 - 1); |
| 5027 | __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 5028 | |
| 5029 | // a1 : function |
| 5030 | // a2 : number of parameters (tagged) |
| 5031 | // a3 : parameters pointer |
| 5032 | // Registers used over whole function: |
| 5033 | // t1 : arguments count (tagged) |
| 5034 | // t2 : mapped parameter count (tagged) |
| 5035 | |
| 5036 | // Check if the calling frame is an arguments adaptor frame. |
| 5037 | Label adaptor_frame, try_allocate, runtime; |
| 5038 | __ lw(t0, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 5039 | __ lw(a0, MemOperand(t0, StandardFrameConstants::kContextOffset)); |
| 5040 | __ Branch(&adaptor_frame, eq, a0, |
| 5041 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5042 | |
| 5043 | // No adaptor, parameter count = argument count. |
| 5044 | __ mov(t1, a2); |
| 5045 | __ Branch(USE_DELAY_SLOT, &try_allocate); |
| 5046 | __ mov(t2, a2); // In delay slot. |
| 5047 | |
| 5048 | // We have an adaptor frame. Patch the parameters pointer. |
| 5049 | __ bind(&adaptor_frame); |
| 5050 | __ lw(t1, MemOperand(t0, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 5051 | __ Lsa(t0, t0, t1, 1); |
| 5052 | __ Addu(a3, t0, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 5053 | |
| 5054 | // t1 = argument count (tagged) |
| 5055 | // t2 = parameter count (tagged) |
| 5056 | // Compute the mapped parameter count = min(t2, t1) in t2. |
| 5057 | __ mov(t2, a2); |
| 5058 | __ Branch(&try_allocate, le, t2, Operand(t1)); |
| 5059 | __ mov(t2, t1); |
| 5060 | |
| 5061 | __ bind(&try_allocate); |
| 5062 | |
| 5063 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 5064 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 5065 | const int kParameterMapHeaderSize = |
| 5066 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 5067 | // If there are no mapped parameters, we do not need the parameter_map. |
| 5068 | Label param_map_size; |
| 5069 | DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0)); |
| 5070 | __ Branch(USE_DELAY_SLOT, ¶m_map_size, eq, t2, Operand(zero_reg)); |
| 5071 | __ mov(t5, zero_reg); // In delay slot: param map size = 0 when t2 == 0. |
| 5072 | __ sll(t5, t2, 1); |
| 5073 | __ addiu(t5, t5, kParameterMapHeaderSize); |
| 5074 | __ bind(¶m_map_size); |
| 5075 | |
| 5076 | // 2. Backing store. |
| 5077 | __ Lsa(t5, t5, t1, 1); |
| 5078 | __ Addu(t5, t5, Operand(FixedArray::kHeaderSize)); |
| 5079 | |
| 5080 | // 3. Arguments object. |
| 5081 | __ Addu(t5, t5, Operand(JSSloppyArgumentsObject::kSize)); |
| 5082 | |
| 5083 | // Do the allocation of all three objects in one go. |
| 5084 | __ Allocate(t5, v0, t5, t0, &runtime, TAG_OBJECT); |
| 5085 | |
| 5086 | // v0 = address of new object(s) (tagged) |
| 5087 | // a2 = argument count (smi-tagged) |
| 5088 | // Get the arguments boilerplate from the current native context into t0. |
| 5089 | const int kNormalOffset = |
| 5090 | Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX); |
| 5091 | const int kAliasedOffset = |
| 5092 | Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX); |
| 5093 | |
| 5094 | __ lw(t0, NativeContextMemOperand()); |
| 5095 | Label skip2_ne, skip2_eq; |
| 5096 | __ Branch(&skip2_ne, ne, t2, Operand(zero_reg)); |
| 5097 | __ lw(t0, MemOperand(t0, kNormalOffset)); |
| 5098 | __ bind(&skip2_ne); |
| 5099 | |
| 5100 | __ Branch(&skip2_eq, eq, t2, Operand(zero_reg)); |
| 5101 | __ lw(t0, MemOperand(t0, kAliasedOffset)); |
| 5102 | __ bind(&skip2_eq); |
| 5103 | |
| 5104 | // v0 = address of new object (tagged) |
| 5105 | // a2 = argument count (smi-tagged) |
| 5106 | // t0 = address of arguments map (tagged) |
| 5107 | // t2 = mapped parameter count (tagged) |
| 5108 | __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset)); |
| 5109 | __ LoadRoot(t5, Heap::kEmptyFixedArrayRootIndex); |
| 5110 | __ sw(t5, FieldMemOperand(v0, JSObject::kPropertiesOffset)); |
| 5111 | __ sw(t5, FieldMemOperand(v0, JSObject::kElementsOffset)); |
| 5112 | |
| 5113 | // Set up the callee in-object property. |
| 5114 | __ AssertNotSmi(a1); |
| 5115 | __ sw(a1, FieldMemOperand(v0, JSSloppyArgumentsObject::kCalleeOffset)); |
| 5116 | |
| 5117 | // Use the length (smi tagged) and set that as an in-object property too. |
| 5118 | __ AssertSmi(t1); |
| 5119 | __ sw(t1, FieldMemOperand(v0, JSSloppyArgumentsObject::kLengthOffset)); |
| 5120 | |
| 5121 | // Set up the elements pointer in the allocated arguments object. |
| 5122 | // If we allocated a parameter map, t0 will point there, otherwise |
| 5123 | // it will point to the backing store. |
| 5124 | __ Addu(t0, v0, Operand(JSSloppyArgumentsObject::kSize)); |
| 5125 | __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset)); |
| 5126 | |
| 5127 | // v0 = address of new object (tagged) |
| 5128 | // a2 = argument count (tagged) |
| 5129 | // t0 = address of parameter map or backing store (tagged) |
| 5130 | // t2 = mapped parameter count (tagged) |
| 5131 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 5132 | Label skip_parameter_map; |
| 5133 | Label skip3; |
| 5134 | __ Branch(&skip3, ne, t2, Operand(Smi::FromInt(0))); |
| 5135 | // Move backing store address to a1, because it is |
| 5136 | // expected there when filling in the unmapped arguments. |
| 5137 | __ mov(a1, t0); |
| 5138 | __ bind(&skip3); |
| 5139 | |
| 5140 | __ Branch(&skip_parameter_map, eq, t2, Operand(Smi::FromInt(0))); |
| 5141 | |
| 5142 | __ LoadRoot(t1, Heap::kSloppyArgumentsElementsMapRootIndex); |
| 5143 | __ sw(t1, FieldMemOperand(t0, FixedArray::kMapOffset)); |
| 5144 | __ Addu(t1, t2, Operand(Smi::FromInt(2))); |
| 5145 | __ sw(t1, FieldMemOperand(t0, FixedArray::kLengthOffset)); |
| 5146 | __ sw(cp, FieldMemOperand(t0, FixedArray::kHeaderSize + 0 * kPointerSize)); |
| 5147 | __ Lsa(t1, t0, t2, 1); |
| 5148 | __ Addu(t1, t1, Operand(kParameterMapHeaderSize)); |
| 5149 | __ sw(t1, FieldMemOperand(t0, FixedArray::kHeaderSize + 1 * kPointerSize)); |
| 5150 | |
| 5151 | // Copy the parameter slots and the holes in the arguments. |
| 5152 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 5153 | // where parameters are stored in reverse order, at |
| 5154 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 5155 | // The mapped parameter thus need to get indices |
| 5156 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 5157 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 5158 | // We loop from right to left. |
| 5159 | Label parameters_loop, parameters_test; |
| 5160 | __ mov(t1, t2); |
| 5161 | __ Addu(t5, a2, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 5162 | __ Subu(t5, t5, Operand(t2)); |
| 5163 | __ LoadRoot(t3, Heap::kTheHoleValueRootIndex); |
| 5164 | __ Lsa(a1, t0, t1, 1); |
| 5165 | __ Addu(a1, a1, Operand(kParameterMapHeaderSize)); |
| 5166 | |
| 5167 | // a1 = address of backing store (tagged) |
| 5168 | // t0 = address of parameter map (tagged) |
| 5169 | // a0 = temporary scratch (a.o., for address calculation) |
| 5170 | // t1 = loop variable (tagged) |
| 5171 | // t3 = the hole value |
| 5172 | __ jmp(¶meters_test); |
| 5173 | |
| 5174 | __ bind(¶meters_loop); |
| 5175 | __ Subu(t1, t1, Operand(Smi::FromInt(1))); |
| 5176 | __ sll(a0, t1, 1); |
| 5177 | __ Addu(a0, a0, Operand(kParameterMapHeaderSize - kHeapObjectTag)); |
| 5178 | __ Addu(t6, t0, a0); |
| 5179 | __ sw(t5, MemOperand(t6)); |
| 5180 | __ Subu(a0, a0, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize)); |
| 5181 | __ Addu(t6, a1, a0); |
| 5182 | __ sw(t3, MemOperand(t6)); |
| 5183 | __ Addu(t5, t5, Operand(Smi::FromInt(1))); |
| 5184 | __ bind(¶meters_test); |
| 5185 | __ Branch(¶meters_loop, ne, t1, Operand(Smi::FromInt(0))); |
| 5186 | |
| 5187 | // t1 = argument count (tagged). |
| 5188 | __ lw(t1, FieldMemOperand(v0, JSSloppyArgumentsObject::kLengthOffset)); |
| 5189 | |
| 5190 | __ bind(&skip_parameter_map); |
| 5191 | // v0 = address of new object (tagged) |
| 5192 | // a1 = address of backing store (tagged) |
| 5193 | // t1 = argument count (tagged) |
| 5194 | // t2 = mapped parameter count (tagged) |
| 5195 | // t5 = scratch |
| 5196 | // Copy arguments header and remaining slots (if there are any). |
| 5197 | __ LoadRoot(t5, Heap::kFixedArrayMapRootIndex); |
| 5198 | __ sw(t5, FieldMemOperand(a1, FixedArray::kMapOffset)); |
| 5199 | __ sw(t1, FieldMemOperand(a1, FixedArray::kLengthOffset)); |
| 5200 | |
| 5201 | Label arguments_loop, arguments_test; |
| 5202 | __ sll(t6, t2, 1); |
| 5203 | __ Subu(a3, a3, Operand(t6)); |
| 5204 | __ jmp(&arguments_test); |
| 5205 | |
| 5206 | __ bind(&arguments_loop); |
| 5207 | __ Subu(a3, a3, Operand(kPointerSize)); |
| 5208 | __ lw(t0, MemOperand(a3, 0)); |
| 5209 | __ Lsa(t5, a1, t2, 1); |
| 5210 | __ sw(t0, FieldMemOperand(t5, FixedArray::kHeaderSize)); |
| 5211 | __ Addu(t2, t2, Operand(Smi::FromInt(1))); |
| 5212 | |
| 5213 | __ bind(&arguments_test); |
| 5214 | __ Branch(&arguments_loop, lt, t2, Operand(t1)); |
| 5215 | |
| 5216 | // Return. |
| 5217 | __ Ret(); |
| 5218 | |
| 5219 | // Do the runtime call to allocate the arguments object. |
| 5220 | // t1 = argument count (tagged) |
| 5221 | __ bind(&runtime); |
| 5222 | __ Push(a1, a3, t1); |
| 5223 | __ TailCallRuntime(Runtime::kNewSloppyArguments); |
| 5224 | } |
| 5225 | |
| 5226 | |
| 5227 | void FastNewStrictArgumentsStub::Generate(MacroAssembler* masm) { |
| 5228 | // ----------- S t a t e ------------- |
| 5229 | // -- a1 : function |
| 5230 | // -- cp : context |
| 5231 | // -- fp : frame pointer |
| 5232 | // -- ra : return address |
| 5233 | // ----------------------------------- |
| 5234 | __ AssertFunction(a1); |
| 5235 | |
| 5236 | // For Ignition we need to skip all possible handler/stub frames until |
| 5237 | // we reach the JavaScript frame for the function (similar to what the |
| 5238 | // runtime fallback implementation does). So make a2 point to that |
| 5239 | // JavaScript frame. |
| 5240 | { |
| 5241 | Label loop, loop_entry; |
| 5242 | __ Branch(USE_DELAY_SLOT, &loop_entry); |
| 5243 | __ mov(a2, fp); // In delay slot. |
| 5244 | __ bind(&loop); |
| 5245 | __ lw(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
| 5246 | __ bind(&loop_entry); |
| 5247 | __ lw(a3, MemOperand(a2, StandardFrameConstants::kMarkerOffset)); |
| 5248 | __ Branch(&loop, ne, a1, Operand(a3)); |
| 5249 | } |
| 5250 | |
| 5251 | // Check if we have an arguments adaptor frame below the function frame. |
| 5252 | Label arguments_adaptor, arguments_done; |
| 5253 | __ lw(a3, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
| 5254 | __ lw(a0, MemOperand(a3, StandardFrameConstants::kContextOffset)); |
| 5255 | __ Branch(&arguments_adaptor, eq, a0, |
| 5256 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5257 | { |
| 5258 | __ lw(a1, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 5259 | __ lw(a0, |
| 5260 | FieldMemOperand(a1, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 5261 | __ Lsa(a2, a2, a0, kPointerSizeLog2 - 1); |
| 5262 | __ Addu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset - |
| 5263 | 1 * kPointerSize)); |
| 5264 | } |
| 5265 | __ Branch(&arguments_done); |
| 5266 | __ bind(&arguments_adaptor); |
| 5267 | { |
| 5268 | __ lw(a0, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 5269 | __ Lsa(a2, a3, a0, kPointerSizeLog2 - 1); |
| 5270 | __ Addu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset - |
| 5271 | 1 * kPointerSize)); |
| 5272 | } |
| 5273 | __ bind(&arguments_done); |
| 5274 | |
| 5275 | // ----------- S t a t e ------------- |
| 5276 | // -- cp : context |
| 5277 | // -- a0 : number of rest parameters (tagged) |
| 5278 | // -- a2 : pointer to first rest parameters |
| 5279 | // -- ra : return address |
| 5280 | // ----------------------------------- |
| 5281 | |
| 5282 | // Allocate space for the strict arguments object plus the backing store. |
| 5283 | Label allocate, done_allocate; |
| 5284 | __ li(a1, Operand(JSStrictArgumentsObject::kSize + FixedArray::kHeaderSize)); |
| 5285 | __ Lsa(a1, a1, a0, kPointerSizeLog2 - 1); |
| 5286 | __ Allocate(a1, v0, a3, t0, &allocate, TAG_OBJECT); |
| 5287 | __ bind(&done_allocate); |
| 5288 | |
| 5289 | // Setup the elements array in v0. |
| 5290 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 5291 | __ sw(at, FieldMemOperand(v0, FixedArray::kMapOffset)); |
| 5292 | __ sw(a0, FieldMemOperand(v0, FixedArray::kLengthOffset)); |
| 5293 | __ Addu(a3, v0, Operand(FixedArray::kHeaderSize)); |
| 5294 | { |
| 5295 | Label loop, done_loop; |
| 5296 | __ sll(at, a0, kPointerSizeLog2 - 1); |
| 5297 | __ Addu(a1, a3, at); |
| 5298 | __ bind(&loop); |
| 5299 | __ Branch(&done_loop, eq, a1, Operand(a3)); |
| 5300 | __ lw(at, MemOperand(a2, 0 * kPointerSize)); |
| 5301 | __ sw(at, FieldMemOperand(a3, 0 * kPointerSize)); |
| 5302 | __ Subu(a2, a2, Operand(1 * kPointerSize)); |
| 5303 | __ Addu(a3, a3, Operand(1 * kPointerSize)); |
| 5304 | __ Branch(&loop); |
| 5305 | __ bind(&done_loop); |
| 5306 | } |
| 5307 | |
| 5308 | // Setup the strict arguments object in a3. |
| 5309 | __ LoadNativeContextSlot(Context::STRICT_ARGUMENTS_MAP_INDEX, at); |
| 5310 | __ sw(at, FieldMemOperand(a3, JSStrictArgumentsObject::kMapOffset)); |
| 5311 | __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex); |
| 5312 | __ sw(at, FieldMemOperand(a3, JSStrictArgumentsObject::kPropertiesOffset)); |
| 5313 | __ sw(v0, FieldMemOperand(a3, JSStrictArgumentsObject::kElementsOffset)); |
| 5314 | __ sw(a0, FieldMemOperand(a3, JSStrictArgumentsObject::kLengthOffset)); |
| 5315 | STATIC_ASSERT(JSStrictArgumentsObject::kSize == 4 * kPointerSize); |
| 5316 | __ Ret(USE_DELAY_SLOT); |
| 5317 | __ mov(v0, a3); // In delay slot |
| 5318 | |
| 5319 | // Fall back to %AllocateInNewSpace. |
| 5320 | __ bind(&allocate); |
| 5321 | { |
| 5322 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5323 | __ SmiTag(a1); |
| 5324 | __ Push(a0, a2, a1); |
| 5325 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 5326 | __ Pop(a0, a2); |
| 5327 | } |
| 5328 | __ jmp(&done_allocate); |
| 5329 | } |
| 5330 | |
| 5331 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5332 | void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) { |
| 5333 | Register context_reg = cp; |
| 5334 | Register slot_reg = a2; |
| 5335 | Register result_reg = v0; |
| 5336 | Label slow_case; |
| 5337 | |
| 5338 | // Go up context chain to the script context. |
| 5339 | for (int i = 0; i < depth(); ++i) { |
| 5340 | __ lw(result_reg, ContextMemOperand(context_reg, Context::PREVIOUS_INDEX)); |
| 5341 | context_reg = result_reg; |
| 5342 | } |
| 5343 | |
| 5344 | // Load the PropertyCell value at the specified slot. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5345 | __ Lsa(at, context_reg, slot_reg, kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5346 | __ lw(result_reg, ContextMemOperand(at, 0)); |
| 5347 | __ lw(result_reg, FieldMemOperand(result_reg, PropertyCell::kValueOffset)); |
| 5348 | |
| 5349 | // Check that value is not the_hole. |
| 5350 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 5351 | __ Branch(&slow_case, eq, result_reg, Operand(at)); |
| 5352 | __ Ret(); |
| 5353 | |
| 5354 | // Fallback to the runtime. |
| 5355 | __ bind(&slow_case); |
| 5356 | __ SmiTag(slot_reg); |
| 5357 | __ Push(slot_reg); |
| 5358 | __ TailCallRuntime(Runtime::kLoadGlobalViaContext); |
| 5359 | } |
| 5360 | |
| 5361 | |
| 5362 | void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) { |
| 5363 | Register context_reg = cp; |
| 5364 | Register slot_reg = a2; |
| 5365 | Register value_reg = a0; |
| 5366 | Register cell_reg = t0; |
| 5367 | Register cell_value_reg = t1; |
| 5368 | Register cell_details_reg = t2; |
| 5369 | Label fast_heapobject_case, fast_smi_case, slow_case; |
| 5370 | |
| 5371 | if (FLAG_debug_code) { |
| 5372 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 5373 | __ Check(ne, kUnexpectedValue, value_reg, Operand(at)); |
| 5374 | } |
| 5375 | |
| 5376 | // Go up context chain to the script context. |
| 5377 | for (int i = 0; i < depth(); ++i) { |
| 5378 | __ lw(cell_reg, ContextMemOperand(context_reg, Context::PREVIOUS_INDEX)); |
| 5379 | context_reg = cell_reg; |
| 5380 | } |
| 5381 | |
| 5382 | // Load the PropertyCell at the specified slot. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5383 | __ Lsa(at, context_reg, slot_reg, kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5384 | __ lw(cell_reg, ContextMemOperand(at, 0)); |
| 5385 | |
| 5386 | // Load PropertyDetails for the cell (actually only the cell_type and kind). |
| 5387 | __ lw(cell_details_reg, |
| 5388 | FieldMemOperand(cell_reg, PropertyCell::kDetailsOffset)); |
| 5389 | __ SmiUntag(cell_details_reg); |
| 5390 | __ And(cell_details_reg, cell_details_reg, |
| 5391 | PropertyDetails::PropertyCellTypeField::kMask | |
| 5392 | PropertyDetails::KindField::kMask | |
| 5393 | PropertyDetails::kAttributesReadOnlyMask); |
| 5394 | |
| 5395 | // Check if PropertyCell holds mutable data. |
| 5396 | Label not_mutable_data; |
| 5397 | __ Branch(¬_mutable_data, ne, cell_details_reg, |
| 5398 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5399 | PropertyCellType::kMutable) | |
| 5400 | PropertyDetails::KindField::encode(kData))); |
| 5401 | __ JumpIfSmi(value_reg, &fast_smi_case); |
| 5402 | __ bind(&fast_heapobject_case); |
| 5403 | __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5404 | __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg, |
| 5405 | cell_details_reg, kRAHasNotBeenSaved, kDontSaveFPRegs, |
| 5406 | EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); |
| 5407 | // RecordWriteField clobbers the value register, so we need to reload. |
| 5408 | __ Ret(USE_DELAY_SLOT); |
| 5409 | __ lw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5410 | __ bind(¬_mutable_data); |
| 5411 | |
| 5412 | // Check if PropertyCell value matches the new value (relevant for Constant, |
| 5413 | // ConstantType and Undefined cells). |
| 5414 | Label not_same_value; |
| 5415 | __ lw(cell_value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5416 | __ Branch(¬_same_value, ne, value_reg, Operand(cell_value_reg)); |
| 5417 | // Make sure the PropertyCell is not marked READ_ONLY. |
| 5418 | __ And(at, cell_details_reg, PropertyDetails::kAttributesReadOnlyMask); |
| 5419 | __ Branch(&slow_case, ne, at, Operand(zero_reg)); |
| 5420 | if (FLAG_debug_code) { |
| 5421 | Label done; |
| 5422 | // This can only be true for Constant, ConstantType and Undefined cells, |
| 5423 | // because we never store the_hole via this stub. |
| 5424 | __ Branch(&done, eq, cell_details_reg, |
| 5425 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5426 | PropertyCellType::kConstant) | |
| 5427 | PropertyDetails::KindField::encode(kData))); |
| 5428 | __ Branch(&done, eq, cell_details_reg, |
| 5429 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5430 | PropertyCellType::kConstantType) | |
| 5431 | PropertyDetails::KindField::encode(kData))); |
| 5432 | __ Check(eq, kUnexpectedValue, cell_details_reg, |
| 5433 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5434 | PropertyCellType::kUndefined) | |
| 5435 | PropertyDetails::KindField::encode(kData))); |
| 5436 | __ bind(&done); |
| 5437 | } |
| 5438 | __ Ret(); |
| 5439 | __ bind(¬_same_value); |
| 5440 | |
| 5441 | // Check if PropertyCell contains data with constant type (and is not |
| 5442 | // READ_ONLY). |
| 5443 | __ Branch(&slow_case, ne, cell_details_reg, |
| 5444 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5445 | PropertyCellType::kConstantType) | |
| 5446 | PropertyDetails::KindField::encode(kData))); |
| 5447 | |
| 5448 | // Now either both old and new values must be SMIs or both must be heap |
| 5449 | // objects with same map. |
| 5450 | Label value_is_heap_object; |
| 5451 | __ JumpIfNotSmi(value_reg, &value_is_heap_object); |
| 5452 | __ JumpIfNotSmi(cell_value_reg, &slow_case); |
| 5453 | // Old and new values are SMIs, no need for a write barrier here. |
| 5454 | __ bind(&fast_smi_case); |
| 5455 | __ Ret(USE_DELAY_SLOT); |
| 5456 | __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5457 | __ bind(&value_is_heap_object); |
| 5458 | __ JumpIfSmi(cell_value_reg, &slow_case); |
| 5459 | Register cell_value_map_reg = cell_value_reg; |
| 5460 | __ lw(cell_value_map_reg, |
| 5461 | FieldMemOperand(cell_value_reg, HeapObject::kMapOffset)); |
| 5462 | __ Branch(&fast_heapobject_case, eq, cell_value_map_reg, |
| 5463 | FieldMemOperand(value_reg, HeapObject::kMapOffset)); |
| 5464 | |
| 5465 | // Fallback to the runtime. |
| 5466 | __ bind(&slow_case); |
| 5467 | __ SmiTag(slot_reg); |
| 5468 | __ Push(slot_reg, value_reg); |
| 5469 | __ TailCallRuntime(is_strict(language_mode()) |
| 5470 | ? Runtime::kStoreGlobalViaContext_Strict |
| 5471 | : Runtime::kStoreGlobalViaContext_Sloppy); |
| 5472 | } |
| 5473 | |
| 5474 | |
| 5475 | static int AddressOffset(ExternalReference ref0, ExternalReference ref1) { |
| 5476 | return ref0.address() - ref1.address(); |
| 5477 | } |
| 5478 | |
| 5479 | |
| 5480 | // Calls an API function. Allocates HandleScope, extracts returned value |
| 5481 | // from handle and propagates exceptions. Restores context. stack_space |
| 5482 | // - space to be unwound on exit (includes the call JS arguments space and |
| 5483 | // the additional space allocated for the fast call). |
| 5484 | static void CallApiFunctionAndReturn( |
| 5485 | MacroAssembler* masm, Register function_address, |
| 5486 | ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset, |
| 5487 | MemOperand return_value_operand, MemOperand* context_restore_operand) { |
| 5488 | Isolate* isolate = masm->isolate(); |
| 5489 | ExternalReference next_address = |
| 5490 | ExternalReference::handle_scope_next_address(isolate); |
| 5491 | const int kNextOffset = 0; |
| 5492 | const int kLimitOffset = AddressOffset( |
| 5493 | ExternalReference::handle_scope_limit_address(isolate), next_address); |
| 5494 | const int kLevelOffset = AddressOffset( |
| 5495 | ExternalReference::handle_scope_level_address(isolate), next_address); |
| 5496 | |
| 5497 | DCHECK(function_address.is(a1) || function_address.is(a2)); |
| 5498 | |
| 5499 | Label profiler_disabled; |
| 5500 | Label end_profiler_check; |
| 5501 | __ li(t9, Operand(ExternalReference::is_profiling_address(isolate))); |
| 5502 | __ lb(t9, MemOperand(t9, 0)); |
| 5503 | __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg)); |
| 5504 | |
| 5505 | // Additional parameter is the address of the actual callback. |
| 5506 | __ li(t9, Operand(thunk_ref)); |
| 5507 | __ jmp(&end_profiler_check); |
| 5508 | |
| 5509 | __ bind(&profiler_disabled); |
| 5510 | __ mov(t9, function_address); |
| 5511 | __ bind(&end_profiler_check); |
| 5512 | |
| 5513 | // Allocate HandleScope in callee-save registers. |
| 5514 | __ li(s3, Operand(next_address)); |
| 5515 | __ lw(s0, MemOperand(s3, kNextOffset)); |
| 5516 | __ lw(s1, MemOperand(s3, kLimitOffset)); |
| 5517 | __ lw(s2, MemOperand(s3, kLevelOffset)); |
| 5518 | __ Addu(s2, s2, Operand(1)); |
| 5519 | __ sw(s2, MemOperand(s3, kLevelOffset)); |
| 5520 | |
| 5521 | if (FLAG_log_timer_events) { |
| 5522 | FrameScope frame(masm, StackFrame::MANUAL); |
| 5523 | __ PushSafepointRegisters(); |
| 5524 | __ PrepareCallCFunction(1, a0); |
| 5525 | __ li(a0, Operand(ExternalReference::isolate_address(isolate))); |
| 5526 | __ CallCFunction(ExternalReference::log_enter_external_function(isolate), |
| 5527 | 1); |
| 5528 | __ PopSafepointRegisters(); |
| 5529 | } |
| 5530 | |
| 5531 | // Native call returns to the DirectCEntry stub which redirects to the |
| 5532 | // return address pushed on stack (could have moved after GC). |
| 5533 | // DirectCEntry stub itself is generated early and never moves. |
| 5534 | DirectCEntryStub stub(isolate); |
| 5535 | stub.GenerateCall(masm, t9); |
| 5536 | |
| 5537 | if (FLAG_log_timer_events) { |
| 5538 | FrameScope frame(masm, StackFrame::MANUAL); |
| 5539 | __ PushSafepointRegisters(); |
| 5540 | __ PrepareCallCFunction(1, a0); |
| 5541 | __ li(a0, Operand(ExternalReference::isolate_address(isolate))); |
| 5542 | __ CallCFunction(ExternalReference::log_leave_external_function(isolate), |
| 5543 | 1); |
| 5544 | __ PopSafepointRegisters(); |
| 5545 | } |
| 5546 | |
| 5547 | Label promote_scheduled_exception; |
| 5548 | Label delete_allocated_handles; |
| 5549 | Label leave_exit_frame; |
| 5550 | Label return_value_loaded; |
| 5551 | |
| 5552 | // Load value from ReturnValue. |
| 5553 | __ lw(v0, return_value_operand); |
| 5554 | __ bind(&return_value_loaded); |
| 5555 | |
| 5556 | // No more valid handles (the result handle was the last one). Restore |
| 5557 | // previous handle scope. |
| 5558 | __ sw(s0, MemOperand(s3, kNextOffset)); |
| 5559 | if (__ emit_debug_code()) { |
| 5560 | __ lw(a1, MemOperand(s3, kLevelOffset)); |
| 5561 | __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2)); |
| 5562 | } |
| 5563 | __ Subu(s2, s2, Operand(1)); |
| 5564 | __ sw(s2, MemOperand(s3, kLevelOffset)); |
| 5565 | __ lw(at, MemOperand(s3, kLimitOffset)); |
| 5566 | __ Branch(&delete_allocated_handles, ne, s1, Operand(at)); |
| 5567 | |
| 5568 | // Leave the API exit frame. |
| 5569 | __ bind(&leave_exit_frame); |
| 5570 | |
| 5571 | bool restore_context = context_restore_operand != NULL; |
| 5572 | if (restore_context) { |
| 5573 | __ lw(cp, *context_restore_operand); |
| 5574 | } |
| 5575 | if (stack_space_offset != kInvalidStackOffset) { |
| 5576 | // ExitFrame contains four MIPS argument slots after DirectCEntryStub call |
| 5577 | // so this must be accounted for. |
| 5578 | __ lw(s0, MemOperand(sp, stack_space_offset + kCArgsSlotsSize)); |
| 5579 | } else { |
| 5580 | __ li(s0, Operand(stack_space)); |
| 5581 | } |
| 5582 | __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN, |
| 5583 | stack_space_offset != kInvalidStackOffset); |
| 5584 | |
| 5585 | // Check if the function scheduled an exception. |
| 5586 | __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); |
| 5587 | __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate))); |
| 5588 | __ lw(t1, MemOperand(at)); |
| 5589 | __ Branch(&promote_scheduled_exception, ne, t0, Operand(t1)); |
| 5590 | |
| 5591 | __ Ret(); |
| 5592 | |
| 5593 | // Re-throw by promoting a scheduled exception. |
| 5594 | __ bind(&promote_scheduled_exception); |
| 5595 | __ TailCallRuntime(Runtime::kPromoteScheduledException); |
| 5596 | |
| 5597 | // HandleScope limit has changed. Delete allocated extensions. |
| 5598 | __ bind(&delete_allocated_handles); |
| 5599 | __ sw(s1, MemOperand(s3, kLimitOffset)); |
| 5600 | __ mov(s0, v0); |
| 5601 | __ mov(a0, v0); |
| 5602 | __ PrepareCallCFunction(1, s1); |
| 5603 | __ li(a0, Operand(ExternalReference::isolate_address(isolate))); |
| 5604 | __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate), |
| 5605 | 1); |
| 5606 | __ mov(v0, s0); |
| 5607 | __ jmp(&leave_exit_frame); |
| 5608 | } |
| 5609 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5610 | static void CallApiFunctionStubHelper(MacroAssembler* masm, |
| 5611 | const ParameterCount& argc, |
| 5612 | bool return_first_arg, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5613 | bool call_data_undefined, bool is_lazy) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5614 | // ----------- S t a t e ------------- |
| 5615 | // -- a0 : callee |
| 5616 | // -- t0 : call_data |
| 5617 | // -- a2 : holder |
| 5618 | // -- a1 : api_function_address |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5619 | // -- a3 : number of arguments if argc is a register |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5620 | // -- cp : context |
| 5621 | // -- |
| 5622 | // -- sp[0] : last argument |
| 5623 | // -- ... |
| 5624 | // -- sp[(argc - 1)* 4] : first argument |
| 5625 | // -- sp[argc * 4] : receiver |
| 5626 | // ----------------------------------- |
| 5627 | |
| 5628 | Register callee = a0; |
| 5629 | Register call_data = t0; |
| 5630 | Register holder = a2; |
| 5631 | Register api_function_address = a1; |
| 5632 | Register context = cp; |
| 5633 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5634 | typedef FunctionCallbackArguments FCA; |
| 5635 | |
| 5636 | STATIC_ASSERT(FCA::kContextSaveIndex == 6); |
| 5637 | STATIC_ASSERT(FCA::kCalleeIndex == 5); |
| 5638 | STATIC_ASSERT(FCA::kDataIndex == 4); |
| 5639 | STATIC_ASSERT(FCA::kReturnValueOffset == 3); |
| 5640 | STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); |
| 5641 | STATIC_ASSERT(FCA::kIsolateIndex == 1); |
| 5642 | STATIC_ASSERT(FCA::kHolderIndex == 0); |
| 5643 | STATIC_ASSERT(FCA::kArgsLength == 7); |
| 5644 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5645 | DCHECK(argc.is_immediate() || a3.is(argc.reg())); |
| 5646 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5647 | // Save context, callee and call data. |
| 5648 | __ Push(context, callee, call_data); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5649 | if (!is_lazy) { |
| 5650 | // Load context from callee. |
| 5651 | __ lw(context, FieldMemOperand(callee, JSFunction::kContextOffset)); |
| 5652 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5653 | |
| 5654 | Register scratch = call_data; |
| 5655 | if (!call_data_undefined) { |
| 5656 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 5657 | } |
| 5658 | // Push return value and default return value. |
| 5659 | __ Push(scratch, scratch); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5660 | __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5661 | // Push isolate and holder. |
| 5662 | __ Push(scratch, holder); |
| 5663 | |
| 5664 | // Prepare arguments. |
| 5665 | __ mov(scratch, sp); |
| 5666 | |
| 5667 | // Allocate the v8::Arguments structure in the arguments' space since |
| 5668 | // it's not controlled by GC. |
| 5669 | const int kApiStackSpace = 4; |
| 5670 | |
| 5671 | FrameScope frame_scope(masm, StackFrame::MANUAL); |
| 5672 | __ EnterExitFrame(false, kApiStackSpace); |
| 5673 | |
| 5674 | DCHECK(!api_function_address.is(a0) && !scratch.is(a0)); |
| 5675 | // a0 = FunctionCallbackInfo& |
| 5676 | // Arguments is after the return address. |
| 5677 | __ Addu(a0, sp, Operand(1 * kPointerSize)); |
| 5678 | // FunctionCallbackInfo::implicit_args_ |
| 5679 | __ sw(scratch, MemOperand(a0, 0 * kPointerSize)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5680 | if (argc.is_immediate()) { |
| 5681 | // FunctionCallbackInfo::values_ |
| 5682 | __ Addu(at, scratch, |
| 5683 | Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize)); |
| 5684 | __ sw(at, MemOperand(a0, 1 * kPointerSize)); |
| 5685 | // FunctionCallbackInfo::length_ = argc |
| 5686 | __ li(at, Operand(argc.immediate())); |
| 5687 | __ sw(at, MemOperand(a0, 2 * kPointerSize)); |
| 5688 | // FunctionCallbackInfo::is_construct_call_ = 0 |
| 5689 | __ sw(zero_reg, MemOperand(a0, 3 * kPointerSize)); |
| 5690 | } else { |
| 5691 | // FunctionCallbackInfo::values_ |
| 5692 | __ sll(at, argc.reg(), kPointerSizeLog2); |
| 5693 | __ Addu(at, at, scratch); |
| 5694 | __ Addu(at, at, Operand((FCA::kArgsLength - 1) * kPointerSize)); |
| 5695 | __ sw(at, MemOperand(a0, 1 * kPointerSize)); |
| 5696 | // FunctionCallbackInfo::length_ = argc |
| 5697 | __ sw(argc.reg(), MemOperand(a0, 2 * kPointerSize)); |
| 5698 | // FunctionCallbackInfo::is_construct_call_ |
| 5699 | __ Addu(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1)); |
| 5700 | __ sll(at, argc.reg(), kPointerSizeLog2); |
| 5701 | __ sw(at, MemOperand(a0, 3 * kPointerSize)); |
| 5702 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5703 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5704 | ExternalReference thunk_ref = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5705 | ExternalReference::invoke_function_callback(masm->isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5706 | |
| 5707 | AllowExternalCallThatCantCauseGC scope(masm); |
| 5708 | MemOperand context_restore_operand( |
| 5709 | fp, (2 + FCA::kContextSaveIndex) * kPointerSize); |
| 5710 | // Stores return the first js argument. |
| 5711 | int return_value_offset = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5712 | if (return_first_arg) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5713 | return_value_offset = 2 + FCA::kArgsLength; |
| 5714 | } else { |
| 5715 | return_value_offset = 2 + FCA::kReturnValueOffset; |
| 5716 | } |
| 5717 | MemOperand return_value_operand(fp, return_value_offset * kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5718 | int stack_space = 0; |
| 5719 | int32_t stack_space_offset = 4 * kPointerSize; |
| 5720 | if (argc.is_immediate()) { |
| 5721 | stack_space = argc.immediate() + FCA::kArgsLength + 1; |
| 5722 | stack_space_offset = kInvalidStackOffset; |
| 5723 | } |
| 5724 | CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space, |
| 5725 | stack_space_offset, return_value_operand, |
| 5726 | &context_restore_operand); |
| 5727 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5728 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5729 | |
| 5730 | void CallApiFunctionStub::Generate(MacroAssembler* masm) { |
| 5731 | bool call_data_undefined = this->call_data_undefined(); |
| 5732 | CallApiFunctionStubHelper(masm, ParameterCount(a3), false, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5733 | call_data_undefined, false); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5734 | } |
| 5735 | |
| 5736 | |
| 5737 | void CallApiAccessorStub::Generate(MacroAssembler* masm) { |
| 5738 | bool is_store = this->is_store(); |
| 5739 | int argc = this->argc(); |
| 5740 | bool call_data_undefined = this->call_data_undefined(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5741 | bool is_lazy = this->is_lazy(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5742 | CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5743 | call_data_undefined, is_lazy); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5744 | } |
| 5745 | |
| 5746 | |
| 5747 | void CallApiGetterStub::Generate(MacroAssembler* masm) { |
| 5748 | // ----------- S t a t e ------------- |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5749 | // -- sp[0] : name |
| 5750 | // -- sp[4 .. (4 + kArgsLength*4)] : v8::PropertyCallbackInfo::args_ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5751 | // -- ... |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5752 | // -- a2 : api_function_address |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5753 | // ----------------------------------- |
| 5754 | |
| 5755 | Register api_function_address = ApiGetterDescriptor::function_address(); |
| 5756 | DCHECK(api_function_address.is(a2)); |
| 5757 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5758 | // v8::PropertyCallbackInfo::args_ array and name handle. |
| 5759 | const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1; |
| 5760 | |
| 5761 | // Load address of v8::PropertyAccessorInfo::args_ array and name handle. |
| 5762 | __ mov(a0, sp); // a0 = Handle<Name> |
| 5763 | __ Addu(a1, a0, Operand(1 * kPointerSize)); // a1 = v8::PCI::args_ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5764 | |
| 5765 | const int kApiStackSpace = 1; |
| 5766 | FrameScope frame_scope(masm, StackFrame::MANUAL); |
| 5767 | __ EnterExitFrame(false, kApiStackSpace); |
| 5768 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5769 | // Create v8::PropertyCallbackInfo object on the stack and initialize |
| 5770 | // it's args_ field. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5771 | __ sw(a1, MemOperand(sp, 1 * kPointerSize)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5772 | __ Addu(a1, sp, Operand(1 * kPointerSize)); // a1 = v8::PropertyCallbackInfo& |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5773 | |
| 5774 | ExternalReference thunk_ref = |
| 5775 | ExternalReference::invoke_accessor_getter_callback(isolate()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5776 | |
| 5777 | // +3 is to skip prolog, return address and name handle. |
| 5778 | MemOperand return_value_operand( |
| 5779 | fp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5780 | CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, |
| 5781 | kStackUnwindSpace, kInvalidStackOffset, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5782 | return_value_operand, NULL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5783 | } |
| 5784 | |
| 5785 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5786 | #undef __ |
| 5787 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5788 | } // namespace internal |
| 5789 | } // namespace v8 |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5790 | |
| 5791 | #endif // V8_TARGET_ARCH_MIPS |