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
1982 // Check that the constructor is not a smi.
1983 __ JumpIfSmi(rdi, &non_function);
1984 // Check that constructor is a JSFunction.
1985 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, r11);
1986 __ j(not_equal, &non_function);
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 // Tail call to the function-specific construct stub (still in the caller
2012 // context at this point).
2013 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
2014 __ movp(rcx, FieldOperand(rcx, SharedFunctionInfo::kConstructStubOffset));
2015 __ leap(rcx, FieldOperand(rcx, Code::kHeaderSize));
2018 __ bind(&non_function);
2020 __ Jump(isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
2024 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2025 __ movp(vector, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
2026 __ movp(vector, FieldOperand(vector, JSFunction::kSharedFunctionInfoOffset));
2027 __ movp(vector, FieldOperand(vector,
2028 SharedFunctionInfo::kFeedbackVectorOffset));
2032 void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) {
2036 // rcx - allocation site (loaded from vector[slot]).
2037 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r8);
2039 __ j(not_equal, miss);
2041 __ movp(rax, Immediate(arg_count()));
2043 // Increment the call count for monomorphic function calls.
2044 __ SmiAddConstant(FieldOperand(rbx, rdx, times_pointer_size,
2045 FixedArray::kHeaderSize + kPointerSize),
2046 Smi::FromInt(CallICNexus::kCallCountIncrement));
2050 ArrayConstructorStub stub(masm->isolate(), arg_count());
2051 __ TailCallStub(&stub);
2055 void CallICStub::Generate(MacroAssembler* masm) {
2059 Isolate* isolate = masm->isolate();
2060 const int with_types_offset =
2061 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2062 const int generic_offset =
2063 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2064 Label extra_checks_or_miss, slow_start;
2065 Label slow, wrap, cont;
2066 Label have_js_function;
2067 int argc = arg_count();
2068 StackArgumentsAccessor args(rsp, argc);
2069 ParameterCount actual(argc);
2071 // The checks. First, does rdi match the recorded monomorphic target?
2072 __ SmiToInteger32(rdx, rdx);
2074 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize));
2076 // We don't know that we have a weak cell. We might have a private symbol
2077 // or an AllocationSite, but the memory is safe to examine.
2078 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2080 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2081 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2082 // computed, meaning that it can't appear to be a pointer. If the low bit is
2083 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2085 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2086 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2087 WeakCell::kValueOffset &&
2088 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2090 __ cmpp(rdi, FieldOperand(rcx, WeakCell::kValueOffset));
2091 __ j(not_equal, &extra_checks_or_miss);
2093 // The compare above could have been a SMI/SMI comparison. Guard against this
2094 // convincing us that we have a monomorphic JSFunction.
2095 __ JumpIfSmi(rdi, &extra_checks_or_miss);
2097 // Increment the call count for monomorphic function calls.
2098 __ SmiAddConstant(FieldOperand(rbx, rdx, times_pointer_size,
2099 FixedArray::kHeaderSize + kPointerSize),
2100 Smi::FromInt(CallICNexus::kCallCountIncrement));
2102 __ bind(&have_js_function);
2103 if (CallAsMethod()) {
2104 EmitContinueIfStrictOrNative(masm, &cont);
2106 // Load the receiver from the stack.
2107 __ movp(rax, args.GetReceiverOperand());
2109 __ JumpIfSmi(rax, &wrap);
2111 __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx);
2117 __ InvokeFunction(rdi, actual, JUMP_FUNCTION, NullCallWrapper());
2120 EmitSlowCase(masm, &args, argc);
2122 if (CallAsMethod()) {
2124 EmitWrapCase(masm, &args, &cont);
2127 __ bind(&extra_checks_or_miss);
2128 Label uninitialized, miss, not_allocation_site;
2130 __ Cmp(rcx, TypeFeedbackVector::MegamorphicSentinel(isolate));
2131 __ j(equal, &slow_start);
2133 // Check if we have an allocation site.
2134 __ CompareRoot(FieldOperand(rcx, HeapObject::kMapOffset),
2135 Heap::kAllocationSiteMapRootIndex);
2136 __ j(not_equal, ¬_allocation_site);
2138 // We have an allocation site.
2139 HandleArrayCase(masm, &miss);
2141 __ bind(¬_allocation_site);
2143 // The following cases attempt to handle MISS cases without going to the
2145 if (FLAG_trace_ic) {
2149 __ Cmp(rcx, TypeFeedbackVector::UninitializedSentinel(isolate));
2150 __ j(equal, &uninitialized);
2152 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2153 // to handle it here. More complex cases are dealt with in the runtime.
2154 __ AssertNotSmi(rcx);
2155 __ CmpObjectType(rcx, JS_FUNCTION_TYPE, rcx);
2156 __ j(not_equal, &miss);
2157 __ Move(FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize),
2158 TypeFeedbackVector::MegamorphicSentinel(isolate));
2159 // We have to update statistics for runtime profiling.
2160 __ SmiAddConstant(FieldOperand(rbx, with_types_offset), Smi::FromInt(-1));
2161 __ SmiAddConstant(FieldOperand(rbx, generic_offset), Smi::FromInt(1));
2162 __ jmp(&slow_start);
2164 __ bind(&uninitialized);
2166 // We are going monomorphic, provided we actually have a JSFunction.
2167 __ JumpIfSmi(rdi, &miss);
2169 // Goto miss case if we do not have a function.
2170 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx);
2171 __ j(not_equal, &miss);
2173 // Make sure the function is not the Array() function, which requires special
2174 // behavior on MISS.
2175 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, rcx);
2180 __ SmiAddConstant(FieldOperand(rbx, with_types_offset), Smi::FromInt(1));
2182 // Initialize the call counter.
2183 __ Move(FieldOperand(rbx, rdx, times_pointer_size,
2184 FixedArray::kHeaderSize + kPointerSize),
2185 Smi::FromInt(CallICNexus::kCallCountIncrement));
2187 // Store the function. Use a stub since we need a frame for allocation.
2189 // rdx - slot (needs to be in smi form)
2192 FrameScope scope(masm, StackFrame::INTERNAL);
2193 CreateWeakCellStub create_stub(isolate);
2195 __ Integer32ToSmi(rdx, rdx);
2197 __ CallStub(&create_stub);
2201 __ jmp(&have_js_function);
2203 // We are here because tracing is on or we encountered a MISS case we can't
2209 __ bind(&slow_start);
2210 // Check that function is not a smi.
2211 __ JumpIfSmi(rdi, &slow);
2212 // Check that function is a JSFunction.
2213 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx);
2214 __ j(not_equal, &slow);
2215 __ jmp(&have_js_function);
2222 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2223 FrameScope scope(masm, StackFrame::INTERNAL);
2225 // Push the receiver and the function and feedback info.
2228 __ Integer32ToSmi(rdx, rdx);
2232 __ CallRuntime(Runtime::kCallIC_Miss, 3);
2234 // Move result to edi and exit the internal frame.
2239 bool CEntryStub::NeedsImmovableCode() {
2244 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
2245 CEntryStub::GenerateAheadOfTime(isolate);
2246 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
2247 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
2248 // It is important that the store buffer overflow stubs are generated first.
2249 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
2250 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
2251 CreateWeakCellStub::GenerateAheadOfTime(isolate);
2252 BinaryOpICStub::GenerateAheadOfTime(isolate);
2253 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
2254 StoreFastElementStub::GenerateAheadOfTime(isolate);
2255 TypeofStub::GenerateAheadOfTime(isolate);
2259 void CodeStub::GenerateFPStubs(Isolate* isolate) {
2263 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
2264 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
2266 CEntryStub save_doubles(isolate, 1, kSaveFPRegs);
2267 save_doubles.GetCode();
2271 void CEntryStub::Generate(MacroAssembler* masm) {
2272 // rax: number of arguments including receiver
2273 // rbx: pointer to C function (C callee-saved)
2274 // rbp: frame pointer of calling JS frame (restored after C call)
2275 // rsp: stack pointer (restored after C call)
2276 // rsi: current context (restored)
2278 ProfileEntryHookStub::MaybeCallEntryHook(masm);
2280 // Enter the exit frame that transitions from JavaScript to C++.
2282 int arg_stack_space = (result_size() < 2 ? 2 : 4);
2284 int arg_stack_space = 0;
2286 __ EnterExitFrame(arg_stack_space, save_doubles());
2288 // rbx: pointer to builtin function (C callee-saved).
2289 // rbp: frame pointer of exit frame (restored after C call).
2290 // rsp: stack pointer (restored after C call).
2291 // r14: number of arguments including receiver (C callee-saved).
2292 // r15: argv pointer (C callee-saved).
2294 // Simple results returned in rax (both AMD64 and Win64 calling conventions).
2295 // Complex results must be written to address passed as first argument.
2296 // AMD64 calling convention: a struct of two pointers in rax+rdx
2298 // Check stack alignment.
2299 if (FLAG_debug_code) {
2300 __ CheckStackAlignment();
2305 // Windows 64-bit ABI passes arguments in rcx, rdx, r8, r9.
2306 // Pass argv and argc as two parameters. The arguments object will
2307 // be created by stubs declared by DECLARE_RUNTIME_FUNCTION().
2308 if (result_size() < 2) {
2309 // Pass a pointer to the Arguments object as the first argument.
2310 // Return result in single register (rax).
2311 __ movp(rcx, r14); // argc.
2312 __ movp(rdx, r15); // argv.
2313 __ Move(r8, ExternalReference::isolate_address(isolate()));
2315 DCHECK_EQ(2, result_size());
2316 // Pass a pointer to the result location as the first argument.
2317 __ leap(rcx, StackSpaceOperand(2));
2318 // Pass a pointer to the Arguments object as the second argument.
2319 __ movp(rdx, r14); // argc.
2320 __ movp(r8, r15); // argv.
2321 __ Move(r9, ExternalReference::isolate_address(isolate()));
2325 // GCC passes arguments in rdi, rsi, rdx, rcx, r8, r9.
2326 __ movp(rdi, r14); // argc.
2327 __ movp(rsi, r15); // argv.
2328 __ Move(rdx, ExternalReference::isolate_address(isolate()));
2331 // Result is in rax - do not destroy this register!
2334 // If return value is on the stack, pop it to registers.
2335 if (result_size() > 1) {
2336 DCHECK_EQ(2, result_size());
2337 // Read result values stored on stack. Result is stored
2338 // above the four argument mirror slots and the two
2339 // Arguments object slots.
2340 __ movq(rax, Operand(rsp, 6 * kRegisterSize));
2341 __ movq(rdx, Operand(rsp, 7 * kRegisterSize));
2345 // Check result for exception sentinel.
2346 Label exception_returned;
2347 __ CompareRoot(rax, Heap::kExceptionRootIndex);
2348 __ j(equal, &exception_returned);
2350 // Check that there is no pending exception, otherwise we
2351 // should have returned the exception sentinel.
2352 if (FLAG_debug_code) {
2354 __ LoadRoot(r14, Heap::kTheHoleValueRootIndex);
2355 ExternalReference pending_exception_address(
2356 Isolate::kPendingExceptionAddress, isolate());
2357 Operand pending_exception_operand =
2358 masm->ExternalOperand(pending_exception_address);
2359 __ cmpp(r14, pending_exception_operand);
2360 __ j(equal, &okay, Label::kNear);
2365 // Exit the JavaScript to C++ exit frame.
2366 __ LeaveExitFrame(save_doubles());
2369 // Handling of exception.
2370 __ bind(&exception_returned);
2372 ExternalReference pending_handler_context_address(
2373 Isolate::kPendingHandlerContextAddress, isolate());
2374 ExternalReference pending_handler_code_address(
2375 Isolate::kPendingHandlerCodeAddress, isolate());
2376 ExternalReference pending_handler_offset_address(
2377 Isolate::kPendingHandlerOffsetAddress, isolate());
2378 ExternalReference pending_handler_fp_address(
2379 Isolate::kPendingHandlerFPAddress, isolate());
2380 ExternalReference pending_handler_sp_address(
2381 Isolate::kPendingHandlerSPAddress, isolate());
2383 // Ask the runtime for help to determine the handler. This will set rax to
2384 // contain the current pending exception, don't clobber it.
2385 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
2388 FrameScope scope(masm, StackFrame::MANUAL);
2389 __ movp(arg_reg_1, Immediate(0)); // argc.
2390 __ movp(arg_reg_2, Immediate(0)); // argv.
2391 __ Move(arg_reg_3, ExternalReference::isolate_address(isolate()));
2392 __ PrepareCallCFunction(3);
2393 __ CallCFunction(find_handler, 3);
2396 // Retrieve the handler context, SP and FP.
2397 __ movp(rsi, masm->ExternalOperand(pending_handler_context_address));
2398 __ movp(rsp, masm->ExternalOperand(pending_handler_sp_address));
2399 __ movp(rbp, masm->ExternalOperand(pending_handler_fp_address));
2401 // If the handler is a JS frame, restore the context to the frame. Note that
2402 // the context will be set to (rsi == 0) for non-JS frames.
2405 __ j(zero, &skip, Label::kNear);
2406 __ movp(Operand(rbp, StandardFrameConstants::kContextOffset), rsi);
2409 // Compute the handler entry address and jump to it.
2410 __ movp(rdi, masm->ExternalOperand(pending_handler_code_address));
2411 __ movp(rdx, masm->ExternalOperand(pending_handler_offset_address));
2412 __ leap(rdi, FieldOperand(rdi, rdx, times_1, Code::kHeaderSize));
2417 void JSEntryStub::Generate(MacroAssembler* masm) {
2418 Label invoke, handler_entry, exit;
2419 Label not_outermost_js, not_outermost_js_2;
2421 ProfileEntryHookStub::MaybeCallEntryHook(masm);
2423 { // NOLINT. Scope block confuses linter.
2424 MacroAssembler::NoRootArrayScope uninitialized_root_register(masm);
2429 // Push the stack frame type marker twice.
2430 int marker = type();
2431 // Scratch register is neither callee-save, nor an argument register on any
2432 // platform. It's free to use at this point.
2433 // Cannot use smi-register for loading yet.
2434 __ Move(kScratchRegister, Smi::FromInt(marker), Assembler::RelocInfoNone());
2435 __ Push(kScratchRegister); // context slot
2436 __ Push(kScratchRegister); // function slot
2437 // Save callee-saved registers (X64/X32/Win64 calling conventions).
2443 __ pushq(rdi); // Only callee save in Win64 ABI, argument in AMD64 ABI.
2444 __ pushq(rsi); // Only callee save in Win64 ABI, argument in AMD64 ABI.
2449 // On Win64 XMM6-XMM15 are callee-save
2450 __ subp(rsp, Immediate(EntryFrameConstants::kXMMRegistersBlockSize));
2451 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 0), xmm6);
2452 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 1), xmm7);
2453 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 2), xmm8);
2454 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 3), xmm9);
2455 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 4), xmm10);
2456 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 5), xmm11);
2457 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 6), xmm12);
2458 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 7), xmm13);
2459 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 8), xmm14);
2460 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 9), xmm15);
2463 // Set up the roots and smi constant registers.
2464 // Needs to be done before any further smi loads.
2465 __ InitializeRootRegister();
2468 // Save copies of the top frame descriptor on the stack.
2469 ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, isolate());
2471 Operand c_entry_fp_operand = masm->ExternalOperand(c_entry_fp);
2472 __ Push(c_entry_fp_operand);
2475 // If this is the outermost JS call, set js_entry_sp value.
2476 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
2477 __ Load(rax, js_entry_sp);
2479 __ j(not_zero, ¬_outermost_js);
2480 __ Push(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
2482 __ Store(js_entry_sp, rax);
2485 __ bind(¬_outermost_js);
2486 __ Push(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME));
2489 // Jump to a faked try block that does the invoke, with a faked catch
2490 // block that sets the pending exception.
2492 __ bind(&handler_entry);
2493 handler_offset_ = handler_entry.pos();
2494 // Caught exception: Store result (exception) in the pending exception
2495 // field in the JSEnv and return a failure sentinel.
2496 ExternalReference pending_exception(Isolate::kPendingExceptionAddress,
2498 __ Store(pending_exception, rax);
2499 __ LoadRoot(rax, Heap::kExceptionRootIndex);
2502 // Invoke: Link this frame into the handler chain.
2504 __ PushStackHandler();
2506 // Clear any pending exceptions.
2507 __ LoadRoot(rax, Heap::kTheHoleValueRootIndex);
2508 __ Store(pending_exception, rax);
2510 // Fake a receiver (NULL).
2511 __ Push(Immediate(0)); // receiver
2513 // Invoke the function by calling through JS entry trampoline builtin and
2514 // pop the faked function when we return. We load the address from an
2515 // external reference instead of inlining the call target address directly
2516 // in the code, because the builtin stubs may not have been generated yet
2517 // at the time this code is generated.
2518 if (type() == StackFrame::ENTRY_CONSTRUCT) {
2519 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
2521 __ Load(rax, construct_entry);
2523 ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
2524 __ Load(rax, entry);
2526 __ leap(kScratchRegister, FieldOperand(rax, Code::kHeaderSize));
2527 __ call(kScratchRegister);
2529 // Unlink this frame from the handler chain.
2530 __ PopStackHandler();
2533 // Check if the current stack frame is marked as the outermost JS frame.
2535 __ Cmp(rbx, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
2536 __ j(not_equal, ¬_outermost_js_2);
2537 __ Move(kScratchRegister, js_entry_sp);
2538 __ movp(Operand(kScratchRegister, 0), Immediate(0));
2539 __ bind(¬_outermost_js_2);
2541 // Restore the top frame descriptor from the stack.
2542 { Operand c_entry_fp_operand = masm->ExternalOperand(c_entry_fp);
2543 __ Pop(c_entry_fp_operand);
2546 // Restore callee-saved registers (X64 conventions).
2548 // On Win64 XMM6-XMM15 are callee-save
2549 __ movdqu(xmm6, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 0));
2550 __ movdqu(xmm7, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 1));
2551 __ movdqu(xmm8, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 2));
2552 __ movdqu(xmm9, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 3));
2553 __ movdqu(xmm10, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 4));
2554 __ movdqu(xmm11, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 5));
2555 __ movdqu(xmm12, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 6));
2556 __ movdqu(xmm13, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 7));
2557 __ movdqu(xmm14, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 8));
2558 __ movdqu(xmm15, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 9));
2559 __ addp(rsp, Immediate(EntryFrameConstants::kXMMRegistersBlockSize));
2564 // Callee save on in Win64 ABI, arguments/volatile in AMD64 ABI.
2572 __ addp(rsp, Immediate(2 * kPointerSize)); // remove markers
2574 // Restore frame pointer and return.
2580 void InstanceOfStub::Generate(MacroAssembler* masm) {
2581 Register const object = rdx; // Object (lhs).
2582 Register const function = rax; // Function (rhs).
2583 Register const object_map = rcx; // Map of {object}.
2584 Register const function_map = r8; // Map of {function}.
2585 Register const function_prototype = rdi; // Prototype of {function}.
2587 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
2588 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
2590 // Check if {object} is a smi.
2591 Label object_is_smi;
2592 __ JumpIfSmi(object, &object_is_smi, Label::kNear);
2594 // Lookup the {function} and the {object} map in the global instanceof cache.
2595 // Note: This is safe because we clear the global instanceof cache whenever
2596 // we change the prototype of any object.
2597 Label fast_case, slow_case;
2598 __ movp(object_map, FieldOperand(object, HeapObject::kMapOffset));
2599 __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
2600 __ j(not_equal, &fast_case, Label::kNear);
2601 __ CompareRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
2602 __ j(not_equal, &fast_case, Label::kNear);
2603 __ LoadRoot(rax, Heap::kInstanceofCacheAnswerRootIndex);
2606 // If {object} is a smi we can safely return false if {function} is a JS
2607 // function, otherwise we have to miss to the runtime and throw an exception.
2608 __ bind(&object_is_smi);
2609 __ JumpIfSmi(function, &slow_case);
2610 __ CmpObjectType(function, JS_FUNCTION_TYPE, function_map);
2611 __ j(not_equal, &slow_case);
2612 __ LoadRoot(rax, Heap::kFalseValueRootIndex);
2615 // Fast-case: The {function} must be a valid JSFunction.
2616 __ bind(&fast_case);
2617 __ JumpIfSmi(function, &slow_case);
2618 __ CmpObjectType(function, JS_FUNCTION_TYPE, function_map);
2619 __ j(not_equal, &slow_case);
2621 // Ensure that {function} has an instance prototype.
2622 __ testb(FieldOperand(function_map, Map::kBitFieldOffset),
2623 Immediate(1 << Map::kHasNonInstancePrototype));
2624 __ j(not_zero, &slow_case);
2626 // Ensure that {function} is not bound.
2627 Register const shared_info = kScratchRegister;
2628 __ movp(shared_info,
2629 FieldOperand(function, JSFunction::kSharedFunctionInfoOffset));
2630 __ TestBitSharedFunctionInfoSpecialField(
2631 shared_info, SharedFunctionInfo::kCompilerHintsOffset,
2632 SharedFunctionInfo::kBoundFunction);
2633 __ j(not_zero, &slow_case);
2635 // Get the "prototype" (or initial map) of the {function}.
2636 __ movp(function_prototype,
2637 FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
2638 __ AssertNotSmi(function_prototype);
2640 // Resolve the prototype if the {function} has an initial map. Afterwards the
2641 // {function_prototype} will be either the JSReceiver prototype object or the
2642 // hole value, which means that no instances of the {function} were created so
2643 // far and hence we should return false.
2644 Label function_prototype_valid;
2645 Register const function_prototype_map = kScratchRegister;
2646 __ CmpObjectType(function_prototype, MAP_TYPE, function_prototype_map);
2647 __ j(not_equal, &function_prototype_valid, Label::kNear);
2648 __ movp(function_prototype,
2649 FieldOperand(function_prototype, Map::kPrototypeOffset));
2650 __ bind(&function_prototype_valid);
2651 __ AssertNotSmi(function_prototype);
2653 // Update the global instanceof cache with the current {object} map and
2654 // {function}. The cached answer will be set when it is known below.
2655 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
2656 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
2658 // Loop through the prototype chain looking for the {function} prototype.
2659 // Assume true, and change to false if not found.
2660 Register const object_prototype = object_map;
2662 __ LoadRoot(rax, Heap::kTrueValueRootIndex);
2664 __ movp(object_prototype, FieldOperand(object_map, Map::kPrototypeOffset));
2665 __ cmpp(object_prototype, function_prototype);
2666 __ j(equal, &done, Label::kNear);
2667 __ CompareRoot(object_prototype, Heap::kNullValueRootIndex);
2668 __ movp(object_map, FieldOperand(object_prototype, HeapObject::kMapOffset));
2669 __ j(not_equal, &loop);
2670 __ LoadRoot(rax, Heap::kFalseValueRootIndex);
2672 __ StoreRoot(rax, Heap::kInstanceofCacheAnswerRootIndex);
2675 // Slow-case: Call the runtime function.
2676 __ bind(&slow_case);
2677 __ PopReturnAddressTo(kScratchRegister);
2680 __ PushReturnAddressFrom(kScratchRegister);
2681 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
2685 // -------------------------------------------------------------------------
2686 // StringCharCodeAtGenerator
2688 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2689 // If the receiver is a smi trigger the non-string case.
2690 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2691 __ JumpIfSmi(object_, receiver_not_string_);
2693 // Fetch the instance type of the receiver into result register.
2694 __ movp(result_, FieldOperand(object_, HeapObject::kMapOffset));
2695 __ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset));
2696 // If the receiver is not a string trigger the non-string case.
2697 __ testb(result_, Immediate(kIsNotStringMask));
2698 __ j(not_zero, receiver_not_string_);
2701 // If the index is non-smi trigger the non-smi case.
2702 __ JumpIfNotSmi(index_, &index_not_smi_);
2703 __ bind(&got_smi_index_);
2705 // Check for index out of range.
2706 __ SmiCompare(index_, FieldOperand(object_, String::kLengthOffset));
2707 __ j(above_equal, index_out_of_range_);
2709 __ SmiToInteger32(index_, index_);
2711 StringCharLoadGenerator::Generate(
2712 masm, object_, index_, result_, &call_runtime_);
2714 __ Integer32ToSmi(result_, result_);
2719 void StringCharCodeAtGenerator::GenerateSlow(
2720 MacroAssembler* masm, EmbedMode embed_mode,
2721 const RuntimeCallHelper& call_helper) {
2722 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2724 Factory* factory = masm->isolate()->factory();
2725 // Index is not a smi.
2726 __ bind(&index_not_smi_);
2727 // If index is a heap number, try converting it to an integer.
2729 factory->heap_number_map(),
2732 call_helper.BeforeCall(masm);
2733 if (embed_mode == PART_OF_IC_HANDLER) {
2734 __ Push(LoadWithVectorDescriptor::VectorRegister());
2735 __ Push(LoadDescriptor::SlotRegister());
2738 __ Push(index_); // Consumed by runtime conversion function.
2739 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2740 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2742 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2743 // NumberToSmi discards numbers that are not exact integers.
2744 __ CallRuntime(Runtime::kNumberToSmi, 1);
2746 if (!index_.is(rax)) {
2747 // Save the conversion result before the pop instructions below
2748 // have a chance to overwrite it.
2749 __ movp(index_, rax);
2752 if (embed_mode == PART_OF_IC_HANDLER) {
2753 __ Pop(LoadDescriptor::SlotRegister());
2754 __ Pop(LoadWithVectorDescriptor::VectorRegister());
2756 // Reload the instance type.
2757 __ movp(result_, FieldOperand(object_, HeapObject::kMapOffset));
2758 __ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset));
2759 call_helper.AfterCall(masm);
2760 // If index is still not a smi, it must be out of range.
2761 __ JumpIfNotSmi(index_, index_out_of_range_);
2762 // Otherwise, return to the fast path.
2763 __ jmp(&got_smi_index_);
2765 // Call runtime. We get here when the receiver is a string and the
2766 // index is a number, but the code of getting the actual character
2767 // is too complex (e.g., when the string needs to be flattened).
2768 __ bind(&call_runtime_);
2769 call_helper.BeforeCall(masm);
2771 __ Integer32ToSmi(index_, index_);
2773 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
2774 if (!result_.is(rax)) {
2775 __ movp(result_, rax);
2777 call_helper.AfterCall(masm);
2780 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
2784 // -------------------------------------------------------------------------
2785 // StringCharFromCodeGenerator
2787 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
2788 // Fast case of Heap::LookupSingleCharacterStringFromCode.
2789 __ JumpIfNotSmi(code_, &slow_case_);
2790 __ SmiCompare(code_, Smi::FromInt(String::kMaxOneByteCharCode));
2791 __ j(above, &slow_case_);
2793 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
2794 SmiIndex index = masm->SmiToIndex(kScratchRegister, code_, kPointerSizeLog2);
2795 __ movp(result_, FieldOperand(result_, index.reg, index.scale,
2796 FixedArray::kHeaderSize));
2797 __ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
2798 __ j(equal, &slow_case_);
2803 void StringCharFromCodeGenerator::GenerateSlow(
2804 MacroAssembler* masm,
2805 const RuntimeCallHelper& call_helper) {
2806 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
2808 __ bind(&slow_case_);
2809 call_helper.BeforeCall(masm);
2811 __ CallRuntime(Runtime::kCharFromCode, 1);
2812 if (!result_.is(rax)) {
2813 __ movp(result_, rax);
2815 call_helper.AfterCall(masm);
2818 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
2822 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
2826 String::Encoding encoding) {
2827 // Nothing to do for zero characters.
2829 __ testl(count, count);
2830 __ j(zero, &done, Label::kNear);
2832 // Make count the number of bytes to copy.
2833 if (encoding == String::TWO_BYTE_ENCODING) {
2834 STATIC_ASSERT(2 == sizeof(uc16));
2835 __ addl(count, count);
2838 // Copy remaining characters.
2841 __ movb(kScratchRegister, Operand(src, 0));
2842 __ movb(Operand(dest, 0), kScratchRegister);
2846 __ j(not_zero, &loop);
2852 void SubStringStub::Generate(MacroAssembler* masm) {
2855 // Stack frame on entry.
2856 // rsp[0] : return address
2861 enum SubStringStubArgumentIndices {
2862 STRING_ARGUMENT_INDEX,
2863 FROM_ARGUMENT_INDEX,
2865 SUB_STRING_ARGUMENT_COUNT
2868 StackArgumentsAccessor args(rsp, SUB_STRING_ARGUMENT_COUNT,
2869 ARGUMENTS_DONT_CONTAIN_RECEIVER);
2871 // Make sure first argument is a string.
2872 __ movp(rax, args.GetArgumentOperand(STRING_ARGUMENT_INDEX));
2873 STATIC_ASSERT(kSmiTag == 0);
2874 __ testl(rax, Immediate(kSmiTagMask));
2875 __ j(zero, &runtime);
2876 Condition is_string = masm->IsObjectStringType(rax, rbx, rbx);
2877 __ j(NegateCondition(is_string), &runtime);
2880 // rbx: instance type
2881 // Calculate length of sub string using the smi values.
2882 __ movp(rcx, args.GetArgumentOperand(TO_ARGUMENT_INDEX));
2883 __ movp(rdx, args.GetArgumentOperand(FROM_ARGUMENT_INDEX));
2884 __ JumpUnlessBothNonNegativeSmi(rcx, rdx, &runtime);
2886 __ SmiSub(rcx, rcx, rdx); // Overflow doesn't happen.
2887 __ cmpp(rcx, FieldOperand(rax, String::kLengthOffset));
2888 Label not_original_string;
2889 // Shorter than original string's length: an actual substring.
2890 __ j(below, ¬_original_string, Label::kNear);
2891 // Longer than original string's length or negative: unsafe arguments.
2892 __ j(above, &runtime);
2893 // Return original string.
2894 Counters* counters = isolate()->counters();
2895 __ IncrementCounter(counters->sub_string_native(), 1);
2896 __ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
2897 __ bind(¬_original_string);
2900 __ SmiCompare(rcx, Smi::FromInt(1));
2901 __ j(equal, &single_char);
2903 __ SmiToInteger32(rcx, rcx);
2906 // rbx: instance type
2907 // rcx: sub string length
2908 // rdx: from index (smi)
2909 // Deal with different string types: update the index if necessary
2910 // and put the underlying string into edi.
2911 Label underlying_unpacked, sliced_string, seq_or_external_string;
2912 // If the string is not indirect, it can only be sequential or external.
2913 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
2914 STATIC_ASSERT(kIsIndirectStringMask != 0);
2915 __ testb(rbx, Immediate(kIsIndirectStringMask));
2916 __ j(zero, &seq_or_external_string, Label::kNear);
2918 __ testb(rbx, Immediate(kSlicedNotConsMask));
2919 __ j(not_zero, &sliced_string, Label::kNear);
2920 // Cons string. Check whether it is flat, then fetch first part.
2921 // Flat cons strings have an empty second part.
2922 __ CompareRoot(FieldOperand(rax, ConsString::kSecondOffset),
2923 Heap::kempty_stringRootIndex);
2924 __ j(not_equal, &runtime);
2925 __ movp(rdi, FieldOperand(rax, ConsString::kFirstOffset));
2926 // Update instance type.
2927 __ movp(rbx, FieldOperand(rdi, HeapObject::kMapOffset));
2928 __ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset));
2929 __ jmp(&underlying_unpacked, Label::kNear);
2931 __ bind(&sliced_string);
2932 // Sliced string. Fetch parent and correct start index by offset.
2933 __ addp(rdx, FieldOperand(rax, SlicedString::kOffsetOffset));
2934 __ movp(rdi, FieldOperand(rax, SlicedString::kParentOffset));
2935 // Update instance type.
2936 __ movp(rbx, FieldOperand(rdi, HeapObject::kMapOffset));
2937 __ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset));
2938 __ jmp(&underlying_unpacked, Label::kNear);
2940 __ bind(&seq_or_external_string);
2941 // Sequential or external string. Just move string to the correct register.
2944 __ bind(&underlying_unpacked);
2946 if (FLAG_string_slices) {
2948 // rdi: underlying subject string
2949 // rbx: instance type of underlying subject string
2950 // rdx: adjusted start index (smi)
2952 // If coming from the make_two_character_string path, the string
2953 // is too short to be sliced anyways.
2954 __ cmpp(rcx, Immediate(SlicedString::kMinLength));
2955 // Short slice. Copy instead of slicing.
2956 __ j(less, ©_routine);
2957 // Allocate new sliced string. At this point we do not reload the instance
2958 // type including the string encoding because we simply rely on the info
2959 // provided by the original string. It does not matter if the original
2960 // string's encoding is wrong because we always have to recheck encoding of
2961 // the newly created string's parent anyways due to externalized strings.
2962 Label two_byte_slice, set_slice_header;
2963 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
2964 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
2965 __ testb(rbx, Immediate(kStringEncodingMask));
2966 __ j(zero, &two_byte_slice, Label::kNear);
2967 __ AllocateOneByteSlicedString(rax, rbx, r14, &runtime);
2968 __ jmp(&set_slice_header, Label::kNear);
2969 __ bind(&two_byte_slice);
2970 __ AllocateTwoByteSlicedString(rax, rbx, r14, &runtime);
2971 __ bind(&set_slice_header);
2972 __ Integer32ToSmi(rcx, rcx);
2973 __ movp(FieldOperand(rax, SlicedString::kLengthOffset), rcx);
2974 __ movp(FieldOperand(rax, SlicedString::kHashFieldOffset),
2975 Immediate(String::kEmptyHashField));
2976 __ movp(FieldOperand(rax, SlicedString::kParentOffset), rdi);
2977 __ movp(FieldOperand(rax, SlicedString::kOffsetOffset), rdx);
2978 __ IncrementCounter(counters->sub_string_native(), 1);
2979 __ ret(3 * kPointerSize);
2981 __ bind(©_routine);
2984 // rdi: underlying subject string
2985 // rbx: instance type of underlying subject string
2986 // rdx: adjusted start index (smi)
2988 // The subject string can only be external or sequential string of either
2989 // encoding at this point.
2990 Label two_byte_sequential, sequential_string;
2991 STATIC_ASSERT(kExternalStringTag != 0);
2992 STATIC_ASSERT(kSeqStringTag == 0);
2993 __ testb(rbx, Immediate(kExternalStringTag));
2994 __ j(zero, &sequential_string);
2996 // Handle external string.
2997 // Rule out short external strings.
2998 STATIC_ASSERT(kShortExternalStringTag != 0);
2999 __ testb(rbx, Immediate(kShortExternalStringMask));
3000 __ j(not_zero, &runtime);
3001 __ movp(rdi, FieldOperand(rdi, ExternalString::kResourceDataOffset));
3002 // Move the pointer so that offset-wise, it looks like a sequential string.
3003 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3004 __ subp(rdi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3006 __ bind(&sequential_string);
3007 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3008 __ testb(rbx, Immediate(kStringEncodingMask));
3009 __ j(zero, &two_byte_sequential);
3011 // Allocate the result.
3012 __ AllocateOneByteString(rax, rcx, r11, r14, r15, &runtime);
3014 // rax: result string
3015 // rcx: result string length
3016 { // Locate character of sub string start.
3017 SmiIndex smi_as_index = masm->SmiToIndex(rdx, rdx, times_1);
3018 __ leap(r14, Operand(rdi, smi_as_index.reg, smi_as_index.scale,
3019 SeqOneByteString::kHeaderSize - kHeapObjectTag));
3021 // Locate first character of result.
3022 __ leap(rdi, FieldOperand(rax, SeqOneByteString::kHeaderSize));
3024 // rax: result string
3025 // rcx: result length
3026 // r14: first character of result
3027 // rsi: character of sub string start
3028 StringHelper::GenerateCopyCharacters(
3029 masm, rdi, r14, rcx, String::ONE_BYTE_ENCODING);
3030 __ IncrementCounter(counters->sub_string_native(), 1);
3031 __ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
3033 __ bind(&two_byte_sequential);
3034 // Allocate the result.
3035 __ AllocateTwoByteString(rax, rcx, r11, r14, r15, &runtime);
3037 // rax: result string
3038 // rcx: result string length
3039 { // Locate character of sub string start.
3040 SmiIndex smi_as_index = masm->SmiToIndex(rdx, rdx, times_2);
3041 __ leap(r14, Operand(rdi, smi_as_index.reg, smi_as_index.scale,
3042 SeqOneByteString::kHeaderSize - kHeapObjectTag));
3044 // Locate first character of result.
3045 __ leap(rdi, FieldOperand(rax, SeqTwoByteString::kHeaderSize));
3047 // rax: result string
3048 // rcx: result length
3049 // rdi: first character of result
3050 // r14: character of sub string start
3051 StringHelper::GenerateCopyCharacters(
3052 masm, rdi, r14, rcx, String::TWO_BYTE_ENCODING);
3053 __ IncrementCounter(counters->sub_string_native(), 1);
3054 __ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
3056 // Just jump to runtime to create the sub string.
3058 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3060 __ bind(&single_char);
3062 // rbx: instance type
3063 // rcx: sub string length (smi)
3064 // rdx: from index (smi)
3065 StringCharAtGenerator generator(rax, rdx, rcx, rax, &runtime, &runtime,
3066 &runtime, STRING_INDEX_IS_NUMBER,
3067 RECEIVER_IS_STRING);
3068 generator.GenerateFast(masm);
3069 __ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
3070 generator.SkipSlow(masm, &runtime);
3074 void ToNumberStub::Generate(MacroAssembler* masm) {
3075 // The ToNumber stub takes one argument in rax.
3077 __ JumpIfNotSmi(rax, ¬_smi, Label::kNear);
3081 Label not_heap_number;
3082 __ CompareRoot(FieldOperand(rax, HeapObject::kMapOffset),
3083 Heap::kHeapNumberMapRootIndex);
3084 __ j(not_equal, ¬_heap_number, Label::kNear);
3086 __ bind(¬_heap_number);
3088 Label not_string, slow_string;
3089 __ CmpObjectType(rax, FIRST_NONSTRING_TYPE, rdi);
3092 __ j(above_equal, ¬_string, Label::kNear);
3093 // Check if string has a cached array index.
3094 __ testl(FieldOperand(rax, String::kHashFieldOffset),
3095 Immediate(String::kContainsCachedArrayIndexMask));
3096 __ j(not_zero, &slow_string, Label::kNear);
3097 __ movl(rax, FieldOperand(rax, String::kHashFieldOffset));
3098 __ IndexFromHash(rax, rax);
3100 __ bind(&slow_string);
3101 __ PopReturnAddressTo(rcx); // Pop return address.
3102 __ Push(rax); // Push argument.
3103 __ PushReturnAddressFrom(rcx); // Push return address.
3104 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3105 __ bind(¬_string);
3108 __ CmpInstanceType(rdi, ODDBALL_TYPE);
3109 __ j(not_equal, ¬_oddball, Label::kNear);
3110 __ movp(rax, FieldOperand(rax, Oddball::kToNumberOffset));
3112 __ bind(¬_oddball);
3114 __ PopReturnAddressTo(rcx); // Pop return address.
3115 __ Push(rax); // Push argument.
3116 __ PushReturnAddressFrom(rcx); // Push return address.
3117 __ TailCallRuntime(Runtime::kToNumber, 1, 1);
3121 void ToStringStub::Generate(MacroAssembler* masm) {
3122 // The ToString stub takes one argument in rax.
3124 __ JumpIfSmi(rax, &is_number, Label::kNear);
3127 __ CmpObjectType(rax, FIRST_NONSTRING_TYPE, rdi);
3129 // rdi: receiver map
3130 __ j(above_equal, ¬_string, Label::kNear);
3132 __ bind(¬_string);
3134 Label not_heap_number;
3135 __ CompareRoot(rax, Heap::kHeapNumberMapRootIndex);
3136 __ j(not_equal, ¬_heap_number, Label::kNear);
3137 __ bind(&is_number);
3138 NumberToStringStub stub(isolate());
3139 __ TailCallStub(&stub);
3140 __ bind(¬_heap_number);
3143 __ CmpInstanceType(rdi, ODDBALL_TYPE);
3144 __ j(not_equal, ¬_oddball, Label::kNear);
3145 __ movp(rax, FieldOperand(rax, Oddball::kToStringOffset));
3147 __ bind(¬_oddball);
3149 __ PopReturnAddressTo(rcx); // Pop return address.
3150 __ Push(rax); // Push argument.
3151 __ PushReturnAddressFrom(rcx); // Push return address.
3152 __ TailCallRuntime(Runtime::kToString, 1, 1);
3156 void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
3160 Register scratch2) {
3161 Register length = scratch1;
3164 Label check_zero_length;
3165 __ movp(length, FieldOperand(left, String::kLengthOffset));
3166 __ SmiCompare(length, FieldOperand(right, String::kLengthOffset));
3167 __ j(equal, &check_zero_length, Label::kNear);
3168 __ Move(rax, Smi::FromInt(NOT_EQUAL));
3171 // Check if the length is zero.
3172 Label compare_chars;
3173 __ bind(&check_zero_length);
3174 STATIC_ASSERT(kSmiTag == 0);
3176 __ j(not_zero, &compare_chars, Label::kNear);
3177 __ Move(rax, Smi::FromInt(EQUAL));
3180 // Compare characters.
3181 __ bind(&compare_chars);
3182 Label strings_not_equal;
3183 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2,
3184 &strings_not_equal, Label::kNear);
3186 // Characters are equal.
3187 __ Move(rax, Smi::FromInt(EQUAL));
3190 // Characters are not equal.
3191 __ bind(&strings_not_equal);
3192 __ Move(rax, Smi::FromInt(NOT_EQUAL));
3197 void StringHelper::GenerateCompareFlatOneByteStrings(
3198 MacroAssembler* masm, Register left, Register right, Register scratch1,
3199 Register scratch2, Register scratch3, Register scratch4) {
3200 // Ensure that you can always subtract a string length from a non-negative
3201 // number (e.g. another length).
3202 STATIC_ASSERT(String::kMaxLength < 0x7fffffff);
3204 // Find minimum length and length difference.
3205 __ movp(scratch1, FieldOperand(left, String::kLengthOffset));
3206 __ movp(scratch4, scratch1);
3209 FieldOperand(right, String::kLengthOffset));
3210 // Register scratch4 now holds left.length - right.length.
3211 const Register length_difference = scratch4;
3213 __ j(less, &left_shorter, Label::kNear);
3214 // The right string isn't longer that the left one.
3215 // Get the right string's length by subtracting the (non-negative) difference
3216 // from the left string's length.
3217 __ SmiSub(scratch1, scratch1, length_difference);
3218 __ bind(&left_shorter);
3219 // Register scratch1 now holds Min(left.length, right.length).
3220 const Register min_length = scratch1;
3222 Label compare_lengths;
3223 // If min-length is zero, go directly to comparing lengths.
3224 __ SmiTest(min_length);
3225 __ j(zero, &compare_lengths, Label::kNear);
3228 Label result_not_equal;
3229 GenerateOneByteCharsCompareLoop(
3230 masm, left, right, min_length, scratch2, &result_not_equal,
3231 // In debug-code mode, SmiTest below might push
3232 // the target label outside the near range.
3235 // Completed loop without finding different characters.
3236 // Compare lengths (precomputed).
3237 __ bind(&compare_lengths);
3238 __ SmiTest(length_difference);
3239 Label length_not_equal;
3240 __ j(not_zero, &length_not_equal, Label::kNear);
3243 __ Move(rax, Smi::FromInt(EQUAL));
3246 Label result_greater;
3248 __ bind(&length_not_equal);
3249 __ j(greater, &result_greater, Label::kNear);
3250 __ jmp(&result_less, Label::kNear);
3251 __ bind(&result_not_equal);
3252 // Unequal comparison of left to right, either character or length.
3253 __ j(above, &result_greater, Label::kNear);
3254 __ bind(&result_less);
3257 __ Move(rax, Smi::FromInt(LESS));
3260 // Result is GREATER.
3261 __ bind(&result_greater);
3262 __ Move(rax, Smi::FromInt(GREATER));
3267 void StringHelper::GenerateOneByteCharsCompareLoop(
3268 MacroAssembler* masm, Register left, Register right, Register length,
3269 Register scratch, Label* chars_not_equal, Label::Distance near_jump) {
3270 // Change index to run from -length to -1 by adding length to string
3271 // start. This means that loop ends when index reaches zero, which
3272 // doesn't need an additional compare.
3273 __ SmiToInteger32(length, length);
3275 FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize));
3277 FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize));
3279 Register index = length; // index = -length;
3284 __ movb(scratch, Operand(left, index, times_1, 0));
3285 __ cmpb(scratch, Operand(right, index, times_1, 0));
3286 __ j(not_equal, chars_not_equal, near_jump);
3288 __ j(not_zero, &loop);
3292 void StringCompareStub::Generate(MacroAssembler* masm) {
3293 // ----------- S t a t e -------------
3294 // -- rdx : left string
3295 // -- rax : right string
3296 // -- rsp[0] : return address
3297 // -----------------------------------
3298 __ AssertString(rdx);
3299 __ AssertString(rax);
3301 // Check for identity.
3304 __ j(not_equal, ¬_same, Label::kNear);
3305 __ Move(rax, Smi::FromInt(EQUAL));
3306 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1);
3311 // Check that both are sequential one-byte strings.
3313 __ JumpIfNotBothSequentialOneByteStrings(rdx, rax, rcx, rbx, &runtime);
3315 // Inline comparison of one-byte strings.
3316 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1);
3317 StringHelper::GenerateCompareFlatOneByteStrings(masm, rdx, rax, rcx, rbx, rdi,
3320 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
3321 // tagged as a small integer.
3323 __ PopReturnAddressTo(rcx);
3326 __ PushReturnAddressFrom(rcx);
3327 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3331 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3332 // ----------- S t a t e -------------
3335 // -- rsp[0] : return address
3336 // -----------------------------------
3338 // Load rcx with the allocation site. We stick an undefined dummy value here
3339 // and replace it with the real allocation site later when we instantiate this
3340 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3341 __ Move(rcx, handle(isolate()->heap()->undefined_value()));
3343 // Make sure that we actually patched the allocation site.
3344 if (FLAG_debug_code) {
3345 __ testb(rcx, Immediate(kSmiTagMask));
3346 __ Assert(not_equal, kExpectedAllocationSite);
3347 __ Cmp(FieldOperand(rcx, HeapObject::kMapOffset),
3348 isolate()->factory()->allocation_site_map());
3349 __ Assert(equal, kExpectedAllocationSite);
3352 // Tail call into the stub that handles binary operations with allocation
3354 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3355 __ TailCallStub(&stub);
3359 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3360 DCHECK(state() == CompareICState::SMI);
3362 __ JumpIfNotBothSmi(rdx, rax, &miss, Label::kNear);
3364 if (GetCondition() == equal) {
3365 // For equality we do not care about the sign of the result.
3370 __ j(no_overflow, &done, Label::kNear);
3371 // Correct sign of result in case of overflow.
3383 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3384 DCHECK(state() == CompareICState::NUMBER);
3387 Label unordered, maybe_undefined1, maybe_undefined2;
3390 if (left() == CompareICState::SMI) {
3391 __ JumpIfNotSmi(rdx, &miss);
3393 if (right() == CompareICState::SMI) {
3394 __ JumpIfNotSmi(rax, &miss);
3397 // Load left and right operand.
3398 Label done, left, left_smi, right_smi;
3399 __ JumpIfSmi(rax, &right_smi, Label::kNear);
3400 __ CompareMap(rax, isolate()->factory()->heap_number_map());
3401 __ j(not_equal, &maybe_undefined1, Label::kNear);
3402 __ movsd(xmm1, FieldOperand(rax, HeapNumber::kValueOffset));
3403 __ jmp(&left, Label::kNear);
3404 __ bind(&right_smi);
3405 __ SmiToInteger32(rcx, rax); // Can't clobber rax yet.
3406 __ Cvtlsi2sd(xmm1, rcx);
3409 __ JumpIfSmi(rdx, &left_smi, Label::kNear);
3410 __ CompareMap(rdx, isolate()->factory()->heap_number_map());
3411 __ j(not_equal, &maybe_undefined2, Label::kNear);
3412 __ movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset));
3415 __ SmiToInteger32(rcx, rdx); // Can't clobber rdx yet.
3416 __ Cvtlsi2sd(xmm0, rcx);
3420 __ ucomisd(xmm0, xmm1);
3422 // Don't base result on EFLAGS when a NaN is involved.
3423 __ j(parity_even, &unordered, Label::kNear);
3425 // Return a result of -1, 0, or 1, based on EFLAGS.
3426 // Performing mov, because xor would destroy the flag register.
3427 __ movl(rax, Immediate(0));
3428 __ movl(rcx, Immediate(0));
3429 __ setcc(above, rax); // Add one to zero if carry clear and not equal.
3430 __ sbbp(rax, rcx); // Subtract one if below (aka. carry set).
3433 __ bind(&unordered);
3434 __ bind(&generic_stub);
3435 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3436 CompareICState::GENERIC, CompareICState::GENERIC);
3437 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET);
3439 __ bind(&maybe_undefined1);
3440 if (Token::IsOrderedRelationalCompareOp(op())) {
3441 __ Cmp(rax, isolate()->factory()->undefined_value());
3442 __ j(not_equal, &miss);
3443 __ JumpIfSmi(rdx, &unordered);
3444 __ CmpObjectType(rdx, HEAP_NUMBER_TYPE, rcx);
3445 __ j(not_equal, &maybe_undefined2, Label::kNear);
3449 __ bind(&maybe_undefined2);
3450 if (Token::IsOrderedRelationalCompareOp(op())) {
3451 __ Cmp(rdx, isolate()->factory()->undefined_value());
3452 __ j(equal, &unordered);
3460 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3461 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3462 DCHECK(GetCondition() == equal);
3464 // Registers containing left and right operands respectively.
3465 Register left = rdx;
3466 Register right = rax;
3467 Register tmp1 = rcx;
3468 Register tmp2 = rbx;
3470 // Check that both operands are heap objects.
3472 Condition cond = masm->CheckEitherSmi(left, right, tmp1);
3473 __ j(cond, &miss, Label::kNear);
3475 // Check that both operands are internalized strings.
3476 __ movp(tmp1, FieldOperand(left, HeapObject::kMapOffset));
3477 __ movp(tmp2, FieldOperand(right, HeapObject::kMapOffset));
3478 __ movzxbp(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
3479 __ movzxbp(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
3480 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3482 __ testb(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask));
3483 __ j(not_zero, &miss, Label::kNear);
3485 // Internalized strings are compared by identity.
3487 __ cmpp(left, right);
3488 // Make sure rax is non-zero. At this point input operands are
3489 // guaranteed to be non-zero.
3490 DCHECK(right.is(rax));
3491 __ j(not_equal, &done, Label::kNear);
3492 STATIC_ASSERT(EQUAL == 0);
3493 STATIC_ASSERT(kSmiTag == 0);
3494 __ Move(rax, Smi::FromInt(EQUAL));
3503 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3504 DCHECK(state() == CompareICState::UNIQUE_NAME);
3505 DCHECK(GetCondition() == equal);
3507 // Registers containing left and right operands respectively.
3508 Register left = rdx;
3509 Register right = rax;
3510 Register tmp1 = rcx;
3511 Register tmp2 = rbx;
3513 // Check that both operands are heap objects.
3515 Condition cond = masm->CheckEitherSmi(left, right, tmp1);
3516 __ j(cond, &miss, Label::kNear);
3518 // Check that both operands are unique names. This leaves the instance
3519 // types loaded in tmp1 and tmp2.
3520 __ movp(tmp1, FieldOperand(left, HeapObject::kMapOffset));
3521 __ movp(tmp2, FieldOperand(right, HeapObject::kMapOffset));
3522 __ movzxbp(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
3523 __ movzxbp(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
3525 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss, Label::kNear);
3526 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss, Label::kNear);
3528 // Unique names are compared by identity.
3530 __ cmpp(left, right);
3531 // Make sure rax is non-zero. At this point input operands are
3532 // guaranteed to be non-zero.
3533 DCHECK(right.is(rax));
3534 __ j(not_equal, &done, Label::kNear);
3535 STATIC_ASSERT(EQUAL == 0);
3536 STATIC_ASSERT(kSmiTag == 0);
3537 __ Move(rax, Smi::FromInt(EQUAL));
3546 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3547 DCHECK(state() == CompareICState::STRING);
3550 bool equality = Token::IsEqualityOp(op());
3552 // Registers containing left and right operands respectively.
3553 Register left = rdx;
3554 Register right = rax;
3555 Register tmp1 = rcx;
3556 Register tmp2 = rbx;
3557 Register tmp3 = rdi;
3559 // Check that both operands are heap objects.
3560 Condition cond = masm->CheckEitherSmi(left, right, tmp1);
3563 // Check that both operands are strings. This leaves the instance
3564 // types loaded in tmp1 and tmp2.
3565 __ movp(tmp1, FieldOperand(left, HeapObject::kMapOffset));
3566 __ movp(tmp2, FieldOperand(right, HeapObject::kMapOffset));
3567 __ movzxbp(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
3568 __ movzxbp(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
3569 __ movp(tmp3, tmp1);
3570 STATIC_ASSERT(kNotStringTag != 0);
3572 __ testb(tmp3, Immediate(kIsNotStringMask));
3573 __ j(not_zero, &miss);
3575 // Fast check for identical strings.
3577 __ cmpp(left, right);
3578 __ j(not_equal, ¬_same, Label::kNear);
3579 STATIC_ASSERT(EQUAL == 0);
3580 STATIC_ASSERT(kSmiTag == 0);
3581 __ Move(rax, Smi::FromInt(EQUAL));
3584 // Handle not identical strings.
3587 // Check that both strings are internalized strings. If they are, we're done
3588 // because we already know they are not identical. We also know they are both
3592 STATIC_ASSERT(kInternalizedTag == 0);
3594 __ testb(tmp1, Immediate(kIsNotInternalizedMask));
3595 __ j(not_zero, &do_compare, Label::kNear);
3596 // Make sure rax is non-zero. At this point input operands are
3597 // guaranteed to be non-zero.
3598 DCHECK(right.is(rax));
3600 __ bind(&do_compare);
3603 // Check that both strings are sequential one-byte.
3605 __ JumpIfNotBothSequentialOneByteStrings(left, right, tmp1, tmp2, &runtime);
3607 // Compare flat one-byte strings. Returns when done.
3609 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1,
3612 StringHelper::GenerateCompareFlatOneByteStrings(
3613 masm, left, right, tmp1, tmp2, tmp3, kScratchRegister);
3616 // Handle more complex cases in runtime.
3618 __ PopReturnAddressTo(tmp1);
3621 __ PushReturnAddressFrom(tmp1);
3623 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3625 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3633 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3634 DCHECK(state() == CompareICState::OBJECT);
3636 Condition either_smi = masm->CheckEitherSmi(rdx, rax);
3637 __ j(either_smi, &miss, Label::kNear);
3639 __ CmpObjectType(rax, JS_OBJECT_TYPE, rcx);
3640 __ j(not_equal, &miss, Label::kNear);
3641 __ CmpObjectType(rdx, JS_OBJECT_TYPE, rcx);
3642 __ j(not_equal, &miss, Label::kNear);
3644 DCHECK(GetCondition() == equal);
3653 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3655 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3656 Condition either_smi = masm->CheckEitherSmi(rdx, rax);
3657 __ j(either_smi, &miss, Label::kNear);
3659 __ GetWeakValue(rdi, cell);
3660 __ cmpp(FieldOperand(rdx, HeapObject::kMapOffset), rdi);
3661 __ j(not_equal, &miss, Label::kNear);
3662 __ cmpp(FieldOperand(rax, HeapObject::kMapOffset), rdi);
3663 __ j(not_equal, &miss, Label::kNear);
3665 if (Token::IsEqualityOp(op())) {
3668 } else if (is_strong(strength())) {
3669 __ TailCallRuntime(Runtime::kThrowStrongModeImplicitConversion, 0, 1);
3671 __ PopReturnAddressTo(rcx);
3674 __ Push(Smi::FromInt(NegativeComparisonResult(GetCondition())));
3675 __ PushReturnAddressFrom(rcx);
3676 __ TailCallRuntime(Runtime::kCompare, 3, 1);
3684 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3686 // Call the runtime system in a fresh internal frame.
3687 FrameScope scope(masm, StackFrame::INTERNAL);
3692 __ Push(Smi::FromInt(op()));
3693 __ CallRuntime(Runtime::kCompareIC_Miss, 3);
3695 // Compute the entry point of the rewritten stub.
3696 __ leap(rdi, FieldOperand(rax, Code::kHeaderSize));
3701 // Do a tail call to the rewritten stub.
3706 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3709 Register properties,
3712 DCHECK(name->IsUniqueName());
3713 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3714 // not equal to the name and kProbes-th slot is not used (its name is the
3715 // undefined value), it guarantees the hash table doesn't contain the
3716 // property. It's true even if some slots represent deleted properties
3717 // (their names are the hole value).
3718 for (int i = 0; i < kInlinedProbes; i++) {
3719 // r0 points to properties hash.
3720 // Compute the masked index: (hash + i + i * i) & mask.
3721 Register index = r0;
3722 // Capacity is smi 2^n.
3723 __ SmiToInteger32(index, FieldOperand(properties, kCapacityOffset));
3726 Immediate(name->Hash() + NameDictionary::GetProbeOffset(i)));
3728 // Scale the index by multiplying by the entry size.
3729 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3730 __ leap(index, Operand(index, index, times_2, 0)); // index *= 3.
3732 Register entity_name = r0;
3733 // Having undefined at this place means the name is not contained.
3734 STATIC_ASSERT(kSmiTagSize == 1);
3735 __ movp(entity_name, Operand(properties,
3738 kElementsStartOffset - kHeapObjectTag));
3739 __ Cmp(entity_name, masm->isolate()->factory()->undefined_value());
3742 // Stop if found the property.
3743 __ Cmp(entity_name, Handle<Name>(name));
3747 // Check for the hole and skip.
3748 __ CompareRoot(entity_name, Heap::kTheHoleValueRootIndex);
3749 __ j(equal, &good, Label::kNear);
3751 // Check if the entry name is not a unique name.
3752 __ movp(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset));
3753 __ JumpIfNotUniqueNameInstanceType(
3754 FieldOperand(entity_name, Map::kInstanceTypeOffset), miss);
3758 NameDictionaryLookupStub stub(masm->isolate(), properties, r0, r0,
3760 __ Push(Handle<Object>(name));
3761 __ Push(Immediate(name->Hash()));
3764 __ j(not_zero, miss);
3769 // Probe the name dictionary in the |elements| register. Jump to the
3770 // |done| label if a property with the given name is found leaving the
3771 // index into the dictionary in |r1|. Jump to the |miss| label
3773 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3780 DCHECK(!elements.is(r0));
3781 DCHECK(!elements.is(r1));
3782 DCHECK(!name.is(r0));
3783 DCHECK(!name.is(r1));
3785 __ AssertName(name);
3787 __ SmiToInteger32(r0, FieldOperand(elements, kCapacityOffset));
3790 for (int i = 0; i < kInlinedProbes; i++) {
3791 // Compute the masked index: (hash + i + i * i) & mask.
3792 __ movl(r1, FieldOperand(name, Name::kHashFieldOffset));
3793 __ shrl(r1, Immediate(Name::kHashShift));
3795 __ addl(r1, Immediate(NameDictionary::GetProbeOffset(i)));
3799 // Scale the index by multiplying by the entry size.
3800 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3801 __ leap(r1, Operand(r1, r1, times_2, 0)); // r1 = r1 * 3
3803 // Check if the key is identical to the name.
3804 __ cmpp(name, Operand(elements, r1, times_pointer_size,
3805 kElementsStartOffset - kHeapObjectTag));
3809 NameDictionaryLookupStub stub(masm->isolate(), elements, r0, r1,
3812 __ movl(r0, FieldOperand(name, Name::kHashFieldOffset));
3813 __ shrl(r0, Immediate(Name::kHashShift));
3823 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
3824 // This stub overrides SometimesSetsUpAFrame() to return false. That means
3825 // we cannot call anything that could cause a GC from this stub.
3826 // Stack frame on entry:
3827 // rsp[0 * kPointerSize] : return address.
3828 // rsp[1 * kPointerSize] : key's hash.
3829 // rsp[2 * kPointerSize] : key.
3831 // dictionary_: NameDictionary to probe.
3832 // result_: used as scratch.
3833 // index_: will hold an index of entry if lookup is successful.
3834 // might alias with result_.
3836 // result_ is zero if lookup failed, non zero otherwise.
3838 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
3840 Register scratch = result();
3842 __ SmiToInteger32(scratch, FieldOperand(dictionary(), kCapacityOffset));
3846 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3847 // not equal to the name and kProbes-th slot is not used (its name is the
3848 // undefined value), it guarantees the hash table doesn't contain the
3849 // property. It's true even if some slots represent deleted properties
3850 // (their names are the null value).
3851 StackArgumentsAccessor args(rsp, 2, ARGUMENTS_DONT_CONTAIN_RECEIVER,
3853 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
3854 // Compute the masked index: (hash + i + i * i) & mask.
3855 __ movp(scratch, args.GetArgumentOperand(1));
3857 __ addl(scratch, Immediate(NameDictionary::GetProbeOffset(i)));
3859 __ andp(scratch, Operand(rsp, 0));
3861 // Scale the index by multiplying by the entry size.
3862 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3863 __ leap(index(), Operand(scratch, scratch, times_2, 0)); // index *= 3.
3865 // Having undefined at this place means the name is not contained.
3866 __ movp(scratch, Operand(dictionary(), index(), times_pointer_size,
3867 kElementsStartOffset - kHeapObjectTag));
3869 __ Cmp(scratch, isolate()->factory()->undefined_value());
3870 __ j(equal, ¬_in_dictionary);
3872 // Stop if found the property.
3873 __ cmpp(scratch, args.GetArgumentOperand(0));
3874 __ j(equal, &in_dictionary);
3876 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
3877 // If we hit a key that is not a unique name during negative
3878 // lookup we have to bailout as this key might be equal to the
3879 // key we are looking for.
3881 // Check if the entry name is not a unique name.
3882 __ movp(scratch, FieldOperand(scratch, HeapObject::kMapOffset));
3883 __ JumpIfNotUniqueNameInstanceType(
3884 FieldOperand(scratch, Map::kInstanceTypeOffset),
3885 &maybe_in_dictionary);
3889 __ bind(&maybe_in_dictionary);
3890 // If we are doing negative lookup then probing failure should be
3891 // treated as a lookup success. For positive lookup probing failure
3892 // should be treated as lookup failure.
3893 if (mode() == POSITIVE_LOOKUP) {
3894 __ movp(scratch, Immediate(0));
3896 __ ret(2 * kPointerSize);
3899 __ bind(&in_dictionary);
3900 __ movp(scratch, Immediate(1));
3902 __ ret(2 * kPointerSize);
3904 __ bind(¬_in_dictionary);
3905 __ movp(scratch, Immediate(0));
3907 __ ret(2 * kPointerSize);
3911 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
3913 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
3915 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
3920 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
3921 // the value has just been written into the object, now this stub makes sure
3922 // we keep the GC informed. The word in the object where the value has been
3923 // written is in the address register.
3924 void RecordWriteStub::Generate(MacroAssembler* masm) {
3925 Label skip_to_incremental_noncompacting;
3926 Label skip_to_incremental_compacting;
3928 // The first two instructions are generated with labels so as to get the
3929 // offset fixed up correctly by the bind(Label*) call. We patch it back and
3930 // forth between a compare instructions (a nop in this position) and the
3931 // real branch when we start and stop incremental heap marking.
3932 // See RecordWriteStub::Patch for details.
3933 __ jmp(&skip_to_incremental_noncompacting, Label::kNear);
3934 __ jmp(&skip_to_incremental_compacting, Label::kFar);
3936 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3937 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
3938 MacroAssembler::kReturnAtEnd);
3943 __ bind(&skip_to_incremental_noncompacting);
3944 GenerateIncremental(masm, INCREMENTAL);
3946 __ bind(&skip_to_incremental_compacting);
3947 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
3949 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
3950 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
3951 masm->set_byte_at(0, kTwoByteNopInstruction);
3952 masm->set_byte_at(2, kFiveByteNopInstruction);
3956 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
3959 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3960 Label dont_need_remembered_set;
3962 __ movp(regs_.scratch0(), Operand(regs_.address(), 0));
3963 __ JumpIfNotInNewSpace(regs_.scratch0(),
3965 &dont_need_remembered_set);
3967 __ CheckPageFlag(regs_.object(),
3969 1 << MemoryChunk::SCAN_ON_SCAVENGE,
3971 &dont_need_remembered_set);
3973 // First notify the incremental marker if necessary, then update the
3975 CheckNeedsToInformIncrementalMarker(
3976 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
3977 InformIncrementalMarker(masm);
3978 regs_.Restore(masm);
3979 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
3980 MacroAssembler::kReturnAtEnd);
3982 __ bind(&dont_need_remembered_set);
3985 CheckNeedsToInformIncrementalMarker(
3986 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
3987 InformIncrementalMarker(masm);
3988 regs_.Restore(masm);
3993 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
3994 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
3996 arg_reg_1.is(regs_.address()) ? kScratchRegister : regs_.address();
3997 DCHECK(!address.is(regs_.object()));
3998 DCHECK(!address.is(arg_reg_1));
3999 __ Move(address, regs_.address());
4000 __ Move(arg_reg_1, regs_.object());
4001 // TODO(gc) Can we just set address arg2 in the beginning?
4002 __ Move(arg_reg_2, address);
4003 __ LoadAddress(arg_reg_3,
4004 ExternalReference::isolate_address(isolate()));
4005 int argument_count = 3;
4007 AllowExternalCallThatCantCauseGC scope(masm);
4008 __ PrepareCallCFunction(argument_count);
4010 ExternalReference::incremental_marking_record_write_function(isolate()),
4012 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4016 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4017 MacroAssembler* masm,
4018 OnNoNeedToInformIncrementalMarker on_no_need,
4021 Label need_incremental;
4022 Label need_incremental_pop_object;
4024 __ movp(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask));
4025 __ andp(regs_.scratch0(), regs_.object());
4026 __ movp(regs_.scratch1(),
4027 Operand(regs_.scratch0(),
4028 MemoryChunk::kWriteBarrierCounterOffset));
4029 __ subp(regs_.scratch1(), Immediate(1));
4030 __ movp(Operand(regs_.scratch0(),
4031 MemoryChunk::kWriteBarrierCounterOffset),
4033 __ j(negative, &need_incremental);
4035 // Let's look at the color of the object: If it is not black we don't have
4036 // to inform the incremental marker.
4037 __ JumpIfBlack(regs_.object(),
4043 regs_.Restore(masm);
4044 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4045 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4046 MacroAssembler::kReturnAtEnd);
4053 // Get the value from the slot.
4054 __ movp(regs_.scratch0(), Operand(regs_.address(), 0));
4056 if (mode == INCREMENTAL_COMPACTION) {
4057 Label ensure_not_white;
4059 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4060 regs_.scratch1(), // Scratch.
4061 MemoryChunk::kEvacuationCandidateMask,
4066 __ CheckPageFlag(regs_.object(),
4067 regs_.scratch1(), // Scratch.
4068 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4072 __ bind(&ensure_not_white);
4075 // We need an extra register for this, so we push the object register
4077 __ Push(regs_.object());
4078 __ EnsureNotWhite(regs_.scratch0(), // The value.
4079 regs_.scratch1(), // Scratch.
4080 regs_.object(), // Scratch.
4081 &need_incremental_pop_object,
4083 __ Pop(regs_.object());
4085 regs_.Restore(masm);
4086 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4087 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4088 MacroAssembler::kReturnAtEnd);
4093 __ bind(&need_incremental_pop_object);
4094 __ Pop(regs_.object());
4096 __ bind(&need_incremental);
4098 // Fall through when we need to inform the incremental marker.
4102 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4103 // ----------- S t a t e -------------
4104 // -- rax : element value to store
4105 // -- rcx : element index as smi
4106 // -- rsp[0] : return address
4107 // -- rsp[8] : array literal index in function
4108 // -- rsp[16] : array literal
4109 // clobbers rbx, rdx, rdi
4110 // -----------------------------------
4113 Label double_elements;
4115 Label slow_elements;
4116 Label fast_elements;
4118 // Get array literal index, array literal and its map.
4119 StackArgumentsAccessor args(rsp, 2, ARGUMENTS_DONT_CONTAIN_RECEIVER);
4120 __ movp(rdx, args.GetArgumentOperand(1));
4121 __ movp(rbx, args.GetArgumentOperand(0));
4122 __ movp(rdi, FieldOperand(rbx, JSObject::kMapOffset));
4124 __ CheckFastElements(rdi, &double_elements);
4126 // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS
4127 __ JumpIfSmi(rax, &smi_element);
4128 __ CheckFastSmiElements(rdi, &fast_elements);
4130 // Store into the array literal requires a elements transition. Call into
4133 __ bind(&slow_elements);
4134 __ PopReturnAddressTo(rdi);
4138 __ movp(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
4139 __ Push(FieldOperand(rbx, JSFunction::kLiteralsOffset));
4141 __ PushReturnAddressFrom(rdi);
4142 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4144 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4145 __ bind(&fast_elements);
4146 __ SmiToInteger32(kScratchRegister, rcx);
4147 __ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset));
4148 __ leap(rcx, FieldOperand(rbx, kScratchRegister, times_pointer_size,
4149 FixedArrayBase::kHeaderSize));
4150 __ movp(Operand(rcx, 0), rax);
4151 // Update the write barrier for the array store.
4152 __ RecordWrite(rbx, rcx, rax,
4154 EMIT_REMEMBERED_SET,
4158 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or
4159 // FAST_*_ELEMENTS, and value is Smi.
4160 __ bind(&smi_element);
4161 __ SmiToInteger32(kScratchRegister, rcx);
4162 __ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset));
4163 __ movp(FieldOperand(rbx, kScratchRegister, times_pointer_size,
4164 FixedArrayBase::kHeaderSize), rax);
4167 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
4168 __ bind(&double_elements);
4170 __ movp(r9, FieldOperand(rbx, JSObject::kElementsOffset));
4171 __ SmiToInteger32(r11, rcx);
4172 __ StoreNumberToDoubleElements(rax,
4181 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4182 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4183 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4184 int parameter_count_offset =
4185 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4186 __ movp(rbx, MemOperand(rbp, parameter_count_offset));
4187 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4188 __ PopReturnAddressTo(rcx);
4189 int additional_offset =
4190 function_mode() == JS_FUNCTION_STUB_MODE ? kPointerSize : 0;
4191 __ leap(rsp, MemOperand(rsp, rbx, times_pointer_size, additional_offset));
4192 __ jmp(rcx); // Return to IC Miss stub, continuation still on stack.
4196 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4197 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4198 LoadICStub stub(isolate(), state());
4199 stub.GenerateForTrampoline(masm);
4203 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4204 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4205 KeyedLoadICStub stub(isolate(), state());
4206 stub.GenerateForTrampoline(masm);
4210 static void HandleArrayCases(MacroAssembler* masm, Register feedback,
4211 Register receiver_map, Register scratch1,
4212 Register scratch2, Register scratch3,
4213 bool is_polymorphic, Label* miss) {
4214 // feedback initially contains the feedback array
4215 Label next_loop, prepare_next;
4216 Label start_polymorphic;
4218 Register counter = scratch1;
4219 Register length = scratch2;
4220 Register cached_map = scratch3;
4222 __ movp(cached_map, FieldOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4223 __ cmpp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4224 __ j(not_equal, &start_polymorphic);
4226 // found, now call handler.
4227 Register handler = feedback;
4228 __ movp(handler, FieldOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4229 __ leap(handler, FieldOperand(handler, Code::kHeaderSize));
4232 // Polymorphic, we have to loop from 2 to N
4233 __ bind(&start_polymorphic);
4234 __ SmiToInteger32(length, FieldOperand(feedback, FixedArray::kLengthOffset));
4235 if (!is_polymorphic) {
4236 // If the IC could be monomorphic we have to make sure we don't go past the
4237 // end of the feedback array.
4238 __ cmpl(length, Immediate(2));
4241 __ movl(counter, Immediate(2));
4243 __ bind(&next_loop);
4244 __ movp(cached_map, FieldOperand(feedback, counter, times_pointer_size,
4245 FixedArray::kHeaderSize));
4246 __ cmpp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4247 __ j(not_equal, &prepare_next);
4248 __ movp(handler, FieldOperand(feedback, counter, times_pointer_size,
4249 FixedArray::kHeaderSize + kPointerSize));
4250 __ leap(handler, FieldOperand(handler, Code::kHeaderSize));
4253 __ bind(&prepare_next);
4254 __ addl(counter, Immediate(2));
4255 __ cmpl(counter, length);
4256 __ j(less, &next_loop);
4258 // We exhausted our array of map handler pairs.
4263 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4264 Register receiver_map, Register feedback,
4265 Register vector, Register integer_slot,
4266 Label* compare_map, Label* load_smi_map,
4268 __ JumpIfSmi(receiver, load_smi_map);
4269 __ movp(receiver_map, FieldOperand(receiver, 0));
4271 __ bind(compare_map);
4272 __ cmpp(receiver_map, FieldOperand(feedback, WeakCell::kValueOffset));
4273 __ j(not_equal, try_array);
4274 Register handler = feedback;
4275 __ movp(handler, FieldOperand(vector, integer_slot, times_pointer_size,
4276 FixedArray::kHeaderSize + kPointerSize));
4277 __ leap(handler, FieldOperand(handler, Code::kHeaderSize));
4282 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4285 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4286 GenerateImpl(masm, true);
4290 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4291 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // rdx
4292 Register name = LoadWithVectorDescriptor::NameRegister(); // rcx
4293 Register vector = LoadWithVectorDescriptor::VectorRegister(); // rbx
4294 Register slot = LoadWithVectorDescriptor::SlotRegister(); // rax
4295 Register feedback = rdi;
4296 Register integer_slot = r8;
4297 Register receiver_map = r9;
4299 __ SmiToInteger32(integer_slot, slot);
4300 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4301 FixedArray::kHeaderSize));
4303 // Try to quickly handle the monomorphic case without knowing for sure
4304 // if we have a weak cell in feedback. We do know it's safe to look
4305 // at WeakCell::kValueOffset.
4306 Label try_array, load_smi_map, compare_map;
4307 Label not_array, miss;
4308 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector,
4309 integer_slot, &compare_map, &load_smi_map, &try_array);
4311 // Is it a fixed array?
4312 __ bind(&try_array);
4313 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex);
4314 __ j(not_equal, ¬_array);
4315 HandleArrayCases(masm, feedback, receiver_map, integer_slot, r11, r15, true,
4318 __ bind(¬_array);
4319 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4320 __ j(not_equal, &miss);
4321 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4322 Code::ComputeHandlerFlags(Code::LOAD_IC));
4323 masm->isolate()->stub_cache()->GenerateProbe(
4324 masm, Code::LOAD_IC, code_flags, receiver, name, feedback, no_reg);
4327 LoadIC::GenerateMiss(masm, LoadIC::kStressDispatcher);
4329 __ bind(&load_smi_map);
4330 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4331 __ jmp(&compare_map);
4335 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4336 GenerateImpl(masm, false);
4340 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4341 GenerateImpl(masm, true);
4345 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4346 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // rdx
4347 Register key = LoadWithVectorDescriptor::NameRegister(); // rcx
4348 Register vector = LoadWithVectorDescriptor::VectorRegister(); // rbx
4349 Register slot = LoadWithVectorDescriptor::SlotRegister(); // rax
4350 Register feedback = rdi;
4351 Register integer_slot = r8;
4352 Register receiver_map = r9;
4354 __ SmiToInteger32(integer_slot, slot);
4355 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4356 FixedArray::kHeaderSize));
4358 // Try to quickly handle the monomorphic case without knowing for sure
4359 // if we have a weak cell in feedback. We do know it's safe to look
4360 // at WeakCell::kValueOffset.
4361 Label try_array, load_smi_map, compare_map;
4362 Label not_array, miss;
4363 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector,
4364 integer_slot, &compare_map, &load_smi_map, &try_array);
4366 __ bind(&try_array);
4367 // Is it a fixed array?
4368 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex);
4369 __ j(not_equal, ¬_array);
4371 // We have a polymorphic element handler.
4372 Label polymorphic, try_poly_name;
4373 __ bind(&polymorphic);
4374 HandleArrayCases(masm, feedback, receiver_map, integer_slot, r11, r15, true,
4377 __ bind(¬_array);
4379 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4380 __ j(not_equal, &try_poly_name);
4381 Handle<Code> megamorphic_stub =
4382 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4383 __ jmp(megamorphic_stub, RelocInfo::CODE_TARGET);
4385 __ bind(&try_poly_name);
4386 // We might have a name in feedback, and a fixed array in the next slot.
4387 __ cmpp(key, feedback);
4388 __ j(not_equal, &miss);
4389 // If the name comparison succeeded, we know we have a fixed array with
4390 // at least one map/handler pair.
4391 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4392 FixedArray::kHeaderSize + kPointerSize));
4393 HandleArrayCases(masm, feedback, receiver_map, integer_slot, r11, r15, false,
4397 KeyedLoadIC::GenerateMiss(masm);
4399 __ bind(&load_smi_map);
4400 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4401 __ jmp(&compare_map);
4405 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4406 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4407 VectorStoreICStub stub(isolate(), state());
4408 stub.GenerateForTrampoline(masm);
4412 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4413 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4414 VectorKeyedStoreICStub stub(isolate(), state());
4415 stub.GenerateForTrampoline(masm);
4419 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4420 GenerateImpl(masm, false);
4424 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4425 GenerateImpl(masm, true);
4429 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4430 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // rdx
4431 Register key = VectorStoreICDescriptor::NameRegister(); // rcx
4432 Register vector = VectorStoreICDescriptor::VectorRegister(); // rbx
4433 Register slot = VectorStoreICDescriptor::SlotRegister(); // rdi
4434 DCHECK(VectorStoreICDescriptor::ValueRegister().is(rax)); // rax
4435 Register feedback = r8;
4436 Register integer_slot = r9;
4437 Register receiver_map = r11;
4438 DCHECK(!AreAliased(feedback, integer_slot, vector, slot, receiver_map));
4440 __ SmiToInteger32(integer_slot, slot);
4441 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4442 FixedArray::kHeaderSize));
4444 // Try to quickly handle the monomorphic case without knowing for sure
4445 // if we have a weak cell in feedback. We do know it's safe to look
4446 // at WeakCell::kValueOffset.
4447 Label try_array, load_smi_map, compare_map;
4448 Label not_array, miss;
4449 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector,
4450 integer_slot, &compare_map, &load_smi_map, &try_array);
4452 // Is it a fixed array?
4453 __ bind(&try_array);
4454 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex);
4455 __ j(not_equal, ¬_array);
4456 HandleArrayCases(masm, feedback, receiver_map, integer_slot, r14, r15, true,
4459 __ bind(¬_array);
4460 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4461 __ j(not_equal, &miss);
4463 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4464 Code::ComputeHandlerFlags(Code::STORE_IC));
4465 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::STORE_IC, code_flags,
4466 receiver, key, feedback, no_reg);
4469 StoreIC::GenerateMiss(masm);
4471 __ bind(&load_smi_map);
4472 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4473 __ jmp(&compare_map);
4477 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4478 GenerateImpl(masm, false);
4482 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4483 GenerateImpl(masm, true);
4487 static void HandlePolymorphicKeyedStoreCase(MacroAssembler* masm,
4488 Register receiver_map,
4489 Register feedback, Register scratch,
4491 Register scratch2, Label* miss) {
4492 // feedback initially contains the feedback array
4493 Label next, next_loop, prepare_next;
4494 Label transition_call;
4496 Register cached_map = scratch;
4497 Register counter = scratch1;
4498 Register length = scratch2;
4500 // Polymorphic, we have to loop from 0 to N - 1
4501 __ movp(counter, Immediate(0));
4502 __ movp(length, FieldOperand(feedback, FixedArray::kLengthOffset));
4503 __ SmiToInteger32(length, length);
4505 __ bind(&next_loop);
4506 __ movp(cached_map, FieldOperand(feedback, counter, times_pointer_size,
4507 FixedArray::kHeaderSize));
4508 __ cmpp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4509 __ j(not_equal, &prepare_next);
4510 __ movp(cached_map, FieldOperand(feedback, counter, times_pointer_size,
4511 FixedArray::kHeaderSize + kPointerSize));
4512 __ CompareRoot(cached_map, Heap::kUndefinedValueRootIndex);
4513 __ j(not_equal, &transition_call);
4514 __ movp(feedback, FieldOperand(feedback, counter, times_pointer_size,
4515 FixedArray::kHeaderSize + 2 * kPointerSize));
4516 __ leap(feedback, FieldOperand(feedback, Code::kHeaderSize));
4519 __ bind(&transition_call);
4520 DCHECK(receiver_map.is(VectorStoreTransitionDescriptor::MapRegister()));
4521 __ movp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4522 // The weak cell may have been cleared.
4523 __ JumpIfSmi(receiver_map, miss);
4524 // Get the handler in value.
4525 __ movp(feedback, FieldOperand(feedback, counter, times_pointer_size,
4526 FixedArray::kHeaderSize + 2 * kPointerSize));
4527 __ leap(feedback, FieldOperand(feedback, Code::kHeaderSize));
4530 __ bind(&prepare_next);
4531 __ addl(counter, Immediate(3));
4532 __ cmpl(counter, length);
4533 __ j(less, &next_loop);
4535 // We exhausted our array of map handler pairs.
4540 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4541 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // rdx
4542 Register key = VectorStoreICDescriptor::NameRegister(); // rcx
4543 Register vector = VectorStoreICDescriptor::VectorRegister(); // rbx
4544 Register slot = VectorStoreICDescriptor::SlotRegister(); // rdi
4545 DCHECK(VectorStoreICDescriptor::ValueRegister().is(rax)); // rax
4546 Register feedback = r8;
4547 Register integer_slot = r9;
4548 Register receiver_map = r11;
4549 DCHECK(!AreAliased(feedback, integer_slot, vector, slot, receiver_map));
4551 __ SmiToInteger32(integer_slot, slot);
4552 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4553 FixedArray::kHeaderSize));
4555 // Try to quickly handle the monomorphic case without knowing for sure
4556 // if we have a weak cell in feedback. We do know it's safe to look
4557 // at WeakCell::kValueOffset.
4558 Label try_array, load_smi_map, compare_map;
4559 Label not_array, miss;
4560 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector,
4561 integer_slot, &compare_map, &load_smi_map, &try_array);
4563 // Is it a fixed array?
4564 __ bind(&try_array);
4565 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex);
4566 __ j(not_equal, ¬_array);
4567 HandlePolymorphicKeyedStoreCase(masm, receiver_map, feedback, integer_slot,
4570 __ bind(¬_array);
4571 Label try_poly_name;
4572 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4573 __ j(not_equal, &try_poly_name);
4575 Handle<Code> megamorphic_stub =
4576 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4577 __ jmp(megamorphic_stub, RelocInfo::CODE_TARGET);
4579 __ bind(&try_poly_name);
4580 // We might have a name in feedback, and a fixed array in the next slot.
4581 __ cmpp(key, feedback);
4582 __ j(not_equal, &miss);
4583 // If the name comparison succeeded, we know we have a fixed array with
4584 // at least one map/handler pair.
4585 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4586 FixedArray::kHeaderSize + kPointerSize));
4587 HandleArrayCases(masm, feedback, receiver_map, integer_slot, r14, r15, false,
4591 KeyedStoreIC::GenerateMiss(masm);
4593 __ bind(&load_smi_map);
4594 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4595 __ jmp(&compare_map);
4599 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4600 EmitLoadTypeFeedbackVector(masm, rbx);
4601 CallICStub stub(isolate(), state());
4602 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET);
4606 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4607 if (masm->isolate()->function_entry_hook() != NULL) {
4608 ProfileEntryHookStub stub(masm->isolate());
4609 masm->CallStub(&stub);
4614 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4615 // This stub can be called from essentially anywhere, so it needs to save
4616 // all volatile and callee-save registers.
4617 const size_t kNumSavedRegisters = 2;
4618 __ pushq(arg_reg_1);
4619 __ pushq(arg_reg_2);
4621 // Calculate the original stack pointer and store it in the second arg.
4623 Operand(rsp, kNumSavedRegisters * kRegisterSize + kPCOnStackSize));
4625 // Calculate the function address to the first arg.
4626 __ movp(arg_reg_1, Operand(rsp, kNumSavedRegisters * kRegisterSize));
4627 __ subp(arg_reg_1, Immediate(Assembler::kShortCallInstructionLength));
4629 // Save the remainder of the volatile registers.
4630 masm->PushCallerSaved(kSaveFPRegs, arg_reg_1, arg_reg_2);
4632 // Call the entry hook function.
4633 __ Move(rax, FUNCTION_ADDR(isolate()->function_entry_hook()),
4634 Assembler::RelocInfoNone());
4636 AllowExternalCallThatCantCauseGC scope(masm);
4638 const int kArgumentCount = 2;
4639 __ PrepareCallCFunction(kArgumentCount);
4640 __ CallCFunction(rax, kArgumentCount);
4642 // Restore volatile regs.
4643 masm->PopCallerSaved(kSaveFPRegs, arg_reg_1, arg_reg_2);
4652 static void CreateArrayDispatch(MacroAssembler* masm,
4653 AllocationSiteOverrideMode mode) {
4654 if (mode == DISABLE_ALLOCATION_SITES) {
4655 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4656 __ TailCallStub(&stub);
4657 } else if (mode == DONT_OVERRIDE) {
4658 int last_index = GetSequenceIndexFromFastElementsKind(
4659 TERMINAL_FAST_ELEMENTS_KIND);
4660 for (int i = 0; i <= last_index; ++i) {
4662 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4663 __ cmpl(rdx, Immediate(kind));
4664 __ j(not_equal, &next);
4665 T stub(masm->isolate(), kind);
4666 __ TailCallStub(&stub);
4670 // If we reached this point there is a problem.
4671 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4678 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4679 AllocationSiteOverrideMode mode) {
4680 // rbx - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4681 // rdx - kind (if mode != DISABLE_ALLOCATION_SITES)
4682 // rax - number of arguments
4683 // rdi - constructor?
4684 // rsp[0] - return address
4685 // rsp[8] - last argument
4686 Handle<Object> undefined_sentinel(
4687 masm->isolate()->heap()->undefined_value(),
4690 Label normal_sequence;
4691 if (mode == DONT_OVERRIDE) {
4692 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4693 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4694 STATIC_ASSERT(FAST_ELEMENTS == 2);
4695 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4696 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4697 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4699 // is the low bit set? If so, we are holey and that is good.
4700 __ testb(rdx, Immediate(1));
4701 __ j(not_zero, &normal_sequence);
4704 // look at the first argument
4705 StackArgumentsAccessor args(rsp, 1, ARGUMENTS_DONT_CONTAIN_RECEIVER);
4706 __ movp(rcx, args.GetArgumentOperand(0));
4708 __ j(zero, &normal_sequence);
4710 if (mode == DISABLE_ALLOCATION_SITES) {
4711 ElementsKind initial = GetInitialFastElementsKind();
4712 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4714 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4716 DISABLE_ALLOCATION_SITES);
4717 __ TailCallStub(&stub_holey);
4719 __ bind(&normal_sequence);
4720 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4722 DISABLE_ALLOCATION_SITES);
4723 __ TailCallStub(&stub);
4724 } else if (mode == DONT_OVERRIDE) {
4725 // We are going to create a holey array, but our kind is non-holey.
4726 // Fix kind and retry (only if we have an allocation site in the slot).
4729 if (FLAG_debug_code) {
4730 Handle<Map> allocation_site_map =
4731 masm->isolate()->factory()->allocation_site_map();
4732 __ Cmp(FieldOperand(rbx, 0), allocation_site_map);
4733 __ Assert(equal, kExpectedAllocationSite);
4736 // Save the resulting elements kind in type info. We can't just store r3
4737 // in the AllocationSite::transition_info field because elements kind is
4738 // restricted to a portion of the field...upper bits need to be left alone.
4739 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4740 __ SmiAddConstant(FieldOperand(rbx, AllocationSite::kTransitionInfoOffset),
4741 Smi::FromInt(kFastElementsKindPackedToHoley));
4743 __ bind(&normal_sequence);
4744 int last_index = GetSequenceIndexFromFastElementsKind(
4745 TERMINAL_FAST_ELEMENTS_KIND);
4746 for (int i = 0; i <= last_index; ++i) {
4748 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4749 __ cmpl(rdx, Immediate(kind));
4750 __ j(not_equal, &next);
4751 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4752 __ TailCallStub(&stub);
4756 // If we reached this point there is a problem.
4757 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4765 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4766 int to_index = GetSequenceIndexFromFastElementsKind(
4767 TERMINAL_FAST_ELEMENTS_KIND);
4768 for (int i = 0; i <= to_index; ++i) {
4769 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4770 T stub(isolate, kind);
4772 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4773 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4780 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4781 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4783 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4785 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4790 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4792 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4793 for (int i = 0; i < 2; i++) {
4794 // For internal arrays we only need a few things
4795 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4797 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4799 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4805 void ArrayConstructorStub::GenerateDispatchToArrayStub(
4806 MacroAssembler* masm,
4807 AllocationSiteOverrideMode mode) {
4808 if (argument_count() == ANY) {
4809 Label not_zero_case, not_one_case;
4811 __ j(not_zero, ¬_zero_case);
4812 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4814 __ bind(¬_zero_case);
4815 __ cmpl(rax, Immediate(1));
4816 __ j(greater, ¬_one_case);
4817 CreateArrayDispatchOneArgument(masm, mode);
4819 __ bind(¬_one_case);
4820 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4821 } else if (argument_count() == NONE) {
4822 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4823 } else if (argument_count() == ONE) {
4824 CreateArrayDispatchOneArgument(masm, mode);
4825 } else if (argument_count() == MORE_THAN_ONE) {
4826 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4833 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4834 // ----------- S t a t e -------------
4836 // -- rbx : AllocationSite or undefined
4837 // -- rdi : constructor
4838 // -- rdx : original constructor
4839 // -- rsp[0] : return address
4840 // -- rsp[8] : last argument
4841 // -----------------------------------
4842 if (FLAG_debug_code) {
4843 // The array construct code is only set for the global and natives
4844 // builtin Array functions which always have maps.
4846 // Initial map for the builtin Array function should be a map.
4847 __ movp(rcx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
4848 // Will both indicate a NULL and a Smi.
4849 STATIC_ASSERT(kSmiTag == 0);
4850 Condition not_smi = NegateCondition(masm->CheckSmi(rcx));
4851 __ Check(not_smi, kUnexpectedInitialMapForArrayFunction);
4852 __ CmpObjectType(rcx, MAP_TYPE, rcx);
4853 __ Check(equal, kUnexpectedInitialMapForArrayFunction);
4855 // We should either have undefined in rbx or a valid AllocationSite
4856 __ AssertUndefinedOrAllocationSite(rbx);
4861 __ j(not_equal, &subclassing);
4864 // If the feedback vector is the undefined value call an array constructor
4865 // that doesn't use AllocationSites.
4866 __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex);
4867 __ j(equal, &no_info);
4869 // Only look at the lower 16 bits of the transition info.
4870 __ movp(rdx, FieldOperand(rbx, AllocationSite::kTransitionInfoOffset));
4871 __ SmiToInteger32(rdx, rdx);
4872 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4873 __ andp(rdx, Immediate(AllocationSite::ElementsKindBits::kMask));
4874 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4877 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
4880 __ bind(&subclassing);
4881 __ Pop(rcx); // return address.
4886 switch (argument_count()) {
4889 __ addp(rax, Immediate(2));
4892 __ movp(rax, Immediate(2));
4895 __ movp(rax, Immediate(3));
4900 __ JumpToExternalReference(
4901 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()),
4906 void InternalArrayConstructorStub::GenerateCase(
4907 MacroAssembler* masm, ElementsKind kind) {
4908 Label not_zero_case, not_one_case;
4909 Label normal_sequence;
4912 __ j(not_zero, ¬_zero_case);
4913 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4914 __ TailCallStub(&stub0);
4916 __ bind(¬_zero_case);
4917 __ cmpl(rax, Immediate(1));
4918 __ j(greater, ¬_one_case);
4920 if (IsFastPackedElementsKind(kind)) {
4921 // We might need to create a holey array
4922 // look at the first argument
4923 StackArgumentsAccessor args(rsp, 1, ARGUMENTS_DONT_CONTAIN_RECEIVER);
4924 __ movp(rcx, args.GetArgumentOperand(0));
4926 __ j(zero, &normal_sequence);
4928 InternalArraySingleArgumentConstructorStub
4929 stub1_holey(isolate(), GetHoleyElementsKind(kind));
4930 __ TailCallStub(&stub1_holey);
4933 __ bind(&normal_sequence);
4934 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
4935 __ TailCallStub(&stub1);
4937 __ bind(¬_one_case);
4938 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
4939 __ TailCallStub(&stubN);
4943 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
4944 // ----------- S t a t e -------------
4946 // -- rdi : constructor
4947 // -- rsp[0] : return address
4948 // -- rsp[8] : last argument
4949 // -----------------------------------
4951 if (FLAG_debug_code) {
4952 // The array construct code is only set for the global and natives
4953 // builtin Array functions which always have maps.
4955 // Initial map for the builtin Array function should be a map.
4956 __ movp(rcx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
4957 // Will both indicate a NULL and a Smi.
4958 STATIC_ASSERT(kSmiTag == 0);
4959 Condition not_smi = NegateCondition(masm->CheckSmi(rcx));
4960 __ Check(not_smi, kUnexpectedInitialMapForArrayFunction);
4961 __ CmpObjectType(rcx, MAP_TYPE, rcx);
4962 __ Check(equal, kUnexpectedInitialMapForArrayFunction);
4965 // Figure out the right elements kind
4966 __ movp(rcx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
4968 // Load the map's "bit field 2" into |result|. We only need the first byte,
4969 // but the following masking takes care of that anyway.
4970 __ movzxbp(rcx, FieldOperand(rcx, Map::kBitField2Offset));
4971 // Retrieve elements_kind from bit field 2.
4972 __ DecodeField<Map::ElementsKindBits>(rcx);
4974 if (FLAG_debug_code) {
4976 __ cmpl(rcx, Immediate(FAST_ELEMENTS));
4978 __ cmpl(rcx, Immediate(FAST_HOLEY_ELEMENTS));
4980 kInvalidElementsKindForInternalArrayOrInternalPackedArray);
4984 Label fast_elements_case;
4985 __ cmpl(rcx, Immediate(FAST_ELEMENTS));
4986 __ j(equal, &fast_elements_case);
4987 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
4989 __ bind(&fast_elements_case);
4990 GenerateCase(masm, FAST_ELEMENTS);
4994 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
4995 Register context_reg = rsi;
4996 Register slot_reg = rbx;
4997 Register result_reg = rax;
5000 // Go up context chain to the script context.
5001 for (int i = 0; i < depth(); ++i) {
5002 __ movp(rdi, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5006 // Load the PropertyCell value at the specified slot.
5007 __ movp(result_reg, ContextOperand(context_reg, slot_reg));
5008 __ movp(result_reg, FieldOperand(result_reg, PropertyCell::kValueOffset));
5010 // Check that value is not the_hole.
5011 __ CompareRoot(result_reg, Heap::kTheHoleValueRootIndex);
5012 __ j(equal, &slow_case, Label::kNear);
5015 // Fallback to the runtime.
5016 __ bind(&slow_case);
5017 __ Integer32ToSmi(slot_reg, slot_reg);
5018 __ PopReturnAddressTo(kScratchRegister);
5020 __ Push(kScratchRegister);
5021 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5025 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5026 Register context_reg = rsi;
5027 Register slot_reg = rbx;
5028 Register value_reg = rax;
5029 Register cell_reg = r8;
5030 Register cell_details_reg = rdx;
5031 Register cell_value_reg = r9;
5032 Label fast_heapobject_case, fast_smi_case, slow_case;
5034 if (FLAG_debug_code) {
5035 __ CompareRoot(value_reg, Heap::kTheHoleValueRootIndex);
5036 __ Check(not_equal, kUnexpectedValue);
5039 // Go up context chain to the script context.
5040 for (int i = 0; i < depth(); ++i) {
5041 __ movp(rdi, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5045 // Load the PropertyCell at the specified slot.
5046 __ movp(cell_reg, ContextOperand(context_reg, slot_reg));
5048 // Load PropertyDetails for the cell (actually only the cell_type, kind and
5049 // READ_ONLY bit of attributes).
5050 __ SmiToInteger32(cell_details_reg,
5051 FieldOperand(cell_reg, PropertyCell::kDetailsOffset));
5052 __ andl(cell_details_reg,
5053 Immediate(PropertyDetails::PropertyCellTypeField::kMask |
5054 PropertyDetails::KindField::kMask |
5055 PropertyDetails::kAttributesReadOnlyMask));
5057 // Check if PropertyCell holds mutable data.
5058 Label not_mutable_data;
5059 __ cmpl(cell_details_reg,
5060 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5061 PropertyCellType::kMutable) |
5062 PropertyDetails::KindField::encode(kData)));
5063 __ j(not_equal, ¬_mutable_data);
5064 __ JumpIfSmi(value_reg, &fast_smi_case);
5065 __ bind(&fast_heapobject_case);
5066 __ movp(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg);
5067 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg,
5068 cell_value_reg, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5070 // RecordWriteField clobbers the value register, so we need to reload.
5071 __ movp(value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset));
5073 __ bind(¬_mutable_data);
5075 // Check if PropertyCell value matches the new value (relevant for Constant,
5076 // ConstantType and Undefined cells).
5077 Label not_same_value;
5078 __ movp(cell_value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset));
5079 __ cmpp(cell_value_reg, value_reg);
5080 __ j(not_equal, ¬_same_value,
5081 FLAG_debug_code ? Label::kFar : Label::kNear);
5082 // Make sure the PropertyCell is not marked READ_ONLY.
5083 __ testl(cell_details_reg,
5084 Immediate(PropertyDetails::kAttributesReadOnlyMask));
5085 __ j(not_zero, &slow_case);
5086 if (FLAG_debug_code) {
5088 // This can only be true for Constant, ConstantType and Undefined cells,
5089 // because we never store the_hole via this stub.
5090 __ cmpl(cell_details_reg,
5091 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5092 PropertyCellType::kConstant) |
5093 PropertyDetails::KindField::encode(kData)));
5095 __ cmpl(cell_details_reg,
5096 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5097 PropertyCellType::kConstantType) |
5098 PropertyDetails::KindField::encode(kData)));
5100 __ cmpl(cell_details_reg,
5101 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5102 PropertyCellType::kUndefined) |
5103 PropertyDetails::KindField::encode(kData)));
5104 __ Check(equal, kUnexpectedValue);
5108 __ bind(¬_same_value);
5110 // Check if PropertyCell contains data with constant type (and is not
5112 __ cmpl(cell_details_reg,
5113 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5114 PropertyCellType::kConstantType) |
5115 PropertyDetails::KindField::encode(kData)));
5116 __ j(not_equal, &slow_case, Label::kNear);
5118 // Now either both old and new values must be SMIs or both must be heap
5119 // objects with same map.
5120 Label value_is_heap_object;
5121 __ JumpIfNotSmi(value_reg, &value_is_heap_object, Label::kNear);
5122 __ JumpIfNotSmi(cell_value_reg, &slow_case, Label::kNear);
5123 // Old and new values are SMIs, no need for a write barrier here.
5124 __ bind(&fast_smi_case);
5125 __ movp(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg);
5127 __ bind(&value_is_heap_object);
5128 __ JumpIfSmi(cell_value_reg, &slow_case, Label::kNear);
5129 Register cell_value_map_reg = cell_value_reg;
5130 __ movp(cell_value_map_reg,
5131 FieldOperand(cell_value_reg, HeapObject::kMapOffset));
5132 __ cmpp(cell_value_map_reg, FieldOperand(value_reg, HeapObject::kMapOffset));
5133 __ j(equal, &fast_heapobject_case);
5135 // Fallback to the runtime.
5136 __ bind(&slow_case);
5137 __ Integer32ToSmi(slot_reg, slot_reg);
5138 __ PopReturnAddressTo(kScratchRegister);
5141 __ Push(kScratchRegister);
5142 __ TailCallRuntime(is_strict(language_mode())
5143 ? Runtime::kStoreGlobalViaContext_Strict
5144 : Runtime::kStoreGlobalViaContext_Sloppy,
5149 static int Offset(ExternalReference ref0, ExternalReference ref1) {
5150 int64_t offset = (ref0.address() - ref1.address());
5151 // Check that fits into int.
5152 DCHECK(static_cast<int>(offset) == offset);
5153 return static_cast<int>(offset);
5157 // Prepares stack to put arguments (aligns and so on). WIN64 calling
5158 // convention requires to put the pointer to the return value slot into
5159 // rcx (rcx must be preserverd until CallApiFunctionAndReturn). Saves
5160 // context (rsi). Clobbers rax. Allocates arg_stack_space * kPointerSize
5161 // inside the exit frame (not GCed) accessible via StackSpaceOperand.
5162 static void PrepareCallApiFunction(MacroAssembler* masm, int arg_stack_space) {
5163 __ EnterApiExitFrame(arg_stack_space);
5167 // Calls an API function. Allocates HandleScope, extracts returned value
5168 // from handle and propagates exceptions. Clobbers r14, r15, rbx and
5169 // caller-save registers. Restores context. On return removes
5170 // stack_space * kPointerSize (GCed).
5171 static void CallApiFunctionAndReturn(MacroAssembler* masm,
5172 Register function_address,
5173 ExternalReference thunk_ref,
5174 Register thunk_last_arg, int stack_space,
5175 Operand* stack_space_operand,
5176 Operand return_value_operand,
5177 Operand* context_restore_operand) {
5179 Label promote_scheduled_exception;
5180 Label delete_allocated_handles;
5181 Label leave_exit_frame;
5184 Isolate* isolate = masm->isolate();
5185 Factory* factory = isolate->factory();
5186 ExternalReference next_address =
5187 ExternalReference::handle_scope_next_address(isolate);
5188 const int kNextOffset = 0;
5189 const int kLimitOffset = Offset(
5190 ExternalReference::handle_scope_limit_address(isolate), next_address);
5191 const int kLevelOffset = Offset(
5192 ExternalReference::handle_scope_level_address(isolate), next_address);
5193 ExternalReference scheduled_exception_address =
5194 ExternalReference::scheduled_exception_address(isolate);
5196 DCHECK(rdx.is(function_address) || r8.is(function_address));
5197 // Allocate HandleScope in callee-save registers.
5198 Register prev_next_address_reg = r14;
5199 Register prev_limit_reg = rbx;
5200 Register base_reg = r15;
5201 __ Move(base_reg, next_address);
5202 __ movp(prev_next_address_reg, Operand(base_reg, kNextOffset));
5203 __ movp(prev_limit_reg, Operand(base_reg, kLimitOffset));
5204 __ addl(Operand(base_reg, kLevelOffset), Immediate(1));
5206 if (FLAG_log_timer_events) {
5207 FrameScope frame(masm, StackFrame::MANUAL);
5208 __ PushSafepointRegisters();
5209 __ PrepareCallCFunction(1);
5210 __ LoadAddress(arg_reg_1, ExternalReference::isolate_address(isolate));
5211 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5213 __ PopSafepointRegisters();
5216 Label profiler_disabled;
5217 Label end_profiler_check;
5218 __ Move(rax, ExternalReference::is_profiling_address(isolate));
5219 __ cmpb(Operand(rax, 0), Immediate(0));
5220 __ j(zero, &profiler_disabled);
5222 // Third parameter is the address of the actual getter function.
5223 __ Move(thunk_last_arg, function_address);
5224 __ Move(rax, thunk_ref);
5225 __ jmp(&end_profiler_check);
5227 __ bind(&profiler_disabled);
5228 // Call the api function!
5229 __ Move(rax, function_address);
5231 __ bind(&end_profiler_check);
5233 // Call the api function!
5236 if (FLAG_log_timer_events) {
5237 FrameScope frame(masm, StackFrame::MANUAL);
5238 __ PushSafepointRegisters();
5239 __ PrepareCallCFunction(1);
5240 __ LoadAddress(arg_reg_1, ExternalReference::isolate_address(isolate));
5241 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5243 __ PopSafepointRegisters();
5246 // Load the value from ReturnValue
5247 __ movp(rax, return_value_operand);
5250 // No more valid handles (the result handle was the last one). Restore
5251 // previous handle scope.
5252 __ subl(Operand(base_reg, kLevelOffset), Immediate(1));
5253 __ movp(Operand(base_reg, kNextOffset), prev_next_address_reg);
5254 __ cmpp(prev_limit_reg, Operand(base_reg, kLimitOffset));
5255 __ j(not_equal, &delete_allocated_handles);
5257 // Leave the API exit frame.
5258 __ bind(&leave_exit_frame);
5259 bool restore_context = context_restore_operand != NULL;
5260 if (restore_context) {
5261 __ movp(rsi, *context_restore_operand);
5263 if (stack_space_operand != nullptr) {
5264 __ movp(rbx, *stack_space_operand);
5266 __ LeaveApiExitFrame(!restore_context);
5268 // Check if the function scheduled an exception.
5269 __ Move(rdi, scheduled_exception_address);
5270 __ Cmp(Operand(rdi, 0), factory->the_hole_value());
5271 __ j(not_equal, &promote_scheduled_exception);
5274 // Check if the function returned a valid JavaScript value.
5276 Register return_value = rax;
5279 __ JumpIfSmi(return_value, &ok, Label::kNear);
5280 __ movp(map, FieldOperand(return_value, HeapObject::kMapOffset));
5282 __ CmpInstanceType(map, LAST_NAME_TYPE);
5283 __ j(below_equal, &ok, Label::kNear);
5285 __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE);
5286 __ j(above_equal, &ok, Label::kNear);
5288 __ CompareRoot(map, Heap::kHeapNumberMapRootIndex);
5289 __ j(equal, &ok, Label::kNear);
5291 __ CompareRoot(return_value, Heap::kUndefinedValueRootIndex);
5292 __ j(equal, &ok, Label::kNear);
5294 __ CompareRoot(return_value, Heap::kTrueValueRootIndex);
5295 __ j(equal, &ok, Label::kNear);
5297 __ CompareRoot(return_value, Heap::kFalseValueRootIndex);
5298 __ j(equal, &ok, Label::kNear);
5300 __ CompareRoot(return_value, Heap::kNullValueRootIndex);
5301 __ j(equal, &ok, Label::kNear);
5303 __ Abort(kAPICallReturnedInvalidObject);
5308 if (stack_space_operand != nullptr) {
5309 DCHECK_EQ(stack_space, 0);
5310 __ PopReturnAddressTo(rcx);
5314 __ ret(stack_space * kPointerSize);
5317 // Re-throw by promoting a scheduled exception.
5318 __ bind(&promote_scheduled_exception);
5319 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5321 // HandleScope limit has changed. Delete allocated extensions.
5322 __ bind(&delete_allocated_handles);
5323 __ movp(Operand(base_reg, kLimitOffset), prev_limit_reg);
5324 __ movp(prev_limit_reg, rax);
5325 __ LoadAddress(arg_reg_1, ExternalReference::isolate_address(isolate));
5327 ExternalReference::delete_handle_scope_extensions(isolate));
5329 __ movp(rax, prev_limit_reg);
5330 __ jmp(&leave_exit_frame);
5334 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5335 const ParameterCount& argc,
5336 bool return_first_arg,
5337 bool call_data_undefined) {
5338 // ----------- S t a t e -------------
5340 // -- rbx : call_data
5342 // -- rdx : api_function_address
5344 // -- rax : number of arguments if argc is a register
5345 // -- rsp[0] : return address
5346 // -- rsp[8] : last argument
5348 // -- rsp[argc * 8] : first argument
5349 // -- rsp[(argc + 1) * 8] : receiver
5350 // -----------------------------------
5352 Register callee = rdi;
5353 Register call_data = rbx;
5354 Register holder = rcx;
5355 Register api_function_address = rdx;
5356 Register context = rsi;
5357 Register return_address = r8;
5359 typedef FunctionCallbackArguments FCA;
5361 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5362 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5363 STATIC_ASSERT(FCA::kDataIndex == 4);
5364 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5365 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5366 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5367 STATIC_ASSERT(FCA::kHolderIndex == 0);
5368 STATIC_ASSERT(FCA::kArgsLength == 7);
5370 DCHECK(argc.is_immediate() || rax.is(argc.reg()));
5372 __ PopReturnAddressTo(return_address);
5382 Register scratch = call_data;
5383 if (!call_data_undefined) {
5384 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5388 // return value default
5391 __ Move(scratch, ExternalReference::isolate_address(masm->isolate()));
5396 __ movp(scratch, rsp);
5397 // Push return address back on stack.
5398 __ PushReturnAddressFrom(return_address);
5400 // load context from callee
5401 __ movp(context, FieldOperand(callee, JSFunction::kContextOffset));
5403 // Allocate the v8::Arguments structure in the arguments' space since
5404 // it's not controlled by GC.
5405 const int kApiStackSpace = 4;
5407 PrepareCallApiFunction(masm, kApiStackSpace);
5409 // FunctionCallbackInfo::implicit_args_.
5410 __ movp(StackSpaceOperand(0), scratch);
5411 if (argc.is_immediate()) {
5412 __ addp(scratch, Immediate((argc.immediate() + FCA::kArgsLength - 1) *
5414 // FunctionCallbackInfo::values_.
5415 __ movp(StackSpaceOperand(1), scratch);
5416 // FunctionCallbackInfo::length_.
5417 __ Set(StackSpaceOperand(2), argc.immediate());
5418 // FunctionCallbackInfo::is_construct_call_.
5419 __ Set(StackSpaceOperand(3), 0);
5421 __ leap(scratch, Operand(scratch, argc.reg(), times_pointer_size,
5422 (FCA::kArgsLength - 1) * kPointerSize));
5423 // FunctionCallbackInfo::values_.
5424 __ movp(StackSpaceOperand(1), scratch);
5425 // FunctionCallbackInfo::length_.
5426 __ movp(StackSpaceOperand(2), argc.reg());
5427 // FunctionCallbackInfo::is_construct_call_.
5428 __ leap(argc.reg(), Operand(argc.reg(), times_pointer_size,
5429 (FCA::kArgsLength + 1) * kPointerSize));
5430 __ movp(StackSpaceOperand(3), argc.reg());
5433 #if defined(__MINGW64__) || defined(_WIN64)
5434 Register arguments_arg = rcx;
5435 Register callback_arg = rdx;
5437 Register arguments_arg = rdi;
5438 Register callback_arg = rsi;
5441 // It's okay if api_function_address == callback_arg
5442 // but not arguments_arg
5443 DCHECK(!api_function_address.is(arguments_arg));
5445 // v8::InvocationCallback's argument.
5446 __ leap(arguments_arg, StackSpaceOperand(0));
5448 ExternalReference thunk_ref =
5449 ExternalReference::invoke_function_callback(masm->isolate());
5451 // Accessor for FunctionCallbackInfo and first js arg.
5452 StackArgumentsAccessor args_from_rbp(rbp, FCA::kArgsLength + 1,
5453 ARGUMENTS_DONT_CONTAIN_RECEIVER);
5454 Operand context_restore_operand = args_from_rbp.GetArgumentOperand(
5455 FCA::kArgsLength - FCA::kContextSaveIndex);
5456 Operand is_construct_call_operand = StackSpaceOperand(3);
5457 Operand return_value_operand = args_from_rbp.GetArgumentOperand(
5458 return_first_arg ? 0 : FCA::kArgsLength - FCA::kReturnValueOffset);
5459 int stack_space = 0;
5460 Operand* stack_space_operand = &is_construct_call_operand;
5461 if (argc.is_immediate()) {
5462 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5463 stack_space_operand = nullptr;
5465 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, callback_arg,
5466 stack_space, stack_space_operand,
5467 return_value_operand, &context_restore_operand);
5471 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5472 bool call_data_undefined = this->call_data_undefined();
5473 CallApiFunctionStubHelper(masm, ParameterCount(rax), false,
5474 call_data_undefined);
5478 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5479 bool is_store = this->is_store();
5480 int argc = this->argc();
5481 bool call_data_undefined = this->call_data_undefined();
5482 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5483 call_data_undefined);
5487 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5488 // ----------- S t a t e -------------
5489 // -- rsp[0] : return address
5491 // -- rsp[16 - kArgsLength*8] : PropertyCallbackArguments object
5493 // -- r8 : api_function_address
5494 // -----------------------------------
5496 #if defined(__MINGW64__) || defined(_WIN64)
5497 Register getter_arg = r8;
5498 Register accessor_info_arg = rdx;
5499 Register name_arg = rcx;
5501 Register getter_arg = rdx;
5502 Register accessor_info_arg = rsi;
5503 Register name_arg = rdi;
5505 Register api_function_address = ApiGetterDescriptor::function_address();
5506 DCHECK(api_function_address.is(r8));
5507 Register scratch = rax;
5509 // v8::Arguments::values_ and handler for name.
5510 const int kStackSpace = PropertyCallbackArguments::kArgsLength + 1;
5512 // Allocate v8::AccessorInfo in non-GCed stack space.
5513 const int kArgStackSpace = 1;
5515 __ leap(name_arg, Operand(rsp, kPCOnStackSize));
5517 PrepareCallApiFunction(masm, kArgStackSpace);
5518 __ leap(scratch, Operand(name_arg, 1 * kPointerSize));
5520 // v8::PropertyAccessorInfo::args_.
5521 __ movp(StackSpaceOperand(0), scratch);
5523 // The context register (rsi) has been saved in PrepareCallApiFunction and
5524 // could be used to pass arguments.
5525 __ leap(accessor_info_arg, StackSpaceOperand(0));
5527 ExternalReference thunk_ref =
5528 ExternalReference::invoke_accessor_getter_callback(isolate());
5530 // It's okay if api_function_address == getter_arg
5531 // but not accessor_info_arg or name_arg
5532 DCHECK(!api_function_address.is(accessor_info_arg) &&
5533 !api_function_address.is(name_arg));
5535 // The name handler is counted as an argument.
5536 StackArgumentsAccessor args(rbp, PropertyCallbackArguments::kArgsLength);
5537 Operand return_value_operand = args.GetArgumentOperand(
5538 PropertyCallbackArguments::kArgsLength - 1 -
5539 PropertyCallbackArguments::kReturnValueOffset);
5540 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, getter_arg,
5541 kStackSpace, nullptr, return_value_operand, NULL);
5547 } // namespace internal
5550 #endif // V8_TARGET_ARCH_X64