1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "src/bootstrapper.h"
8 #include "src/code-stubs.h"
9 #include "src/codegen.h"
10 #include "src/ic/handler-compiler.h"
11 #include "src/ic/ic.h"
12 #include "src/ic/stub-cache.h"
13 #include "src/isolate.h"
14 #include "src/regexp/jsregexp.h"
15 #include "src/regexp/regexp-macro-assembler.h"
16 #include "src/runtime/runtime.h"
17 #include "src/x64/code-stubs-x64.h"
23 static void InitializeArrayConstructorDescriptor(
24 Isolate* isolate, CodeStubDescriptor* descriptor,
25 int constant_stack_parameter_count) {
26 Address deopt_handler = Runtime::FunctionForId(
27 Runtime::kArrayConstructor)->entry;
29 if (constant_stack_parameter_count == 0) {
30 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
31 JS_FUNCTION_STUB_MODE);
33 descriptor->Initialize(rax, deopt_handler, constant_stack_parameter_count,
34 JS_FUNCTION_STUB_MODE);
39 static void InitializeInternalArrayConstructorDescriptor(
40 Isolate* isolate, CodeStubDescriptor* descriptor,
41 int constant_stack_parameter_count) {
42 Address deopt_handler = Runtime::FunctionForId(
43 Runtime::kInternalArrayConstructor)->entry;
45 if (constant_stack_parameter_count == 0) {
46 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
47 JS_FUNCTION_STUB_MODE);
49 descriptor->Initialize(rax, deopt_handler, constant_stack_parameter_count,
50 JS_FUNCTION_STUB_MODE);
55 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
56 CodeStubDescriptor* descriptor) {
57 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
61 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
62 CodeStubDescriptor* descriptor) {
63 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
67 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
68 CodeStubDescriptor* descriptor) {
69 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
73 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
74 CodeStubDescriptor* descriptor) {
75 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
79 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
80 CodeStubDescriptor* descriptor) {
81 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
85 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
86 CodeStubDescriptor* descriptor) {
87 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
91 #define __ ACCESS_MASM(masm)
94 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
95 ExternalReference miss) {
96 // Update the static counter each time a new code stub is generated.
97 isolate()->counters()->code_stubs()->Increment();
99 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
100 int param_count = descriptor.GetRegisterParameterCount();
102 // Call the runtime system in a fresh internal frame.
103 FrameScope scope(masm, StackFrame::INTERNAL);
104 DCHECK(param_count == 0 ||
105 rax.is(descriptor.GetRegisterParameter(param_count - 1)));
107 for (int i = 0; i < param_count; ++i) {
108 __ Push(descriptor.GetRegisterParameter(i));
110 __ CallExternalReference(miss, param_count);
117 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
118 __ PushCallerSaved(save_doubles() ? kSaveFPRegs : kDontSaveFPRegs);
119 const int argument_count = 1;
120 __ PrepareCallCFunction(argument_count);
121 __ LoadAddress(arg_reg_1,
122 ExternalReference::isolate_address(isolate()));
124 AllowExternalCallThatCantCauseGC scope(masm);
126 ExternalReference::store_buffer_overflow_function(isolate()),
128 __ PopCallerSaved(save_doubles() ? kSaveFPRegs : kDontSaveFPRegs);
133 class FloatingPointHelper : public AllStatic {
135 enum ConvertUndefined {
136 CONVERT_UNDEFINED_TO_ZERO,
139 // Load the operands from rdx and rax into xmm0 and xmm1, as doubles.
140 // If the operands are not both numbers, jump to not_numbers.
141 // Leaves rdx and rax unchanged. SmiOperands assumes both are smis.
142 // NumberOperands assumes both are smis or heap numbers.
143 static void LoadSSE2UnknownOperands(MacroAssembler* masm,
148 void DoubleToIStub::Generate(MacroAssembler* masm) {
149 Register input_reg = this->source();
150 Register final_result_reg = this->destination();
151 DCHECK(is_truncating());
153 Label check_negative, process_64_bits, done;
155 int double_offset = offset();
157 // Account for return address and saved regs if input is rsp.
158 if (input_reg.is(rsp)) double_offset += 3 * kRegisterSize;
160 MemOperand mantissa_operand(MemOperand(input_reg, double_offset));
161 MemOperand exponent_operand(MemOperand(input_reg,
162 double_offset + kDoubleSize / 2));
165 Register scratch_candidates[3] = { rbx, rdx, rdi };
166 for (int i = 0; i < 3; i++) {
167 scratch1 = scratch_candidates[i];
168 if (!final_result_reg.is(scratch1) && !input_reg.is(scratch1)) break;
171 // Since we must use rcx for shifts below, use some other register (rax)
172 // to calculate the result if ecx is the requested return register.
173 Register result_reg = final_result_reg.is(rcx) ? rax : final_result_reg;
174 // Save ecx if it isn't the return register and therefore volatile, or if it
175 // is the return register, then save the temp register we use in its stead
177 Register save_reg = final_result_reg.is(rcx) ? rax : rcx;
181 bool stash_exponent_copy = !input_reg.is(rsp);
182 __ movl(scratch1, mantissa_operand);
183 __ movsd(xmm0, mantissa_operand);
184 __ movl(rcx, exponent_operand);
185 if (stash_exponent_copy) __ pushq(rcx);
187 __ andl(rcx, Immediate(HeapNumber::kExponentMask));
188 __ shrl(rcx, Immediate(HeapNumber::kExponentShift));
189 __ leal(result_reg, MemOperand(rcx, -HeapNumber::kExponentBias));
190 __ cmpl(result_reg, Immediate(HeapNumber::kMantissaBits));
191 __ j(below, &process_64_bits);
193 // Result is entirely in lower 32-bits of mantissa
194 int delta = HeapNumber::kExponentBias + Double::kPhysicalSignificandSize;
195 __ subl(rcx, Immediate(delta));
196 __ xorl(result_reg, result_reg);
197 __ cmpl(rcx, Immediate(31));
199 __ shll_cl(scratch1);
200 __ jmp(&check_negative);
202 __ bind(&process_64_bits);
203 __ cvttsd2siq(result_reg, xmm0);
204 __ jmp(&done, Label::kNear);
206 // If the double was negative, negate the integer result.
207 __ bind(&check_negative);
208 __ movl(result_reg, scratch1);
210 if (stash_exponent_copy) {
211 __ cmpl(MemOperand(rsp, 0), Immediate(0));
213 __ cmpl(exponent_operand, Immediate(0));
215 __ cmovl(greater, result_reg, scratch1);
219 if (stash_exponent_copy) {
220 __ addp(rsp, Immediate(kDoubleSize));
222 if (!final_result_reg.is(result_reg)) {
223 DCHECK(final_result_reg.is(rcx));
224 __ movl(final_result_reg, result_reg);
232 void FloatingPointHelper::LoadSSE2UnknownOperands(MacroAssembler* masm,
233 Label* not_numbers) {
234 Label load_smi_rdx, load_nonsmi_rax, load_smi_rax, load_float_rax, done;
235 // Load operand in rdx into xmm0, or branch to not_numbers.
236 __ LoadRoot(rcx, Heap::kHeapNumberMapRootIndex);
237 __ JumpIfSmi(rdx, &load_smi_rdx);
238 __ cmpp(FieldOperand(rdx, HeapObject::kMapOffset), rcx);
239 __ j(not_equal, not_numbers); // Argument in rdx is not a number.
240 __ movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset));
241 // Load operand in rax into xmm1, or branch to not_numbers.
242 __ JumpIfSmi(rax, &load_smi_rax);
244 __ bind(&load_nonsmi_rax);
245 __ cmpp(FieldOperand(rax, HeapObject::kMapOffset), rcx);
246 __ j(not_equal, not_numbers);
247 __ movsd(xmm1, FieldOperand(rax, HeapNumber::kValueOffset));
250 __ bind(&load_smi_rdx);
251 __ SmiToInteger32(kScratchRegister, rdx);
252 __ Cvtlsi2sd(xmm0, kScratchRegister);
253 __ JumpIfNotSmi(rax, &load_nonsmi_rax);
255 __ bind(&load_smi_rax);
256 __ SmiToInteger32(kScratchRegister, rax);
257 __ Cvtlsi2sd(xmm1, kScratchRegister);
262 void MathPowStub::Generate(MacroAssembler* masm) {
263 const Register exponent = MathPowTaggedDescriptor::exponent();
264 DCHECK(exponent.is(rdx));
265 const Register base = rax;
266 const Register scratch = rcx;
267 const XMMRegister double_result = xmm3;
268 const XMMRegister double_base = xmm2;
269 const XMMRegister double_exponent = xmm1;
270 const XMMRegister double_scratch = xmm4;
272 Label call_runtime, done, exponent_not_smi, int_exponent;
274 // Save 1 in double_result - we need this several times later on.
275 __ movp(scratch, Immediate(1));
276 __ Cvtlsi2sd(double_result, scratch);
278 if (exponent_type() == ON_STACK) {
279 Label base_is_smi, unpack_exponent;
280 // The exponent and base are supplied as arguments on the stack.
281 // This can only happen if the stub is called from non-optimized code.
282 // Load input parameters from stack.
283 StackArgumentsAccessor args(rsp, 2, ARGUMENTS_DONT_CONTAIN_RECEIVER);
284 __ movp(base, args.GetArgumentOperand(0));
285 __ movp(exponent, args.GetArgumentOperand(1));
286 __ JumpIfSmi(base, &base_is_smi, Label::kNear);
287 __ CompareRoot(FieldOperand(base, HeapObject::kMapOffset),
288 Heap::kHeapNumberMapRootIndex);
289 __ j(not_equal, &call_runtime);
291 __ movsd(double_base, FieldOperand(base, HeapNumber::kValueOffset));
292 __ jmp(&unpack_exponent, Label::kNear);
294 __ bind(&base_is_smi);
295 __ SmiToInteger32(base, base);
296 __ Cvtlsi2sd(double_base, base);
297 __ bind(&unpack_exponent);
299 __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear);
300 __ SmiToInteger32(exponent, exponent);
301 __ jmp(&int_exponent);
303 __ bind(&exponent_not_smi);
304 __ CompareRoot(FieldOperand(exponent, HeapObject::kMapOffset),
305 Heap::kHeapNumberMapRootIndex);
306 __ j(not_equal, &call_runtime);
307 __ movsd(double_exponent, FieldOperand(exponent, HeapNumber::kValueOffset));
308 } else if (exponent_type() == TAGGED) {
309 __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear);
310 __ SmiToInteger32(exponent, exponent);
311 __ jmp(&int_exponent);
313 __ bind(&exponent_not_smi);
314 __ movsd(double_exponent, FieldOperand(exponent, HeapNumber::kValueOffset));
317 if (exponent_type() != INTEGER) {
318 Label fast_power, try_arithmetic_simplification;
319 // Detect integer exponents stored as double.
320 __ DoubleToI(exponent, double_exponent, double_scratch,
321 TREAT_MINUS_ZERO_AS_ZERO, &try_arithmetic_simplification,
322 &try_arithmetic_simplification,
323 &try_arithmetic_simplification);
324 __ jmp(&int_exponent);
326 __ bind(&try_arithmetic_simplification);
327 __ cvttsd2si(exponent, double_exponent);
328 // Skip to runtime if possibly NaN (indicated by the indefinite integer).
329 __ cmpl(exponent, Immediate(0x1));
330 __ j(overflow, &call_runtime);
332 if (exponent_type() == ON_STACK) {
333 // Detect square root case. Crankshaft detects constant +/-0.5 at
334 // compile time and uses DoMathPowHalf instead. We then skip this check
335 // for non-constant cases of +/-0.5 as these hardly occur.
336 Label continue_sqrt, continue_rsqrt, not_plus_half;
338 // Load double_scratch with 0.5.
339 __ movq(scratch, V8_UINT64_C(0x3FE0000000000000));
340 __ movq(double_scratch, scratch);
341 // Already ruled out NaNs for exponent.
342 __ ucomisd(double_scratch, double_exponent);
343 __ j(not_equal, ¬_plus_half, Label::kNear);
345 // Calculates square root of base. Check for the special case of
346 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
347 // According to IEEE-754, double-precision -Infinity has the highest
348 // 12 bits set and the lowest 52 bits cleared.
349 __ movq(scratch, V8_UINT64_C(0xFFF0000000000000));
350 __ movq(double_scratch, scratch);
351 __ ucomisd(double_scratch, double_base);
352 // Comparing -Infinity with NaN results in "unordered", which sets the
353 // zero flag as if both were equal. However, it also sets the carry flag.
354 __ j(not_equal, &continue_sqrt, Label::kNear);
355 __ j(carry, &continue_sqrt, Label::kNear);
357 // Set result to Infinity in the special case.
358 __ xorps(double_result, double_result);
359 __ subsd(double_result, double_scratch);
362 __ bind(&continue_sqrt);
363 // sqrtsd returns -0 when input is -0. ECMA spec requires +0.
364 __ xorps(double_scratch, double_scratch);
365 __ addsd(double_scratch, double_base); // Convert -0 to 0.
366 __ sqrtsd(double_result, double_scratch);
370 __ bind(¬_plus_half);
371 // Load double_scratch with -0.5 by substracting 1.
372 __ subsd(double_scratch, double_result);
373 // Already ruled out NaNs for exponent.
374 __ ucomisd(double_scratch, double_exponent);
375 __ j(not_equal, &fast_power, Label::kNear);
377 // Calculates reciprocal of square root of base. Check for the special
378 // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
379 // According to IEEE-754, double-precision -Infinity has the highest
380 // 12 bits set and the lowest 52 bits cleared.
381 __ movq(scratch, V8_UINT64_C(0xFFF0000000000000));
382 __ movq(double_scratch, scratch);
383 __ ucomisd(double_scratch, double_base);
384 // Comparing -Infinity with NaN results in "unordered", which sets the
385 // zero flag as if both were equal. However, it also sets the carry flag.
386 __ j(not_equal, &continue_rsqrt, Label::kNear);
387 __ j(carry, &continue_rsqrt, Label::kNear);
389 // Set result to 0 in the special case.
390 __ xorps(double_result, double_result);
393 __ bind(&continue_rsqrt);
394 // sqrtsd returns -0 when input is -0. ECMA spec requires +0.
395 __ xorps(double_exponent, double_exponent);
396 __ addsd(double_exponent, double_base); // Convert -0 to +0.
397 __ sqrtsd(double_exponent, double_exponent);
398 __ divsd(double_result, double_exponent);
402 // Using FPU instructions to calculate power.
403 Label fast_power_failed;
404 __ bind(&fast_power);
405 __ fnclex(); // Clear flags to catch exceptions later.
406 // Transfer (B)ase and (E)xponent onto the FPU register stack.
407 __ subp(rsp, Immediate(kDoubleSize));
408 __ movsd(Operand(rsp, 0), double_exponent);
409 __ fld_d(Operand(rsp, 0)); // E
410 __ movsd(Operand(rsp, 0), double_base);
411 __ fld_d(Operand(rsp, 0)); // B, E
413 // Exponent is in st(1) and base is in st(0)
414 // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B)
415 // FYL2X calculates st(1) * log2(st(0))
418 __ frndint(); // rnd(X), X
419 __ fsub(1); // rnd(X), X-rnd(X)
420 __ fxch(1); // X - rnd(X), rnd(X)
421 // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1
422 __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X)
423 __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X)
424 __ faddp(1); // 2^(X-rnd(X)), rnd(X)
425 // FSCALE calculates st(0) * 2^st(1)
426 __ fscale(); // 2^X, rnd(X)
428 // Bail out to runtime in case of exceptions in the status word.
430 __ testb(rax, Immediate(0x5F)); // Check for all but precision exception.
431 __ j(not_zero, &fast_power_failed, Label::kNear);
432 __ fstp_d(Operand(rsp, 0));
433 __ movsd(double_result, Operand(rsp, 0));
434 __ addp(rsp, Immediate(kDoubleSize));
437 __ bind(&fast_power_failed);
439 __ addp(rsp, Immediate(kDoubleSize));
440 __ jmp(&call_runtime);
443 // Calculate power with integer exponent.
444 __ bind(&int_exponent);
445 const XMMRegister double_scratch2 = double_exponent;
446 // Back up exponent as we need to check if exponent is negative later.
447 __ movp(scratch, exponent); // Back up exponent.
448 __ movsd(double_scratch, double_base); // Back up base.
449 __ movsd(double_scratch2, double_result); // Load double_exponent with 1.
451 // Get absolute value of exponent.
452 Label no_neg, while_true, while_false;
453 __ testl(scratch, scratch);
454 __ j(positive, &no_neg, Label::kNear);
458 __ j(zero, &while_false, Label::kNear);
459 __ shrl(scratch, Immediate(1));
460 // Above condition means CF==0 && ZF==0. This means that the
461 // bit that has been shifted out is 0 and the result is not 0.
462 __ j(above, &while_true, Label::kNear);
463 __ movsd(double_result, double_scratch);
464 __ j(zero, &while_false, Label::kNear);
466 __ bind(&while_true);
467 __ shrl(scratch, Immediate(1));
468 __ mulsd(double_scratch, double_scratch);
469 __ j(above, &while_true, Label::kNear);
470 __ mulsd(double_result, double_scratch);
471 __ j(not_zero, &while_true);
473 __ bind(&while_false);
474 // If the exponent is negative, return 1/result.
475 __ testl(exponent, exponent);
476 __ j(greater, &done);
477 __ divsd(double_scratch2, double_result);
478 __ movsd(double_result, double_scratch2);
479 // Test whether result is zero. Bail out to check for subnormal result.
480 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
481 __ xorps(double_scratch2, double_scratch2);
482 __ ucomisd(double_scratch2, double_result);
483 // double_exponent aliased as double_scratch2 has already been overwritten
484 // and may not have contained the exponent value in the first place when the
485 // input was a smi. We reset it with exponent value before bailing out.
486 __ j(not_equal, &done);
487 __ Cvtlsi2sd(double_exponent, exponent);
489 // Returning or bailing out.
490 Counters* counters = isolate()->counters();
491 if (exponent_type() == ON_STACK) {
492 // The arguments are still on the stack.
493 __ bind(&call_runtime);
494 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
496 // The stub is called from non-optimized code, which expects the result
497 // as heap number in rax.
499 __ AllocateHeapNumber(rax, rcx, &call_runtime);
500 __ movsd(FieldOperand(rax, HeapNumber::kValueOffset), double_result);
501 __ IncrementCounter(counters->math_pow(), 1);
502 __ ret(2 * kPointerSize);
504 __ bind(&call_runtime);
505 // Move base to the correct argument register. Exponent is already in xmm1.
506 __ movsd(xmm0, double_base);
507 DCHECK(double_exponent.is(xmm1));
509 AllowExternalCallThatCantCauseGC scope(masm);
510 __ PrepareCallCFunction(2);
512 ExternalReference::power_double_double_function(isolate()), 2);
514 // Return value is in xmm0.
515 __ movsd(double_result, xmm0);
518 __ IncrementCounter(counters->math_pow(), 1);
524 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
526 Register receiver = LoadDescriptor::ReceiverRegister();
527 // Ensure that the vector and slot registers won't be clobbered before
528 // calling the miss handler.
529 DCHECK(!AreAliased(r8, r9, LoadWithVectorDescriptor::VectorRegister(),
530 LoadDescriptor::SlotRegister()));
532 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r8,
535 PropertyAccessCompiler::TailCallBuiltin(
536 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
540 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
541 // The key is in rdx and the parameter count is in rax.
542 DCHECK(rdx.is(ArgumentsAccessReadDescriptor::index()));
543 DCHECK(rax.is(ArgumentsAccessReadDescriptor::parameter_count()));
545 // Check that the key is a smi.
547 __ JumpIfNotSmi(rdx, &slow);
549 // Check if the calling frame is an arguments adaptor frame. We look at the
550 // context offset, and if the frame is not a regular one, then we find a
551 // Smi instead of the context. We can't use SmiCompare here, because that
552 // only works for comparing two smis.
554 __ movp(rbx, Operand(rbp, StandardFrameConstants::kCallerFPOffset));
555 __ Cmp(Operand(rbx, StandardFrameConstants::kContextOffset),
556 Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
557 __ j(equal, &adaptor);
559 // Check index against formal parameters count limit passed in
560 // through register rax. Use unsigned comparison to get negative
563 __ j(above_equal, &slow);
565 // Read the argument from the stack and return it.
566 __ SmiSub(rax, rax, rdx);
567 __ SmiToInteger32(rax, rax);
568 StackArgumentsAccessor args(rbp, rax, ARGUMENTS_DONT_CONTAIN_RECEIVER);
569 __ movp(rax, args.GetArgumentOperand(0));
572 // Arguments adaptor case: Check index against actual arguments
573 // limit found in the arguments adaptor frame. Use unsigned
574 // comparison to get negative check for free.
576 __ movp(rcx, Operand(rbx, ArgumentsAdaptorFrameConstants::kLengthOffset));
578 __ j(above_equal, &slow);
580 // Read the argument from the stack and return it.
581 __ SmiSub(rcx, rcx, rdx);
582 __ SmiToInteger32(rcx, rcx);
583 StackArgumentsAccessor adaptor_args(rbx, rcx,
584 ARGUMENTS_DONT_CONTAIN_RECEIVER);
585 __ movp(rax, adaptor_args.GetArgumentOperand(0));
588 // Slow-case: Handle non-smi or out-of-bounds access to arguments
589 // by calling the runtime system.
591 __ PopReturnAddressTo(rbx);
593 __ PushReturnAddressFrom(rbx);
594 __ TailCallRuntime(Runtime::kArguments, 1, 1);
598 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
600 // rsp[0] : return address
601 // rsp[8] : number of parameters (tagged)
602 // rsp[16] : receiver displacement
603 // rsp[24] : function
604 // Registers used over the whole function:
605 // rbx: the mapped parameter count (untagged)
606 // rax: the allocated object (tagged).
607 Factory* factory = isolate()->factory();
609 StackArgumentsAccessor args(rsp, 3, ARGUMENTS_DONT_CONTAIN_RECEIVER);
610 __ SmiToInteger64(rbx, args.GetArgumentOperand(2));
611 // rbx = parameter count (untagged)
613 // Check if the calling frame is an arguments adaptor frame.
615 Label adaptor_frame, try_allocate;
616 __ movp(rdx, Operand(rbp, StandardFrameConstants::kCallerFPOffset));
617 __ movp(rcx, Operand(rdx, StandardFrameConstants::kContextOffset));
618 __ Cmp(rcx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
619 __ j(equal, &adaptor_frame);
621 // No adaptor, parameter count = argument count.
623 __ jmp(&try_allocate, Label::kNear);
625 // We have an adaptor frame. Patch the parameters pointer.
626 __ bind(&adaptor_frame);
627 __ SmiToInteger64(rcx,
629 ArgumentsAdaptorFrameConstants::kLengthOffset));
630 __ leap(rdx, Operand(rdx, rcx, times_pointer_size,
631 StandardFrameConstants::kCallerSPOffset));
632 __ movp(args.GetArgumentOperand(1), rdx);
634 // rbx = parameter count (untagged)
635 // rcx = argument count (untagged)
636 // Compute the mapped parameter count = min(rbx, rcx) in rbx.
638 __ j(less_equal, &try_allocate, Label::kNear);
641 __ bind(&try_allocate);
643 // Compute the sizes of backing store, parameter map, and arguments object.
644 // 1. Parameter map, has 2 extra words containing context and backing store.
645 const int kParameterMapHeaderSize =
646 FixedArray::kHeaderSize + 2 * kPointerSize;
647 Label no_parameter_map;
650 __ j(zero, &no_parameter_map, Label::kNear);
651 __ leap(r8, Operand(rbx, times_pointer_size, kParameterMapHeaderSize));
652 __ bind(&no_parameter_map);
655 __ leap(r8, Operand(r8, rcx, times_pointer_size, FixedArray::kHeaderSize));
657 // 3. Arguments object.
658 __ addp(r8, Immediate(Heap::kSloppyArgumentsObjectSize));
660 // Do the allocation of all three objects in one go.
661 __ Allocate(r8, rax, rdx, rdi, &runtime, TAG_OBJECT);
663 // rax = address of new object(s) (tagged)
664 // rcx = argument count (untagged)
665 // Get the arguments map from the current native context into rdi.
666 Label has_mapped_parameters, instantiate;
667 __ movp(rdi, Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
668 __ movp(rdi, FieldOperand(rdi, GlobalObject::kNativeContextOffset));
670 __ j(not_zero, &has_mapped_parameters, Label::kNear);
672 const int kIndex = Context::SLOPPY_ARGUMENTS_MAP_INDEX;
673 __ movp(rdi, Operand(rdi, Context::SlotOffset(kIndex)));
674 __ jmp(&instantiate, Label::kNear);
676 const int kAliasedIndex = Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX;
677 __ bind(&has_mapped_parameters);
678 __ movp(rdi, Operand(rdi, Context::SlotOffset(kAliasedIndex)));
679 __ bind(&instantiate);
681 // rax = address of new object (tagged)
682 // rbx = mapped parameter count (untagged)
683 // rcx = argument count (untagged)
684 // rdi = address of arguments map (tagged)
685 __ movp(FieldOperand(rax, JSObject::kMapOffset), rdi);
686 __ LoadRoot(kScratchRegister, Heap::kEmptyFixedArrayRootIndex);
687 __ movp(FieldOperand(rax, JSObject::kPropertiesOffset), kScratchRegister);
688 __ movp(FieldOperand(rax, JSObject::kElementsOffset), kScratchRegister);
690 // Set up the callee in-object property.
691 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
692 __ movp(rdx, args.GetArgumentOperand(0));
693 __ AssertNotSmi(rdx);
694 __ movp(FieldOperand(rax, JSObject::kHeaderSize +
695 Heap::kArgumentsCalleeIndex * kPointerSize),
698 // Use the length (smi tagged) and set that as an in-object property too.
699 // Note: rcx is tagged from here on.
700 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
701 __ Integer32ToSmi(rcx, rcx);
702 __ movp(FieldOperand(rax, JSObject::kHeaderSize +
703 Heap::kArgumentsLengthIndex * kPointerSize),
706 // Set up the elements pointer in the allocated arguments object.
707 // If we allocated a parameter map, edi will point there, otherwise to the
709 __ leap(rdi, Operand(rax, Heap::kSloppyArgumentsObjectSize));
710 __ movp(FieldOperand(rax, JSObject::kElementsOffset), rdi);
712 // rax = address of new object (tagged)
713 // rbx = mapped parameter count (untagged)
714 // rcx = argument count (tagged)
715 // rdi = address of parameter map or backing store (tagged)
717 // Initialize parameter map. If there are no mapped arguments, we're done.
718 Label skip_parameter_map;
720 __ j(zero, &skip_parameter_map);
722 __ LoadRoot(kScratchRegister, Heap::kSloppyArgumentsElementsMapRootIndex);
723 // rbx contains the untagged argument count. Add 2 and tag to write.
724 __ movp(FieldOperand(rdi, FixedArray::kMapOffset), kScratchRegister);
725 __ Integer64PlusConstantToSmi(r9, rbx, 2);
726 __ movp(FieldOperand(rdi, FixedArray::kLengthOffset), r9);
727 __ movp(FieldOperand(rdi, FixedArray::kHeaderSize + 0 * kPointerSize), rsi);
728 __ leap(r9, Operand(rdi, rbx, times_pointer_size, kParameterMapHeaderSize));
729 __ movp(FieldOperand(rdi, FixedArray::kHeaderSize + 1 * kPointerSize), r9);
731 // Copy the parameter slots and the holes in the arguments.
732 // We need to fill in mapped_parameter_count slots. They index the context,
733 // where parameters are stored in reverse order, at
734 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
735 // The mapped parameter thus need to get indices
736 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
737 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
738 // We loop from right to left.
739 Label parameters_loop, parameters_test;
741 // Load tagged parameter count into r9.
742 __ Integer32ToSmi(r9, rbx);
743 __ Move(r8, Smi::FromInt(Context::MIN_CONTEXT_SLOTS));
744 __ addp(r8, args.GetArgumentOperand(2));
746 __ Move(r11, factory->the_hole_value());
748 __ leap(rdi, Operand(rdi, rbx, times_pointer_size, kParameterMapHeaderSize));
749 // r9 = loop variable (tagged)
750 // r8 = mapping index (tagged)
751 // r11 = the hole value
752 // rdx = address of parameter map (tagged)
753 // rdi = address of backing store (tagged)
754 __ jmp(¶meters_test, Label::kNear);
756 __ bind(¶meters_loop);
757 __ SmiSubConstant(r9, r9, Smi::FromInt(1));
758 __ SmiToInteger64(kScratchRegister, r9);
759 __ movp(FieldOperand(rdx, kScratchRegister,
761 kParameterMapHeaderSize),
763 __ movp(FieldOperand(rdi, kScratchRegister,
765 FixedArray::kHeaderSize),
767 __ SmiAddConstant(r8, r8, Smi::FromInt(1));
768 __ bind(¶meters_test);
770 __ j(not_zero, ¶meters_loop, Label::kNear);
772 __ bind(&skip_parameter_map);
774 // rcx = argument count (tagged)
775 // rdi = address of backing store (tagged)
776 // Copy arguments header and remaining slots (if there are any).
777 __ Move(FieldOperand(rdi, FixedArray::kMapOffset),
778 factory->fixed_array_map());
779 __ movp(FieldOperand(rdi, FixedArray::kLengthOffset), rcx);
781 Label arguments_loop, arguments_test;
783 __ movp(rdx, args.GetArgumentOperand(1));
784 // Untag rcx for the loop below.
785 __ SmiToInteger64(rcx, rcx);
786 __ leap(kScratchRegister, Operand(r8, times_pointer_size, 0));
787 __ subp(rdx, kScratchRegister);
788 __ jmp(&arguments_test, Label::kNear);
790 __ bind(&arguments_loop);
791 __ subp(rdx, Immediate(kPointerSize));
792 __ movp(r9, Operand(rdx, 0));
793 __ movp(FieldOperand(rdi, r8,
795 FixedArray::kHeaderSize),
797 __ addp(r8, Immediate(1));
799 __ bind(&arguments_test);
801 __ j(less, &arguments_loop, Label::kNear);
803 // Return and remove the on-stack parameters.
804 __ ret(3 * kPointerSize);
806 // Do the runtime call to allocate the arguments object.
807 // rcx = argument count (untagged)
809 __ Integer32ToSmi(rcx, rcx);
810 __ movp(args.GetArgumentOperand(2), rcx); // Patch argument count.
811 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
815 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
816 // rsp[0] : return address
817 // rsp[8] : number of parameters
818 // rsp[16] : receiver displacement
819 // rsp[24] : function
821 // Check if the calling frame is an arguments adaptor frame.
823 __ movp(rdx, Operand(rbp, StandardFrameConstants::kCallerFPOffset));
824 __ movp(rcx, Operand(rdx, StandardFrameConstants::kContextOffset));
825 __ Cmp(rcx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
826 __ j(not_equal, &runtime);
828 // Patch the arguments.length and the parameters pointer.
829 StackArgumentsAccessor args(rsp, 3, ARGUMENTS_DONT_CONTAIN_RECEIVER);
830 __ movp(rcx, Operand(rdx, ArgumentsAdaptorFrameConstants::kLengthOffset));
831 __ movp(args.GetArgumentOperand(2), rcx);
832 __ SmiToInteger64(rcx, rcx);
833 __ leap(rdx, Operand(rdx, rcx, times_pointer_size,
834 StandardFrameConstants::kCallerSPOffset));
835 __ movp(args.GetArgumentOperand(1), rdx);
838 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
842 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
843 // Return address is on the stack.
846 Register receiver = LoadDescriptor::ReceiverRegister();
847 Register key = LoadDescriptor::NameRegister();
848 Register scratch = rax;
849 DCHECK(!scratch.is(receiver) && !scratch.is(key));
851 // Check that the key is an array index, that is Uint32.
852 STATIC_ASSERT(kSmiValueSize <= 32);
853 __ JumpUnlessNonNegativeSmi(key, &slow);
855 // Everything is fine, call runtime.
856 __ PopReturnAddressTo(scratch);
857 __ Push(receiver); // receiver
859 __ PushReturnAddressFrom(scratch);
861 // Perform tail call to the entry.
862 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
865 PropertyAccessCompiler::TailCallBuiltin(
866 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
870 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
871 // Return address is on the stack.
874 Register receiver = LoadDescriptor::ReceiverRegister();
875 Register index = LoadDescriptor::NameRegister();
876 Register scratch = rdi;
877 Register result = rax;
878 DCHECK(!scratch.is(receiver) && !scratch.is(index));
879 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
880 result.is(LoadDescriptor::SlotRegister()));
882 // StringCharAtGenerator doesn't use the result register until it's passed
883 // the different miss possibilities. If it did, we would have a conflict
884 // when FLAG_vector_ics is true.
885 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
886 &miss, // When not a string.
887 &miss, // When not a number.
888 &miss, // When index out of range.
889 STRING_INDEX_IS_ARRAY_INDEX,
891 char_at_generator.GenerateFast(masm);
894 StubRuntimeCallHelper call_helper;
895 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
898 PropertyAccessCompiler::TailCallBuiltin(
899 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
903 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
904 // rsp[0] : return address
905 // rsp[8] : number of parameters
906 // rsp[16] : receiver displacement
907 // rsp[24] : function
909 // Check if the calling frame is an arguments adaptor frame.
910 Label adaptor_frame, try_allocate, runtime;
911 __ movp(rdx, Operand(rbp, StandardFrameConstants::kCallerFPOffset));
912 __ movp(rcx, Operand(rdx, StandardFrameConstants::kContextOffset));
913 __ Cmp(rcx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
914 __ j(equal, &adaptor_frame);
916 // Get the length from the frame.
917 StackArgumentsAccessor args(rsp, 3, ARGUMENTS_DONT_CONTAIN_RECEIVER);
918 __ movp(rcx, args.GetArgumentOperand(2));
919 __ SmiToInteger64(rcx, rcx);
920 __ jmp(&try_allocate);
922 // Patch the arguments.length and the parameters pointer.
923 __ bind(&adaptor_frame);
924 __ movp(rcx, Operand(rdx, ArgumentsAdaptorFrameConstants::kLengthOffset));
926 __ movp(args.GetArgumentOperand(2), rcx);
927 __ SmiToInteger64(rcx, rcx);
928 __ leap(rdx, Operand(rdx, rcx, times_pointer_size,
929 StandardFrameConstants::kCallerSPOffset));
930 __ movp(args.GetArgumentOperand(1), rdx);
932 // Try the new space allocation. Start out with computing the size of
933 // the arguments object and the elements array.
934 Label add_arguments_object;
935 __ bind(&try_allocate);
937 __ j(zero, &add_arguments_object, Label::kNear);
938 __ leap(rcx, Operand(rcx, times_pointer_size, FixedArray::kHeaderSize));
939 __ bind(&add_arguments_object);
940 __ addp(rcx, Immediate(Heap::kStrictArgumentsObjectSize));
942 // Do the allocation of both objects in one go.
943 __ Allocate(rcx, rax, rdx, rbx, &runtime, TAG_OBJECT);
945 // Get the arguments map from the current native context.
946 __ movp(rdi, Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
947 __ movp(rdi, FieldOperand(rdi, GlobalObject::kNativeContextOffset));
948 const int offset = Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX);
949 __ movp(rdi, Operand(rdi, offset));
951 __ movp(FieldOperand(rax, JSObject::kMapOffset), rdi);
952 __ LoadRoot(kScratchRegister, Heap::kEmptyFixedArrayRootIndex);
953 __ movp(FieldOperand(rax, JSObject::kPropertiesOffset), kScratchRegister);
954 __ movp(FieldOperand(rax, JSObject::kElementsOffset), kScratchRegister);
956 // Get the length (smi tagged) and set that as an in-object property too.
957 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
958 __ movp(rcx, args.GetArgumentOperand(2));
959 __ movp(FieldOperand(rax, JSObject::kHeaderSize +
960 Heap::kArgumentsLengthIndex * kPointerSize),
963 // If there are no actual arguments, we're done.
968 // Get the parameters pointer from the stack.
969 __ movp(rdx, args.GetArgumentOperand(1));
971 // Set up the elements pointer in the allocated arguments object and
972 // initialize the header in the elements fixed array.
973 __ leap(rdi, Operand(rax, Heap::kStrictArgumentsObjectSize));
974 __ movp(FieldOperand(rax, JSObject::kElementsOffset), rdi);
975 __ LoadRoot(kScratchRegister, Heap::kFixedArrayMapRootIndex);
976 __ movp(FieldOperand(rdi, FixedArray::kMapOffset), kScratchRegister);
979 __ movp(FieldOperand(rdi, FixedArray::kLengthOffset), rcx);
980 // Untag the length for the loop below.
981 __ SmiToInteger64(rcx, rcx);
983 // Copy the fixed array slots.
986 __ movp(rbx, Operand(rdx, -1 * kPointerSize)); // Skip receiver.
987 __ movp(FieldOperand(rdi, FixedArray::kHeaderSize), rbx);
988 __ addp(rdi, Immediate(kPointerSize));
989 __ subp(rdx, Immediate(kPointerSize));
991 __ j(not_zero, &loop);
993 // Return and remove the on-stack parameters.
995 __ ret(3 * kPointerSize);
997 // Do the runtime call to allocate the arguments object.
999 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
1003 void RegExpExecStub::Generate(MacroAssembler* masm) {
1004 // Just jump directly to runtime if native RegExp is not selected at compile
1005 // time or if regexp entry in generated code is turned off runtime switch or
1007 #ifdef V8_INTERPRETED_REGEXP
1008 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1009 #else // V8_INTERPRETED_REGEXP
1011 // Stack frame on entry.
1012 // rsp[0] : return address
1013 // rsp[8] : last_match_info (expected JSArray)
1014 // rsp[16] : previous index
1015 // rsp[24] : subject string
1016 // rsp[32] : JSRegExp object
1018 enum RegExpExecStubArgumentIndices {
1019 JS_REG_EXP_OBJECT_ARGUMENT_INDEX,
1020 SUBJECT_STRING_ARGUMENT_INDEX,
1021 PREVIOUS_INDEX_ARGUMENT_INDEX,
1022 LAST_MATCH_INFO_ARGUMENT_INDEX,
1023 REG_EXP_EXEC_ARGUMENT_COUNT
1026 StackArgumentsAccessor args(rsp, REG_EXP_EXEC_ARGUMENT_COUNT,
1027 ARGUMENTS_DONT_CONTAIN_RECEIVER);
1029 // Ensure that a RegExp stack is allocated.
1030 ExternalReference address_of_regexp_stack_memory_address =
1031 ExternalReference::address_of_regexp_stack_memory_address(isolate());
1032 ExternalReference address_of_regexp_stack_memory_size =
1033 ExternalReference::address_of_regexp_stack_memory_size(isolate());
1034 __ Load(kScratchRegister, address_of_regexp_stack_memory_size);
1035 __ testp(kScratchRegister, kScratchRegister);
1036 __ j(zero, &runtime);
1038 // Check that the first argument is a JSRegExp object.
1039 __ movp(rax, args.GetArgumentOperand(JS_REG_EXP_OBJECT_ARGUMENT_INDEX));
1040 __ JumpIfSmi(rax, &runtime);
1041 __ CmpObjectType(rax, JS_REGEXP_TYPE, kScratchRegister);
1042 __ j(not_equal, &runtime);
1044 // Check that the RegExp has been compiled (data contains a fixed array).
1045 __ movp(rax, FieldOperand(rax, JSRegExp::kDataOffset));
1046 if (FLAG_debug_code) {
1047 Condition is_smi = masm->CheckSmi(rax);
1048 __ Check(NegateCondition(is_smi),
1049 kUnexpectedTypeForRegExpDataFixedArrayExpected);
1050 __ CmpObjectType(rax, FIXED_ARRAY_TYPE, kScratchRegister);
1051 __ Check(equal, kUnexpectedTypeForRegExpDataFixedArrayExpected);
1054 // rax: RegExp data (FixedArray)
1055 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
1056 __ SmiToInteger32(rbx, FieldOperand(rax, JSRegExp::kDataTagOffset));
1057 __ cmpl(rbx, Immediate(JSRegExp::IRREGEXP));
1058 __ j(not_equal, &runtime);
1060 // rax: RegExp data (FixedArray)
1061 // Check that the number of captures fit in the static offsets vector buffer.
1062 __ SmiToInteger32(rdx,
1063 FieldOperand(rax, JSRegExp::kIrregexpCaptureCountOffset));
1064 // Check (number_of_captures + 1) * 2 <= offsets vector size
1065 // Or number_of_captures <= offsets vector size / 2 - 1
1066 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
1067 __ cmpl(rdx, Immediate(Isolate::kJSRegexpStaticOffsetsVectorSize / 2 - 1));
1068 __ j(above, &runtime);
1070 // Reset offset for possibly sliced string.
1072 __ movp(rdi, args.GetArgumentOperand(SUBJECT_STRING_ARGUMENT_INDEX));
1073 __ JumpIfSmi(rdi, &runtime);
1074 __ movp(r15, rdi); // Make a copy of the original subject string.
1075 __ movp(rbx, FieldOperand(rdi, HeapObject::kMapOffset));
1076 __ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset));
1077 // rax: RegExp data (FixedArray)
1078 // rdi: subject string
1079 // r15: subject string
1080 // Handle subject string according to its encoding and representation:
1081 // (1) Sequential two byte? If yes, go to (9).
1082 // (2) Sequential one byte? If yes, go to (6).
1083 // (3) Anything but sequential or cons? If yes, go to (7).
1084 // (4) Cons string. If the string is flat, replace subject with first string.
1085 // Otherwise bailout.
1086 // (5a) Is subject sequential two byte? If yes, go to (9).
1087 // (5b) Is subject external? If yes, go to (8).
1088 // (6) One byte sequential. Load regexp code for one byte.
1092 // Deferred code at the end of the stub:
1093 // (7) Not a long external string? If yes, go to (10).
1094 // (8) External string. Make it, offset-wise, look like a sequential string.
1095 // (8a) Is the external string one byte? If yes, go to (6).
1096 // (9) Two byte sequential. Load regexp code for one byte. Go to (E).
1097 // (10) Short external string or not a string? If yes, bail out to runtime.
1098 // (11) Sliced string. Replace subject with parent. Go to (5a).
1100 Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */,
1101 external_string /* 8 */, check_underlying /* 5a */,
1102 not_seq_nor_cons /* 7 */, check_code /* E */,
1103 not_long_external /* 10 */;
1105 // (1) Sequential two byte? If yes, go to (9).
1106 __ andb(rbx, Immediate(kIsNotStringMask |
1107 kStringRepresentationMask |
1108 kStringEncodingMask |
1109 kShortExternalStringMask));
1110 STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0);
1111 __ j(zero, &seq_two_byte_string); // Go to (9).
1113 // (2) Sequential one byte? If yes, go to (6).
1114 // Any other sequential string must be one byte.
1115 __ andb(rbx, Immediate(kIsNotStringMask |
1116 kStringRepresentationMask |
1117 kShortExternalStringMask));
1118 __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6).
1120 // (3) Anything but sequential or cons? If yes, go to (7).
1121 // We check whether the subject string is a cons, since sequential strings
1122 // have already been covered.
1123 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
1124 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
1125 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
1126 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
1127 __ cmpp(rbx, Immediate(kExternalStringTag));
1128 __ j(greater_equal, ¬_seq_nor_cons); // Go to (7).
1130 // (4) Cons string. Check that it's flat.
1131 // Replace subject with first string and reload instance type.
1132 __ CompareRoot(FieldOperand(rdi, ConsString::kSecondOffset),
1133 Heap::kempty_stringRootIndex);
1134 __ j(not_equal, &runtime);
1135 __ movp(rdi, FieldOperand(rdi, ConsString::kFirstOffset));
1136 __ bind(&check_underlying);
1137 __ movp(rbx, FieldOperand(rdi, HeapObject::kMapOffset));
1138 __ movp(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset));
1140 // (5a) Is subject sequential two byte? If yes, go to (9).
1141 __ testb(rbx, Immediate(kStringRepresentationMask | kStringEncodingMask));
1142 STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0);
1143 __ j(zero, &seq_two_byte_string); // Go to (9).
1144 // (5b) Is subject external? If yes, go to (8).
1145 __ testb(rbx, Immediate(kStringRepresentationMask));
1146 // The underlying external string is never a short external string.
1147 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
1148 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
1149 __ j(not_zero, &external_string); // Go to (8)
1151 // (6) One byte sequential. Load regexp code for one byte.
1152 __ bind(&seq_one_byte_string);
1153 // rax: RegExp data (FixedArray)
1154 __ movp(r11, FieldOperand(rax, JSRegExp::kDataOneByteCodeOffset));
1155 __ Set(rcx, 1); // Type is one byte.
1157 // (E) Carry on. String handling is done.
1158 __ bind(&check_code);
1159 // r11: irregexp code
1160 // Check that the irregexp code has been generated for the actual string
1161 // encoding. If it has, the field contains a code object otherwise it contains
1162 // smi (code flushing support)
1163 __ JumpIfSmi(r11, &runtime);
1165 // rdi: sequential subject string (or look-alike, external string)
1166 // r15: original subject string
1167 // rcx: encoding of subject string (1 if one_byte, 0 if two_byte);
1169 // Load used arguments before starting to push arguments for call to native
1170 // RegExp code to avoid handling changing stack height.
1171 // We have to use r15 instead of rdi to load the length because rdi might
1172 // have been only made to look like a sequential string when it actually
1173 // is an external string.
1174 __ movp(rbx, args.GetArgumentOperand(PREVIOUS_INDEX_ARGUMENT_INDEX));
1175 __ JumpIfNotSmi(rbx, &runtime);
1176 __ SmiCompare(rbx, FieldOperand(r15, String::kLengthOffset));
1177 __ j(above_equal, &runtime);
1178 __ SmiToInteger64(rbx, rbx);
1180 // rdi: subject string
1181 // rbx: previous index
1182 // rcx: encoding of subject string (1 if one_byte 0 if two_byte);
1184 // All checks done. Now push arguments for native regexp code.
1185 Counters* counters = isolate()->counters();
1186 __ IncrementCounter(counters->regexp_entry_native(), 1);
1188 // Isolates: note we add an additional parameter here (isolate pointer).
1189 static const int kRegExpExecuteArguments = 9;
1190 int argument_slots_on_stack =
1191 masm->ArgumentStackSlotsForCFunctionCall(kRegExpExecuteArguments);
1192 __ EnterApiExitFrame(argument_slots_on_stack);
1194 // Argument 9: Pass current isolate address.
1195 __ LoadAddress(kScratchRegister,
1196 ExternalReference::isolate_address(isolate()));
1197 __ movq(Operand(rsp, (argument_slots_on_stack - 1) * kRegisterSize),
1200 // Argument 8: Indicate that this is a direct call from JavaScript.
1201 __ movq(Operand(rsp, (argument_slots_on_stack - 2) * kRegisterSize),
1204 // Argument 7: Start (high end) of backtracking stack memory area.
1205 __ Move(kScratchRegister, address_of_regexp_stack_memory_address);
1206 __ movp(r9, Operand(kScratchRegister, 0));
1207 __ Move(kScratchRegister, address_of_regexp_stack_memory_size);
1208 __ addp(r9, Operand(kScratchRegister, 0));
1209 __ movq(Operand(rsp, (argument_slots_on_stack - 3) * kRegisterSize), r9);
1211 // Argument 6: Set the number of capture registers to zero to force global
1212 // regexps to behave as non-global. This does not affect non-global regexps.
1213 // Argument 6 is passed in r9 on Linux and on the stack on Windows.
1215 __ movq(Operand(rsp, (argument_slots_on_stack - 4) * kRegisterSize),
1221 // Argument 5: static offsets vector buffer.
1223 r8, ExternalReference::address_of_static_offsets_vector(isolate()));
1224 // Argument 5 passed in r8 on Linux and on the stack on Windows.
1226 __ movq(Operand(rsp, (argument_slots_on_stack - 5) * kRegisterSize), r8);
1229 // rdi: subject string
1230 // rbx: previous index
1231 // rcx: encoding of subject string (1 if one_byte 0 if two_byte);
1233 // r14: slice offset
1234 // r15: original subject string
1236 // Argument 2: Previous index.
1237 __ movp(arg_reg_2, rbx);
1239 // Argument 4: End of string data
1240 // Argument 3: Start of string data
1241 Label setup_two_byte, setup_rest, got_length, length_not_from_slice;
1242 // Prepare start and end index of the input.
1243 // Load the length from the original sliced string if that is the case.
1245 __ SmiToInteger32(arg_reg_3, FieldOperand(r15, String::kLengthOffset));
1246 __ addp(r14, arg_reg_3); // Using arg3 as scratch.
1248 // rbx: start index of the input
1249 // r14: end index of the input
1250 // r15: original subject string
1251 __ testb(rcx, rcx); // Last use of rcx as encoding of subject string.
1252 __ j(zero, &setup_two_byte, Label::kNear);
1254 FieldOperand(rdi, r14, times_1, SeqOneByteString::kHeaderSize));
1256 FieldOperand(rdi, rbx, times_1, SeqOneByteString::kHeaderSize));
1257 __ jmp(&setup_rest, Label::kNear);
1258 __ bind(&setup_two_byte);
1260 FieldOperand(rdi, r14, times_2, SeqTwoByteString::kHeaderSize));
1262 FieldOperand(rdi, rbx, times_2, SeqTwoByteString::kHeaderSize));
1263 __ bind(&setup_rest);
1265 // Argument 1: Original subject string.
1266 // The original subject is in the previous stack frame. Therefore we have to
1267 // use rbp, which points exactly to one pointer size below the previous rsp.
1268 // (Because creating a new stack frame pushes the previous rbp onto the stack
1269 // and thereby moves up rsp by one kPointerSize.)
1270 __ movp(arg_reg_1, r15);
1272 // Locate the code entry and call it.
1273 __ addp(r11, Immediate(Code::kHeaderSize - kHeapObjectTag));
1276 __ LeaveApiExitFrame(true);
1278 // Check the result.
1281 __ cmpl(rax, Immediate(1));
1282 // We expect exactly one result since we force the called regexp to behave
1284 __ j(equal, &success, Label::kNear);
1285 __ cmpl(rax, Immediate(NativeRegExpMacroAssembler::EXCEPTION));
1286 __ j(equal, &exception);
1287 __ cmpl(rax, Immediate(NativeRegExpMacroAssembler::FAILURE));
1288 // If none of the above, it can only be retry.
1289 // Handle that in the runtime system.
1290 __ j(not_equal, &runtime);
1292 // For failure return null.
1293 __ LoadRoot(rax, Heap::kNullValueRootIndex);
1294 __ ret(REG_EXP_EXEC_ARGUMENT_COUNT * kPointerSize);
1296 // Load RegExp data.
1298 __ movp(rax, args.GetArgumentOperand(JS_REG_EXP_OBJECT_ARGUMENT_INDEX));
1299 __ movp(rcx, FieldOperand(rax, JSRegExp::kDataOffset));
1300 __ SmiToInteger32(rax,
1301 FieldOperand(rcx, JSRegExp::kIrregexpCaptureCountOffset));
1302 // Calculate number of capture registers (number_of_captures + 1) * 2.
1303 __ leal(rdx, Operand(rax, rax, times_1, 2));
1305 // rdx: Number of capture registers
1306 // Check that the fourth object is a JSArray object.
1307 __ movp(r15, args.GetArgumentOperand(LAST_MATCH_INFO_ARGUMENT_INDEX));
1308 __ JumpIfSmi(r15, &runtime);
1309 __ CmpObjectType(r15, JS_ARRAY_TYPE, kScratchRegister);
1310 __ j(not_equal, &runtime);
1311 // Check that the JSArray is in fast case.
1312 __ movp(rbx, FieldOperand(r15, JSArray::kElementsOffset));
1313 __ movp(rax, FieldOperand(rbx, HeapObject::kMapOffset));
1314 __ CompareRoot(rax, Heap::kFixedArrayMapRootIndex);
1315 __ j(not_equal, &runtime);
1316 // Check that the last match info has space for the capture registers and the
1317 // additional information. Ensure no overflow in add.
1318 STATIC_ASSERT(FixedArray::kMaxLength < kMaxInt - FixedArray::kLengthOffset);
1319 __ SmiToInteger32(rax, FieldOperand(rbx, FixedArray::kLengthOffset));
1320 __ subl(rax, Immediate(RegExpImpl::kLastMatchOverhead));
1322 __ j(greater, &runtime);
1324 // rbx: last_match_info backing store (FixedArray)
1325 // rdx: number of capture registers
1326 // Store the capture count.
1327 __ Integer32ToSmi(kScratchRegister, rdx);
1328 __ movp(FieldOperand(rbx, RegExpImpl::kLastCaptureCountOffset),
1330 // Store last subject and last input.
1331 __ movp(rax, args.GetArgumentOperand(SUBJECT_STRING_ARGUMENT_INDEX));
1332 __ movp(FieldOperand(rbx, RegExpImpl::kLastSubjectOffset), rax);
1334 __ RecordWriteField(rbx,
1335 RegExpImpl::kLastSubjectOffset,
1340 __ movp(FieldOperand(rbx, RegExpImpl::kLastInputOffset), rax);
1341 __ RecordWriteField(rbx,
1342 RegExpImpl::kLastInputOffset,
1347 // Get the static offsets vector filled by the native regexp code.
1349 rcx, ExternalReference::address_of_static_offsets_vector(isolate()));
1351 // rbx: last_match_info backing store (FixedArray)
1352 // rcx: offsets vector
1353 // rdx: number of capture registers
1354 Label next_capture, done;
1355 // Capture register counter starts from number of capture registers and
1356 // counts down until wraping after zero.
1357 __ bind(&next_capture);
1358 __ subp(rdx, Immediate(1));
1359 __ j(negative, &done, Label::kNear);
1360 // Read the value from the static offsets vector buffer and make it a smi.
1361 __ movl(rdi, Operand(rcx, rdx, times_int_size, 0));
1362 __ Integer32ToSmi(rdi, rdi);
1363 // Store the smi value in the last match info.
1364 __ movp(FieldOperand(rbx,
1367 RegExpImpl::kFirstCaptureOffset),
1369 __ jmp(&next_capture);
1372 // Return last match info.
1374 __ ret(REG_EXP_EXEC_ARGUMENT_COUNT * kPointerSize);
1376 __ bind(&exception);
1377 // Result must now be exception. If there is no pending exception already a
1378 // stack overflow (on the backtrack stack) was detected in RegExp code but
1379 // haven't created the exception yet. Handle that in the runtime system.
1380 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
1381 ExternalReference pending_exception_address(
1382 Isolate::kPendingExceptionAddress, isolate());
1383 Operand pending_exception_operand =
1384 masm->ExternalOperand(pending_exception_address, rbx);
1385 __ movp(rax, pending_exception_operand);
1386 __ LoadRoot(rdx, Heap::kTheHoleValueRootIndex);
1388 __ j(equal, &runtime);
1390 // For exception, throw the exception again.
1391 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
1393 // Do the runtime call to execute the regexp.
1395 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1397 // Deferred code for string handling.
1398 // (7) Not a long external string? If yes, go to (10).
1399 __ bind(¬_seq_nor_cons);
1400 // Compare flags are still set from (3).
1401 __ j(greater, ¬_long_external, Label::kNear); // Go to (10).
1403 // (8) External string. Short external strings have been ruled out.
1404 __ bind(&external_string);
1405 __ movp(rbx, FieldOperand(rdi, HeapObject::kMapOffset));
1406 __ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset));
1407 if (FLAG_debug_code) {
1408 // Assert that we do not have a cons or slice (indirect strings) here.
1409 // Sequential strings have already been ruled out.
1410 __ testb(rbx, Immediate(kIsIndirectStringMask));
1411 __ Assert(zero, kExternalStringExpectedButNotFound);
1413 __ movp(rdi, FieldOperand(rdi, ExternalString::kResourceDataOffset));
1414 // Move the pointer so that offset-wise, it looks like a sequential string.
1415 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
1416 __ subp(rdi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
1417 STATIC_ASSERT(kTwoByteStringTag == 0);
1418 // (8a) Is the external string one byte? If yes, go to (6).
1419 __ testb(rbx, Immediate(kStringEncodingMask));
1420 __ j(not_zero, &seq_one_byte_string); // Goto (6).
1422 // rdi: subject string (flat two-byte)
1423 // rax: RegExp data (FixedArray)
1424 // (9) Two byte sequential. Load regexp code for one byte. Go to (E).
1425 __ bind(&seq_two_byte_string);
1426 __ movp(r11, FieldOperand(rax, JSRegExp::kDataUC16CodeOffset));
1427 __ Set(rcx, 0); // Type is two byte.
1428 __ jmp(&check_code); // Go to (E).
1430 // (10) Not a string or a short external string? If yes, bail out to runtime.
1431 __ bind(¬_long_external);
1432 // Catch non-string subject or short external string.
1433 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
1434 __ testb(rbx, Immediate(kIsNotStringMask | kShortExternalStringMask));
1435 __ j(not_zero, &runtime);
1437 // (11) Sliced string. Replace subject with parent. Go to (5a).
1438 // Load offset into r14 and replace subject string with parent.
1439 __ SmiToInteger32(r14, FieldOperand(rdi, SlicedString::kOffsetOffset));
1440 __ movp(rdi, FieldOperand(rdi, SlicedString::kParentOffset));
1441 __ jmp(&check_underlying);
1442 #endif // V8_INTERPRETED_REGEXP
1446 static int NegativeComparisonResult(Condition cc) {
1447 DCHECK(cc != equal);
1448 DCHECK((cc == less) || (cc == less_equal)
1449 || (cc == greater) || (cc == greater_equal));
1450 return (cc == greater || cc == greater_equal) ? LESS : GREATER;
1454 static void CheckInputType(MacroAssembler* masm, Register input,
1455 CompareICState::State expected, Label* fail) {
1457 if (expected == CompareICState::SMI) {
1458 __ JumpIfNotSmi(input, fail);
1459 } else if (expected == CompareICState::NUMBER) {
1460 __ JumpIfSmi(input, &ok);
1461 __ CompareMap(input, masm->isolate()->factory()->heap_number_map());
1462 __ j(not_equal, fail);
1464 // We could be strict about internalized/non-internalized here, but as long as
1465 // hydrogen doesn't care, the stub doesn't have to care either.
1470 static void BranchIfNotInternalizedString(MacroAssembler* masm,
1474 __ JumpIfSmi(object, label);
1475 __ movp(scratch, FieldOperand(object, HeapObject::kMapOffset));
1477 FieldOperand(scratch, Map::kInstanceTypeOffset));
1478 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
1479 __ testb(scratch, Immediate(kIsNotStringMask | kIsNotInternalizedMask));
1480 __ j(not_zero, label);
1484 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
1485 Label runtime_call, check_unequal_objects, done;
1486 Condition cc = GetCondition();
1487 Factory* factory = isolate()->factory();
1490 CheckInputType(masm, rdx, left(), &miss);
1491 CheckInputType(masm, rax, right(), &miss);
1493 // Compare two smis.
1494 Label non_smi, smi_done;
1495 __ JumpIfNotBothSmi(rax, rdx, &non_smi);
1497 __ j(no_overflow, &smi_done);
1498 __ notp(rdx); // Correct sign in case of overflow. rdx cannot be 0 here.
1504 // The compare stub returns a positive, negative, or zero 64-bit integer
1505 // value in rax, corresponding to result of comparing the two inputs.
1506 // NOTICE! This code is only reached after a smi-fast-case check, so
1507 // it is certain that at least one operand isn't a smi.
1509 // Two identical objects are equal unless they are both NaN or undefined.
1511 Label not_identical;
1513 __ j(not_equal, ¬_identical, Label::kNear);
1516 // Check for undefined. undefined OP undefined is false even though
1517 // undefined == undefined.
1518 __ CompareRoot(rdx, Heap::kUndefinedValueRootIndex);
1519 if (is_strong(strength())) {
1520 // In strong mode, this comparison must throw, so call the runtime.
1521 __ j(equal, &runtime_call, Label::kFar);
1523 Label check_for_nan;
1524 __ j(not_equal, &check_for_nan, Label::kNear);
1525 __ Set(rax, NegativeComparisonResult(cc));
1527 __ bind(&check_for_nan);
1531 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
1532 // so we do the second best thing - test it ourselves.
1534 // If it's not a heap number, then return equal for (in)equality operator.
1535 __ Cmp(FieldOperand(rdx, HeapObject::kMapOffset),
1536 factory->heap_number_map());
1537 __ j(equal, &heap_number, Label::kNear);
1539 __ movp(rcx, FieldOperand(rax, HeapObject::kMapOffset));
1540 __ movzxbl(rcx, FieldOperand(rcx, Map::kInstanceTypeOffset));
1541 // Call runtime on identical objects. Otherwise return equal.
1542 __ cmpb(rcx, Immediate(static_cast<uint8_t>(FIRST_SPEC_OBJECT_TYPE)));
1543 __ j(above_equal, &runtime_call, Label::kFar);
1544 // Call runtime on identical symbols since we need to throw a TypeError.
1545 __ cmpb(rcx, Immediate(static_cast<uint8_t>(SYMBOL_TYPE)));
1546 __ j(equal, &runtime_call, Label::kFar);
1547 // Call runtime on identical SIMD values since we must throw a TypeError.
1548 __ cmpb(rcx, Immediate(static_cast<uint8_t>(SIMD128_VALUE_TYPE)));
1549 __ j(equal, &runtime_call, Label::kFar);
1550 if (is_strong(strength())) {
1551 // We have already tested for smis and heap numbers, so if both
1552 // arguments are not strings we must proceed to the slow case.
1553 __ testb(rcx, Immediate(kIsNotStringMask));
1554 __ j(not_zero, &runtime_call, Label::kFar);
1560 __ bind(&heap_number);
1561 // It is a heap number, so return equal if it's not NaN.
1562 // For NaN, return 1 for every condition except greater and
1563 // greater-equal. Return -1 for them, so the comparison yields
1564 // false for all conditions except not-equal.
1566 __ movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset));
1567 __ ucomisd(xmm0, xmm0);
1568 __ setcc(parity_even, rax);
1569 // rax is 0 for equal non-NaN heapnumbers, 1 for NaNs.
1570 if (cc == greater_equal || cc == greater) {
1575 __ bind(¬_identical);
1578 if (cc == equal) { // Both strict and non-strict.
1579 Label slow; // Fallthrough label.
1581 // If we're doing a strict equality comparison, we don't have to do
1582 // type conversion, so we generate code to do fast comparison for objects
1583 // and oddballs. Non-smi numbers and strings still go through the usual
1586 // If either is a Smi (we know that not both are), then they can only
1587 // be equal if the other is a HeapNumber. If so, use the slow case.
1590 __ SelectNonSmi(rbx, rax, rdx, ¬_smis);
1592 // Check if the non-smi operand is a heap number.
1593 __ Cmp(FieldOperand(rbx, HeapObject::kMapOffset),
1594 factory->heap_number_map());
1595 // If heap number, handle it in the slow case.
1597 // Return non-equal. ebx (the lower half of rbx) is not zero.
1604 // If either operand is a JSObject or an oddball value, then they are not
1605 // equal since their pointers are different
1606 // There is no test for undetectability in strict equality.
1608 // If the first object is a JS object, we have done pointer comparison.
1609 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
1610 Label first_non_object;
1611 __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx);
1612 __ j(below, &first_non_object, Label::kNear);
1613 // Return non-zero (rax (not rax) is not zero)
1614 Label return_not_equal;
1615 STATIC_ASSERT(kHeapObjectTag != 0);
1616 __ bind(&return_not_equal);
1619 __ bind(&first_non_object);
1620 // Check for oddballs: true, false, null, undefined.
1621 __ CmpInstanceType(rcx, ODDBALL_TYPE);
1622 __ j(equal, &return_not_equal);
1624 __ CmpObjectType(rdx, FIRST_SPEC_OBJECT_TYPE, rcx);
1625 __ j(above_equal, &return_not_equal);
1627 // Check for oddballs: true, false, null, undefined.
1628 __ CmpInstanceType(rcx, ODDBALL_TYPE);
1629 __ j(equal, &return_not_equal);
1631 // Fall through to the general case.
1636 // Generate the number comparison code.
1637 Label non_number_comparison;
1639 FloatingPointHelper::LoadSSE2UnknownOperands(masm, &non_number_comparison);
1642 __ ucomisd(xmm0, xmm1);
1644 // Don't base result on EFLAGS when a NaN is involved.
1645 __ j(parity_even, &unordered, Label::kNear);
1646 // Return a result of -1, 0, or 1, based on EFLAGS.
1647 __ setcc(above, rax);
1648 __ setcc(below, rcx);
1652 // If one of the numbers was NaN, then the result is always false.
1653 // The cc is never not-equal.
1654 __ bind(&unordered);
1655 DCHECK(cc != not_equal);
1656 if (cc == less || cc == less_equal) {
1663 // The number comparison code did not provide a valid result.
1664 __ bind(&non_number_comparison);
1666 // Fast negative check for internalized-to-internalized equality.
1667 Label check_for_strings;
1669 BranchIfNotInternalizedString(
1670 masm, &check_for_strings, rax, kScratchRegister);
1671 BranchIfNotInternalizedString(
1672 masm, &check_for_strings, rdx, kScratchRegister);
1674 // We've already checked for object identity, so if both operands are
1675 // internalized strings they aren't equal. Register rax (not rax) already
1676 // holds a non-zero value, which indicates not equal, so just return.
1680 __ bind(&check_for_strings);
1682 __ JumpIfNotBothSequentialOneByteStrings(rdx, rax, rcx, rbx,
1683 &check_unequal_objects);
1685 // Inline comparison of one-byte strings.
1687 StringHelper::GenerateFlatOneByteStringEquals(masm, rdx, rax, rcx, rbx);
1689 StringHelper::GenerateCompareFlatOneByteStrings(masm, rdx, rax, rcx, rbx,
1694 __ Abort(kUnexpectedFallThroughFromStringComparison);
1697 __ bind(&check_unequal_objects);
1698 if (cc == equal && !strict()) {
1699 // Not strict equality. Objects are unequal if
1700 // they are both JSObjects and not undetectable,
1701 // and their pointers are different.
1702 Label return_unequal;
1703 // At most one is a smi, so we can test for smi by adding the two.
1704 // A smi plus a heap object has the low bit set, a heap object plus
1705 // a heap object has the low bit clear.
1706 STATIC_ASSERT(kSmiTag == 0);
1707 STATIC_ASSERT(kSmiTagMask == 1);
1708 __ leap(rcx, Operand(rax, rdx, times_1, 0));
1709 __ testb(rcx, Immediate(kSmiTagMask));
1710 __ j(not_zero, &runtime_call, Label::kNear);
1711 __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rbx);
1712 __ j(below, &runtime_call, Label::kNear);
1713 __ CmpObjectType(rdx, FIRST_SPEC_OBJECT_TYPE, rcx);
1714 __ j(below, &runtime_call, Label::kNear);
1715 __ testb(FieldOperand(rbx, Map::kBitFieldOffset),
1716 Immediate(1 << Map::kIsUndetectable));
1717 __ j(zero, &return_unequal, Label::kNear);
1718 __ testb(FieldOperand(rcx, Map::kBitFieldOffset),
1719 Immediate(1 << Map::kIsUndetectable));
1720 __ j(zero, &return_unequal, Label::kNear);
1721 // The objects are both undetectable, so they both compare as the value
1722 // undefined, and are equal.
1724 __ bind(&return_unequal);
1725 // Return non-equal by returning the non-zero object pointer in rax,
1726 // or return equal if we fell through to here.
1729 __ bind(&runtime_call);
1731 // Push arguments below the return address to prepare jump to builtin.
1732 __ PopReturnAddressTo(rcx);
1736 // Figure out which native to call and setup the arguments.
1738 __ PushReturnAddressFrom(rcx);
1739 __ TailCallRuntime(strict() ? Runtime::kStrictEquals : Runtime::kEquals, 2,
1742 __ Push(Smi::FromInt(NegativeComparisonResult(cc)));
1743 __ PushReturnAddressFrom(rcx);
1745 is_strong(strength()) ? Runtime::kCompare_Strong : Runtime::kCompare, 3,
1754 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
1756 // rax : number of arguments to the construct function
1757 // rbx : feedback vector
1758 // rcx : original constructor (for IsSuperConstructorCall)
1759 // rdx : slot in feedback vector (Smi)
1760 // rdi : the function to call
1761 FrameScope scope(masm, StackFrame::INTERNAL);
1763 // Number-of-arguments register must be smi-tagged to call out.
1764 __ Integer32ToSmi(rax, rax);
1767 __ Integer32ToSmi(rdx, rdx);
1783 __ SmiToInteger32(rax, rax);
1787 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
1788 // Cache the called function in a feedback vector slot. Cache states
1789 // are uninitialized, monomorphic (indicated by a JSFunction), and
1791 // rax : number of arguments to the construct function
1792 // rbx : feedback vector
1793 // rcx : original constructor (for IsSuperConstructorCall)
1794 // rdx : slot in feedback vector (Smi)
1795 // rdi : the function to call
1796 Isolate* isolate = masm->isolate();
1797 Label initialize, done, miss, megamorphic, not_array_function,
1798 done_no_smi_convert;
1800 // Load the cache state into r11.
1801 __ SmiToInteger32(rdx, rdx);
1803 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize));
1805 // A monomorphic cache hit or an already megamorphic state: invoke the
1806 // function without changing the state.
1807 // We don't know if r11 is a WeakCell or a Symbol, but it's harmless to read
1808 // at this position in a symbol (see static asserts in
1809 // type-feedback-vector.h).
1810 Label check_allocation_site;
1811 __ cmpp(rdi, FieldOperand(r11, WeakCell::kValueOffset));
1812 __ j(equal, &done, Label::kFar);
1813 __ CompareRoot(r11, Heap::kmegamorphic_symbolRootIndex);
1814 __ j(equal, &done, Label::kFar);
1815 __ CompareRoot(FieldOperand(r11, HeapObject::kMapOffset),
1816 Heap::kWeakCellMapRootIndex);
1817 __ j(not_equal, &check_allocation_site);
1819 // If the weak cell is cleared, we have a new chance to become monomorphic.
1820 __ CheckSmi(FieldOperand(r11, WeakCell::kValueOffset));
1821 __ j(equal, &initialize);
1822 __ jmp(&megamorphic);
1824 __ bind(&check_allocation_site);
1825 // If we came here, we need to see if we are the array function.
1826 // If we didn't have a matching function, and we didn't find the megamorph
1827 // sentinel, then we have in the slot either some other function or an
1829 __ CompareRoot(FieldOperand(r11, 0), Heap::kAllocationSiteMapRootIndex);
1830 __ j(not_equal, &miss);
1832 // Make sure the function is the Array() function
1833 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r11);
1835 __ j(not_equal, &megamorphic);
1840 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
1842 __ CompareRoot(r11, Heap::kuninitialized_symbolRootIndex);
1843 __ j(equal, &initialize);
1844 // MegamorphicSentinel is an immortal immovable object (undefined) so no
1845 // write-barrier is needed.
1846 __ bind(&megamorphic);
1847 __ Move(FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize),
1848 TypeFeedbackVector::MegamorphicSentinel(isolate));
1851 // An uninitialized cache is patched with the function or sentinel to
1852 // indicate the ElementsKind if function is the Array constructor.
1853 __ bind(&initialize);
1855 // Make sure the function is the Array() function
1856 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r11);
1858 __ j(not_equal, ¬_array_function);
1860 CreateAllocationSiteStub create_stub(isolate);
1861 CallStubInRecordCallTarget(masm, &create_stub, is_super);
1862 __ jmp(&done_no_smi_convert);
1864 __ bind(¬_array_function);
1865 CreateWeakCellStub weak_cell_stub(isolate);
1866 CallStubInRecordCallTarget(masm, &weak_cell_stub, is_super);
1867 __ jmp(&done_no_smi_convert);
1870 __ Integer32ToSmi(rdx, rdx);
1872 __ bind(&done_no_smi_convert);
1876 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
1877 // Do not transform the receiver for strict mode functions.
1878 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
1879 __ testb(FieldOperand(rcx, SharedFunctionInfo::kStrictModeByteOffset),
1880 Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte));
1881 __ j(not_equal, cont);
1883 // Do not transform the receiver for natives.
1884 // SharedFunctionInfo is already loaded into rcx.
1885 __ testb(FieldOperand(rcx, SharedFunctionInfo::kNativeByteOffset),
1886 Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte));
1887 __ j(not_equal, cont);
1891 static void EmitSlowCase(MacroAssembler* masm, StackArgumentsAccessor* args,
1894 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
1898 static void EmitWrapCase(MacroAssembler* masm,
1899 StackArgumentsAccessor* args,
1901 // Wrap the receiver and patch it back onto the stack.
1902 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
1904 ToObjectStub stub(masm->isolate());
1908 __ movp(args->GetReceiverOperand(), rax);
1913 static void CallFunctionNoFeedback(MacroAssembler* masm,
1914 int argc, bool needs_checks,
1915 bool call_as_method) {
1916 // rdi : the function to call
1918 // wrap_and_call can only be true if we are compiling a monomorphic method.
1919 Label slow, wrap, cont;
1920 StackArgumentsAccessor args(rsp, argc);
1923 // Check that the function really is a JavaScript function.
1924 __ JumpIfSmi(rdi, &slow);
1926 // Goto slow case if we do not have a function.
1927 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx);
1928 __ j(not_equal, &slow);
1931 // Fast-case: Just invoke the function.
1932 ParameterCount actual(argc);
1934 if (call_as_method) {
1936 EmitContinueIfStrictOrNative(masm, &cont);
1939 // Load the receiver from the stack.
1940 __ movp(rax, args.GetReceiverOperand());
1943 __ JumpIfSmi(rax, &wrap);
1945 __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx);
1954 __ InvokeFunction(rdi, actual, JUMP_FUNCTION, NullCallWrapper());
1957 // Slow-case: Non-function called.
1959 EmitSlowCase(masm, &args, argc);
1962 if (call_as_method) {
1964 EmitWrapCase(masm, &args, &cont);
1969 void CallFunctionStub::Generate(MacroAssembler* masm) {
1970 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
1974 void CallConstructStub::Generate(MacroAssembler* masm) {
1975 // rax : number of arguments
1976 // rbx : feedback vector
1977 // rcx : original constructor (for IsSuperConstructorCall)
1978 // rdx : slot in feedback vector (Smi, for RecordCallTarget)
1979 // rdi : constructor function
1980 Label slow, non_function_call;
1982 // Check that function is not a smi.
1983 __ JumpIfSmi(rdi, &non_function_call);
1984 // Check that function is a JSFunction.
1985 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, r11);
1986 __ j(not_equal, &slow);
1988 if (RecordCallTarget()) {
1989 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
1991 __ SmiToInteger32(rdx, rdx);
1992 Label feedback_register_initialized;
1993 // Put the AllocationSite from the feedback vector into rbx, or undefined.
1994 __ movp(rbx, FieldOperand(rbx, rdx, times_pointer_size,
1995 FixedArray::kHeaderSize));
1996 __ CompareRoot(FieldOperand(rbx, 0), Heap::kAllocationSiteMapRootIndex);
1997 __ j(equal, &feedback_register_initialized);
1998 __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex);
1999 __ bind(&feedback_register_initialized);
2001 __ AssertUndefinedOrAllocationSite(rbx);
2004 // Pass original constructor to construct stub.
2005 if (IsSuperConstructorCall()) {
2011 // Jump to the function-specific construct stub.
2012 Register jmp_reg = rcx;
2013 __ movp(jmp_reg, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
2014 __ movp(jmp_reg, FieldOperand(jmp_reg,
2015 SharedFunctionInfo::kConstructStubOffset));
2016 __ leap(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize));
2019 // rdi: called object
2020 // rax: number of arguments
2024 __ CmpInstanceType(r11, JS_FUNCTION_PROXY_TYPE);
2025 __ j(not_equal, &non_function_call, Label::kNear);
2027 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies.
2028 __ movp(rdi, FieldOperand(rdi, JSFunctionProxy::kConstructTrapOffset));
2029 __ Jump(isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2031 __ bind(&non_function_call);
2033 // Determine the delegate for the target (if any).
2034 FrameScope scope(masm, StackFrame::INTERNAL);
2035 __ Integer32ToSmi(rax, rax);
2038 __ CallRuntime(Runtime::kGetConstructorDelegate, 1);
2041 __ SmiToInteger32(rax, rax);
2043 // The delegate is always a regular function.
2044 __ AssertFunction(rdi);
2045 __ Jump(isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET);
2050 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2051 __ movp(vector, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
2052 __ movp(vector, FieldOperand(vector, JSFunction::kSharedFunctionInfoOffset));
2053 __ movp(vector, FieldOperand(vector,
2054 SharedFunctionInfo::kFeedbackVectorOffset));
2058 void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) {
2062 // rcx - allocation site (loaded from vector[slot]).
2063 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r8);
2065 __ j(not_equal, miss);
2067 __ movp(rax, Immediate(arg_count()));
2069 // Increment the call count for monomorphic function calls.
2070 __ SmiAddConstant(FieldOperand(rbx, rdx, times_pointer_size,
2071 FixedArray::kHeaderSize + kPointerSize),
2072 Smi::FromInt(CallICNexus::kCallCountIncrement));
2076 ArrayConstructorStub stub(masm->isolate(), arg_count());
2077 __ TailCallStub(&stub);
2081 void CallICStub::Generate(MacroAssembler* masm) {
2085 Isolate* isolate = masm->isolate();
2086 const int with_types_offset =
2087 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2088 const int generic_offset =
2089 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2090 Label extra_checks_or_miss, slow_start;
2091 Label slow, wrap, cont;
2092 Label have_js_function;
2093 int argc = arg_count();
2094 StackArgumentsAccessor args(rsp, argc);
2095 ParameterCount actual(argc);
2097 // The checks. First, does rdi match the recorded monomorphic target?
2098 __ SmiToInteger32(rdx, rdx);
2100 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize));
2102 // We don't know that we have a weak cell. We might have a private symbol
2103 // or an AllocationSite, but the memory is safe to examine.
2104 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2106 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2107 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2108 // computed, meaning that it can't appear to be a pointer. If the low bit is
2109 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2111 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2112 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2113 WeakCell::kValueOffset &&
2114 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2116 __ cmpp(rdi, FieldOperand(rcx, WeakCell::kValueOffset));
2117 __ j(not_equal, &extra_checks_or_miss);
2119 // The compare above could have been a SMI/SMI comparison. Guard against this
2120 // convincing us that we have a monomorphic JSFunction.
2121 __ JumpIfSmi(rdi, &extra_checks_or_miss);
2123 // Increment the call count for monomorphic function calls.
2124 __ SmiAddConstant(FieldOperand(rbx, rdx, times_pointer_size,
2125 FixedArray::kHeaderSize + kPointerSize),
2126 Smi::FromInt(CallICNexus::kCallCountIncrement));
2128 __ bind(&have_js_function);
2129 if (CallAsMethod()) {
2130 EmitContinueIfStrictOrNative(masm, &cont);
2132 // Load the receiver from the stack.
2133 __ movp(rax, args.GetReceiverOperand());
2135 __ JumpIfSmi(rax, &wrap);
2137 __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx);
2143 __ InvokeFunction(rdi, actual, JUMP_FUNCTION, NullCallWrapper());
2146 EmitSlowCase(masm, &args, argc);
2148 if (CallAsMethod()) {
2150 EmitWrapCase(masm, &args, &cont);
2153 __ bind(&extra_checks_or_miss);
2154 Label uninitialized, miss, not_allocation_site;
2156 __ Cmp(rcx, TypeFeedbackVector::MegamorphicSentinel(isolate));
2157 __ j(equal, &slow_start);
2159 // Check if we have an allocation site.
2160 __ CompareRoot(FieldOperand(rcx, HeapObject::kMapOffset),
2161 Heap::kAllocationSiteMapRootIndex);
2162 __ j(not_equal, ¬_allocation_site);
2164 // We have an allocation site.
2165 HandleArrayCase(masm, &miss);
2167 __ bind(¬_allocation_site);
2169 // The following cases attempt to handle MISS cases without going to the
2171 if (FLAG_trace_ic) {
2175 __ Cmp(rcx, TypeFeedbackVector::UninitializedSentinel(isolate));
2176 __ j(equal, &uninitialized);
2178 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2179 // to handle it here. More complex cases are dealt with in the runtime.
2180 __ AssertNotSmi(rcx);
2181 __ CmpObjectType(rcx, JS_FUNCTION_TYPE, rcx);
2182 __ j(not_equal, &miss);
2183 __ Move(FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize),
2184 TypeFeedbackVector::MegamorphicSentinel(isolate));
2185 // We have to update statistics for runtime profiling.
2186 __ SmiAddConstant(FieldOperand(rbx, with_types_offset), Smi::FromInt(-1));
2187 __ SmiAddConstant(FieldOperand(rbx, generic_offset), Smi::FromInt(1));
2188 __ jmp(&slow_start);
2190 __ bind(&uninitialized);
2192 // We are going monomorphic, provided we actually have a JSFunction.
2193 __ JumpIfSmi(rdi, &miss);
2195 // Goto miss case if we do not have a function.
2196 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx);
2197 __ j(not_equal, &miss);
2199 // Make sure the function is not the Array() function, which requires special
2200 // behavior on MISS.
2201 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, rcx);
2206 __ SmiAddConstant(FieldOperand(rbx, with_types_offset), Smi::FromInt(1));
2208 // Initialize the call counter.
2209 __ Move(FieldOperand(rbx, rdx, times_pointer_size,
2210 FixedArray::kHeaderSize + kPointerSize),
2211 Smi::FromInt(CallICNexus::kCallCountIncrement));
2213 // Store the function. Use a stub since we need a frame for allocation.
2215 // rdx - slot (needs to be in smi form)
2218 FrameScope scope(masm, StackFrame::INTERNAL);
2219 CreateWeakCellStub create_stub(isolate);
2221 __ Integer32ToSmi(rdx, rdx);
2223 __ CallStub(&create_stub);
2227 __ jmp(&have_js_function);
2229 // We are here because tracing is on or we encountered a MISS case we can't
2235 __ bind(&slow_start);
2236 // Check that function is not a smi.
2237 __ JumpIfSmi(rdi, &slow);
2238 // Check that function is a JSFunction.
2239 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx);
2240 __ j(not_equal, &slow);
2241 __ jmp(&have_js_function);
2248 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2249 FrameScope scope(masm, StackFrame::INTERNAL);
2251 // Push the receiver and the function and feedback info.
2254 __ Integer32ToSmi(rdx, rdx);
2258 __ CallRuntime(Runtime::kCallIC_Miss, 3);
2260 // Move result to edi and exit the internal frame.
2265 bool CEntryStub::NeedsImmovableCode() {
2270 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
2271 CEntryStub::GenerateAheadOfTime(isolate);
2272 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
2273 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
2274 // It is important that the store buffer overflow stubs are generated first.
2275 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
2276 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
2277 CreateWeakCellStub::GenerateAheadOfTime(isolate);
2278 BinaryOpICStub::GenerateAheadOfTime(isolate);
2279 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
2280 StoreFastElementStub::GenerateAheadOfTime(isolate);
2281 TypeofStub::GenerateAheadOfTime(isolate);
2285 void CodeStub::GenerateFPStubs(Isolate* isolate) {
2289 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
2290 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
2292 CEntryStub save_doubles(isolate, 1, kSaveFPRegs);
2293 save_doubles.GetCode();
2297 void CEntryStub::Generate(MacroAssembler* masm) {
2298 // rax: number of arguments including receiver
2299 // rbx: pointer to C function (C callee-saved)
2300 // rbp: frame pointer of calling JS frame (restored after C call)
2301 // rsp: stack pointer (restored after C call)
2302 // rsi: current context (restored)
2304 ProfileEntryHookStub::MaybeCallEntryHook(masm);
2306 // Enter the exit frame that transitions from JavaScript to C++.
2308 int arg_stack_space = (result_size() < 2 ? 2 : 4);
2310 int arg_stack_space = 0;
2312 __ EnterExitFrame(arg_stack_space, save_doubles());
2314 // rbx: pointer to builtin function (C callee-saved).
2315 // rbp: frame pointer of exit frame (restored after C call).
2316 // rsp: stack pointer (restored after C call).
2317 // r14: number of arguments including receiver (C callee-saved).
2318 // r15: argv pointer (C callee-saved).
2320 // Simple results returned in rax (both AMD64 and Win64 calling conventions).
2321 // Complex results must be written to address passed as first argument.
2322 // AMD64 calling convention: a struct of two pointers in rax+rdx
2324 // Check stack alignment.
2325 if (FLAG_debug_code) {
2326 __ CheckStackAlignment();
2331 // Windows 64-bit ABI passes arguments in rcx, rdx, r8, r9.
2332 // Pass argv and argc as two parameters. The arguments object will
2333 // be created by stubs declared by DECLARE_RUNTIME_FUNCTION().
2334 if (result_size() < 2) {
2335 // Pass a pointer to the Arguments object as the first argument.
2336 // Return result in single register (rax).
2337 __ movp(rcx, r14); // argc.
2338 __ movp(rdx, r15); // argv.
2339 __ Move(r8, ExternalReference::isolate_address(isolate()));
2341 DCHECK_EQ(2, result_size());
2342 // Pass a pointer to the result location as the first argument.
2343 __ leap(rcx, StackSpaceOperand(2));
2344 // Pass a pointer to the Arguments object as the second argument.
2345 __ movp(rdx, r14); // argc.
2346 __ movp(r8, r15); // argv.
2347 __ Move(r9, ExternalReference::isolate_address(isolate()));
2351 // GCC passes arguments in rdi, rsi, rdx, rcx, r8, r9.
2352 __ movp(rdi, r14); // argc.
2353 __ movp(rsi, r15); // argv.
2354 __ Move(rdx, ExternalReference::isolate_address(isolate()));
2357 // Result is in rax - do not destroy this register!
2360 // If return value is on the stack, pop it to registers.
2361 if (result_size() > 1) {
2362 DCHECK_EQ(2, result_size());
2363 // Read result values stored on stack. Result is stored
2364 // above the four argument mirror slots and the two
2365 // Arguments object slots.
2366 __ movq(rax, Operand(rsp, 6 * kRegisterSize));
2367 __ movq(rdx, Operand(rsp, 7 * kRegisterSize));
2371 // Check result for exception sentinel.
2372 Label exception_returned;
2373 __ CompareRoot(rax, Heap::kExceptionRootIndex);
2374 __ j(equal, &exception_returned);
2376 // Check that there is no pending exception, otherwise we
2377 // should have returned the exception sentinel.
2378 if (FLAG_debug_code) {
2380 __ LoadRoot(r14, Heap::kTheHoleValueRootIndex);
2381 ExternalReference pending_exception_address(
2382 Isolate::kPendingExceptionAddress, isolate());
2383 Operand pending_exception_operand =
2384 masm->ExternalOperand(pending_exception_address);
2385 __ cmpp(r14, pending_exception_operand);
2386 __ j(equal, &okay, Label::kNear);
2391 // Exit the JavaScript to C++ exit frame.
2392 __ LeaveExitFrame(save_doubles());
2395 // Handling of exception.
2396 __ bind(&exception_returned);
2398 ExternalReference pending_handler_context_address(
2399 Isolate::kPendingHandlerContextAddress, isolate());
2400 ExternalReference pending_handler_code_address(
2401 Isolate::kPendingHandlerCodeAddress, isolate());
2402 ExternalReference pending_handler_offset_address(
2403 Isolate::kPendingHandlerOffsetAddress, isolate());
2404 ExternalReference pending_handler_fp_address(
2405 Isolate::kPendingHandlerFPAddress, isolate());
2406 ExternalReference pending_handler_sp_address(
2407 Isolate::kPendingHandlerSPAddress, isolate());
2409 // Ask the runtime for help to determine the handler. This will set rax to
2410 // contain the current pending exception, don't clobber it.
2411 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
2414 FrameScope scope(masm, StackFrame::MANUAL);
2415 __ movp(arg_reg_1, Immediate(0)); // argc.
2416 __ movp(arg_reg_2, Immediate(0)); // argv.
2417 __ Move(arg_reg_3, ExternalReference::isolate_address(isolate()));
2418 __ PrepareCallCFunction(3);
2419 __ CallCFunction(find_handler, 3);
2422 // Retrieve the handler context, SP and FP.
2423 __ movp(rsi, masm->ExternalOperand(pending_handler_context_address));
2424 __ movp(rsp, masm->ExternalOperand(pending_handler_sp_address));
2425 __ movp(rbp, masm->ExternalOperand(pending_handler_fp_address));
2427 // If the handler is a JS frame, restore the context to the frame. Note that
2428 // the context will be set to (rsi == 0) for non-JS frames.
2431 __ j(zero, &skip, Label::kNear);
2432 __ movp(Operand(rbp, StandardFrameConstants::kContextOffset), rsi);
2435 // Compute the handler entry address and jump to it.
2436 __ movp(rdi, masm->ExternalOperand(pending_handler_code_address));
2437 __ movp(rdx, masm->ExternalOperand(pending_handler_offset_address));
2438 __ leap(rdi, FieldOperand(rdi, rdx, times_1, Code::kHeaderSize));
2443 void JSEntryStub::Generate(MacroAssembler* masm) {
2444 Label invoke, handler_entry, exit;
2445 Label not_outermost_js, not_outermost_js_2;
2447 ProfileEntryHookStub::MaybeCallEntryHook(masm);
2449 { // NOLINT. Scope block confuses linter.
2450 MacroAssembler::NoRootArrayScope uninitialized_root_register(masm);
2455 // Push the stack frame type marker twice.
2456 int marker = type();
2457 // Scratch register is neither callee-save, nor an argument register on any
2458 // platform. It's free to use at this point.
2459 // Cannot use smi-register for loading yet.
2460 __ Move(kScratchRegister, Smi::FromInt(marker), Assembler::RelocInfoNone());
2461 __ Push(kScratchRegister); // context slot
2462 __ Push(kScratchRegister); // function slot
2463 // Save callee-saved registers (X64/X32/Win64 calling conventions).
2469 __ pushq(rdi); // Only callee save in Win64 ABI, argument in AMD64 ABI.
2470 __ pushq(rsi); // Only callee save in Win64 ABI, argument in AMD64 ABI.
2475 // On Win64 XMM6-XMM15 are callee-save
2476 __ subp(rsp, Immediate(EntryFrameConstants::kXMMRegistersBlockSize));
2477 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 0), xmm6);
2478 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 1), xmm7);
2479 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 2), xmm8);
2480 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 3), xmm9);
2481 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 4), xmm10);
2482 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 5), xmm11);
2483 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 6), xmm12);
2484 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 7), xmm13);
2485 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 8), xmm14);
2486 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 9), xmm15);
2489 // Set up the roots and smi constant registers.
2490 // Needs to be done before any further smi loads.
2491 __ InitializeRootRegister();
2494 // Save copies of the top frame descriptor on the stack.
2495 ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, isolate());
2497 Operand c_entry_fp_operand = masm->ExternalOperand(c_entry_fp);
2498 __ Push(c_entry_fp_operand);
2501 // If this is the outermost JS call, set js_entry_sp value.
2502 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
2503 __ Load(rax, js_entry_sp);
2505 __ j(not_zero, ¬_outermost_js);
2506 __ Push(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
2508 __ Store(js_entry_sp, rax);
2511 __ bind(¬_outermost_js);
2512 __ Push(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME));
2515 // Jump to a faked try block that does the invoke, with a faked catch
2516 // block that sets the pending exception.
2518 __ bind(&handler_entry);
2519 handler_offset_ = handler_entry.pos();
2520 // Caught exception: Store result (exception) in the pending exception
2521 // field in the JSEnv and return a failure sentinel.
2522 ExternalReference pending_exception(Isolate::kPendingExceptionAddress,
2524 __ Store(pending_exception, rax);
2525 __ LoadRoot(rax, Heap::kExceptionRootIndex);
2528 // Invoke: Link this frame into the handler chain.
2530 __ PushStackHandler();
2532 // Clear any pending exceptions.
2533 __ LoadRoot(rax, Heap::kTheHoleValueRootIndex);
2534 __ Store(pending_exception, rax);
2536 // Fake a receiver (NULL).
2537 __ Push(Immediate(0)); // receiver
2539 // Invoke the function by calling through JS entry trampoline builtin and
2540 // pop the faked function when we return. We load the address from an
2541 // external reference instead of inlining the call target address directly
2542 // in the code, because the builtin stubs may not have been generated yet
2543 // at the time this code is generated.
2544 if (type() == StackFrame::ENTRY_CONSTRUCT) {
2545 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
2547 __ Load(rax, construct_entry);
2549 ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
2550 __ Load(rax, entry);
2552 __ leap(kScratchRegister, FieldOperand(rax, Code::kHeaderSize));
2553 __ call(kScratchRegister);
2555 // Unlink this frame from the handler chain.
2556 __ PopStackHandler();
2559 // Check if the current stack frame is marked as the outermost JS frame.
2561 __ Cmp(rbx, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
2562 __ j(not_equal, ¬_outermost_js_2);
2563 __ Move(kScratchRegister, js_entry_sp);
2564 __ movp(Operand(kScratchRegister, 0), Immediate(0));
2565 __ bind(¬_outermost_js_2);
2567 // Restore the top frame descriptor from the stack.
2568 { Operand c_entry_fp_operand = masm->ExternalOperand(c_entry_fp);
2569 __ Pop(c_entry_fp_operand);
2572 // Restore callee-saved registers (X64 conventions).
2574 // On Win64 XMM6-XMM15 are callee-save
2575 __ movdqu(xmm6, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 0));
2576 __ movdqu(xmm7, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 1));
2577 __ movdqu(xmm8, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 2));
2578 __ movdqu(xmm9, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 3));
2579 __ movdqu(xmm10, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 4));
2580 __ movdqu(xmm11, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 5));
2581 __ movdqu(xmm12, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 6));
2582 __ movdqu(xmm13, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 7));
2583 __ movdqu(xmm14, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 8));
2584 __ movdqu(xmm15, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 9));
2585 __ addp(rsp, Immediate(EntryFrameConstants::kXMMRegistersBlockSize));
2590 // Callee save on in Win64 ABI, arguments/volatile in AMD64 ABI.
2598 __ addp(rsp, Immediate(2 * kPointerSize)); // remove markers
2600 // Restore frame pointer and return.
2606 void InstanceOfStub::Generate(MacroAssembler* masm) {
2607 Register const object = rdx; // Object (lhs).
2608 Register const function = rax; // Function (rhs).
2609 Register const object_map = rcx; // Map of {object}.
2610 Register const function_map = r8; // Map of {function}.
2611 Register const function_prototype = rdi; // Prototype of {function}.
2613 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
2614 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
2616 // Check if {object} is a smi.
2617 Label object_is_smi;
2618 __ JumpIfSmi(object, &object_is_smi, Label::kNear);
2620 // Lookup the {function} and the {object} map in the global instanceof cache.
2621 // Note: This is safe because we clear the global instanceof cache whenever
2622 // we change the prototype of any object.
2623 Label fast_case, slow_case;
2624 __ movp(object_map, FieldOperand(object, HeapObject::kMapOffset));
2625 __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
2626 __ j(not_equal, &fast_case, Label::kNear);
2627 __ CompareRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
2628 __ j(not_equal, &fast_case, Label::kNear);
2629 __ LoadRoot(rax, Heap::kInstanceofCacheAnswerRootIndex);
2632 // If {object} is a smi we can safely return false if {function} is a JS
2633 // function, otherwise we have to miss to the runtime and throw an exception.
2634 __ bind(&object_is_smi);
2635 __ JumpIfSmi(function, &slow_case);
2636 __ CmpObjectType(function, JS_FUNCTION_TYPE, function_map);
2637 __ j(not_equal, &slow_case);
2638 __ LoadRoot(rax, Heap::kFalseValueRootIndex);
2641 // Fast-case: The {function} must be a valid JSFunction.
2642 __ bind(&fast_case);
2643 __ JumpIfSmi(function, &slow_case);
2644 __ CmpObjectType(function, JS_FUNCTION_TYPE, function_map);
2645 __ j(not_equal, &slow_case);
2647 // Ensure that {function} has an instance prototype.
2648 __ testb(FieldOperand(function_map, Map::kBitFieldOffset),
2649 Immediate(1 << Map::kHasNonInstancePrototype));
2650 __ j(not_zero, &slow_case);
2652 // Ensure that {function} is not bound.
2653 Register const shared_info = kScratchRegister;
2654 __ movp(shared_info,
2655 FieldOperand(function, JSFunction::kSharedFunctionInfoOffset));
2656 __ TestBitSharedFunctionInfoSpecialField(
2657 shared_info, SharedFunctionInfo::kCompilerHintsOffset,
2658 SharedFunctionInfo::kBoundFunction);
2659 __ j(not_zero, &slow_case);
2661 // Get the "prototype" (or initial map) of the {function}.
2662 __ movp(function_prototype,
2663 FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
2664 __ AssertNotSmi(function_prototype);
2666 // Resolve the prototype if the {function} has an initial map. Afterwards the
2667 // {function_prototype} will be either the JSReceiver prototype object or the
2668 // hole value, which means that no instances of the {function} were created so
2669 // far and hence we should return false.
2670 Label function_prototype_valid;
2671 Register const function_prototype_map = kScratchRegister;
2672 __ CmpObjectType(function_prototype, MAP_TYPE, function_prototype_map);
2673 __ j(not_equal, &function_prototype_valid, Label::kNear);
2674 __ movp(function_prototype,
2675 FieldOperand(function_prototype, Map::kPrototypeOffset));
2676 __ bind(&function_prototype_valid);
2677 __ AssertNotSmi(function_prototype);
2679 // Update the global instanceof cache with the current {object} map and
2680 // {function}. The cached answer will be set when it is known below.
2681 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
2682 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
2684 // Loop through the prototype chain looking for the {function} prototype.
2685 // Assume true, and change to false if not found.
2686 Register const object_prototype = object_map;
2688 __ LoadRoot(rax, Heap::kTrueValueRootIndex);
2690 __ movp(object_prototype, FieldOperand(object_map, Map::kPrototypeOffset));
2691 __ cmpp(object_prototype, function_prototype);
2692 __ j(equal, &done, Label::kNear);
2693 __ CompareRoot(object_prototype, Heap::kNullValueRootIndex);
2694 __ movp(object_map, FieldOperand(object_prototype, HeapObject::kMapOffset));
2695 __ j(not_equal, &loop);
2696 __ LoadRoot(rax, Heap::kFalseValueRootIndex);
2698 __ StoreRoot(rax, Heap::kInstanceofCacheAnswerRootIndex);
2701 // Slow-case: Call the runtime function.
2702 __ bind(&slow_case);
2703 __ PopReturnAddressTo(kScratchRegister);
2706 __ PushReturnAddressFrom(kScratchRegister);
2707 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
2711 // -------------------------------------------------------------------------
2712 // StringCharCodeAtGenerator
2714 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2715 // If the receiver is a smi trigger the non-string case.
2716 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2717 __ JumpIfSmi(object_, receiver_not_string_);
2719 // Fetch the instance type of the receiver into result register.
2720 __ movp(result_, FieldOperand(object_, HeapObject::kMapOffset));
2721 __ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset));
2722 // If the receiver is not a string trigger the non-string case.
2723 __ testb(result_, Immediate(kIsNotStringMask));
2724 __ j(not_zero, receiver_not_string_);
2727 // If the index is non-smi trigger the non-smi case.
2728 __ JumpIfNotSmi(index_, &index_not_smi_);
2729 __ bind(&got_smi_index_);
2731 // Check for index out of range.
2732 __ SmiCompare(index_, FieldOperand(object_, String::kLengthOffset));
2733 __ j(above_equal, index_out_of_range_);
2735 __ SmiToInteger32(index_, index_);
2737 StringCharLoadGenerator::Generate(
2738 masm, object_, index_, result_, &call_runtime_);
2740 __ Integer32ToSmi(result_, result_);
2745 void StringCharCodeAtGenerator::GenerateSlow(
2746 MacroAssembler* masm, EmbedMode embed_mode,
2747 const RuntimeCallHelper& call_helper) {
2748 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2750 Factory* factory = masm->isolate()->factory();
2751 // Index is not a smi.
2752 __ bind(&index_not_smi_);
2753 // If index is a heap number, try converting it to an integer.
2755 factory->heap_number_map(),
2758 call_helper.BeforeCall(masm);
2759 if (embed_mode == PART_OF_IC_HANDLER) {
2760 __ Push(LoadWithVectorDescriptor::VectorRegister());
2761 __ Push(LoadDescriptor::SlotRegister());
2764 __ Push(index_); // Consumed by runtime conversion function.
2765 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2766 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2768 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2769 // NumberToSmi discards numbers that are not exact integers.
2770 __ CallRuntime(Runtime::kNumberToSmi, 1);
2772 if (!index_.is(rax)) {
2773 // Save the conversion result before the pop instructions below
2774 // have a chance to overwrite it.
2775 __ movp(index_, rax);
2778 if (embed_mode == PART_OF_IC_HANDLER) {
2779 __ Pop(LoadDescriptor::SlotRegister());
2780 __ Pop(LoadWithVectorDescriptor::VectorRegister());
2782 // Reload the instance type.
2783 __ movp(result_, FieldOperand(object_, HeapObject::kMapOffset));
2784 __ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset));
2785 call_helper.AfterCall(masm);
2786 // If index is still not a smi, it must be out of range.
2787 __ JumpIfNotSmi(index_, index_out_of_range_);
2788 // Otherwise, return to the fast path.
2789 __ jmp(&got_smi_index_);
2791 // Call runtime. We get here when the receiver is a string and the
2792 // index is a number, but the code of getting the actual character
2793 // is too complex (e.g., when the string needs to be flattened).
2794 __ bind(&call_runtime_);
2795 call_helper.BeforeCall(masm);
2797 __ Integer32ToSmi(index_, index_);
2799 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
2800 if (!result_.is(rax)) {
2801 __ movp(result_, rax);
2803 call_helper.AfterCall(masm);
2806 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
2810 // -------------------------------------------------------------------------
2811 // StringCharFromCodeGenerator
2813 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
2814 // Fast case of Heap::LookupSingleCharacterStringFromCode.
2815 __ JumpIfNotSmi(code_, &slow_case_);
2816 __ SmiCompare(code_, Smi::FromInt(String::kMaxOneByteCharCode));
2817 __ j(above, &slow_case_);
2819 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
2820 SmiIndex index = masm->SmiToIndex(kScratchRegister, code_, kPointerSizeLog2);
2821 __ movp(result_, FieldOperand(result_, index.reg, index.scale,
2822 FixedArray::kHeaderSize));
2823 __ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
2824 __ j(equal, &slow_case_);
2829 void StringCharFromCodeGenerator::GenerateSlow(
2830 MacroAssembler* masm,
2831 const RuntimeCallHelper& call_helper) {
2832 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
2834 __ bind(&slow_case_);
2835 call_helper.BeforeCall(masm);
2837 __ CallRuntime(Runtime::kCharFromCode, 1);
2838 if (!result_.is(rax)) {
2839 __ movp(result_, rax);
2841 call_helper.AfterCall(masm);
2844 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
2848 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
2852 String::Encoding encoding) {
2853 // Nothing to do for zero characters.
2855 __ testl(count, count);
2856 __ j(zero, &done, Label::kNear);
2858 // Make count the number of bytes to copy.
2859 if (encoding == String::TWO_BYTE_ENCODING) {
2860 STATIC_ASSERT(2 == sizeof(uc16));
2861 __ addl(count, count);
2864 // Copy remaining characters.
2867 __ movb(kScratchRegister, Operand(src, 0));
2868 __ movb(Operand(dest, 0), kScratchRegister);
2872 __ j(not_zero, &loop);
2878 void SubStringStub::Generate(MacroAssembler* masm) {
2881 // Stack frame on entry.
2882 // rsp[0] : return address
2887 enum SubStringStubArgumentIndices {
2888 STRING_ARGUMENT_INDEX,
2889 FROM_ARGUMENT_INDEX,
2891 SUB_STRING_ARGUMENT_COUNT
2894 StackArgumentsAccessor args(rsp, SUB_STRING_ARGUMENT_COUNT,
2895 ARGUMENTS_DONT_CONTAIN_RECEIVER);
2897 // Make sure first argument is a string.
2898 __ movp(rax, args.GetArgumentOperand(STRING_ARGUMENT_INDEX));
2899 STATIC_ASSERT(kSmiTag == 0);
2900 __ testl(rax, Immediate(kSmiTagMask));
2901 __ j(zero, &runtime);
2902 Condition is_string = masm->IsObjectStringType(rax, rbx, rbx);
2903 __ j(NegateCondition(is_string), &runtime);
2906 // rbx: instance type
2907 // Calculate length of sub string using the smi values.
2908 __ movp(rcx, args.GetArgumentOperand(TO_ARGUMENT_INDEX));
2909 __ movp(rdx, args.GetArgumentOperand(FROM_ARGUMENT_INDEX));
2910 __ JumpUnlessBothNonNegativeSmi(rcx, rdx, &runtime);
2912 __ SmiSub(rcx, rcx, rdx); // Overflow doesn't happen.
2913 __ cmpp(rcx, FieldOperand(rax, String::kLengthOffset));
2914 Label not_original_string;
2915 // Shorter than original string's length: an actual substring.
2916 __ j(below, ¬_original_string, Label::kNear);
2917 // Longer than original string's length or negative: unsafe arguments.
2918 __ j(above, &runtime);
2919 // Return original string.
2920 Counters* counters = isolate()->counters();
2921 __ IncrementCounter(counters->sub_string_native(), 1);
2922 __ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
2923 __ bind(¬_original_string);
2926 __ SmiCompare(rcx, Smi::FromInt(1));
2927 __ j(equal, &single_char);
2929 __ SmiToInteger32(rcx, rcx);
2932 // rbx: instance type
2933 // rcx: sub string length
2934 // rdx: from index (smi)
2935 // Deal with different string types: update the index if necessary
2936 // and put the underlying string into edi.
2937 Label underlying_unpacked, sliced_string, seq_or_external_string;
2938 // If the string is not indirect, it can only be sequential or external.
2939 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
2940 STATIC_ASSERT(kIsIndirectStringMask != 0);
2941 __ testb(rbx, Immediate(kIsIndirectStringMask));
2942 __ j(zero, &seq_or_external_string, Label::kNear);
2944 __ testb(rbx, Immediate(kSlicedNotConsMask));
2945 __ j(not_zero, &sliced_string, Label::kNear);
2946 // Cons string. Check whether it is flat, then fetch first part.
2947 // Flat cons strings have an empty second part.
2948 __ CompareRoot(FieldOperand(rax, ConsString::kSecondOffset),
2949 Heap::kempty_stringRootIndex);
2950 __ j(not_equal, &runtime);
2951 __ movp(rdi, FieldOperand(rax, ConsString::kFirstOffset));
2952 // Update instance type.
2953 __ movp(rbx, FieldOperand(rdi, HeapObject::kMapOffset));
2954 __ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset));
2955 __ jmp(&underlying_unpacked, Label::kNear);
2957 __ bind(&sliced_string);
2958 // Sliced string. Fetch parent and correct start index by offset.
2959 __ addp(rdx, FieldOperand(rax, SlicedString::kOffsetOffset));
2960 __ movp(rdi, FieldOperand(rax, SlicedString::kParentOffset));
2961 // Update instance type.
2962 __ movp(rbx, FieldOperand(rdi, HeapObject::kMapOffset));
2963 __ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset));
2964 __ jmp(&underlying_unpacked, Label::kNear);
2966 __ bind(&seq_or_external_string);
2967 // Sequential or external string. Just move string to the correct register.
2970 __ bind(&underlying_unpacked);
2972 if (FLAG_string_slices) {
2974 // rdi: underlying subject string
2975 // rbx: instance type of underlying subject string
2976 // rdx: adjusted start index (smi)
2978 // If coming from the make_two_character_string path, the string
2979 // is too short to be sliced anyways.
2980 __ cmpp(rcx, Immediate(SlicedString::kMinLength));
2981 // Short slice. Copy instead of slicing.
2982 __ j(less, ©_routine);
2983 // Allocate new sliced string. At this point we do not reload the instance
2984 // type including the string encoding because we simply rely on the info
2985 // provided by the original string. It does not matter if the original
2986 // string's encoding is wrong because we always have to recheck encoding of
2987 // the newly created string's parent anyways due to externalized strings.
2988 Label two_byte_slice, set_slice_header;
2989 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
2990 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
2991 __ testb(rbx, Immediate(kStringEncodingMask));
2992 __ j(zero, &two_byte_slice, Label::kNear);
2993 __ AllocateOneByteSlicedString(rax, rbx, r14, &runtime);
2994 __ jmp(&set_slice_header, Label::kNear);
2995 __ bind(&two_byte_slice);
2996 __ AllocateTwoByteSlicedString(rax, rbx, r14, &runtime);
2997 __ bind(&set_slice_header);
2998 __ Integer32ToSmi(rcx, rcx);
2999 __ movp(FieldOperand(rax, SlicedString::kLengthOffset), rcx);
3000 __ movp(FieldOperand(rax, SlicedString::kHashFieldOffset),
3001 Immediate(String::kEmptyHashField));
3002 __ movp(FieldOperand(rax, SlicedString::kParentOffset), rdi);
3003 __ movp(FieldOperand(rax, SlicedString::kOffsetOffset), rdx);
3004 __ IncrementCounter(counters->sub_string_native(), 1);
3005 __ ret(3 * kPointerSize);
3007 __ bind(©_routine);
3010 // rdi: underlying subject string
3011 // rbx: instance type of underlying subject string
3012 // rdx: adjusted start index (smi)
3014 // The subject string can only be external or sequential string of either
3015 // encoding at this point.
3016 Label two_byte_sequential, sequential_string;
3017 STATIC_ASSERT(kExternalStringTag != 0);
3018 STATIC_ASSERT(kSeqStringTag == 0);
3019 __ testb(rbx, Immediate(kExternalStringTag));
3020 __ j(zero, &sequential_string);
3022 // Handle external string.
3023 // Rule out short external strings.
3024 STATIC_ASSERT(kShortExternalStringTag != 0);
3025 __ testb(rbx, Immediate(kShortExternalStringMask));
3026 __ j(not_zero, &runtime);
3027 __ movp(rdi, FieldOperand(rdi, ExternalString::kResourceDataOffset));
3028 // Move the pointer so that offset-wise, it looks like a sequential string.
3029 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3030 __ subp(rdi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3032 __ bind(&sequential_string);
3033 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3034 __ testb(rbx, Immediate(kStringEncodingMask));
3035 __ j(zero, &two_byte_sequential);
3037 // Allocate the result.
3038 __ AllocateOneByteString(rax, rcx, r11, r14, r15, &runtime);
3040 // rax: result string
3041 // rcx: result string length
3042 { // Locate character of sub string start.
3043 SmiIndex smi_as_index = masm->SmiToIndex(rdx, rdx, times_1);
3044 __ leap(r14, Operand(rdi, smi_as_index.reg, smi_as_index.scale,
3045 SeqOneByteString::kHeaderSize - kHeapObjectTag));
3047 // Locate first character of result.
3048 __ leap(rdi, FieldOperand(rax, SeqOneByteString::kHeaderSize));
3050 // rax: result string
3051 // rcx: result length
3052 // r14: first character of result
3053 // rsi: character of sub string start
3054 StringHelper::GenerateCopyCharacters(
3055 masm, rdi, r14, rcx, String::ONE_BYTE_ENCODING);
3056 __ IncrementCounter(counters->sub_string_native(), 1);
3057 __ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
3059 __ bind(&two_byte_sequential);
3060 // Allocate the result.
3061 __ AllocateTwoByteString(rax, rcx, r11, r14, r15, &runtime);
3063 // rax: result string
3064 // rcx: result string length
3065 { // Locate character of sub string start.
3066 SmiIndex smi_as_index = masm->SmiToIndex(rdx, rdx, times_2);
3067 __ leap(r14, Operand(rdi, smi_as_index.reg, smi_as_index.scale,
3068 SeqOneByteString::kHeaderSize - kHeapObjectTag));
3070 // Locate first character of result.
3071 __ leap(rdi, FieldOperand(rax, SeqTwoByteString::kHeaderSize));
3073 // rax: result string
3074 // rcx: result length
3075 // rdi: first character of result
3076 // r14: character of sub string start
3077 StringHelper::GenerateCopyCharacters(
3078 masm, rdi, r14, rcx, String::TWO_BYTE_ENCODING);
3079 __ IncrementCounter(counters->sub_string_native(), 1);
3080 __ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
3082 // Just jump to runtime to create the sub string.
3084 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3086 __ bind(&single_char);
3088 // rbx: instance type
3089 // rcx: sub string length (smi)
3090 // rdx: from index (smi)
3091 StringCharAtGenerator generator(rax, rdx, rcx, rax, &runtime, &runtime,
3092 &runtime, STRING_INDEX_IS_NUMBER,
3093 RECEIVER_IS_STRING);
3094 generator.GenerateFast(masm);
3095 __ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
3096 generator.SkipSlow(masm, &runtime);
3100 void ToNumberStub::Generate(MacroAssembler* masm) {
3101 // The ToNumber stub takes one argument in rax.
3103 __ JumpIfNotSmi(rax, ¬_smi, Label::kNear);
3107 Label not_heap_number;
3108 __ CompareRoot(FieldOperand(rax, HeapObject::kMapOffset),
3109 Heap::kHeapNumberMapRootIndex);
3110 __ j(not_equal, ¬_heap_number, Label::kNear);
3112 __ bind(¬_heap_number);
3114 Label not_string, slow_string;
3115 __ CmpObjectType(rax, FIRST_NONSTRING_TYPE, rdi);
3118 __ j(above_equal, ¬_string, Label::kNear);
3119 // Check if string has a cached array index.
3120 __ testl(FieldOperand(rax, String::kHashFieldOffset),
3121 Immediate(String::kContainsCachedArrayIndexMask));
3122 __ j(not_zero, &slow_string, Label::kNear);
3123 __ movl(rax, FieldOperand(rax, String::kHashFieldOffset));
3124 __ IndexFromHash(rax, rax);
3126 __ bind(&slow_string);
3127 __ PopReturnAddressTo(rcx); // Pop return address.
3128 __ Push(rax); // Push argument.
3129 __ PushReturnAddressFrom(rcx); // Push return address.
3130 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3131 __ bind(¬_string);
3134 __ CmpInstanceType(rdi, ODDBALL_TYPE);
3135 __ j(not_equal, ¬_oddball, Label::kNear);
3136 __ movp(rax, FieldOperand(rax, Oddball::kToNumberOffset));
3138 __ bind(¬_oddball);
3140 __ PopReturnAddressTo(rcx); // Pop return address.
3141 __ Push(rax); // Push argument.
3142 __ PushReturnAddressFrom(rcx); // Push return address.
3143 __ TailCallRuntime(Runtime::kToNumber, 1, 1);
3147 void ToStringStub::Generate(MacroAssembler* masm) {
3148 // The ToString stub takes one argument in rax.
3150 __ JumpIfSmi(rax, &is_number, Label::kNear);
3153 __ CmpObjectType(rax, FIRST_NONSTRING_TYPE, rdi);
3155 // rdi: receiver map
3156 __ j(above_equal, ¬_string, Label::kNear);
3158 __ bind(¬_string);
3160 Label not_heap_number;
3161 __ CompareRoot(rax, Heap::kHeapNumberMapRootIndex);
3162 __ j(not_equal, ¬_heap_number, Label::kNear);
3163 __ bind(&is_number);
3164 NumberToStringStub stub(isolate());
3165 __ TailCallStub(&stub);
3166 __ bind(¬_heap_number);
3169 __ CmpInstanceType(rdi, ODDBALL_TYPE);
3170 __ j(not_equal, ¬_oddball, Label::kNear);
3171 __ movp(rax, FieldOperand(rax, Oddball::kToStringOffset));
3173 __ bind(¬_oddball);
3175 __ PopReturnAddressTo(rcx); // Pop return address.
3176 __ Push(rax); // Push argument.
3177 __ PushReturnAddressFrom(rcx); // Push return address.
3178 __ TailCallRuntime(Runtime::kToString, 1, 1);
3182 void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
3186 Register scratch2) {
3187 Register length = scratch1;
3190 Label check_zero_length;
3191 __ movp(length, FieldOperand(left, String::kLengthOffset));
3192 __ SmiCompare(length, FieldOperand(right, String::kLengthOffset));
3193 __ j(equal, &check_zero_length, Label::kNear);
3194 __ Move(rax, Smi::FromInt(NOT_EQUAL));
3197 // Check if the length is zero.
3198 Label compare_chars;
3199 __ bind(&check_zero_length);
3200 STATIC_ASSERT(kSmiTag == 0);
3202 __ j(not_zero, &compare_chars, Label::kNear);
3203 __ Move(rax, Smi::FromInt(EQUAL));
3206 // Compare characters.
3207 __ bind(&compare_chars);
3208 Label strings_not_equal;
3209 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2,
3210 &strings_not_equal, Label::kNear);
3212 // Characters are equal.
3213 __ Move(rax, Smi::FromInt(EQUAL));
3216 // Characters are not equal.
3217 __ bind(&strings_not_equal);
3218 __ Move(rax, Smi::FromInt(NOT_EQUAL));
3223 void StringHelper::GenerateCompareFlatOneByteStrings(
3224 MacroAssembler* masm, Register left, Register right, Register scratch1,
3225 Register scratch2, Register scratch3, Register scratch4) {
3226 // Ensure that you can always subtract a string length from a non-negative
3227 // number (e.g. another length).
3228 STATIC_ASSERT(String::kMaxLength < 0x7fffffff);
3230 // Find minimum length and length difference.
3231 __ movp(scratch1, FieldOperand(left, String::kLengthOffset));
3232 __ movp(scratch4, scratch1);
3235 FieldOperand(right, String::kLengthOffset));
3236 // Register scratch4 now holds left.length - right.length.
3237 const Register length_difference = scratch4;
3239 __ j(less, &left_shorter, Label::kNear);
3240 // The right string isn't longer that the left one.
3241 // Get the right string's length by subtracting the (non-negative) difference
3242 // from the left string's length.
3243 __ SmiSub(scratch1, scratch1, length_difference);
3244 __ bind(&left_shorter);
3245 // Register scratch1 now holds Min(left.length, right.length).
3246 const Register min_length = scratch1;
3248 Label compare_lengths;
3249 // If min-length is zero, go directly to comparing lengths.
3250 __ SmiTest(min_length);
3251 __ j(zero, &compare_lengths, Label::kNear);
3254 Label result_not_equal;
3255 GenerateOneByteCharsCompareLoop(
3256 masm, left, right, min_length, scratch2, &result_not_equal,
3257 // In debug-code mode, SmiTest below might push
3258 // the target label outside the near range.
3261 // Completed loop without finding different characters.
3262 // Compare lengths (precomputed).
3263 __ bind(&compare_lengths);
3264 __ SmiTest(length_difference);
3265 Label length_not_equal;
3266 __ j(not_zero, &length_not_equal, Label::kNear);
3269 __ Move(rax, Smi::FromInt(EQUAL));
3272 Label result_greater;
3274 __ bind(&length_not_equal);
3275 __ j(greater, &result_greater, Label::kNear);
3276 __ jmp(&result_less, Label::kNear);
3277 __ bind(&result_not_equal);
3278 // Unequal comparison of left to right, either character or length.
3279 __ j(above, &result_greater, Label::kNear);
3280 __ bind(&result_less);
3283 __ Move(rax, Smi::FromInt(LESS));
3286 // Result is GREATER.
3287 __ bind(&result_greater);
3288 __ Move(rax, Smi::FromInt(GREATER));
3293 void StringHelper::GenerateOneByteCharsCompareLoop(
3294 MacroAssembler* masm, Register left, Register right, Register length,
3295 Register scratch, Label* chars_not_equal, Label::Distance near_jump) {
3296 // Change index to run from -length to -1 by adding length to string
3297 // start. This means that loop ends when index reaches zero, which
3298 // doesn't need an additional compare.
3299 __ SmiToInteger32(length, length);
3301 FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize));
3303 FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize));
3305 Register index = length; // index = -length;
3310 __ movb(scratch, Operand(left, index, times_1, 0));
3311 __ cmpb(scratch, Operand(right, index, times_1, 0));
3312 __ j(not_equal, chars_not_equal, near_jump);
3314 __ j(not_zero, &loop);
3318 void StringCompareStub::Generate(MacroAssembler* masm) {
3319 // ----------- S t a t e -------------
3320 // -- rdx : left string
3321 // -- rax : right string
3322 // -- rsp[0] : return address
3323 // -----------------------------------
3324 __ AssertString(rdx);
3325 __ AssertString(rax);
3327 // Check for identity.
3330 __ j(not_equal, ¬_same, Label::kNear);
3331 __ Move(rax, Smi::FromInt(EQUAL));
3332 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1);
3337 // Check that both are sequential one-byte strings.
3339 __ JumpIfNotBothSequentialOneByteStrings(rdx, rax, rcx, rbx, &runtime);
3341 // Inline comparison of one-byte strings.
3342 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1);
3343 StringHelper::GenerateCompareFlatOneByteStrings(masm, rdx, rax, rcx, rbx, rdi,
3346 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
3347 // tagged as a small integer.
3349 __ PopReturnAddressTo(rcx);
3352 __ PushReturnAddressFrom(rcx);
3353 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3357 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3358 // ----------- S t a t e -------------
3361 // -- rsp[0] : return address
3362 // -----------------------------------
3364 // Load rcx with the allocation site. We stick an undefined dummy value here
3365 // and replace it with the real allocation site later when we instantiate this
3366 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3367 __ Move(rcx, handle(isolate()->heap()->undefined_value()));
3369 // Make sure that we actually patched the allocation site.
3370 if (FLAG_debug_code) {
3371 __ testb(rcx, Immediate(kSmiTagMask));
3372 __ Assert(not_equal, kExpectedAllocationSite);
3373 __ Cmp(FieldOperand(rcx, HeapObject::kMapOffset),
3374 isolate()->factory()->allocation_site_map());
3375 __ Assert(equal, kExpectedAllocationSite);
3378 // Tail call into the stub that handles binary operations with allocation
3380 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3381 __ TailCallStub(&stub);
3385 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3386 DCHECK(state() == CompareICState::SMI);
3388 __ JumpIfNotBothSmi(rdx, rax, &miss, Label::kNear);
3390 if (GetCondition() == equal) {
3391 // For equality we do not care about the sign of the result.
3396 __ j(no_overflow, &done, Label::kNear);
3397 // Correct sign of result in case of overflow.
3409 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3410 DCHECK(state() == CompareICState::NUMBER);
3413 Label unordered, maybe_undefined1, maybe_undefined2;
3416 if (left() == CompareICState::SMI) {
3417 __ JumpIfNotSmi(rdx, &miss);
3419 if (right() == CompareICState::SMI) {
3420 __ JumpIfNotSmi(rax, &miss);
3423 // Load left and right operand.
3424 Label done, left, left_smi, right_smi;
3425 __ JumpIfSmi(rax, &right_smi, Label::kNear);
3426 __ CompareMap(rax, isolate()->factory()->heap_number_map());
3427 __ j(not_equal, &maybe_undefined1, Label::kNear);
3428 __ movsd(xmm1, FieldOperand(rax, HeapNumber::kValueOffset));
3429 __ jmp(&left, Label::kNear);
3430 __ bind(&right_smi);
3431 __ SmiToInteger32(rcx, rax); // Can't clobber rax yet.
3432 __ Cvtlsi2sd(xmm1, rcx);
3435 __ JumpIfSmi(rdx, &left_smi, Label::kNear);
3436 __ CompareMap(rdx, isolate()->factory()->heap_number_map());
3437 __ j(not_equal, &maybe_undefined2, Label::kNear);
3438 __ movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset));
3441 __ SmiToInteger32(rcx, rdx); // Can't clobber rdx yet.
3442 __ Cvtlsi2sd(xmm0, rcx);
3446 __ ucomisd(xmm0, xmm1);
3448 // Don't base result on EFLAGS when a NaN is involved.
3449 __ j(parity_even, &unordered, Label::kNear);
3451 // Return a result of -1, 0, or 1, based on EFLAGS.
3452 // Performing mov, because xor would destroy the flag register.
3453 __ movl(rax, Immediate(0));
3454 __ movl(rcx, Immediate(0));
3455 __ setcc(above, rax); // Add one to zero if carry clear and not equal.
3456 __ sbbp(rax, rcx); // Subtract one if below (aka. carry set).
3459 __ bind(&unordered);
3460 __ bind(&generic_stub);
3461 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3462 CompareICState::GENERIC, CompareICState::GENERIC);
3463 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET);
3465 __ bind(&maybe_undefined1);
3466 if (Token::IsOrderedRelationalCompareOp(op())) {
3467 __ Cmp(rax, isolate()->factory()->undefined_value());
3468 __ j(not_equal, &miss);
3469 __ JumpIfSmi(rdx, &unordered);
3470 __ CmpObjectType(rdx, HEAP_NUMBER_TYPE, rcx);
3471 __ j(not_equal, &maybe_undefined2, Label::kNear);
3475 __ bind(&maybe_undefined2);
3476 if (Token::IsOrderedRelationalCompareOp(op())) {
3477 __ Cmp(rdx, isolate()->factory()->undefined_value());
3478 __ j(equal, &unordered);
3486 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3487 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3488 DCHECK(GetCondition() == equal);
3490 // Registers containing left and right operands respectively.
3491 Register left = rdx;
3492 Register right = rax;
3493 Register tmp1 = rcx;
3494 Register tmp2 = rbx;
3496 // Check that both operands are heap objects.
3498 Condition cond = masm->CheckEitherSmi(left, right, tmp1);
3499 __ j(cond, &miss, Label::kNear);
3501 // Check that both operands are internalized strings.
3502 __ movp(tmp1, FieldOperand(left, HeapObject::kMapOffset));
3503 __ movp(tmp2, FieldOperand(right, HeapObject::kMapOffset));
3504 __ movzxbp(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
3505 __ movzxbp(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
3506 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3508 __ testb(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask));
3509 __ j(not_zero, &miss, Label::kNear);
3511 // Internalized strings are compared by identity.
3513 __ cmpp(left, right);
3514 // Make sure rax is non-zero. At this point input operands are
3515 // guaranteed to be non-zero.
3516 DCHECK(right.is(rax));
3517 __ j(not_equal, &done, Label::kNear);
3518 STATIC_ASSERT(EQUAL == 0);
3519 STATIC_ASSERT(kSmiTag == 0);
3520 __ Move(rax, Smi::FromInt(EQUAL));
3529 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3530 DCHECK(state() == CompareICState::UNIQUE_NAME);
3531 DCHECK(GetCondition() == equal);
3533 // Registers containing left and right operands respectively.
3534 Register left = rdx;
3535 Register right = rax;
3536 Register tmp1 = rcx;
3537 Register tmp2 = rbx;
3539 // Check that both operands are heap objects.
3541 Condition cond = masm->CheckEitherSmi(left, right, tmp1);
3542 __ j(cond, &miss, Label::kNear);
3544 // Check that both operands are unique names. This leaves the instance
3545 // types loaded in tmp1 and tmp2.
3546 __ movp(tmp1, FieldOperand(left, HeapObject::kMapOffset));
3547 __ movp(tmp2, FieldOperand(right, HeapObject::kMapOffset));
3548 __ movzxbp(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
3549 __ movzxbp(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
3551 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss, Label::kNear);
3552 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss, Label::kNear);
3554 // Unique names are compared by identity.
3556 __ cmpp(left, right);
3557 // Make sure rax is non-zero. At this point input operands are
3558 // guaranteed to be non-zero.
3559 DCHECK(right.is(rax));
3560 __ j(not_equal, &done, Label::kNear);
3561 STATIC_ASSERT(EQUAL == 0);
3562 STATIC_ASSERT(kSmiTag == 0);
3563 __ Move(rax, Smi::FromInt(EQUAL));
3572 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3573 DCHECK(state() == CompareICState::STRING);
3576 bool equality = Token::IsEqualityOp(op());
3578 // Registers containing left and right operands respectively.
3579 Register left = rdx;
3580 Register right = rax;
3581 Register tmp1 = rcx;
3582 Register tmp2 = rbx;
3583 Register tmp3 = rdi;
3585 // Check that both operands are heap objects.
3586 Condition cond = masm->CheckEitherSmi(left, right, tmp1);
3589 // Check that both operands are strings. This leaves the instance
3590 // types loaded in tmp1 and tmp2.
3591 __ movp(tmp1, FieldOperand(left, HeapObject::kMapOffset));
3592 __ movp(tmp2, FieldOperand(right, HeapObject::kMapOffset));
3593 __ movzxbp(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
3594 __ movzxbp(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
3595 __ movp(tmp3, tmp1);
3596 STATIC_ASSERT(kNotStringTag != 0);
3598 __ testb(tmp3, Immediate(kIsNotStringMask));
3599 __ j(not_zero, &miss);
3601 // Fast check for identical strings.
3603 __ cmpp(left, right);
3604 __ j(not_equal, ¬_same, Label::kNear);
3605 STATIC_ASSERT(EQUAL == 0);
3606 STATIC_ASSERT(kSmiTag == 0);
3607 __ Move(rax, Smi::FromInt(EQUAL));
3610 // Handle not identical strings.
3613 // Check that both strings are internalized strings. If they are, we're done
3614 // because we already know they are not identical. We also know they are both
3618 STATIC_ASSERT(kInternalizedTag == 0);
3620 __ testb(tmp1, Immediate(kIsNotInternalizedMask));
3621 __ j(not_zero, &do_compare, Label::kNear);
3622 // Make sure rax is non-zero. At this point input operands are
3623 // guaranteed to be non-zero.
3624 DCHECK(right.is(rax));
3626 __ bind(&do_compare);
3629 // Check that both strings are sequential one-byte.
3631 __ JumpIfNotBothSequentialOneByteStrings(left, right, tmp1, tmp2, &runtime);
3633 // Compare flat one-byte strings. Returns when done.
3635 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1,
3638 StringHelper::GenerateCompareFlatOneByteStrings(
3639 masm, left, right, tmp1, tmp2, tmp3, kScratchRegister);
3642 // Handle more complex cases in runtime.
3644 __ PopReturnAddressTo(tmp1);
3647 __ PushReturnAddressFrom(tmp1);
3649 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3651 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3659 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3660 DCHECK(state() == CompareICState::OBJECT);
3662 Condition either_smi = masm->CheckEitherSmi(rdx, rax);
3663 __ j(either_smi, &miss, Label::kNear);
3665 __ CmpObjectType(rax, JS_OBJECT_TYPE, rcx);
3666 __ j(not_equal, &miss, Label::kNear);
3667 __ CmpObjectType(rdx, JS_OBJECT_TYPE, rcx);
3668 __ j(not_equal, &miss, Label::kNear);
3670 DCHECK(GetCondition() == equal);
3679 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3681 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3682 Condition either_smi = masm->CheckEitherSmi(rdx, rax);
3683 __ j(either_smi, &miss, Label::kNear);
3685 __ GetWeakValue(rdi, cell);
3686 __ cmpp(FieldOperand(rdx, HeapObject::kMapOffset), rdi);
3687 __ j(not_equal, &miss, Label::kNear);
3688 __ cmpp(FieldOperand(rax, HeapObject::kMapOffset), rdi);
3689 __ j(not_equal, &miss, Label::kNear);
3691 if (Token::IsEqualityOp(op())) {
3694 } else if (is_strong(strength())) {
3695 __ TailCallRuntime(Runtime::kThrowStrongModeImplicitConversion, 0, 1);
3697 __ PopReturnAddressTo(rcx);
3700 __ Push(Smi::FromInt(NegativeComparisonResult(GetCondition())));
3701 __ PushReturnAddressFrom(rcx);
3702 __ TailCallRuntime(Runtime::kCompare, 3, 1);
3710 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3712 // Call the runtime system in a fresh internal frame.
3713 FrameScope scope(masm, StackFrame::INTERNAL);
3718 __ Push(Smi::FromInt(op()));
3719 __ CallRuntime(Runtime::kCompareIC_Miss, 3);
3721 // Compute the entry point of the rewritten stub.
3722 __ leap(rdi, FieldOperand(rax, Code::kHeaderSize));
3727 // Do a tail call to the rewritten stub.
3732 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3735 Register properties,
3738 DCHECK(name->IsUniqueName());
3739 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3740 // not equal to the name and kProbes-th slot is not used (its name is the
3741 // undefined value), it guarantees the hash table doesn't contain the
3742 // property. It's true even if some slots represent deleted properties
3743 // (their names are the hole value).
3744 for (int i = 0; i < kInlinedProbes; i++) {
3745 // r0 points to properties hash.
3746 // Compute the masked index: (hash + i + i * i) & mask.
3747 Register index = r0;
3748 // Capacity is smi 2^n.
3749 __ SmiToInteger32(index, FieldOperand(properties, kCapacityOffset));
3752 Immediate(name->Hash() + NameDictionary::GetProbeOffset(i)));
3754 // Scale the index by multiplying by the entry size.
3755 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3756 __ leap(index, Operand(index, index, times_2, 0)); // index *= 3.
3758 Register entity_name = r0;
3759 // Having undefined at this place means the name is not contained.
3760 STATIC_ASSERT(kSmiTagSize == 1);
3761 __ movp(entity_name, Operand(properties,
3764 kElementsStartOffset - kHeapObjectTag));
3765 __ Cmp(entity_name, masm->isolate()->factory()->undefined_value());
3768 // Stop if found the property.
3769 __ Cmp(entity_name, Handle<Name>(name));
3773 // Check for the hole and skip.
3774 __ CompareRoot(entity_name, Heap::kTheHoleValueRootIndex);
3775 __ j(equal, &good, Label::kNear);
3777 // Check if the entry name is not a unique name.
3778 __ movp(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset));
3779 __ JumpIfNotUniqueNameInstanceType(
3780 FieldOperand(entity_name, Map::kInstanceTypeOffset), miss);
3784 NameDictionaryLookupStub stub(masm->isolate(), properties, r0, r0,
3786 __ Push(Handle<Object>(name));
3787 __ Push(Immediate(name->Hash()));
3790 __ j(not_zero, miss);
3795 // Probe the name dictionary in the |elements| register. Jump to the
3796 // |done| label if a property with the given name is found leaving the
3797 // index into the dictionary in |r1|. Jump to the |miss| label
3799 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3806 DCHECK(!elements.is(r0));
3807 DCHECK(!elements.is(r1));
3808 DCHECK(!name.is(r0));
3809 DCHECK(!name.is(r1));
3811 __ AssertName(name);
3813 __ SmiToInteger32(r0, FieldOperand(elements, kCapacityOffset));
3816 for (int i = 0; i < kInlinedProbes; i++) {
3817 // Compute the masked index: (hash + i + i * i) & mask.
3818 __ movl(r1, FieldOperand(name, Name::kHashFieldOffset));
3819 __ shrl(r1, Immediate(Name::kHashShift));
3821 __ addl(r1, Immediate(NameDictionary::GetProbeOffset(i)));
3825 // Scale the index by multiplying by the entry size.
3826 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3827 __ leap(r1, Operand(r1, r1, times_2, 0)); // r1 = r1 * 3
3829 // Check if the key is identical to the name.
3830 __ cmpp(name, Operand(elements, r1, times_pointer_size,
3831 kElementsStartOffset - kHeapObjectTag));
3835 NameDictionaryLookupStub stub(masm->isolate(), elements, r0, r1,
3838 __ movl(r0, FieldOperand(name, Name::kHashFieldOffset));
3839 __ shrl(r0, Immediate(Name::kHashShift));
3849 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
3850 // This stub overrides SometimesSetsUpAFrame() to return false. That means
3851 // we cannot call anything that could cause a GC from this stub.
3852 // Stack frame on entry:
3853 // rsp[0 * kPointerSize] : return address.
3854 // rsp[1 * kPointerSize] : key's hash.
3855 // rsp[2 * kPointerSize] : key.
3857 // dictionary_: NameDictionary to probe.
3858 // result_: used as scratch.
3859 // index_: will hold an index of entry if lookup is successful.
3860 // might alias with result_.
3862 // result_ is zero if lookup failed, non zero otherwise.
3864 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
3866 Register scratch = result();
3868 __ SmiToInteger32(scratch, FieldOperand(dictionary(), kCapacityOffset));
3872 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3873 // not equal to the name and kProbes-th slot is not used (its name is the
3874 // undefined value), it guarantees the hash table doesn't contain the
3875 // property. It's true even if some slots represent deleted properties
3876 // (their names are the null value).
3877 StackArgumentsAccessor args(rsp, 2, ARGUMENTS_DONT_CONTAIN_RECEIVER,
3879 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
3880 // Compute the masked index: (hash + i + i * i) & mask.
3881 __ movp(scratch, args.GetArgumentOperand(1));
3883 __ addl(scratch, Immediate(NameDictionary::GetProbeOffset(i)));
3885 __ andp(scratch, Operand(rsp, 0));
3887 // Scale the index by multiplying by the entry size.
3888 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3889 __ leap(index(), Operand(scratch, scratch, times_2, 0)); // index *= 3.
3891 // Having undefined at this place means the name is not contained.
3892 __ movp(scratch, Operand(dictionary(), index(), times_pointer_size,
3893 kElementsStartOffset - kHeapObjectTag));
3895 __ Cmp(scratch, isolate()->factory()->undefined_value());
3896 __ j(equal, ¬_in_dictionary);
3898 // Stop if found the property.
3899 __ cmpp(scratch, args.GetArgumentOperand(0));
3900 __ j(equal, &in_dictionary);
3902 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
3903 // If we hit a key that is not a unique name during negative
3904 // lookup we have to bailout as this key might be equal to the
3905 // key we are looking for.
3907 // Check if the entry name is not a unique name.
3908 __ movp(scratch, FieldOperand(scratch, HeapObject::kMapOffset));
3909 __ JumpIfNotUniqueNameInstanceType(
3910 FieldOperand(scratch, Map::kInstanceTypeOffset),
3911 &maybe_in_dictionary);
3915 __ bind(&maybe_in_dictionary);
3916 // If we are doing negative lookup then probing failure should be
3917 // treated as a lookup success. For positive lookup probing failure
3918 // should be treated as lookup failure.
3919 if (mode() == POSITIVE_LOOKUP) {
3920 __ movp(scratch, Immediate(0));
3922 __ ret(2 * kPointerSize);
3925 __ bind(&in_dictionary);
3926 __ movp(scratch, Immediate(1));
3928 __ ret(2 * kPointerSize);
3930 __ bind(¬_in_dictionary);
3931 __ movp(scratch, Immediate(0));
3933 __ ret(2 * kPointerSize);
3937 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
3939 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
3941 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
3946 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
3947 // the value has just been written into the object, now this stub makes sure
3948 // we keep the GC informed. The word in the object where the value has been
3949 // written is in the address register.
3950 void RecordWriteStub::Generate(MacroAssembler* masm) {
3951 Label skip_to_incremental_noncompacting;
3952 Label skip_to_incremental_compacting;
3954 // The first two instructions are generated with labels so as to get the
3955 // offset fixed up correctly by the bind(Label*) call. We patch it back and
3956 // forth between a compare instructions (a nop in this position) and the
3957 // real branch when we start and stop incremental heap marking.
3958 // See RecordWriteStub::Patch for details.
3959 __ jmp(&skip_to_incremental_noncompacting, Label::kNear);
3960 __ jmp(&skip_to_incremental_compacting, Label::kFar);
3962 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3963 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
3964 MacroAssembler::kReturnAtEnd);
3969 __ bind(&skip_to_incremental_noncompacting);
3970 GenerateIncremental(masm, INCREMENTAL);
3972 __ bind(&skip_to_incremental_compacting);
3973 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
3975 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
3976 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
3977 masm->set_byte_at(0, kTwoByteNopInstruction);
3978 masm->set_byte_at(2, kFiveByteNopInstruction);
3982 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
3985 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3986 Label dont_need_remembered_set;
3988 __ movp(regs_.scratch0(), Operand(regs_.address(), 0));
3989 __ JumpIfNotInNewSpace(regs_.scratch0(),
3991 &dont_need_remembered_set);
3993 __ CheckPageFlag(regs_.object(),
3995 1 << MemoryChunk::SCAN_ON_SCAVENGE,
3997 &dont_need_remembered_set);
3999 // First notify the incremental marker if necessary, then update the
4001 CheckNeedsToInformIncrementalMarker(
4002 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4003 InformIncrementalMarker(masm);
4004 regs_.Restore(masm);
4005 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4006 MacroAssembler::kReturnAtEnd);
4008 __ bind(&dont_need_remembered_set);
4011 CheckNeedsToInformIncrementalMarker(
4012 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4013 InformIncrementalMarker(masm);
4014 regs_.Restore(masm);
4019 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4020 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4022 arg_reg_1.is(regs_.address()) ? kScratchRegister : regs_.address();
4023 DCHECK(!address.is(regs_.object()));
4024 DCHECK(!address.is(arg_reg_1));
4025 __ Move(address, regs_.address());
4026 __ Move(arg_reg_1, regs_.object());
4027 // TODO(gc) Can we just set address arg2 in the beginning?
4028 __ Move(arg_reg_2, address);
4029 __ LoadAddress(arg_reg_3,
4030 ExternalReference::isolate_address(isolate()));
4031 int argument_count = 3;
4033 AllowExternalCallThatCantCauseGC scope(masm);
4034 __ PrepareCallCFunction(argument_count);
4036 ExternalReference::incremental_marking_record_write_function(isolate()),
4038 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4042 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4043 MacroAssembler* masm,
4044 OnNoNeedToInformIncrementalMarker on_no_need,
4047 Label need_incremental;
4048 Label need_incremental_pop_object;
4050 __ movp(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask));
4051 __ andp(regs_.scratch0(), regs_.object());
4052 __ movp(regs_.scratch1(),
4053 Operand(regs_.scratch0(),
4054 MemoryChunk::kWriteBarrierCounterOffset));
4055 __ subp(regs_.scratch1(), Immediate(1));
4056 __ movp(Operand(regs_.scratch0(),
4057 MemoryChunk::kWriteBarrierCounterOffset),
4059 __ j(negative, &need_incremental);
4061 // Let's look at the color of the object: If it is not black we don't have
4062 // to inform the incremental marker.
4063 __ JumpIfBlack(regs_.object(),
4069 regs_.Restore(masm);
4070 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4071 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4072 MacroAssembler::kReturnAtEnd);
4079 // Get the value from the slot.
4080 __ movp(regs_.scratch0(), Operand(regs_.address(), 0));
4082 if (mode == INCREMENTAL_COMPACTION) {
4083 Label ensure_not_white;
4085 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4086 regs_.scratch1(), // Scratch.
4087 MemoryChunk::kEvacuationCandidateMask,
4092 __ CheckPageFlag(regs_.object(),
4093 regs_.scratch1(), // Scratch.
4094 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4098 __ bind(&ensure_not_white);
4101 // We need an extra register for this, so we push the object register
4103 __ Push(regs_.object());
4104 __ EnsureNotWhite(regs_.scratch0(), // The value.
4105 regs_.scratch1(), // Scratch.
4106 regs_.object(), // Scratch.
4107 &need_incremental_pop_object,
4109 __ Pop(regs_.object());
4111 regs_.Restore(masm);
4112 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4113 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4114 MacroAssembler::kReturnAtEnd);
4119 __ bind(&need_incremental_pop_object);
4120 __ Pop(regs_.object());
4122 __ bind(&need_incremental);
4124 // Fall through when we need to inform the incremental marker.
4128 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4129 // ----------- S t a t e -------------
4130 // -- rax : element value to store
4131 // -- rcx : element index as smi
4132 // -- rsp[0] : return address
4133 // -- rsp[8] : array literal index in function
4134 // -- rsp[16] : array literal
4135 // clobbers rbx, rdx, rdi
4136 // -----------------------------------
4139 Label double_elements;
4141 Label slow_elements;
4142 Label fast_elements;
4144 // Get array literal index, array literal and its map.
4145 StackArgumentsAccessor args(rsp, 2, ARGUMENTS_DONT_CONTAIN_RECEIVER);
4146 __ movp(rdx, args.GetArgumentOperand(1));
4147 __ movp(rbx, args.GetArgumentOperand(0));
4148 __ movp(rdi, FieldOperand(rbx, JSObject::kMapOffset));
4150 __ CheckFastElements(rdi, &double_elements);
4152 // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS
4153 __ JumpIfSmi(rax, &smi_element);
4154 __ CheckFastSmiElements(rdi, &fast_elements);
4156 // Store into the array literal requires a elements transition. Call into
4159 __ bind(&slow_elements);
4160 __ PopReturnAddressTo(rdi);
4164 __ movp(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
4165 __ Push(FieldOperand(rbx, JSFunction::kLiteralsOffset));
4167 __ PushReturnAddressFrom(rdi);
4168 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4170 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4171 __ bind(&fast_elements);
4172 __ SmiToInteger32(kScratchRegister, rcx);
4173 __ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset));
4174 __ leap(rcx, FieldOperand(rbx, kScratchRegister, times_pointer_size,
4175 FixedArrayBase::kHeaderSize));
4176 __ movp(Operand(rcx, 0), rax);
4177 // Update the write barrier for the array store.
4178 __ RecordWrite(rbx, rcx, rax,
4180 EMIT_REMEMBERED_SET,
4184 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or
4185 // FAST_*_ELEMENTS, and value is Smi.
4186 __ bind(&smi_element);
4187 __ SmiToInteger32(kScratchRegister, rcx);
4188 __ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset));
4189 __ movp(FieldOperand(rbx, kScratchRegister, times_pointer_size,
4190 FixedArrayBase::kHeaderSize), rax);
4193 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
4194 __ bind(&double_elements);
4196 __ movp(r9, FieldOperand(rbx, JSObject::kElementsOffset));
4197 __ SmiToInteger32(r11, rcx);
4198 __ StoreNumberToDoubleElements(rax,
4207 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4208 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4209 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4210 int parameter_count_offset =
4211 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4212 __ movp(rbx, MemOperand(rbp, parameter_count_offset));
4213 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4214 __ PopReturnAddressTo(rcx);
4215 int additional_offset =
4216 function_mode() == JS_FUNCTION_STUB_MODE ? kPointerSize : 0;
4217 __ leap(rsp, MemOperand(rsp, rbx, times_pointer_size, additional_offset));
4218 __ jmp(rcx); // Return to IC Miss stub, continuation still on stack.
4222 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4223 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4224 LoadICStub stub(isolate(), state());
4225 stub.GenerateForTrampoline(masm);
4229 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4230 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4231 KeyedLoadICStub stub(isolate(), state());
4232 stub.GenerateForTrampoline(masm);
4236 static void HandleArrayCases(MacroAssembler* masm, Register feedback,
4237 Register receiver_map, Register scratch1,
4238 Register scratch2, Register scratch3,
4239 bool is_polymorphic, Label* miss) {
4240 // feedback initially contains the feedback array
4241 Label next_loop, prepare_next;
4242 Label start_polymorphic;
4244 Register counter = scratch1;
4245 Register length = scratch2;
4246 Register cached_map = scratch3;
4248 __ movp(cached_map, FieldOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4249 __ cmpp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4250 __ j(not_equal, &start_polymorphic);
4252 // found, now call handler.
4253 Register handler = feedback;
4254 __ movp(handler, FieldOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4255 __ leap(handler, FieldOperand(handler, Code::kHeaderSize));
4258 // Polymorphic, we have to loop from 2 to N
4259 __ bind(&start_polymorphic);
4260 __ SmiToInteger32(length, FieldOperand(feedback, FixedArray::kLengthOffset));
4261 if (!is_polymorphic) {
4262 // If the IC could be monomorphic we have to make sure we don't go past the
4263 // end of the feedback array.
4264 __ cmpl(length, Immediate(2));
4267 __ movl(counter, Immediate(2));
4269 __ bind(&next_loop);
4270 __ movp(cached_map, FieldOperand(feedback, counter, times_pointer_size,
4271 FixedArray::kHeaderSize));
4272 __ cmpp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4273 __ j(not_equal, &prepare_next);
4274 __ movp(handler, FieldOperand(feedback, counter, times_pointer_size,
4275 FixedArray::kHeaderSize + kPointerSize));
4276 __ leap(handler, FieldOperand(handler, Code::kHeaderSize));
4279 __ bind(&prepare_next);
4280 __ addl(counter, Immediate(2));
4281 __ cmpl(counter, length);
4282 __ j(less, &next_loop);
4284 // We exhausted our array of map handler pairs.
4289 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4290 Register receiver_map, Register feedback,
4291 Register vector, Register integer_slot,
4292 Label* compare_map, Label* load_smi_map,
4294 __ JumpIfSmi(receiver, load_smi_map);
4295 __ movp(receiver_map, FieldOperand(receiver, 0));
4297 __ bind(compare_map);
4298 __ cmpp(receiver_map, FieldOperand(feedback, WeakCell::kValueOffset));
4299 __ j(not_equal, try_array);
4300 Register handler = feedback;
4301 __ movp(handler, FieldOperand(vector, integer_slot, times_pointer_size,
4302 FixedArray::kHeaderSize + kPointerSize));
4303 __ leap(handler, FieldOperand(handler, Code::kHeaderSize));
4308 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4311 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4312 GenerateImpl(masm, true);
4316 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4317 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // rdx
4318 Register name = LoadWithVectorDescriptor::NameRegister(); // rcx
4319 Register vector = LoadWithVectorDescriptor::VectorRegister(); // rbx
4320 Register slot = LoadWithVectorDescriptor::SlotRegister(); // rax
4321 Register feedback = rdi;
4322 Register integer_slot = r8;
4323 Register receiver_map = r9;
4325 __ SmiToInteger32(integer_slot, slot);
4326 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4327 FixedArray::kHeaderSize));
4329 // Try to quickly handle the monomorphic case without knowing for sure
4330 // if we have a weak cell in feedback. We do know it's safe to look
4331 // at WeakCell::kValueOffset.
4332 Label try_array, load_smi_map, compare_map;
4333 Label not_array, miss;
4334 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector,
4335 integer_slot, &compare_map, &load_smi_map, &try_array);
4337 // Is it a fixed array?
4338 __ bind(&try_array);
4339 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex);
4340 __ j(not_equal, ¬_array);
4341 HandleArrayCases(masm, feedback, receiver_map, integer_slot, r11, r15, true,
4344 __ bind(¬_array);
4345 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4346 __ j(not_equal, &miss);
4347 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4348 Code::ComputeHandlerFlags(Code::LOAD_IC));
4349 masm->isolate()->stub_cache()->GenerateProbe(
4350 masm, Code::LOAD_IC, code_flags, receiver, name, feedback, no_reg);
4353 LoadIC::GenerateMiss(masm, LoadIC::kStressDispatcher);
4355 __ bind(&load_smi_map);
4356 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4357 __ jmp(&compare_map);
4361 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4362 GenerateImpl(masm, false);
4366 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4367 GenerateImpl(masm, true);
4371 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4372 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // rdx
4373 Register key = LoadWithVectorDescriptor::NameRegister(); // rcx
4374 Register vector = LoadWithVectorDescriptor::VectorRegister(); // rbx
4375 Register slot = LoadWithVectorDescriptor::SlotRegister(); // rax
4376 Register feedback = rdi;
4377 Register integer_slot = r8;
4378 Register receiver_map = r9;
4380 __ SmiToInteger32(integer_slot, slot);
4381 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4382 FixedArray::kHeaderSize));
4384 // Try to quickly handle the monomorphic case without knowing for sure
4385 // if we have a weak cell in feedback. We do know it's safe to look
4386 // at WeakCell::kValueOffset.
4387 Label try_array, load_smi_map, compare_map;
4388 Label not_array, miss;
4389 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector,
4390 integer_slot, &compare_map, &load_smi_map, &try_array);
4392 __ bind(&try_array);
4393 // Is it a fixed array?
4394 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex);
4395 __ j(not_equal, ¬_array);
4397 // We have a polymorphic element handler.
4398 Label polymorphic, try_poly_name;
4399 __ bind(&polymorphic);
4400 HandleArrayCases(masm, feedback, receiver_map, integer_slot, r11, r15, true,
4403 __ bind(¬_array);
4405 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4406 __ j(not_equal, &try_poly_name);
4407 Handle<Code> megamorphic_stub =
4408 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4409 __ jmp(megamorphic_stub, RelocInfo::CODE_TARGET);
4411 __ bind(&try_poly_name);
4412 // We might have a name in feedback, and a fixed array in the next slot.
4413 __ cmpp(key, feedback);
4414 __ j(not_equal, &miss);
4415 // If the name comparison succeeded, we know we have a fixed array with
4416 // at least one map/handler pair.
4417 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4418 FixedArray::kHeaderSize + kPointerSize));
4419 HandleArrayCases(masm, feedback, receiver_map, integer_slot, r11, r15, false,
4423 KeyedLoadIC::GenerateMiss(masm);
4425 __ bind(&load_smi_map);
4426 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4427 __ jmp(&compare_map);
4431 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4432 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4433 VectorStoreICStub stub(isolate(), state());
4434 stub.GenerateForTrampoline(masm);
4438 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4439 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4440 VectorKeyedStoreICStub stub(isolate(), state());
4441 stub.GenerateForTrampoline(masm);
4445 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4446 GenerateImpl(masm, false);
4450 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4451 GenerateImpl(masm, true);
4455 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4456 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // rdx
4457 Register key = VectorStoreICDescriptor::NameRegister(); // rcx
4458 Register vector = VectorStoreICDescriptor::VectorRegister(); // rbx
4459 Register slot = VectorStoreICDescriptor::SlotRegister(); // rdi
4460 DCHECK(VectorStoreICDescriptor::ValueRegister().is(rax)); // rax
4461 Register feedback = r8;
4462 Register integer_slot = r9;
4463 Register receiver_map = r11;
4464 DCHECK(!AreAliased(feedback, integer_slot, vector, slot, receiver_map));
4466 __ SmiToInteger32(integer_slot, slot);
4467 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4468 FixedArray::kHeaderSize));
4470 // Try to quickly handle the monomorphic case without knowing for sure
4471 // if we have a weak cell in feedback. We do know it's safe to look
4472 // at WeakCell::kValueOffset.
4473 Label try_array, load_smi_map, compare_map;
4474 Label not_array, miss;
4475 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector,
4476 integer_slot, &compare_map, &load_smi_map, &try_array);
4478 // Is it a fixed array?
4479 __ bind(&try_array);
4480 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex);
4481 __ j(not_equal, ¬_array);
4482 HandleArrayCases(masm, feedback, receiver_map, integer_slot, r14, r15, true,
4485 __ bind(¬_array);
4486 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4487 __ j(not_equal, &miss);
4489 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4490 Code::ComputeHandlerFlags(Code::STORE_IC));
4491 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::STORE_IC, code_flags,
4492 receiver, key, feedback, no_reg);
4495 StoreIC::GenerateMiss(masm);
4497 __ bind(&load_smi_map);
4498 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4499 __ jmp(&compare_map);
4503 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4504 GenerateImpl(masm, false);
4508 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4509 GenerateImpl(masm, true);
4513 static void HandlePolymorphicKeyedStoreCase(MacroAssembler* masm,
4514 Register receiver_map,
4515 Register feedback, Register scratch,
4517 Register scratch2, Label* miss) {
4518 // feedback initially contains the feedback array
4519 Label next, next_loop, prepare_next;
4520 Label transition_call;
4522 Register cached_map = scratch;
4523 Register counter = scratch1;
4524 Register length = scratch2;
4526 // Polymorphic, we have to loop from 0 to N - 1
4527 __ movp(counter, Immediate(0));
4528 __ movp(length, FieldOperand(feedback, FixedArray::kLengthOffset));
4529 __ SmiToInteger32(length, length);
4531 __ bind(&next_loop);
4532 __ movp(cached_map, FieldOperand(feedback, counter, times_pointer_size,
4533 FixedArray::kHeaderSize));
4534 __ cmpp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4535 __ j(not_equal, &prepare_next);
4536 __ movp(cached_map, FieldOperand(feedback, counter, times_pointer_size,
4537 FixedArray::kHeaderSize + kPointerSize));
4538 __ CompareRoot(cached_map, Heap::kUndefinedValueRootIndex);
4539 __ j(not_equal, &transition_call);
4540 __ movp(feedback, FieldOperand(feedback, counter, times_pointer_size,
4541 FixedArray::kHeaderSize + 2 * kPointerSize));
4542 __ leap(feedback, FieldOperand(feedback, Code::kHeaderSize));
4545 __ bind(&transition_call);
4546 DCHECK(receiver_map.is(VectorStoreTransitionDescriptor::MapRegister()));
4547 __ movp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4548 // The weak cell may have been cleared.
4549 __ JumpIfSmi(receiver_map, miss);
4550 // Get the handler in value.
4551 __ movp(feedback, FieldOperand(feedback, counter, times_pointer_size,
4552 FixedArray::kHeaderSize + 2 * kPointerSize));
4553 __ leap(feedback, FieldOperand(feedback, Code::kHeaderSize));
4556 __ bind(&prepare_next);
4557 __ addl(counter, Immediate(3));
4558 __ cmpl(counter, length);
4559 __ j(less, &next_loop);
4561 // We exhausted our array of map handler pairs.
4566 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4567 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // rdx
4568 Register key = VectorStoreICDescriptor::NameRegister(); // rcx
4569 Register vector = VectorStoreICDescriptor::VectorRegister(); // rbx
4570 Register slot = VectorStoreICDescriptor::SlotRegister(); // rdi
4571 DCHECK(VectorStoreICDescriptor::ValueRegister().is(rax)); // rax
4572 Register feedback = r8;
4573 Register integer_slot = r9;
4574 Register receiver_map = r11;
4575 DCHECK(!AreAliased(feedback, integer_slot, vector, slot, receiver_map));
4577 __ SmiToInteger32(integer_slot, slot);
4578 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4579 FixedArray::kHeaderSize));
4581 // Try to quickly handle the monomorphic case without knowing for sure
4582 // if we have a weak cell in feedback. We do know it's safe to look
4583 // at WeakCell::kValueOffset.
4584 Label try_array, load_smi_map, compare_map;
4585 Label not_array, miss;
4586 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector,
4587 integer_slot, &compare_map, &load_smi_map, &try_array);
4589 // Is it a fixed array?
4590 __ bind(&try_array);
4591 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex);
4592 __ j(not_equal, ¬_array);
4593 HandlePolymorphicKeyedStoreCase(masm, receiver_map, feedback, integer_slot,
4596 __ bind(¬_array);
4597 Label try_poly_name;
4598 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4599 __ j(not_equal, &try_poly_name);
4601 Handle<Code> megamorphic_stub =
4602 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4603 __ jmp(megamorphic_stub, RelocInfo::CODE_TARGET);
4605 __ bind(&try_poly_name);
4606 // We might have a name in feedback, and a fixed array in the next slot.
4607 __ cmpp(key, feedback);
4608 __ j(not_equal, &miss);
4609 // If the name comparison succeeded, we know we have a fixed array with
4610 // at least one map/handler pair.
4611 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4612 FixedArray::kHeaderSize + kPointerSize));
4613 HandleArrayCases(masm, feedback, receiver_map, integer_slot, r14, r15, false,
4617 KeyedStoreIC::GenerateMiss(masm);
4619 __ bind(&load_smi_map);
4620 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4621 __ jmp(&compare_map);
4625 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4626 EmitLoadTypeFeedbackVector(masm, rbx);
4627 CallICStub stub(isolate(), state());
4628 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET);
4632 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4633 if (masm->isolate()->function_entry_hook() != NULL) {
4634 ProfileEntryHookStub stub(masm->isolate());
4635 masm->CallStub(&stub);
4640 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4641 // This stub can be called from essentially anywhere, so it needs to save
4642 // all volatile and callee-save registers.
4643 const size_t kNumSavedRegisters = 2;
4644 __ pushq(arg_reg_1);
4645 __ pushq(arg_reg_2);
4647 // Calculate the original stack pointer and store it in the second arg.
4649 Operand(rsp, kNumSavedRegisters * kRegisterSize + kPCOnStackSize));
4651 // Calculate the function address to the first arg.
4652 __ movp(arg_reg_1, Operand(rsp, kNumSavedRegisters * kRegisterSize));
4653 __ subp(arg_reg_1, Immediate(Assembler::kShortCallInstructionLength));
4655 // Save the remainder of the volatile registers.
4656 masm->PushCallerSaved(kSaveFPRegs, arg_reg_1, arg_reg_2);
4658 // Call the entry hook function.
4659 __ Move(rax, FUNCTION_ADDR(isolate()->function_entry_hook()),
4660 Assembler::RelocInfoNone());
4662 AllowExternalCallThatCantCauseGC scope(masm);
4664 const int kArgumentCount = 2;
4665 __ PrepareCallCFunction(kArgumentCount);
4666 __ CallCFunction(rax, kArgumentCount);
4668 // Restore volatile regs.
4669 masm->PopCallerSaved(kSaveFPRegs, arg_reg_1, arg_reg_2);
4678 static void CreateArrayDispatch(MacroAssembler* masm,
4679 AllocationSiteOverrideMode mode) {
4680 if (mode == DISABLE_ALLOCATION_SITES) {
4681 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4682 __ TailCallStub(&stub);
4683 } else if (mode == DONT_OVERRIDE) {
4684 int last_index = GetSequenceIndexFromFastElementsKind(
4685 TERMINAL_FAST_ELEMENTS_KIND);
4686 for (int i = 0; i <= last_index; ++i) {
4688 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4689 __ cmpl(rdx, Immediate(kind));
4690 __ j(not_equal, &next);
4691 T stub(masm->isolate(), kind);
4692 __ TailCallStub(&stub);
4696 // If we reached this point there is a problem.
4697 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4704 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4705 AllocationSiteOverrideMode mode) {
4706 // rbx - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4707 // rdx - kind (if mode != DISABLE_ALLOCATION_SITES)
4708 // rax - number of arguments
4709 // rdi - constructor?
4710 // rsp[0] - return address
4711 // rsp[8] - last argument
4712 Handle<Object> undefined_sentinel(
4713 masm->isolate()->heap()->undefined_value(),
4716 Label normal_sequence;
4717 if (mode == DONT_OVERRIDE) {
4718 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4719 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4720 STATIC_ASSERT(FAST_ELEMENTS == 2);
4721 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4722 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4723 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4725 // is the low bit set? If so, we are holey and that is good.
4726 __ testb(rdx, Immediate(1));
4727 __ j(not_zero, &normal_sequence);
4730 // look at the first argument
4731 StackArgumentsAccessor args(rsp, 1, ARGUMENTS_DONT_CONTAIN_RECEIVER);
4732 __ movp(rcx, args.GetArgumentOperand(0));
4734 __ j(zero, &normal_sequence);
4736 if (mode == DISABLE_ALLOCATION_SITES) {
4737 ElementsKind initial = GetInitialFastElementsKind();
4738 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4740 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4742 DISABLE_ALLOCATION_SITES);
4743 __ TailCallStub(&stub_holey);
4745 __ bind(&normal_sequence);
4746 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4748 DISABLE_ALLOCATION_SITES);
4749 __ TailCallStub(&stub);
4750 } else if (mode == DONT_OVERRIDE) {
4751 // We are going to create a holey array, but our kind is non-holey.
4752 // Fix kind and retry (only if we have an allocation site in the slot).
4755 if (FLAG_debug_code) {
4756 Handle<Map> allocation_site_map =
4757 masm->isolate()->factory()->allocation_site_map();
4758 __ Cmp(FieldOperand(rbx, 0), allocation_site_map);
4759 __ Assert(equal, kExpectedAllocationSite);
4762 // Save the resulting elements kind in type info. We can't just store r3
4763 // in the AllocationSite::transition_info field because elements kind is
4764 // restricted to a portion of the field...upper bits need to be left alone.
4765 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4766 __ SmiAddConstant(FieldOperand(rbx, AllocationSite::kTransitionInfoOffset),
4767 Smi::FromInt(kFastElementsKindPackedToHoley));
4769 __ bind(&normal_sequence);
4770 int last_index = GetSequenceIndexFromFastElementsKind(
4771 TERMINAL_FAST_ELEMENTS_KIND);
4772 for (int i = 0; i <= last_index; ++i) {
4774 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4775 __ cmpl(rdx, Immediate(kind));
4776 __ j(not_equal, &next);
4777 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4778 __ TailCallStub(&stub);
4782 // If we reached this point there is a problem.
4783 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4791 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4792 int to_index = GetSequenceIndexFromFastElementsKind(
4793 TERMINAL_FAST_ELEMENTS_KIND);
4794 for (int i = 0; i <= to_index; ++i) {
4795 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4796 T stub(isolate, kind);
4798 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4799 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4806 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4807 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4809 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4811 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4816 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4818 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4819 for (int i = 0; i < 2; i++) {
4820 // For internal arrays we only need a few things
4821 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4823 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4825 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4831 void ArrayConstructorStub::GenerateDispatchToArrayStub(
4832 MacroAssembler* masm,
4833 AllocationSiteOverrideMode mode) {
4834 if (argument_count() == ANY) {
4835 Label not_zero_case, not_one_case;
4837 __ j(not_zero, ¬_zero_case);
4838 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4840 __ bind(¬_zero_case);
4841 __ cmpl(rax, Immediate(1));
4842 __ j(greater, ¬_one_case);
4843 CreateArrayDispatchOneArgument(masm, mode);
4845 __ bind(¬_one_case);
4846 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4847 } else if (argument_count() == NONE) {
4848 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4849 } else if (argument_count() == ONE) {
4850 CreateArrayDispatchOneArgument(masm, mode);
4851 } else if (argument_count() == MORE_THAN_ONE) {
4852 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4859 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4860 // ----------- S t a t e -------------
4862 // -- rbx : AllocationSite or undefined
4863 // -- rdi : constructor
4864 // -- rdx : original constructor
4865 // -- rsp[0] : return address
4866 // -- rsp[8] : last argument
4867 // -----------------------------------
4868 if (FLAG_debug_code) {
4869 // The array construct code is only set for the global and natives
4870 // builtin Array functions which always have maps.
4872 // Initial map for the builtin Array function should be a map.
4873 __ movp(rcx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
4874 // Will both indicate a NULL and a Smi.
4875 STATIC_ASSERT(kSmiTag == 0);
4876 Condition not_smi = NegateCondition(masm->CheckSmi(rcx));
4877 __ Check(not_smi, kUnexpectedInitialMapForArrayFunction);
4878 __ CmpObjectType(rcx, MAP_TYPE, rcx);
4879 __ Check(equal, kUnexpectedInitialMapForArrayFunction);
4881 // We should either have undefined in rbx or a valid AllocationSite
4882 __ AssertUndefinedOrAllocationSite(rbx);
4887 __ j(not_equal, &subclassing);
4890 // If the feedback vector is the undefined value call an array constructor
4891 // that doesn't use AllocationSites.
4892 __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex);
4893 __ j(equal, &no_info);
4895 // Only look at the lower 16 bits of the transition info.
4896 __ movp(rdx, FieldOperand(rbx, AllocationSite::kTransitionInfoOffset));
4897 __ SmiToInteger32(rdx, rdx);
4898 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4899 __ andp(rdx, Immediate(AllocationSite::ElementsKindBits::kMask));
4900 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4903 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
4906 __ bind(&subclassing);
4907 __ Pop(rcx); // return address.
4912 switch (argument_count()) {
4915 __ addp(rax, Immediate(2));
4918 __ movp(rax, Immediate(2));
4921 __ movp(rax, Immediate(3));
4926 __ JumpToExternalReference(
4927 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()),
4932 void InternalArrayConstructorStub::GenerateCase(
4933 MacroAssembler* masm, ElementsKind kind) {
4934 Label not_zero_case, not_one_case;
4935 Label normal_sequence;
4938 __ j(not_zero, ¬_zero_case);
4939 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4940 __ TailCallStub(&stub0);
4942 __ bind(¬_zero_case);
4943 __ cmpl(rax, Immediate(1));
4944 __ j(greater, ¬_one_case);
4946 if (IsFastPackedElementsKind(kind)) {
4947 // We might need to create a holey array
4948 // look at the first argument
4949 StackArgumentsAccessor args(rsp, 1, ARGUMENTS_DONT_CONTAIN_RECEIVER);
4950 __ movp(rcx, args.GetArgumentOperand(0));
4952 __ j(zero, &normal_sequence);
4954 InternalArraySingleArgumentConstructorStub
4955 stub1_holey(isolate(), GetHoleyElementsKind(kind));
4956 __ TailCallStub(&stub1_holey);
4959 __ bind(&normal_sequence);
4960 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
4961 __ TailCallStub(&stub1);
4963 __ bind(¬_one_case);
4964 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
4965 __ TailCallStub(&stubN);
4969 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
4970 // ----------- S t a t e -------------
4972 // -- rdi : constructor
4973 // -- rsp[0] : return address
4974 // -- rsp[8] : last argument
4975 // -----------------------------------
4977 if (FLAG_debug_code) {
4978 // The array construct code is only set for the global and natives
4979 // builtin Array functions which always have maps.
4981 // Initial map for the builtin Array function should be a map.
4982 __ movp(rcx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
4983 // Will both indicate a NULL and a Smi.
4984 STATIC_ASSERT(kSmiTag == 0);
4985 Condition not_smi = NegateCondition(masm->CheckSmi(rcx));
4986 __ Check(not_smi, kUnexpectedInitialMapForArrayFunction);
4987 __ CmpObjectType(rcx, MAP_TYPE, rcx);
4988 __ Check(equal, kUnexpectedInitialMapForArrayFunction);
4991 // Figure out the right elements kind
4992 __ movp(rcx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
4994 // Load the map's "bit field 2" into |result|. We only need the first byte,
4995 // but the following masking takes care of that anyway.
4996 __ movzxbp(rcx, FieldOperand(rcx, Map::kBitField2Offset));
4997 // Retrieve elements_kind from bit field 2.
4998 __ DecodeField<Map::ElementsKindBits>(rcx);
5000 if (FLAG_debug_code) {
5002 __ cmpl(rcx, Immediate(FAST_ELEMENTS));
5004 __ cmpl(rcx, Immediate(FAST_HOLEY_ELEMENTS));
5006 kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5010 Label fast_elements_case;
5011 __ cmpl(rcx, Immediate(FAST_ELEMENTS));
5012 __ j(equal, &fast_elements_case);
5013 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5015 __ bind(&fast_elements_case);
5016 GenerateCase(masm, FAST_ELEMENTS);
5020 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5021 Register context_reg = rsi;
5022 Register slot_reg = rbx;
5023 Register result_reg = rax;
5026 // Go up context chain to the script context.
5027 for (int i = 0; i < depth(); ++i) {
5028 __ movp(rdi, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5032 // Load the PropertyCell value at the specified slot.
5033 __ movp(result_reg, ContextOperand(context_reg, slot_reg));
5034 __ movp(result_reg, FieldOperand(result_reg, PropertyCell::kValueOffset));
5036 // Check that value is not the_hole.
5037 __ CompareRoot(result_reg, Heap::kTheHoleValueRootIndex);
5038 __ j(equal, &slow_case, Label::kNear);
5041 // Fallback to the runtime.
5042 __ bind(&slow_case);
5043 __ Integer32ToSmi(slot_reg, slot_reg);
5044 __ PopReturnAddressTo(kScratchRegister);
5046 __ Push(kScratchRegister);
5047 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5051 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5052 Register context_reg = rsi;
5053 Register slot_reg = rbx;
5054 Register value_reg = rax;
5055 Register cell_reg = r8;
5056 Register cell_details_reg = rdx;
5057 Register cell_value_reg = r9;
5058 Label fast_heapobject_case, fast_smi_case, slow_case;
5060 if (FLAG_debug_code) {
5061 __ CompareRoot(value_reg, Heap::kTheHoleValueRootIndex);
5062 __ Check(not_equal, kUnexpectedValue);
5065 // Go up context chain to the script context.
5066 for (int i = 0; i < depth(); ++i) {
5067 __ movp(rdi, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5071 // Load the PropertyCell at the specified slot.
5072 __ movp(cell_reg, ContextOperand(context_reg, slot_reg));
5074 // Load PropertyDetails for the cell (actually only the cell_type, kind and
5075 // READ_ONLY bit of attributes).
5076 __ SmiToInteger32(cell_details_reg,
5077 FieldOperand(cell_reg, PropertyCell::kDetailsOffset));
5078 __ andl(cell_details_reg,
5079 Immediate(PropertyDetails::PropertyCellTypeField::kMask |
5080 PropertyDetails::KindField::kMask |
5081 PropertyDetails::kAttributesReadOnlyMask));
5083 // Check if PropertyCell holds mutable data.
5084 Label not_mutable_data;
5085 __ cmpl(cell_details_reg,
5086 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5087 PropertyCellType::kMutable) |
5088 PropertyDetails::KindField::encode(kData)));
5089 __ j(not_equal, ¬_mutable_data);
5090 __ JumpIfSmi(value_reg, &fast_smi_case);
5091 __ bind(&fast_heapobject_case);
5092 __ movp(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg);
5093 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg,
5094 cell_value_reg, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5096 // RecordWriteField clobbers the value register, so we need to reload.
5097 __ movp(value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset));
5099 __ bind(¬_mutable_data);
5101 // Check if PropertyCell value matches the new value (relevant for Constant,
5102 // ConstantType and Undefined cells).
5103 Label not_same_value;
5104 __ movp(cell_value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset));
5105 __ cmpp(cell_value_reg, value_reg);
5106 __ j(not_equal, ¬_same_value,
5107 FLAG_debug_code ? Label::kFar : Label::kNear);
5108 // Make sure the PropertyCell is not marked READ_ONLY.
5109 __ testl(cell_details_reg,
5110 Immediate(PropertyDetails::kAttributesReadOnlyMask));
5111 __ j(not_zero, &slow_case);
5112 if (FLAG_debug_code) {
5114 // This can only be true for Constant, ConstantType and Undefined cells,
5115 // because we never store the_hole via this stub.
5116 __ cmpl(cell_details_reg,
5117 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5118 PropertyCellType::kConstant) |
5119 PropertyDetails::KindField::encode(kData)));
5121 __ cmpl(cell_details_reg,
5122 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5123 PropertyCellType::kConstantType) |
5124 PropertyDetails::KindField::encode(kData)));
5126 __ cmpl(cell_details_reg,
5127 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5128 PropertyCellType::kUndefined) |
5129 PropertyDetails::KindField::encode(kData)));
5130 __ Check(equal, kUnexpectedValue);
5134 __ bind(¬_same_value);
5136 // Check if PropertyCell contains data with constant type (and is not
5138 __ cmpl(cell_details_reg,
5139 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5140 PropertyCellType::kConstantType) |
5141 PropertyDetails::KindField::encode(kData)));
5142 __ j(not_equal, &slow_case, Label::kNear);
5144 // Now either both old and new values must be SMIs or both must be heap
5145 // objects with same map.
5146 Label value_is_heap_object;
5147 __ JumpIfNotSmi(value_reg, &value_is_heap_object, Label::kNear);
5148 __ JumpIfNotSmi(cell_value_reg, &slow_case, Label::kNear);
5149 // Old and new values are SMIs, no need for a write barrier here.
5150 __ bind(&fast_smi_case);
5151 __ movp(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg);
5153 __ bind(&value_is_heap_object);
5154 __ JumpIfSmi(cell_value_reg, &slow_case, Label::kNear);
5155 Register cell_value_map_reg = cell_value_reg;
5156 __ movp(cell_value_map_reg,
5157 FieldOperand(cell_value_reg, HeapObject::kMapOffset));
5158 __ cmpp(cell_value_map_reg, FieldOperand(value_reg, HeapObject::kMapOffset));
5159 __ j(equal, &fast_heapobject_case);
5161 // Fallback to the runtime.
5162 __ bind(&slow_case);
5163 __ Integer32ToSmi(slot_reg, slot_reg);
5164 __ PopReturnAddressTo(kScratchRegister);
5167 __ Push(kScratchRegister);
5168 __ TailCallRuntime(is_strict(language_mode())
5169 ? Runtime::kStoreGlobalViaContext_Strict
5170 : Runtime::kStoreGlobalViaContext_Sloppy,
5175 static int Offset(ExternalReference ref0, ExternalReference ref1) {
5176 int64_t offset = (ref0.address() - ref1.address());
5177 // Check that fits into int.
5178 DCHECK(static_cast<int>(offset) == offset);
5179 return static_cast<int>(offset);
5183 // Prepares stack to put arguments (aligns and so on). WIN64 calling
5184 // convention requires to put the pointer to the return value slot into
5185 // rcx (rcx must be preserverd until CallApiFunctionAndReturn). Saves
5186 // context (rsi). Clobbers rax. Allocates arg_stack_space * kPointerSize
5187 // inside the exit frame (not GCed) accessible via StackSpaceOperand.
5188 static void PrepareCallApiFunction(MacroAssembler* masm, int arg_stack_space) {
5189 __ EnterApiExitFrame(arg_stack_space);
5193 // Calls an API function. Allocates HandleScope, extracts returned value
5194 // from handle and propagates exceptions. Clobbers r14, r15, rbx and
5195 // caller-save registers. Restores context. On return removes
5196 // stack_space * kPointerSize (GCed).
5197 static void CallApiFunctionAndReturn(MacroAssembler* masm,
5198 Register function_address,
5199 ExternalReference thunk_ref,
5200 Register thunk_last_arg, int stack_space,
5201 Operand* stack_space_operand,
5202 Operand return_value_operand,
5203 Operand* context_restore_operand) {
5205 Label promote_scheduled_exception;
5206 Label delete_allocated_handles;
5207 Label leave_exit_frame;
5210 Isolate* isolate = masm->isolate();
5211 Factory* factory = isolate->factory();
5212 ExternalReference next_address =
5213 ExternalReference::handle_scope_next_address(isolate);
5214 const int kNextOffset = 0;
5215 const int kLimitOffset = Offset(
5216 ExternalReference::handle_scope_limit_address(isolate), next_address);
5217 const int kLevelOffset = Offset(
5218 ExternalReference::handle_scope_level_address(isolate), next_address);
5219 ExternalReference scheduled_exception_address =
5220 ExternalReference::scheduled_exception_address(isolate);
5222 DCHECK(rdx.is(function_address) || r8.is(function_address));
5223 // Allocate HandleScope in callee-save registers.
5224 Register prev_next_address_reg = r14;
5225 Register prev_limit_reg = rbx;
5226 Register base_reg = r15;
5227 __ Move(base_reg, next_address);
5228 __ movp(prev_next_address_reg, Operand(base_reg, kNextOffset));
5229 __ movp(prev_limit_reg, Operand(base_reg, kLimitOffset));
5230 __ addl(Operand(base_reg, kLevelOffset), Immediate(1));
5232 if (FLAG_log_timer_events) {
5233 FrameScope frame(masm, StackFrame::MANUAL);
5234 __ PushSafepointRegisters();
5235 __ PrepareCallCFunction(1);
5236 __ LoadAddress(arg_reg_1, ExternalReference::isolate_address(isolate));
5237 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5239 __ PopSafepointRegisters();
5242 Label profiler_disabled;
5243 Label end_profiler_check;
5244 __ Move(rax, ExternalReference::is_profiling_address(isolate));
5245 __ cmpb(Operand(rax, 0), Immediate(0));
5246 __ j(zero, &profiler_disabled);
5248 // Third parameter is the address of the actual getter function.
5249 __ Move(thunk_last_arg, function_address);
5250 __ Move(rax, thunk_ref);
5251 __ jmp(&end_profiler_check);
5253 __ bind(&profiler_disabled);
5254 // Call the api function!
5255 __ Move(rax, function_address);
5257 __ bind(&end_profiler_check);
5259 // Call the api function!
5262 if (FLAG_log_timer_events) {
5263 FrameScope frame(masm, StackFrame::MANUAL);
5264 __ PushSafepointRegisters();
5265 __ PrepareCallCFunction(1);
5266 __ LoadAddress(arg_reg_1, ExternalReference::isolate_address(isolate));
5267 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5269 __ PopSafepointRegisters();
5272 // Load the value from ReturnValue
5273 __ movp(rax, return_value_operand);
5276 // No more valid handles (the result handle was the last one). Restore
5277 // previous handle scope.
5278 __ subl(Operand(base_reg, kLevelOffset), Immediate(1));
5279 __ movp(Operand(base_reg, kNextOffset), prev_next_address_reg);
5280 __ cmpp(prev_limit_reg, Operand(base_reg, kLimitOffset));
5281 __ j(not_equal, &delete_allocated_handles);
5283 // Leave the API exit frame.
5284 __ bind(&leave_exit_frame);
5285 bool restore_context = context_restore_operand != NULL;
5286 if (restore_context) {
5287 __ movp(rsi, *context_restore_operand);
5289 if (stack_space_operand != nullptr) {
5290 __ movp(rbx, *stack_space_operand);
5292 __ LeaveApiExitFrame(!restore_context);
5294 // Check if the function scheduled an exception.
5295 __ Move(rdi, scheduled_exception_address);
5296 __ Cmp(Operand(rdi, 0), factory->the_hole_value());
5297 __ j(not_equal, &promote_scheduled_exception);
5300 // Check if the function returned a valid JavaScript value.
5302 Register return_value = rax;
5305 __ JumpIfSmi(return_value, &ok, Label::kNear);
5306 __ movp(map, FieldOperand(return_value, HeapObject::kMapOffset));
5308 __ CmpInstanceType(map, LAST_NAME_TYPE);
5309 __ j(below_equal, &ok, Label::kNear);
5311 __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE);
5312 __ j(above_equal, &ok, Label::kNear);
5314 __ CompareRoot(map, Heap::kHeapNumberMapRootIndex);
5315 __ j(equal, &ok, Label::kNear);
5317 __ CompareRoot(return_value, Heap::kUndefinedValueRootIndex);
5318 __ j(equal, &ok, Label::kNear);
5320 __ CompareRoot(return_value, Heap::kTrueValueRootIndex);
5321 __ j(equal, &ok, Label::kNear);
5323 __ CompareRoot(return_value, Heap::kFalseValueRootIndex);
5324 __ j(equal, &ok, Label::kNear);
5326 __ CompareRoot(return_value, Heap::kNullValueRootIndex);
5327 __ j(equal, &ok, Label::kNear);
5329 __ Abort(kAPICallReturnedInvalidObject);
5334 if (stack_space_operand != nullptr) {
5335 DCHECK_EQ(stack_space, 0);
5336 __ PopReturnAddressTo(rcx);
5340 __ ret(stack_space * kPointerSize);
5343 // Re-throw by promoting a scheduled exception.
5344 __ bind(&promote_scheduled_exception);
5345 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5347 // HandleScope limit has changed. Delete allocated extensions.
5348 __ bind(&delete_allocated_handles);
5349 __ movp(Operand(base_reg, kLimitOffset), prev_limit_reg);
5350 __ movp(prev_limit_reg, rax);
5351 __ LoadAddress(arg_reg_1, ExternalReference::isolate_address(isolate));
5353 ExternalReference::delete_handle_scope_extensions(isolate));
5355 __ movp(rax, prev_limit_reg);
5356 __ jmp(&leave_exit_frame);
5360 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5361 const ParameterCount& argc,
5362 bool return_first_arg,
5363 bool call_data_undefined) {
5364 // ----------- S t a t e -------------
5366 // -- rbx : call_data
5368 // -- rdx : api_function_address
5370 // -- rax : number of arguments if argc is a register
5371 // -- rsp[0] : return address
5372 // -- rsp[8] : last argument
5374 // -- rsp[argc * 8] : first argument
5375 // -- rsp[(argc + 1) * 8] : receiver
5376 // -----------------------------------
5378 Register callee = rdi;
5379 Register call_data = rbx;
5380 Register holder = rcx;
5381 Register api_function_address = rdx;
5382 Register context = rsi;
5383 Register return_address = r8;
5385 typedef FunctionCallbackArguments FCA;
5387 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5388 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5389 STATIC_ASSERT(FCA::kDataIndex == 4);
5390 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5391 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5392 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5393 STATIC_ASSERT(FCA::kHolderIndex == 0);
5394 STATIC_ASSERT(FCA::kArgsLength == 7);
5396 DCHECK(argc.is_immediate() || rax.is(argc.reg()));
5398 __ PopReturnAddressTo(return_address);
5408 Register scratch = call_data;
5409 if (!call_data_undefined) {
5410 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5414 // return value default
5417 __ Move(scratch, ExternalReference::isolate_address(masm->isolate()));
5422 __ movp(scratch, rsp);
5423 // Push return address back on stack.
5424 __ PushReturnAddressFrom(return_address);
5426 // load context from callee
5427 __ movp(context, FieldOperand(callee, JSFunction::kContextOffset));
5429 // Allocate the v8::Arguments structure in the arguments' space since
5430 // it's not controlled by GC.
5431 const int kApiStackSpace = 4;
5433 PrepareCallApiFunction(masm, kApiStackSpace);
5435 // FunctionCallbackInfo::implicit_args_.
5436 __ movp(StackSpaceOperand(0), scratch);
5437 if (argc.is_immediate()) {
5438 __ addp(scratch, Immediate((argc.immediate() + FCA::kArgsLength - 1) *
5440 // FunctionCallbackInfo::values_.
5441 __ movp(StackSpaceOperand(1), scratch);
5442 // FunctionCallbackInfo::length_.
5443 __ Set(StackSpaceOperand(2), argc.immediate());
5444 // FunctionCallbackInfo::is_construct_call_.
5445 __ Set(StackSpaceOperand(3), 0);
5447 __ leap(scratch, Operand(scratch, argc.reg(), times_pointer_size,
5448 (FCA::kArgsLength - 1) * kPointerSize));
5449 // FunctionCallbackInfo::values_.
5450 __ movp(StackSpaceOperand(1), scratch);
5451 // FunctionCallbackInfo::length_.
5452 __ movp(StackSpaceOperand(2), argc.reg());
5453 // FunctionCallbackInfo::is_construct_call_.
5454 __ leap(argc.reg(), Operand(argc.reg(), times_pointer_size,
5455 (FCA::kArgsLength + 1) * kPointerSize));
5456 __ movp(StackSpaceOperand(3), argc.reg());
5459 #if defined(__MINGW64__) || defined(_WIN64)
5460 Register arguments_arg = rcx;
5461 Register callback_arg = rdx;
5463 Register arguments_arg = rdi;
5464 Register callback_arg = rsi;
5467 // It's okay if api_function_address == callback_arg
5468 // but not arguments_arg
5469 DCHECK(!api_function_address.is(arguments_arg));
5471 // v8::InvocationCallback's argument.
5472 __ leap(arguments_arg, StackSpaceOperand(0));
5474 ExternalReference thunk_ref =
5475 ExternalReference::invoke_function_callback(masm->isolate());
5477 // Accessor for FunctionCallbackInfo and first js arg.
5478 StackArgumentsAccessor args_from_rbp(rbp, FCA::kArgsLength + 1,
5479 ARGUMENTS_DONT_CONTAIN_RECEIVER);
5480 Operand context_restore_operand = args_from_rbp.GetArgumentOperand(
5481 FCA::kArgsLength - FCA::kContextSaveIndex);
5482 Operand is_construct_call_operand = StackSpaceOperand(3);
5483 Operand return_value_operand = args_from_rbp.GetArgumentOperand(
5484 return_first_arg ? 0 : FCA::kArgsLength - FCA::kReturnValueOffset);
5485 int stack_space = 0;
5486 Operand* stack_space_operand = &is_construct_call_operand;
5487 if (argc.is_immediate()) {
5488 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5489 stack_space_operand = nullptr;
5491 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, callback_arg,
5492 stack_space, stack_space_operand,
5493 return_value_operand, &context_restore_operand);
5497 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5498 bool call_data_undefined = this->call_data_undefined();
5499 CallApiFunctionStubHelper(masm, ParameterCount(rax), false,
5500 call_data_undefined);
5504 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5505 bool is_store = this->is_store();
5506 int argc = this->argc();
5507 bool call_data_undefined = this->call_data_undefined();
5508 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5509 call_data_undefined);
5513 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5514 // ----------- S t a t e -------------
5515 // -- rsp[0] : return address
5517 // -- rsp[16 - kArgsLength*8] : PropertyCallbackArguments object
5519 // -- r8 : api_function_address
5520 // -----------------------------------
5522 #if defined(__MINGW64__) || defined(_WIN64)
5523 Register getter_arg = r8;
5524 Register accessor_info_arg = rdx;
5525 Register name_arg = rcx;
5527 Register getter_arg = rdx;
5528 Register accessor_info_arg = rsi;
5529 Register name_arg = rdi;
5531 Register api_function_address = ApiGetterDescriptor::function_address();
5532 DCHECK(api_function_address.is(r8));
5533 Register scratch = rax;
5535 // v8::Arguments::values_ and handler for name.
5536 const int kStackSpace = PropertyCallbackArguments::kArgsLength + 1;
5538 // Allocate v8::AccessorInfo in non-GCed stack space.
5539 const int kArgStackSpace = 1;
5541 __ leap(name_arg, Operand(rsp, kPCOnStackSize));
5543 PrepareCallApiFunction(masm, kArgStackSpace);
5544 __ leap(scratch, Operand(name_arg, 1 * kPointerSize));
5546 // v8::PropertyAccessorInfo::args_.
5547 __ movp(StackSpaceOperand(0), scratch);
5549 // The context register (rsi) has been saved in PrepareCallApiFunction and
5550 // could be used to pass arguments.
5551 __ leap(accessor_info_arg, StackSpaceOperand(0));
5553 ExternalReference thunk_ref =
5554 ExternalReference::invoke_accessor_getter_callback(isolate());
5556 // It's okay if api_function_address == getter_arg
5557 // but not accessor_info_arg or name_arg
5558 DCHECK(!api_function_address.is(accessor_info_arg) &&
5559 !api_function_address.is(name_arg));
5561 // The name handler is counted as an argument.
5562 StackArgumentsAccessor args(rbp, PropertyCallbackArguments::kArgsLength);
5563 Operand return_value_operand = args.GetArgumentOperand(
5564 PropertyCallbackArguments::kArgsLength - 1 -
5565 PropertyCallbackArguments::kReturnValueOffset);
5566 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, getter_arg,
5567 kStackSpace, nullptr, return_value_operand, NULL);
5573 } // namespace internal
5576 #endif // V8_TARGET_ARCH_X64