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