Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #if V8_TARGET_ARCH_ARM64 |
| 6 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7 | #include "src/code-stubs.h" |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 8 | #include "src/api-arguments.h" |
| 9 | #include "src/bootstrapper.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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/regexp/jsregexp.h" |
| 16 | #include "src/regexp/regexp-macro-assembler.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 17 | #include "src/runtime/runtime.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 18 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 19 | #include "src/arm64/code-stubs-arm64.h" |
| 20 | #include "src/arm64/frames-arm64.h" |
| 21 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 22 | namespace v8 { |
| 23 | namespace internal { |
| 24 | |
| 25 | |
| 26 | static void InitializeArrayConstructorDescriptor( |
| 27 | Isolate* isolate, CodeStubDescriptor* descriptor, |
| 28 | int constant_stack_parameter_count) { |
| 29 | // cp: context |
| 30 | // x1: function |
| 31 | // x2: allocation site with elements kind |
| 32 | // x0: number of arguments to the constructor function |
| 33 | Address deopt_handler = Runtime::FunctionForId( |
| 34 | Runtime::kArrayConstructor)->entry; |
| 35 | |
| 36 | if (constant_stack_parameter_count == 0) { |
| 37 | descriptor->Initialize(deopt_handler, constant_stack_parameter_count, |
| 38 | JS_FUNCTION_STUB_MODE); |
| 39 | } else { |
| 40 | descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 41 | JS_FUNCTION_STUB_MODE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
| 45 | |
| 46 | void ArrayNoArgumentConstructorStub::InitializeDescriptor( |
| 47 | CodeStubDescriptor* descriptor) { |
| 48 | InitializeArrayConstructorDescriptor(isolate(), descriptor, 0); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | void ArraySingleArgumentConstructorStub::InitializeDescriptor( |
| 53 | CodeStubDescriptor* descriptor) { |
| 54 | InitializeArrayConstructorDescriptor(isolate(), descriptor, 1); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | void ArrayNArgumentsConstructorStub::InitializeDescriptor( |
| 59 | CodeStubDescriptor* descriptor) { |
| 60 | InitializeArrayConstructorDescriptor(isolate(), descriptor, -1); |
| 61 | } |
| 62 | |
| 63 | |
| 64 | static void InitializeInternalArrayConstructorDescriptor( |
| 65 | Isolate* isolate, CodeStubDescriptor* descriptor, |
| 66 | int constant_stack_parameter_count) { |
| 67 | Address deopt_handler = Runtime::FunctionForId( |
| 68 | Runtime::kInternalArrayConstructor)->entry; |
| 69 | |
| 70 | if (constant_stack_parameter_count == 0) { |
| 71 | descriptor->Initialize(deopt_handler, constant_stack_parameter_count, |
| 72 | JS_FUNCTION_STUB_MODE); |
| 73 | } else { |
| 74 | descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 75 | JS_FUNCTION_STUB_MODE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
| 79 | |
| 80 | void InternalArrayNoArgumentConstructorStub::InitializeDescriptor( |
| 81 | CodeStubDescriptor* descriptor) { |
| 82 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0); |
| 83 | } |
| 84 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 85 | void FastArrayPushStub::InitializeDescriptor(CodeStubDescriptor* descriptor) { |
| 86 | Address deopt_handler = Runtime::FunctionForId(Runtime::kArrayPush)->entry; |
| 87 | descriptor->Initialize(x0, deopt_handler, -1, JS_FUNCTION_STUB_MODE); |
| 88 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 89 | |
| 90 | void InternalArraySingleArgumentConstructorStub::InitializeDescriptor( |
| 91 | CodeStubDescriptor* descriptor) { |
| 92 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | void InternalArrayNArgumentsConstructorStub::InitializeDescriptor( |
| 97 | CodeStubDescriptor* descriptor) { |
| 98 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | #define __ ACCESS_MASM(masm) |
| 103 | |
| 104 | |
| 105 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm, |
| 106 | ExternalReference miss) { |
| 107 | // Update the static counter each time a new code stub is generated. |
| 108 | isolate()->counters()->code_stubs()->Increment(); |
| 109 | |
| 110 | CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 111 | int param_count = descriptor.GetRegisterParameterCount(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 112 | { |
| 113 | // Call the runtime system in a fresh internal frame. |
| 114 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 115 | DCHECK((param_count == 0) || |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 116 | x0.Is(descriptor.GetRegisterParameter(param_count - 1))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 117 | |
| 118 | // Push arguments |
| 119 | MacroAssembler::PushPopQueue queue(masm); |
| 120 | for (int i = 0; i < param_count; ++i) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 121 | queue.Queue(descriptor.GetRegisterParameter(i)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 122 | } |
| 123 | queue.PushQueued(); |
| 124 | |
| 125 | __ CallExternalReference(miss, param_count); |
| 126 | } |
| 127 | |
| 128 | __ Ret(); |
| 129 | } |
| 130 | |
| 131 | |
| 132 | void DoubleToIStub::Generate(MacroAssembler* masm) { |
| 133 | Label done; |
| 134 | Register input = source(); |
| 135 | Register result = destination(); |
| 136 | DCHECK(is_truncating()); |
| 137 | |
| 138 | DCHECK(result.Is64Bits()); |
| 139 | DCHECK(jssp.Is(masm->StackPointer())); |
| 140 | |
| 141 | int double_offset = offset(); |
| 142 | |
| 143 | DoubleRegister double_scratch = d0; // only used if !skip_fastpath() |
| 144 | Register scratch1 = GetAllocatableRegisterThatIsNotOneOf(input, result); |
| 145 | Register scratch2 = |
| 146 | GetAllocatableRegisterThatIsNotOneOf(input, result, scratch1); |
| 147 | |
| 148 | __ Push(scratch1, scratch2); |
| 149 | // Account for saved regs if input is jssp. |
| 150 | if (input.is(jssp)) double_offset += 2 * kPointerSize; |
| 151 | |
| 152 | if (!skip_fastpath()) { |
| 153 | __ Push(double_scratch); |
| 154 | if (input.is(jssp)) double_offset += 1 * kDoubleSize; |
| 155 | __ Ldr(double_scratch, MemOperand(input, double_offset)); |
| 156 | // Try to convert with a FPU convert instruction. This handles all |
| 157 | // non-saturating cases. |
| 158 | __ TryConvertDoubleToInt64(result, double_scratch, &done); |
| 159 | __ Fmov(result, double_scratch); |
| 160 | } else { |
| 161 | __ Ldr(result, MemOperand(input, double_offset)); |
| 162 | } |
| 163 | |
| 164 | // If we reach here we need to manually convert the input to an int32. |
| 165 | |
| 166 | // Extract the exponent. |
| 167 | Register exponent = scratch1; |
| 168 | __ Ubfx(exponent, result, HeapNumber::kMantissaBits, |
| 169 | HeapNumber::kExponentBits); |
| 170 | |
| 171 | // It the exponent is >= 84 (kMantissaBits + 32), the result is always 0 since |
| 172 | // the mantissa gets shifted completely out of the int32_t result. |
| 173 | __ Cmp(exponent, HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 32); |
| 174 | __ CzeroX(result, ge); |
| 175 | __ B(ge, &done); |
| 176 | |
| 177 | // The Fcvtzs sequence handles all cases except where the conversion causes |
| 178 | // signed overflow in the int64_t target. Since we've already handled |
| 179 | // exponents >= 84, we can guarantee that 63 <= exponent < 84. |
| 180 | |
| 181 | if (masm->emit_debug_code()) { |
| 182 | __ Cmp(exponent, HeapNumber::kExponentBias + 63); |
| 183 | // Exponents less than this should have been handled by the Fcvt case. |
| 184 | __ Check(ge, kUnexpectedValue); |
| 185 | } |
| 186 | |
| 187 | // Isolate the mantissa bits, and set the implicit '1'. |
| 188 | Register mantissa = scratch2; |
| 189 | __ Ubfx(mantissa, result, 0, HeapNumber::kMantissaBits); |
| 190 | __ Orr(mantissa, mantissa, 1UL << HeapNumber::kMantissaBits); |
| 191 | |
| 192 | // Negate the mantissa if necessary. |
| 193 | __ Tst(result, kXSignMask); |
| 194 | __ Cneg(mantissa, mantissa, ne); |
| 195 | |
| 196 | // Shift the mantissa bits in the correct place. We know that we have to shift |
| 197 | // it left here, because exponent >= 63 >= kMantissaBits. |
| 198 | __ Sub(exponent, exponent, |
| 199 | HeapNumber::kExponentBias + HeapNumber::kMantissaBits); |
| 200 | __ Lsl(result, mantissa, exponent); |
| 201 | |
| 202 | __ Bind(&done); |
| 203 | if (!skip_fastpath()) { |
| 204 | __ Pop(double_scratch); |
| 205 | } |
| 206 | __ Pop(scratch2, scratch1); |
| 207 | __ Ret(); |
| 208 | } |
| 209 | |
| 210 | |
| 211 | // See call site for description. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 212 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, Register left, |
| 213 | Register right, Register scratch, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 214 | FPRegister double_scratch, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 215 | Label* slow, Condition cond) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 216 | DCHECK(!AreAliased(left, right, scratch)); |
| 217 | Label not_identical, return_equal, heap_number; |
| 218 | Register result = x0; |
| 219 | |
| 220 | __ Cmp(right, left); |
| 221 | __ B(ne, ¬_identical); |
| 222 | |
| 223 | // Test for NaN. Sadly, we can't just compare to factory::nan_value(), |
| 224 | // so we do the second best thing - test it ourselves. |
| 225 | // They are both equal and they are not both Smis so both of them are not |
| 226 | // Smis. If it's not a heap number, then return equal. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 227 | Register right_type = scratch; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 228 | if ((cond == lt) || (cond == gt)) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 229 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 230 | __ JumpIfObjectType(right, right_type, right_type, FIRST_JS_RECEIVER_TYPE, |
| 231 | slow, ge); |
| 232 | // Call runtime on identical symbols since we need to throw a TypeError. |
| 233 | __ Cmp(right_type, SYMBOL_TYPE); |
| 234 | __ B(eq, slow); |
| 235 | // Call runtime on identical SIMD values since we must throw a TypeError. |
| 236 | __ Cmp(right_type, SIMD128_VALUE_TYPE); |
| 237 | __ B(eq, slow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 238 | } else if (cond == eq) { |
| 239 | __ JumpIfHeapNumber(right, &heap_number); |
| 240 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 241 | __ JumpIfObjectType(right, right_type, right_type, HEAP_NUMBER_TYPE, |
| 242 | &heap_number); |
| 243 | // Comparing JS objects with <=, >= is complicated. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 244 | __ Cmp(right_type, FIRST_JS_RECEIVER_TYPE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 245 | __ B(ge, slow); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 246 | // Call runtime on identical symbols since we need to throw a TypeError. |
| 247 | __ Cmp(right_type, SYMBOL_TYPE); |
| 248 | __ B(eq, slow); |
| 249 | // Call runtime on identical SIMD values since we must throw a TypeError. |
| 250 | __ Cmp(right_type, SIMD128_VALUE_TYPE); |
| 251 | __ B(eq, slow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 252 | // Normally here we fall through to return_equal, but undefined is |
| 253 | // special: (undefined == undefined) == true, but |
| 254 | // (undefined <= undefined) == false! See ECMAScript 11.8.5. |
| 255 | if ((cond == le) || (cond == ge)) { |
| 256 | __ Cmp(right_type, ODDBALL_TYPE); |
| 257 | __ B(ne, &return_equal); |
| 258 | __ JumpIfNotRoot(right, Heap::kUndefinedValueRootIndex, &return_equal); |
| 259 | if (cond == le) { |
| 260 | // undefined <= undefined should fail. |
| 261 | __ Mov(result, GREATER); |
| 262 | } else { |
| 263 | // undefined >= undefined should fail. |
| 264 | __ Mov(result, LESS); |
| 265 | } |
| 266 | __ Ret(); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | __ Bind(&return_equal); |
| 271 | if (cond == lt) { |
| 272 | __ Mov(result, GREATER); // Things aren't less than themselves. |
| 273 | } else if (cond == gt) { |
| 274 | __ Mov(result, LESS); // Things aren't greater than themselves. |
| 275 | } else { |
| 276 | __ Mov(result, EQUAL); // Things are <=, >=, ==, === themselves. |
| 277 | } |
| 278 | __ Ret(); |
| 279 | |
| 280 | // Cases lt and gt have been handled earlier, and case ne is never seen, as |
| 281 | // it is handled in the parser (see Parser::ParseBinaryExpression). We are |
| 282 | // only concerned with cases ge, le and eq here. |
| 283 | if ((cond != lt) && (cond != gt)) { |
| 284 | DCHECK((cond == ge) || (cond == le) || (cond == eq)); |
| 285 | __ Bind(&heap_number); |
| 286 | // Left and right are identical pointers to a heap number object. Return |
| 287 | // non-equal if the heap number is a NaN, and equal otherwise. Comparing |
| 288 | // the number to itself will set the overflow flag iff the number is NaN. |
| 289 | __ Ldr(double_scratch, FieldMemOperand(right, HeapNumber::kValueOffset)); |
| 290 | __ Fcmp(double_scratch, double_scratch); |
| 291 | __ B(vc, &return_equal); // Not NaN, so treat as normal heap number. |
| 292 | |
| 293 | if (cond == le) { |
| 294 | __ Mov(result, GREATER); |
| 295 | } else { |
| 296 | __ Mov(result, LESS); |
| 297 | } |
| 298 | __ Ret(); |
| 299 | } |
| 300 | |
| 301 | // No fall through here. |
| 302 | if (FLAG_debug_code) { |
| 303 | __ Unreachable(); |
| 304 | } |
| 305 | |
| 306 | __ Bind(¬_identical); |
| 307 | } |
| 308 | |
| 309 | |
| 310 | // See call site for description. |
| 311 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 312 | Register left, |
| 313 | Register right, |
| 314 | Register left_type, |
| 315 | Register right_type, |
| 316 | Register scratch) { |
| 317 | DCHECK(!AreAliased(left, right, left_type, right_type, scratch)); |
| 318 | |
| 319 | if (masm->emit_debug_code()) { |
| 320 | // We assume that the arguments are not identical. |
| 321 | __ Cmp(left, right); |
| 322 | __ Assert(ne, kExpectedNonIdenticalObjects); |
| 323 | } |
| 324 | |
| 325 | // If either operand is a JS object or an oddball value, then they are not |
| 326 | // equal since their pointers are different. |
| 327 | // There is no test for undetectability in strict equality. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 328 | STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 329 | Label right_non_object; |
| 330 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 331 | __ Cmp(right_type, FIRST_JS_RECEIVER_TYPE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 332 | __ B(lt, &right_non_object); |
| 333 | |
| 334 | // Return non-zero - x0 already contains a non-zero pointer. |
| 335 | DCHECK(left.is(x0) || right.is(x0)); |
| 336 | Label return_not_equal; |
| 337 | __ Bind(&return_not_equal); |
| 338 | __ Ret(); |
| 339 | |
| 340 | __ Bind(&right_non_object); |
| 341 | |
| 342 | // Check for oddballs: true, false, null, undefined. |
| 343 | __ Cmp(right_type, ODDBALL_TYPE); |
| 344 | |
| 345 | // If right is not ODDBALL, test left. Otherwise, set eq condition. |
| 346 | __ Ccmp(left_type, ODDBALL_TYPE, ZFlag, ne); |
| 347 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 348 | // If right or left is not ODDBALL, test left >= FIRST_JS_RECEIVER_TYPE. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 349 | // Otherwise, right or left is ODDBALL, so set a ge condition. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 350 | __ Ccmp(left_type, FIRST_JS_RECEIVER_TYPE, NVFlag, ne); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 351 | |
| 352 | __ B(ge, &return_not_equal); |
| 353 | |
| 354 | // Internalized strings are unique, so they can only be equal if they are the |
| 355 | // same object. We have already tested that case, so if left and right are |
| 356 | // both internalized strings, they cannot be equal. |
| 357 | STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0)); |
| 358 | __ Orr(scratch, left_type, right_type); |
| 359 | __ TestAndBranchIfAllClear( |
| 360 | scratch, kIsNotStringMask | kIsNotInternalizedMask, &return_not_equal); |
| 361 | } |
| 362 | |
| 363 | |
| 364 | // See call site for description. |
| 365 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 366 | Register left, |
| 367 | Register right, |
| 368 | FPRegister left_d, |
| 369 | FPRegister right_d, |
| 370 | Label* slow, |
| 371 | bool strict) { |
| 372 | DCHECK(!AreAliased(left_d, right_d)); |
| 373 | DCHECK((left.is(x0) && right.is(x1)) || |
| 374 | (right.is(x0) && left.is(x1))); |
| 375 | Register result = x0; |
| 376 | |
| 377 | Label right_is_smi, done; |
| 378 | __ JumpIfSmi(right, &right_is_smi); |
| 379 | |
| 380 | // Left is the smi. Check whether right is a heap number. |
| 381 | if (strict) { |
| 382 | // If right is not a number and left is a smi, then strict equality cannot |
| 383 | // succeed. Return non-equal. |
| 384 | Label is_heap_number; |
| 385 | __ JumpIfHeapNumber(right, &is_heap_number); |
| 386 | // Register right is a non-zero pointer, which is a valid NOT_EQUAL result. |
| 387 | if (!right.is(result)) { |
| 388 | __ Mov(result, NOT_EQUAL); |
| 389 | } |
| 390 | __ Ret(); |
| 391 | __ Bind(&is_heap_number); |
| 392 | } else { |
| 393 | // Smi compared non-strictly with a non-smi, non-heap-number. Call the |
| 394 | // runtime. |
| 395 | __ JumpIfNotHeapNumber(right, slow); |
| 396 | } |
| 397 | |
| 398 | // Left is the smi. Right is a heap number. Load right value into right_d, and |
| 399 | // convert left smi into double in left_d. |
| 400 | __ Ldr(right_d, FieldMemOperand(right, HeapNumber::kValueOffset)); |
| 401 | __ SmiUntagToDouble(left_d, left); |
| 402 | __ B(&done); |
| 403 | |
| 404 | __ Bind(&right_is_smi); |
| 405 | // Right is a smi. Check whether the non-smi left is a heap number. |
| 406 | if (strict) { |
| 407 | // If left is not a number and right is a smi then strict equality cannot |
| 408 | // succeed. Return non-equal. |
| 409 | Label is_heap_number; |
| 410 | __ JumpIfHeapNumber(left, &is_heap_number); |
| 411 | // Register left is a non-zero pointer, which is a valid NOT_EQUAL result. |
| 412 | if (!left.is(result)) { |
| 413 | __ Mov(result, NOT_EQUAL); |
| 414 | } |
| 415 | __ Ret(); |
| 416 | __ Bind(&is_heap_number); |
| 417 | } else { |
| 418 | // Smi compared non-strictly with a non-smi, non-heap-number. Call the |
| 419 | // runtime. |
| 420 | __ JumpIfNotHeapNumber(left, slow); |
| 421 | } |
| 422 | |
| 423 | // Right is the smi. Left is a heap number. Load left value into left_d, and |
| 424 | // convert right smi into double in right_d. |
| 425 | __ Ldr(left_d, FieldMemOperand(left, HeapNumber::kValueOffset)); |
| 426 | __ SmiUntagToDouble(right_d, right); |
| 427 | |
| 428 | // Fall through to both_loaded_as_doubles. |
| 429 | __ Bind(&done); |
| 430 | } |
| 431 | |
| 432 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 433 | // Fast negative check for internalized-to-internalized equality or receiver |
| 434 | // equality. Also handles the undetectable receiver to null/undefined |
| 435 | // comparison. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 436 | // See call site for description. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 437 | static void EmitCheckForInternalizedStringsOrObjects( |
| 438 | MacroAssembler* masm, Register left, Register right, Register left_map, |
| 439 | Register right_map, Register left_type, Register right_type, |
| 440 | Label* possible_strings, Label* runtime_call) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 441 | DCHECK(!AreAliased(left, right, left_map, right_map, left_type, right_type)); |
| 442 | Register result = x0; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 443 | DCHECK(left.is(x0) || right.is(x0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 444 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 445 | Label object_test, return_equal, return_unequal, undetectable; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 446 | STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0)); |
| 447 | // TODO(all): reexamine this branch sequence for optimisation wrt branch |
| 448 | // prediction. |
| 449 | __ Tbnz(right_type, MaskToBit(kIsNotStringMask), &object_test); |
| 450 | __ Tbnz(right_type, MaskToBit(kIsNotInternalizedMask), possible_strings); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 451 | __ Tbnz(left_type, MaskToBit(kIsNotStringMask), runtime_call); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 452 | __ Tbnz(left_type, MaskToBit(kIsNotInternalizedMask), possible_strings); |
| 453 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 454 | // Both are internalized. We already checked they weren't the same pointer so |
| 455 | // they are not equal. Return non-equal by returning the non-zero object |
| 456 | // pointer in x0. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 457 | __ Ret(); |
| 458 | |
| 459 | __ Bind(&object_test); |
| 460 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 461 | Register left_bitfield = left_type; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 462 | Register right_bitfield = right_type; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 463 | __ Ldrb(right_bitfield, FieldMemOperand(right_map, Map::kBitFieldOffset)); |
| 464 | __ Ldrb(left_bitfield, FieldMemOperand(left_map, Map::kBitFieldOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 465 | __ Tbnz(right_bitfield, MaskToBit(1 << Map::kIsUndetectable), &undetectable); |
| 466 | __ Tbnz(left_bitfield, MaskToBit(1 << Map::kIsUndetectable), &return_unequal); |
| 467 | |
| 468 | __ CompareInstanceType(right_map, right_type, FIRST_JS_RECEIVER_TYPE); |
| 469 | __ B(lt, runtime_call); |
| 470 | __ CompareInstanceType(left_map, left_type, FIRST_JS_RECEIVER_TYPE); |
| 471 | __ B(lt, runtime_call); |
| 472 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 473 | __ Bind(&return_unequal); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 474 | // Return non-equal by returning the non-zero object pointer in x0. |
| 475 | __ Ret(); |
| 476 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 477 | __ Bind(&undetectable); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 478 | __ Tbz(left_bitfield, MaskToBit(1 << Map::kIsUndetectable), &return_unequal); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 479 | |
| 480 | // If both sides are JSReceivers, then the result is false according to |
| 481 | // the HTML specification, which says that only comparisons with null or |
| 482 | // undefined are affected by special casing for document.all. |
| 483 | __ CompareInstanceType(right_map, right_type, ODDBALL_TYPE); |
| 484 | __ B(eq, &return_equal); |
| 485 | __ CompareInstanceType(left_map, left_type, ODDBALL_TYPE); |
| 486 | __ B(ne, &return_unequal); |
| 487 | |
| 488 | __ Bind(&return_equal); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 489 | __ Mov(result, EQUAL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 490 | __ Ret(); |
| 491 | } |
| 492 | |
| 493 | |
| 494 | static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input, |
| 495 | CompareICState::State expected, |
| 496 | Label* fail) { |
| 497 | Label ok; |
| 498 | if (expected == CompareICState::SMI) { |
| 499 | __ JumpIfNotSmi(input, fail); |
| 500 | } else if (expected == CompareICState::NUMBER) { |
| 501 | __ JumpIfSmi(input, &ok); |
| 502 | __ JumpIfNotHeapNumber(input, fail); |
| 503 | } |
| 504 | // We could be strict about internalized/non-internalized here, but as long as |
| 505 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 506 | __ Bind(&ok); |
| 507 | } |
| 508 | |
| 509 | |
| 510 | void CompareICStub::GenerateGeneric(MacroAssembler* masm) { |
| 511 | Register lhs = x1; |
| 512 | Register rhs = x0; |
| 513 | Register result = x0; |
| 514 | Condition cond = GetCondition(); |
| 515 | |
| 516 | Label miss; |
| 517 | CompareICStub_CheckInputType(masm, lhs, left(), &miss); |
| 518 | CompareICStub_CheckInputType(masm, rhs, right(), &miss); |
| 519 | |
| 520 | Label slow; // Call builtin. |
| 521 | Label not_smis, both_loaded_as_doubles; |
| 522 | Label not_two_smis, smi_done; |
| 523 | __ JumpIfEitherNotSmi(lhs, rhs, ¬_two_smis); |
| 524 | __ SmiUntag(lhs); |
| 525 | __ Sub(result, lhs, Operand::UntagSmi(rhs)); |
| 526 | __ Ret(); |
| 527 | |
| 528 | __ Bind(¬_two_smis); |
| 529 | |
| 530 | // NOTICE! This code is only reached after a smi-fast-case check, so it is |
| 531 | // certain that at least one operand isn't a smi. |
| 532 | |
| 533 | // Handle the case where the objects are identical. Either returns the answer |
| 534 | // 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] | 535 | EmitIdenticalObjectComparison(masm, lhs, rhs, x10, d0, &slow, cond); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 536 | |
| 537 | // If either is a smi (we know that at least one is not a smi), then they can |
| 538 | // only be strictly equal if the other is a HeapNumber. |
| 539 | __ JumpIfBothNotSmi(lhs, rhs, ¬_smis); |
| 540 | |
| 541 | // Exactly one operand is a smi. EmitSmiNonsmiComparison generates code that |
| 542 | // can: |
| 543 | // 1) Return the answer. |
| 544 | // 2) Branch to the slow case. |
| 545 | // 3) Fall through to both_loaded_as_doubles. |
| 546 | // In case 3, we have found out that we were dealing with a number-number |
| 547 | // comparison. The double values of the numbers have been loaded, right into |
| 548 | // rhs_d, left into lhs_d. |
| 549 | FPRegister rhs_d = d0; |
| 550 | FPRegister lhs_d = d1; |
| 551 | EmitSmiNonsmiComparison(masm, lhs, rhs, lhs_d, rhs_d, &slow, strict()); |
| 552 | |
| 553 | __ Bind(&both_loaded_as_doubles); |
| 554 | // The arguments have been converted to doubles and stored in rhs_d and |
| 555 | // lhs_d. |
| 556 | Label nan; |
| 557 | __ Fcmp(lhs_d, rhs_d); |
| 558 | __ B(vs, &nan); // Overflow flag set if either is NaN. |
| 559 | STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1)); |
| 560 | __ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL). |
| 561 | __ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0. |
| 562 | __ Ret(); |
| 563 | |
| 564 | __ Bind(&nan); |
| 565 | // Left and/or right is a NaN. Load the result register with whatever makes |
| 566 | // the comparison fail, since comparisons with NaN always fail (except ne, |
| 567 | // which is filtered out at a higher level.) |
| 568 | DCHECK(cond != ne); |
| 569 | if ((cond == lt) || (cond == le)) { |
| 570 | __ Mov(result, GREATER); |
| 571 | } else { |
| 572 | __ Mov(result, LESS); |
| 573 | } |
| 574 | __ Ret(); |
| 575 | |
| 576 | __ Bind(¬_smis); |
| 577 | // At this point we know we are dealing with two different objects, and |
| 578 | // neither of them is a smi. The objects are in rhs_ and lhs_. |
| 579 | |
| 580 | // Load the maps and types of the objects. |
| 581 | Register rhs_map = x10; |
| 582 | Register rhs_type = x11; |
| 583 | Register lhs_map = x12; |
| 584 | Register lhs_type = x13; |
| 585 | __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 586 | __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset)); |
| 587 | __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset)); |
| 588 | __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset)); |
| 589 | |
| 590 | if (strict()) { |
| 591 | // This emits a non-equal return sequence for some object types, or falls |
| 592 | // through if it was not lucky. |
| 593 | EmitStrictTwoHeapObjectCompare(masm, lhs, rhs, lhs_type, rhs_type, x14); |
| 594 | } |
| 595 | |
| 596 | Label check_for_internalized_strings; |
| 597 | Label flat_string_check; |
| 598 | // Check for heap number comparison. Branch to earlier double comparison code |
| 599 | // if they are heap numbers, otherwise, branch to internalized string check. |
| 600 | __ Cmp(rhs_type, HEAP_NUMBER_TYPE); |
| 601 | __ B(ne, &check_for_internalized_strings); |
| 602 | __ Cmp(lhs_map, rhs_map); |
| 603 | |
| 604 | // If maps aren't equal, lhs_ and rhs_ are not heap numbers. Branch to flat |
| 605 | // string check. |
| 606 | __ B(ne, &flat_string_check); |
| 607 | |
| 608 | // Both lhs_ and rhs_ are heap numbers. Load them and branch to the double |
| 609 | // comparison code. |
| 610 | __ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 611 | __ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 612 | __ B(&both_loaded_as_doubles); |
| 613 | |
| 614 | __ Bind(&check_for_internalized_strings); |
| 615 | // In the strict case, the EmitStrictTwoHeapObjectCompare already took care |
| 616 | // of internalized strings. |
| 617 | if ((cond == eq) && !strict()) { |
| 618 | // Returns an answer for two internalized strings or two detectable objects. |
| 619 | // Otherwise branches to the string case or not both strings case. |
| 620 | EmitCheckForInternalizedStringsOrObjects(masm, lhs, rhs, lhs_map, rhs_map, |
| 621 | lhs_type, rhs_type, |
| 622 | &flat_string_check, &slow); |
| 623 | } |
| 624 | |
| 625 | // Check for both being sequential one-byte strings, |
| 626 | // and inline if that is the case. |
| 627 | __ Bind(&flat_string_check); |
| 628 | __ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x14, |
| 629 | x15, &slow); |
| 630 | |
| 631 | __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, x10, |
| 632 | x11); |
| 633 | if (cond == eq) { |
| 634 | StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11, |
| 635 | x12); |
| 636 | } else { |
| 637 | StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11, |
| 638 | x12, x13); |
| 639 | } |
| 640 | |
| 641 | // Never fall through to here. |
| 642 | if (FLAG_debug_code) { |
| 643 | __ Unreachable(); |
| 644 | } |
| 645 | |
| 646 | __ Bind(&slow); |
| 647 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 648 | if (cond == eq) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 649 | { |
| 650 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 651 | __ Push(lhs, rhs); |
| 652 | __ CallRuntime(strict() ? Runtime::kStrictEqual : Runtime::kEqual); |
| 653 | } |
| 654 | // Turn true into 0 and false into some non-zero value. |
| 655 | STATIC_ASSERT(EQUAL == 0); |
| 656 | __ LoadRoot(x1, Heap::kTrueValueRootIndex); |
| 657 | __ Sub(x0, x0, x1); |
| 658 | __ Ret(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 659 | } else { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 660 | __ Push(lhs, rhs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 661 | int ncr; // NaN compare result |
| 662 | if ((cond == lt) || (cond == le)) { |
| 663 | ncr = GREATER; |
| 664 | } else { |
| 665 | DCHECK((cond == gt) || (cond == ge)); // remaining cases |
| 666 | ncr = LESS; |
| 667 | } |
| 668 | __ Mov(x10, Smi::FromInt(ncr)); |
| 669 | __ Push(x10); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 670 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 671 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 672 | // tagged as a small integer. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 673 | __ TailCallRuntime(Runtime::kCompare); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 674 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 675 | |
| 676 | __ Bind(&miss); |
| 677 | GenerateMiss(masm); |
| 678 | } |
| 679 | |
| 680 | |
| 681 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 682 | CPURegList saved_regs = kCallerSaved; |
| 683 | CPURegList saved_fp_regs = kCallerSavedFP; |
| 684 | |
| 685 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 686 | // store the registers in any particular way, but we do have to store and |
| 687 | // restore them. |
| 688 | |
| 689 | // We don't care if MacroAssembler scratch registers are corrupted. |
| 690 | saved_regs.Remove(*(masm->TmpList())); |
| 691 | saved_fp_regs.Remove(*(masm->FPTmpList())); |
| 692 | |
| 693 | __ PushCPURegList(saved_regs); |
| 694 | if (save_doubles()) { |
| 695 | __ PushCPURegList(saved_fp_regs); |
| 696 | } |
| 697 | |
| 698 | AllowExternalCallThatCantCauseGC scope(masm); |
| 699 | __ Mov(x0, ExternalReference::isolate_address(isolate())); |
| 700 | __ CallCFunction( |
| 701 | ExternalReference::store_buffer_overflow_function(isolate()), 1, 0); |
| 702 | |
| 703 | if (save_doubles()) { |
| 704 | __ PopCPURegList(saved_fp_regs); |
| 705 | } |
| 706 | __ PopCPURegList(saved_regs); |
| 707 | __ Ret(); |
| 708 | } |
| 709 | |
| 710 | |
| 711 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 712 | Isolate* isolate) { |
| 713 | StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs); |
| 714 | stub1.GetCode(); |
| 715 | StoreBufferOverflowStub stub2(isolate, kSaveFPRegs); |
| 716 | stub2.GetCode(); |
| 717 | } |
| 718 | |
| 719 | |
| 720 | void StoreRegistersStateStub::Generate(MacroAssembler* masm) { |
| 721 | MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm); |
| 722 | UseScratchRegisterScope temps(masm); |
| 723 | Register saved_lr = temps.UnsafeAcquire(to_be_pushed_lr()); |
| 724 | Register return_address = temps.AcquireX(); |
| 725 | __ Mov(return_address, lr); |
| 726 | // Restore lr with the value it had before the call to this stub (the value |
| 727 | // which must be pushed). |
| 728 | __ Mov(lr, saved_lr); |
| 729 | __ PushSafepointRegisters(); |
| 730 | __ Ret(return_address); |
| 731 | } |
| 732 | |
| 733 | |
| 734 | void RestoreRegistersStateStub::Generate(MacroAssembler* masm) { |
| 735 | MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm); |
| 736 | UseScratchRegisterScope temps(masm); |
| 737 | Register return_address = temps.AcquireX(); |
| 738 | // Preserve the return address (lr will be clobbered by the pop). |
| 739 | __ Mov(return_address, lr); |
| 740 | __ PopSafepointRegisters(); |
| 741 | __ Ret(return_address); |
| 742 | } |
| 743 | |
| 744 | |
| 745 | void MathPowStub::Generate(MacroAssembler* masm) { |
| 746 | // Stack on entry: |
| 747 | // jssp[0]: Exponent (as a tagged value). |
| 748 | // jssp[1]: Base (as a tagged value). |
| 749 | // |
| 750 | // The (tagged) result will be returned in x0, as a heap number. |
| 751 | |
| 752 | Register result_tagged = x0; |
| 753 | Register base_tagged = x10; |
| 754 | Register exponent_tagged = MathPowTaggedDescriptor::exponent(); |
| 755 | DCHECK(exponent_tagged.is(x11)); |
| 756 | Register exponent_integer = MathPowIntegerDescriptor::exponent(); |
| 757 | DCHECK(exponent_integer.is(x12)); |
| 758 | Register scratch1 = x14; |
| 759 | Register scratch0 = x15; |
| 760 | Register saved_lr = x19; |
| 761 | FPRegister result_double = d0; |
| 762 | FPRegister base_double = d0; |
| 763 | FPRegister exponent_double = d1; |
| 764 | FPRegister base_double_copy = d2; |
| 765 | FPRegister scratch1_double = d6; |
| 766 | FPRegister scratch0_double = d7; |
| 767 | |
| 768 | // A fast-path for integer exponents. |
| 769 | Label exponent_is_smi, exponent_is_integer; |
| 770 | // Bail out to runtime. |
| 771 | Label call_runtime; |
| 772 | // Allocate a heap number for the result, and return it. |
| 773 | Label done; |
| 774 | |
| 775 | // Unpack the inputs. |
| 776 | if (exponent_type() == ON_STACK) { |
| 777 | Label base_is_smi; |
| 778 | Label unpack_exponent; |
| 779 | |
| 780 | __ Pop(exponent_tagged, base_tagged); |
| 781 | |
| 782 | __ JumpIfSmi(base_tagged, &base_is_smi); |
| 783 | __ JumpIfNotHeapNumber(base_tagged, &call_runtime); |
| 784 | // base_tagged is a heap number, so load its double value. |
| 785 | __ Ldr(base_double, FieldMemOperand(base_tagged, HeapNumber::kValueOffset)); |
| 786 | __ B(&unpack_exponent); |
| 787 | __ Bind(&base_is_smi); |
| 788 | // base_tagged is a SMI, so untag it and convert it to a double. |
| 789 | __ SmiUntagToDouble(base_double, base_tagged); |
| 790 | |
| 791 | __ Bind(&unpack_exponent); |
| 792 | // x10 base_tagged The tagged base (input). |
| 793 | // x11 exponent_tagged The tagged exponent (input). |
| 794 | // d1 base_double The base as a double. |
| 795 | __ JumpIfSmi(exponent_tagged, &exponent_is_smi); |
| 796 | __ JumpIfNotHeapNumber(exponent_tagged, &call_runtime); |
| 797 | // exponent_tagged is a heap number, so load its double value. |
| 798 | __ Ldr(exponent_double, |
| 799 | FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset)); |
| 800 | } else if (exponent_type() == TAGGED) { |
| 801 | __ JumpIfSmi(exponent_tagged, &exponent_is_smi); |
| 802 | __ Ldr(exponent_double, |
| 803 | FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset)); |
| 804 | } |
| 805 | |
| 806 | // Handle double (heap number) exponents. |
| 807 | if (exponent_type() != INTEGER) { |
| 808 | // Detect integer exponents stored as doubles and handle those in the |
| 809 | // integer fast-path. |
| 810 | __ TryRepresentDoubleAsInt64(exponent_integer, exponent_double, |
| 811 | scratch0_double, &exponent_is_integer); |
| 812 | |
| 813 | if (exponent_type() == ON_STACK) { |
| 814 | FPRegister half_double = d3; |
| 815 | FPRegister minus_half_double = d4; |
| 816 | // Detect square root case. Crankshaft detects constant +/-0.5 at compile |
| 817 | // time and uses DoMathPowHalf instead. We then skip this check for |
| 818 | // non-constant cases of +/-0.5 as these hardly occur. |
| 819 | |
| 820 | __ Fmov(minus_half_double, -0.5); |
| 821 | __ Fmov(half_double, 0.5); |
| 822 | __ Fcmp(minus_half_double, exponent_double); |
| 823 | __ Fccmp(half_double, exponent_double, NZFlag, ne); |
| 824 | // Condition flags at this point: |
| 825 | // 0.5; nZCv // Identified by eq && pl |
| 826 | // -0.5: NZcv // Identified by eq && mi |
| 827 | // other: ?z?? // Identified by ne |
| 828 | __ B(ne, &call_runtime); |
| 829 | |
| 830 | // The exponent is 0.5 or -0.5. |
| 831 | |
| 832 | // Given that exponent is known to be either 0.5 or -0.5, the following |
| 833 | // special cases could apply (according to ECMA-262 15.8.2.13): |
| 834 | // |
| 835 | // base.isNaN(): The result is NaN. |
| 836 | // (base == +INFINITY) || (base == -INFINITY) |
| 837 | // exponent == 0.5: The result is +INFINITY. |
| 838 | // exponent == -0.5: The result is +0. |
| 839 | // (base == +0) || (base == -0) |
| 840 | // exponent == 0.5: The result is +0. |
| 841 | // exponent == -0.5: The result is +INFINITY. |
| 842 | // (base < 0) && base.isFinite(): The result is NaN. |
| 843 | // |
| 844 | // Fsqrt (and Fdiv for the -0.5 case) can handle all of those except |
| 845 | // where base is -INFINITY or -0. |
| 846 | |
| 847 | // Add +0 to base. This has no effect other than turning -0 into +0. |
| 848 | __ Fadd(base_double, base_double, fp_zero); |
| 849 | // The operation -0+0 results in +0 in all cases except where the |
| 850 | // FPCR rounding mode is 'round towards minus infinity' (RM). The |
| 851 | // ARM64 simulator does not currently simulate FPCR (where the rounding |
| 852 | // mode is set), so test the operation with some debug code. |
| 853 | if (masm->emit_debug_code()) { |
| 854 | UseScratchRegisterScope temps(masm); |
| 855 | Register temp = temps.AcquireX(); |
| 856 | __ Fneg(scratch0_double, fp_zero); |
| 857 | // Verify that we correctly generated +0.0 and -0.0. |
| 858 | // bits(+0.0) = 0x0000000000000000 |
| 859 | // bits(-0.0) = 0x8000000000000000 |
| 860 | __ Fmov(temp, fp_zero); |
| 861 | __ CheckRegisterIsClear(temp, kCouldNotGenerateZero); |
| 862 | __ Fmov(temp, scratch0_double); |
| 863 | __ Eor(temp, temp, kDSignMask); |
| 864 | __ CheckRegisterIsClear(temp, kCouldNotGenerateNegativeZero); |
| 865 | // Check that -0.0 + 0.0 == +0.0. |
| 866 | __ Fadd(scratch0_double, scratch0_double, fp_zero); |
| 867 | __ Fmov(temp, scratch0_double); |
| 868 | __ CheckRegisterIsClear(temp, kExpectedPositiveZero); |
| 869 | } |
| 870 | |
| 871 | // If base is -INFINITY, make it +INFINITY. |
| 872 | // * Calculate base - base: All infinities will become NaNs since both |
| 873 | // -INFINITY+INFINITY and +INFINITY-INFINITY are NaN in ARM64. |
| 874 | // * If the result is NaN, calculate abs(base). |
| 875 | __ Fsub(scratch0_double, base_double, base_double); |
| 876 | __ Fcmp(scratch0_double, 0.0); |
| 877 | __ Fabs(scratch1_double, base_double); |
| 878 | __ Fcsel(base_double, scratch1_double, base_double, vs); |
| 879 | |
| 880 | // Calculate the square root of base. |
| 881 | __ Fsqrt(result_double, base_double); |
| 882 | __ Fcmp(exponent_double, 0.0); |
| 883 | __ B(ge, &done); // Finish now for exponents of 0.5. |
| 884 | // Find the inverse for exponents of -0.5. |
| 885 | __ Fmov(scratch0_double, 1.0); |
| 886 | __ Fdiv(result_double, scratch0_double, result_double); |
| 887 | __ B(&done); |
| 888 | } |
| 889 | |
| 890 | { |
| 891 | AllowExternalCallThatCantCauseGC scope(masm); |
| 892 | __ Mov(saved_lr, lr); |
| 893 | __ CallCFunction( |
| 894 | ExternalReference::power_double_double_function(isolate()), |
| 895 | 0, 2); |
| 896 | __ Mov(lr, saved_lr); |
| 897 | __ B(&done); |
| 898 | } |
| 899 | |
| 900 | // Handle SMI exponents. |
| 901 | __ Bind(&exponent_is_smi); |
| 902 | // x10 base_tagged The tagged base (input). |
| 903 | // x11 exponent_tagged The tagged exponent (input). |
| 904 | // d1 base_double The base as a double. |
| 905 | __ SmiUntag(exponent_integer, exponent_tagged); |
| 906 | } |
| 907 | |
| 908 | __ Bind(&exponent_is_integer); |
| 909 | // x10 base_tagged The tagged base (input). |
| 910 | // x11 exponent_tagged The tagged exponent (input). |
| 911 | // x12 exponent_integer The exponent as an integer. |
| 912 | // d1 base_double The base as a double. |
| 913 | |
| 914 | // Find abs(exponent). For negative exponents, we can find the inverse later. |
| 915 | Register exponent_abs = x13; |
| 916 | __ Cmp(exponent_integer, 0); |
| 917 | __ Cneg(exponent_abs, exponent_integer, mi); |
| 918 | // x13 exponent_abs The value of abs(exponent_integer). |
| 919 | |
| 920 | // Repeatedly multiply to calculate the power. |
| 921 | // result = 1.0; |
| 922 | // For each bit n (exponent_integer{n}) { |
| 923 | // if (exponent_integer{n}) { |
| 924 | // result *= base; |
| 925 | // } |
| 926 | // base *= base; |
| 927 | // if (remaining bits in exponent_integer are all zero) { |
| 928 | // break; |
| 929 | // } |
| 930 | // } |
| 931 | Label power_loop, power_loop_entry, power_loop_exit; |
| 932 | __ Fmov(scratch1_double, base_double); |
| 933 | __ Fmov(base_double_copy, base_double); |
| 934 | __ Fmov(result_double, 1.0); |
| 935 | __ B(&power_loop_entry); |
| 936 | |
| 937 | __ Bind(&power_loop); |
| 938 | __ Fmul(scratch1_double, scratch1_double, scratch1_double); |
| 939 | __ Lsr(exponent_abs, exponent_abs, 1); |
| 940 | __ Cbz(exponent_abs, &power_loop_exit); |
| 941 | |
| 942 | __ Bind(&power_loop_entry); |
| 943 | __ Tbz(exponent_abs, 0, &power_loop); |
| 944 | __ Fmul(result_double, result_double, scratch1_double); |
| 945 | __ B(&power_loop); |
| 946 | |
| 947 | __ Bind(&power_loop_exit); |
| 948 | |
| 949 | // If the exponent was positive, result_double holds the result. |
| 950 | __ Tbz(exponent_integer, kXSignBit, &done); |
| 951 | |
| 952 | // The exponent was negative, so find the inverse. |
| 953 | __ Fmov(scratch0_double, 1.0); |
| 954 | __ Fdiv(result_double, scratch0_double, result_double); |
| 955 | // ECMA-262 only requires Math.pow to return an 'implementation-dependent |
| 956 | // approximation' of base^exponent. However, mjsunit/math-pow uses Math.pow |
| 957 | // to calculate the subnormal value 2^-1074. This method of calculating |
| 958 | // negative powers doesn't work because 2^1074 overflows to infinity. To |
| 959 | // catch this corner-case, we bail out if the result was 0. (This can only |
| 960 | // occur if the divisor is infinity or the base is zero.) |
| 961 | __ Fcmp(result_double, 0.0); |
| 962 | __ B(&done, ne); |
| 963 | |
| 964 | if (exponent_type() == ON_STACK) { |
| 965 | // Bail out to runtime code. |
| 966 | __ Bind(&call_runtime); |
| 967 | // Put the arguments back on the stack. |
| 968 | __ Push(base_tagged, exponent_tagged); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 969 | __ TailCallRuntime(Runtime::kMathPowRT); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 970 | |
| 971 | // Return. |
| 972 | __ Bind(&done); |
| 973 | __ AllocateHeapNumber(result_tagged, &call_runtime, scratch0, scratch1, |
| 974 | result_double); |
| 975 | DCHECK(result_tagged.is(x0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 976 | __ Ret(); |
| 977 | } else { |
| 978 | AllowExternalCallThatCantCauseGC scope(masm); |
| 979 | __ Mov(saved_lr, lr); |
| 980 | __ Fmov(base_double, base_double_copy); |
| 981 | __ Scvtf(exponent_double, exponent_integer); |
| 982 | __ CallCFunction( |
| 983 | ExternalReference::power_double_double_function(isolate()), |
| 984 | 0, 2); |
| 985 | __ Mov(lr, saved_lr); |
| 986 | __ Bind(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 987 | __ Ret(); |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | |
| 992 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 993 | // It is important that the following stubs are generated in this order |
| 994 | // because pregenerated stubs can only call other pregenerated stubs. |
| 995 | // RecordWriteStub uses StoreBufferOverflowStub, which in turn uses |
| 996 | // CEntryStub. |
| 997 | CEntryStub::GenerateAheadOfTime(isolate); |
| 998 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
| 999 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
| 1000 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
| 1001 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1002 | CreateWeakCellStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1003 | BinaryOpICStub::GenerateAheadOfTime(isolate); |
| 1004 | StoreRegistersStateStub::GenerateAheadOfTime(isolate); |
| 1005 | RestoreRegistersStateStub::GenerateAheadOfTime(isolate); |
| 1006 | BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1007 | StoreFastElementStub::GenerateAheadOfTime(isolate); |
| 1008 | TypeofStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | |
| 1012 | void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) { |
| 1013 | StoreRegistersStateStub stub(isolate); |
| 1014 | stub.GetCode(); |
| 1015 | } |
| 1016 | |
| 1017 | |
| 1018 | void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) { |
| 1019 | RestoreRegistersStateStub stub(isolate); |
| 1020 | stub.GetCode(); |
| 1021 | } |
| 1022 | |
| 1023 | |
| 1024 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
| 1025 | // Floating-point code doesn't get special handling in ARM64, so there's |
| 1026 | // nothing to do here. |
| 1027 | USE(isolate); |
| 1028 | } |
| 1029 | |
| 1030 | |
| 1031 | bool CEntryStub::NeedsImmovableCode() { |
| 1032 | // CEntryStub stores the return address on the stack before calling into |
| 1033 | // C++ code. In some cases, the VM accesses this address, but it is not used |
| 1034 | // when the C++ code returns to the stub because LR holds the return address |
| 1035 | // in AAPCS64. If the stub is moved (perhaps during a GC), we could end up |
| 1036 | // returning to dead code. |
| 1037 | // TODO(jbramley): Whilst this is the only analysis that makes sense, I can't |
| 1038 | // find any comment to confirm this, and I don't hit any crashes whatever |
| 1039 | // this function returns. The anaylsis should be properly confirmed. |
| 1040 | return true; |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
| 1045 | CEntryStub stub(isolate, 1, kDontSaveFPRegs); |
| 1046 | stub.GetCode(); |
| 1047 | CEntryStub stub_fp(isolate, 1, kSaveFPRegs); |
| 1048 | stub_fp.GetCode(); |
| 1049 | } |
| 1050 | |
| 1051 | |
| 1052 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 1053 | // The Abort mechanism relies on CallRuntime, which in turn relies on |
| 1054 | // CEntryStub, so until this stub has been generated, we have to use a |
| 1055 | // fall-back Abort mechanism. |
| 1056 | // |
| 1057 | // Note that this stub must be generated before any use of Abort. |
| 1058 | MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm); |
| 1059 | |
| 1060 | ASM_LOCATION("CEntryStub::Generate entry"); |
| 1061 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 1062 | |
| 1063 | // Register parameters: |
| 1064 | // x0: argc (including receiver, untagged) |
| 1065 | // x1: target |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1066 | // If argv_in_register(): |
| 1067 | // x11: argv (pointer to first argument) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1068 | // |
| 1069 | // The stack on entry holds the arguments and the receiver, with the receiver |
| 1070 | // at the highest address: |
| 1071 | // |
| 1072 | // jssp]argc-1]: receiver |
| 1073 | // jssp[argc-2]: arg[argc-2] |
| 1074 | // ... ... |
| 1075 | // jssp[1]: arg[1] |
| 1076 | // jssp[0]: arg[0] |
| 1077 | // |
| 1078 | // The arguments are in reverse order, so that arg[argc-2] is actually the |
| 1079 | // first argument to the target function and arg[0] is the last. |
| 1080 | DCHECK(jssp.Is(__ StackPointer())); |
| 1081 | const Register& argc_input = x0; |
| 1082 | const Register& target_input = x1; |
| 1083 | |
| 1084 | // Calculate argv, argc and the target address, and store them in |
| 1085 | // callee-saved registers so we can retry the call without having to reload |
| 1086 | // these arguments. |
| 1087 | // TODO(jbramley): If the first call attempt succeeds in the common case (as |
| 1088 | // it should), then we might be better off putting these parameters directly |
| 1089 | // into their argument registers, rather than using callee-saved registers and |
| 1090 | // preserving them on the stack. |
| 1091 | const Register& argv = x21; |
| 1092 | const Register& argc = x22; |
| 1093 | const Register& target = x23; |
| 1094 | |
| 1095 | // Derive argv from the stack pointer so that it points to the first argument |
| 1096 | // (arg[argc-2]), or just below the receiver in case there are no arguments. |
| 1097 | // - Adjust for the arg[] array. |
| 1098 | Register temp_argv = x11; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1099 | if (!argv_in_register()) { |
| 1100 | __ Add(temp_argv, jssp, Operand(x0, LSL, kPointerSizeLog2)); |
| 1101 | // - Adjust for the receiver. |
| 1102 | __ Sub(temp_argv, temp_argv, 1 * kPointerSize); |
| 1103 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1104 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1105 | // Reserve three slots to preserve x21-x23 callee-saved registers. If the |
| 1106 | // result size is too large to be returned in registers then also reserve |
| 1107 | // space for the return value. |
| 1108 | int extra_stack_space = 3 + (result_size() <= 2 ? 0 : result_size()); |
| 1109 | // Enter the exit frame. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1110 | FrameScope scope(masm, StackFrame::MANUAL); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1111 | __ EnterExitFrame(save_doubles(), x10, extra_stack_space); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1112 | DCHECK(csp.Is(__ StackPointer())); |
| 1113 | |
| 1114 | // Poke callee-saved registers into reserved space. |
| 1115 | __ Poke(argv, 1 * kPointerSize); |
| 1116 | __ Poke(argc, 2 * kPointerSize); |
| 1117 | __ Poke(target, 3 * kPointerSize); |
| 1118 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1119 | if (result_size() > 2) { |
| 1120 | // Save the location of the return value into x8 for call. |
| 1121 | __ Add(x8, __ StackPointer(), Operand(4 * kPointerSize)); |
| 1122 | } |
| 1123 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1124 | // We normally only keep tagged values in callee-saved registers, as they |
| 1125 | // could be pushed onto the stack by called stubs and functions, and on the |
| 1126 | // stack they can confuse the GC. However, we're only calling C functions |
| 1127 | // which can push arbitrary data onto the stack anyway, and so the GC won't |
| 1128 | // examine that part of the stack. |
| 1129 | __ Mov(argc, argc_input); |
| 1130 | __ Mov(target, target_input); |
| 1131 | __ Mov(argv, temp_argv); |
| 1132 | |
| 1133 | // x21 : argv |
| 1134 | // x22 : argc |
| 1135 | // x23 : call target |
| 1136 | // |
| 1137 | // The stack (on entry) holds the arguments and the receiver, with the |
| 1138 | // receiver at the highest address: |
| 1139 | // |
| 1140 | // argv[8]: receiver |
| 1141 | // argv -> argv[0]: arg[argc-2] |
| 1142 | // ... ... |
| 1143 | // argv[...]: arg[1] |
| 1144 | // argv[...]: arg[0] |
| 1145 | // |
| 1146 | // Immediately below (after) this is the exit frame, as constructed by |
| 1147 | // EnterExitFrame: |
| 1148 | // fp[8]: CallerPC (lr) |
| 1149 | // fp -> fp[0]: CallerFP (old fp) |
| 1150 | // fp[-8]: Space reserved for SPOffset. |
| 1151 | // fp[-16]: CodeObject() |
| 1152 | // csp[...]: Saved doubles, if saved_doubles is true. |
| 1153 | // csp[32]: Alignment padding, if necessary. |
| 1154 | // csp[24]: Preserved x23 (used for target). |
| 1155 | // csp[16]: Preserved x22 (used for argc). |
| 1156 | // csp[8]: Preserved x21 (used for argv). |
| 1157 | // csp -> csp[0]: Space reserved for the return address. |
| 1158 | // |
| 1159 | // After a successful call, the exit frame, preserved registers (x21-x23) and |
| 1160 | // the arguments (including the receiver) are dropped or popped as |
| 1161 | // appropriate. The stub then returns. |
| 1162 | // |
| 1163 | // After an unsuccessful call, the exit frame and suchlike are left |
| 1164 | // untouched, and the stub either throws an exception by jumping to one of |
| 1165 | // the exception_returned label. |
| 1166 | |
| 1167 | DCHECK(csp.Is(__ StackPointer())); |
| 1168 | |
| 1169 | // Prepare AAPCS64 arguments to pass to the builtin. |
| 1170 | __ Mov(x0, argc); |
| 1171 | __ Mov(x1, argv); |
| 1172 | __ Mov(x2, ExternalReference::isolate_address(isolate())); |
| 1173 | |
| 1174 | Label return_location; |
| 1175 | __ Adr(x12, &return_location); |
| 1176 | __ Poke(x12, 0); |
| 1177 | |
| 1178 | if (__ emit_debug_code()) { |
| 1179 | // Verify that the slot below fp[kSPOffset]-8 points to the return location |
| 1180 | // (currently in x12). |
| 1181 | UseScratchRegisterScope temps(masm); |
| 1182 | Register temp = temps.AcquireX(); |
| 1183 | __ Ldr(temp, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
| 1184 | __ Ldr(temp, MemOperand(temp, -static_cast<int64_t>(kXRegSize))); |
| 1185 | __ Cmp(temp, x12); |
| 1186 | __ Check(eq, kReturnAddressNotFoundInFrame); |
| 1187 | } |
| 1188 | |
| 1189 | // Call the builtin. |
| 1190 | __ Blr(target); |
| 1191 | __ Bind(&return_location); |
| 1192 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1193 | if (result_size() > 2) { |
| 1194 | DCHECK_EQ(3, result_size()); |
| 1195 | // Read result values stored on stack. |
| 1196 | __ Ldr(x0, MemOperand(__ StackPointer(), 4 * kPointerSize)); |
| 1197 | __ Ldr(x1, MemOperand(__ StackPointer(), 5 * kPointerSize)); |
| 1198 | __ Ldr(x2, MemOperand(__ StackPointer(), 6 * kPointerSize)); |
| 1199 | } |
| 1200 | // Result returned in x0, x1:x0 or x2:x1:x0 - do not destroy these registers! |
| 1201 | |
| 1202 | // x0 result0 The return code from the call. |
| 1203 | // x1 result1 For calls which return ObjectPair or ObjectTriple. |
| 1204 | // x2 result2 For calls which return ObjectTriple. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1205 | // x21 argv |
| 1206 | // x22 argc |
| 1207 | // x23 target |
| 1208 | const Register& result = x0; |
| 1209 | |
| 1210 | // Check result for exception sentinel. |
| 1211 | Label exception_returned; |
| 1212 | __ CompareRoot(result, Heap::kExceptionRootIndex); |
| 1213 | __ B(eq, &exception_returned); |
| 1214 | |
| 1215 | // The call succeeded, so unwind the stack and return. |
| 1216 | |
| 1217 | // Restore callee-saved registers x21-x23. |
| 1218 | __ Mov(x11, argc); |
| 1219 | |
| 1220 | __ Peek(argv, 1 * kPointerSize); |
| 1221 | __ Peek(argc, 2 * kPointerSize); |
| 1222 | __ Peek(target, 3 * kPointerSize); |
| 1223 | |
| 1224 | __ LeaveExitFrame(save_doubles(), x10, true); |
| 1225 | DCHECK(jssp.Is(__ StackPointer())); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1226 | if (!argv_in_register()) { |
| 1227 | // Drop the remaining stack slots and return from the stub. |
| 1228 | __ Drop(x11); |
| 1229 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1230 | __ AssertFPCRState(); |
| 1231 | __ Ret(); |
| 1232 | |
| 1233 | // The stack pointer is still csp if we aren't returning, and the frame |
| 1234 | // hasn't changed (except for the return address). |
| 1235 | __ SetStackPointer(csp); |
| 1236 | |
| 1237 | // Handling of exception. |
| 1238 | __ Bind(&exception_returned); |
| 1239 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1240 | ExternalReference pending_handler_context_address( |
| 1241 | Isolate::kPendingHandlerContextAddress, isolate()); |
| 1242 | ExternalReference pending_handler_code_address( |
| 1243 | Isolate::kPendingHandlerCodeAddress, isolate()); |
| 1244 | ExternalReference pending_handler_offset_address( |
| 1245 | Isolate::kPendingHandlerOffsetAddress, isolate()); |
| 1246 | ExternalReference pending_handler_fp_address( |
| 1247 | Isolate::kPendingHandlerFPAddress, isolate()); |
| 1248 | ExternalReference pending_handler_sp_address( |
| 1249 | Isolate::kPendingHandlerSPAddress, isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1250 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1251 | // Ask the runtime for help to determine the handler. This will set x0 to |
| 1252 | // contain the current pending exception, don't clobber it. |
| 1253 | ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler, |
| 1254 | isolate()); |
| 1255 | DCHECK(csp.Is(masm->StackPointer())); |
| 1256 | { |
| 1257 | FrameScope scope(masm, StackFrame::MANUAL); |
| 1258 | __ Mov(x0, 0); // argc. |
| 1259 | __ Mov(x1, 0); // argv. |
| 1260 | __ Mov(x2, ExternalReference::isolate_address(isolate())); |
| 1261 | __ CallCFunction(find_handler, 3); |
| 1262 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1263 | |
| 1264 | // We didn't execute a return case, so the stack frame hasn't been updated |
| 1265 | // (except for the return address slot). However, we don't need to initialize |
| 1266 | // jssp because the throw method will immediately overwrite it when it |
| 1267 | // unwinds the stack. |
| 1268 | __ SetStackPointer(jssp); |
| 1269 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1270 | // Retrieve the handler context, SP and FP. |
| 1271 | __ Mov(cp, Operand(pending_handler_context_address)); |
| 1272 | __ Ldr(cp, MemOperand(cp)); |
| 1273 | __ Mov(jssp, Operand(pending_handler_sp_address)); |
| 1274 | __ Ldr(jssp, MemOperand(jssp)); |
| 1275 | __ Mov(fp, Operand(pending_handler_fp_address)); |
| 1276 | __ Ldr(fp, MemOperand(fp)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1277 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1278 | // If the handler is a JS frame, restore the context to the frame. Note that |
| 1279 | // the context will be set to (cp == 0) for non-JS frames. |
| 1280 | Label not_js_frame; |
| 1281 | __ Cbz(cp, ¬_js_frame); |
| 1282 | __ Str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 1283 | __ Bind(¬_js_frame); |
| 1284 | |
| 1285 | // Compute the handler entry address and jump to it. |
| 1286 | __ Mov(x10, Operand(pending_handler_code_address)); |
| 1287 | __ Ldr(x10, MemOperand(x10)); |
| 1288 | __ Mov(x11, Operand(pending_handler_offset_address)); |
| 1289 | __ Ldr(x11, MemOperand(x11)); |
| 1290 | __ Add(x10, x10, Code::kHeaderSize - kHeapObjectTag); |
| 1291 | __ Add(x10, x10, x11); |
| 1292 | __ Br(x10); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | |
| 1296 | // This is the entry point from C++. 5 arguments are provided in x0-x4. |
| 1297 | // See use of the CALL_GENERATED_CODE macro for example in src/execution.cc. |
| 1298 | // Input: |
| 1299 | // x0: code entry. |
| 1300 | // x1: function. |
| 1301 | // x2: receiver. |
| 1302 | // x3: argc. |
| 1303 | // x4: argv. |
| 1304 | // Output: |
| 1305 | // x0: result. |
| 1306 | void JSEntryStub::Generate(MacroAssembler* masm) { |
| 1307 | DCHECK(jssp.Is(__ StackPointer())); |
| 1308 | Register code_entry = x0; |
| 1309 | |
| 1310 | // Enable instruction instrumentation. This only works on the simulator, and |
| 1311 | // will have no effect on the model or real hardware. |
| 1312 | __ EnableInstrumentation(); |
| 1313 | |
| 1314 | Label invoke, handler_entry, exit; |
| 1315 | |
| 1316 | // Push callee-saved registers and synchronize the system stack pointer (csp) |
| 1317 | // and the JavaScript stack pointer (jssp). |
| 1318 | // |
| 1319 | // We must not write to jssp until after the PushCalleeSavedRegisters() |
| 1320 | // call, since jssp is itself a callee-saved register. |
| 1321 | __ SetStackPointer(csp); |
| 1322 | __ PushCalleeSavedRegisters(); |
| 1323 | __ Mov(jssp, csp); |
| 1324 | __ SetStackPointer(jssp); |
| 1325 | |
| 1326 | // Configure the FPCR. We don't restore it, so this is technically not allowed |
| 1327 | // according to AAPCS64. However, we only set default-NaN mode and this will |
| 1328 | // be harmless for most C code. Also, it works for ARM. |
| 1329 | __ ConfigureFPCR(); |
| 1330 | |
| 1331 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 1332 | |
| 1333 | // Set up the reserved register for 0.0. |
| 1334 | __ Fmov(fp_zero, 0.0); |
| 1335 | |
| 1336 | // Build an entry frame (see layout below). |
| 1337 | int marker = type(); |
| 1338 | int64_t bad_frame_pointer = -1L; // Bad frame pointer to fail if it is used. |
| 1339 | __ Mov(x13, bad_frame_pointer); |
| 1340 | __ Mov(x12, Smi::FromInt(marker)); |
| 1341 | __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate())); |
| 1342 | __ Ldr(x10, MemOperand(x11)); |
| 1343 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1344 | __ Push(x13, x12, xzr, x10); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1345 | // Set up fp. |
| 1346 | __ Sub(fp, jssp, EntryFrameConstants::kCallerFPOffset); |
| 1347 | |
| 1348 | // Push the JS entry frame marker. Also set js_entry_sp if this is the |
| 1349 | // outermost JS call. |
| 1350 | Label non_outermost_js, done; |
| 1351 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate()); |
| 1352 | __ Mov(x10, ExternalReference(js_entry_sp)); |
| 1353 | __ Ldr(x11, MemOperand(x10)); |
| 1354 | __ Cbnz(x11, &non_outermost_js); |
| 1355 | __ Str(fp, MemOperand(x10)); |
| 1356 | __ Mov(x12, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)); |
| 1357 | __ Push(x12); |
| 1358 | __ B(&done); |
| 1359 | __ Bind(&non_outermost_js); |
| 1360 | // We spare one instruction by pushing xzr since the marker is 0. |
| 1361 | DCHECK(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME) == NULL); |
| 1362 | __ Push(xzr); |
| 1363 | __ Bind(&done); |
| 1364 | |
| 1365 | // The frame set up looks like this: |
| 1366 | // jssp[0] : JS entry frame marker. |
| 1367 | // jssp[1] : C entry FP. |
| 1368 | // jssp[2] : stack frame marker. |
| 1369 | // jssp[3] : stack frmae marker. |
| 1370 | // jssp[4] : bad frame pointer 0xfff...ff <- fp points here. |
| 1371 | |
| 1372 | |
| 1373 | // Jump to a faked try block that does the invoke, with a faked catch |
| 1374 | // block that sets the pending exception. |
| 1375 | __ B(&invoke); |
| 1376 | |
| 1377 | // Prevent the constant pool from being emitted between the record of the |
| 1378 | // handler_entry position and the first instruction of the sequence here. |
| 1379 | // There is no risk because Assembler::Emit() emits the instruction before |
| 1380 | // checking for constant pool emission, but we do not want to depend on |
| 1381 | // that. |
| 1382 | { |
| 1383 | Assembler::BlockPoolsScope block_pools(masm); |
| 1384 | __ bind(&handler_entry); |
| 1385 | handler_offset_ = handler_entry.pos(); |
| 1386 | // Caught exception: Store result (exception) in the pending exception |
| 1387 | // field in the JSEnv and return a failure sentinel. Coming in here the |
| 1388 | // fp will be invalid because the PushTryHandler below sets it to 0 to |
| 1389 | // signal the existence of the JSEntry frame. |
| 1390 | __ Mov(x10, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
| 1391 | isolate()))); |
| 1392 | } |
| 1393 | __ Str(code_entry, MemOperand(x10)); |
| 1394 | __ LoadRoot(x0, Heap::kExceptionRootIndex); |
| 1395 | __ B(&exit); |
| 1396 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1397 | // Invoke: Link this frame into the handler chain. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1398 | __ Bind(&invoke); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1399 | __ PushStackHandler(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1400 | // If an exception not caught by another handler occurs, this handler |
| 1401 | // returns control to the code after the B(&invoke) above, which |
| 1402 | // restores all callee-saved registers (including cp and fp) to their |
| 1403 | // saved values before returning a failure to C. |
| 1404 | |
| 1405 | // Clear any pending exceptions. |
| 1406 | __ Mov(x10, Operand(isolate()->factory()->the_hole_value())); |
| 1407 | __ Mov(x11, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
| 1408 | isolate()))); |
| 1409 | __ Str(x10, MemOperand(x11)); |
| 1410 | |
| 1411 | // Invoke the function by calling through the JS entry trampoline builtin. |
| 1412 | // Notice that we cannot store a reference to the trampoline code directly in |
| 1413 | // this stub, because runtime stubs are not traversed when doing GC. |
| 1414 | |
| 1415 | // Expected registers by Builtins::JSEntryTrampoline |
| 1416 | // x0: code entry. |
| 1417 | // x1: function. |
| 1418 | // x2: receiver. |
| 1419 | // x3: argc. |
| 1420 | // x4: argv. |
| 1421 | ExternalReference entry(type() == StackFrame::ENTRY_CONSTRUCT |
| 1422 | ? Builtins::kJSConstructEntryTrampoline |
| 1423 | : Builtins::kJSEntryTrampoline, |
| 1424 | isolate()); |
| 1425 | __ Mov(x10, entry); |
| 1426 | |
| 1427 | // Call the JSEntryTrampoline. |
| 1428 | __ Ldr(x11, MemOperand(x10)); // Dereference the address. |
| 1429 | __ Add(x12, x11, Code::kHeaderSize - kHeapObjectTag); |
| 1430 | __ Blr(x12); |
| 1431 | |
| 1432 | // Unlink this frame from the handler chain. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1433 | __ PopStackHandler(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1434 | |
| 1435 | |
| 1436 | __ Bind(&exit); |
| 1437 | // x0 holds the result. |
| 1438 | // The stack pointer points to the top of the entry frame pushed on entry from |
| 1439 | // C++ (at the beginning of this stub): |
| 1440 | // jssp[0] : JS entry frame marker. |
| 1441 | // jssp[1] : C entry FP. |
| 1442 | // jssp[2] : stack frame marker. |
| 1443 | // jssp[3] : stack frmae marker. |
| 1444 | // jssp[4] : bad frame pointer 0xfff...ff <- fp points here. |
| 1445 | |
| 1446 | // Check if the current stack frame is marked as the outermost JS frame. |
| 1447 | Label non_outermost_js_2; |
| 1448 | __ Pop(x10); |
| 1449 | __ Cmp(x10, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)); |
| 1450 | __ B(ne, &non_outermost_js_2); |
| 1451 | __ Mov(x11, ExternalReference(js_entry_sp)); |
| 1452 | __ Str(xzr, MemOperand(x11)); |
| 1453 | __ Bind(&non_outermost_js_2); |
| 1454 | |
| 1455 | // Restore the top frame descriptors from the stack. |
| 1456 | __ Pop(x10); |
| 1457 | __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate())); |
| 1458 | __ Str(x10, MemOperand(x11)); |
| 1459 | |
| 1460 | // Reset the stack to the callee saved registers. |
| 1461 | __ Drop(-EntryFrameConstants::kCallerFPOffset, kByteSizeInBytes); |
| 1462 | // Restore the callee-saved registers and return. |
| 1463 | DCHECK(jssp.Is(__ StackPointer())); |
| 1464 | __ Mov(csp, jssp); |
| 1465 | __ SetStackPointer(csp); |
| 1466 | __ PopCalleeSavedRegisters(); |
| 1467 | // After this point, we must not modify jssp because it is a callee-saved |
| 1468 | // register which we have just restored. |
| 1469 | __ Ret(); |
| 1470 | } |
| 1471 | |
| 1472 | |
| 1473 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 1474 | Label miss; |
| 1475 | Register receiver = LoadDescriptor::ReceiverRegister(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1476 | // Ensure that the vector and slot registers won't be clobbered before |
| 1477 | // calling the miss handler. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1478 | DCHECK(!AreAliased(x10, x11, LoadWithVectorDescriptor::VectorRegister(), |
| 1479 | LoadWithVectorDescriptor::SlotRegister())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1480 | |
| 1481 | NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, x10, |
| 1482 | x11, &miss); |
| 1483 | |
| 1484 | __ Bind(&miss); |
| 1485 | PropertyAccessCompiler::TailCallBuiltin( |
| 1486 | masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC)); |
| 1487 | } |
| 1488 | |
| 1489 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1490 | void LoadIndexedStringStub::Generate(MacroAssembler* masm) { |
| 1491 | // Return address is in lr. |
| 1492 | Label miss; |
| 1493 | |
| 1494 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 1495 | Register index = LoadDescriptor::NameRegister(); |
| 1496 | Register result = x0; |
| 1497 | Register scratch = x10; |
| 1498 | DCHECK(!scratch.is(receiver) && !scratch.is(index)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1499 | DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) && |
| 1500 | result.is(LoadWithVectorDescriptor::SlotRegister())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1501 | |
| 1502 | // StringCharAtGenerator doesn't use the result register until it's passed |
| 1503 | // the different miss possibilities. If it did, we would have a conflict |
| 1504 | // when FLAG_vector_ics is true. |
| 1505 | StringCharAtGenerator char_at_generator(receiver, index, scratch, result, |
| 1506 | &miss, // When not a string. |
| 1507 | &miss, // When not a number. |
| 1508 | &miss, // When index out of range. |
| 1509 | STRING_INDEX_IS_ARRAY_INDEX, |
| 1510 | RECEIVER_IS_STRING); |
| 1511 | char_at_generator.GenerateFast(masm); |
| 1512 | __ Ret(); |
| 1513 | |
| 1514 | StubRuntimeCallHelper call_helper; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1515 | char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1516 | |
| 1517 | __ Bind(&miss); |
| 1518 | PropertyAccessCompiler::TailCallBuiltin( |
| 1519 | masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC)); |
| 1520 | } |
| 1521 | |
| 1522 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1523 | void InstanceOfStub::Generate(MacroAssembler* masm) { |
| 1524 | Register const object = x1; // Object (lhs). |
| 1525 | Register const function = x0; // Function (rhs). |
| 1526 | Register const object_map = x2; // Map of {object}. |
| 1527 | Register const function_map = x3; // Map of {function}. |
| 1528 | Register const function_prototype = x4; // Prototype of {function}. |
| 1529 | Register const scratch = x5; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1530 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1531 | DCHECK(object.is(InstanceOfDescriptor::LeftRegister())); |
| 1532 | DCHECK(function.is(InstanceOfDescriptor::RightRegister())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1533 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1534 | // Check if {object} is a smi. |
| 1535 | Label object_is_smi; |
| 1536 | __ JumpIfSmi(object, &object_is_smi); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1537 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1538 | // Lookup the {function} and the {object} map in the global instanceof cache. |
| 1539 | // Note: This is safe because we clear the global instanceof cache whenever |
| 1540 | // we change the prototype of any object. |
| 1541 | Label fast_case, slow_case; |
| 1542 | __ Ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1543 | __ JumpIfNotRoot(function, Heap::kInstanceofCacheFunctionRootIndex, |
| 1544 | &fast_case); |
| 1545 | __ JumpIfNotRoot(object_map, Heap::kInstanceofCacheMapRootIndex, &fast_case); |
| 1546 | __ LoadRoot(x0, Heap::kInstanceofCacheAnswerRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1547 | __ Ret(); |
| 1548 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1549 | // If {object} is a smi we can safely return false if {function} is a JS |
| 1550 | // function, otherwise we have to miss to the runtime and throw an exception. |
| 1551 | __ Bind(&object_is_smi); |
| 1552 | __ JumpIfSmi(function, &slow_case); |
| 1553 | __ JumpIfNotObjectType(function, function_map, scratch, JS_FUNCTION_TYPE, |
| 1554 | &slow_case); |
| 1555 | __ LoadRoot(x0, Heap::kFalseValueRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1556 | __ Ret(); |
| 1557 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1558 | // Fast-case: The {function} must be a valid JSFunction. |
| 1559 | __ Bind(&fast_case); |
| 1560 | __ JumpIfSmi(function, &slow_case); |
| 1561 | __ JumpIfNotObjectType(function, function_map, scratch, JS_FUNCTION_TYPE, |
| 1562 | &slow_case); |
| 1563 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1564 | // Go to the runtime if the function is not a constructor. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1565 | __ Ldrb(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1566 | __ Tbz(scratch, Map::kIsConstructor, &slow_case); |
| 1567 | |
| 1568 | // Ensure that {function} has an instance prototype. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1569 | __ Tbnz(scratch, Map::kHasNonInstancePrototype, &slow_case); |
| 1570 | |
| 1571 | // Get the "prototype" (or initial map) of the {function}. |
| 1572 | __ Ldr(function_prototype, |
| 1573 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1574 | __ AssertNotSmi(function_prototype); |
| 1575 | |
| 1576 | // Resolve the prototype if the {function} has an initial map. Afterwards the |
| 1577 | // {function_prototype} will be either the JSReceiver prototype object or the |
| 1578 | // hole value, which means that no instances of the {function} were created so |
| 1579 | // far and hence we should return false. |
| 1580 | Label function_prototype_valid; |
| 1581 | __ JumpIfNotObjectType(function_prototype, scratch, scratch, MAP_TYPE, |
| 1582 | &function_prototype_valid); |
| 1583 | __ Ldr(function_prototype, |
| 1584 | FieldMemOperand(function_prototype, Map::kPrototypeOffset)); |
| 1585 | __ Bind(&function_prototype_valid); |
| 1586 | __ AssertNotSmi(function_prototype); |
| 1587 | |
| 1588 | // Update the global instanceof cache with the current {object} map and |
| 1589 | // {function}. The cached answer will be set when it is known below. |
| 1590 | __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex); |
| 1591 | __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex); |
| 1592 | |
| 1593 | // Loop through the prototype chain looking for the {function} prototype. |
| 1594 | // Assume true, and change to false if not found. |
| 1595 | Register const object_instance_type = function_map; |
| 1596 | Register const map_bit_field = function_map; |
| 1597 | Register const null = scratch; |
| 1598 | Register const result = x0; |
| 1599 | |
| 1600 | Label done, loop, fast_runtime_fallback; |
| 1601 | __ LoadRoot(result, Heap::kTrueValueRootIndex); |
| 1602 | __ LoadRoot(null, Heap::kNullValueRootIndex); |
| 1603 | __ Bind(&loop); |
| 1604 | |
| 1605 | // Check if the object needs to be access checked. |
| 1606 | __ Ldrb(map_bit_field, FieldMemOperand(object_map, Map::kBitFieldOffset)); |
| 1607 | __ TestAndBranchIfAnySet(map_bit_field, 1 << Map::kIsAccessCheckNeeded, |
| 1608 | &fast_runtime_fallback); |
| 1609 | // Check if the current object is a Proxy. |
| 1610 | __ CompareInstanceType(object_map, object_instance_type, JS_PROXY_TYPE); |
| 1611 | __ B(eq, &fast_runtime_fallback); |
| 1612 | |
| 1613 | __ Ldr(object, FieldMemOperand(object_map, Map::kPrototypeOffset)); |
| 1614 | __ Cmp(object, function_prototype); |
| 1615 | __ B(eq, &done); |
| 1616 | __ Cmp(object, null); |
| 1617 | __ Ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1618 | __ B(ne, &loop); |
| 1619 | __ LoadRoot(result, Heap::kFalseValueRootIndex); |
| 1620 | __ Bind(&done); |
| 1621 | __ StoreRoot(result, Heap::kInstanceofCacheAnswerRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1622 | __ Ret(); |
| 1623 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1624 | // Found Proxy or access check needed: Call the runtime |
| 1625 | __ Bind(&fast_runtime_fallback); |
| 1626 | __ Push(object, function_prototype); |
| 1627 | // Invalidate the instanceof cache. |
| 1628 | __ Move(scratch, Smi::FromInt(0)); |
| 1629 | __ StoreRoot(scratch, Heap::kInstanceofCacheFunctionRootIndex); |
| 1630 | __ TailCallRuntime(Runtime::kHasInPrototypeChain); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1631 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1632 | // Slow-case: Call the %InstanceOf runtime function. |
| 1633 | __ bind(&slow_case); |
| 1634 | __ Push(object, function); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1635 | __ TailCallRuntime(is_es6_instanceof() ? Runtime::kOrdinaryHasInstance |
| 1636 | : Runtime::kInstanceOf); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1640 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 1641 | #ifdef V8_INTERPRETED_REGEXP |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1642 | __ TailCallRuntime(Runtime::kRegExpExec); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1643 | #else // V8_INTERPRETED_REGEXP |
| 1644 | |
| 1645 | // Stack frame on entry. |
| 1646 | // jssp[0]: last_match_info (expected JSArray) |
| 1647 | // jssp[8]: previous index |
| 1648 | // jssp[16]: subject string |
| 1649 | // jssp[24]: JSRegExp object |
| 1650 | Label runtime; |
| 1651 | |
| 1652 | // Use of registers for this function. |
| 1653 | |
| 1654 | // Variable registers: |
| 1655 | // x10-x13 used as scratch registers |
| 1656 | // w0 string_type type of subject string |
| 1657 | // x2 jsstring_length subject string length |
| 1658 | // x3 jsregexp_object JSRegExp object |
| 1659 | // w4 string_encoding Latin1 or UC16 |
| 1660 | // w5 sliced_string_offset if the string is a SlicedString |
| 1661 | // offset to the underlying string |
| 1662 | // w6 string_representation groups attributes of the string: |
| 1663 | // - is a string |
| 1664 | // - type of the string |
| 1665 | // - is a short external string |
| 1666 | Register string_type = w0; |
| 1667 | Register jsstring_length = x2; |
| 1668 | Register jsregexp_object = x3; |
| 1669 | Register string_encoding = w4; |
| 1670 | Register sliced_string_offset = w5; |
| 1671 | Register string_representation = w6; |
| 1672 | |
| 1673 | // These are in callee save registers and will be preserved by the call |
| 1674 | // to the native RegExp code, as this code is called using the normal |
| 1675 | // C calling convention. When calling directly from generated code the |
| 1676 | // native RegExp code will not do a GC and therefore the content of |
| 1677 | // these registers are safe to use after the call. |
| 1678 | |
| 1679 | // x19 subject subject string |
| 1680 | // x20 regexp_data RegExp data (FixedArray) |
| 1681 | // x21 last_match_info_elements info relative to the last match |
| 1682 | // (FixedArray) |
| 1683 | // x22 code_object generated regexp code |
| 1684 | Register subject = x19; |
| 1685 | Register regexp_data = x20; |
| 1686 | Register last_match_info_elements = x21; |
| 1687 | Register code_object = x22; |
| 1688 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1689 | // Stack frame. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1690 | // jssp[00]: last_match_info (JSArray) |
| 1691 | // jssp[08]: previous index |
| 1692 | // jssp[16]: subject string |
| 1693 | // jssp[24]: JSRegExp object |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1694 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1695 | const int kLastMatchInfoOffset = 0 * kPointerSize; |
| 1696 | const int kPreviousIndexOffset = 1 * kPointerSize; |
| 1697 | const int kSubjectOffset = 2 * kPointerSize; |
| 1698 | const int kJSRegExpOffset = 3 * kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1699 | |
| 1700 | // Ensure that a RegExp stack is allocated. |
| 1701 | ExternalReference address_of_regexp_stack_memory_address = |
| 1702 | ExternalReference::address_of_regexp_stack_memory_address(isolate()); |
| 1703 | ExternalReference address_of_regexp_stack_memory_size = |
| 1704 | ExternalReference::address_of_regexp_stack_memory_size(isolate()); |
| 1705 | __ Mov(x10, address_of_regexp_stack_memory_size); |
| 1706 | __ Ldr(x10, MemOperand(x10)); |
| 1707 | __ Cbz(x10, &runtime); |
| 1708 | |
| 1709 | // Check that the first argument is a JSRegExp object. |
| 1710 | DCHECK(jssp.Is(__ StackPointer())); |
| 1711 | __ Peek(jsregexp_object, kJSRegExpOffset); |
| 1712 | __ JumpIfSmi(jsregexp_object, &runtime); |
| 1713 | __ JumpIfNotObjectType(jsregexp_object, x10, x10, JS_REGEXP_TYPE, &runtime); |
| 1714 | |
| 1715 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 1716 | __ Ldr(regexp_data, FieldMemOperand(jsregexp_object, JSRegExp::kDataOffset)); |
| 1717 | if (FLAG_debug_code) { |
| 1718 | STATIC_ASSERT(kSmiTag == 0); |
| 1719 | __ Tst(regexp_data, kSmiTagMask); |
| 1720 | __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
| 1721 | __ CompareObjectType(regexp_data, x10, x10, FIXED_ARRAY_TYPE); |
| 1722 | __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
| 1723 | } |
| 1724 | |
| 1725 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 1726 | __ Ldr(x10, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset)); |
| 1727 | __ Cmp(x10, Smi::FromInt(JSRegExp::IRREGEXP)); |
| 1728 | __ B(ne, &runtime); |
| 1729 | |
| 1730 | // Check that the number of captures fit in the static offsets vector buffer. |
| 1731 | // We have always at least one capture for the whole match, plus additional |
| 1732 | // ones due to capturing parentheses. A capture takes 2 registers. |
| 1733 | // The number of capture registers then is (number_of_captures + 1) * 2. |
| 1734 | __ Ldrsw(x10, |
| 1735 | UntagSmiFieldMemOperand(regexp_data, |
| 1736 | JSRegExp::kIrregexpCaptureCountOffset)); |
| 1737 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 1738 | // number_of_captures * 2 <= offsets vector size - 2 |
| 1739 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 1740 | __ Add(x10, x10, x10); |
| 1741 | __ Cmp(x10, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
| 1742 | __ B(hi, &runtime); |
| 1743 | |
| 1744 | // Initialize offset for possibly sliced string. |
| 1745 | __ Mov(sliced_string_offset, 0); |
| 1746 | |
| 1747 | DCHECK(jssp.Is(__ StackPointer())); |
| 1748 | __ Peek(subject, kSubjectOffset); |
| 1749 | __ JumpIfSmi(subject, &runtime); |
| 1750 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1751 | __ Ldr(jsstring_length, FieldMemOperand(subject, String::kLengthOffset)); |
| 1752 | |
| 1753 | // Handle subject string according to its encoding and representation: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1754 | // (1) Sequential string? If yes, go to (4). |
| 1755 | // (2) Sequential or cons? If not, go to (5). |
| 1756 | // (3) Cons string. If the string is flat, replace subject with first string |
| 1757 | // and go to (1). Otherwise bail out to runtime. |
| 1758 | // (4) Sequential string. Load regexp code according to encoding. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1759 | // (E) Carry on. |
| 1760 | /// [...] |
| 1761 | |
| 1762 | // Deferred code at the end of the stub: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1763 | // (5) Long external string? If not, go to (7). |
| 1764 | // (6) External string. Make it, offset-wise, look like a sequential string. |
| 1765 | // Go to (4). |
| 1766 | // (7) Short external string or not a string? If yes, bail out to runtime. |
| 1767 | // (8) Sliced string. Replace subject with parent. Go to (1). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1768 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1769 | Label check_underlying; // (1) |
| 1770 | Label seq_string; // (4) |
| 1771 | Label not_seq_nor_cons; // (5) |
| 1772 | Label external_string; // (6) |
| 1773 | Label not_long_external; // (7) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1774 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1775 | __ Bind(&check_underlying); |
| 1776 | __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 1777 | __ Ldrb(string_type, FieldMemOperand(x10, Map::kInstanceTypeOffset)); |
| 1778 | |
| 1779 | // (1) Sequential string? If yes, go to (4). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1780 | __ And(string_representation, |
| 1781 | string_type, |
| 1782 | kIsNotStringMask | |
| 1783 | kStringRepresentationMask | |
| 1784 | kShortExternalStringMask); |
| 1785 | // We depend on the fact that Strings of type |
| 1786 | // SeqString and not ShortExternalString are defined |
| 1787 | // by the following pattern: |
| 1788 | // string_type: 0XX0 XX00 |
| 1789 | // ^ ^ ^^ |
| 1790 | // | | || |
| 1791 | // | | is a SeqString |
| 1792 | // | is not a short external String |
| 1793 | // is a String |
| 1794 | STATIC_ASSERT((kStringTag | kSeqStringTag) == 0); |
| 1795 | STATIC_ASSERT(kShortExternalStringTag != 0); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1796 | __ Cbz(string_representation, &seq_string); // Go to (4). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1797 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1798 | // (2) Sequential or cons? If not, go to (5). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1799 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 1800 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
| 1801 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 1802 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
| 1803 | __ Cmp(string_representation, kExternalStringTag); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1804 | __ B(ge, ¬_seq_nor_cons); // Go to (5). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1805 | |
| 1806 | // (3) Cons string. Check that it's flat. |
| 1807 | __ Ldr(x10, FieldMemOperand(subject, ConsString::kSecondOffset)); |
| 1808 | __ JumpIfNotRoot(x10, Heap::kempty_stringRootIndex, &runtime); |
| 1809 | // Replace subject with first string. |
| 1810 | __ Ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1811 | __ B(&check_underlying); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1812 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1813 | // (4) Sequential string. Load regexp code according to encoding. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1814 | __ Bind(&seq_string); |
| 1815 | |
| 1816 | // Check that the third argument is a positive smi less than the subject |
| 1817 | // string length. A negative value will be greater (unsigned comparison). |
| 1818 | DCHECK(jssp.Is(__ StackPointer())); |
| 1819 | __ Peek(x10, kPreviousIndexOffset); |
| 1820 | __ JumpIfNotSmi(x10, &runtime); |
| 1821 | __ Cmp(jsstring_length, x10); |
| 1822 | __ B(ls, &runtime); |
| 1823 | |
| 1824 | // Argument 2 (x1): We need to load argument 2 (the previous index) into x1 |
| 1825 | // before entering the exit frame. |
| 1826 | __ SmiUntag(x1, x10); |
| 1827 | |
| 1828 | // The third bit determines the string encoding in string_type. |
| 1829 | STATIC_ASSERT(kOneByteStringTag == 0x04); |
| 1830 | STATIC_ASSERT(kTwoByteStringTag == 0x00); |
| 1831 | STATIC_ASSERT(kStringEncodingMask == 0x04); |
| 1832 | |
| 1833 | // Find the code object based on the assumptions above. |
| 1834 | // kDataOneByteCodeOffset and kDataUC16CodeOffset are adjacent, adds an offset |
| 1835 | // of kPointerSize to reach the latter. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1836 | STATIC_ASSERT(JSRegExp::kDataOneByteCodeOffset + kPointerSize == |
| 1837 | JSRegExp::kDataUC16CodeOffset); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1838 | __ Mov(x10, kPointerSize); |
| 1839 | // We will need the encoding later: Latin1 = 0x04 |
| 1840 | // UC16 = 0x00 |
| 1841 | __ Ands(string_encoding, string_type, kStringEncodingMask); |
| 1842 | __ CzeroX(x10, ne); |
| 1843 | __ Add(x10, regexp_data, x10); |
| 1844 | __ Ldr(code_object, FieldMemOperand(x10, JSRegExp::kDataOneByteCodeOffset)); |
| 1845 | |
| 1846 | // (E) Carry on. String handling is done. |
| 1847 | |
| 1848 | // Check that the irregexp code has been generated for the actual string |
| 1849 | // encoding. If it has, the field contains a code object otherwise it contains |
| 1850 | // a smi (code flushing support). |
| 1851 | __ JumpIfSmi(code_object, &runtime); |
| 1852 | |
| 1853 | // All checks done. Now push arguments for native regexp code. |
| 1854 | __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1, |
| 1855 | x10, |
| 1856 | x11); |
| 1857 | |
| 1858 | // Isolates: note we add an additional parameter here (isolate pointer). |
| 1859 | __ EnterExitFrame(false, x10, 1); |
| 1860 | DCHECK(csp.Is(__ StackPointer())); |
| 1861 | |
| 1862 | // We have 9 arguments to pass to the regexp code, therefore we have to pass |
| 1863 | // one on the stack and the rest as registers. |
| 1864 | |
| 1865 | // Note that the placement of the argument on the stack isn't standard |
| 1866 | // AAPCS64: |
| 1867 | // csp[0]: Space for the return address placed by DirectCEntryStub. |
| 1868 | // csp[8]: Argument 9, the current isolate address. |
| 1869 | |
| 1870 | __ Mov(x10, ExternalReference::isolate_address(isolate())); |
| 1871 | __ Poke(x10, kPointerSize); |
| 1872 | |
| 1873 | Register length = w11; |
| 1874 | Register previous_index_in_bytes = w12; |
| 1875 | Register start = x13; |
| 1876 | |
| 1877 | // Load start of the subject string. |
| 1878 | __ Add(start, subject, SeqString::kHeaderSize - kHeapObjectTag); |
| 1879 | // Load the length from the original subject string from the previous stack |
| 1880 | // frame. Therefore we have to use fp, which points exactly to two pointer |
| 1881 | // sizes below the previous sp. (Because creating a new stack frame pushes |
| 1882 | // the previous fp onto the stack and decrements sp by 2 * kPointerSize.) |
| 1883 | __ Ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize)); |
| 1884 | __ Ldr(length, UntagSmiFieldMemOperand(subject, String::kLengthOffset)); |
| 1885 | |
| 1886 | // Handle UC16 encoding, two bytes make one character. |
| 1887 | // string_encoding: if Latin1: 0x04 |
| 1888 | // if UC16: 0x00 |
| 1889 | STATIC_ASSERT(kStringEncodingMask == 0x04); |
| 1890 | __ Ubfx(string_encoding, string_encoding, 2, 1); |
| 1891 | __ Eor(string_encoding, string_encoding, 1); |
| 1892 | // string_encoding: if Latin1: 0 |
| 1893 | // if UC16: 1 |
| 1894 | |
| 1895 | // Convert string positions from characters to bytes. |
| 1896 | // Previous index is in x1. |
| 1897 | __ Lsl(previous_index_in_bytes, w1, string_encoding); |
| 1898 | __ Lsl(length, length, string_encoding); |
| 1899 | __ Lsl(sliced_string_offset, sliced_string_offset, string_encoding); |
| 1900 | |
| 1901 | // Argument 1 (x0): Subject string. |
| 1902 | __ Mov(x0, subject); |
| 1903 | |
| 1904 | // Argument 2 (x1): Previous index, already there. |
| 1905 | |
| 1906 | // Argument 3 (x2): Get the start of input. |
| 1907 | // Start of input = start of string + previous index + substring offset |
| 1908 | // (0 if the string |
| 1909 | // is not sliced). |
| 1910 | __ Add(w10, previous_index_in_bytes, sliced_string_offset); |
| 1911 | __ Add(x2, start, Operand(w10, UXTW)); |
| 1912 | |
| 1913 | // Argument 4 (x3): |
| 1914 | // End of input = start of input + (length of input - previous index) |
| 1915 | __ Sub(w10, length, previous_index_in_bytes); |
| 1916 | __ Add(x3, x2, Operand(w10, UXTW)); |
| 1917 | |
| 1918 | // Argument 5 (x4): static offsets vector buffer. |
| 1919 | __ Mov(x4, ExternalReference::address_of_static_offsets_vector(isolate())); |
| 1920 | |
| 1921 | // Argument 6 (x5): Set the number of capture registers to zero to force |
| 1922 | // global regexps to behave as non-global. This stub is not used for global |
| 1923 | // regexps. |
| 1924 | __ Mov(x5, 0); |
| 1925 | |
| 1926 | // Argument 7 (x6): Start (high end) of backtracking stack memory area. |
| 1927 | __ Mov(x10, address_of_regexp_stack_memory_address); |
| 1928 | __ Ldr(x10, MemOperand(x10)); |
| 1929 | __ Mov(x11, address_of_regexp_stack_memory_size); |
| 1930 | __ Ldr(x11, MemOperand(x11)); |
| 1931 | __ Add(x6, x10, x11); |
| 1932 | |
| 1933 | // Argument 8 (x7): Indicate that this is a direct call from JavaScript. |
| 1934 | __ Mov(x7, 1); |
| 1935 | |
| 1936 | // Locate the code entry and call it. |
| 1937 | __ Add(code_object, code_object, Code::kHeaderSize - kHeapObjectTag); |
| 1938 | DirectCEntryStub stub(isolate()); |
| 1939 | stub.GenerateCall(masm, code_object); |
| 1940 | |
| 1941 | __ LeaveExitFrame(false, x10, true); |
| 1942 | |
| 1943 | // The generated regexp code returns an int32 in w0. |
| 1944 | Label failure, exception; |
| 1945 | __ CompareAndBranch(w0, NativeRegExpMacroAssembler::FAILURE, eq, &failure); |
| 1946 | __ CompareAndBranch(w0, |
| 1947 | NativeRegExpMacroAssembler::EXCEPTION, |
| 1948 | eq, |
| 1949 | &exception); |
| 1950 | __ CompareAndBranch(w0, NativeRegExpMacroAssembler::RETRY, eq, &runtime); |
| 1951 | |
| 1952 | // Success: process the result from the native regexp code. |
| 1953 | Register number_of_capture_registers = x12; |
| 1954 | |
| 1955 | // Calculate number of capture registers (number_of_captures + 1) * 2 |
| 1956 | // and store it in the last match info. |
| 1957 | __ Ldrsw(x10, |
| 1958 | UntagSmiFieldMemOperand(regexp_data, |
| 1959 | JSRegExp::kIrregexpCaptureCountOffset)); |
| 1960 | __ Add(x10, x10, x10); |
| 1961 | __ Add(number_of_capture_registers, x10, 2); |
| 1962 | |
| 1963 | // Check that the fourth object is a JSArray object. |
| 1964 | DCHECK(jssp.Is(__ StackPointer())); |
| 1965 | __ Peek(x10, kLastMatchInfoOffset); |
| 1966 | __ JumpIfSmi(x10, &runtime); |
| 1967 | __ JumpIfNotObjectType(x10, x11, x11, JS_ARRAY_TYPE, &runtime); |
| 1968 | |
| 1969 | // Check that the JSArray is the fast case. |
| 1970 | __ Ldr(last_match_info_elements, |
| 1971 | FieldMemOperand(x10, JSArray::kElementsOffset)); |
| 1972 | __ Ldr(x10, |
| 1973 | FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset)); |
| 1974 | __ JumpIfNotRoot(x10, Heap::kFixedArrayMapRootIndex, &runtime); |
| 1975 | |
| 1976 | // Check that the last match info has space for the capture registers and the |
| 1977 | // additional information (overhead). |
| 1978 | // (number_of_captures + 1) * 2 + overhead <= last match info size |
| 1979 | // (number_of_captures * 2) + 2 + overhead <= last match info size |
| 1980 | // number_of_capture_registers + overhead <= last match info size |
| 1981 | __ Ldrsw(x10, |
| 1982 | UntagSmiFieldMemOperand(last_match_info_elements, |
| 1983 | FixedArray::kLengthOffset)); |
| 1984 | __ Add(x11, number_of_capture_registers, RegExpImpl::kLastMatchOverhead); |
| 1985 | __ Cmp(x11, x10); |
| 1986 | __ B(gt, &runtime); |
| 1987 | |
| 1988 | // Store the capture count. |
| 1989 | __ SmiTag(x10, number_of_capture_registers); |
| 1990 | __ Str(x10, |
| 1991 | FieldMemOperand(last_match_info_elements, |
| 1992 | RegExpImpl::kLastCaptureCountOffset)); |
| 1993 | // Store last subject and last input. |
| 1994 | __ Str(subject, |
| 1995 | FieldMemOperand(last_match_info_elements, |
| 1996 | RegExpImpl::kLastSubjectOffset)); |
| 1997 | // Use x10 as the subject string in order to only need |
| 1998 | // one RecordWriteStub. |
| 1999 | __ Mov(x10, subject); |
| 2000 | __ RecordWriteField(last_match_info_elements, |
| 2001 | RegExpImpl::kLastSubjectOffset, |
| 2002 | x10, |
| 2003 | x11, |
| 2004 | kLRHasNotBeenSaved, |
| 2005 | kDontSaveFPRegs); |
| 2006 | __ Str(subject, |
| 2007 | FieldMemOperand(last_match_info_elements, |
| 2008 | RegExpImpl::kLastInputOffset)); |
| 2009 | __ Mov(x10, subject); |
| 2010 | __ RecordWriteField(last_match_info_elements, |
| 2011 | RegExpImpl::kLastInputOffset, |
| 2012 | x10, |
| 2013 | x11, |
| 2014 | kLRHasNotBeenSaved, |
| 2015 | kDontSaveFPRegs); |
| 2016 | |
| 2017 | Register last_match_offsets = x13; |
| 2018 | Register offsets_vector_index = x14; |
| 2019 | Register current_offset = x15; |
| 2020 | |
| 2021 | // Get the static offsets vector filled by the native regexp code |
| 2022 | // and fill the last match info. |
| 2023 | ExternalReference address_of_static_offsets_vector = |
| 2024 | ExternalReference::address_of_static_offsets_vector(isolate()); |
| 2025 | __ Mov(offsets_vector_index, address_of_static_offsets_vector); |
| 2026 | |
| 2027 | Label next_capture, done; |
| 2028 | // Capture register counter starts from number of capture registers and |
| 2029 | // iterates down to zero (inclusive). |
| 2030 | __ Add(last_match_offsets, |
| 2031 | last_match_info_elements, |
| 2032 | RegExpImpl::kFirstCaptureOffset - kHeapObjectTag); |
| 2033 | __ Bind(&next_capture); |
| 2034 | __ Subs(number_of_capture_registers, number_of_capture_registers, 2); |
| 2035 | __ B(mi, &done); |
| 2036 | // Read two 32 bit values from the static offsets vector buffer into |
| 2037 | // an X register |
| 2038 | __ Ldr(current_offset, |
| 2039 | MemOperand(offsets_vector_index, kWRegSize * 2, PostIndex)); |
| 2040 | // Store the smi values in the last match info. |
| 2041 | __ SmiTag(x10, current_offset); |
| 2042 | // Clearing the 32 bottom bits gives us a Smi. |
| 2043 | STATIC_ASSERT(kSmiTag == 0); |
| 2044 | __ Bic(x11, current_offset, kSmiShiftMask); |
| 2045 | __ Stp(x10, |
| 2046 | x11, |
| 2047 | MemOperand(last_match_offsets, kXRegSize * 2, PostIndex)); |
| 2048 | __ B(&next_capture); |
| 2049 | __ Bind(&done); |
| 2050 | |
| 2051 | // Return last match info. |
| 2052 | __ Peek(x0, kLastMatchInfoOffset); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2053 | // Drop the 4 arguments of the stub from the stack. |
| 2054 | __ Drop(4); |
| 2055 | __ Ret(); |
| 2056 | |
| 2057 | __ Bind(&exception); |
| 2058 | Register exception_value = x0; |
| 2059 | // A stack overflow (on the backtrack stack) may have occured |
| 2060 | // in the RegExp code but no exception has been created yet. |
| 2061 | // If there is no pending exception, handle that in the runtime system. |
| 2062 | __ Mov(x10, Operand(isolate()->factory()->the_hole_value())); |
| 2063 | __ Mov(x11, |
| 2064 | Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
| 2065 | isolate()))); |
| 2066 | __ Ldr(exception_value, MemOperand(x11)); |
| 2067 | __ Cmp(x10, exception_value); |
| 2068 | __ B(eq, &runtime); |
| 2069 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2070 | // For exception, throw the exception again. |
| 2071 | __ TailCallRuntime(Runtime::kRegExpExecReThrow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2072 | |
| 2073 | __ Bind(&failure); |
| 2074 | __ Mov(x0, Operand(isolate()->factory()->null_value())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2075 | // Drop the 4 arguments of the stub from the stack. |
| 2076 | __ Drop(4); |
| 2077 | __ Ret(); |
| 2078 | |
| 2079 | __ Bind(&runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2080 | __ TailCallRuntime(Runtime::kRegExpExec); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2081 | |
| 2082 | // Deferred code for string handling. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2083 | // (5) Long external string? If not, go to (7). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2084 | __ Bind(¬_seq_nor_cons); |
| 2085 | // Compare flags are still set. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2086 | __ B(ne, ¬_long_external); // Go to (7). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2087 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2088 | // (6) External string. Make it, offset-wise, look like a sequential string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2089 | __ Bind(&external_string); |
| 2090 | if (masm->emit_debug_code()) { |
| 2091 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 2092 | // Sequential strings have already been ruled out. |
| 2093 | __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 2094 | __ Ldrb(x10, FieldMemOperand(x10, Map::kInstanceTypeOffset)); |
| 2095 | __ Tst(x10, kIsIndirectStringMask); |
| 2096 | __ Check(eq, kExternalStringExpectedButNotFound); |
| 2097 | __ And(x10, x10, kStringRepresentationMask); |
| 2098 | __ Cmp(x10, 0); |
| 2099 | __ Check(ne, kExternalStringExpectedButNotFound); |
| 2100 | } |
| 2101 | __ Ldr(subject, |
| 2102 | FieldMemOperand(subject, ExternalString::kResourceDataOffset)); |
| 2103 | // Move the pointer so that offset-wise, it looks like a sequential string. |
| 2104 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
| 2105 | __ Sub(subject, subject, SeqTwoByteString::kHeaderSize - kHeapObjectTag); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2106 | __ B(&seq_string); // Go to (4). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2107 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2108 | // (7) If this is a short external string or not a string, bail out to |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2109 | // runtime. |
| 2110 | __ Bind(¬_long_external); |
| 2111 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 2112 | __ TestAndBranchIfAnySet(string_representation, |
| 2113 | kShortExternalStringMask | kIsNotStringMask, |
| 2114 | &runtime); |
| 2115 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2116 | // (8) Sliced string. Replace subject with parent. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2117 | __ Ldr(sliced_string_offset, |
| 2118 | UntagSmiFieldMemOperand(subject, SlicedString::kOffsetOffset)); |
| 2119 | __ Ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2120 | __ B(&check_underlying); // Go to (1). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2121 | #endif |
| 2122 | } |
| 2123 | |
| 2124 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2125 | static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub, |
| 2126 | Register argc, Register function, |
| 2127 | Register feedback_vector, Register index, |
| 2128 | Register new_target) { |
| 2129 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2130 | |
| 2131 | // Number-of-arguments register must be smi-tagged to call out. |
| 2132 | __ SmiTag(argc); |
| 2133 | __ Push(argc, function, feedback_vector, index); |
| 2134 | |
| 2135 | DCHECK(feedback_vector.Is(x2) && index.Is(x3)); |
| 2136 | __ CallStub(stub); |
| 2137 | |
| 2138 | __ Pop(index, feedback_vector, function, argc); |
| 2139 | __ SmiUntag(argc); |
| 2140 | } |
| 2141 | |
| 2142 | |
| 2143 | static void GenerateRecordCallTarget(MacroAssembler* masm, Register argc, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2144 | Register function, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2145 | Register feedback_vector, Register index, |
| 2146 | Register new_target, Register scratch1, |
| 2147 | Register scratch2, Register scratch3) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2148 | ASM_LOCATION("GenerateRecordCallTarget"); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2149 | DCHECK(!AreAliased(scratch1, scratch2, scratch3, argc, function, |
| 2150 | feedback_vector, index, new_target)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2151 | // Cache the called function in a feedback vector slot. Cache states are |
| 2152 | // uninitialized, monomorphic (indicated by a JSFunction), and megamorphic. |
| 2153 | // argc : number of arguments to the construct function |
| 2154 | // function : the function to call |
| 2155 | // feedback_vector : the feedback vector |
| 2156 | // index : slot in feedback vector (smi) |
| 2157 | Label initialize, done, miss, megamorphic, not_array_function; |
| 2158 | |
| 2159 | DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()), |
| 2160 | masm->isolate()->heap()->megamorphic_symbol()); |
| 2161 | DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()), |
| 2162 | masm->isolate()->heap()->uninitialized_symbol()); |
| 2163 | |
| 2164 | // Load the cache state. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2165 | Register feedback = scratch1; |
| 2166 | Register feedback_map = scratch2; |
| 2167 | Register feedback_value = scratch3; |
| 2168 | __ Add(feedback, feedback_vector, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2169 | Operand::UntagSmiAndScale(index, kPointerSizeLog2)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2170 | __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2171 | |
| 2172 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 2173 | // function without changing the state. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2174 | // We don't know if feedback value is a WeakCell or a Symbol, but it's |
| 2175 | // harmless to read at this position in a symbol (see static asserts in |
| 2176 | // type-feedback-vector.h). |
| 2177 | Label check_allocation_site; |
| 2178 | __ Ldr(feedback_value, FieldMemOperand(feedback, WeakCell::kValueOffset)); |
| 2179 | __ Cmp(function, feedback_value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2180 | __ B(eq, &done); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2181 | __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex); |
| 2182 | __ B(eq, &done); |
| 2183 | __ Ldr(feedback_map, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 2184 | __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex); |
| 2185 | __ B(ne, &check_allocation_site); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2186 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2187 | // If the weak cell is cleared, we have a new chance to become monomorphic. |
| 2188 | __ JumpIfSmi(feedback_value, &initialize); |
| 2189 | __ B(&megamorphic); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2190 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2191 | __ bind(&check_allocation_site); |
| 2192 | // If we came here, we need to see if we are the array function. |
| 2193 | // If we didn't have a matching function, and we didn't find the megamorph |
| 2194 | // sentinel, then we have in the slot either some other function or an |
| 2195 | // AllocationSite. |
| 2196 | __ JumpIfNotRoot(feedback_map, Heap::kAllocationSiteMapRootIndex, &miss); |
| 2197 | |
| 2198 | // Make sure the function is the Array() function |
| 2199 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, scratch1); |
| 2200 | __ Cmp(function, scratch1); |
| 2201 | __ B(ne, &megamorphic); |
| 2202 | __ B(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2203 | |
| 2204 | __ Bind(&miss); |
| 2205 | |
| 2206 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 2207 | // megamorphic. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2208 | __ JumpIfRoot(scratch1, Heap::kuninitialized_symbolRootIndex, &initialize); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2209 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 2210 | // write-barrier is needed. |
| 2211 | __ Bind(&megamorphic); |
| 2212 | __ Add(scratch1, feedback_vector, |
| 2213 | Operand::UntagSmiAndScale(index, kPointerSizeLog2)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2214 | __ LoadRoot(scratch2, Heap::kmegamorphic_symbolRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2215 | __ Str(scratch2, FieldMemOperand(scratch1, FixedArray::kHeaderSize)); |
| 2216 | __ B(&done); |
| 2217 | |
| 2218 | // An uninitialized cache is patched with the function or sentinel to |
| 2219 | // indicate the ElementsKind if function is the Array constructor. |
| 2220 | __ Bind(&initialize); |
| 2221 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2222 | // Make sure the function is the Array() function |
| 2223 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, scratch1); |
| 2224 | __ Cmp(function, scratch1); |
| 2225 | __ B(ne, ¬_array_function); |
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 | // The target function is the Array constructor, |
| 2228 | // Create an AllocationSite if we don't already have it, store it in the |
| 2229 | // slot. |
| 2230 | CreateAllocationSiteStub create_stub(masm->isolate()); |
| 2231 | CallStubInRecordCallTarget(masm, &create_stub, argc, function, |
| 2232 | feedback_vector, index, new_target); |
| 2233 | __ B(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2234 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2235 | __ Bind(¬_array_function); |
| 2236 | CreateWeakCellStub weak_cell_stub(masm->isolate()); |
| 2237 | CallStubInRecordCallTarget(masm, &weak_cell_stub, argc, function, |
| 2238 | feedback_vector, index, new_target); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2239 | __ Bind(&done); |
| 2240 | } |
| 2241 | |
| 2242 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2243 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 2244 | ASM_LOCATION("CallConstructStub::Generate"); |
| 2245 | // x0 : number of arguments |
| 2246 | // x1 : the function to call |
| 2247 | // x2 : feedback vector |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2248 | // x3 : slot in feedback vector (Smi, for RecordCallTarget) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2249 | Register function = x1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2250 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2251 | Label non_function; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2252 | // Check that the function is not a smi. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2253 | __ JumpIfSmi(function, &non_function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2254 | // Check that the function is a JSFunction. |
| 2255 | Register object_type = x10; |
| 2256 | __ JumpIfNotObjectType(function, object_type, object_type, JS_FUNCTION_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2257 | &non_function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2258 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2259 | GenerateRecordCallTarget(masm, x0, function, x2, x3, x4, x5, x11, x12); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2260 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2261 | __ Add(x5, x2, Operand::UntagSmiAndScale(x3, kPointerSizeLog2)); |
| 2262 | Label feedback_register_initialized; |
| 2263 | // Put the AllocationSite from the feedback vector into x2, or undefined. |
| 2264 | __ Ldr(x2, FieldMemOperand(x5, FixedArray::kHeaderSize)); |
| 2265 | __ Ldr(x5, FieldMemOperand(x2, AllocationSite::kMapOffset)); |
| 2266 | __ JumpIfRoot(x5, Heap::kAllocationSiteMapRootIndex, |
| 2267 | &feedback_register_initialized); |
| 2268 | __ LoadRoot(x2, Heap::kUndefinedValueRootIndex); |
| 2269 | __ bind(&feedback_register_initialized); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2270 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2271 | __ AssertUndefinedOrAllocationSite(x2, x5); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2272 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2273 | __ Mov(x3, function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2274 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2275 | // Tail call to the function-specific construct stub (still in the caller |
| 2276 | // context at this point). |
| 2277 | __ Ldr(x4, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset)); |
| 2278 | __ Ldr(x4, FieldMemOperand(x4, SharedFunctionInfo::kConstructStubOffset)); |
| 2279 | __ Add(x4, x4, Code::kHeaderSize - kHeapObjectTag); |
| 2280 | __ Br(x4); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2281 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2282 | __ Bind(&non_function); |
| 2283 | __ Mov(x3, function); |
| 2284 | __ Jump(isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2288 | void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2289 | // x1 - function |
| 2290 | // x3 - slot id |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2291 | // x2 - vector |
| 2292 | // x4 - allocation site (loaded from vector[slot]) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2293 | Register function = x1; |
| 2294 | Register feedback_vector = x2; |
| 2295 | Register index = x3; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2296 | Register allocation_site = x4; |
| 2297 | Register scratch = x5; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2298 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2299 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2300 | __ Cmp(function, scratch); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2301 | __ B(ne, miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2302 | |
| 2303 | __ Mov(x0, Operand(arg_count())); |
| 2304 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2305 | // Increment the call count for monomorphic function calls. |
| 2306 | __ Add(feedback_vector, feedback_vector, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2307 | Operand::UntagSmiAndScale(index, kPointerSizeLog2)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2308 | __ Add(feedback_vector, feedback_vector, |
| 2309 | Operand(FixedArray::kHeaderSize + kPointerSize)); |
| 2310 | __ Ldr(index, FieldMemOperand(feedback_vector, 0)); |
| 2311 | __ Add(index, index, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement))); |
| 2312 | __ Str(index, FieldMemOperand(feedback_vector, 0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2313 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2314 | // Set up arguments for the array constructor stub. |
| 2315 | Register allocation_site_arg = feedback_vector; |
| 2316 | Register new_target_arg = index; |
| 2317 | __ Mov(allocation_site_arg, allocation_site); |
| 2318 | __ Mov(new_target_arg, function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2319 | ArrayConstructorStub stub(masm->isolate(), arg_count()); |
| 2320 | __ TailCallStub(&stub); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | |
| 2324 | void CallICStub::Generate(MacroAssembler* masm) { |
| 2325 | ASM_LOCATION("CallICStub"); |
| 2326 | |
| 2327 | // x1 - function |
| 2328 | // x3 - slot id (Smi) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2329 | // x2 - vector |
| 2330 | Label extra_checks_or_miss, call, call_function; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2331 | int argc = arg_count(); |
| 2332 | ParameterCount actual(argc); |
| 2333 | |
| 2334 | Register function = x1; |
| 2335 | Register feedback_vector = x2; |
| 2336 | Register index = x3; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2337 | |
| 2338 | // The checks. First, does x1 match the recorded monomorphic target? |
| 2339 | __ Add(x4, feedback_vector, |
| 2340 | Operand::UntagSmiAndScale(index, kPointerSizeLog2)); |
| 2341 | __ Ldr(x4, FieldMemOperand(x4, FixedArray::kHeaderSize)); |
| 2342 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2343 | // We don't know that we have a weak cell. We might have a private symbol |
| 2344 | // or an AllocationSite, but the memory is safe to examine. |
| 2345 | // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to |
| 2346 | // FixedArray. |
| 2347 | // WeakCell::kValueOffset - contains a JSFunction or Smi(0) |
| 2348 | // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not |
| 2349 | // computed, meaning that it can't appear to be a pointer. If the low bit is |
| 2350 | // 0, then hash is computed, but the 0 bit prevents the field from appearing |
| 2351 | // to be a pointer. |
| 2352 | STATIC_ASSERT(WeakCell::kSize >= kPointerSize); |
| 2353 | STATIC_ASSERT(AllocationSite::kTransitionInfoOffset == |
| 2354 | WeakCell::kValueOffset && |
| 2355 | WeakCell::kValueOffset == Symbol::kHashFieldSlot); |
| 2356 | |
| 2357 | __ Ldr(x5, FieldMemOperand(x4, WeakCell::kValueOffset)); |
| 2358 | __ Cmp(x5, function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2359 | __ B(ne, &extra_checks_or_miss); |
| 2360 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2361 | // The compare above could have been a SMI/SMI comparison. Guard against this |
| 2362 | // convincing us that we have a monomorphic JSFunction. |
| 2363 | __ JumpIfSmi(function, &extra_checks_or_miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2364 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2365 | // Increment the call count for monomorphic function calls. |
| 2366 | __ Add(feedback_vector, feedback_vector, |
| 2367 | Operand::UntagSmiAndScale(index, kPointerSizeLog2)); |
| 2368 | __ Add(feedback_vector, feedback_vector, |
| 2369 | Operand(FixedArray::kHeaderSize + kPointerSize)); |
| 2370 | __ Ldr(index, FieldMemOperand(feedback_vector, 0)); |
| 2371 | __ Add(index, index, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement))); |
| 2372 | __ Str(index, FieldMemOperand(feedback_vector, 0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2373 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2374 | __ Bind(&call_function); |
| 2375 | __ Mov(x0, argc); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2376 | __ Jump(masm->isolate()->builtins()->CallFunction(convert_mode(), |
| 2377 | tail_call_mode()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2378 | RelocInfo::CODE_TARGET); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2379 | |
| 2380 | __ bind(&extra_checks_or_miss); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2381 | Label uninitialized, miss, not_allocation_site; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2382 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2383 | __ JumpIfRoot(x4, Heap::kmegamorphic_symbolRootIndex, &call); |
| 2384 | |
| 2385 | __ Ldr(x5, FieldMemOperand(x4, HeapObject::kMapOffset)); |
| 2386 | __ JumpIfNotRoot(x5, Heap::kAllocationSiteMapRootIndex, ¬_allocation_site); |
| 2387 | |
| 2388 | HandleArrayCase(masm, &miss); |
| 2389 | |
| 2390 | __ bind(¬_allocation_site); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2391 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2392 | // The following cases attempt to handle MISS cases without going to the |
| 2393 | // runtime. |
| 2394 | if (FLAG_trace_ic) { |
| 2395 | __ jmp(&miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2396 | } |
| 2397 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2398 | __ JumpIfRoot(x4, Heap::kuninitialized_symbolRootIndex, &miss); |
| 2399 | |
| 2400 | // We are going megamorphic. If the feedback is a JSFunction, it is fine |
| 2401 | // to handle it here. More complex cases are dealt with in the runtime. |
| 2402 | __ AssertNotSmi(x4); |
| 2403 | __ JumpIfNotObjectType(x4, x5, x5, JS_FUNCTION_TYPE, &miss); |
| 2404 | __ Add(x4, feedback_vector, |
| 2405 | Operand::UntagSmiAndScale(index, kPointerSizeLog2)); |
| 2406 | __ LoadRoot(x5, Heap::kmegamorphic_symbolRootIndex); |
| 2407 | __ Str(x5, FieldMemOperand(x4, FixedArray::kHeaderSize)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2408 | |
| 2409 | __ Bind(&call); |
| 2410 | __ Mov(x0, argc); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2411 | __ Jump(masm->isolate()->builtins()->Call(convert_mode(), tail_call_mode()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2412 | RelocInfo::CODE_TARGET); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2413 | |
| 2414 | __ bind(&uninitialized); |
| 2415 | |
| 2416 | // We are going monomorphic, provided we actually have a JSFunction. |
| 2417 | __ JumpIfSmi(function, &miss); |
| 2418 | |
| 2419 | // Goto miss case if we do not have a function. |
| 2420 | __ JumpIfNotObjectType(function, x5, x5, JS_FUNCTION_TYPE, &miss); |
| 2421 | |
| 2422 | // Make sure the function is not the Array() function, which requires special |
| 2423 | // behavior on MISS. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2424 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, x5); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2425 | __ Cmp(function, x5); |
| 2426 | __ B(eq, &miss); |
| 2427 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2428 | // Make sure the function belongs to the same native context. |
| 2429 | __ Ldr(x4, FieldMemOperand(function, JSFunction::kContextOffset)); |
| 2430 | __ Ldr(x4, ContextMemOperand(x4, Context::NATIVE_CONTEXT_INDEX)); |
| 2431 | __ Ldr(x5, NativeContextMemOperand()); |
| 2432 | __ Cmp(x4, x5); |
| 2433 | __ B(ne, &miss); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2434 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2435 | // Initialize the call counter. |
| 2436 | __ Mov(x5, Smi::FromInt(CallICNexus::kCallCountIncrement)); |
| 2437 | __ Adds(x4, feedback_vector, |
| 2438 | Operand::UntagSmiAndScale(index, kPointerSizeLog2)); |
| 2439 | __ Str(x5, FieldMemOperand(x4, FixedArray::kHeaderSize + kPointerSize)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2440 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2441 | // Store the function. Use a stub since we need a frame for allocation. |
| 2442 | // x2 - vector |
| 2443 | // x3 - slot |
| 2444 | // x1 - function |
| 2445 | { |
| 2446 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2447 | CreateWeakCellStub create_stub(masm->isolate()); |
| 2448 | __ Push(function); |
| 2449 | __ CallStub(&create_stub); |
| 2450 | __ Pop(function); |
| 2451 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2452 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2453 | __ B(&call_function); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2454 | |
| 2455 | // We are here because tracing is on or we encountered a MISS case we can't |
| 2456 | // handle here. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2457 | __ bind(&miss); |
| 2458 | GenerateMiss(masm); |
| 2459 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2460 | __ B(&call); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | |
| 2464 | void CallICStub::GenerateMiss(MacroAssembler* masm) { |
| 2465 | ASM_LOCATION("CallICStub[Miss]"); |
| 2466 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2467 | FrameScope scope(masm, StackFrame::INTERNAL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2468 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2469 | // Push the receiver and the function and feedback info. |
| 2470 | __ Push(x1, x2, x3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2471 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2472 | // Call the entry. |
| 2473 | __ CallRuntime(Runtime::kCallIC_Miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2474 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2475 | // Move result to edi and exit the internal frame. |
| 2476 | __ Mov(x1, x0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | |
| 2480 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 2481 | // If the receiver is a smi trigger the non-string case. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2482 | if (check_mode_ == RECEIVER_IS_UNKNOWN) { |
| 2483 | __ JumpIfSmi(object_, receiver_not_string_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2484 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2485 | // Fetch the instance type of the receiver into result register. |
| 2486 | __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 2487 | __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2488 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2489 | // If the receiver is not a string trigger the non-string case. |
| 2490 | __ TestAndBranchIfAnySet(result_, kIsNotStringMask, receiver_not_string_); |
| 2491 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2492 | |
| 2493 | // If the index is non-smi trigger the non-smi case. |
| 2494 | __ JumpIfNotSmi(index_, &index_not_smi_); |
| 2495 | |
| 2496 | __ Bind(&got_smi_index_); |
| 2497 | // Check for index out of range. |
| 2498 | __ Ldrsw(result_, UntagSmiFieldMemOperand(object_, String::kLengthOffset)); |
| 2499 | __ Cmp(result_, Operand::UntagSmi(index_)); |
| 2500 | __ B(ls, index_out_of_range_); |
| 2501 | |
| 2502 | __ SmiUntag(index_); |
| 2503 | |
| 2504 | StringCharLoadGenerator::Generate(masm, |
| 2505 | object_, |
| 2506 | index_.W(), |
| 2507 | result_, |
| 2508 | &call_runtime_); |
| 2509 | __ SmiTag(result_); |
| 2510 | __ Bind(&exit_); |
| 2511 | } |
| 2512 | |
| 2513 | |
| 2514 | void StringCharCodeAtGenerator::GenerateSlow( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2515 | MacroAssembler* masm, EmbedMode embed_mode, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2516 | const RuntimeCallHelper& call_helper) { |
| 2517 | __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase); |
| 2518 | |
| 2519 | __ Bind(&index_not_smi_); |
| 2520 | // If index is a heap number, try converting it to an integer. |
| 2521 | __ JumpIfNotHeapNumber(index_, index_not_number_); |
| 2522 | call_helper.BeforeCall(masm); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2523 | if (embed_mode == PART_OF_IC_HANDLER) { |
| 2524 | __ Push(LoadWithVectorDescriptor::VectorRegister(), |
| 2525 | LoadWithVectorDescriptor::SlotRegister(), object_, index_); |
| 2526 | } else { |
| 2527 | // Save object_ on the stack and pass index_ as argument for runtime call. |
| 2528 | __ Push(object_, index_); |
| 2529 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2530 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2531 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2532 | } else { |
| 2533 | DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 2534 | // NumberToSmi discards numbers that are not exact integers. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2535 | __ CallRuntime(Runtime::kNumberToSmi); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2536 | } |
| 2537 | // Save the conversion result before the pop instructions below |
| 2538 | // have a chance to overwrite it. |
| 2539 | __ Mov(index_, x0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2540 | if (embed_mode == PART_OF_IC_HANDLER) { |
| 2541 | __ Pop(object_, LoadWithVectorDescriptor::SlotRegister(), |
| 2542 | LoadWithVectorDescriptor::VectorRegister()); |
| 2543 | } else { |
| 2544 | __ Pop(object_); |
| 2545 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2546 | // Reload the instance type. |
| 2547 | __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 2548 | __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 2549 | call_helper.AfterCall(masm); |
| 2550 | |
| 2551 | // If index is still not a smi, it must be out of range. |
| 2552 | __ JumpIfNotSmi(index_, index_out_of_range_); |
| 2553 | // Otherwise, return to the fast path. |
| 2554 | __ B(&got_smi_index_); |
| 2555 | |
| 2556 | // Call runtime. We get here when the receiver is a string and the |
| 2557 | // index is a number, but the code of getting the actual character |
| 2558 | // is too complex (e.g., when the string needs to be flattened). |
| 2559 | __ Bind(&call_runtime_); |
| 2560 | call_helper.BeforeCall(masm); |
| 2561 | __ SmiTag(index_); |
| 2562 | __ Push(object_, index_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2563 | __ CallRuntime(Runtime::kStringCharCodeAtRT); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2564 | __ Mov(result_, x0); |
| 2565 | call_helper.AfterCall(masm); |
| 2566 | __ B(&exit_); |
| 2567 | |
| 2568 | __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase); |
| 2569 | } |
| 2570 | |
| 2571 | |
| 2572 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 2573 | __ JumpIfNotSmi(code_, &slow_case_); |
| 2574 | __ Cmp(code_, Smi::FromInt(String::kMaxOneByteCharCode)); |
| 2575 | __ B(hi, &slow_case_); |
| 2576 | |
| 2577 | __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex); |
| 2578 | // At this point code register contains smi tagged one-byte char code. |
| 2579 | __ Add(result_, result_, Operand::UntagSmiAndScale(code_, kPointerSizeLog2)); |
| 2580 | __ Ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize)); |
| 2581 | __ JumpIfRoot(result_, Heap::kUndefinedValueRootIndex, &slow_case_); |
| 2582 | __ Bind(&exit_); |
| 2583 | } |
| 2584 | |
| 2585 | |
| 2586 | void StringCharFromCodeGenerator::GenerateSlow( |
| 2587 | MacroAssembler* masm, |
| 2588 | const RuntimeCallHelper& call_helper) { |
| 2589 | __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase); |
| 2590 | |
| 2591 | __ Bind(&slow_case_); |
| 2592 | call_helper.BeforeCall(masm); |
| 2593 | __ Push(code_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2594 | __ CallRuntime(Runtime::kStringCharFromCode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2595 | __ Mov(result_, x0); |
| 2596 | call_helper.AfterCall(masm); |
| 2597 | __ B(&exit_); |
| 2598 | |
| 2599 | __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase); |
| 2600 | } |
| 2601 | |
| 2602 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2603 | void CompareICStub::GenerateBooleans(MacroAssembler* masm) { |
| 2604 | // Inputs are in x0 (lhs) and x1 (rhs). |
| 2605 | DCHECK_EQ(CompareICState::BOOLEAN, state()); |
| 2606 | ASM_LOCATION("CompareICStub[Booleans]"); |
| 2607 | Label miss; |
| 2608 | |
| 2609 | __ CheckMap(x1, x2, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK); |
| 2610 | __ CheckMap(x0, x3, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2611 | if (!Token::IsEqualityOp(op())) { |
| 2612 | __ Ldr(x1, FieldMemOperand(x1, Oddball::kToNumberOffset)); |
| 2613 | __ AssertSmi(x1); |
| 2614 | __ Ldr(x0, FieldMemOperand(x0, Oddball::kToNumberOffset)); |
| 2615 | __ AssertSmi(x0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2616 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2617 | __ Sub(x0, x1, x0); |
| 2618 | __ Ret(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2619 | |
| 2620 | __ Bind(&miss); |
| 2621 | GenerateMiss(masm); |
| 2622 | } |
| 2623 | |
| 2624 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2625 | void CompareICStub::GenerateSmis(MacroAssembler* masm) { |
| 2626 | // Inputs are in x0 (lhs) and x1 (rhs). |
| 2627 | DCHECK(state() == CompareICState::SMI); |
| 2628 | ASM_LOCATION("CompareICStub[Smis]"); |
| 2629 | Label miss; |
| 2630 | // Bail out (to 'miss') unless both x0 and x1 are smis. |
| 2631 | __ JumpIfEitherNotSmi(x0, x1, &miss); |
| 2632 | |
| 2633 | if (GetCondition() == eq) { |
| 2634 | // For equality we do not care about the sign of the result. |
| 2635 | __ Sub(x0, x0, x1); |
| 2636 | } else { |
| 2637 | // Untag before subtracting to avoid handling overflow. |
| 2638 | __ SmiUntag(x1); |
| 2639 | __ Sub(x0, x1, Operand::UntagSmi(x0)); |
| 2640 | } |
| 2641 | __ Ret(); |
| 2642 | |
| 2643 | __ Bind(&miss); |
| 2644 | GenerateMiss(masm); |
| 2645 | } |
| 2646 | |
| 2647 | |
| 2648 | void CompareICStub::GenerateNumbers(MacroAssembler* masm) { |
| 2649 | DCHECK(state() == CompareICState::NUMBER); |
| 2650 | ASM_LOCATION("CompareICStub[HeapNumbers]"); |
| 2651 | |
| 2652 | Label unordered, maybe_undefined1, maybe_undefined2; |
| 2653 | Label miss, handle_lhs, values_in_d_regs; |
| 2654 | Label untag_rhs, untag_lhs; |
| 2655 | |
| 2656 | Register result = x0; |
| 2657 | Register rhs = x0; |
| 2658 | Register lhs = x1; |
| 2659 | FPRegister rhs_d = d0; |
| 2660 | FPRegister lhs_d = d1; |
| 2661 | |
| 2662 | if (left() == CompareICState::SMI) { |
| 2663 | __ JumpIfNotSmi(lhs, &miss); |
| 2664 | } |
| 2665 | if (right() == CompareICState::SMI) { |
| 2666 | __ JumpIfNotSmi(rhs, &miss); |
| 2667 | } |
| 2668 | |
| 2669 | __ SmiUntagToDouble(rhs_d, rhs, kSpeculativeUntag); |
| 2670 | __ SmiUntagToDouble(lhs_d, lhs, kSpeculativeUntag); |
| 2671 | |
| 2672 | // Load rhs if it's a heap number. |
| 2673 | __ JumpIfSmi(rhs, &handle_lhs); |
| 2674 | __ JumpIfNotHeapNumber(rhs, &maybe_undefined1); |
| 2675 | __ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 2676 | |
| 2677 | // Load lhs if it's a heap number. |
| 2678 | __ Bind(&handle_lhs); |
| 2679 | __ JumpIfSmi(lhs, &values_in_d_regs); |
| 2680 | __ JumpIfNotHeapNumber(lhs, &maybe_undefined2); |
| 2681 | __ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 2682 | |
| 2683 | __ Bind(&values_in_d_regs); |
| 2684 | __ Fcmp(lhs_d, rhs_d); |
| 2685 | __ B(vs, &unordered); // Overflow flag set if either is NaN. |
| 2686 | STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1)); |
| 2687 | __ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL). |
| 2688 | __ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0. |
| 2689 | __ Ret(); |
| 2690 | |
| 2691 | __ Bind(&unordered); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2692 | CompareICStub stub(isolate(), op(), CompareICState::GENERIC, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2693 | CompareICState::GENERIC, CompareICState::GENERIC); |
| 2694 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 2695 | |
| 2696 | __ Bind(&maybe_undefined1); |
| 2697 | if (Token::IsOrderedRelationalCompareOp(op())) { |
| 2698 | __ JumpIfNotRoot(rhs, Heap::kUndefinedValueRootIndex, &miss); |
| 2699 | __ JumpIfSmi(lhs, &unordered); |
| 2700 | __ JumpIfNotHeapNumber(lhs, &maybe_undefined2); |
| 2701 | __ B(&unordered); |
| 2702 | } |
| 2703 | |
| 2704 | __ Bind(&maybe_undefined2); |
| 2705 | if (Token::IsOrderedRelationalCompareOp(op())) { |
| 2706 | __ JumpIfRoot(lhs, Heap::kUndefinedValueRootIndex, &unordered); |
| 2707 | } |
| 2708 | |
| 2709 | __ Bind(&miss); |
| 2710 | GenerateMiss(masm); |
| 2711 | } |
| 2712 | |
| 2713 | |
| 2714 | void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 2715 | DCHECK(state() == CompareICState::INTERNALIZED_STRING); |
| 2716 | ASM_LOCATION("CompareICStub[InternalizedStrings]"); |
| 2717 | Label miss; |
| 2718 | |
| 2719 | Register result = x0; |
| 2720 | Register rhs = x0; |
| 2721 | Register lhs = x1; |
| 2722 | |
| 2723 | // Check that both operands are heap objects. |
| 2724 | __ JumpIfEitherSmi(lhs, rhs, &miss); |
| 2725 | |
| 2726 | // Check that both operands are internalized strings. |
| 2727 | Register rhs_map = x10; |
| 2728 | Register lhs_map = x11; |
| 2729 | Register rhs_type = x10; |
| 2730 | Register lhs_type = x11; |
| 2731 | __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset)); |
| 2732 | __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 2733 | __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset)); |
| 2734 | __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset)); |
| 2735 | |
| 2736 | STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0)); |
| 2737 | __ Orr(x12, lhs_type, rhs_type); |
| 2738 | __ TestAndBranchIfAnySet( |
| 2739 | x12, kIsNotStringMask | kIsNotInternalizedMask, &miss); |
| 2740 | |
| 2741 | // Internalized strings are compared by identity. |
| 2742 | STATIC_ASSERT(EQUAL == 0); |
| 2743 | __ Cmp(lhs, rhs); |
| 2744 | __ Cset(result, ne); |
| 2745 | __ Ret(); |
| 2746 | |
| 2747 | __ Bind(&miss); |
| 2748 | GenerateMiss(masm); |
| 2749 | } |
| 2750 | |
| 2751 | |
| 2752 | void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 2753 | DCHECK(state() == CompareICState::UNIQUE_NAME); |
| 2754 | ASM_LOCATION("CompareICStub[UniqueNames]"); |
| 2755 | DCHECK(GetCondition() == eq); |
| 2756 | Label miss; |
| 2757 | |
| 2758 | Register result = x0; |
| 2759 | Register rhs = x0; |
| 2760 | Register lhs = x1; |
| 2761 | |
| 2762 | Register lhs_instance_type = w2; |
| 2763 | Register rhs_instance_type = w3; |
| 2764 | |
| 2765 | // Check that both operands are heap objects. |
| 2766 | __ JumpIfEitherSmi(lhs, rhs, &miss); |
| 2767 | |
| 2768 | // Check that both operands are unique names. This leaves the instance |
| 2769 | // types loaded in tmp1 and tmp2. |
| 2770 | __ Ldr(x10, FieldMemOperand(lhs, HeapObject::kMapOffset)); |
| 2771 | __ Ldr(x11, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 2772 | __ Ldrb(lhs_instance_type, FieldMemOperand(x10, Map::kInstanceTypeOffset)); |
| 2773 | __ Ldrb(rhs_instance_type, FieldMemOperand(x11, Map::kInstanceTypeOffset)); |
| 2774 | |
| 2775 | // To avoid a miss, each instance type should be either SYMBOL_TYPE or it |
| 2776 | // should have kInternalizedTag set. |
| 2777 | __ JumpIfNotUniqueNameInstanceType(lhs_instance_type, &miss); |
| 2778 | __ JumpIfNotUniqueNameInstanceType(rhs_instance_type, &miss); |
| 2779 | |
| 2780 | // Unique names are compared by identity. |
| 2781 | STATIC_ASSERT(EQUAL == 0); |
| 2782 | __ Cmp(lhs, rhs); |
| 2783 | __ Cset(result, ne); |
| 2784 | __ Ret(); |
| 2785 | |
| 2786 | __ Bind(&miss); |
| 2787 | GenerateMiss(masm); |
| 2788 | } |
| 2789 | |
| 2790 | |
| 2791 | void CompareICStub::GenerateStrings(MacroAssembler* masm) { |
| 2792 | DCHECK(state() == CompareICState::STRING); |
| 2793 | ASM_LOCATION("CompareICStub[Strings]"); |
| 2794 | |
| 2795 | Label miss; |
| 2796 | |
| 2797 | bool equality = Token::IsEqualityOp(op()); |
| 2798 | |
| 2799 | Register result = x0; |
| 2800 | Register rhs = x0; |
| 2801 | Register lhs = x1; |
| 2802 | |
| 2803 | // Check that both operands are heap objects. |
| 2804 | __ JumpIfEitherSmi(rhs, lhs, &miss); |
| 2805 | |
| 2806 | // Check that both operands are strings. |
| 2807 | Register rhs_map = x10; |
| 2808 | Register lhs_map = x11; |
| 2809 | Register rhs_type = x10; |
| 2810 | Register lhs_type = x11; |
| 2811 | __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset)); |
| 2812 | __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 2813 | __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset)); |
| 2814 | __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset)); |
| 2815 | STATIC_ASSERT(kNotStringTag != 0); |
| 2816 | __ Orr(x12, lhs_type, rhs_type); |
| 2817 | __ Tbnz(x12, MaskToBit(kIsNotStringMask), &miss); |
| 2818 | |
| 2819 | // Fast check for identical strings. |
| 2820 | Label not_equal; |
| 2821 | __ Cmp(lhs, rhs); |
| 2822 | __ B(ne, ¬_equal); |
| 2823 | __ Mov(result, EQUAL); |
| 2824 | __ Ret(); |
| 2825 | |
| 2826 | __ Bind(¬_equal); |
| 2827 | // Handle not identical strings |
| 2828 | |
| 2829 | // Check that both strings are internalized strings. If they are, we're done |
| 2830 | // because we already know they are not identical. We know they are both |
| 2831 | // strings. |
| 2832 | if (equality) { |
| 2833 | DCHECK(GetCondition() == eq); |
| 2834 | STATIC_ASSERT(kInternalizedTag == 0); |
| 2835 | Label not_internalized_strings; |
| 2836 | __ Orr(x12, lhs_type, rhs_type); |
| 2837 | __ TestAndBranchIfAnySet( |
| 2838 | x12, kIsNotInternalizedMask, ¬_internalized_strings); |
| 2839 | // Result is in rhs (x0), and not EQUAL, as rhs is not a smi. |
| 2840 | __ Ret(); |
| 2841 | __ Bind(¬_internalized_strings); |
| 2842 | } |
| 2843 | |
| 2844 | // Check that both strings are sequential one-byte. |
| 2845 | Label runtime; |
| 2846 | __ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x12, |
| 2847 | x13, &runtime); |
| 2848 | |
| 2849 | // Compare flat one-byte strings. Returns when done. |
| 2850 | if (equality) { |
| 2851 | StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11, |
| 2852 | x12); |
| 2853 | } else { |
| 2854 | StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11, |
| 2855 | x12, x13); |
| 2856 | } |
| 2857 | |
| 2858 | // Handle more complex cases in runtime. |
| 2859 | __ Bind(&runtime); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2860 | if (equality) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2861 | { |
| 2862 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2863 | __ Push(lhs, rhs); |
| 2864 | __ CallRuntime(Runtime::kStringEqual); |
| 2865 | } |
| 2866 | __ LoadRoot(x1, Heap::kTrueValueRootIndex); |
| 2867 | __ Sub(x0, x0, x1); |
| 2868 | __ Ret(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2869 | } else { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2870 | __ Push(lhs, rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2871 | __ TailCallRuntime(Runtime::kStringCompare); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2872 | } |
| 2873 | |
| 2874 | __ Bind(&miss); |
| 2875 | GenerateMiss(masm); |
| 2876 | } |
| 2877 | |
| 2878 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2879 | void CompareICStub::GenerateReceivers(MacroAssembler* masm) { |
| 2880 | DCHECK_EQ(CompareICState::RECEIVER, state()); |
| 2881 | ASM_LOCATION("CompareICStub[Receivers]"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2882 | |
| 2883 | Label miss; |
| 2884 | |
| 2885 | Register result = x0; |
| 2886 | Register rhs = x0; |
| 2887 | Register lhs = x1; |
| 2888 | |
| 2889 | __ JumpIfEitherSmi(rhs, lhs, &miss); |
| 2890 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2891 | STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
| 2892 | __ JumpIfObjectType(rhs, x10, x10, FIRST_JS_RECEIVER_TYPE, &miss, lt); |
| 2893 | __ JumpIfObjectType(lhs, x10, x10, FIRST_JS_RECEIVER_TYPE, &miss, lt); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2894 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2895 | DCHECK_EQ(eq, GetCondition()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2896 | __ Sub(result, rhs, lhs); |
| 2897 | __ Ret(); |
| 2898 | |
| 2899 | __ Bind(&miss); |
| 2900 | GenerateMiss(masm); |
| 2901 | } |
| 2902 | |
| 2903 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2904 | void CompareICStub::GenerateKnownReceivers(MacroAssembler* masm) { |
| 2905 | ASM_LOCATION("CompareICStub[KnownReceivers]"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2906 | |
| 2907 | Label miss; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2908 | Handle<WeakCell> cell = Map::WeakCellForMap(known_map_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2909 | |
| 2910 | Register result = x0; |
| 2911 | Register rhs = x0; |
| 2912 | Register lhs = x1; |
| 2913 | |
| 2914 | __ JumpIfEitherSmi(rhs, lhs, &miss); |
| 2915 | |
| 2916 | Register rhs_map = x10; |
| 2917 | Register lhs_map = x11; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2918 | Register map = x12; |
| 2919 | __ GetWeakValue(map, cell); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2920 | __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 2921 | __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2922 | __ Cmp(rhs_map, map); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2923 | __ B(ne, &miss); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2924 | __ Cmp(lhs_map, map); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2925 | __ B(ne, &miss); |
| 2926 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2927 | if (Token::IsEqualityOp(op())) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2928 | __ Sub(result, rhs, lhs); |
| 2929 | __ Ret(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2930 | } else { |
| 2931 | Register ncr = x2; |
| 2932 | if (op() == Token::LT || op() == Token::LTE) { |
| 2933 | __ Mov(ncr, Smi::FromInt(GREATER)); |
| 2934 | } else { |
| 2935 | __ Mov(ncr, Smi::FromInt(LESS)); |
| 2936 | } |
| 2937 | __ Push(lhs, rhs, ncr); |
| 2938 | __ TailCallRuntime(Runtime::kCompare); |
| 2939 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2940 | |
| 2941 | __ Bind(&miss); |
| 2942 | GenerateMiss(masm); |
| 2943 | } |
| 2944 | |
| 2945 | |
| 2946 | // This method handles the case where a compare stub had the wrong |
| 2947 | // implementation. It calls a miss handler, which re-writes the stub. All other |
| 2948 | // CompareICStub::Generate* methods should fall back into this one if their |
| 2949 | // operands were not the expected types. |
| 2950 | void CompareICStub::GenerateMiss(MacroAssembler* masm) { |
| 2951 | ASM_LOCATION("CompareICStub[Miss]"); |
| 2952 | |
| 2953 | Register stub_entry = x11; |
| 2954 | { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2955 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2956 | Register op = x10; |
| 2957 | Register left = x1; |
| 2958 | Register right = x0; |
| 2959 | // Preserve some caller-saved registers. |
| 2960 | __ Push(x1, x0, lr); |
| 2961 | // Push the arguments. |
| 2962 | __ Mov(op, Smi::FromInt(this->op())); |
| 2963 | __ Push(left, right, op); |
| 2964 | |
| 2965 | // Call the miss handler. This also pops the arguments. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2966 | __ CallRuntime(Runtime::kCompareIC_Miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2967 | |
| 2968 | // Compute the entry point of the rewritten stub. |
| 2969 | __ Add(stub_entry, x0, Code::kHeaderSize - kHeapObjectTag); |
| 2970 | // Restore caller-saved registers. |
| 2971 | __ Pop(lr, x0, x1); |
| 2972 | } |
| 2973 | |
| 2974 | // Tail-call to the new stub. |
| 2975 | __ Jump(stub_entry); |
| 2976 | } |
| 2977 | |
| 2978 | |
| 2979 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 2980 | ASM_LOCATION("SubStringStub::Generate"); |
| 2981 | Label runtime; |
| 2982 | |
| 2983 | // Stack frame on entry. |
| 2984 | // lr: return address |
| 2985 | // jssp[0]: substring "to" offset |
| 2986 | // jssp[8]: substring "from" offset |
| 2987 | // jssp[16]: pointer to string object |
| 2988 | |
| 2989 | // This stub is called from the native-call %_SubString(...), so |
| 2990 | // nothing can be assumed about the arguments. It is tested that: |
| 2991 | // "string" is a sequential string, |
| 2992 | // both "from" and "to" are smis, and |
| 2993 | // 0 <= from <= to <= string.length (in debug mode.) |
| 2994 | // If any of these assumptions fail, we call the runtime system. |
| 2995 | |
| 2996 | static const int kToOffset = 0 * kPointerSize; |
| 2997 | static const int kFromOffset = 1 * kPointerSize; |
| 2998 | static const int kStringOffset = 2 * kPointerSize; |
| 2999 | |
| 3000 | Register to = x0; |
| 3001 | Register from = x15; |
| 3002 | Register input_string = x10; |
| 3003 | Register input_length = x11; |
| 3004 | Register input_type = x12; |
| 3005 | Register result_string = x0; |
| 3006 | Register result_length = x1; |
| 3007 | Register temp = x3; |
| 3008 | |
| 3009 | __ Peek(to, kToOffset); |
| 3010 | __ Peek(from, kFromOffset); |
| 3011 | |
| 3012 | // Check that both from and to are smis. If not, jump to runtime. |
| 3013 | __ JumpIfEitherNotSmi(from, to, &runtime); |
| 3014 | __ SmiUntag(from); |
| 3015 | __ SmiUntag(to); |
| 3016 | |
| 3017 | // Calculate difference between from and to. If to < from, branch to runtime. |
| 3018 | __ Subs(result_length, to, from); |
| 3019 | __ B(mi, &runtime); |
| 3020 | |
| 3021 | // Check from is positive. |
| 3022 | __ Tbnz(from, kWSignBit, &runtime); |
| 3023 | |
| 3024 | // Make sure first argument is a string. |
| 3025 | __ Peek(input_string, kStringOffset); |
| 3026 | __ JumpIfSmi(input_string, &runtime); |
| 3027 | __ IsObjectJSStringType(input_string, input_type, &runtime); |
| 3028 | |
| 3029 | Label single_char; |
| 3030 | __ Cmp(result_length, 1); |
| 3031 | __ B(eq, &single_char); |
| 3032 | |
| 3033 | // Short-cut for the case of trivial substring. |
| 3034 | Label return_x0; |
| 3035 | __ Ldrsw(input_length, |
| 3036 | UntagSmiFieldMemOperand(input_string, String::kLengthOffset)); |
| 3037 | |
| 3038 | __ Cmp(result_length, input_length); |
| 3039 | __ CmovX(x0, input_string, eq); |
| 3040 | // Return original string. |
| 3041 | __ B(eq, &return_x0); |
| 3042 | |
| 3043 | // Longer than original string's length or negative: unsafe arguments. |
| 3044 | __ B(hi, &runtime); |
| 3045 | |
| 3046 | // Shorter than original string's length: an actual substring. |
| 3047 | |
| 3048 | // x0 to substring end character offset |
| 3049 | // x1 result_length length of substring result |
| 3050 | // x10 input_string pointer to input string object |
| 3051 | // x10 unpacked_string pointer to unpacked string object |
| 3052 | // x11 input_length length of input string |
| 3053 | // x12 input_type instance type of input string |
| 3054 | // x15 from substring start character offset |
| 3055 | |
| 3056 | // Deal with different string types: update the index if necessary and put |
| 3057 | // the underlying string into register unpacked_string. |
| 3058 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 3059 | Label update_instance_type; |
| 3060 | // If the string is not indirect, it can only be sequential or external. |
| 3061 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 3062 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 3063 | |
| 3064 | // Test for string types, and branch/fall through to appropriate unpacking |
| 3065 | // code. |
| 3066 | __ Tst(input_type, kIsIndirectStringMask); |
| 3067 | __ B(eq, &seq_or_external_string); |
| 3068 | __ Tst(input_type, kSlicedNotConsMask); |
| 3069 | __ B(ne, &sliced_string); |
| 3070 | |
| 3071 | Register unpacked_string = input_string; |
| 3072 | |
| 3073 | // Cons string. Check whether it is flat, then fetch first part. |
| 3074 | __ Ldr(temp, FieldMemOperand(input_string, ConsString::kSecondOffset)); |
| 3075 | __ JumpIfNotRoot(temp, Heap::kempty_stringRootIndex, &runtime); |
| 3076 | __ Ldr(unpacked_string, |
| 3077 | FieldMemOperand(input_string, ConsString::kFirstOffset)); |
| 3078 | __ B(&update_instance_type); |
| 3079 | |
| 3080 | __ Bind(&sliced_string); |
| 3081 | // Sliced string. Fetch parent and correct start index by offset. |
| 3082 | __ Ldrsw(temp, |
| 3083 | UntagSmiFieldMemOperand(input_string, SlicedString::kOffsetOffset)); |
| 3084 | __ Add(from, from, temp); |
| 3085 | __ Ldr(unpacked_string, |
| 3086 | FieldMemOperand(input_string, SlicedString::kParentOffset)); |
| 3087 | |
| 3088 | __ Bind(&update_instance_type); |
| 3089 | __ Ldr(temp, FieldMemOperand(unpacked_string, HeapObject::kMapOffset)); |
| 3090 | __ Ldrb(input_type, FieldMemOperand(temp, Map::kInstanceTypeOffset)); |
| 3091 | // Now control must go to &underlying_unpacked. Since the no code is generated |
| 3092 | // before then we fall through instead of generating a useless branch. |
| 3093 | |
| 3094 | __ Bind(&seq_or_external_string); |
| 3095 | // Sequential or external string. Registers unpacked_string and input_string |
| 3096 | // alias, so there's nothing to do here. |
| 3097 | // Note that if code is added here, the above code must be updated. |
| 3098 | |
| 3099 | // x0 result_string pointer to result string object (uninit) |
| 3100 | // x1 result_length length of substring result |
| 3101 | // x10 unpacked_string pointer to unpacked string object |
| 3102 | // x11 input_length length of input string |
| 3103 | // x12 input_type instance type of input string |
| 3104 | // x15 from substring start character offset |
| 3105 | __ Bind(&underlying_unpacked); |
| 3106 | |
| 3107 | if (FLAG_string_slices) { |
| 3108 | Label copy_routine; |
| 3109 | __ Cmp(result_length, SlicedString::kMinLength); |
| 3110 | // Short slice. Copy instead of slicing. |
| 3111 | __ B(lt, ©_routine); |
| 3112 | // Allocate new sliced string. At this point we do not reload the instance |
| 3113 | // type including the string encoding because we simply rely on the info |
| 3114 | // provided by the original string. It does not matter if the original |
| 3115 | // string's encoding is wrong because we always have to recheck encoding of |
| 3116 | // the newly created string's parent anyway due to externalized strings. |
| 3117 | Label two_byte_slice, set_slice_header; |
| 3118 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
| 3119 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 3120 | __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_slice); |
| 3121 | __ AllocateOneByteSlicedString(result_string, result_length, x3, x4, |
| 3122 | &runtime); |
| 3123 | __ B(&set_slice_header); |
| 3124 | |
| 3125 | __ Bind(&two_byte_slice); |
| 3126 | __ AllocateTwoByteSlicedString(result_string, result_length, x3, x4, |
| 3127 | &runtime); |
| 3128 | |
| 3129 | __ Bind(&set_slice_header); |
| 3130 | __ SmiTag(from); |
| 3131 | __ Str(from, FieldMemOperand(result_string, SlicedString::kOffsetOffset)); |
| 3132 | __ Str(unpacked_string, |
| 3133 | FieldMemOperand(result_string, SlicedString::kParentOffset)); |
| 3134 | __ B(&return_x0); |
| 3135 | |
| 3136 | __ Bind(©_routine); |
| 3137 | } |
| 3138 | |
| 3139 | // x0 result_string pointer to result string object (uninit) |
| 3140 | // x1 result_length length of substring result |
| 3141 | // x10 unpacked_string pointer to unpacked string object |
| 3142 | // x11 input_length length of input string |
| 3143 | // x12 input_type instance type of input string |
| 3144 | // x13 unpacked_char0 pointer to first char of unpacked string (uninit) |
| 3145 | // x13 substring_char0 pointer to first char of substring (uninit) |
| 3146 | // x14 result_char0 pointer to first char of result (uninit) |
| 3147 | // x15 from substring start character offset |
| 3148 | Register unpacked_char0 = x13; |
| 3149 | Register substring_char0 = x13; |
| 3150 | Register result_char0 = x14; |
| 3151 | Label two_byte_sequential, sequential_string, allocate_result; |
| 3152 | STATIC_ASSERT(kExternalStringTag != 0); |
| 3153 | STATIC_ASSERT(kSeqStringTag == 0); |
| 3154 | |
| 3155 | __ Tst(input_type, kExternalStringTag); |
| 3156 | __ B(eq, &sequential_string); |
| 3157 | |
| 3158 | __ Tst(input_type, kShortExternalStringTag); |
| 3159 | __ B(ne, &runtime); |
| 3160 | __ Ldr(unpacked_char0, |
| 3161 | FieldMemOperand(unpacked_string, ExternalString::kResourceDataOffset)); |
| 3162 | // unpacked_char0 points to the first character of the underlying string. |
| 3163 | __ B(&allocate_result); |
| 3164 | |
| 3165 | __ Bind(&sequential_string); |
| 3166 | // Locate first character of underlying subject string. |
| 3167 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
| 3168 | __ Add(unpacked_char0, unpacked_string, |
| 3169 | SeqOneByteString::kHeaderSize - kHeapObjectTag); |
| 3170 | |
| 3171 | __ Bind(&allocate_result); |
| 3172 | // Sequential one-byte string. Allocate the result. |
| 3173 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
| 3174 | __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_sequential); |
| 3175 | |
| 3176 | // Allocate and copy the resulting one-byte string. |
| 3177 | __ AllocateOneByteString(result_string, result_length, x3, x4, x5, &runtime); |
| 3178 | |
| 3179 | // Locate first character of substring to copy. |
| 3180 | __ Add(substring_char0, unpacked_char0, from); |
| 3181 | |
| 3182 | // Locate first character of result. |
| 3183 | __ Add(result_char0, result_string, |
| 3184 | SeqOneByteString::kHeaderSize - kHeapObjectTag); |
| 3185 | |
| 3186 | STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 3187 | __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong); |
| 3188 | __ B(&return_x0); |
| 3189 | |
| 3190 | // Allocate and copy the resulting two-byte string. |
| 3191 | __ Bind(&two_byte_sequential); |
| 3192 | __ AllocateTwoByteString(result_string, result_length, x3, x4, x5, &runtime); |
| 3193 | |
| 3194 | // Locate first character of substring to copy. |
| 3195 | __ Add(substring_char0, unpacked_char0, Operand(from, LSL, 1)); |
| 3196 | |
| 3197 | // Locate first character of result. |
| 3198 | __ Add(result_char0, result_string, |
| 3199 | SeqTwoByteString::kHeaderSize - kHeapObjectTag); |
| 3200 | |
| 3201 | STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 3202 | __ Add(result_length, result_length, result_length); |
| 3203 | __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong); |
| 3204 | |
| 3205 | __ Bind(&return_x0); |
| 3206 | Counters* counters = isolate()->counters(); |
| 3207 | __ IncrementCounter(counters->sub_string_native(), 1, x3, x4); |
| 3208 | __ Drop(3); |
| 3209 | __ Ret(); |
| 3210 | |
| 3211 | __ Bind(&runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3212 | __ TailCallRuntime(Runtime::kSubString); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3213 | |
| 3214 | __ bind(&single_char); |
| 3215 | // x1: result_length |
| 3216 | // x10: input_string |
| 3217 | // x12: input_type |
| 3218 | // x15: from (untagged) |
| 3219 | __ SmiTag(from); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3220 | StringCharAtGenerator generator(input_string, from, result_length, x0, |
| 3221 | &runtime, &runtime, &runtime, |
| 3222 | STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3223 | generator.GenerateFast(masm); |
| 3224 | __ Drop(3); |
| 3225 | __ Ret(); |
| 3226 | generator.SkipSlow(masm, &runtime); |
| 3227 | } |
| 3228 | |
| 3229 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3230 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 3231 | // The ToNumber stub takes one argument in x0. |
| 3232 | Label not_smi; |
| 3233 | __ JumpIfNotSmi(x0, ¬_smi); |
| 3234 | __ Ret(); |
| 3235 | __ Bind(¬_smi); |
| 3236 | |
| 3237 | Label not_heap_number; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 3238 | __ CompareObjectType(x0, x1, x1, HEAP_NUMBER_TYPE); |
| 3239 | // x0: receiver |
| 3240 | // x1: receiver instance type |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3241 | __ B(ne, ¬_heap_number); |
| 3242 | __ Ret(); |
| 3243 | __ Bind(¬_heap_number); |
| 3244 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 3245 | NonNumberToNumberStub stub(masm->isolate()); |
| 3246 | __ TailCallStub(&stub); |
| 3247 | } |
| 3248 | |
| 3249 | void NonNumberToNumberStub::Generate(MacroAssembler* masm) { |
| 3250 | // The NonNumberToNumber stub takes one argument in x0. |
| 3251 | __ AssertNotNumber(x0); |
| 3252 | |
| 3253 | Label not_string; |
| 3254 | __ CompareObjectType(x0, x1, x1, FIRST_NONSTRING_TYPE); |
| 3255 | // x0: receiver |
| 3256 | // x1: receiver instance type |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3257 | __ B(hs, ¬_string); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 3258 | StringToNumberStub stub(masm->isolate()); |
| 3259 | __ TailCallStub(&stub); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3260 | __ Bind(¬_string); |
| 3261 | |
| 3262 | Label not_oddball; |
| 3263 | __ Cmp(x1, ODDBALL_TYPE); |
| 3264 | __ B(ne, ¬_oddball); |
| 3265 | __ Ldr(x0, FieldMemOperand(x0, Oddball::kToNumberOffset)); |
| 3266 | __ Ret(); |
| 3267 | __ Bind(¬_oddball); |
| 3268 | |
| 3269 | __ Push(x0); // Push argument. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3270 | __ TailCallRuntime(Runtime::kToNumber); |
| 3271 | } |
| 3272 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 3273 | void StringToNumberStub::Generate(MacroAssembler* masm) { |
| 3274 | // The StringToNumber stub takes one argument in x0. |
| 3275 | __ AssertString(x0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3276 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 3277 | // Check if string has a cached array index. |
| 3278 | Label runtime; |
| 3279 | __ Ldr(x2, FieldMemOperand(x0, String::kHashFieldOffset)); |
| 3280 | __ Tst(x2, Operand(String::kContainsCachedArrayIndexMask)); |
| 3281 | __ B(ne, &runtime); |
| 3282 | __ IndexFromHash(x2, x0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3283 | __ Ret(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3284 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 3285 | __ Bind(&runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3286 | __ Push(x0); // Push argument. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 3287 | __ TailCallRuntime(Runtime::kStringToNumber); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3288 | } |
| 3289 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3290 | void ToStringStub::Generate(MacroAssembler* masm) { |
| 3291 | // The ToString stub takes one argument in x0. |
| 3292 | Label is_number; |
| 3293 | __ JumpIfSmi(x0, &is_number); |
| 3294 | |
| 3295 | Label not_string; |
| 3296 | __ JumpIfObjectType(x0, x1, x1, FIRST_NONSTRING_TYPE, ¬_string, hs); |
| 3297 | // x0: receiver |
| 3298 | // x1: receiver instance type |
| 3299 | __ Ret(); |
| 3300 | __ Bind(¬_string); |
| 3301 | |
| 3302 | Label not_heap_number; |
| 3303 | __ Cmp(x1, HEAP_NUMBER_TYPE); |
| 3304 | __ B(ne, ¬_heap_number); |
| 3305 | __ Bind(&is_number); |
| 3306 | NumberToStringStub stub(isolate()); |
| 3307 | __ TailCallStub(&stub); |
| 3308 | __ Bind(¬_heap_number); |
| 3309 | |
| 3310 | Label not_oddball; |
| 3311 | __ Cmp(x1, ODDBALL_TYPE); |
| 3312 | __ B(ne, ¬_oddball); |
| 3313 | __ Ldr(x0, FieldMemOperand(x0, Oddball::kToStringOffset)); |
| 3314 | __ Ret(); |
| 3315 | __ Bind(¬_oddball); |
| 3316 | |
| 3317 | __ Push(x0); // Push argument. |
| 3318 | __ TailCallRuntime(Runtime::kToString); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3319 | } |
| 3320 | |
| 3321 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3322 | void ToNameStub::Generate(MacroAssembler* masm) { |
| 3323 | // The ToName stub takes one argument in x0. |
| 3324 | Label is_number; |
| 3325 | __ JumpIfSmi(x0, &is_number); |
| 3326 | |
| 3327 | Label not_name; |
| 3328 | STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE); |
| 3329 | __ JumpIfObjectType(x0, x1, x1, LAST_NAME_TYPE, ¬_name, hi); |
| 3330 | // x0: receiver |
| 3331 | // x1: receiver instance type |
| 3332 | __ Ret(); |
| 3333 | __ Bind(¬_name); |
| 3334 | |
| 3335 | Label not_heap_number; |
| 3336 | __ Cmp(x1, HEAP_NUMBER_TYPE); |
| 3337 | __ B(ne, ¬_heap_number); |
| 3338 | __ Bind(&is_number); |
| 3339 | NumberToStringStub stub(isolate()); |
| 3340 | __ TailCallStub(&stub); |
| 3341 | __ Bind(¬_heap_number); |
| 3342 | |
| 3343 | Label not_oddball; |
| 3344 | __ Cmp(x1, ODDBALL_TYPE); |
| 3345 | __ B(ne, ¬_oddball); |
| 3346 | __ Ldr(x0, FieldMemOperand(x0, Oddball::kToStringOffset)); |
| 3347 | __ Ret(); |
| 3348 | __ Bind(¬_oddball); |
| 3349 | |
| 3350 | __ Push(x0); // Push argument. |
| 3351 | __ TailCallRuntime(Runtime::kToName); |
| 3352 | } |
| 3353 | |
| 3354 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3355 | void StringHelper::GenerateFlatOneByteStringEquals( |
| 3356 | MacroAssembler* masm, Register left, Register right, Register scratch1, |
| 3357 | Register scratch2, Register scratch3) { |
| 3358 | DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3)); |
| 3359 | Register result = x0; |
| 3360 | Register left_length = scratch1; |
| 3361 | Register right_length = scratch2; |
| 3362 | |
| 3363 | // Compare lengths. If lengths differ, strings can't be equal. Lengths are |
| 3364 | // smis, and don't need to be untagged. |
| 3365 | Label strings_not_equal, check_zero_length; |
| 3366 | __ Ldr(left_length, FieldMemOperand(left, String::kLengthOffset)); |
| 3367 | __ Ldr(right_length, FieldMemOperand(right, String::kLengthOffset)); |
| 3368 | __ Cmp(left_length, right_length); |
| 3369 | __ B(eq, &check_zero_length); |
| 3370 | |
| 3371 | __ Bind(&strings_not_equal); |
| 3372 | __ Mov(result, Smi::FromInt(NOT_EQUAL)); |
| 3373 | __ Ret(); |
| 3374 | |
| 3375 | // Check if the length is zero. If so, the strings must be equal (and empty.) |
| 3376 | Label compare_chars; |
| 3377 | __ Bind(&check_zero_length); |
| 3378 | STATIC_ASSERT(kSmiTag == 0); |
| 3379 | __ Cbnz(left_length, &compare_chars); |
| 3380 | __ Mov(result, Smi::FromInt(EQUAL)); |
| 3381 | __ Ret(); |
| 3382 | |
| 3383 | // Compare characters. Falls through if all characters are equal. |
| 3384 | __ Bind(&compare_chars); |
| 3385 | GenerateOneByteCharsCompareLoop(masm, left, right, left_length, scratch2, |
| 3386 | scratch3, &strings_not_equal); |
| 3387 | |
| 3388 | // Characters in strings are equal. |
| 3389 | __ Mov(result, Smi::FromInt(EQUAL)); |
| 3390 | __ Ret(); |
| 3391 | } |
| 3392 | |
| 3393 | |
| 3394 | void StringHelper::GenerateCompareFlatOneByteStrings( |
| 3395 | MacroAssembler* masm, Register left, Register right, Register scratch1, |
| 3396 | Register scratch2, Register scratch3, Register scratch4) { |
| 3397 | DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3, scratch4)); |
| 3398 | Label result_not_equal, compare_lengths; |
| 3399 | |
| 3400 | // Find minimum length and length difference. |
| 3401 | Register length_delta = scratch3; |
| 3402 | __ Ldr(scratch1, FieldMemOperand(left, String::kLengthOffset)); |
| 3403 | __ Ldr(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 3404 | __ Subs(length_delta, scratch1, scratch2); |
| 3405 | |
| 3406 | Register min_length = scratch1; |
| 3407 | __ Csel(min_length, scratch2, scratch1, gt); |
| 3408 | __ Cbz(min_length, &compare_lengths); |
| 3409 | |
| 3410 | // Compare loop. |
| 3411 | GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2, |
| 3412 | scratch4, &result_not_equal); |
| 3413 | |
| 3414 | // Compare lengths - strings up to min-length are equal. |
| 3415 | __ Bind(&compare_lengths); |
| 3416 | |
| 3417 | DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0)); |
| 3418 | |
| 3419 | // Use length_delta as result if it's zero. |
| 3420 | Register result = x0; |
| 3421 | __ Subs(result, length_delta, 0); |
| 3422 | |
| 3423 | __ Bind(&result_not_equal); |
| 3424 | Register greater = x10; |
| 3425 | Register less = x11; |
| 3426 | __ Mov(greater, Smi::FromInt(GREATER)); |
| 3427 | __ Mov(less, Smi::FromInt(LESS)); |
| 3428 | __ CmovX(result, greater, gt); |
| 3429 | __ CmovX(result, less, lt); |
| 3430 | __ Ret(); |
| 3431 | } |
| 3432 | |
| 3433 | |
| 3434 | void StringHelper::GenerateOneByteCharsCompareLoop( |
| 3435 | MacroAssembler* masm, Register left, Register right, Register length, |
| 3436 | Register scratch1, Register scratch2, Label* chars_not_equal) { |
| 3437 | DCHECK(!AreAliased(left, right, length, scratch1, scratch2)); |
| 3438 | |
| 3439 | // Change index to run from -length to -1 by adding length to string |
| 3440 | // start. This means that loop ends when index reaches zero, which |
| 3441 | // doesn't need an additional compare. |
| 3442 | __ SmiUntag(length); |
| 3443 | __ Add(scratch1, length, SeqOneByteString::kHeaderSize - kHeapObjectTag); |
| 3444 | __ Add(left, left, scratch1); |
| 3445 | __ Add(right, right, scratch1); |
| 3446 | |
| 3447 | Register index = length; |
| 3448 | __ Neg(index, length); // index = -length; |
| 3449 | |
| 3450 | // Compare loop |
| 3451 | Label loop; |
| 3452 | __ Bind(&loop); |
| 3453 | __ Ldrb(scratch1, MemOperand(left, index)); |
| 3454 | __ Ldrb(scratch2, MemOperand(right, index)); |
| 3455 | __ Cmp(scratch1, scratch2); |
| 3456 | __ B(ne, chars_not_equal); |
| 3457 | __ Add(index, index, 1); |
| 3458 | __ Cbnz(index, &loop); |
| 3459 | } |
| 3460 | |
| 3461 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3462 | void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) { |
| 3463 | // ----------- S t a t e ------------- |
| 3464 | // -- x1 : left |
| 3465 | // -- x0 : right |
| 3466 | // -- lr : return address |
| 3467 | // ----------------------------------- |
| 3468 | |
| 3469 | // Load x2 with the allocation site. We stick an undefined dummy value here |
| 3470 | // and replace it with the real allocation site later when we instantiate this |
| 3471 | // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate(). |
| 3472 | __ LoadObject(x2, handle(isolate()->heap()->undefined_value())); |
| 3473 | |
| 3474 | // Make sure that we actually patched the allocation site. |
| 3475 | if (FLAG_debug_code) { |
| 3476 | __ AssertNotSmi(x2, kExpectedAllocationSite); |
| 3477 | __ Ldr(x10, FieldMemOperand(x2, HeapObject::kMapOffset)); |
| 3478 | __ AssertRegisterIsRoot(x10, Heap::kAllocationSiteMapRootIndex, |
| 3479 | kExpectedAllocationSite); |
| 3480 | } |
| 3481 | |
| 3482 | // Tail call into the stub that handles binary operations with allocation |
| 3483 | // sites. |
| 3484 | BinaryOpWithAllocationSiteStub stub(isolate(), state()); |
| 3485 | __ TailCallStub(&stub); |
| 3486 | } |
| 3487 | |
| 3488 | |
| 3489 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 3490 | // We need some extra registers for this stub, they have been allocated |
| 3491 | // but we need to save them before using them. |
| 3492 | regs_.Save(masm); |
| 3493 | |
| 3494 | if (remembered_set_action() == EMIT_REMEMBERED_SET) { |
| 3495 | Label dont_need_remembered_set; |
| 3496 | |
| 3497 | Register val = regs_.scratch0(); |
| 3498 | __ Ldr(val, MemOperand(regs_.address())); |
| 3499 | __ JumpIfNotInNewSpace(val, &dont_need_remembered_set); |
| 3500 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3501 | __ JumpIfInNewSpace(regs_.object(), &dont_need_remembered_set); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3502 | |
| 3503 | // First notify the incremental marker if necessary, then update the |
| 3504 | // remembered set. |
| 3505 | CheckNeedsToInformIncrementalMarker( |
| 3506 | masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode); |
| 3507 | InformIncrementalMarker(masm); |
| 3508 | regs_.Restore(masm); // Restore the extra scratch registers we used. |
| 3509 | |
| 3510 | __ RememberedSetHelper(object(), address(), |
| 3511 | value(), // scratch1 |
| 3512 | save_fp_regs_mode(), MacroAssembler::kReturnAtEnd); |
| 3513 | |
| 3514 | __ Bind(&dont_need_remembered_set); |
| 3515 | } |
| 3516 | |
| 3517 | CheckNeedsToInformIncrementalMarker( |
| 3518 | masm, kReturnOnNoNeedToInformIncrementalMarker, mode); |
| 3519 | InformIncrementalMarker(masm); |
| 3520 | regs_.Restore(masm); // Restore the extra scratch registers we used. |
| 3521 | __ Ret(); |
| 3522 | } |
| 3523 | |
| 3524 | |
| 3525 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) { |
| 3526 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode()); |
| 3527 | Register address = |
| 3528 | x0.Is(regs_.address()) ? regs_.scratch0() : regs_.address(); |
| 3529 | DCHECK(!address.Is(regs_.object())); |
| 3530 | DCHECK(!address.Is(x0)); |
| 3531 | __ Mov(address, regs_.address()); |
| 3532 | __ Mov(x0, regs_.object()); |
| 3533 | __ Mov(x1, address); |
| 3534 | __ Mov(x2, ExternalReference::isolate_address(isolate())); |
| 3535 | |
| 3536 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3537 | ExternalReference function = |
| 3538 | ExternalReference::incremental_marking_record_write_function( |
| 3539 | isolate()); |
| 3540 | __ CallCFunction(function, 3, 0); |
| 3541 | |
| 3542 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode()); |
| 3543 | } |
| 3544 | |
| 3545 | |
| 3546 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 3547 | MacroAssembler* masm, |
| 3548 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 3549 | Mode mode) { |
| 3550 | Label on_black; |
| 3551 | Label need_incremental; |
| 3552 | Label need_incremental_pop_scratch; |
| 3553 | |
| 3554 | Register mem_chunk = regs_.scratch0(); |
| 3555 | Register counter = regs_.scratch1(); |
| 3556 | __ Bic(mem_chunk, regs_.object(), Page::kPageAlignmentMask); |
| 3557 | __ Ldr(counter, |
| 3558 | MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset)); |
| 3559 | __ Subs(counter, counter, 1); |
| 3560 | __ Str(counter, |
| 3561 | MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset)); |
| 3562 | __ B(mi, &need_incremental); |
| 3563 | |
| 3564 | // If the object is not black we don't have to inform the incremental marker. |
| 3565 | __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black); |
| 3566 | |
| 3567 | regs_.Restore(masm); // Restore the extra scratch registers we used. |
| 3568 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 3569 | __ RememberedSetHelper(object(), address(), |
| 3570 | value(), // scratch1 |
| 3571 | save_fp_regs_mode(), MacroAssembler::kReturnAtEnd); |
| 3572 | } else { |
| 3573 | __ Ret(); |
| 3574 | } |
| 3575 | |
| 3576 | __ Bind(&on_black); |
| 3577 | // Get the value from the slot. |
| 3578 | Register val = regs_.scratch0(); |
| 3579 | __ Ldr(val, MemOperand(regs_.address())); |
| 3580 | |
| 3581 | if (mode == INCREMENTAL_COMPACTION) { |
| 3582 | Label ensure_not_white; |
| 3583 | |
| 3584 | __ CheckPageFlagClear(val, regs_.scratch1(), |
| 3585 | MemoryChunk::kEvacuationCandidateMask, |
| 3586 | &ensure_not_white); |
| 3587 | |
| 3588 | __ CheckPageFlagClear(regs_.object(), |
| 3589 | regs_.scratch1(), |
| 3590 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 3591 | &need_incremental); |
| 3592 | |
| 3593 | __ Bind(&ensure_not_white); |
| 3594 | } |
| 3595 | |
| 3596 | // We need extra registers for this, so we push the object and the address |
| 3597 | // register temporarily. |
| 3598 | __ Push(regs_.address(), regs_.object()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3599 | __ JumpIfWhite(val, |
| 3600 | regs_.scratch1(), // Scratch. |
| 3601 | regs_.object(), // Scratch. |
| 3602 | regs_.address(), // Scratch. |
| 3603 | regs_.scratch2(), // Scratch. |
| 3604 | &need_incremental_pop_scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3605 | __ Pop(regs_.object(), regs_.address()); |
| 3606 | |
| 3607 | regs_.Restore(masm); // Restore the extra scratch registers we used. |
| 3608 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 3609 | __ RememberedSetHelper(object(), address(), |
| 3610 | value(), // scratch1 |
| 3611 | save_fp_regs_mode(), MacroAssembler::kReturnAtEnd); |
| 3612 | } else { |
| 3613 | __ Ret(); |
| 3614 | } |
| 3615 | |
| 3616 | __ Bind(&need_incremental_pop_scratch); |
| 3617 | __ Pop(regs_.object(), regs_.address()); |
| 3618 | |
| 3619 | __ Bind(&need_incremental); |
| 3620 | // Fall through when we need to inform the incremental marker. |
| 3621 | } |
| 3622 | |
| 3623 | |
| 3624 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 3625 | Label skip_to_incremental_noncompacting; |
| 3626 | Label skip_to_incremental_compacting; |
| 3627 | |
| 3628 | // We patch these two first instructions back and forth between a nop and |
| 3629 | // real branch when we start and stop incremental heap marking. |
| 3630 | // Initially the stub is expected to be in STORE_BUFFER_ONLY mode, so 2 nops |
| 3631 | // are generated. |
| 3632 | // See RecordWriteStub::Patch for details. |
| 3633 | { |
| 3634 | InstructionAccurateScope scope(masm, 2); |
| 3635 | __ adr(xzr, &skip_to_incremental_noncompacting); |
| 3636 | __ adr(xzr, &skip_to_incremental_compacting); |
| 3637 | } |
| 3638 | |
| 3639 | if (remembered_set_action() == EMIT_REMEMBERED_SET) { |
| 3640 | __ RememberedSetHelper(object(), address(), |
| 3641 | value(), // scratch1 |
| 3642 | save_fp_regs_mode(), MacroAssembler::kReturnAtEnd); |
| 3643 | } |
| 3644 | __ Ret(); |
| 3645 | |
| 3646 | __ Bind(&skip_to_incremental_noncompacting); |
| 3647 | GenerateIncremental(masm, INCREMENTAL); |
| 3648 | |
| 3649 | __ Bind(&skip_to_incremental_compacting); |
| 3650 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 3651 | } |
| 3652 | |
| 3653 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3654 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
| 3655 | CEntryStub ces(isolate(), 1, kSaveFPRegs); |
| 3656 | __ Call(ces.GetCode(), RelocInfo::CODE_TARGET); |
| 3657 | int parameter_count_offset = |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 3658 | StubFailureTrampolineFrameConstants::kArgumentsLengthOffset; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3659 | __ Ldr(x1, MemOperand(fp, parameter_count_offset)); |
| 3660 | if (function_mode() == JS_FUNCTION_STUB_MODE) { |
| 3661 | __ Add(x1, x1, 1); |
| 3662 | } |
| 3663 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 3664 | __ Drop(x1); |
| 3665 | // Return to IC Miss stub, continuation still on stack. |
| 3666 | __ Ret(); |
| 3667 | } |
| 3668 | |
| 3669 | |
| 3670 | void LoadICTrampolineStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3671 | __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister()); |
| 3672 | LoadICStub stub(isolate(), state()); |
| 3673 | stub.GenerateForTrampoline(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3674 | } |
| 3675 | |
| 3676 | |
| 3677 | void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3678 | __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister()); |
| 3679 | KeyedLoadICStub stub(isolate(), state()); |
| 3680 | stub.GenerateForTrampoline(masm); |
| 3681 | } |
| 3682 | |
| 3683 | |
| 3684 | void CallICTrampolineStub::Generate(MacroAssembler* masm) { |
| 3685 | __ EmitLoadTypeFeedbackVector(x2); |
| 3686 | CallICStub stub(isolate(), state()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3687 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 3688 | } |
| 3689 | |
| 3690 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3691 | void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); } |
| 3692 | |
| 3693 | |
| 3694 | void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 3695 | GenerateImpl(masm, true); |
| 3696 | } |
| 3697 | |
| 3698 | |
| 3699 | static void HandleArrayCases(MacroAssembler* masm, Register feedback, |
| 3700 | Register receiver_map, Register scratch1, |
| 3701 | Register scratch2, bool is_polymorphic, |
| 3702 | Label* miss) { |
| 3703 | // feedback initially contains the feedback array |
| 3704 | Label next_loop, prepare_next; |
| 3705 | Label load_smi_map, compare_map; |
| 3706 | Label start_polymorphic; |
| 3707 | |
| 3708 | Register cached_map = scratch1; |
| 3709 | |
| 3710 | __ Ldr(cached_map, |
| 3711 | FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0))); |
| 3712 | __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset)); |
| 3713 | __ Cmp(receiver_map, cached_map); |
| 3714 | __ B(ne, &start_polymorphic); |
| 3715 | // found, now call handler. |
| 3716 | Register handler = feedback; |
| 3717 | __ Ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1))); |
| 3718 | __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag); |
| 3719 | __ Jump(feedback); |
| 3720 | |
| 3721 | Register length = scratch2; |
| 3722 | __ Bind(&start_polymorphic); |
| 3723 | __ Ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset)); |
| 3724 | if (!is_polymorphic) { |
| 3725 | __ Cmp(length, Operand(Smi::FromInt(2))); |
| 3726 | __ B(eq, miss); |
| 3727 | } |
| 3728 | |
| 3729 | Register too_far = length; |
| 3730 | Register pointer_reg = feedback; |
| 3731 | |
| 3732 | // +-----+------+------+-----+-----+ ... ----+ |
| 3733 | // | map | len | wm0 | h0 | wm1 | hN | |
| 3734 | // +-----+------+------+-----+-----+ ... ----+ |
| 3735 | // 0 1 2 len-1 |
| 3736 | // ^ ^ |
| 3737 | // | | |
| 3738 | // pointer_reg too_far |
| 3739 | // aka feedback scratch2 |
| 3740 | // also need receiver_map |
| 3741 | // use cached_map (scratch1) to look in the weak map values. |
| 3742 | __ Add(too_far, feedback, |
| 3743 | Operand::UntagSmiAndScale(length, kPointerSizeLog2)); |
| 3744 | __ Add(too_far, too_far, FixedArray::kHeaderSize - kHeapObjectTag); |
| 3745 | __ Add(pointer_reg, feedback, |
| 3746 | FixedArray::OffsetOfElementAt(2) - kHeapObjectTag); |
| 3747 | |
| 3748 | __ Bind(&next_loop); |
| 3749 | __ Ldr(cached_map, MemOperand(pointer_reg)); |
| 3750 | __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset)); |
| 3751 | __ Cmp(receiver_map, cached_map); |
| 3752 | __ B(ne, &prepare_next); |
| 3753 | __ Ldr(handler, MemOperand(pointer_reg, kPointerSize)); |
| 3754 | __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag); |
| 3755 | __ Jump(handler); |
| 3756 | |
| 3757 | __ Bind(&prepare_next); |
| 3758 | __ Add(pointer_reg, pointer_reg, kPointerSize * 2); |
| 3759 | __ Cmp(pointer_reg, too_far); |
| 3760 | __ B(lt, &next_loop); |
| 3761 | |
| 3762 | // We exhausted our array of map handler pairs. |
| 3763 | __ jmp(miss); |
| 3764 | } |
| 3765 | |
| 3766 | |
| 3767 | static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver, |
| 3768 | Register receiver_map, Register feedback, |
| 3769 | Register vector, Register slot, |
| 3770 | Register scratch, Label* compare_map, |
| 3771 | Label* load_smi_map, Label* try_array) { |
| 3772 | __ JumpIfSmi(receiver, load_smi_map); |
| 3773 | __ Ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 3774 | __ bind(compare_map); |
| 3775 | Register cached_map = scratch; |
| 3776 | // Move the weak map into the weak_cell register. |
| 3777 | __ Ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset)); |
| 3778 | __ Cmp(cached_map, receiver_map); |
| 3779 | __ B(ne, try_array); |
| 3780 | |
| 3781 | Register handler = feedback; |
| 3782 | __ Add(handler, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2)); |
| 3783 | __ Ldr(handler, |
| 3784 | FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize)); |
| 3785 | __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag); |
| 3786 | __ Jump(handler); |
| 3787 | } |
| 3788 | |
| 3789 | |
| 3790 | void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 3791 | Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // x1 |
| 3792 | Register name = LoadWithVectorDescriptor::NameRegister(); // x2 |
| 3793 | Register vector = LoadWithVectorDescriptor::VectorRegister(); // x3 |
| 3794 | Register slot = LoadWithVectorDescriptor::SlotRegister(); // x0 |
| 3795 | Register feedback = x4; |
| 3796 | Register receiver_map = x5; |
| 3797 | Register scratch1 = x6; |
| 3798 | |
| 3799 | __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2)); |
| 3800 | __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 3801 | |
| 3802 | // Try to quickly handle the monomorphic case without knowing for sure |
| 3803 | // if we have a weak cell in feedback. We do know it's safe to look |
| 3804 | // at WeakCell::kValueOffset. |
| 3805 | Label try_array, load_smi_map, compare_map; |
| 3806 | Label not_array, miss; |
| 3807 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 3808 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 3809 | |
| 3810 | // Is it a fixed array? |
| 3811 | __ Bind(&try_array); |
| 3812 | __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 3813 | __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array); |
| 3814 | HandleArrayCases(masm, feedback, receiver_map, scratch1, x7, true, &miss); |
| 3815 | |
| 3816 | __ Bind(¬_array); |
| 3817 | __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex, &miss); |
| 3818 | Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags( |
| 3819 | Code::ComputeHandlerFlags(Code::LOAD_IC)); |
| 3820 | masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags, |
| 3821 | receiver, name, feedback, |
| 3822 | receiver_map, scratch1, x7); |
| 3823 | |
| 3824 | __ Bind(&miss); |
| 3825 | LoadIC::GenerateMiss(masm); |
| 3826 | |
| 3827 | __ Bind(&load_smi_map); |
| 3828 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 3829 | __ jmp(&compare_map); |
| 3830 | } |
| 3831 | |
| 3832 | |
| 3833 | void KeyedLoadICStub::Generate(MacroAssembler* masm) { |
| 3834 | GenerateImpl(masm, false); |
| 3835 | } |
| 3836 | |
| 3837 | |
| 3838 | void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 3839 | GenerateImpl(masm, true); |
| 3840 | } |
| 3841 | |
| 3842 | |
| 3843 | void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 3844 | Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // x1 |
| 3845 | Register key = LoadWithVectorDescriptor::NameRegister(); // x2 |
| 3846 | Register vector = LoadWithVectorDescriptor::VectorRegister(); // x3 |
| 3847 | Register slot = LoadWithVectorDescriptor::SlotRegister(); // x0 |
| 3848 | Register feedback = x4; |
| 3849 | Register receiver_map = x5; |
| 3850 | Register scratch1 = x6; |
| 3851 | |
| 3852 | __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2)); |
| 3853 | __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 3854 | |
| 3855 | // Try to quickly handle the monomorphic case without knowing for sure |
| 3856 | // if we have a weak cell in feedback. We do know it's safe to look |
| 3857 | // at WeakCell::kValueOffset. |
| 3858 | Label try_array, load_smi_map, compare_map; |
| 3859 | Label not_array, miss; |
| 3860 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 3861 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 3862 | |
| 3863 | __ Bind(&try_array); |
| 3864 | // Is it a fixed array? |
| 3865 | __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 3866 | __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array); |
| 3867 | |
| 3868 | // We have a polymorphic element handler. |
| 3869 | Label polymorphic, try_poly_name; |
| 3870 | __ Bind(&polymorphic); |
| 3871 | HandleArrayCases(masm, feedback, receiver_map, scratch1, x7, true, &miss); |
| 3872 | |
| 3873 | __ Bind(¬_array); |
| 3874 | // Is it generic? |
| 3875 | __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex, |
| 3876 | &try_poly_name); |
| 3877 | Handle<Code> megamorphic_stub = |
| 3878 | KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState()); |
| 3879 | __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET); |
| 3880 | |
| 3881 | __ Bind(&try_poly_name); |
| 3882 | // We might have a name in feedback, and a fixed array in the next slot. |
| 3883 | __ Cmp(key, feedback); |
| 3884 | __ B(ne, &miss); |
| 3885 | // If the name comparison succeeded, we know we have a fixed array with |
| 3886 | // at least one map/handler pair. |
| 3887 | __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2)); |
| 3888 | __ Ldr(feedback, |
| 3889 | FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize)); |
| 3890 | HandleArrayCases(masm, feedback, receiver_map, scratch1, x7, false, &miss); |
| 3891 | |
| 3892 | __ Bind(&miss); |
| 3893 | KeyedLoadIC::GenerateMiss(masm); |
| 3894 | |
| 3895 | __ Bind(&load_smi_map); |
| 3896 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 3897 | __ jmp(&compare_map); |
| 3898 | } |
| 3899 | |
| 3900 | |
| 3901 | void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) { |
| 3902 | __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister()); |
| 3903 | VectorStoreICStub stub(isolate(), state()); |
| 3904 | stub.GenerateForTrampoline(masm); |
| 3905 | } |
| 3906 | |
| 3907 | |
| 3908 | void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) { |
| 3909 | __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister()); |
| 3910 | VectorKeyedStoreICStub stub(isolate(), state()); |
| 3911 | stub.GenerateForTrampoline(masm); |
| 3912 | } |
| 3913 | |
| 3914 | |
| 3915 | void VectorStoreICStub::Generate(MacroAssembler* masm) { |
| 3916 | GenerateImpl(masm, false); |
| 3917 | } |
| 3918 | |
| 3919 | |
| 3920 | void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 3921 | GenerateImpl(masm, true); |
| 3922 | } |
| 3923 | |
| 3924 | |
| 3925 | void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 3926 | Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // x1 |
| 3927 | Register key = VectorStoreICDescriptor::NameRegister(); // x2 |
| 3928 | Register vector = VectorStoreICDescriptor::VectorRegister(); // x3 |
| 3929 | Register slot = VectorStoreICDescriptor::SlotRegister(); // x4 |
| 3930 | DCHECK(VectorStoreICDescriptor::ValueRegister().is(x0)); // x0 |
| 3931 | Register feedback = x5; |
| 3932 | Register receiver_map = x6; |
| 3933 | Register scratch1 = x7; |
| 3934 | |
| 3935 | __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2)); |
| 3936 | __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 3937 | |
| 3938 | // Try to quickly handle the monomorphic case without knowing for sure |
| 3939 | // if we have a weak cell in feedback. We do know it's safe to look |
| 3940 | // at WeakCell::kValueOffset. |
| 3941 | Label try_array, load_smi_map, compare_map; |
| 3942 | Label not_array, miss; |
| 3943 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 3944 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 3945 | |
| 3946 | // Is it a fixed array? |
| 3947 | __ Bind(&try_array); |
| 3948 | __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 3949 | __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array); |
| 3950 | HandleArrayCases(masm, feedback, receiver_map, scratch1, x8, true, &miss); |
| 3951 | |
| 3952 | __ Bind(¬_array); |
| 3953 | __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex, &miss); |
| 3954 | Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags( |
| 3955 | Code::ComputeHandlerFlags(Code::STORE_IC)); |
| 3956 | masm->isolate()->stub_cache()->GenerateProbe(masm, Code::STORE_IC, code_flags, |
| 3957 | receiver, key, feedback, |
| 3958 | receiver_map, scratch1, x8); |
| 3959 | |
| 3960 | __ Bind(&miss); |
| 3961 | StoreIC::GenerateMiss(masm); |
| 3962 | |
| 3963 | __ Bind(&load_smi_map); |
| 3964 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 3965 | __ jmp(&compare_map); |
| 3966 | } |
| 3967 | |
| 3968 | |
| 3969 | void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) { |
| 3970 | GenerateImpl(masm, false); |
| 3971 | } |
| 3972 | |
| 3973 | |
| 3974 | void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 3975 | GenerateImpl(masm, true); |
| 3976 | } |
| 3977 | |
| 3978 | |
| 3979 | static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback, |
| 3980 | Register receiver_map, Register scratch1, |
| 3981 | Register scratch2, Label* miss) { |
| 3982 | // feedback initially contains the feedback array |
| 3983 | Label next_loop, prepare_next; |
| 3984 | Label start_polymorphic; |
| 3985 | Label transition_call; |
| 3986 | |
| 3987 | Register cached_map = scratch1; |
| 3988 | Register too_far = scratch2; |
| 3989 | Register pointer_reg = feedback; |
| 3990 | |
| 3991 | __ Ldr(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset)); |
| 3992 | |
| 3993 | // +-----+------+------+-----+-----+-----+ ... ----+ |
| 3994 | // | map | len | wm0 | wt0 | h0 | wm1 | hN | |
| 3995 | // +-----+------+------+-----+-----+ ----+ ... ----+ |
| 3996 | // 0 1 2 len-1 |
| 3997 | // ^ ^ |
| 3998 | // | | |
| 3999 | // pointer_reg too_far |
| 4000 | // aka feedback scratch2 |
| 4001 | // also need receiver_map |
| 4002 | // use cached_map (scratch1) to look in the weak map values. |
| 4003 | __ Add(too_far, feedback, |
| 4004 | Operand::UntagSmiAndScale(too_far, kPointerSizeLog2)); |
| 4005 | __ Add(too_far, too_far, FixedArray::kHeaderSize - kHeapObjectTag); |
| 4006 | __ Add(pointer_reg, feedback, |
| 4007 | FixedArray::OffsetOfElementAt(0) - kHeapObjectTag); |
| 4008 | |
| 4009 | __ Bind(&next_loop); |
| 4010 | __ Ldr(cached_map, MemOperand(pointer_reg)); |
| 4011 | __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset)); |
| 4012 | __ Cmp(receiver_map, cached_map); |
| 4013 | __ B(ne, &prepare_next); |
| 4014 | // Is it a transitioning store? |
| 4015 | __ Ldr(too_far, MemOperand(pointer_reg, kPointerSize)); |
| 4016 | __ CompareRoot(too_far, Heap::kUndefinedValueRootIndex); |
| 4017 | __ B(ne, &transition_call); |
| 4018 | |
| 4019 | __ Ldr(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2)); |
| 4020 | __ Add(pointer_reg, pointer_reg, Code::kHeaderSize - kHeapObjectTag); |
| 4021 | __ Jump(pointer_reg); |
| 4022 | |
| 4023 | __ Bind(&transition_call); |
| 4024 | __ Ldr(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset)); |
| 4025 | __ JumpIfSmi(too_far, miss); |
| 4026 | |
| 4027 | __ Ldr(receiver_map, MemOperand(pointer_reg, kPointerSize * 2)); |
| 4028 | // Load the map into the correct register. |
| 4029 | DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister())); |
| 4030 | __ mov(feedback, too_far); |
| 4031 | __ Add(receiver_map, receiver_map, Code::kHeaderSize - kHeapObjectTag); |
| 4032 | __ Jump(receiver_map); |
| 4033 | |
| 4034 | __ Bind(&prepare_next); |
| 4035 | __ Add(pointer_reg, pointer_reg, kPointerSize * 3); |
| 4036 | __ Cmp(pointer_reg, too_far); |
| 4037 | __ B(lt, &next_loop); |
| 4038 | |
| 4039 | // We exhausted our array of map handler pairs. |
| 4040 | __ jmp(miss); |
| 4041 | } |
| 4042 | |
| 4043 | |
| 4044 | void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4045 | Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // x1 |
| 4046 | Register key = VectorStoreICDescriptor::NameRegister(); // x2 |
| 4047 | Register vector = VectorStoreICDescriptor::VectorRegister(); // x3 |
| 4048 | Register slot = VectorStoreICDescriptor::SlotRegister(); // x4 |
| 4049 | DCHECK(VectorStoreICDescriptor::ValueRegister().is(x0)); // x0 |
| 4050 | Register feedback = x5; |
| 4051 | Register receiver_map = x6; |
| 4052 | Register scratch1 = x7; |
| 4053 | |
| 4054 | __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2)); |
| 4055 | __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 4056 | |
| 4057 | // Try to quickly handle the monomorphic case without knowing for sure |
| 4058 | // if we have a weak cell in feedback. We do know it's safe to look |
| 4059 | // at WeakCell::kValueOffset. |
| 4060 | Label try_array, load_smi_map, compare_map; |
| 4061 | Label not_array, miss; |
| 4062 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 4063 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 4064 | |
| 4065 | __ Bind(&try_array); |
| 4066 | // Is it a fixed array? |
| 4067 | __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 4068 | __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array); |
| 4069 | |
| 4070 | // We have a polymorphic element handler. |
| 4071 | Label try_poly_name; |
| 4072 | HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, x8, &miss); |
| 4073 | |
| 4074 | __ Bind(¬_array); |
| 4075 | // Is it generic? |
| 4076 | __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex, |
| 4077 | &try_poly_name); |
| 4078 | Handle<Code> megamorphic_stub = |
| 4079 | KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState()); |
| 4080 | __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET); |
| 4081 | |
| 4082 | __ Bind(&try_poly_name); |
| 4083 | // We might have a name in feedback, and a fixed array in the next slot. |
| 4084 | __ Cmp(key, feedback); |
| 4085 | __ B(ne, &miss); |
| 4086 | // If the name comparison succeeded, we know we have a fixed array with |
| 4087 | // at least one map/handler pair. |
| 4088 | __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2)); |
| 4089 | __ Ldr(feedback, |
| 4090 | FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize)); |
| 4091 | HandleArrayCases(masm, feedback, receiver_map, scratch1, x8, false, &miss); |
| 4092 | |
| 4093 | __ Bind(&miss); |
| 4094 | KeyedStoreIC::GenerateMiss(masm); |
| 4095 | |
| 4096 | __ Bind(&load_smi_map); |
| 4097 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 4098 | __ jmp(&compare_map); |
| 4099 | } |
| 4100 | |
| 4101 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4102 | // The entry hook is a "BumpSystemStackPointer" instruction (sub), followed by |
| 4103 | // a "Push lr" instruction, followed by a call. |
| 4104 | static const unsigned int kProfileEntryHookCallSize = |
| 4105 | Assembler::kCallSizeWithRelocation + (2 * kInstructionSize); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4106 | |
| 4107 | |
| 4108 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 4109 | if (masm->isolate()->function_entry_hook() != NULL) { |
| 4110 | ProfileEntryHookStub stub(masm->isolate()); |
| 4111 | Assembler::BlockConstPoolScope no_const_pools(masm); |
| 4112 | DontEmitDebugCodeScope no_debug_code(masm); |
| 4113 | Label entry_hook_call_start; |
| 4114 | __ Bind(&entry_hook_call_start); |
| 4115 | __ Push(lr); |
| 4116 | __ CallStub(&stub); |
| 4117 | DCHECK(masm->SizeOfCodeGeneratedSince(&entry_hook_call_start) == |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4118 | kProfileEntryHookCallSize); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4119 | |
| 4120 | __ Pop(lr); |
| 4121 | } |
| 4122 | } |
| 4123 | |
| 4124 | |
| 4125 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 4126 | MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm); |
| 4127 | |
| 4128 | // Save all kCallerSaved registers (including lr), since this can be called |
| 4129 | // from anywhere. |
| 4130 | // TODO(jbramley): What about FP registers? |
| 4131 | __ PushCPURegList(kCallerSaved); |
| 4132 | DCHECK(kCallerSaved.IncludesAliasOf(lr)); |
| 4133 | const int kNumSavedRegs = kCallerSaved.Count(); |
| 4134 | |
| 4135 | // Compute the function's address as the first argument. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4136 | __ Sub(x0, lr, kProfileEntryHookCallSize); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4137 | |
| 4138 | #if V8_HOST_ARCH_ARM64 |
| 4139 | uintptr_t entry_hook = |
| 4140 | reinterpret_cast<uintptr_t>(isolate()->function_entry_hook()); |
| 4141 | __ Mov(x10, entry_hook); |
| 4142 | #else |
| 4143 | // Under the simulator we need to indirect the entry hook through a trampoline |
| 4144 | // function at a known address. |
| 4145 | ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline)); |
| 4146 | __ Mov(x10, Operand(ExternalReference(&dispatcher, |
| 4147 | ExternalReference::BUILTIN_CALL, |
| 4148 | isolate()))); |
| 4149 | // It additionally takes an isolate as a third parameter |
| 4150 | __ Mov(x2, ExternalReference::isolate_address(isolate())); |
| 4151 | #endif |
| 4152 | |
| 4153 | // The caller's return address is above the saved temporaries. |
| 4154 | // Grab its location for the second argument to the hook. |
| 4155 | __ Add(x1, __ StackPointer(), kNumSavedRegs * kPointerSize); |
| 4156 | |
| 4157 | { |
| 4158 | // Create a dummy frame, as CallCFunction requires this. |
| 4159 | FrameScope frame(masm, StackFrame::MANUAL); |
| 4160 | __ CallCFunction(x10, 2, 0); |
| 4161 | } |
| 4162 | |
| 4163 | __ PopCPURegList(kCallerSaved); |
| 4164 | __ Ret(); |
| 4165 | } |
| 4166 | |
| 4167 | |
| 4168 | void DirectCEntryStub::Generate(MacroAssembler* masm) { |
| 4169 | // When calling into C++ code the stack pointer must be csp. |
| 4170 | // Therefore this code must use csp for peek/poke operations when the |
| 4171 | // stub is generated. When the stub is called |
| 4172 | // (via DirectCEntryStub::GenerateCall), the caller must setup an ExitFrame |
| 4173 | // and configure the stack pointer *before* doing the call. |
| 4174 | const Register old_stack_pointer = __ StackPointer(); |
| 4175 | __ SetStackPointer(csp); |
| 4176 | |
| 4177 | // Put return address on the stack (accessible to GC through exit frame pc). |
| 4178 | __ Poke(lr, 0); |
| 4179 | // Call the C++ function. |
| 4180 | __ Blr(x10); |
| 4181 | // Return to calling code. |
| 4182 | __ Peek(lr, 0); |
| 4183 | __ AssertFPCRState(); |
| 4184 | __ Ret(); |
| 4185 | |
| 4186 | __ SetStackPointer(old_stack_pointer); |
| 4187 | } |
| 4188 | |
| 4189 | void DirectCEntryStub::GenerateCall(MacroAssembler* masm, |
| 4190 | Register target) { |
| 4191 | // Make sure the caller configured the stack pointer (see comment in |
| 4192 | // DirectCEntryStub::Generate). |
| 4193 | DCHECK(csp.Is(__ StackPointer())); |
| 4194 | |
| 4195 | intptr_t code = |
| 4196 | reinterpret_cast<intptr_t>(GetCode().location()); |
| 4197 | __ Mov(lr, Operand(code, RelocInfo::CODE_TARGET)); |
| 4198 | __ Mov(x10, target); |
| 4199 | // Branch to the stub. |
| 4200 | __ Blr(lr); |
| 4201 | } |
| 4202 | |
| 4203 | |
| 4204 | // Probe the name dictionary in the 'elements' register. |
| 4205 | // Jump to the 'done' label if a property with the given name is found. |
| 4206 | // Jump to the 'miss' label otherwise. |
| 4207 | // |
| 4208 | // If lookup was successful 'scratch2' will be equal to elements + 4 * index. |
| 4209 | // 'elements' and 'name' registers are preserved on miss. |
| 4210 | void NameDictionaryLookupStub::GeneratePositiveLookup( |
| 4211 | MacroAssembler* masm, |
| 4212 | Label* miss, |
| 4213 | Label* done, |
| 4214 | Register elements, |
| 4215 | Register name, |
| 4216 | Register scratch1, |
| 4217 | Register scratch2) { |
| 4218 | DCHECK(!AreAliased(elements, name, scratch1, scratch2)); |
| 4219 | |
| 4220 | // Assert that name contains a string. |
| 4221 | __ AssertName(name); |
| 4222 | |
| 4223 | // Compute the capacity mask. |
| 4224 | __ Ldrsw(scratch1, UntagSmiFieldMemOperand(elements, kCapacityOffset)); |
| 4225 | __ Sub(scratch1, scratch1, 1); |
| 4226 | |
| 4227 | // Generate an unrolled loop that performs a few probes before giving up. |
| 4228 | for (int i = 0; i < kInlinedProbes; i++) { |
| 4229 | // Compute the masked index: (hash + i + i * i) & mask. |
| 4230 | __ Ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset)); |
| 4231 | if (i > 0) { |
| 4232 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 4233 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 4234 | // shifted in the following and instruction. |
| 4235 | DCHECK(NameDictionary::GetProbeOffset(i) < |
| 4236 | 1 << (32 - Name::kHashFieldOffset)); |
| 4237 | __ Add(scratch2, scratch2, Operand( |
| 4238 | NameDictionary::GetProbeOffset(i) << Name::kHashShift)); |
| 4239 | } |
| 4240 | __ And(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift)); |
| 4241 | |
| 4242 | // Scale the index by multiplying by the element size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4243 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4244 | __ Add(scratch2, scratch2, Operand(scratch2, LSL, 1)); |
| 4245 | |
| 4246 | // Check if the key is identical to the name. |
| 4247 | UseScratchRegisterScope temps(masm); |
| 4248 | Register scratch3 = temps.AcquireX(); |
| 4249 | __ Add(scratch2, elements, Operand(scratch2, LSL, kPointerSizeLog2)); |
| 4250 | __ Ldr(scratch3, FieldMemOperand(scratch2, kElementsStartOffset)); |
| 4251 | __ Cmp(name, scratch3); |
| 4252 | __ B(eq, done); |
| 4253 | } |
| 4254 | |
| 4255 | // The inlined probes didn't find the entry. |
| 4256 | // Call the complete stub to scan the whole dictionary. |
| 4257 | |
| 4258 | CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6); |
| 4259 | spill_list.Combine(lr); |
| 4260 | spill_list.Remove(scratch1); |
| 4261 | spill_list.Remove(scratch2); |
| 4262 | |
| 4263 | __ PushCPURegList(spill_list); |
| 4264 | |
| 4265 | if (name.is(x0)) { |
| 4266 | DCHECK(!elements.is(x1)); |
| 4267 | __ Mov(x1, name); |
| 4268 | __ Mov(x0, elements); |
| 4269 | } else { |
| 4270 | __ Mov(x0, elements); |
| 4271 | __ Mov(x1, name); |
| 4272 | } |
| 4273 | |
| 4274 | Label not_found; |
| 4275 | NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP); |
| 4276 | __ CallStub(&stub); |
| 4277 | __ Cbz(x0, ¬_found); |
| 4278 | __ Mov(scratch2, x2); // Move entry index into scratch2. |
| 4279 | __ PopCPURegList(spill_list); |
| 4280 | __ B(done); |
| 4281 | |
| 4282 | __ Bind(¬_found); |
| 4283 | __ PopCPURegList(spill_list); |
| 4284 | __ B(miss); |
| 4285 | } |
| 4286 | |
| 4287 | |
| 4288 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 4289 | Label* miss, |
| 4290 | Label* done, |
| 4291 | Register receiver, |
| 4292 | Register properties, |
| 4293 | Handle<Name> name, |
| 4294 | Register scratch0) { |
| 4295 | DCHECK(!AreAliased(receiver, properties, scratch0)); |
| 4296 | DCHECK(name->IsUniqueName()); |
| 4297 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 4298 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 4299 | // undefined value), it guarantees the hash table doesn't contain the |
| 4300 | // property. It's true even if some slots represent deleted properties |
| 4301 | // (their names are the hole value). |
| 4302 | for (int i = 0; i < kInlinedProbes; i++) { |
| 4303 | // scratch0 points to properties hash. |
| 4304 | // Compute the masked index: (hash + i + i * i) & mask. |
| 4305 | Register index = scratch0; |
| 4306 | // Capacity is smi 2^n. |
| 4307 | __ Ldrsw(index, UntagSmiFieldMemOperand(properties, kCapacityOffset)); |
| 4308 | __ Sub(index, index, 1); |
| 4309 | __ And(index, index, name->Hash() + NameDictionary::GetProbeOffset(i)); |
| 4310 | |
| 4311 | // Scale the index by multiplying by the entry size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4312 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4313 | __ Add(index, index, Operand(index, LSL, 1)); // index *= 3. |
| 4314 | |
| 4315 | Register entity_name = scratch0; |
| 4316 | // Having undefined at this place means the name is not contained. |
| 4317 | Register tmp = index; |
| 4318 | __ Add(tmp, properties, Operand(index, LSL, kPointerSizeLog2)); |
| 4319 | __ Ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset)); |
| 4320 | |
| 4321 | __ JumpIfRoot(entity_name, Heap::kUndefinedValueRootIndex, done); |
| 4322 | |
| 4323 | // Stop if found the property. |
| 4324 | __ Cmp(entity_name, Operand(name)); |
| 4325 | __ B(eq, miss); |
| 4326 | |
| 4327 | Label good; |
| 4328 | __ JumpIfRoot(entity_name, Heap::kTheHoleValueRootIndex, &good); |
| 4329 | |
| 4330 | // Check if the entry name is not a unique name. |
| 4331 | __ Ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset)); |
| 4332 | __ Ldrb(entity_name, |
| 4333 | FieldMemOperand(entity_name, Map::kInstanceTypeOffset)); |
| 4334 | __ JumpIfNotUniqueNameInstanceType(entity_name, miss); |
| 4335 | __ Bind(&good); |
| 4336 | } |
| 4337 | |
| 4338 | CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6); |
| 4339 | spill_list.Combine(lr); |
| 4340 | spill_list.Remove(scratch0); // Scratch registers don't need to be preserved. |
| 4341 | |
| 4342 | __ PushCPURegList(spill_list); |
| 4343 | |
| 4344 | __ Ldr(x0, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 4345 | __ Mov(x1, Operand(name)); |
| 4346 | NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP); |
| 4347 | __ CallStub(&stub); |
| 4348 | // Move stub return value to scratch0. Note that scratch0 is not included in |
| 4349 | // spill_list and won't be clobbered by PopCPURegList. |
| 4350 | __ Mov(scratch0, x0); |
| 4351 | __ PopCPURegList(spill_list); |
| 4352 | |
| 4353 | __ Cbz(scratch0, done); |
| 4354 | __ B(miss); |
| 4355 | } |
| 4356 | |
| 4357 | |
| 4358 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
| 4359 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 4360 | // we cannot call anything that could cause a GC from this stub. |
| 4361 | // |
| 4362 | // Arguments are in x0 and x1: |
| 4363 | // x0: property dictionary. |
| 4364 | // x1: the name of the property we are looking for. |
| 4365 | // |
| 4366 | // Return value is in x0 and is zero if lookup failed, non zero otherwise. |
| 4367 | // If the lookup is successful, x2 will contains the index of the entry. |
| 4368 | |
| 4369 | Register result = x0; |
| 4370 | Register dictionary = x0; |
| 4371 | Register key = x1; |
| 4372 | Register index = x2; |
| 4373 | Register mask = x3; |
| 4374 | Register hash = x4; |
| 4375 | Register undefined = x5; |
| 4376 | Register entry_key = x6; |
| 4377 | |
| 4378 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 4379 | |
| 4380 | __ Ldrsw(mask, UntagSmiFieldMemOperand(dictionary, kCapacityOffset)); |
| 4381 | __ Sub(mask, mask, 1); |
| 4382 | |
| 4383 | __ Ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset)); |
| 4384 | __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex); |
| 4385 | |
| 4386 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 4387 | // Compute the masked index: (hash + i + i * i) & mask. |
| 4388 | // Capacity is smi 2^n. |
| 4389 | if (i > 0) { |
| 4390 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 4391 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 4392 | // shifted in the following and instruction. |
| 4393 | DCHECK(NameDictionary::GetProbeOffset(i) < |
| 4394 | 1 << (32 - Name::kHashFieldOffset)); |
| 4395 | __ Add(index, hash, |
| 4396 | NameDictionary::GetProbeOffset(i) << Name::kHashShift); |
| 4397 | } else { |
| 4398 | __ Mov(index, hash); |
| 4399 | } |
| 4400 | __ And(index, mask, Operand(index, LSR, Name::kHashShift)); |
| 4401 | |
| 4402 | // Scale the index by multiplying by the entry size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4403 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4404 | __ Add(index, index, Operand(index, LSL, 1)); // index *= 3. |
| 4405 | |
| 4406 | __ Add(index, dictionary, Operand(index, LSL, kPointerSizeLog2)); |
| 4407 | __ Ldr(entry_key, FieldMemOperand(index, kElementsStartOffset)); |
| 4408 | |
| 4409 | // Having undefined at this place means the name is not contained. |
| 4410 | __ Cmp(entry_key, undefined); |
| 4411 | __ B(eq, ¬_in_dictionary); |
| 4412 | |
| 4413 | // Stop if found the property. |
| 4414 | __ Cmp(entry_key, key); |
| 4415 | __ B(eq, &in_dictionary); |
| 4416 | |
| 4417 | if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) { |
| 4418 | // Check if the entry name is not a unique name. |
| 4419 | __ Ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset)); |
| 4420 | __ Ldrb(entry_key, FieldMemOperand(entry_key, Map::kInstanceTypeOffset)); |
| 4421 | __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary); |
| 4422 | } |
| 4423 | } |
| 4424 | |
| 4425 | __ Bind(&maybe_in_dictionary); |
| 4426 | // If we are doing negative lookup then probing failure should be |
| 4427 | // treated as a lookup success. For positive lookup, probing failure |
| 4428 | // should be treated as lookup failure. |
| 4429 | if (mode() == POSITIVE_LOOKUP) { |
| 4430 | __ Mov(result, 0); |
| 4431 | __ Ret(); |
| 4432 | } |
| 4433 | |
| 4434 | __ Bind(&in_dictionary); |
| 4435 | __ Mov(result, 1); |
| 4436 | __ Ret(); |
| 4437 | |
| 4438 | __ Bind(¬_in_dictionary); |
| 4439 | __ Mov(result, 0); |
| 4440 | __ Ret(); |
| 4441 | } |
| 4442 | |
| 4443 | |
| 4444 | template<class T> |
| 4445 | static void CreateArrayDispatch(MacroAssembler* masm, |
| 4446 | AllocationSiteOverrideMode mode) { |
| 4447 | ASM_LOCATION("CreateArrayDispatch"); |
| 4448 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 4449 | T stub(masm->isolate(), GetInitialFastElementsKind(), mode); |
| 4450 | __ TailCallStub(&stub); |
| 4451 | |
| 4452 | } else if (mode == DONT_OVERRIDE) { |
| 4453 | Register kind = x3; |
| 4454 | int last_index = |
| 4455 | GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND); |
| 4456 | for (int i = 0; i <= last_index; ++i) { |
| 4457 | Label next; |
| 4458 | ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i); |
| 4459 | // TODO(jbramley): Is this the best way to handle this? Can we make the |
| 4460 | // tail calls conditional, rather than hopping over each one? |
| 4461 | __ CompareAndBranch(kind, candidate_kind, ne, &next); |
| 4462 | T stub(masm->isolate(), candidate_kind); |
| 4463 | __ TailCallStub(&stub); |
| 4464 | __ Bind(&next); |
| 4465 | } |
| 4466 | |
| 4467 | // If we reached this point there is a problem. |
| 4468 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 4469 | |
| 4470 | } else { |
| 4471 | UNREACHABLE(); |
| 4472 | } |
| 4473 | } |
| 4474 | |
| 4475 | |
| 4476 | // TODO(jbramley): If this needs to be a special case, make it a proper template |
| 4477 | // specialization, and not a separate function. |
| 4478 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm, |
| 4479 | AllocationSiteOverrideMode mode) { |
| 4480 | ASM_LOCATION("CreateArrayDispatchOneArgument"); |
| 4481 | // x0 - argc |
| 4482 | // x1 - constructor? |
| 4483 | // x2 - allocation site (if mode != DISABLE_ALLOCATION_SITES) |
| 4484 | // x3 - kind (if mode != DISABLE_ALLOCATION_SITES) |
| 4485 | // sp[0] - last argument |
| 4486 | |
| 4487 | Register allocation_site = x2; |
| 4488 | Register kind = x3; |
| 4489 | |
| 4490 | Label normal_sequence; |
| 4491 | if (mode == DONT_OVERRIDE) { |
| 4492 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 4493 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 4494 | STATIC_ASSERT(FAST_ELEMENTS == 2); |
| 4495 | STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 4496 | STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 4497 | STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
| 4498 | |
| 4499 | // Is the low bit set? If so, the array is holey. |
| 4500 | __ Tbnz(kind, 0, &normal_sequence); |
| 4501 | } |
| 4502 | |
| 4503 | // Look at the last argument. |
| 4504 | // TODO(jbramley): What does a 0 argument represent? |
| 4505 | __ Peek(x10, 0); |
| 4506 | __ Cbz(x10, &normal_sequence); |
| 4507 | |
| 4508 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 4509 | ElementsKind initial = GetInitialFastElementsKind(); |
| 4510 | ElementsKind holey_initial = GetHoleyElementsKind(initial); |
| 4511 | |
| 4512 | ArraySingleArgumentConstructorStub stub_holey(masm->isolate(), |
| 4513 | holey_initial, |
| 4514 | DISABLE_ALLOCATION_SITES); |
| 4515 | __ TailCallStub(&stub_holey); |
| 4516 | |
| 4517 | __ Bind(&normal_sequence); |
| 4518 | ArraySingleArgumentConstructorStub stub(masm->isolate(), |
| 4519 | initial, |
| 4520 | DISABLE_ALLOCATION_SITES); |
| 4521 | __ TailCallStub(&stub); |
| 4522 | } else if (mode == DONT_OVERRIDE) { |
| 4523 | // We are going to create a holey array, but our kind is non-holey. |
| 4524 | // Fix kind and retry (only if we have an allocation site in the slot). |
| 4525 | __ Orr(kind, kind, 1); |
| 4526 | |
| 4527 | if (FLAG_debug_code) { |
| 4528 | __ Ldr(x10, FieldMemOperand(allocation_site, 0)); |
| 4529 | __ JumpIfNotRoot(x10, Heap::kAllocationSiteMapRootIndex, |
| 4530 | &normal_sequence); |
| 4531 | __ Assert(eq, kExpectedAllocationSite); |
| 4532 | } |
| 4533 | |
| 4534 | // Save the resulting elements kind in type info. We can't just store 'kind' |
| 4535 | // in the AllocationSite::transition_info field because elements kind is |
| 4536 | // restricted to a portion of the field; upper bits need to be left alone. |
| 4537 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 4538 | __ Ldr(x11, FieldMemOperand(allocation_site, |
| 4539 | AllocationSite::kTransitionInfoOffset)); |
| 4540 | __ Add(x11, x11, Smi::FromInt(kFastElementsKindPackedToHoley)); |
| 4541 | __ Str(x11, FieldMemOperand(allocation_site, |
| 4542 | AllocationSite::kTransitionInfoOffset)); |
| 4543 | |
| 4544 | __ Bind(&normal_sequence); |
| 4545 | int last_index = |
| 4546 | GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND); |
| 4547 | for (int i = 0; i <= last_index; ++i) { |
| 4548 | Label next; |
| 4549 | ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i); |
| 4550 | __ CompareAndBranch(kind, candidate_kind, ne, &next); |
| 4551 | ArraySingleArgumentConstructorStub stub(masm->isolate(), candidate_kind); |
| 4552 | __ TailCallStub(&stub); |
| 4553 | __ Bind(&next); |
| 4554 | } |
| 4555 | |
| 4556 | // If we reached this point there is a problem. |
| 4557 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 4558 | } else { |
| 4559 | UNREACHABLE(); |
| 4560 | } |
| 4561 | } |
| 4562 | |
| 4563 | |
| 4564 | template<class T> |
| 4565 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 4566 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 4567 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4568 | for (int i = 0; i <= to_index; ++i) { |
| 4569 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4570 | T stub(isolate, kind); |
| 4571 | stub.GetCode(); |
| 4572 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
| 4573 | T stub1(isolate, kind, DISABLE_ALLOCATION_SITES); |
| 4574 | stub1.GetCode(); |
| 4575 | } |
| 4576 | } |
| 4577 | } |
| 4578 | |
| 4579 | |
| 4580 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 4581 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 4582 | isolate); |
| 4583 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 4584 | isolate); |
| 4585 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 4586 | isolate); |
| 4587 | } |
| 4588 | |
| 4589 | |
| 4590 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 4591 | Isolate* isolate) { |
| 4592 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 4593 | for (int i = 0; i < 2; i++) { |
| 4594 | // For internal arrays we only need a few things |
| 4595 | InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]); |
| 4596 | stubh1.GetCode(); |
| 4597 | InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]); |
| 4598 | stubh2.GetCode(); |
| 4599 | InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]); |
| 4600 | stubh3.GetCode(); |
| 4601 | } |
| 4602 | } |
| 4603 | |
| 4604 | |
| 4605 | void ArrayConstructorStub::GenerateDispatchToArrayStub( |
| 4606 | MacroAssembler* masm, |
| 4607 | AllocationSiteOverrideMode mode) { |
| 4608 | Register argc = x0; |
| 4609 | if (argument_count() == ANY) { |
| 4610 | Label zero_case, n_case; |
| 4611 | __ Cbz(argc, &zero_case); |
| 4612 | __ Cmp(argc, 1); |
| 4613 | __ B(ne, &n_case); |
| 4614 | |
| 4615 | // One argument. |
| 4616 | CreateArrayDispatchOneArgument(masm, mode); |
| 4617 | |
| 4618 | __ Bind(&zero_case); |
| 4619 | // No arguments. |
| 4620 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 4621 | |
| 4622 | __ Bind(&n_case); |
| 4623 | // N arguments. |
| 4624 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 4625 | |
| 4626 | } else if (argument_count() == NONE) { |
| 4627 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 4628 | } else if (argument_count() == ONE) { |
| 4629 | CreateArrayDispatchOneArgument(masm, mode); |
| 4630 | } else if (argument_count() == MORE_THAN_ONE) { |
| 4631 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 4632 | } else { |
| 4633 | UNREACHABLE(); |
| 4634 | } |
| 4635 | } |
| 4636 | |
| 4637 | |
| 4638 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 4639 | ASM_LOCATION("ArrayConstructorStub::Generate"); |
| 4640 | // ----------- S t a t e ------------- |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4641 | // -- x0 : argc (only if argument_count() is ANY or MORE_THAN_ONE) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4642 | // -- x1 : constructor |
| 4643 | // -- x2 : AllocationSite or undefined |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4644 | // -- x3 : new target |
| 4645 | // -- sp[0] : last argument |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4646 | // ----------------------------------- |
| 4647 | Register constructor = x1; |
| 4648 | Register allocation_site = x2; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4649 | Register new_target = x3; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4650 | |
| 4651 | if (FLAG_debug_code) { |
| 4652 | // The array construct code is only set for the global and natives |
| 4653 | // builtin Array functions which always have maps. |
| 4654 | |
| 4655 | Label unexpected_map, map_ok; |
| 4656 | // Initial map for the builtin Array function should be a map. |
| 4657 | __ Ldr(x10, FieldMemOperand(constructor, |
| 4658 | JSFunction::kPrototypeOrInitialMapOffset)); |
| 4659 | // Will both indicate a NULL and a Smi. |
| 4660 | __ JumpIfSmi(x10, &unexpected_map); |
| 4661 | __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok); |
| 4662 | __ Bind(&unexpected_map); |
| 4663 | __ Abort(kUnexpectedInitialMapForArrayFunction); |
| 4664 | __ Bind(&map_ok); |
| 4665 | |
| 4666 | // We should either have undefined in the allocation_site register or a |
| 4667 | // valid AllocationSite. |
| 4668 | __ AssertUndefinedOrAllocationSite(allocation_site, x10); |
| 4669 | } |
| 4670 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4671 | // Enter the context of the Array function. |
| 4672 | __ Ldr(cp, FieldMemOperand(x1, JSFunction::kContextOffset)); |
| 4673 | |
| 4674 | Label subclassing; |
| 4675 | __ Cmp(new_target, constructor); |
| 4676 | __ B(ne, &subclassing); |
| 4677 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4678 | Register kind = x3; |
| 4679 | Label no_info; |
| 4680 | // Get the elements kind and case on that. |
| 4681 | __ JumpIfRoot(allocation_site, Heap::kUndefinedValueRootIndex, &no_info); |
| 4682 | |
| 4683 | __ Ldrsw(kind, |
| 4684 | UntagSmiFieldMemOperand(allocation_site, |
| 4685 | AllocationSite::kTransitionInfoOffset)); |
| 4686 | __ And(kind, kind, AllocationSite::ElementsKindBits::kMask); |
| 4687 | GenerateDispatchToArrayStub(masm, DONT_OVERRIDE); |
| 4688 | |
| 4689 | __ Bind(&no_info); |
| 4690 | GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4691 | |
| 4692 | // Subclassing support. |
| 4693 | __ Bind(&subclassing); |
| 4694 | switch (argument_count()) { |
| 4695 | case ANY: |
| 4696 | case MORE_THAN_ONE: |
| 4697 | __ Poke(constructor, Operand(x0, LSL, kPointerSizeLog2)); |
| 4698 | __ Add(x0, x0, Operand(3)); |
| 4699 | break; |
| 4700 | case NONE: |
| 4701 | __ Poke(constructor, 0 * kPointerSize); |
| 4702 | __ Mov(x0, Operand(3)); |
| 4703 | break; |
| 4704 | case ONE: |
| 4705 | __ Poke(constructor, 1 * kPointerSize); |
| 4706 | __ Mov(x0, Operand(4)); |
| 4707 | break; |
| 4708 | } |
| 4709 | __ Push(new_target, allocation_site); |
| 4710 | __ JumpToExternalReference(ExternalReference(Runtime::kNewArray, isolate())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4711 | } |
| 4712 | |
| 4713 | |
| 4714 | void InternalArrayConstructorStub::GenerateCase( |
| 4715 | MacroAssembler* masm, ElementsKind kind) { |
| 4716 | Label zero_case, n_case; |
| 4717 | Register argc = x0; |
| 4718 | |
| 4719 | __ Cbz(argc, &zero_case); |
| 4720 | __ CompareAndBranch(argc, 1, ne, &n_case); |
| 4721 | |
| 4722 | // One argument. |
| 4723 | if (IsFastPackedElementsKind(kind)) { |
| 4724 | Label packed_case; |
| 4725 | |
| 4726 | // We might need to create a holey array; look at the first argument. |
| 4727 | __ Peek(x10, 0); |
| 4728 | __ Cbz(x10, &packed_case); |
| 4729 | |
| 4730 | InternalArraySingleArgumentConstructorStub |
| 4731 | stub1_holey(isolate(), GetHoleyElementsKind(kind)); |
| 4732 | __ TailCallStub(&stub1_holey); |
| 4733 | |
| 4734 | __ Bind(&packed_case); |
| 4735 | } |
| 4736 | InternalArraySingleArgumentConstructorStub stub1(isolate(), kind); |
| 4737 | __ TailCallStub(&stub1); |
| 4738 | |
| 4739 | __ Bind(&zero_case); |
| 4740 | // No arguments. |
| 4741 | InternalArrayNoArgumentConstructorStub stub0(isolate(), kind); |
| 4742 | __ TailCallStub(&stub0); |
| 4743 | |
| 4744 | __ Bind(&n_case); |
| 4745 | // N arguments. |
| 4746 | InternalArrayNArgumentsConstructorStub stubN(isolate(), kind); |
| 4747 | __ TailCallStub(&stubN); |
| 4748 | } |
| 4749 | |
| 4750 | |
| 4751 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 4752 | // ----------- S t a t e ------------- |
| 4753 | // -- x0 : argc |
| 4754 | // -- x1 : constructor |
| 4755 | // -- sp[0] : return address |
| 4756 | // -- sp[4] : last argument |
| 4757 | // ----------------------------------- |
| 4758 | |
| 4759 | Register constructor = x1; |
| 4760 | |
| 4761 | if (FLAG_debug_code) { |
| 4762 | // The array construct code is only set for the global and natives |
| 4763 | // builtin Array functions which always have maps. |
| 4764 | |
| 4765 | Label unexpected_map, map_ok; |
| 4766 | // Initial map for the builtin Array function should be a map. |
| 4767 | __ Ldr(x10, FieldMemOperand(constructor, |
| 4768 | JSFunction::kPrototypeOrInitialMapOffset)); |
| 4769 | // Will both indicate a NULL and a Smi. |
| 4770 | __ JumpIfSmi(x10, &unexpected_map); |
| 4771 | __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok); |
| 4772 | __ Bind(&unexpected_map); |
| 4773 | __ Abort(kUnexpectedInitialMapForArrayFunction); |
| 4774 | __ Bind(&map_ok); |
| 4775 | } |
| 4776 | |
| 4777 | Register kind = w3; |
| 4778 | // Figure out the right elements kind |
| 4779 | __ Ldr(x10, FieldMemOperand(constructor, |
| 4780 | JSFunction::kPrototypeOrInitialMapOffset)); |
| 4781 | |
| 4782 | // Retrieve elements_kind from map. |
| 4783 | __ LoadElementsKindFromMap(kind, x10); |
| 4784 | |
| 4785 | if (FLAG_debug_code) { |
| 4786 | Label done; |
| 4787 | __ Cmp(x3, FAST_ELEMENTS); |
| 4788 | __ Ccmp(x3, FAST_HOLEY_ELEMENTS, ZFlag, ne); |
| 4789 | __ Assert(eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray); |
| 4790 | } |
| 4791 | |
| 4792 | Label fast_elements_case; |
| 4793 | __ CompareAndBranch(kind, FAST_ELEMENTS, eq, &fast_elements_case); |
| 4794 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 4795 | |
| 4796 | __ Bind(&fast_elements_case); |
| 4797 | GenerateCase(masm, FAST_ELEMENTS); |
| 4798 | } |
| 4799 | |
| 4800 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4801 | void FastNewObjectStub::Generate(MacroAssembler* masm) { |
| 4802 | // ----------- S t a t e ------------- |
| 4803 | // -- x1 : target |
| 4804 | // -- x3 : new target |
| 4805 | // -- cp : context |
| 4806 | // -- lr : return address |
| 4807 | // ----------------------------------- |
| 4808 | __ AssertFunction(x1); |
| 4809 | __ AssertReceiver(x3); |
| 4810 | |
| 4811 | // Verify that the new target is a JSFunction. |
| 4812 | Label new_object; |
| 4813 | __ JumpIfNotObjectType(x3, x2, x2, JS_FUNCTION_TYPE, &new_object); |
| 4814 | |
| 4815 | // Load the initial map and verify that it's in fact a map. |
| 4816 | __ Ldr(x2, FieldMemOperand(x3, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4817 | __ JumpIfSmi(x2, &new_object); |
| 4818 | __ JumpIfNotObjectType(x2, x0, x0, MAP_TYPE, &new_object); |
| 4819 | |
| 4820 | // Fall back to runtime if the target differs from the new target's |
| 4821 | // initial map constructor. |
| 4822 | __ Ldr(x0, FieldMemOperand(x2, Map::kConstructorOrBackPointerOffset)); |
| 4823 | __ CompareAndBranch(x0, x1, ne, &new_object); |
| 4824 | |
| 4825 | // Allocate the JSObject on the heap. |
| 4826 | Label allocate, done_allocate; |
| 4827 | __ Ldrb(x4, FieldMemOperand(x2, Map::kInstanceSizeOffset)); |
| 4828 | __ Allocate(x4, x0, x5, x6, &allocate, SIZE_IN_WORDS); |
| 4829 | __ Bind(&done_allocate); |
| 4830 | |
| 4831 | // Initialize the JSObject fields. |
| 4832 | __ Mov(x1, x0); |
| 4833 | STATIC_ASSERT(JSObject::kMapOffset == 0 * kPointerSize); |
| 4834 | __ Str(x2, MemOperand(x1, kPointerSize, PostIndex)); |
| 4835 | __ LoadRoot(x3, Heap::kEmptyFixedArrayRootIndex); |
| 4836 | STATIC_ASSERT(JSObject::kPropertiesOffset == 1 * kPointerSize); |
| 4837 | STATIC_ASSERT(JSObject::kElementsOffset == 2 * kPointerSize); |
| 4838 | __ Stp(x3, x3, MemOperand(x1, 2 * kPointerSize, PostIndex)); |
| 4839 | STATIC_ASSERT(JSObject::kHeaderSize == 3 * kPointerSize); |
| 4840 | |
| 4841 | // ----------- S t a t e ------------- |
| 4842 | // -- x0 : result (untagged) |
| 4843 | // -- x1 : result fields (untagged) |
| 4844 | // -- x5 : result end (untagged) |
| 4845 | // -- x2 : initial map |
| 4846 | // -- cp : context |
| 4847 | // -- lr : return address |
| 4848 | // ----------------------------------- |
| 4849 | |
| 4850 | // Perform in-object slack tracking if requested. |
| 4851 | Label slack_tracking; |
| 4852 | STATIC_ASSERT(Map::kNoSlackTracking == 0); |
| 4853 | __ LoadRoot(x6, Heap::kUndefinedValueRootIndex); |
| 4854 | __ Ldr(w3, FieldMemOperand(x2, Map::kBitField3Offset)); |
| 4855 | __ TestAndBranchIfAnySet(w3, Map::ConstructionCounter::kMask, |
| 4856 | &slack_tracking); |
| 4857 | { |
| 4858 | // Initialize all in-object fields with undefined. |
| 4859 | __ InitializeFieldsWithFiller(x1, x5, x6); |
| 4860 | |
| 4861 | // Add the object tag to make the JSObject real. |
| 4862 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4863 | __ Add(x0, x0, kHeapObjectTag); |
| 4864 | __ Ret(); |
| 4865 | } |
| 4866 | __ Bind(&slack_tracking); |
| 4867 | { |
| 4868 | // Decrease generous allocation count. |
| 4869 | STATIC_ASSERT(Map::ConstructionCounter::kNext == 32); |
| 4870 | __ Sub(w3, w3, 1 << Map::ConstructionCounter::kShift); |
| 4871 | __ Str(w3, FieldMemOperand(x2, Map::kBitField3Offset)); |
| 4872 | |
| 4873 | // Initialize the in-object fields with undefined. |
| 4874 | __ Ldrb(x4, FieldMemOperand(x2, Map::kUnusedPropertyFieldsOffset)); |
| 4875 | __ Sub(x4, x5, Operand(x4, LSL, kPointerSizeLog2)); |
| 4876 | __ InitializeFieldsWithFiller(x1, x4, x6); |
| 4877 | |
| 4878 | // Initialize the remaining (reserved) fields with one pointer filler map. |
| 4879 | __ LoadRoot(x6, Heap::kOnePointerFillerMapRootIndex); |
| 4880 | __ InitializeFieldsWithFiller(x1, x5, x6); |
| 4881 | |
| 4882 | // Add the object tag to make the JSObject real. |
| 4883 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4884 | __ Add(x0, x0, kHeapObjectTag); |
| 4885 | |
| 4886 | // Check if we can finalize the instance size. |
| 4887 | Label finalize; |
| 4888 | STATIC_ASSERT(Map::kSlackTrackingCounterEnd == 1); |
| 4889 | __ TestAndBranchIfAllClear(w3, Map::ConstructionCounter::kMask, &finalize); |
| 4890 | __ Ret(); |
| 4891 | |
| 4892 | // Finalize the instance size. |
| 4893 | __ Bind(&finalize); |
| 4894 | { |
| 4895 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4896 | __ Push(x0, x2); |
| 4897 | __ CallRuntime(Runtime::kFinalizeInstanceSize); |
| 4898 | __ Pop(x0); |
| 4899 | } |
| 4900 | __ Ret(); |
| 4901 | } |
| 4902 | |
| 4903 | // Fall back to %AllocateInNewSpace. |
| 4904 | __ Bind(&allocate); |
| 4905 | { |
| 4906 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4907 | STATIC_ASSERT(kSmiTag == 0); |
| 4908 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4909 | __ Mov(x4, |
| 4910 | Operand(x4, LSL, kPointerSizeLog2 + kSmiTagSize + kSmiShiftSize)); |
| 4911 | __ Push(x2, x4); |
| 4912 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 4913 | __ Pop(x2); |
| 4914 | } |
| 4915 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4916 | __ Sub(x0, x0, kHeapObjectTag); |
| 4917 | __ Ldrb(x5, FieldMemOperand(x2, Map::kInstanceSizeOffset)); |
| 4918 | __ Add(x5, x0, Operand(x5, LSL, kPointerSizeLog2)); |
| 4919 | __ B(&done_allocate); |
| 4920 | |
| 4921 | // Fall back to %NewObject. |
| 4922 | __ Bind(&new_object); |
| 4923 | __ Push(x1, x3); |
| 4924 | __ TailCallRuntime(Runtime::kNewObject); |
| 4925 | } |
| 4926 | |
| 4927 | |
| 4928 | void FastNewRestParameterStub::Generate(MacroAssembler* masm) { |
| 4929 | // ----------- S t a t e ------------- |
| 4930 | // -- x1 : function |
| 4931 | // -- cp : context |
| 4932 | // -- fp : frame pointer |
| 4933 | // -- lr : return address |
| 4934 | // ----------------------------------- |
| 4935 | __ AssertFunction(x1); |
| 4936 | |
| 4937 | // For Ignition we need to skip all possible handler/stub frames until |
| 4938 | // we reach the JavaScript frame for the function (similar to what the |
| 4939 | // runtime fallback implementation does). So make x2 point to that |
| 4940 | // JavaScript frame. |
| 4941 | { |
| 4942 | Label loop, loop_entry; |
| 4943 | __ Mov(x2, fp); |
| 4944 | __ B(&loop_entry); |
| 4945 | __ Bind(&loop); |
| 4946 | __ Ldr(x2, MemOperand(x2, StandardFrameConstants::kCallerFPOffset)); |
| 4947 | __ Bind(&loop_entry); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 4948 | __ Ldr(x3, MemOperand(x2, StandardFrameConstants::kFunctionOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4949 | __ Cmp(x3, x1); |
| 4950 | __ B(ne, &loop); |
| 4951 | } |
| 4952 | |
| 4953 | // Check if we have rest parameters (only possible if we have an |
| 4954 | // arguments adaptor frame below the function frame). |
| 4955 | Label no_rest_parameters; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 4956 | __ Ldr(x2, MemOperand(x2, CommonFrameConstants::kCallerFPOffset)); |
| 4957 | __ Ldr(x3, MemOperand(x2, CommonFrameConstants::kContextOrFrameTypeOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4958 | __ Cmp(x3, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
| 4959 | __ B(ne, &no_rest_parameters); |
| 4960 | |
| 4961 | // Check if the arguments adaptor frame contains more arguments than |
| 4962 | // specified by the function's internal formal parameter count. |
| 4963 | Label rest_parameters; |
| 4964 | __ Ldrsw(x0, UntagSmiMemOperand( |
| 4965 | x2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4966 | __ Ldr(x1, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset)); |
| 4967 | __ Ldrsw( |
| 4968 | x1, FieldMemOperand(x1, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 4969 | __ Subs(x0, x0, x1); |
| 4970 | __ B(gt, &rest_parameters); |
| 4971 | |
| 4972 | // Return an empty rest parameter array. |
| 4973 | __ Bind(&no_rest_parameters); |
| 4974 | { |
| 4975 | // ----------- S t a t e ------------- |
| 4976 | // -- cp : context |
| 4977 | // -- lr : return address |
| 4978 | // ----------------------------------- |
| 4979 | |
| 4980 | // Allocate an empty rest parameter array. |
| 4981 | Label allocate, done_allocate; |
| 4982 | __ Allocate(JSArray::kSize, x0, x1, x2, &allocate, TAG_OBJECT); |
| 4983 | __ Bind(&done_allocate); |
| 4984 | |
| 4985 | // Setup the rest parameter array in x0. |
| 4986 | __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, x1); |
| 4987 | __ Str(x1, FieldMemOperand(x0, JSArray::kMapOffset)); |
| 4988 | __ LoadRoot(x1, Heap::kEmptyFixedArrayRootIndex); |
| 4989 | __ Str(x1, FieldMemOperand(x0, JSArray::kPropertiesOffset)); |
| 4990 | __ Str(x1, FieldMemOperand(x0, JSArray::kElementsOffset)); |
| 4991 | __ Mov(x1, Smi::FromInt(0)); |
| 4992 | __ Str(x1, FieldMemOperand(x0, JSArray::kLengthOffset)); |
| 4993 | STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize); |
| 4994 | __ Ret(); |
| 4995 | |
| 4996 | // Fall back to %AllocateInNewSpace. |
| 4997 | __ Bind(&allocate); |
| 4998 | { |
| 4999 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5000 | __ Push(Smi::FromInt(JSArray::kSize)); |
| 5001 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 5002 | } |
| 5003 | __ B(&done_allocate); |
| 5004 | } |
| 5005 | |
| 5006 | __ Bind(&rest_parameters); |
| 5007 | { |
| 5008 | // Compute the pointer to the first rest parameter (skippping the receiver). |
| 5009 | __ Add(x2, x2, Operand(x0, LSL, kPointerSizeLog2)); |
| 5010 | __ Add(x2, x2, StandardFrameConstants::kCallerSPOffset - 1 * kPointerSize); |
| 5011 | |
| 5012 | // ----------- S t a t e ------------- |
| 5013 | // -- cp : context |
| 5014 | // -- x0 : number of rest parameters |
| 5015 | // -- x2 : pointer to first rest parameters |
| 5016 | // -- lr : return address |
| 5017 | // ----------------------------------- |
| 5018 | |
| 5019 | // Allocate space for the rest parameter array plus the backing store. |
| 5020 | Label allocate, done_allocate; |
| 5021 | __ Mov(x1, JSArray::kSize + FixedArray::kHeaderSize); |
| 5022 | __ Add(x1, x1, Operand(x0, LSL, kPointerSizeLog2)); |
| 5023 | __ Allocate(x1, x3, x4, x5, &allocate, TAG_OBJECT); |
| 5024 | __ Bind(&done_allocate); |
| 5025 | |
| 5026 | // Compute arguments.length in x6. |
| 5027 | __ SmiTag(x6, x0); |
| 5028 | |
| 5029 | // Setup the elements array in x3. |
| 5030 | __ LoadRoot(x1, Heap::kFixedArrayMapRootIndex); |
| 5031 | __ Str(x1, FieldMemOperand(x3, FixedArray::kMapOffset)); |
| 5032 | __ Str(x6, FieldMemOperand(x3, FixedArray::kLengthOffset)); |
| 5033 | __ Add(x4, x3, FixedArray::kHeaderSize); |
| 5034 | { |
| 5035 | Label loop, done_loop; |
| 5036 | __ Add(x0, x4, Operand(x0, LSL, kPointerSizeLog2)); |
| 5037 | __ Bind(&loop); |
| 5038 | __ Cmp(x4, x0); |
| 5039 | __ B(eq, &done_loop); |
| 5040 | __ Ldr(x5, MemOperand(x2, 0 * kPointerSize)); |
| 5041 | __ Str(x5, FieldMemOperand(x4, 0 * kPointerSize)); |
| 5042 | __ Sub(x2, x2, Operand(1 * kPointerSize)); |
| 5043 | __ Add(x4, x4, Operand(1 * kPointerSize)); |
| 5044 | __ B(&loop); |
| 5045 | __ Bind(&done_loop); |
| 5046 | } |
| 5047 | |
| 5048 | // Setup the rest parameter array in x0. |
| 5049 | __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, x1); |
| 5050 | __ Str(x1, FieldMemOperand(x0, JSArray::kMapOffset)); |
| 5051 | __ LoadRoot(x1, Heap::kEmptyFixedArrayRootIndex); |
| 5052 | __ Str(x1, FieldMemOperand(x0, JSArray::kPropertiesOffset)); |
| 5053 | __ Str(x3, FieldMemOperand(x0, JSArray::kElementsOffset)); |
| 5054 | __ Str(x6, FieldMemOperand(x0, JSArray::kLengthOffset)); |
| 5055 | STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize); |
| 5056 | __ Ret(); |
| 5057 | |
| 5058 | // Fall back to %AllocateInNewSpace. |
| 5059 | __ Bind(&allocate); |
| 5060 | { |
| 5061 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5062 | __ SmiTag(x0); |
| 5063 | __ SmiTag(x1); |
| 5064 | __ Push(x0, x2, x1); |
| 5065 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 5066 | __ Mov(x3, x0); |
| 5067 | __ Pop(x2, x0); |
| 5068 | __ SmiUntag(x0); |
| 5069 | } |
| 5070 | __ B(&done_allocate); |
| 5071 | } |
| 5072 | } |
| 5073 | |
| 5074 | |
| 5075 | void FastNewSloppyArgumentsStub::Generate(MacroAssembler* masm) { |
| 5076 | // ----------- S t a t e ------------- |
| 5077 | // -- x1 : function |
| 5078 | // -- cp : context |
| 5079 | // -- fp : frame pointer |
| 5080 | // -- lr : return address |
| 5081 | // ----------------------------------- |
| 5082 | __ AssertFunction(x1); |
| 5083 | |
| 5084 | // TODO(bmeurer): Cleanup to match the FastNewStrictArgumentsStub. |
| 5085 | __ Ldr(x2, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset)); |
| 5086 | __ Ldrsw( |
| 5087 | x2, FieldMemOperand(x2, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 5088 | __ Add(x3, fp, Operand(x2, LSL, kPointerSizeLog2)); |
| 5089 | __ Add(x3, x3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 5090 | __ SmiTag(x2); |
| 5091 | |
| 5092 | // x1 : function |
| 5093 | // x2 : number of parameters (tagged) |
| 5094 | // x3 : parameters pointer |
| 5095 | // |
| 5096 | // Returns pointer to result object in x0. |
| 5097 | |
| 5098 | // Make an untagged copy of the parameter count. |
| 5099 | // Note: arg_count_smi is an alias of param_count_smi. |
| 5100 | Register function = x1; |
| 5101 | Register arg_count_smi = x2; |
| 5102 | Register param_count_smi = x2; |
| 5103 | Register recv_arg = x3; |
| 5104 | Register param_count = x7; |
| 5105 | __ SmiUntag(param_count, param_count_smi); |
| 5106 | |
| 5107 | // Check if the calling frame is an arguments adaptor frame. |
| 5108 | Register caller_fp = x11; |
| 5109 | Register caller_ctx = x12; |
| 5110 | Label runtime; |
| 5111 | Label adaptor_frame, try_allocate; |
| 5112 | __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5113 | __ Ldr( |
| 5114 | caller_ctx, |
| 5115 | MemOperand(caller_fp, CommonFrameConstants::kContextOrFrameTypeOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5116 | __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
| 5117 | __ B(eq, &adaptor_frame); |
| 5118 | |
| 5119 | // No adaptor, parameter count = argument count. |
| 5120 | |
| 5121 | // x1 function function pointer |
| 5122 | // x2 arg_count_smi number of function arguments (smi) |
| 5123 | // x3 recv_arg pointer to receiver arguments |
| 5124 | // x4 mapped_params number of mapped params, min(params, args) (uninit) |
| 5125 | // x7 param_count number of function parameters |
| 5126 | // x11 caller_fp caller's frame pointer |
| 5127 | // x14 arg_count number of function arguments (uninit) |
| 5128 | |
| 5129 | Register arg_count = x14; |
| 5130 | Register mapped_params = x4; |
| 5131 | __ Mov(arg_count, param_count); |
| 5132 | __ Mov(mapped_params, param_count); |
| 5133 | __ B(&try_allocate); |
| 5134 | |
| 5135 | // We have an adaptor frame. Patch the parameters pointer. |
| 5136 | __ Bind(&adaptor_frame); |
| 5137 | __ Ldr(arg_count_smi, |
| 5138 | MemOperand(caller_fp, |
| 5139 | ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 5140 | __ SmiUntag(arg_count, arg_count_smi); |
| 5141 | __ Add(x10, caller_fp, Operand(arg_count, LSL, kPointerSizeLog2)); |
| 5142 | __ Add(recv_arg, x10, StandardFrameConstants::kCallerSPOffset); |
| 5143 | |
| 5144 | // Compute the mapped parameter count = min(param_count, arg_count) |
| 5145 | __ Cmp(param_count, arg_count); |
| 5146 | __ Csel(mapped_params, param_count, arg_count, lt); |
| 5147 | |
| 5148 | __ Bind(&try_allocate); |
| 5149 | |
| 5150 | // x0 alloc_obj pointer to allocated objects: param map, backing |
| 5151 | // store, arguments (uninit) |
| 5152 | // x1 function function pointer |
| 5153 | // x2 arg_count_smi number of function arguments (smi) |
| 5154 | // x3 recv_arg pointer to receiver arguments |
| 5155 | // x4 mapped_params number of mapped parameters, min(params, args) |
| 5156 | // x7 param_count number of function parameters |
| 5157 | // x10 size size of objects to allocate (uninit) |
| 5158 | // x14 arg_count number of function arguments |
| 5159 | |
| 5160 | // Compute the size of backing store, parameter map, and arguments object. |
| 5161 | // 1. Parameter map, has two extra words containing context and backing |
| 5162 | // store. |
| 5163 | const int kParameterMapHeaderSize = |
| 5164 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 5165 | |
| 5166 | // Calculate the parameter map size, assuming it exists. |
| 5167 | Register size = x10; |
| 5168 | __ Mov(size, Operand(mapped_params, LSL, kPointerSizeLog2)); |
| 5169 | __ Add(size, size, kParameterMapHeaderSize); |
| 5170 | |
| 5171 | // If there are no mapped parameters, set the running size total to zero. |
| 5172 | // Otherwise, use the parameter map size calculated earlier. |
| 5173 | __ Cmp(mapped_params, 0); |
| 5174 | __ CzeroX(size, eq); |
| 5175 | |
| 5176 | // 2. Add the size of the backing store and arguments object. |
| 5177 | __ Add(size, size, Operand(arg_count, LSL, kPointerSizeLog2)); |
| 5178 | __ Add(size, size, FixedArray::kHeaderSize + JSSloppyArgumentsObject::kSize); |
| 5179 | |
| 5180 | // Do the allocation of all three objects in one go. Assign this to x0, as it |
| 5181 | // will be returned to the caller. |
| 5182 | Register alloc_obj = x0; |
| 5183 | __ Allocate(size, alloc_obj, x11, x12, &runtime, TAG_OBJECT); |
| 5184 | |
| 5185 | // Get the arguments boilerplate from the current (global) context. |
| 5186 | |
| 5187 | // x0 alloc_obj pointer to allocated objects (param map, backing |
| 5188 | // store, arguments) |
| 5189 | // x1 function function pointer |
| 5190 | // x2 arg_count_smi number of function arguments (smi) |
| 5191 | // x3 recv_arg pointer to receiver arguments |
| 5192 | // x4 mapped_params number of mapped parameters, min(params, args) |
| 5193 | // x7 param_count number of function parameters |
| 5194 | // x11 sloppy_args_map offset to args (or aliased args) map (uninit) |
| 5195 | // x14 arg_count number of function arguments |
| 5196 | |
| 5197 | Register global_ctx = x10; |
| 5198 | Register sloppy_args_map = x11; |
| 5199 | Register aliased_args_map = x10; |
| 5200 | __ Ldr(global_ctx, NativeContextMemOperand()); |
| 5201 | |
| 5202 | __ Ldr(sloppy_args_map, |
| 5203 | ContextMemOperand(global_ctx, Context::SLOPPY_ARGUMENTS_MAP_INDEX)); |
| 5204 | __ Ldr( |
| 5205 | aliased_args_map, |
| 5206 | ContextMemOperand(global_ctx, Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX)); |
| 5207 | __ Cmp(mapped_params, 0); |
| 5208 | __ CmovX(sloppy_args_map, aliased_args_map, ne); |
| 5209 | |
| 5210 | // Copy the JS object part. |
| 5211 | __ Str(sloppy_args_map, FieldMemOperand(alloc_obj, JSObject::kMapOffset)); |
| 5212 | __ LoadRoot(x10, Heap::kEmptyFixedArrayRootIndex); |
| 5213 | __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kPropertiesOffset)); |
| 5214 | __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kElementsOffset)); |
| 5215 | |
| 5216 | // Set up the callee in-object property. |
| 5217 | __ AssertNotSmi(function); |
| 5218 | __ Str(function, |
| 5219 | FieldMemOperand(alloc_obj, JSSloppyArgumentsObject::kCalleeOffset)); |
| 5220 | |
| 5221 | // Use the length and set that as an in-object property. |
| 5222 | __ Str(arg_count_smi, |
| 5223 | FieldMemOperand(alloc_obj, JSSloppyArgumentsObject::kLengthOffset)); |
| 5224 | |
| 5225 | // Set up the elements pointer in the allocated arguments object. |
| 5226 | // If we allocated a parameter map, "elements" will point there, otherwise |
| 5227 | // it will point to the backing store. |
| 5228 | |
| 5229 | // x0 alloc_obj pointer to allocated objects (param map, backing |
| 5230 | // store, arguments) |
| 5231 | // x1 function function pointer |
| 5232 | // x2 arg_count_smi number of function arguments (smi) |
| 5233 | // x3 recv_arg pointer to receiver arguments |
| 5234 | // x4 mapped_params number of mapped parameters, min(params, args) |
| 5235 | // x5 elements pointer to parameter map or backing store (uninit) |
| 5236 | // x6 backing_store pointer to backing store (uninit) |
| 5237 | // x7 param_count number of function parameters |
| 5238 | // x14 arg_count number of function arguments |
| 5239 | |
| 5240 | Register elements = x5; |
| 5241 | __ Add(elements, alloc_obj, JSSloppyArgumentsObject::kSize); |
| 5242 | __ Str(elements, FieldMemOperand(alloc_obj, JSObject::kElementsOffset)); |
| 5243 | |
| 5244 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 5245 | Label skip_parameter_map; |
| 5246 | __ Cmp(mapped_params, 0); |
| 5247 | // Set up backing store address, because it is needed later for filling in |
| 5248 | // the unmapped arguments. |
| 5249 | Register backing_store = x6; |
| 5250 | __ CmovX(backing_store, elements, eq); |
| 5251 | __ B(eq, &skip_parameter_map); |
| 5252 | |
| 5253 | __ LoadRoot(x10, Heap::kSloppyArgumentsElementsMapRootIndex); |
| 5254 | __ Str(x10, FieldMemOperand(elements, FixedArray::kMapOffset)); |
| 5255 | __ Add(x10, mapped_params, 2); |
| 5256 | __ SmiTag(x10); |
| 5257 | __ Str(x10, FieldMemOperand(elements, FixedArray::kLengthOffset)); |
| 5258 | __ Str(cp, FieldMemOperand(elements, |
| 5259 | FixedArray::kHeaderSize + 0 * kPointerSize)); |
| 5260 | __ Add(x10, elements, Operand(mapped_params, LSL, kPointerSizeLog2)); |
| 5261 | __ Add(x10, x10, kParameterMapHeaderSize); |
| 5262 | __ Str(x10, FieldMemOperand(elements, |
| 5263 | FixedArray::kHeaderSize + 1 * kPointerSize)); |
| 5264 | |
| 5265 | // Copy the parameter slots and the holes in the arguments. |
| 5266 | // We need to fill in mapped_parameter_count slots. Then index the context, |
| 5267 | // where parameters are stored in reverse order, at: |
| 5268 | // |
| 5269 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS + parameter_count - 1 |
| 5270 | // |
| 5271 | // The mapped parameter thus needs to get indices: |
| 5272 | // |
| 5273 | // MIN_CONTEXT_SLOTS + parameter_count - 1 .. |
| 5274 | // MIN_CONTEXT_SLOTS + parameter_count - mapped_parameter_count |
| 5275 | // |
| 5276 | // We loop from right to left. |
| 5277 | |
| 5278 | // x0 alloc_obj pointer to allocated objects (param map, backing |
| 5279 | // store, arguments) |
| 5280 | // x1 function function pointer |
| 5281 | // x2 arg_count_smi number of function arguments (smi) |
| 5282 | // x3 recv_arg pointer to receiver arguments |
| 5283 | // x4 mapped_params number of mapped parameters, min(params, args) |
| 5284 | // x5 elements pointer to parameter map or backing store (uninit) |
| 5285 | // x6 backing_store pointer to backing store (uninit) |
| 5286 | // x7 param_count number of function parameters |
| 5287 | // x11 loop_count parameter loop counter (uninit) |
| 5288 | // x12 index parameter index (smi, uninit) |
| 5289 | // x13 the_hole hole value (uninit) |
| 5290 | // x14 arg_count number of function arguments |
| 5291 | |
| 5292 | Register loop_count = x11; |
| 5293 | Register index = x12; |
| 5294 | Register the_hole = x13; |
| 5295 | Label parameters_loop, parameters_test; |
| 5296 | __ Mov(loop_count, mapped_params); |
| 5297 | __ Add(index, param_count, static_cast<int>(Context::MIN_CONTEXT_SLOTS)); |
| 5298 | __ Sub(index, index, mapped_params); |
| 5299 | __ SmiTag(index); |
| 5300 | __ LoadRoot(the_hole, Heap::kTheHoleValueRootIndex); |
| 5301 | __ Add(backing_store, elements, Operand(loop_count, LSL, kPointerSizeLog2)); |
| 5302 | __ Add(backing_store, backing_store, kParameterMapHeaderSize); |
| 5303 | |
| 5304 | __ B(¶meters_test); |
| 5305 | |
| 5306 | __ Bind(¶meters_loop); |
| 5307 | __ Sub(loop_count, loop_count, 1); |
| 5308 | __ Mov(x10, Operand(loop_count, LSL, kPointerSizeLog2)); |
| 5309 | __ Add(x10, x10, kParameterMapHeaderSize - kHeapObjectTag); |
| 5310 | __ Str(index, MemOperand(elements, x10)); |
| 5311 | __ Sub(x10, x10, kParameterMapHeaderSize - FixedArray::kHeaderSize); |
| 5312 | __ Str(the_hole, MemOperand(backing_store, x10)); |
| 5313 | __ Add(index, index, Smi::FromInt(1)); |
| 5314 | __ Bind(¶meters_test); |
| 5315 | __ Cbnz(loop_count, ¶meters_loop); |
| 5316 | |
| 5317 | __ Bind(&skip_parameter_map); |
| 5318 | // Copy arguments header and remaining slots (if there are any.) |
| 5319 | __ LoadRoot(x10, Heap::kFixedArrayMapRootIndex); |
| 5320 | __ Str(x10, FieldMemOperand(backing_store, FixedArray::kMapOffset)); |
| 5321 | __ Str(arg_count_smi, FieldMemOperand(backing_store, |
| 5322 | FixedArray::kLengthOffset)); |
| 5323 | |
| 5324 | // x0 alloc_obj pointer to allocated objects (param map, backing |
| 5325 | // store, arguments) |
| 5326 | // x1 function function pointer |
| 5327 | // x2 arg_count_smi number of function arguments (smi) |
| 5328 | // x3 recv_arg pointer to receiver arguments |
| 5329 | // x4 mapped_params number of mapped parameters, min(params, args) |
| 5330 | // x6 backing_store pointer to backing store (uninit) |
| 5331 | // x14 arg_count number of function arguments |
| 5332 | |
| 5333 | Label arguments_loop, arguments_test; |
| 5334 | __ Mov(x10, mapped_params); |
| 5335 | __ Sub(recv_arg, recv_arg, Operand(x10, LSL, kPointerSizeLog2)); |
| 5336 | __ B(&arguments_test); |
| 5337 | |
| 5338 | __ Bind(&arguments_loop); |
| 5339 | __ Sub(recv_arg, recv_arg, kPointerSize); |
| 5340 | __ Ldr(x11, MemOperand(recv_arg)); |
| 5341 | __ Add(x12, backing_store, Operand(x10, LSL, kPointerSizeLog2)); |
| 5342 | __ Str(x11, FieldMemOperand(x12, FixedArray::kHeaderSize)); |
| 5343 | __ Add(x10, x10, 1); |
| 5344 | |
| 5345 | __ Bind(&arguments_test); |
| 5346 | __ Cmp(x10, arg_count); |
| 5347 | __ B(lt, &arguments_loop); |
| 5348 | |
| 5349 | __ Ret(); |
| 5350 | |
| 5351 | // Do the runtime call to allocate the arguments object. |
| 5352 | __ Bind(&runtime); |
| 5353 | __ Push(function, recv_arg, arg_count_smi); |
| 5354 | __ TailCallRuntime(Runtime::kNewSloppyArguments); |
| 5355 | } |
| 5356 | |
| 5357 | |
| 5358 | void FastNewStrictArgumentsStub::Generate(MacroAssembler* masm) { |
| 5359 | // ----------- S t a t e ------------- |
| 5360 | // -- x1 : function |
| 5361 | // -- cp : context |
| 5362 | // -- fp : frame pointer |
| 5363 | // -- lr : return address |
| 5364 | // ----------------------------------- |
| 5365 | __ AssertFunction(x1); |
| 5366 | |
| 5367 | // For Ignition we need to skip all possible handler/stub frames until |
| 5368 | // we reach the JavaScript frame for the function (similar to what the |
| 5369 | // runtime fallback implementation does). So make x2 point to that |
| 5370 | // JavaScript frame. |
| 5371 | { |
| 5372 | Label loop, loop_entry; |
| 5373 | __ Mov(x2, fp); |
| 5374 | __ B(&loop_entry); |
| 5375 | __ Bind(&loop); |
| 5376 | __ Ldr(x2, MemOperand(x2, StandardFrameConstants::kCallerFPOffset)); |
| 5377 | __ Bind(&loop_entry); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5378 | __ Ldr(x3, MemOperand(x2, StandardFrameConstants::kFunctionOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5379 | __ Cmp(x3, x1); |
| 5380 | __ B(ne, &loop); |
| 5381 | } |
| 5382 | |
| 5383 | // Check if we have an arguments adaptor frame below the function frame. |
| 5384 | Label arguments_adaptor, arguments_done; |
| 5385 | __ Ldr(x3, MemOperand(x2, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5386 | __ Ldr(x4, MemOperand(x3, CommonFrameConstants::kContextOrFrameTypeOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5387 | __ Cmp(x4, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
| 5388 | __ B(eq, &arguments_adaptor); |
| 5389 | { |
| 5390 | __ Ldr(x1, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset)); |
| 5391 | __ Ldrsw(x0, FieldMemOperand( |
| 5392 | x1, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 5393 | __ Add(x2, x2, Operand(x0, LSL, kPointerSizeLog2)); |
| 5394 | __ Add(x2, x2, StandardFrameConstants::kCallerSPOffset - 1 * kPointerSize); |
| 5395 | } |
| 5396 | __ B(&arguments_done); |
| 5397 | __ Bind(&arguments_adaptor); |
| 5398 | { |
| 5399 | __ Ldrsw(x0, UntagSmiMemOperand( |
| 5400 | x3, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 5401 | __ Add(x2, x3, Operand(x0, LSL, kPointerSizeLog2)); |
| 5402 | __ Add(x2, x2, StandardFrameConstants::kCallerSPOffset - 1 * kPointerSize); |
| 5403 | } |
| 5404 | __ Bind(&arguments_done); |
| 5405 | |
| 5406 | // ----------- S t a t e ------------- |
| 5407 | // -- cp : context |
| 5408 | // -- x0 : number of rest parameters |
| 5409 | // -- x2 : pointer to first rest parameters |
| 5410 | // -- lr : return address |
| 5411 | // ----------------------------------- |
| 5412 | |
| 5413 | // Allocate space for the strict arguments object plus the backing store. |
| 5414 | Label allocate, done_allocate; |
| 5415 | __ Mov(x1, JSStrictArgumentsObject::kSize + FixedArray::kHeaderSize); |
| 5416 | __ Add(x1, x1, Operand(x0, LSL, kPointerSizeLog2)); |
| 5417 | __ Allocate(x1, x3, x4, x5, &allocate, TAG_OBJECT); |
| 5418 | __ Bind(&done_allocate); |
| 5419 | |
| 5420 | // Compute arguments.length in x6. |
| 5421 | __ SmiTag(x6, x0); |
| 5422 | |
| 5423 | // Setup the elements array in x3. |
| 5424 | __ LoadRoot(x1, Heap::kFixedArrayMapRootIndex); |
| 5425 | __ Str(x1, FieldMemOperand(x3, FixedArray::kMapOffset)); |
| 5426 | __ Str(x6, FieldMemOperand(x3, FixedArray::kLengthOffset)); |
| 5427 | __ Add(x4, x3, FixedArray::kHeaderSize); |
| 5428 | { |
| 5429 | Label loop, done_loop; |
| 5430 | __ Add(x0, x4, Operand(x0, LSL, kPointerSizeLog2)); |
| 5431 | __ Bind(&loop); |
| 5432 | __ Cmp(x4, x0); |
| 5433 | __ B(eq, &done_loop); |
| 5434 | __ Ldr(x5, MemOperand(x2, 0 * kPointerSize)); |
| 5435 | __ Str(x5, FieldMemOperand(x4, 0 * kPointerSize)); |
| 5436 | __ Sub(x2, x2, Operand(1 * kPointerSize)); |
| 5437 | __ Add(x4, x4, Operand(1 * kPointerSize)); |
| 5438 | __ B(&loop); |
| 5439 | __ Bind(&done_loop); |
| 5440 | } |
| 5441 | |
| 5442 | // Setup the strict arguments object in x0. |
| 5443 | __ LoadNativeContextSlot(Context::STRICT_ARGUMENTS_MAP_INDEX, x1); |
| 5444 | __ Str(x1, FieldMemOperand(x0, JSStrictArgumentsObject::kMapOffset)); |
| 5445 | __ LoadRoot(x1, Heap::kEmptyFixedArrayRootIndex); |
| 5446 | __ Str(x1, FieldMemOperand(x0, JSStrictArgumentsObject::kPropertiesOffset)); |
| 5447 | __ Str(x3, FieldMemOperand(x0, JSStrictArgumentsObject::kElementsOffset)); |
| 5448 | __ Str(x6, FieldMemOperand(x0, JSStrictArgumentsObject::kLengthOffset)); |
| 5449 | STATIC_ASSERT(JSStrictArgumentsObject::kSize == 4 * kPointerSize); |
| 5450 | __ Ret(); |
| 5451 | |
| 5452 | // Fall back to %AllocateInNewSpace. |
| 5453 | __ Bind(&allocate); |
| 5454 | { |
| 5455 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5456 | __ SmiTag(x0); |
| 5457 | __ SmiTag(x1); |
| 5458 | __ Push(x0, x2, x1); |
| 5459 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 5460 | __ Mov(x3, x0); |
| 5461 | __ Pop(x2, x0); |
| 5462 | __ SmiUntag(x0); |
| 5463 | } |
| 5464 | __ B(&done_allocate); |
| 5465 | } |
| 5466 | |
| 5467 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5468 | void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) { |
| 5469 | Register context = cp; |
| 5470 | Register result = x0; |
| 5471 | Register slot = x2; |
| 5472 | Label slow_case; |
| 5473 | |
| 5474 | // Go up the context chain to the script context. |
| 5475 | for (int i = 0; i < depth(); ++i) { |
| 5476 | __ Ldr(result, ContextMemOperand(context, Context::PREVIOUS_INDEX)); |
| 5477 | context = result; |
| 5478 | } |
| 5479 | |
| 5480 | // Load the PropertyCell value at the specified slot. |
| 5481 | __ Add(result, context, Operand(slot, LSL, kPointerSizeLog2)); |
| 5482 | __ Ldr(result, ContextMemOperand(result)); |
| 5483 | __ Ldr(result, FieldMemOperand(result, PropertyCell::kValueOffset)); |
| 5484 | |
| 5485 | // If the result is not the_hole, return. Otherwise, handle in the runtime. |
| 5486 | __ JumpIfRoot(result, Heap::kTheHoleValueRootIndex, &slow_case); |
| 5487 | __ Ret(); |
| 5488 | |
| 5489 | // Fallback to runtime. |
| 5490 | __ Bind(&slow_case); |
| 5491 | __ SmiTag(slot); |
| 5492 | __ Push(slot); |
| 5493 | __ TailCallRuntime(Runtime::kLoadGlobalViaContext); |
| 5494 | } |
| 5495 | |
| 5496 | |
| 5497 | void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) { |
| 5498 | Register context = cp; |
| 5499 | Register value = x0; |
| 5500 | Register slot = x2; |
| 5501 | Register context_temp = x10; |
| 5502 | Register cell = x10; |
| 5503 | Register cell_details = x11; |
| 5504 | Register cell_value = x12; |
| 5505 | Register cell_value_map = x13; |
| 5506 | Register value_map = x14; |
| 5507 | Label fast_heapobject_case, fast_smi_case, slow_case; |
| 5508 | |
| 5509 | if (FLAG_debug_code) { |
| 5510 | __ CompareRoot(value, Heap::kTheHoleValueRootIndex); |
| 5511 | __ Check(ne, kUnexpectedValue); |
| 5512 | } |
| 5513 | |
| 5514 | // Go up the context chain to the script context. |
| 5515 | for (int i = 0; i < depth(); i++) { |
| 5516 | __ Ldr(context_temp, ContextMemOperand(context, Context::PREVIOUS_INDEX)); |
| 5517 | context = context_temp; |
| 5518 | } |
| 5519 | |
| 5520 | // Load the PropertyCell at the specified slot. |
| 5521 | __ Add(cell, context, Operand(slot, LSL, kPointerSizeLog2)); |
| 5522 | __ Ldr(cell, ContextMemOperand(cell)); |
| 5523 | |
| 5524 | // Load PropertyDetails for the cell (actually only the cell_type and kind). |
| 5525 | __ Ldr(cell_details, |
| 5526 | UntagSmiFieldMemOperand(cell, PropertyCell::kDetailsOffset)); |
| 5527 | __ And(cell_details, cell_details, |
| 5528 | PropertyDetails::PropertyCellTypeField::kMask | |
| 5529 | PropertyDetails::KindField::kMask | |
| 5530 | PropertyDetails::kAttributesReadOnlyMask); |
| 5531 | |
| 5532 | // Check if PropertyCell holds mutable data. |
| 5533 | Label not_mutable_data; |
| 5534 | __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode( |
| 5535 | PropertyCellType::kMutable) | |
| 5536 | PropertyDetails::KindField::encode(kData)); |
| 5537 | __ B(ne, ¬_mutable_data); |
| 5538 | __ JumpIfSmi(value, &fast_smi_case); |
| 5539 | __ Bind(&fast_heapobject_case); |
| 5540 | __ Str(value, FieldMemOperand(cell, PropertyCell::kValueOffset)); |
| 5541 | // RecordWriteField clobbers the value register, so we copy it before the |
| 5542 | // call. |
| 5543 | __ Mov(x11, value); |
| 5544 | __ RecordWriteField(cell, PropertyCell::kValueOffset, x11, x12, |
| 5545 | kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET, |
| 5546 | OMIT_SMI_CHECK); |
| 5547 | __ Ret(); |
| 5548 | |
| 5549 | __ Bind(¬_mutable_data); |
| 5550 | // Check if PropertyCell value matches the new value (relevant for Constant, |
| 5551 | // ConstantType and Undefined cells). |
| 5552 | Label not_same_value; |
| 5553 | __ Ldr(cell_value, FieldMemOperand(cell, PropertyCell::kValueOffset)); |
| 5554 | __ Cmp(cell_value, value); |
| 5555 | __ B(ne, ¬_same_value); |
| 5556 | |
| 5557 | // Make sure the PropertyCell is not marked READ_ONLY. |
| 5558 | __ Tst(cell_details, PropertyDetails::kAttributesReadOnlyMask); |
| 5559 | __ B(ne, &slow_case); |
| 5560 | |
| 5561 | if (FLAG_debug_code) { |
| 5562 | Label done; |
| 5563 | // This can only be true for Constant, ConstantType and Undefined cells, |
| 5564 | // because we never store the_hole via this stub. |
| 5565 | __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode( |
| 5566 | PropertyCellType::kConstant) | |
| 5567 | PropertyDetails::KindField::encode(kData)); |
| 5568 | __ B(eq, &done); |
| 5569 | __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode( |
| 5570 | PropertyCellType::kConstantType) | |
| 5571 | PropertyDetails::KindField::encode(kData)); |
| 5572 | __ B(eq, &done); |
| 5573 | __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode( |
| 5574 | PropertyCellType::kUndefined) | |
| 5575 | PropertyDetails::KindField::encode(kData)); |
| 5576 | __ Check(eq, kUnexpectedValue); |
| 5577 | __ Bind(&done); |
| 5578 | } |
| 5579 | __ Ret(); |
| 5580 | __ Bind(¬_same_value); |
| 5581 | |
| 5582 | // Check if PropertyCell contains data with constant type (and is not |
| 5583 | // READ_ONLY). |
| 5584 | __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode( |
| 5585 | PropertyCellType::kConstantType) | |
| 5586 | PropertyDetails::KindField::encode(kData)); |
| 5587 | __ B(ne, &slow_case); |
| 5588 | |
| 5589 | // Now either both old and new values must be smis or both must be heap |
| 5590 | // objects with same map. |
| 5591 | Label value_is_heap_object; |
| 5592 | __ JumpIfNotSmi(value, &value_is_heap_object); |
| 5593 | __ JumpIfNotSmi(cell_value, &slow_case); |
| 5594 | // Old and new values are smis, no need for a write barrier here. |
| 5595 | __ Bind(&fast_smi_case); |
| 5596 | __ Str(value, FieldMemOperand(cell, PropertyCell::kValueOffset)); |
| 5597 | __ Ret(); |
| 5598 | |
| 5599 | __ Bind(&value_is_heap_object); |
| 5600 | __ JumpIfSmi(cell_value, &slow_case); |
| 5601 | |
| 5602 | __ Ldr(cell_value_map, FieldMemOperand(cell_value, HeapObject::kMapOffset)); |
| 5603 | __ Ldr(value_map, FieldMemOperand(value, HeapObject::kMapOffset)); |
| 5604 | __ Cmp(cell_value_map, value_map); |
| 5605 | __ B(eq, &fast_heapobject_case); |
| 5606 | |
| 5607 | // Fall back to the runtime. |
| 5608 | __ Bind(&slow_case); |
| 5609 | __ SmiTag(slot); |
| 5610 | __ Push(slot, value); |
| 5611 | __ TailCallRuntime(is_strict(language_mode()) |
| 5612 | ? Runtime::kStoreGlobalViaContext_Strict |
| 5613 | : Runtime::kStoreGlobalViaContext_Sloppy); |
| 5614 | } |
| 5615 | |
| 5616 | |
| 5617 | // The number of register that CallApiFunctionAndReturn will need to save on |
| 5618 | // the stack. The space for these registers need to be allocated in the |
| 5619 | // ExitFrame before calling CallApiFunctionAndReturn. |
| 5620 | static const int kCallApiFunctionSpillSpace = 4; |
| 5621 | |
| 5622 | |
| 5623 | static int AddressOffset(ExternalReference ref0, ExternalReference ref1) { |
| 5624 | return static_cast<int>(ref0.address() - ref1.address()); |
| 5625 | } |
| 5626 | |
| 5627 | |
| 5628 | // Calls an API function. Allocates HandleScope, extracts returned value |
| 5629 | // from handle and propagates exceptions. |
| 5630 | // 'stack_space' is the space to be unwound on exit (includes the call JS |
| 5631 | // arguments space and the additional space allocated for the fast call). |
| 5632 | // 'spill_offset' is the offset from the stack pointer where |
| 5633 | // CallApiFunctionAndReturn can spill registers. |
| 5634 | static void CallApiFunctionAndReturn( |
| 5635 | MacroAssembler* masm, Register function_address, |
| 5636 | ExternalReference thunk_ref, int stack_space, |
| 5637 | MemOperand* stack_space_operand, int spill_offset, |
| 5638 | MemOperand return_value_operand, MemOperand* context_restore_operand) { |
| 5639 | ASM_LOCATION("CallApiFunctionAndReturn"); |
| 5640 | Isolate* isolate = masm->isolate(); |
| 5641 | ExternalReference next_address = |
| 5642 | ExternalReference::handle_scope_next_address(isolate); |
| 5643 | const int kNextOffset = 0; |
| 5644 | const int kLimitOffset = AddressOffset( |
| 5645 | ExternalReference::handle_scope_limit_address(isolate), next_address); |
| 5646 | const int kLevelOffset = AddressOffset( |
| 5647 | ExternalReference::handle_scope_level_address(isolate), next_address); |
| 5648 | |
| 5649 | DCHECK(function_address.is(x1) || function_address.is(x2)); |
| 5650 | |
| 5651 | Label profiler_disabled; |
| 5652 | Label end_profiler_check; |
| 5653 | __ Mov(x10, ExternalReference::is_profiling_address(isolate)); |
| 5654 | __ Ldrb(w10, MemOperand(x10)); |
| 5655 | __ Cbz(w10, &profiler_disabled); |
| 5656 | __ Mov(x3, thunk_ref); |
| 5657 | __ B(&end_profiler_check); |
| 5658 | |
| 5659 | __ Bind(&profiler_disabled); |
| 5660 | __ Mov(x3, function_address); |
| 5661 | __ Bind(&end_profiler_check); |
| 5662 | |
| 5663 | // Save the callee-save registers we are going to use. |
| 5664 | // TODO(all): Is this necessary? ARM doesn't do it. |
| 5665 | STATIC_ASSERT(kCallApiFunctionSpillSpace == 4); |
| 5666 | __ Poke(x19, (spill_offset + 0) * kXRegSize); |
| 5667 | __ Poke(x20, (spill_offset + 1) * kXRegSize); |
| 5668 | __ Poke(x21, (spill_offset + 2) * kXRegSize); |
| 5669 | __ Poke(x22, (spill_offset + 3) * kXRegSize); |
| 5670 | |
| 5671 | // Allocate HandleScope in callee-save registers. |
| 5672 | // We will need to restore the HandleScope after the call to the API function, |
| 5673 | // by allocating it in callee-save registers they will be preserved by C code. |
| 5674 | Register handle_scope_base = x22; |
| 5675 | Register next_address_reg = x19; |
| 5676 | Register limit_reg = x20; |
| 5677 | Register level_reg = w21; |
| 5678 | |
| 5679 | __ Mov(handle_scope_base, next_address); |
| 5680 | __ Ldr(next_address_reg, MemOperand(handle_scope_base, kNextOffset)); |
| 5681 | __ Ldr(limit_reg, MemOperand(handle_scope_base, kLimitOffset)); |
| 5682 | __ Ldr(level_reg, MemOperand(handle_scope_base, kLevelOffset)); |
| 5683 | __ Add(level_reg, level_reg, 1); |
| 5684 | __ Str(level_reg, MemOperand(handle_scope_base, kLevelOffset)); |
| 5685 | |
| 5686 | if (FLAG_log_timer_events) { |
| 5687 | FrameScope frame(masm, StackFrame::MANUAL); |
| 5688 | __ PushSafepointRegisters(); |
| 5689 | __ Mov(x0, ExternalReference::isolate_address(isolate)); |
| 5690 | __ CallCFunction(ExternalReference::log_enter_external_function(isolate), |
| 5691 | 1); |
| 5692 | __ PopSafepointRegisters(); |
| 5693 | } |
| 5694 | |
| 5695 | // Native call returns to the DirectCEntry stub which redirects to the |
| 5696 | // return address pushed on stack (could have moved after GC). |
| 5697 | // DirectCEntry stub itself is generated early and never moves. |
| 5698 | DirectCEntryStub stub(isolate); |
| 5699 | stub.GenerateCall(masm, x3); |
| 5700 | |
| 5701 | if (FLAG_log_timer_events) { |
| 5702 | FrameScope frame(masm, StackFrame::MANUAL); |
| 5703 | __ PushSafepointRegisters(); |
| 5704 | __ Mov(x0, ExternalReference::isolate_address(isolate)); |
| 5705 | __ CallCFunction(ExternalReference::log_leave_external_function(isolate), |
| 5706 | 1); |
| 5707 | __ PopSafepointRegisters(); |
| 5708 | } |
| 5709 | |
| 5710 | Label promote_scheduled_exception; |
| 5711 | Label delete_allocated_handles; |
| 5712 | Label leave_exit_frame; |
| 5713 | Label return_value_loaded; |
| 5714 | |
| 5715 | // Load value from ReturnValue. |
| 5716 | __ Ldr(x0, return_value_operand); |
| 5717 | __ Bind(&return_value_loaded); |
| 5718 | // No more valid handles (the result handle was the last one). Restore |
| 5719 | // previous handle scope. |
| 5720 | __ Str(next_address_reg, MemOperand(handle_scope_base, kNextOffset)); |
| 5721 | if (__ emit_debug_code()) { |
| 5722 | __ Ldr(w1, MemOperand(handle_scope_base, kLevelOffset)); |
| 5723 | __ Cmp(w1, level_reg); |
| 5724 | __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall); |
| 5725 | } |
| 5726 | __ Sub(level_reg, level_reg, 1); |
| 5727 | __ Str(level_reg, MemOperand(handle_scope_base, kLevelOffset)); |
| 5728 | __ Ldr(x1, MemOperand(handle_scope_base, kLimitOffset)); |
| 5729 | __ Cmp(limit_reg, x1); |
| 5730 | __ B(ne, &delete_allocated_handles); |
| 5731 | |
| 5732 | // Leave the API exit frame. |
| 5733 | __ Bind(&leave_exit_frame); |
| 5734 | // Restore callee-saved registers. |
| 5735 | __ Peek(x19, (spill_offset + 0) * kXRegSize); |
| 5736 | __ Peek(x20, (spill_offset + 1) * kXRegSize); |
| 5737 | __ Peek(x21, (spill_offset + 2) * kXRegSize); |
| 5738 | __ Peek(x22, (spill_offset + 3) * kXRegSize); |
| 5739 | |
| 5740 | bool restore_context = context_restore_operand != NULL; |
| 5741 | if (restore_context) { |
| 5742 | __ Ldr(cp, *context_restore_operand); |
| 5743 | } |
| 5744 | |
| 5745 | if (stack_space_operand != NULL) { |
| 5746 | __ Ldr(w2, *stack_space_operand); |
| 5747 | } |
| 5748 | |
| 5749 | __ LeaveExitFrame(false, x1, !restore_context); |
| 5750 | |
| 5751 | // Check if the function scheduled an exception. |
| 5752 | __ Mov(x5, ExternalReference::scheduled_exception_address(isolate)); |
| 5753 | __ Ldr(x5, MemOperand(x5)); |
| 5754 | __ JumpIfNotRoot(x5, Heap::kTheHoleValueRootIndex, |
| 5755 | &promote_scheduled_exception); |
| 5756 | |
| 5757 | if (stack_space_operand != NULL) { |
| 5758 | __ Drop(x2, 1); |
| 5759 | } else { |
| 5760 | __ Drop(stack_space); |
| 5761 | } |
| 5762 | __ Ret(); |
| 5763 | |
| 5764 | // Re-throw by promoting a scheduled exception. |
| 5765 | __ Bind(&promote_scheduled_exception); |
| 5766 | __ TailCallRuntime(Runtime::kPromoteScheduledException); |
| 5767 | |
| 5768 | // HandleScope limit has changed. Delete allocated extensions. |
| 5769 | __ Bind(&delete_allocated_handles); |
| 5770 | __ Str(limit_reg, MemOperand(handle_scope_base, kLimitOffset)); |
| 5771 | // Save the return value in a callee-save register. |
| 5772 | Register saved_result = x19; |
| 5773 | __ Mov(saved_result, x0); |
| 5774 | __ Mov(x0, ExternalReference::isolate_address(isolate)); |
| 5775 | __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate), |
| 5776 | 1); |
| 5777 | __ Mov(x0, saved_result); |
| 5778 | __ B(&leave_exit_frame); |
| 5779 | } |
| 5780 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5781 | void CallApiCallbackStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5782 | // ----------- S t a t e ------------- |
| 5783 | // -- x0 : callee |
| 5784 | // -- x4 : call_data |
| 5785 | // -- x2 : holder |
| 5786 | // -- x1 : api_function_address |
| 5787 | // -- cp : context |
| 5788 | // -- |
| 5789 | // -- sp[0] : last argument |
| 5790 | // -- ... |
| 5791 | // -- sp[(argc - 1) * 8] : first argument |
| 5792 | // -- sp[argc * 8] : receiver |
| 5793 | // ----------------------------------- |
| 5794 | |
| 5795 | Register callee = x0; |
| 5796 | Register call_data = x4; |
| 5797 | Register holder = x2; |
| 5798 | Register api_function_address = x1; |
| 5799 | Register context = cp; |
| 5800 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5801 | typedef FunctionCallbackArguments FCA; |
| 5802 | |
| 5803 | STATIC_ASSERT(FCA::kContextSaveIndex == 6); |
| 5804 | STATIC_ASSERT(FCA::kCalleeIndex == 5); |
| 5805 | STATIC_ASSERT(FCA::kDataIndex == 4); |
| 5806 | STATIC_ASSERT(FCA::kReturnValueOffset == 3); |
| 5807 | STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); |
| 5808 | STATIC_ASSERT(FCA::kIsolateIndex == 1); |
| 5809 | STATIC_ASSERT(FCA::kHolderIndex == 0); |
| 5810 | STATIC_ASSERT(FCA::kArgsLength == 7); |
| 5811 | |
| 5812 | // FunctionCallbackArguments: context, callee and call data. |
| 5813 | __ Push(context, callee, call_data); |
| 5814 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5815 | if (!is_lazy()) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5816 | // Load context from callee |
| 5817 | __ Ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset)); |
| 5818 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5819 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5820 | if (!call_data_undefined()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5821 | __ LoadRoot(call_data, Heap::kUndefinedValueRootIndex); |
| 5822 | } |
| 5823 | Register isolate_reg = x5; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5824 | __ Mov(isolate_reg, ExternalReference::isolate_address(masm->isolate())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5825 | |
| 5826 | // FunctionCallbackArguments: |
| 5827 | // return value, return value default, isolate, holder. |
| 5828 | __ Push(call_data, call_data, isolate_reg, holder); |
| 5829 | |
| 5830 | // Prepare arguments. |
| 5831 | Register args = x6; |
| 5832 | __ Mov(args, masm->StackPointer()); |
| 5833 | |
| 5834 | // Allocate the v8::Arguments structure in the arguments' space, since it's |
| 5835 | // not controlled by GC. |
| 5836 | const int kApiStackSpace = 4; |
| 5837 | |
| 5838 | // Allocate space for CallApiFunctionAndReturn can store some scratch |
| 5839 | // registeres on the stack. |
| 5840 | const int kCallApiFunctionSpillSpace = 4; |
| 5841 | |
| 5842 | FrameScope frame_scope(masm, StackFrame::MANUAL); |
| 5843 | __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace); |
| 5844 | |
| 5845 | DCHECK(!AreAliased(x0, api_function_address)); |
| 5846 | // x0 = FunctionCallbackInfo& |
| 5847 | // Arguments is after the return address. |
| 5848 | __ Add(x0, masm->StackPointer(), 1 * kPointerSize); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5849 | // FunctionCallbackInfo::implicit_args_ and FunctionCallbackInfo::values_ |
| 5850 | __ Add(x10, args, Operand((FCA::kArgsLength - 1 + argc()) * kPointerSize)); |
| 5851 | __ Stp(args, x10, MemOperand(x0, 0 * kPointerSize)); |
| 5852 | // FunctionCallbackInfo::length_ = argc and |
| 5853 | // FunctionCallbackInfo::is_construct_call = 0 |
| 5854 | __ Mov(x10, argc()); |
| 5855 | __ Stp(x10, xzr, MemOperand(x0, 2 * kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5856 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5857 | ExternalReference thunk_ref = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5858 | ExternalReference::invoke_function_callback(masm->isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5859 | |
| 5860 | AllowExternalCallThatCantCauseGC scope(masm); |
| 5861 | MemOperand context_restore_operand( |
| 5862 | fp, (2 + FCA::kContextSaveIndex) * kPointerSize); |
| 5863 | // Stores return the first js argument |
| 5864 | int return_value_offset = 0; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5865 | if (is_store()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5866 | return_value_offset = 2 + FCA::kArgsLength; |
| 5867 | } else { |
| 5868 | return_value_offset = 2 + FCA::kReturnValueOffset; |
| 5869 | } |
| 5870 | MemOperand return_value_operand(fp, return_value_offset * kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5871 | int stack_space = 0; |
| 5872 | MemOperand is_construct_call_operand = |
| 5873 | MemOperand(masm->StackPointer(), 4 * kPointerSize); |
| 5874 | MemOperand* stack_space_operand = &is_construct_call_operand; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5875 | stack_space = argc() + FCA::kArgsLength + 1; |
| 5876 | stack_space_operand = NULL; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5877 | |
| 5878 | const int spill_offset = 1 + kApiStackSpace; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5879 | CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space, |
| 5880 | stack_space_operand, spill_offset, |
| 5881 | return_value_operand, &context_restore_operand); |
| 5882 | } |
| 5883 | |
| 5884 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5885 | void CallApiGetterStub::Generate(MacroAssembler* masm) { |
| 5886 | // ----------- S t a t e ------------- |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5887 | // -- sp[0] : name |
| 5888 | // -- sp[8 .. (8 + kArgsLength*8)] : v8::PropertyCallbackInfo::args_ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5889 | // -- ... |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5890 | // -- x2 : api_function_address |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5891 | // ----------------------------------- |
| 5892 | |
| 5893 | Register api_function_address = ApiGetterDescriptor::function_address(); |
| 5894 | DCHECK(api_function_address.is(x2)); |
| 5895 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5896 | // v8::PropertyCallbackInfo::args_ array and name handle. |
| 5897 | const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1; |
| 5898 | |
| 5899 | // Load address of v8::PropertyAccessorInfo::args_ array and name handle. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5900 | __ Mov(x0, masm->StackPointer()); // x0 = Handle<Name> |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5901 | __ Add(x1, x0, 1 * kPointerSize); // x1 = v8::PCI::args_ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5902 | |
| 5903 | const int kApiStackSpace = 1; |
| 5904 | |
| 5905 | // Allocate space for CallApiFunctionAndReturn can store some scratch |
| 5906 | // registeres on the stack. |
| 5907 | const int kCallApiFunctionSpillSpace = 4; |
| 5908 | |
| 5909 | FrameScope frame_scope(masm, StackFrame::MANUAL); |
| 5910 | __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace); |
| 5911 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5912 | // Create v8::PropertyCallbackInfo object on the stack and initialize |
| 5913 | // it's args_ field. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5914 | __ Poke(x1, 1 * kPointerSize); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5915 | __ Add(x1, masm->StackPointer(), 1 * kPointerSize); |
| 5916 | // x1 = v8::PropertyCallbackInfo& |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5917 | |
| 5918 | ExternalReference thunk_ref = |
| 5919 | ExternalReference::invoke_accessor_getter_callback(isolate()); |
| 5920 | |
| 5921 | const int spill_offset = 1 + kApiStackSpace; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5922 | // +3 is to skip prolog, return address and name handle. |
| 5923 | MemOperand return_value_operand( |
| 5924 | fp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5925 | CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, |
| 5926 | kStackUnwindSpace, NULL, spill_offset, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5927 | return_value_operand, NULL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5928 | } |
| 5929 | |
| 5930 | |
| 5931 | #undef __ |
| 5932 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5933 | } // namespace internal |
| 5934 | } // namespace v8 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5935 | |
| 5936 | #endif // V8_TARGET_ARCH_ARM64 |