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