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.
1737 if (cc == equal && strict()) {
1738 __ PushReturnAddressFrom(rcx);
1739 __ TailCallRuntime(Runtime::kStrictEquals, 2, 1);
1743 context_index = Context::EQUALS_BUILTIN_INDEX;
1745 context_index = is_strong(strength())
1746 ? Context::COMPARE_STRONG_BUILTIN_INDEX
1747 : Context::COMPARE_BUILTIN_INDEX;
1748 __ Push(Smi::FromInt(NegativeComparisonResult(cc)));
1751 __ PushReturnAddressFrom(rcx);
1753 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
1754 // tagged as a small integer.
1755 __ InvokeBuiltin(context_index, JUMP_FUNCTION);
1763 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
1765 // rax : number of arguments to the construct function
1766 // rbx : feedback vector
1767 // rcx : original constructor (for IsSuperConstructorCall)
1768 // rdx : slot in feedback vector (Smi)
1769 // rdi : the function to call
1770 FrameScope scope(masm, StackFrame::INTERNAL);
1772 // Number-of-arguments register must be smi-tagged to call out.
1773 __ Integer32ToSmi(rax, rax);
1776 __ Integer32ToSmi(rdx, rdx);
1792 __ SmiToInteger32(rax, rax);
1796 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
1797 // Cache the called function in a feedback vector slot. Cache states
1798 // are uninitialized, monomorphic (indicated by a JSFunction), and
1800 // rax : number of arguments to the construct function
1801 // rbx : feedback vector
1802 // rcx : original constructor (for IsSuperConstructorCall)
1803 // rdx : slot in feedback vector (Smi)
1804 // rdi : the function to call
1805 Isolate* isolate = masm->isolate();
1806 Label initialize, done, miss, megamorphic, not_array_function,
1807 done_no_smi_convert;
1809 // Load the cache state into r11.
1810 __ SmiToInteger32(rdx, rdx);
1812 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize));
1814 // A monomorphic cache hit or an already megamorphic state: invoke the
1815 // function without changing the state.
1816 // We don't know if r11 is a WeakCell or a Symbol, but it's harmless to read
1817 // at this position in a symbol (see static asserts in
1818 // type-feedback-vector.h).
1819 Label check_allocation_site;
1820 __ cmpp(rdi, FieldOperand(r11, WeakCell::kValueOffset));
1821 __ j(equal, &done, Label::kFar);
1822 __ CompareRoot(r11, Heap::kmegamorphic_symbolRootIndex);
1823 __ j(equal, &done, Label::kFar);
1824 __ CompareRoot(FieldOperand(r11, HeapObject::kMapOffset),
1825 Heap::kWeakCellMapRootIndex);
1826 __ j(not_equal, FLAG_pretenuring_call_new ? &miss : &check_allocation_site);
1828 // If the weak cell is cleared, we have a new chance to become monomorphic.
1829 __ CheckSmi(FieldOperand(r11, WeakCell::kValueOffset));
1830 __ j(equal, &initialize);
1831 __ jmp(&megamorphic);
1833 if (!FLAG_pretenuring_call_new) {
1834 __ bind(&check_allocation_site);
1835 // If we came here, we need to see if we are the array function.
1836 // If we didn't have a matching function, and we didn't find the megamorph
1837 // sentinel, then we have in the slot either some other function or an
1839 __ CompareRoot(FieldOperand(r11, 0), Heap::kAllocationSiteMapRootIndex);
1840 __ j(not_equal, &miss);
1842 // Make sure the function is the Array() function
1843 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r11);
1845 __ j(not_equal, &megamorphic);
1851 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
1853 __ CompareRoot(r11, Heap::kuninitialized_symbolRootIndex);
1854 __ j(equal, &initialize);
1855 // MegamorphicSentinel is an immortal immovable object (undefined) so no
1856 // write-barrier is needed.
1857 __ bind(&megamorphic);
1858 __ Move(FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize),
1859 TypeFeedbackVector::MegamorphicSentinel(isolate));
1862 // An uninitialized cache is patched with the function or sentinel to
1863 // indicate the ElementsKind if function is the Array constructor.
1864 __ bind(&initialize);
1866 if (!FLAG_pretenuring_call_new) {
1867 // Make sure the function is the Array() function
1868 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r11);
1870 __ j(not_equal, ¬_array_function);
1872 CreateAllocationSiteStub create_stub(isolate);
1873 CallStubInRecordCallTarget(masm, &create_stub, is_super);
1874 __ jmp(&done_no_smi_convert);
1876 __ bind(¬_array_function);
1879 CreateWeakCellStub create_stub(isolate);
1880 CallStubInRecordCallTarget(masm, &create_stub, is_super);
1881 __ jmp(&done_no_smi_convert);
1884 __ Integer32ToSmi(rdx, rdx);
1886 __ bind(&done_no_smi_convert);
1890 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
1891 // Do not transform the receiver for strict mode functions.
1892 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
1893 __ testb(FieldOperand(rcx, SharedFunctionInfo::kStrictModeByteOffset),
1894 Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte));
1895 __ j(not_equal, cont);
1897 // Do not transform the receiver for natives.
1898 // SharedFunctionInfo is already loaded into rcx.
1899 __ testb(FieldOperand(rcx, SharedFunctionInfo::kNativeByteOffset),
1900 Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte));
1901 __ j(not_equal, cont);
1905 static void EmitSlowCase(MacroAssembler* masm, StackArgumentsAccessor* args,
1908 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
1912 static void EmitWrapCase(MacroAssembler* masm,
1913 StackArgumentsAccessor* args,
1915 // Wrap the receiver and patch it back onto the stack.
1916 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
1918 ToObjectStub stub(masm->isolate());
1922 __ movp(args->GetReceiverOperand(), rax);
1927 static void CallFunctionNoFeedback(MacroAssembler* masm,
1928 int argc, bool needs_checks,
1929 bool call_as_method) {
1930 // rdi : the function to call
1932 // wrap_and_call can only be true if we are compiling a monomorphic method.
1933 Label slow, wrap, cont;
1934 StackArgumentsAccessor args(rsp, argc);
1937 // Check that the function really is a JavaScript function.
1938 __ JumpIfSmi(rdi, &slow);
1940 // Goto slow case if we do not have a function.
1941 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx);
1942 __ j(not_equal, &slow);
1945 // Fast-case: Just invoke the function.
1946 ParameterCount actual(argc);
1948 if (call_as_method) {
1950 EmitContinueIfStrictOrNative(masm, &cont);
1953 // Load the receiver from the stack.
1954 __ movp(rax, args.GetReceiverOperand());
1957 __ JumpIfSmi(rax, &wrap);
1959 __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx);
1968 __ InvokeFunction(rdi, actual, JUMP_FUNCTION, NullCallWrapper());
1971 // Slow-case: Non-function called.
1973 EmitSlowCase(masm, &args, argc);
1976 if (call_as_method) {
1978 EmitWrapCase(masm, &args, &cont);
1983 void CallFunctionStub::Generate(MacroAssembler* masm) {
1984 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
1988 void CallConstructStub::Generate(MacroAssembler* masm) {
1989 // rax : number of arguments
1990 // rbx : feedback vector
1991 // rcx : original constructor (for IsSuperConstructorCall)
1992 // rdx : slot in feedback vector (Smi, for RecordCallTarget)
1993 // rdi : constructor function
1994 Label slow, non_function_call;
1996 // Check that function is not a smi.
1997 __ JumpIfSmi(rdi, &non_function_call);
1998 // Check that function is a JSFunction.
1999 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, r11);
2000 __ j(not_equal, &slow);
2002 if (RecordCallTarget()) {
2003 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2005 __ SmiToInteger32(rdx, rdx);
2006 if (FLAG_pretenuring_call_new) {
2007 // Put the AllocationSite from the feedback vector into ebx.
2008 // By adding kPointerSize we encode that we know the AllocationSite
2009 // entry is at the feedback vector slot given by rdx + 1.
2010 __ movp(rbx, FieldOperand(rbx, rdx, times_pointer_size,
2011 FixedArray::kHeaderSize + kPointerSize));
2013 Label feedback_register_initialized;
2014 // Put the AllocationSite from the feedback vector into rbx, or undefined.
2015 __ movp(rbx, FieldOperand(rbx, rdx, times_pointer_size,
2016 FixedArray::kHeaderSize));
2017 __ CompareRoot(FieldOperand(rbx, 0), Heap::kAllocationSiteMapRootIndex);
2018 __ j(equal, &feedback_register_initialized);
2019 __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex);
2020 __ bind(&feedback_register_initialized);
2023 __ AssertUndefinedOrAllocationSite(rbx);
2026 // Pass original constructor to construct stub.
2027 if (IsSuperConstructorCall()) {
2033 // Jump to the function-specific construct stub.
2034 Register jmp_reg = rcx;
2035 __ movp(jmp_reg, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
2036 __ movp(jmp_reg, FieldOperand(jmp_reg,
2037 SharedFunctionInfo::kConstructStubOffset));
2038 __ leap(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize));
2041 // rdi: called object
2042 // rax: number of arguments
2046 __ CmpInstanceType(r11, JS_FUNCTION_PROXY_TYPE);
2047 __ j(not_equal, &non_function_call);
2048 __ GetBuiltinEntry(rdx,
2049 Context::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR_BUILTIN_INDEX);
2052 __ bind(&non_function_call);
2053 __ GetBuiltinEntry(rdx,
2054 Context::CALL_NON_FUNCTION_AS_CONSTRUCTOR_BUILTIN_INDEX);
2056 // Set expected number of arguments to zero (not changing rax).
2058 __ Jump(isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2059 RelocInfo::CODE_TARGET);
2063 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2064 __ movp(vector, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
2065 __ movp(vector, FieldOperand(vector, JSFunction::kSharedFunctionInfoOffset));
2066 __ movp(vector, FieldOperand(vector,
2067 SharedFunctionInfo::kFeedbackVectorOffset));
2071 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2073 // rdx - slot id (as integer)
2076 int argc = arg_count();
2077 ParameterCount actual(argc);
2079 __ SmiToInteger32(rdx, rdx);
2081 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, rcx);
2083 __ j(not_equal, &miss);
2085 __ movp(rax, Immediate(arg_count()));
2086 __ movp(rcx, FieldOperand(rbx, rdx, times_pointer_size,
2087 FixedArray::kHeaderSize));
2088 // Verify that ecx contains an AllocationSite
2089 __ CompareRoot(FieldOperand(rcx, HeapObject::kMapOffset),
2090 Heap::kAllocationSiteMapRootIndex);
2091 __ j(not_equal, &miss, Label::kNear);
2093 // Increment the call count for monomorphic function calls.
2095 __ SmiAddConstant(FieldOperand(rbx, rdx, times_pointer_size,
2096 FixedArray::kHeaderSize + kPointerSize),
2097 Smi::FromInt(CallICNexus::kCallCountIncrement));
2101 ArrayConstructorStub stub(masm->isolate(), arg_count());
2102 __ TailCallStub(&stub);
2108 // The slow case, we need this no matter what to complete a call after a miss.
2109 __ Set(rax, arg_count());
2110 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2114 void CallICStub::Generate(MacroAssembler* masm) {
2118 Isolate* isolate = masm->isolate();
2119 const int with_types_offset =
2120 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2121 const int generic_offset =
2122 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2123 Label extra_checks_or_miss, slow_start;
2124 Label slow, wrap, cont;
2125 Label have_js_function;
2126 int argc = arg_count();
2127 StackArgumentsAccessor args(rsp, argc);
2128 ParameterCount actual(argc);
2130 // The checks. First, does rdi match the recorded monomorphic target?
2131 __ SmiToInteger32(rdx, rdx);
2133 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize));
2135 // We don't know that we have a weak cell. We might have a private symbol
2136 // or an AllocationSite, but the memory is safe to examine.
2137 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2139 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2140 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2141 // computed, meaning that it can't appear to be a pointer. If the low bit is
2142 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2144 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2145 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2146 WeakCell::kValueOffset &&
2147 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2149 __ cmpp(rdi, FieldOperand(rcx, WeakCell::kValueOffset));
2150 __ j(not_equal, &extra_checks_or_miss);
2152 // The compare above could have been a SMI/SMI comparison. Guard against this
2153 // convincing us that we have a monomorphic JSFunction.
2154 __ JumpIfSmi(rdi, &extra_checks_or_miss);
2156 // Increment the call count for monomorphic function calls.
2157 __ SmiAddConstant(FieldOperand(rbx, rdx, times_pointer_size,
2158 FixedArray::kHeaderSize + kPointerSize),
2159 Smi::FromInt(CallICNexus::kCallCountIncrement));
2161 __ bind(&have_js_function);
2162 if (CallAsMethod()) {
2163 EmitContinueIfStrictOrNative(masm, &cont);
2165 // Load the receiver from the stack.
2166 __ movp(rax, args.GetReceiverOperand());
2168 __ JumpIfSmi(rax, &wrap);
2170 __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx);
2176 __ InvokeFunction(rdi, actual, JUMP_FUNCTION, NullCallWrapper());
2179 EmitSlowCase(masm, &args, argc);
2181 if (CallAsMethod()) {
2183 EmitWrapCase(masm, &args, &cont);
2186 __ bind(&extra_checks_or_miss);
2187 Label uninitialized, miss;
2189 __ Cmp(rcx, TypeFeedbackVector::MegamorphicSentinel(isolate));
2190 __ j(equal, &slow_start);
2192 // The following cases attempt to handle MISS cases without going to the
2194 if (FLAG_trace_ic) {
2198 __ Cmp(rcx, TypeFeedbackVector::UninitializedSentinel(isolate));
2199 __ j(equal, &uninitialized);
2201 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2202 // to handle it here. More complex cases are dealt with in the runtime.
2203 __ AssertNotSmi(rcx);
2204 __ CmpObjectType(rcx, JS_FUNCTION_TYPE, rcx);
2205 __ j(not_equal, &miss);
2206 __ Move(FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize),
2207 TypeFeedbackVector::MegamorphicSentinel(isolate));
2208 // We have to update statistics for runtime profiling.
2209 __ SmiAddConstant(FieldOperand(rbx, with_types_offset), Smi::FromInt(-1));
2210 __ SmiAddConstant(FieldOperand(rbx, generic_offset), Smi::FromInt(1));
2211 __ jmp(&slow_start);
2213 __ bind(&uninitialized);
2215 // We are going monomorphic, provided we actually have a JSFunction.
2216 __ JumpIfSmi(rdi, &miss);
2218 // Goto miss case if we do not have a function.
2219 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx);
2220 __ j(not_equal, &miss);
2222 // Make sure the function is not the Array() function, which requires special
2223 // behavior on MISS.
2224 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, rcx);
2229 __ SmiAddConstant(FieldOperand(rbx, with_types_offset), Smi::FromInt(1));
2231 // Initialize the call counter.
2232 __ Move(FieldOperand(rbx, rdx, times_pointer_size,
2233 FixedArray::kHeaderSize + kPointerSize),
2234 Smi::FromInt(CallICNexus::kCallCountIncrement));
2236 // Store the function. Use a stub since we need a frame for allocation.
2238 // rdx - slot (needs to be in smi form)
2241 FrameScope scope(masm, StackFrame::INTERNAL);
2242 CreateWeakCellStub create_stub(isolate);
2244 __ Integer32ToSmi(rdx, rdx);
2246 __ CallStub(&create_stub);
2250 __ jmp(&have_js_function);
2252 // We are here because tracing is on or we encountered a MISS case we can't
2258 __ bind(&slow_start);
2259 // Check that function is not a smi.
2260 __ JumpIfSmi(rdi, &slow);
2261 // Check that function is a JSFunction.
2262 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx);
2263 __ j(not_equal, &slow);
2264 __ jmp(&have_js_function);
2271 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2272 FrameScope scope(masm, StackFrame::INTERNAL);
2274 // Push the receiver and the function and feedback info.
2277 __ Integer32ToSmi(rdx, rdx);
2281 Runtime::FunctionId id = GetICState() == DEFAULT
2282 ? Runtime::kCallIC_Miss
2283 : Runtime::kCallIC_Customization_Miss;
2284 __ CallRuntime(id, 3);
2286 // Move result to edi and exit the internal frame.
2291 bool CEntryStub::NeedsImmovableCode() {
2296 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
2297 CEntryStub::GenerateAheadOfTime(isolate);
2298 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
2299 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
2300 // It is important that the store buffer overflow stubs are generated first.
2301 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
2302 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
2303 CreateWeakCellStub::GenerateAheadOfTime(isolate);
2304 BinaryOpICStub::GenerateAheadOfTime(isolate);
2305 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
2306 StoreFastElementStub::GenerateAheadOfTime(isolate);
2307 TypeofStub::GenerateAheadOfTime(isolate);
2311 void CodeStub::GenerateFPStubs(Isolate* isolate) {
2315 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
2316 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
2318 CEntryStub save_doubles(isolate, 1, kSaveFPRegs);
2319 save_doubles.GetCode();
2323 void CEntryStub::Generate(MacroAssembler* masm) {
2324 // rax: number of arguments including receiver
2325 // rbx: pointer to C function (C callee-saved)
2326 // rbp: frame pointer of calling JS frame (restored after C call)
2327 // rsp: stack pointer (restored after C call)
2328 // rsi: current context (restored)
2330 ProfileEntryHookStub::MaybeCallEntryHook(masm);
2332 // Enter the exit frame that transitions from JavaScript to C++.
2334 int arg_stack_space = (result_size() < 2 ? 2 : 4);
2336 int arg_stack_space = 0;
2338 __ EnterExitFrame(arg_stack_space, save_doubles());
2340 // rbx: pointer to builtin function (C callee-saved).
2341 // rbp: frame pointer of exit frame (restored after C call).
2342 // rsp: stack pointer (restored after C call).
2343 // r14: number of arguments including receiver (C callee-saved).
2344 // r15: argv pointer (C callee-saved).
2346 // Simple results returned in rax (both AMD64 and Win64 calling conventions).
2347 // Complex results must be written to address passed as first argument.
2348 // AMD64 calling convention: a struct of two pointers in rax+rdx
2350 // Check stack alignment.
2351 if (FLAG_debug_code) {
2352 __ CheckStackAlignment();
2357 // Windows 64-bit ABI passes arguments in rcx, rdx, r8, r9.
2358 // Pass argv and argc as two parameters. The arguments object will
2359 // be created by stubs declared by DECLARE_RUNTIME_FUNCTION().
2360 if (result_size() < 2) {
2361 // Pass a pointer to the Arguments object as the first argument.
2362 // Return result in single register (rax).
2363 __ movp(rcx, r14); // argc.
2364 __ movp(rdx, r15); // argv.
2365 __ Move(r8, ExternalReference::isolate_address(isolate()));
2367 DCHECK_EQ(2, result_size());
2368 // Pass a pointer to the result location as the first argument.
2369 __ leap(rcx, StackSpaceOperand(2));
2370 // Pass a pointer to the Arguments object as the second argument.
2371 __ movp(rdx, r14); // argc.
2372 __ movp(r8, r15); // argv.
2373 __ Move(r9, ExternalReference::isolate_address(isolate()));
2377 // GCC passes arguments in rdi, rsi, rdx, rcx, r8, r9.
2378 __ movp(rdi, r14); // argc.
2379 __ movp(rsi, r15); // argv.
2380 __ Move(rdx, ExternalReference::isolate_address(isolate()));
2383 // Result is in rax - do not destroy this register!
2386 // If return value is on the stack, pop it to registers.
2387 if (result_size() > 1) {
2388 DCHECK_EQ(2, result_size());
2389 // Read result values stored on stack. Result is stored
2390 // above the four argument mirror slots and the two
2391 // Arguments object slots.
2392 __ movq(rax, Operand(rsp, 6 * kRegisterSize));
2393 __ movq(rdx, Operand(rsp, 7 * kRegisterSize));
2397 // Check result for exception sentinel.
2398 Label exception_returned;
2399 __ CompareRoot(rax, Heap::kExceptionRootIndex);
2400 __ j(equal, &exception_returned);
2402 // Check that there is no pending exception, otherwise we
2403 // should have returned the exception sentinel.
2404 if (FLAG_debug_code) {
2406 __ LoadRoot(r14, Heap::kTheHoleValueRootIndex);
2407 ExternalReference pending_exception_address(
2408 Isolate::kPendingExceptionAddress, isolate());
2409 Operand pending_exception_operand =
2410 masm->ExternalOperand(pending_exception_address);
2411 __ cmpp(r14, pending_exception_operand);
2412 __ j(equal, &okay, Label::kNear);
2417 // Exit the JavaScript to C++ exit frame.
2418 __ LeaveExitFrame(save_doubles());
2421 // Handling of exception.
2422 __ bind(&exception_returned);
2424 ExternalReference pending_handler_context_address(
2425 Isolate::kPendingHandlerContextAddress, isolate());
2426 ExternalReference pending_handler_code_address(
2427 Isolate::kPendingHandlerCodeAddress, isolate());
2428 ExternalReference pending_handler_offset_address(
2429 Isolate::kPendingHandlerOffsetAddress, isolate());
2430 ExternalReference pending_handler_fp_address(
2431 Isolate::kPendingHandlerFPAddress, isolate());
2432 ExternalReference pending_handler_sp_address(
2433 Isolate::kPendingHandlerSPAddress, isolate());
2435 // Ask the runtime for help to determine the handler. This will set rax to
2436 // contain the current pending exception, don't clobber it.
2437 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
2440 FrameScope scope(masm, StackFrame::MANUAL);
2441 __ movp(arg_reg_1, Immediate(0)); // argc.
2442 __ movp(arg_reg_2, Immediate(0)); // argv.
2443 __ Move(arg_reg_3, ExternalReference::isolate_address(isolate()));
2444 __ PrepareCallCFunction(3);
2445 __ CallCFunction(find_handler, 3);
2448 // Retrieve the handler context, SP and FP.
2449 __ movp(rsi, masm->ExternalOperand(pending_handler_context_address));
2450 __ movp(rsp, masm->ExternalOperand(pending_handler_sp_address));
2451 __ movp(rbp, masm->ExternalOperand(pending_handler_fp_address));
2453 // If the handler is a JS frame, restore the context to the frame. Note that
2454 // the context will be set to (rsi == 0) for non-JS frames.
2457 __ j(zero, &skip, Label::kNear);
2458 __ movp(Operand(rbp, StandardFrameConstants::kContextOffset), rsi);
2461 // Compute the handler entry address and jump to it.
2462 __ movp(rdi, masm->ExternalOperand(pending_handler_code_address));
2463 __ movp(rdx, masm->ExternalOperand(pending_handler_offset_address));
2464 __ leap(rdi, FieldOperand(rdi, rdx, times_1, Code::kHeaderSize));
2469 void JSEntryStub::Generate(MacroAssembler* masm) {
2470 Label invoke, handler_entry, exit;
2471 Label not_outermost_js, not_outermost_js_2;
2473 ProfileEntryHookStub::MaybeCallEntryHook(masm);
2475 { // NOLINT. Scope block confuses linter.
2476 MacroAssembler::NoRootArrayScope uninitialized_root_register(masm);
2481 // Push the stack frame type marker twice.
2482 int marker = type();
2483 // Scratch register is neither callee-save, nor an argument register on any
2484 // platform. It's free to use at this point.
2485 // Cannot use smi-register for loading yet.
2486 __ Move(kScratchRegister, Smi::FromInt(marker), Assembler::RelocInfoNone());
2487 __ Push(kScratchRegister); // context slot
2488 __ Push(kScratchRegister); // function slot
2489 // Save callee-saved registers (X64/X32/Win64 calling conventions).
2495 __ pushq(rdi); // Only callee save in Win64 ABI, argument in AMD64 ABI.
2496 __ pushq(rsi); // Only callee save in Win64 ABI, argument in AMD64 ABI.
2501 // On Win64 XMM6-XMM15 are callee-save
2502 __ subp(rsp, Immediate(EntryFrameConstants::kXMMRegistersBlockSize));
2503 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 0), xmm6);
2504 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 1), xmm7);
2505 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 2), xmm8);
2506 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 3), xmm9);
2507 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 4), xmm10);
2508 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 5), xmm11);
2509 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 6), xmm12);
2510 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 7), xmm13);
2511 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 8), xmm14);
2512 __ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 9), xmm15);
2515 // Set up the roots and smi constant registers.
2516 // Needs to be done before any further smi loads.
2517 __ InitializeRootRegister();
2520 // Save copies of the top frame descriptor on the stack.
2521 ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, isolate());
2523 Operand c_entry_fp_operand = masm->ExternalOperand(c_entry_fp);
2524 __ Push(c_entry_fp_operand);
2527 // If this is the outermost JS call, set js_entry_sp value.
2528 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
2529 __ Load(rax, js_entry_sp);
2531 __ j(not_zero, ¬_outermost_js);
2532 __ Push(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
2534 __ Store(js_entry_sp, rax);
2537 __ bind(¬_outermost_js);
2538 __ Push(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME));
2541 // Jump to a faked try block that does the invoke, with a faked catch
2542 // block that sets the pending exception.
2544 __ bind(&handler_entry);
2545 handler_offset_ = handler_entry.pos();
2546 // Caught exception: Store result (exception) in the pending exception
2547 // field in the JSEnv and return a failure sentinel.
2548 ExternalReference pending_exception(Isolate::kPendingExceptionAddress,
2550 __ Store(pending_exception, rax);
2551 __ LoadRoot(rax, Heap::kExceptionRootIndex);
2554 // Invoke: Link this frame into the handler chain.
2556 __ PushStackHandler();
2558 // Clear any pending exceptions.
2559 __ LoadRoot(rax, Heap::kTheHoleValueRootIndex);
2560 __ Store(pending_exception, rax);
2562 // Fake a receiver (NULL).
2563 __ Push(Immediate(0)); // receiver
2565 // Invoke the function by calling through JS entry trampoline builtin and
2566 // pop the faked function when we return. We load the address from an
2567 // external reference instead of inlining the call target address directly
2568 // in the code, because the builtin stubs may not have been generated yet
2569 // at the time this code is generated.
2570 if (type() == StackFrame::ENTRY_CONSTRUCT) {
2571 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
2573 __ Load(rax, construct_entry);
2575 ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
2576 __ Load(rax, entry);
2578 __ leap(kScratchRegister, FieldOperand(rax, Code::kHeaderSize));
2579 __ call(kScratchRegister);
2581 // Unlink this frame from the handler chain.
2582 __ PopStackHandler();
2585 // Check if the current stack frame is marked as the outermost JS frame.
2587 __ Cmp(rbx, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
2588 __ j(not_equal, ¬_outermost_js_2);
2589 __ Move(kScratchRegister, js_entry_sp);
2590 __ movp(Operand(kScratchRegister, 0), Immediate(0));
2591 __ bind(¬_outermost_js_2);
2593 // Restore the top frame descriptor from the stack.
2594 { Operand c_entry_fp_operand = masm->ExternalOperand(c_entry_fp);
2595 __ Pop(c_entry_fp_operand);
2598 // Restore callee-saved registers (X64 conventions).
2600 // On Win64 XMM6-XMM15 are callee-save
2601 __ movdqu(xmm6, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 0));
2602 __ movdqu(xmm7, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 1));
2603 __ movdqu(xmm8, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 2));
2604 __ movdqu(xmm9, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 3));
2605 __ movdqu(xmm10, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 4));
2606 __ movdqu(xmm11, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 5));
2607 __ movdqu(xmm12, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 6));
2608 __ movdqu(xmm13, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 7));
2609 __ movdqu(xmm14, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 8));
2610 __ movdqu(xmm15, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 9));
2611 __ addp(rsp, Immediate(EntryFrameConstants::kXMMRegistersBlockSize));
2616 // Callee save on in Win64 ABI, arguments/volatile in AMD64 ABI.
2624 __ addp(rsp, Immediate(2 * kPointerSize)); // remove markers
2626 // Restore frame pointer and return.
2632 void InstanceOfStub::Generate(MacroAssembler* masm) {
2633 Register const object = rdx; // Object (lhs).
2634 Register const function = rax; // Function (rhs).
2635 Register const object_map = rcx; // Map of {object}.
2636 Register const function_map = r8; // Map of {function}.
2637 Register const function_prototype = rdi; // Prototype of {function}.
2639 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
2640 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
2642 // Check if {object} is a smi.
2643 Label object_is_smi;
2644 __ JumpIfSmi(object, &object_is_smi, Label::kNear);
2646 // Lookup the {function} and the {object} map in the global instanceof cache.
2647 // Note: This is safe because we clear the global instanceof cache whenever
2648 // we change the prototype of any object.
2649 Label fast_case, slow_case;
2650 __ movp(object_map, FieldOperand(object, HeapObject::kMapOffset));
2651 __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
2652 __ j(not_equal, &fast_case, Label::kNear);
2653 __ CompareRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
2654 __ j(not_equal, &fast_case, Label::kNear);
2655 __ LoadRoot(rax, Heap::kInstanceofCacheAnswerRootIndex);
2658 // If {object} is a smi we can safely return false if {function} is a JS
2659 // function, otherwise we have to miss to the runtime and throw an exception.
2660 __ bind(&object_is_smi);
2661 __ JumpIfSmi(function, &slow_case);
2662 __ CmpObjectType(function, JS_FUNCTION_TYPE, function_map);
2663 __ j(not_equal, &slow_case);
2664 __ LoadRoot(rax, Heap::kFalseValueRootIndex);
2667 // Fast-case: The {function} must be a valid JSFunction.
2668 __ bind(&fast_case);
2669 __ JumpIfSmi(function, &slow_case);
2670 __ CmpObjectType(function, JS_FUNCTION_TYPE, function_map);
2671 __ j(not_equal, &slow_case);
2673 // Ensure that {function} has an instance prototype.
2674 __ testb(FieldOperand(function_map, Map::kBitFieldOffset),
2675 Immediate(1 << Map::kHasNonInstancePrototype));
2676 __ j(not_zero, &slow_case);
2678 // Ensure that {function} is not bound.
2679 Register const shared_info = kScratchRegister;
2680 __ movp(shared_info,
2681 FieldOperand(function, JSFunction::kSharedFunctionInfoOffset));
2682 __ TestBitSharedFunctionInfoSpecialField(
2683 shared_info, SharedFunctionInfo::kCompilerHintsOffset,
2684 SharedFunctionInfo::kBoundFunction);
2685 __ j(not_zero, &slow_case);
2687 // Get the "prototype" (or initial map) of the {function}.
2688 __ movp(function_prototype,
2689 FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
2690 __ AssertNotSmi(function_prototype);
2692 // Resolve the prototype if the {function} has an initial map. Afterwards the
2693 // {function_prototype} will be either the JSReceiver prototype object or the
2694 // hole value, which means that no instances of the {function} were created so
2695 // far and hence we should return false.
2696 Label function_prototype_valid;
2697 Register const function_prototype_map = kScratchRegister;
2698 __ CmpObjectType(function_prototype, MAP_TYPE, function_prototype_map);
2699 __ j(not_equal, &function_prototype_valid, Label::kNear);
2700 __ movp(function_prototype,
2701 FieldOperand(function_prototype, Map::kPrototypeOffset));
2702 __ bind(&function_prototype_valid);
2703 __ AssertNotSmi(function_prototype);
2705 // Update the global instanceof cache with the current {object} map and
2706 // {function}. The cached answer will be set when it is known below.
2707 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
2708 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
2710 // Loop through the prototype chain looking for the {function} prototype.
2711 // Assume true, and change to false if not found.
2712 Register const object_prototype = object_map;
2714 __ LoadRoot(rax, Heap::kTrueValueRootIndex);
2716 __ movp(object_prototype, FieldOperand(object_map, Map::kPrototypeOffset));
2717 __ cmpp(object_prototype, function_prototype);
2718 __ j(equal, &done, Label::kNear);
2719 __ CompareRoot(object_prototype, Heap::kNullValueRootIndex);
2720 __ movp(object_map, FieldOperand(object_prototype, HeapObject::kMapOffset));
2721 __ j(not_equal, &loop);
2722 __ LoadRoot(rax, Heap::kFalseValueRootIndex);
2724 __ StoreRoot(rax, Heap::kInstanceofCacheAnswerRootIndex);
2727 // Slow-case: Call the runtime function.
2728 __ bind(&slow_case);
2729 __ PopReturnAddressTo(kScratchRegister);
2732 __ PushReturnAddressFrom(kScratchRegister);
2733 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
2737 // -------------------------------------------------------------------------
2738 // StringCharCodeAtGenerator
2740 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2741 // If the receiver is a smi trigger the non-string case.
2742 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2743 __ JumpIfSmi(object_, receiver_not_string_);
2745 // Fetch the instance type of the receiver into result register.
2746 __ movp(result_, FieldOperand(object_, HeapObject::kMapOffset));
2747 __ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset));
2748 // If the receiver is not a string trigger the non-string case.
2749 __ testb(result_, Immediate(kIsNotStringMask));
2750 __ j(not_zero, receiver_not_string_);
2753 // If the index is non-smi trigger the non-smi case.
2754 __ JumpIfNotSmi(index_, &index_not_smi_);
2755 __ bind(&got_smi_index_);
2757 // Check for index out of range.
2758 __ SmiCompare(index_, FieldOperand(object_, String::kLengthOffset));
2759 __ j(above_equal, index_out_of_range_);
2761 __ SmiToInteger32(index_, index_);
2763 StringCharLoadGenerator::Generate(
2764 masm, object_, index_, result_, &call_runtime_);
2766 __ Integer32ToSmi(result_, result_);
2771 void StringCharCodeAtGenerator::GenerateSlow(
2772 MacroAssembler* masm, EmbedMode embed_mode,
2773 const RuntimeCallHelper& call_helper) {
2774 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2776 Factory* factory = masm->isolate()->factory();
2777 // Index is not a smi.
2778 __ bind(&index_not_smi_);
2779 // If index is a heap number, try converting it to an integer.
2781 factory->heap_number_map(),
2784 call_helper.BeforeCall(masm);
2785 if (embed_mode == PART_OF_IC_HANDLER) {
2786 __ Push(LoadWithVectorDescriptor::VectorRegister());
2787 __ Push(LoadDescriptor::SlotRegister());
2790 __ Push(index_); // Consumed by runtime conversion function.
2791 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2792 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2794 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2795 // NumberToSmi discards numbers that are not exact integers.
2796 __ CallRuntime(Runtime::kNumberToSmi, 1);
2798 if (!index_.is(rax)) {
2799 // Save the conversion result before the pop instructions below
2800 // have a chance to overwrite it.
2801 __ movp(index_, rax);
2804 if (embed_mode == PART_OF_IC_HANDLER) {
2805 __ Pop(LoadDescriptor::SlotRegister());
2806 __ Pop(LoadWithVectorDescriptor::VectorRegister());
2808 // Reload the instance type.
2809 __ movp(result_, FieldOperand(object_, HeapObject::kMapOffset));
2810 __ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset));
2811 call_helper.AfterCall(masm);
2812 // If index is still not a smi, it must be out of range.
2813 __ JumpIfNotSmi(index_, index_out_of_range_);
2814 // Otherwise, return to the fast path.
2815 __ jmp(&got_smi_index_);
2817 // Call runtime. We get here when the receiver is a string and the
2818 // index is a number, but the code of getting the actual character
2819 // is too complex (e.g., when the string needs to be flattened).
2820 __ bind(&call_runtime_);
2821 call_helper.BeforeCall(masm);
2823 __ Integer32ToSmi(index_, index_);
2825 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
2826 if (!result_.is(rax)) {
2827 __ movp(result_, rax);
2829 call_helper.AfterCall(masm);
2832 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
2836 // -------------------------------------------------------------------------
2837 // StringCharFromCodeGenerator
2839 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
2840 // Fast case of Heap::LookupSingleCharacterStringFromCode.
2841 __ JumpIfNotSmi(code_, &slow_case_);
2842 __ SmiCompare(code_, Smi::FromInt(String::kMaxOneByteCharCode));
2843 __ j(above, &slow_case_);
2845 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
2846 SmiIndex index = masm->SmiToIndex(kScratchRegister, code_, kPointerSizeLog2);
2847 __ movp(result_, FieldOperand(result_, index.reg, index.scale,
2848 FixedArray::kHeaderSize));
2849 __ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
2850 __ j(equal, &slow_case_);
2855 void StringCharFromCodeGenerator::GenerateSlow(
2856 MacroAssembler* masm,
2857 const RuntimeCallHelper& call_helper) {
2858 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
2860 __ bind(&slow_case_);
2861 call_helper.BeforeCall(masm);
2863 __ CallRuntime(Runtime::kCharFromCode, 1);
2864 if (!result_.is(rax)) {
2865 __ movp(result_, rax);
2867 call_helper.AfterCall(masm);
2870 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
2874 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
2878 String::Encoding encoding) {
2879 // Nothing to do for zero characters.
2881 __ testl(count, count);
2882 __ j(zero, &done, Label::kNear);
2884 // Make count the number of bytes to copy.
2885 if (encoding == String::TWO_BYTE_ENCODING) {
2886 STATIC_ASSERT(2 == sizeof(uc16));
2887 __ addl(count, count);
2890 // Copy remaining characters.
2893 __ movb(kScratchRegister, Operand(src, 0));
2894 __ movb(Operand(dest, 0), kScratchRegister);
2898 __ j(not_zero, &loop);
2904 void SubStringStub::Generate(MacroAssembler* masm) {
2907 // Stack frame on entry.
2908 // rsp[0] : return address
2913 enum SubStringStubArgumentIndices {
2914 STRING_ARGUMENT_INDEX,
2915 FROM_ARGUMENT_INDEX,
2917 SUB_STRING_ARGUMENT_COUNT
2920 StackArgumentsAccessor args(rsp, SUB_STRING_ARGUMENT_COUNT,
2921 ARGUMENTS_DONT_CONTAIN_RECEIVER);
2923 // Make sure first argument is a string.
2924 __ movp(rax, args.GetArgumentOperand(STRING_ARGUMENT_INDEX));
2925 STATIC_ASSERT(kSmiTag == 0);
2926 __ testl(rax, Immediate(kSmiTagMask));
2927 __ j(zero, &runtime);
2928 Condition is_string = masm->IsObjectStringType(rax, rbx, rbx);
2929 __ j(NegateCondition(is_string), &runtime);
2932 // rbx: instance type
2933 // Calculate length of sub string using the smi values.
2934 __ movp(rcx, args.GetArgumentOperand(TO_ARGUMENT_INDEX));
2935 __ movp(rdx, args.GetArgumentOperand(FROM_ARGUMENT_INDEX));
2936 __ JumpUnlessBothNonNegativeSmi(rcx, rdx, &runtime);
2938 __ SmiSub(rcx, rcx, rdx); // Overflow doesn't happen.
2939 __ cmpp(rcx, FieldOperand(rax, String::kLengthOffset));
2940 Label not_original_string;
2941 // Shorter than original string's length: an actual substring.
2942 __ j(below, ¬_original_string, Label::kNear);
2943 // Longer than original string's length or negative: unsafe arguments.
2944 __ j(above, &runtime);
2945 // Return original string.
2946 Counters* counters = isolate()->counters();
2947 __ IncrementCounter(counters->sub_string_native(), 1);
2948 __ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
2949 __ bind(¬_original_string);
2952 __ SmiCompare(rcx, Smi::FromInt(1));
2953 __ j(equal, &single_char);
2955 __ SmiToInteger32(rcx, rcx);
2958 // rbx: instance type
2959 // rcx: sub string length
2960 // rdx: from index (smi)
2961 // Deal with different string types: update the index if necessary
2962 // and put the underlying string into edi.
2963 Label underlying_unpacked, sliced_string, seq_or_external_string;
2964 // If the string is not indirect, it can only be sequential or external.
2965 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
2966 STATIC_ASSERT(kIsIndirectStringMask != 0);
2967 __ testb(rbx, Immediate(kIsIndirectStringMask));
2968 __ j(zero, &seq_or_external_string, Label::kNear);
2970 __ testb(rbx, Immediate(kSlicedNotConsMask));
2971 __ j(not_zero, &sliced_string, Label::kNear);
2972 // Cons string. Check whether it is flat, then fetch first part.
2973 // Flat cons strings have an empty second part.
2974 __ CompareRoot(FieldOperand(rax, ConsString::kSecondOffset),
2975 Heap::kempty_stringRootIndex);
2976 __ j(not_equal, &runtime);
2977 __ movp(rdi, FieldOperand(rax, ConsString::kFirstOffset));
2978 // Update instance type.
2979 __ movp(rbx, FieldOperand(rdi, HeapObject::kMapOffset));
2980 __ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset));
2981 __ jmp(&underlying_unpacked, Label::kNear);
2983 __ bind(&sliced_string);
2984 // Sliced string. Fetch parent and correct start index by offset.
2985 __ addp(rdx, FieldOperand(rax, SlicedString::kOffsetOffset));
2986 __ movp(rdi, FieldOperand(rax, SlicedString::kParentOffset));
2987 // Update instance type.
2988 __ movp(rbx, FieldOperand(rdi, HeapObject::kMapOffset));
2989 __ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset));
2990 __ jmp(&underlying_unpacked, Label::kNear);
2992 __ bind(&seq_or_external_string);
2993 // Sequential or external string. Just move string to the correct register.
2996 __ bind(&underlying_unpacked);
2998 if (FLAG_string_slices) {
3000 // rdi: underlying subject string
3001 // rbx: instance type of underlying subject string
3002 // rdx: adjusted start index (smi)
3004 // If coming from the make_two_character_string path, the string
3005 // is too short to be sliced anyways.
3006 __ cmpp(rcx, Immediate(SlicedString::kMinLength));
3007 // Short slice. Copy instead of slicing.
3008 __ j(less, ©_routine);
3009 // Allocate new sliced string. At this point we do not reload the instance
3010 // type including the string encoding because we simply rely on the info
3011 // provided by the original string. It does not matter if the original
3012 // string's encoding is wrong because we always have to recheck encoding of
3013 // the newly created string's parent anyways due to externalized strings.
3014 Label two_byte_slice, set_slice_header;
3015 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3016 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3017 __ testb(rbx, Immediate(kStringEncodingMask));
3018 __ j(zero, &two_byte_slice, Label::kNear);
3019 __ AllocateOneByteSlicedString(rax, rbx, r14, &runtime);
3020 __ jmp(&set_slice_header, Label::kNear);
3021 __ bind(&two_byte_slice);
3022 __ AllocateTwoByteSlicedString(rax, rbx, r14, &runtime);
3023 __ bind(&set_slice_header);
3024 __ Integer32ToSmi(rcx, rcx);
3025 __ movp(FieldOperand(rax, SlicedString::kLengthOffset), rcx);
3026 __ movp(FieldOperand(rax, SlicedString::kHashFieldOffset),
3027 Immediate(String::kEmptyHashField));
3028 __ movp(FieldOperand(rax, SlicedString::kParentOffset), rdi);
3029 __ movp(FieldOperand(rax, SlicedString::kOffsetOffset), rdx);
3030 __ IncrementCounter(counters->sub_string_native(), 1);
3031 __ ret(3 * kPointerSize);
3033 __ bind(©_routine);
3036 // rdi: underlying subject string
3037 // rbx: instance type of underlying subject string
3038 // rdx: adjusted start index (smi)
3040 // The subject string can only be external or sequential string of either
3041 // encoding at this point.
3042 Label two_byte_sequential, sequential_string;
3043 STATIC_ASSERT(kExternalStringTag != 0);
3044 STATIC_ASSERT(kSeqStringTag == 0);
3045 __ testb(rbx, Immediate(kExternalStringTag));
3046 __ j(zero, &sequential_string);
3048 // Handle external string.
3049 // Rule out short external strings.
3050 STATIC_ASSERT(kShortExternalStringTag != 0);
3051 __ testb(rbx, Immediate(kShortExternalStringMask));
3052 __ j(not_zero, &runtime);
3053 __ movp(rdi, FieldOperand(rdi, ExternalString::kResourceDataOffset));
3054 // Move the pointer so that offset-wise, it looks like a sequential string.
3055 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3056 __ subp(rdi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3058 __ bind(&sequential_string);
3059 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3060 __ testb(rbx, Immediate(kStringEncodingMask));
3061 __ j(zero, &two_byte_sequential);
3063 // Allocate the result.
3064 __ AllocateOneByteString(rax, rcx, r11, r14, r15, &runtime);
3066 // rax: result string
3067 // rcx: result string length
3068 { // Locate character of sub string start.
3069 SmiIndex smi_as_index = masm->SmiToIndex(rdx, rdx, times_1);
3070 __ leap(r14, Operand(rdi, smi_as_index.reg, smi_as_index.scale,
3071 SeqOneByteString::kHeaderSize - kHeapObjectTag));
3073 // Locate first character of result.
3074 __ leap(rdi, FieldOperand(rax, SeqOneByteString::kHeaderSize));
3076 // rax: result string
3077 // rcx: result length
3078 // r14: first character of result
3079 // rsi: character of sub string start
3080 StringHelper::GenerateCopyCharacters(
3081 masm, rdi, r14, rcx, String::ONE_BYTE_ENCODING);
3082 __ IncrementCounter(counters->sub_string_native(), 1);
3083 __ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
3085 __ bind(&two_byte_sequential);
3086 // Allocate the result.
3087 __ AllocateTwoByteString(rax, rcx, r11, r14, r15, &runtime);
3089 // rax: result string
3090 // rcx: result string length
3091 { // Locate character of sub string start.
3092 SmiIndex smi_as_index = masm->SmiToIndex(rdx, rdx, times_2);
3093 __ leap(r14, Operand(rdi, smi_as_index.reg, smi_as_index.scale,
3094 SeqOneByteString::kHeaderSize - kHeapObjectTag));
3096 // Locate first character of result.
3097 __ leap(rdi, FieldOperand(rax, SeqTwoByteString::kHeaderSize));
3099 // rax: result string
3100 // rcx: result length
3101 // rdi: first character of result
3102 // r14: character of sub string start
3103 StringHelper::GenerateCopyCharacters(
3104 masm, rdi, r14, rcx, String::TWO_BYTE_ENCODING);
3105 __ IncrementCounter(counters->sub_string_native(), 1);
3106 __ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
3108 // Just jump to runtime to create the sub string.
3110 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3112 __ bind(&single_char);
3114 // rbx: instance type
3115 // rcx: sub string length (smi)
3116 // rdx: from index (smi)
3117 StringCharAtGenerator generator(rax, rdx, rcx, rax, &runtime, &runtime,
3118 &runtime, STRING_INDEX_IS_NUMBER,
3119 RECEIVER_IS_STRING);
3120 generator.GenerateFast(masm);
3121 __ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
3122 generator.SkipSlow(masm, &runtime);
3126 void ToNumberStub::Generate(MacroAssembler* masm) {
3127 // The ToNumber stub takes one argument in rax.
3129 __ JumpIfNotSmi(rax, ¬_smi, Label::kNear);
3133 Label not_heap_number;
3134 __ CompareRoot(FieldOperand(rax, HeapObject::kMapOffset),
3135 Heap::kHeapNumberMapRootIndex);
3136 __ j(not_equal, ¬_heap_number, Label::kNear);
3138 __ bind(¬_heap_number);
3140 Label not_string, slow_string;
3141 __ CmpObjectType(rax, FIRST_NONSTRING_TYPE, rdi);
3144 __ j(above_equal, ¬_string, Label::kNear);
3145 // Check if string has a cached array index.
3146 __ testl(FieldOperand(rax, String::kHashFieldOffset),
3147 Immediate(String::kContainsCachedArrayIndexMask));
3148 __ j(not_zero, &slow_string, Label::kNear);
3149 __ movl(rax, FieldOperand(rax, String::kHashFieldOffset));
3150 __ IndexFromHash(rax, rax);
3152 __ bind(&slow_string);
3153 __ PopReturnAddressTo(rcx); // Pop return address.
3154 __ Push(rax); // Push argument.
3155 __ PushReturnAddressFrom(rcx); // Push return address.
3156 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3157 __ bind(¬_string);
3160 __ CmpInstanceType(rdi, ODDBALL_TYPE);
3161 __ j(not_equal, ¬_oddball, Label::kNear);
3162 __ movp(rax, FieldOperand(rax, Oddball::kToNumberOffset));
3164 __ bind(¬_oddball);
3166 __ PopReturnAddressTo(rcx); // Pop return address.
3167 __ Push(rax); // Push argument.
3168 __ PushReturnAddressFrom(rcx); // Push return address.
3169 __ TailCallRuntime(Runtime::kToNumber, 1, 1);
3173 void ToStringStub::Generate(MacroAssembler* masm) {
3174 // The ToString stub takes one argument in rax.
3176 __ JumpIfSmi(rax, &is_number, Label::kNear);
3179 __ CmpObjectType(rax, FIRST_NONSTRING_TYPE, rdi);
3181 // rdi: receiver map
3182 __ j(above_equal, ¬_string, Label::kNear);
3184 __ bind(¬_string);
3186 Label not_heap_number;
3187 __ CompareRoot(rax, Heap::kHeapNumberMapRootIndex);
3188 __ j(not_equal, ¬_heap_number, Label::kNear);
3189 __ bind(&is_number);
3190 NumberToStringStub stub(isolate());
3191 __ TailCallStub(&stub);
3192 __ bind(¬_heap_number);
3195 __ CmpInstanceType(rdi, ODDBALL_TYPE);
3196 __ j(not_equal, ¬_oddball, Label::kNear);
3197 __ movp(rax, FieldOperand(rax, Oddball::kToStringOffset));
3199 __ bind(¬_oddball);
3201 __ PopReturnAddressTo(rcx); // Pop return address.
3202 __ Push(rax); // Push argument.
3203 __ PushReturnAddressFrom(rcx); // Push return address.
3204 __ TailCallRuntime(Runtime::kToString, 1, 1);
3208 void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
3212 Register scratch2) {
3213 Register length = scratch1;
3216 Label check_zero_length;
3217 __ movp(length, FieldOperand(left, String::kLengthOffset));
3218 __ SmiCompare(length, FieldOperand(right, String::kLengthOffset));
3219 __ j(equal, &check_zero_length, Label::kNear);
3220 __ Move(rax, Smi::FromInt(NOT_EQUAL));
3223 // Check if the length is zero.
3224 Label compare_chars;
3225 __ bind(&check_zero_length);
3226 STATIC_ASSERT(kSmiTag == 0);
3228 __ j(not_zero, &compare_chars, Label::kNear);
3229 __ Move(rax, Smi::FromInt(EQUAL));
3232 // Compare characters.
3233 __ bind(&compare_chars);
3234 Label strings_not_equal;
3235 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2,
3236 &strings_not_equal, Label::kNear);
3238 // Characters are equal.
3239 __ Move(rax, Smi::FromInt(EQUAL));
3242 // Characters are not equal.
3243 __ bind(&strings_not_equal);
3244 __ Move(rax, Smi::FromInt(NOT_EQUAL));
3249 void StringHelper::GenerateCompareFlatOneByteStrings(
3250 MacroAssembler* masm, Register left, Register right, Register scratch1,
3251 Register scratch2, Register scratch3, Register scratch4) {
3252 // Ensure that you can always subtract a string length from a non-negative
3253 // number (e.g. another length).
3254 STATIC_ASSERT(String::kMaxLength < 0x7fffffff);
3256 // Find minimum length and length difference.
3257 __ movp(scratch1, FieldOperand(left, String::kLengthOffset));
3258 __ movp(scratch4, scratch1);
3261 FieldOperand(right, String::kLengthOffset));
3262 // Register scratch4 now holds left.length - right.length.
3263 const Register length_difference = scratch4;
3265 __ j(less, &left_shorter, Label::kNear);
3266 // The right string isn't longer that the left one.
3267 // Get the right string's length by subtracting the (non-negative) difference
3268 // from the left string's length.
3269 __ SmiSub(scratch1, scratch1, length_difference);
3270 __ bind(&left_shorter);
3271 // Register scratch1 now holds Min(left.length, right.length).
3272 const Register min_length = scratch1;
3274 Label compare_lengths;
3275 // If min-length is zero, go directly to comparing lengths.
3276 __ SmiTest(min_length);
3277 __ j(zero, &compare_lengths, Label::kNear);
3280 Label result_not_equal;
3281 GenerateOneByteCharsCompareLoop(
3282 masm, left, right, min_length, scratch2, &result_not_equal,
3283 // In debug-code mode, SmiTest below might push
3284 // the target label outside the near range.
3287 // Completed loop without finding different characters.
3288 // Compare lengths (precomputed).
3289 __ bind(&compare_lengths);
3290 __ SmiTest(length_difference);
3291 Label length_not_equal;
3292 __ j(not_zero, &length_not_equal, Label::kNear);
3295 __ Move(rax, Smi::FromInt(EQUAL));
3298 Label result_greater;
3300 __ bind(&length_not_equal);
3301 __ j(greater, &result_greater, Label::kNear);
3302 __ jmp(&result_less, Label::kNear);
3303 __ bind(&result_not_equal);
3304 // Unequal comparison of left to right, either character or length.
3305 __ j(above, &result_greater, Label::kNear);
3306 __ bind(&result_less);
3309 __ Move(rax, Smi::FromInt(LESS));
3312 // Result is GREATER.
3313 __ bind(&result_greater);
3314 __ Move(rax, Smi::FromInt(GREATER));
3319 void StringHelper::GenerateOneByteCharsCompareLoop(
3320 MacroAssembler* masm, Register left, Register right, Register length,
3321 Register scratch, Label* chars_not_equal, Label::Distance near_jump) {
3322 // Change index to run from -length to -1 by adding length to string
3323 // start. This means that loop ends when index reaches zero, which
3324 // doesn't need an additional compare.
3325 __ SmiToInteger32(length, length);
3327 FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize));
3329 FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize));
3331 Register index = length; // index = -length;
3336 __ movb(scratch, Operand(left, index, times_1, 0));
3337 __ cmpb(scratch, Operand(right, index, times_1, 0));
3338 __ j(not_equal, chars_not_equal, near_jump);
3340 __ j(not_zero, &loop);
3344 void StringCompareStub::Generate(MacroAssembler* masm) {
3347 // Stack frame on entry.
3348 // rsp[0] : return address
3349 // rsp[8] : right string
3350 // rsp[16] : left string
3352 StackArgumentsAccessor args(rsp, 2, ARGUMENTS_DONT_CONTAIN_RECEIVER);
3353 __ movp(rdx, args.GetArgumentOperand(0)); // left
3354 __ movp(rax, args.GetArgumentOperand(1)); // right
3356 // Check for identity.
3359 __ j(not_equal, ¬_same, Label::kNear);
3360 __ Move(rax, Smi::FromInt(EQUAL));
3361 Counters* counters = isolate()->counters();
3362 __ IncrementCounter(counters->string_compare_native(), 1);
3363 __ ret(2 * kPointerSize);
3367 // Check that both are sequential one-byte strings.
3368 __ JumpIfNotBothSequentialOneByteStrings(rdx, rax, rcx, rbx, &runtime);
3370 // Inline comparison of one-byte strings.
3371 __ IncrementCounter(counters->string_compare_native(), 1);
3372 // Drop arguments from the stack
3373 __ PopReturnAddressTo(rcx);
3374 __ addp(rsp, Immediate(2 * kPointerSize));
3375 __ PushReturnAddressFrom(rcx);
3376 StringHelper::GenerateCompareFlatOneByteStrings(masm, rdx, rax, rcx, rbx, rdi,
3379 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
3380 // tagged as a small integer.
3382 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3386 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3387 // ----------- S t a t e -------------
3390 // -- rsp[0] : return address
3391 // -----------------------------------
3393 // Load rcx with the allocation site. We stick an undefined dummy value here
3394 // and replace it with the real allocation site later when we instantiate this
3395 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3396 __ Move(rcx, handle(isolate()->heap()->undefined_value()));
3398 // Make sure that we actually patched the allocation site.
3399 if (FLAG_debug_code) {
3400 __ testb(rcx, Immediate(kSmiTagMask));
3401 __ Assert(not_equal, kExpectedAllocationSite);
3402 __ Cmp(FieldOperand(rcx, HeapObject::kMapOffset),
3403 isolate()->factory()->allocation_site_map());
3404 __ Assert(equal, kExpectedAllocationSite);
3407 // Tail call into the stub that handles binary operations with allocation
3409 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3410 __ TailCallStub(&stub);
3414 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3415 DCHECK(state() == CompareICState::SMI);
3417 __ JumpIfNotBothSmi(rdx, rax, &miss, Label::kNear);
3419 if (GetCondition() == equal) {
3420 // For equality we do not care about the sign of the result.
3425 __ j(no_overflow, &done, Label::kNear);
3426 // Correct sign of result in case of overflow.
3438 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3439 DCHECK(state() == CompareICState::NUMBER);
3442 Label unordered, maybe_undefined1, maybe_undefined2;
3445 if (left() == CompareICState::SMI) {
3446 __ JumpIfNotSmi(rdx, &miss);
3448 if (right() == CompareICState::SMI) {
3449 __ JumpIfNotSmi(rax, &miss);
3452 // Load left and right operand.
3453 Label done, left, left_smi, right_smi;
3454 __ JumpIfSmi(rax, &right_smi, Label::kNear);
3455 __ CompareMap(rax, isolate()->factory()->heap_number_map());
3456 __ j(not_equal, &maybe_undefined1, Label::kNear);
3457 __ movsd(xmm1, FieldOperand(rax, HeapNumber::kValueOffset));
3458 __ jmp(&left, Label::kNear);
3459 __ bind(&right_smi);
3460 __ SmiToInteger32(rcx, rax); // Can't clobber rax yet.
3461 __ Cvtlsi2sd(xmm1, rcx);
3464 __ JumpIfSmi(rdx, &left_smi, Label::kNear);
3465 __ CompareMap(rdx, isolate()->factory()->heap_number_map());
3466 __ j(not_equal, &maybe_undefined2, Label::kNear);
3467 __ movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset));
3470 __ SmiToInteger32(rcx, rdx); // Can't clobber rdx yet.
3471 __ Cvtlsi2sd(xmm0, rcx);
3475 __ ucomisd(xmm0, xmm1);
3477 // Don't base result on EFLAGS when a NaN is involved.
3478 __ j(parity_even, &unordered, Label::kNear);
3480 // Return a result of -1, 0, or 1, based on EFLAGS.
3481 // Performing mov, because xor would destroy the flag register.
3482 __ movl(rax, Immediate(0));
3483 __ movl(rcx, Immediate(0));
3484 __ setcc(above, rax); // Add one to zero if carry clear and not equal.
3485 __ sbbp(rax, rcx); // Subtract one if below (aka. carry set).
3488 __ bind(&unordered);
3489 __ bind(&generic_stub);
3490 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3491 CompareICState::GENERIC, CompareICState::GENERIC);
3492 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET);
3494 __ bind(&maybe_undefined1);
3495 if (Token::IsOrderedRelationalCompareOp(op())) {
3496 __ Cmp(rax, isolate()->factory()->undefined_value());
3497 __ j(not_equal, &miss);
3498 __ JumpIfSmi(rdx, &unordered);
3499 __ CmpObjectType(rdx, HEAP_NUMBER_TYPE, rcx);
3500 __ j(not_equal, &maybe_undefined2, Label::kNear);
3504 __ bind(&maybe_undefined2);
3505 if (Token::IsOrderedRelationalCompareOp(op())) {
3506 __ Cmp(rdx, isolate()->factory()->undefined_value());
3507 __ j(equal, &unordered);
3515 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3516 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3517 DCHECK(GetCondition() == equal);
3519 // Registers containing left and right operands respectively.
3520 Register left = rdx;
3521 Register right = rax;
3522 Register tmp1 = rcx;
3523 Register tmp2 = rbx;
3525 // Check that both operands are heap objects.
3527 Condition cond = masm->CheckEitherSmi(left, right, tmp1);
3528 __ j(cond, &miss, Label::kNear);
3530 // Check that both operands are internalized strings.
3531 __ movp(tmp1, FieldOperand(left, HeapObject::kMapOffset));
3532 __ movp(tmp2, FieldOperand(right, HeapObject::kMapOffset));
3533 __ movzxbp(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
3534 __ movzxbp(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
3535 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3537 __ testb(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask));
3538 __ j(not_zero, &miss, Label::kNear);
3540 // Internalized strings are compared by identity.
3542 __ cmpp(left, right);
3543 // Make sure rax is non-zero. At this point input operands are
3544 // guaranteed to be non-zero.
3545 DCHECK(right.is(rax));
3546 __ j(not_equal, &done, Label::kNear);
3547 STATIC_ASSERT(EQUAL == 0);
3548 STATIC_ASSERT(kSmiTag == 0);
3549 __ Move(rax, Smi::FromInt(EQUAL));
3558 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3559 DCHECK(state() == CompareICState::UNIQUE_NAME);
3560 DCHECK(GetCondition() == equal);
3562 // Registers containing left and right operands respectively.
3563 Register left = rdx;
3564 Register right = rax;
3565 Register tmp1 = rcx;
3566 Register tmp2 = rbx;
3568 // Check that both operands are heap objects.
3570 Condition cond = masm->CheckEitherSmi(left, right, tmp1);
3571 __ j(cond, &miss, Label::kNear);
3573 // Check that both operands are unique names. This leaves the instance
3574 // types loaded in tmp1 and tmp2.
3575 __ movp(tmp1, FieldOperand(left, HeapObject::kMapOffset));
3576 __ movp(tmp2, FieldOperand(right, HeapObject::kMapOffset));
3577 __ movzxbp(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
3578 __ movzxbp(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
3580 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss, Label::kNear);
3581 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss, Label::kNear);
3583 // Unique names are compared by identity.
3585 __ cmpp(left, right);
3586 // Make sure rax is non-zero. At this point input operands are
3587 // guaranteed to be non-zero.
3588 DCHECK(right.is(rax));
3589 __ j(not_equal, &done, Label::kNear);
3590 STATIC_ASSERT(EQUAL == 0);
3591 STATIC_ASSERT(kSmiTag == 0);
3592 __ Move(rax, Smi::FromInt(EQUAL));
3601 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3602 DCHECK(state() == CompareICState::STRING);
3605 bool equality = Token::IsEqualityOp(op());
3607 // Registers containing left and right operands respectively.
3608 Register left = rdx;
3609 Register right = rax;
3610 Register tmp1 = rcx;
3611 Register tmp2 = rbx;
3612 Register tmp3 = rdi;
3614 // Check that both operands are heap objects.
3615 Condition cond = masm->CheckEitherSmi(left, right, tmp1);
3618 // Check that both operands are strings. This leaves the instance
3619 // types loaded in tmp1 and tmp2.
3620 __ movp(tmp1, FieldOperand(left, HeapObject::kMapOffset));
3621 __ movp(tmp2, FieldOperand(right, HeapObject::kMapOffset));
3622 __ movzxbp(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
3623 __ movzxbp(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
3624 __ movp(tmp3, tmp1);
3625 STATIC_ASSERT(kNotStringTag != 0);
3627 __ testb(tmp3, Immediate(kIsNotStringMask));
3628 __ j(not_zero, &miss);
3630 // Fast check for identical strings.
3632 __ cmpp(left, right);
3633 __ j(not_equal, ¬_same, Label::kNear);
3634 STATIC_ASSERT(EQUAL == 0);
3635 STATIC_ASSERT(kSmiTag == 0);
3636 __ Move(rax, Smi::FromInt(EQUAL));
3639 // Handle not identical strings.
3642 // Check that both strings are internalized strings. If they are, we're done
3643 // because we already know they are not identical. We also know they are both
3647 STATIC_ASSERT(kInternalizedTag == 0);
3649 __ testb(tmp1, Immediate(kIsNotInternalizedMask));
3650 __ j(not_zero, &do_compare, Label::kNear);
3651 // Make sure rax is non-zero. At this point input operands are
3652 // guaranteed to be non-zero.
3653 DCHECK(right.is(rax));
3655 __ bind(&do_compare);
3658 // Check that both strings are sequential one-byte.
3660 __ JumpIfNotBothSequentialOneByteStrings(left, right, tmp1, tmp2, &runtime);
3662 // Compare flat one-byte strings. Returns when done.
3664 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1,
3667 StringHelper::GenerateCompareFlatOneByteStrings(
3668 masm, left, right, tmp1, tmp2, tmp3, kScratchRegister);
3671 // Handle more complex cases in runtime.
3673 __ PopReturnAddressTo(tmp1);
3676 __ PushReturnAddressFrom(tmp1);
3678 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3680 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3688 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3689 DCHECK(state() == CompareICState::OBJECT);
3691 Condition either_smi = masm->CheckEitherSmi(rdx, rax);
3692 __ j(either_smi, &miss, Label::kNear);
3694 __ CmpObjectType(rax, JS_OBJECT_TYPE, rcx);
3695 __ j(not_equal, &miss, Label::kNear);
3696 __ CmpObjectType(rdx, JS_OBJECT_TYPE, rcx);
3697 __ j(not_equal, &miss, Label::kNear);
3699 DCHECK(GetCondition() == equal);
3708 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3710 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3711 Condition either_smi = masm->CheckEitherSmi(rdx, rax);
3712 __ j(either_smi, &miss, Label::kNear);
3714 __ GetWeakValue(rdi, cell);
3715 __ movp(rcx, FieldOperand(rax, HeapObject::kMapOffset));
3716 __ movp(rbx, FieldOperand(rdx, HeapObject::kMapOffset));
3718 __ j(not_equal, &miss, Label::kNear);
3720 __ j(not_equal, &miss, Label::kNear);
3730 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3732 // Call the runtime system in a fresh internal frame.
3733 FrameScope scope(masm, StackFrame::INTERNAL);
3738 __ Push(Smi::FromInt(op()));
3739 __ CallRuntime(Runtime::kCompareIC_Miss, 3);
3741 // Compute the entry point of the rewritten stub.
3742 __ leap(rdi, FieldOperand(rax, Code::kHeaderSize));
3747 // Do a tail call to the rewritten stub.
3752 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3755 Register properties,
3758 DCHECK(name->IsUniqueName());
3759 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3760 // not equal to the name and kProbes-th slot is not used (its name is the
3761 // undefined value), it guarantees the hash table doesn't contain the
3762 // property. It's true even if some slots represent deleted properties
3763 // (their names are the hole value).
3764 for (int i = 0; i < kInlinedProbes; i++) {
3765 // r0 points to properties hash.
3766 // Compute the masked index: (hash + i + i * i) & mask.
3767 Register index = r0;
3768 // Capacity is smi 2^n.
3769 __ SmiToInteger32(index, FieldOperand(properties, kCapacityOffset));
3772 Immediate(name->Hash() + NameDictionary::GetProbeOffset(i)));
3774 // Scale the index by multiplying by the entry size.
3775 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3776 __ leap(index, Operand(index, index, times_2, 0)); // index *= 3.
3778 Register entity_name = r0;
3779 // Having undefined at this place means the name is not contained.
3780 STATIC_ASSERT(kSmiTagSize == 1);
3781 __ movp(entity_name, Operand(properties,
3784 kElementsStartOffset - kHeapObjectTag));
3785 __ Cmp(entity_name, masm->isolate()->factory()->undefined_value());
3788 // Stop if found the property.
3789 __ Cmp(entity_name, Handle<Name>(name));
3793 // Check for the hole and skip.
3794 __ CompareRoot(entity_name, Heap::kTheHoleValueRootIndex);
3795 __ j(equal, &good, Label::kNear);
3797 // Check if the entry name is not a unique name.
3798 __ movp(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset));
3799 __ JumpIfNotUniqueNameInstanceType(
3800 FieldOperand(entity_name, Map::kInstanceTypeOffset), miss);
3804 NameDictionaryLookupStub stub(masm->isolate(), properties, r0, r0,
3806 __ Push(Handle<Object>(name));
3807 __ Push(Immediate(name->Hash()));
3810 __ j(not_zero, miss);
3815 // Probe the name dictionary in the |elements| register. Jump to the
3816 // |done| label if a property with the given name is found leaving the
3817 // index into the dictionary in |r1|. Jump to the |miss| label
3819 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3826 DCHECK(!elements.is(r0));
3827 DCHECK(!elements.is(r1));
3828 DCHECK(!name.is(r0));
3829 DCHECK(!name.is(r1));
3831 __ AssertName(name);
3833 __ SmiToInteger32(r0, FieldOperand(elements, kCapacityOffset));
3836 for (int i = 0; i < kInlinedProbes; i++) {
3837 // Compute the masked index: (hash + i + i * i) & mask.
3838 __ movl(r1, FieldOperand(name, Name::kHashFieldOffset));
3839 __ shrl(r1, Immediate(Name::kHashShift));
3841 __ addl(r1, Immediate(NameDictionary::GetProbeOffset(i)));
3845 // Scale the index by multiplying by the entry size.
3846 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3847 __ leap(r1, Operand(r1, r1, times_2, 0)); // r1 = r1 * 3
3849 // Check if the key is identical to the name.
3850 __ cmpp(name, Operand(elements, r1, times_pointer_size,
3851 kElementsStartOffset - kHeapObjectTag));
3855 NameDictionaryLookupStub stub(masm->isolate(), elements, r0, r1,
3858 __ movl(r0, FieldOperand(name, Name::kHashFieldOffset));
3859 __ shrl(r0, Immediate(Name::kHashShift));
3869 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
3870 // This stub overrides SometimesSetsUpAFrame() to return false. That means
3871 // we cannot call anything that could cause a GC from this stub.
3872 // Stack frame on entry:
3873 // rsp[0 * kPointerSize] : return address.
3874 // rsp[1 * kPointerSize] : key's hash.
3875 // rsp[2 * kPointerSize] : key.
3877 // dictionary_: NameDictionary to probe.
3878 // result_: used as scratch.
3879 // index_: will hold an index of entry if lookup is successful.
3880 // might alias with result_.
3882 // result_ is zero if lookup failed, non zero otherwise.
3884 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
3886 Register scratch = result();
3888 __ SmiToInteger32(scratch, FieldOperand(dictionary(), kCapacityOffset));
3892 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3893 // not equal to the name and kProbes-th slot is not used (its name is the
3894 // undefined value), it guarantees the hash table doesn't contain the
3895 // property. It's true even if some slots represent deleted properties
3896 // (their names are the null value).
3897 StackArgumentsAccessor args(rsp, 2, ARGUMENTS_DONT_CONTAIN_RECEIVER,
3899 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
3900 // Compute the masked index: (hash + i + i * i) & mask.
3901 __ movp(scratch, args.GetArgumentOperand(1));
3903 __ addl(scratch, Immediate(NameDictionary::GetProbeOffset(i)));
3905 __ andp(scratch, Operand(rsp, 0));
3907 // Scale the index by multiplying by the entry size.
3908 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3909 __ leap(index(), Operand(scratch, scratch, times_2, 0)); // index *= 3.
3911 // Having undefined at this place means the name is not contained.
3912 __ movp(scratch, Operand(dictionary(), index(), times_pointer_size,
3913 kElementsStartOffset - kHeapObjectTag));
3915 __ Cmp(scratch, isolate()->factory()->undefined_value());
3916 __ j(equal, ¬_in_dictionary);
3918 // Stop if found the property.
3919 __ cmpp(scratch, args.GetArgumentOperand(0));
3920 __ j(equal, &in_dictionary);
3922 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
3923 // If we hit a key that is not a unique name during negative
3924 // lookup we have to bailout as this key might be equal to the
3925 // key we are looking for.
3927 // Check if the entry name is not a unique name.
3928 __ movp(scratch, FieldOperand(scratch, HeapObject::kMapOffset));
3929 __ JumpIfNotUniqueNameInstanceType(
3930 FieldOperand(scratch, Map::kInstanceTypeOffset),
3931 &maybe_in_dictionary);
3935 __ bind(&maybe_in_dictionary);
3936 // If we are doing negative lookup then probing failure should be
3937 // treated as a lookup success. For positive lookup probing failure
3938 // should be treated as lookup failure.
3939 if (mode() == POSITIVE_LOOKUP) {
3940 __ movp(scratch, Immediate(0));
3942 __ ret(2 * kPointerSize);
3945 __ bind(&in_dictionary);
3946 __ movp(scratch, Immediate(1));
3948 __ ret(2 * kPointerSize);
3950 __ bind(¬_in_dictionary);
3951 __ movp(scratch, Immediate(0));
3953 __ ret(2 * kPointerSize);
3957 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
3959 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
3961 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
3966 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
3967 // the value has just been written into the object, now this stub makes sure
3968 // we keep the GC informed. The word in the object where the value has been
3969 // written is in the address register.
3970 void RecordWriteStub::Generate(MacroAssembler* masm) {
3971 Label skip_to_incremental_noncompacting;
3972 Label skip_to_incremental_compacting;
3974 // The first two instructions are generated with labels so as to get the
3975 // offset fixed up correctly by the bind(Label*) call. We patch it back and
3976 // forth between a compare instructions (a nop in this position) and the
3977 // real branch when we start and stop incremental heap marking.
3978 // See RecordWriteStub::Patch for details.
3979 __ jmp(&skip_to_incremental_noncompacting, Label::kNear);
3980 __ jmp(&skip_to_incremental_compacting, Label::kFar);
3982 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3983 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
3984 MacroAssembler::kReturnAtEnd);
3989 __ bind(&skip_to_incremental_noncompacting);
3990 GenerateIncremental(masm, INCREMENTAL);
3992 __ bind(&skip_to_incremental_compacting);
3993 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
3995 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
3996 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
3997 masm->set_byte_at(0, kTwoByteNopInstruction);
3998 masm->set_byte_at(2, kFiveByteNopInstruction);
4002 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4005 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4006 Label dont_need_remembered_set;
4008 __ movp(regs_.scratch0(), Operand(regs_.address(), 0));
4009 __ JumpIfNotInNewSpace(regs_.scratch0(),
4011 &dont_need_remembered_set);
4013 __ CheckPageFlag(regs_.object(),
4015 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4017 &dont_need_remembered_set);
4019 // First notify the incremental marker if necessary, then update the
4021 CheckNeedsToInformIncrementalMarker(
4022 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4023 InformIncrementalMarker(masm);
4024 regs_.Restore(masm);
4025 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4026 MacroAssembler::kReturnAtEnd);
4028 __ bind(&dont_need_remembered_set);
4031 CheckNeedsToInformIncrementalMarker(
4032 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4033 InformIncrementalMarker(masm);
4034 regs_.Restore(masm);
4039 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4040 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4042 arg_reg_1.is(regs_.address()) ? kScratchRegister : regs_.address();
4043 DCHECK(!address.is(regs_.object()));
4044 DCHECK(!address.is(arg_reg_1));
4045 __ Move(address, regs_.address());
4046 __ Move(arg_reg_1, regs_.object());
4047 // TODO(gc) Can we just set address arg2 in the beginning?
4048 __ Move(arg_reg_2, address);
4049 __ LoadAddress(arg_reg_3,
4050 ExternalReference::isolate_address(isolate()));
4051 int argument_count = 3;
4053 AllowExternalCallThatCantCauseGC scope(masm);
4054 __ PrepareCallCFunction(argument_count);
4056 ExternalReference::incremental_marking_record_write_function(isolate()),
4058 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4062 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4063 MacroAssembler* masm,
4064 OnNoNeedToInformIncrementalMarker on_no_need,
4067 Label need_incremental;
4068 Label need_incremental_pop_object;
4070 __ movp(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask));
4071 __ andp(regs_.scratch0(), regs_.object());
4072 __ movp(regs_.scratch1(),
4073 Operand(regs_.scratch0(),
4074 MemoryChunk::kWriteBarrierCounterOffset));
4075 __ subp(regs_.scratch1(), Immediate(1));
4076 __ movp(Operand(regs_.scratch0(),
4077 MemoryChunk::kWriteBarrierCounterOffset),
4079 __ j(negative, &need_incremental);
4081 // Let's look at the color of the object: If it is not black we don't have
4082 // to inform the incremental marker.
4083 __ JumpIfBlack(regs_.object(),
4089 regs_.Restore(masm);
4090 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4091 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4092 MacroAssembler::kReturnAtEnd);
4099 // Get the value from the slot.
4100 __ movp(regs_.scratch0(), Operand(regs_.address(), 0));
4102 if (mode == INCREMENTAL_COMPACTION) {
4103 Label ensure_not_white;
4105 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4106 regs_.scratch1(), // Scratch.
4107 MemoryChunk::kEvacuationCandidateMask,
4112 __ CheckPageFlag(regs_.object(),
4113 regs_.scratch1(), // Scratch.
4114 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4118 __ bind(&ensure_not_white);
4121 // We need an extra register for this, so we push the object register
4123 __ Push(regs_.object());
4124 __ EnsureNotWhite(regs_.scratch0(), // The value.
4125 regs_.scratch1(), // Scratch.
4126 regs_.object(), // Scratch.
4127 &need_incremental_pop_object,
4129 __ Pop(regs_.object());
4131 regs_.Restore(masm);
4132 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4133 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4134 MacroAssembler::kReturnAtEnd);
4139 __ bind(&need_incremental_pop_object);
4140 __ Pop(regs_.object());
4142 __ bind(&need_incremental);
4144 // Fall through when we need to inform the incremental marker.
4148 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4149 // ----------- S t a t e -------------
4150 // -- rax : element value to store
4151 // -- rcx : element index as smi
4152 // -- rsp[0] : return address
4153 // -- rsp[8] : array literal index in function
4154 // -- rsp[16] : array literal
4155 // clobbers rbx, rdx, rdi
4156 // -----------------------------------
4159 Label double_elements;
4161 Label slow_elements;
4162 Label fast_elements;
4164 // Get array literal index, array literal and its map.
4165 StackArgumentsAccessor args(rsp, 2, ARGUMENTS_DONT_CONTAIN_RECEIVER);
4166 __ movp(rdx, args.GetArgumentOperand(1));
4167 __ movp(rbx, args.GetArgumentOperand(0));
4168 __ movp(rdi, FieldOperand(rbx, JSObject::kMapOffset));
4170 __ CheckFastElements(rdi, &double_elements);
4172 // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS
4173 __ JumpIfSmi(rax, &smi_element);
4174 __ CheckFastSmiElements(rdi, &fast_elements);
4176 // Store into the array literal requires a elements transition. Call into
4179 __ bind(&slow_elements);
4180 __ PopReturnAddressTo(rdi);
4184 __ movp(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
4185 __ Push(FieldOperand(rbx, JSFunction::kLiteralsOffset));
4187 __ PushReturnAddressFrom(rdi);
4188 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4190 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4191 __ bind(&fast_elements);
4192 __ SmiToInteger32(kScratchRegister, rcx);
4193 __ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset));
4194 __ leap(rcx, FieldOperand(rbx, kScratchRegister, times_pointer_size,
4195 FixedArrayBase::kHeaderSize));
4196 __ movp(Operand(rcx, 0), rax);
4197 // Update the write barrier for the array store.
4198 __ RecordWrite(rbx, rcx, rax,
4200 EMIT_REMEMBERED_SET,
4204 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or
4205 // FAST_*_ELEMENTS, and value is Smi.
4206 __ bind(&smi_element);
4207 __ SmiToInteger32(kScratchRegister, rcx);
4208 __ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset));
4209 __ movp(FieldOperand(rbx, kScratchRegister, times_pointer_size,
4210 FixedArrayBase::kHeaderSize), rax);
4213 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
4214 __ bind(&double_elements);
4216 __ movp(r9, FieldOperand(rbx, JSObject::kElementsOffset));
4217 __ SmiToInteger32(r11, rcx);
4218 __ StoreNumberToDoubleElements(rax,
4227 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4228 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4229 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4230 int parameter_count_offset =
4231 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4232 __ movp(rbx, MemOperand(rbp, parameter_count_offset));
4233 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4234 __ PopReturnAddressTo(rcx);
4235 int additional_offset =
4236 function_mode() == JS_FUNCTION_STUB_MODE ? kPointerSize : 0;
4237 __ leap(rsp, MemOperand(rsp, rbx, times_pointer_size, additional_offset));
4238 __ jmp(rcx); // Return to IC Miss stub, continuation still on stack.
4242 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4243 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4244 LoadICStub stub(isolate(), state());
4245 stub.GenerateForTrampoline(masm);
4249 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4250 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4251 KeyedLoadICStub stub(isolate(), state());
4252 stub.GenerateForTrampoline(masm);
4256 static void HandleArrayCases(MacroAssembler* masm, Register feedback,
4257 Register receiver_map, Register scratch1,
4258 Register scratch2, Register scratch3,
4259 bool is_polymorphic, Label* miss) {
4260 // feedback initially contains the feedback array
4261 Label next_loop, prepare_next;
4262 Label start_polymorphic;
4264 Register counter = scratch1;
4265 Register length = scratch2;
4266 Register cached_map = scratch3;
4268 __ movp(cached_map, FieldOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4269 __ cmpp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4270 __ j(not_equal, &start_polymorphic);
4272 // found, now call handler.
4273 Register handler = feedback;
4274 __ movp(handler, FieldOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4275 __ leap(handler, FieldOperand(handler, Code::kHeaderSize));
4278 // Polymorphic, we have to loop from 2 to N
4279 __ bind(&start_polymorphic);
4280 __ SmiToInteger32(length, FieldOperand(feedback, FixedArray::kLengthOffset));
4281 if (!is_polymorphic) {
4282 // If the IC could be monomorphic we have to make sure we don't go past the
4283 // end of the feedback array.
4284 __ cmpl(length, Immediate(2));
4287 __ movl(counter, Immediate(2));
4289 __ bind(&next_loop);
4290 __ movp(cached_map, FieldOperand(feedback, counter, times_pointer_size,
4291 FixedArray::kHeaderSize));
4292 __ cmpp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4293 __ j(not_equal, &prepare_next);
4294 __ movp(handler, FieldOperand(feedback, counter, times_pointer_size,
4295 FixedArray::kHeaderSize + kPointerSize));
4296 __ leap(handler, FieldOperand(handler, Code::kHeaderSize));
4299 __ bind(&prepare_next);
4300 __ addl(counter, Immediate(2));
4301 __ cmpl(counter, length);
4302 __ j(less, &next_loop);
4304 // We exhausted our array of map handler pairs.
4309 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4310 Register receiver_map, Register feedback,
4311 Register vector, Register integer_slot,
4312 Label* compare_map, Label* load_smi_map,
4314 __ JumpIfSmi(receiver, load_smi_map);
4315 __ movp(receiver_map, FieldOperand(receiver, 0));
4317 __ bind(compare_map);
4318 __ cmpp(receiver_map, FieldOperand(feedback, WeakCell::kValueOffset));
4319 __ j(not_equal, try_array);
4320 Register handler = feedback;
4321 __ movp(handler, FieldOperand(vector, integer_slot, times_pointer_size,
4322 FixedArray::kHeaderSize + kPointerSize));
4323 __ leap(handler, FieldOperand(handler, Code::kHeaderSize));
4328 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4331 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4332 GenerateImpl(masm, true);
4336 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4337 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // rdx
4338 Register name = LoadWithVectorDescriptor::NameRegister(); // rcx
4339 Register vector = LoadWithVectorDescriptor::VectorRegister(); // rbx
4340 Register slot = LoadWithVectorDescriptor::SlotRegister(); // rax
4341 Register feedback = rdi;
4342 Register integer_slot = r8;
4343 Register receiver_map = r9;
4345 __ SmiToInteger32(integer_slot, slot);
4346 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4347 FixedArray::kHeaderSize));
4349 // Try to quickly handle the monomorphic case without knowing for sure
4350 // if we have a weak cell in feedback. We do know it's safe to look
4351 // at WeakCell::kValueOffset.
4352 Label try_array, load_smi_map, compare_map;
4353 Label not_array, miss;
4354 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector,
4355 integer_slot, &compare_map, &load_smi_map, &try_array);
4357 // Is it a fixed array?
4358 __ bind(&try_array);
4359 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex);
4360 __ j(not_equal, ¬_array);
4361 HandleArrayCases(masm, feedback, receiver_map, integer_slot, r11, r15, true,
4364 __ bind(¬_array);
4365 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4366 __ j(not_equal, &miss);
4367 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4368 Code::ComputeHandlerFlags(Code::LOAD_IC));
4369 masm->isolate()->stub_cache()->GenerateProbe(
4370 masm, Code::LOAD_IC, code_flags, receiver, name, feedback, no_reg);
4373 LoadIC::GenerateMiss(masm);
4375 __ bind(&load_smi_map);
4376 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4377 __ jmp(&compare_map);
4381 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4382 GenerateImpl(masm, false);
4386 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4387 GenerateImpl(masm, true);
4391 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4392 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // rdx
4393 Register key = LoadWithVectorDescriptor::NameRegister(); // rcx
4394 Register vector = LoadWithVectorDescriptor::VectorRegister(); // rbx
4395 Register slot = LoadWithVectorDescriptor::SlotRegister(); // rax
4396 Register feedback = rdi;
4397 Register integer_slot = r8;
4398 Register receiver_map = r9;
4400 __ SmiToInteger32(integer_slot, slot);
4401 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4402 FixedArray::kHeaderSize));
4404 // Try to quickly handle the monomorphic case without knowing for sure
4405 // if we have a weak cell in feedback. We do know it's safe to look
4406 // at WeakCell::kValueOffset.
4407 Label try_array, load_smi_map, compare_map;
4408 Label not_array, miss;
4409 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector,
4410 integer_slot, &compare_map, &load_smi_map, &try_array);
4412 __ bind(&try_array);
4413 // Is it a fixed array?
4414 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex);
4415 __ j(not_equal, ¬_array);
4417 // We have a polymorphic element handler.
4418 Label polymorphic, try_poly_name;
4419 __ bind(&polymorphic);
4420 HandleArrayCases(masm, feedback, receiver_map, integer_slot, r11, r15, true,
4423 __ bind(¬_array);
4425 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4426 __ j(not_equal, &try_poly_name);
4427 Handle<Code> megamorphic_stub =
4428 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4429 __ jmp(megamorphic_stub, RelocInfo::CODE_TARGET);
4431 __ bind(&try_poly_name);
4432 // We might have a name in feedback, and a fixed array in the next slot.
4433 __ cmpp(key, feedback);
4434 __ j(not_equal, &miss);
4435 // If the name comparison succeeded, we know we have a fixed array with
4436 // at least one map/handler pair.
4437 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4438 FixedArray::kHeaderSize + kPointerSize));
4439 HandleArrayCases(masm, feedback, receiver_map, integer_slot, r11, r15, false,
4443 KeyedLoadIC::GenerateMiss(masm);
4445 __ bind(&load_smi_map);
4446 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4447 __ jmp(&compare_map);
4451 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4452 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4453 VectorStoreICStub stub(isolate(), state());
4454 stub.GenerateForTrampoline(masm);
4458 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4459 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4460 VectorKeyedStoreICStub stub(isolate(), state());
4461 stub.GenerateForTrampoline(masm);
4465 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4466 GenerateImpl(masm, false);
4470 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4471 GenerateImpl(masm, true);
4475 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4476 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // rdx
4477 Register key = VectorStoreICDescriptor::NameRegister(); // rcx
4478 Register vector = VectorStoreICDescriptor::VectorRegister(); // rbx
4479 Register slot = VectorStoreICDescriptor::SlotRegister(); // rdi
4480 DCHECK(VectorStoreICDescriptor::ValueRegister().is(rax)); // rax
4481 Register feedback = r8;
4482 Register integer_slot = r9;
4483 Register receiver_map = r11;
4484 DCHECK(!AreAliased(feedback, integer_slot, vector, slot, receiver_map));
4486 __ SmiToInteger32(integer_slot, slot);
4487 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4488 FixedArray::kHeaderSize));
4490 // Try to quickly handle the monomorphic case without knowing for sure
4491 // if we have a weak cell in feedback. We do know it's safe to look
4492 // at WeakCell::kValueOffset.
4493 Label try_array, load_smi_map, compare_map;
4494 Label not_array, miss;
4495 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector,
4496 integer_slot, &compare_map, &load_smi_map, &try_array);
4498 // Is it a fixed array?
4499 __ bind(&try_array);
4500 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex);
4501 __ j(not_equal, ¬_array);
4502 HandleArrayCases(masm, feedback, receiver_map, integer_slot, r14, r15, true,
4505 __ bind(¬_array);
4506 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4507 __ j(not_equal, &miss);
4509 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4510 Code::ComputeHandlerFlags(Code::STORE_IC));
4511 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::STORE_IC, code_flags,
4512 receiver, key, feedback, no_reg);
4515 StoreIC::GenerateMiss(masm);
4517 __ bind(&load_smi_map);
4518 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4519 __ jmp(&compare_map);
4523 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4524 GenerateImpl(masm, false);
4528 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4529 GenerateImpl(masm, true);
4533 static void HandlePolymorphicKeyedStoreCase(MacroAssembler* masm,
4534 Register receiver_map,
4535 Register feedback, Register scratch,
4537 Register scratch2, Label* miss) {
4538 // feedback initially contains the feedback array
4539 Label next, next_loop, prepare_next;
4540 Label transition_call;
4542 Register cached_map = scratch;
4543 Register counter = scratch1;
4544 Register length = scratch2;
4546 // Polymorphic, we have to loop from 0 to N - 1
4547 __ movp(counter, Immediate(0));
4548 __ movp(length, FieldOperand(feedback, FixedArray::kLengthOffset));
4549 __ SmiToInteger32(length, length);
4551 __ bind(&next_loop);
4552 __ movp(cached_map, FieldOperand(feedback, counter, times_pointer_size,
4553 FixedArray::kHeaderSize));
4554 __ cmpp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4555 __ j(not_equal, &prepare_next);
4556 __ movp(cached_map, FieldOperand(feedback, counter, times_pointer_size,
4557 FixedArray::kHeaderSize + kPointerSize));
4558 __ CompareRoot(cached_map, Heap::kUndefinedValueRootIndex);
4559 __ j(not_equal, &transition_call);
4560 __ movp(feedback, FieldOperand(feedback, counter, times_pointer_size,
4561 FixedArray::kHeaderSize + 2 * kPointerSize));
4562 __ leap(feedback, FieldOperand(feedback, Code::kHeaderSize));
4565 __ bind(&transition_call);
4566 DCHECK(receiver_map.is(VectorStoreTransitionDescriptor::MapRegister()));
4567 __ movp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4568 // The weak cell may have been cleared.
4569 __ JumpIfSmi(receiver_map, miss);
4570 // Get the handler in value.
4571 __ movp(feedback, FieldOperand(feedback, counter, times_pointer_size,
4572 FixedArray::kHeaderSize + 2 * kPointerSize));
4573 __ leap(feedback, FieldOperand(feedback, Code::kHeaderSize));
4576 __ bind(&prepare_next);
4577 __ addl(counter, Immediate(3));
4578 __ cmpl(counter, length);
4579 __ j(less, &next_loop);
4581 // We exhausted our array of map handler pairs.
4586 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4587 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // rdx
4588 Register key = VectorStoreICDescriptor::NameRegister(); // rcx
4589 Register vector = VectorStoreICDescriptor::VectorRegister(); // rbx
4590 Register slot = VectorStoreICDescriptor::SlotRegister(); // rdi
4591 DCHECK(VectorStoreICDescriptor::ValueRegister().is(rax)); // rax
4592 Register feedback = r8;
4593 Register integer_slot = r9;
4594 Register receiver_map = r11;
4595 DCHECK(!AreAliased(feedback, integer_slot, vector, slot, receiver_map));
4597 __ SmiToInteger32(integer_slot, slot);
4598 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4599 FixedArray::kHeaderSize));
4601 // Try to quickly handle the monomorphic case without knowing for sure
4602 // if we have a weak cell in feedback. We do know it's safe to look
4603 // at WeakCell::kValueOffset.
4604 Label try_array, load_smi_map, compare_map;
4605 Label not_array, miss;
4606 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector,
4607 integer_slot, &compare_map, &load_smi_map, &try_array);
4609 // Is it a fixed array?
4610 __ bind(&try_array);
4611 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex);
4612 __ j(not_equal, ¬_array);
4613 HandlePolymorphicKeyedStoreCase(masm, receiver_map, feedback, integer_slot,
4616 __ bind(¬_array);
4617 Label try_poly_name;
4618 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4619 __ j(not_equal, &try_poly_name);
4621 Handle<Code> megamorphic_stub =
4622 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4623 __ jmp(megamorphic_stub, RelocInfo::CODE_TARGET);
4625 __ bind(&try_poly_name);
4626 // We might have a name in feedback, and a fixed array in the next slot.
4627 __ cmpp(key, feedback);
4628 __ j(not_equal, &miss);
4629 // If the name comparison succeeded, we know we have a fixed array with
4630 // at least one map/handler pair.
4631 __ movp(feedback, FieldOperand(vector, integer_slot, times_pointer_size,
4632 FixedArray::kHeaderSize + kPointerSize));
4633 HandleArrayCases(masm, feedback, receiver_map, integer_slot, r14, r15, false,
4637 KeyedStoreIC::GenerateMiss(masm);
4639 __ bind(&load_smi_map);
4640 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4641 __ jmp(&compare_map);
4645 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4646 EmitLoadTypeFeedbackVector(masm, rbx);
4647 CallICStub stub(isolate(), state());
4648 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET);
4652 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4653 EmitLoadTypeFeedbackVector(masm, rbx);
4654 CallIC_ArrayStub stub(isolate(), state());
4655 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET);
4659 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4660 if (masm->isolate()->function_entry_hook() != NULL) {
4661 ProfileEntryHookStub stub(masm->isolate());
4662 masm->CallStub(&stub);
4667 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4668 // This stub can be called from essentially anywhere, so it needs to save
4669 // all volatile and callee-save registers.
4670 const size_t kNumSavedRegisters = 2;
4671 __ pushq(arg_reg_1);
4672 __ pushq(arg_reg_2);
4674 // Calculate the original stack pointer and store it in the second arg.
4676 Operand(rsp, kNumSavedRegisters * kRegisterSize + kPCOnStackSize));
4678 // Calculate the function address to the first arg.
4679 __ movp(arg_reg_1, Operand(rsp, kNumSavedRegisters * kRegisterSize));
4680 __ subp(arg_reg_1, Immediate(Assembler::kShortCallInstructionLength));
4682 // Save the remainder of the volatile registers.
4683 masm->PushCallerSaved(kSaveFPRegs, arg_reg_1, arg_reg_2);
4685 // Call the entry hook function.
4686 __ Move(rax, FUNCTION_ADDR(isolate()->function_entry_hook()),
4687 Assembler::RelocInfoNone());
4689 AllowExternalCallThatCantCauseGC scope(masm);
4691 const int kArgumentCount = 2;
4692 __ PrepareCallCFunction(kArgumentCount);
4693 __ CallCFunction(rax, kArgumentCount);
4695 // Restore volatile regs.
4696 masm->PopCallerSaved(kSaveFPRegs, arg_reg_1, arg_reg_2);
4705 static void CreateArrayDispatch(MacroAssembler* masm,
4706 AllocationSiteOverrideMode mode) {
4707 if (mode == DISABLE_ALLOCATION_SITES) {
4708 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4709 __ TailCallStub(&stub);
4710 } else if (mode == DONT_OVERRIDE) {
4711 int last_index = GetSequenceIndexFromFastElementsKind(
4712 TERMINAL_FAST_ELEMENTS_KIND);
4713 for (int i = 0; i <= last_index; ++i) {
4715 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4716 __ cmpl(rdx, Immediate(kind));
4717 __ j(not_equal, &next);
4718 T stub(masm->isolate(), kind);
4719 __ TailCallStub(&stub);
4723 // If we reached this point there is a problem.
4724 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4731 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4732 AllocationSiteOverrideMode mode) {
4733 // rbx - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4734 // rdx - kind (if mode != DISABLE_ALLOCATION_SITES)
4735 // rax - number of arguments
4736 // rdi - constructor?
4737 // rsp[0] - return address
4738 // rsp[8] - last argument
4739 Handle<Object> undefined_sentinel(
4740 masm->isolate()->heap()->undefined_value(),
4743 Label normal_sequence;
4744 if (mode == DONT_OVERRIDE) {
4745 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4746 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4747 STATIC_ASSERT(FAST_ELEMENTS == 2);
4748 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4749 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4750 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4752 // is the low bit set? If so, we are holey and that is good.
4753 __ testb(rdx, Immediate(1));
4754 __ j(not_zero, &normal_sequence);
4757 // look at the first argument
4758 StackArgumentsAccessor args(rsp, 1, ARGUMENTS_DONT_CONTAIN_RECEIVER);
4759 __ movp(rcx, args.GetArgumentOperand(0));
4761 __ j(zero, &normal_sequence);
4763 if (mode == DISABLE_ALLOCATION_SITES) {
4764 ElementsKind initial = GetInitialFastElementsKind();
4765 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4767 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4769 DISABLE_ALLOCATION_SITES);
4770 __ TailCallStub(&stub_holey);
4772 __ bind(&normal_sequence);
4773 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4775 DISABLE_ALLOCATION_SITES);
4776 __ TailCallStub(&stub);
4777 } else if (mode == DONT_OVERRIDE) {
4778 // We are going to create a holey array, but our kind is non-holey.
4779 // Fix kind and retry (only if we have an allocation site in the slot).
4782 if (FLAG_debug_code) {
4783 Handle<Map> allocation_site_map =
4784 masm->isolate()->factory()->allocation_site_map();
4785 __ Cmp(FieldOperand(rbx, 0), allocation_site_map);
4786 __ Assert(equal, kExpectedAllocationSite);
4789 // Save the resulting elements kind in type info. We can't just store r3
4790 // in the AllocationSite::transition_info field because elements kind is
4791 // restricted to a portion of the field...upper bits need to be left alone.
4792 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4793 __ SmiAddConstant(FieldOperand(rbx, AllocationSite::kTransitionInfoOffset),
4794 Smi::FromInt(kFastElementsKindPackedToHoley));
4796 __ bind(&normal_sequence);
4797 int last_index = GetSequenceIndexFromFastElementsKind(
4798 TERMINAL_FAST_ELEMENTS_KIND);
4799 for (int i = 0; i <= last_index; ++i) {
4801 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4802 __ cmpl(rdx, Immediate(kind));
4803 __ j(not_equal, &next);
4804 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4805 __ TailCallStub(&stub);
4809 // If we reached this point there is a problem.
4810 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4818 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4819 int to_index = GetSequenceIndexFromFastElementsKind(
4820 TERMINAL_FAST_ELEMENTS_KIND);
4821 for (int i = 0; i <= to_index; ++i) {
4822 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4823 T stub(isolate, kind);
4825 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4826 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4833 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4834 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4836 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4838 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4843 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4845 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4846 for (int i = 0; i < 2; i++) {
4847 // For internal arrays we only need a few things
4848 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4850 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4852 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4858 void ArrayConstructorStub::GenerateDispatchToArrayStub(
4859 MacroAssembler* masm,
4860 AllocationSiteOverrideMode mode) {
4861 if (argument_count() == ANY) {
4862 Label not_zero_case, not_one_case;
4864 __ j(not_zero, ¬_zero_case);
4865 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4867 __ bind(¬_zero_case);
4868 __ cmpl(rax, Immediate(1));
4869 __ j(greater, ¬_one_case);
4870 CreateArrayDispatchOneArgument(masm, mode);
4872 __ bind(¬_one_case);
4873 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4874 } else if (argument_count() == NONE) {
4875 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4876 } else if (argument_count() == ONE) {
4877 CreateArrayDispatchOneArgument(masm, mode);
4878 } else if (argument_count() == MORE_THAN_ONE) {
4879 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4886 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4887 // ----------- S t a t e -------------
4889 // -- rbx : AllocationSite or undefined
4890 // -- rdi : constructor
4891 // -- rdx : original constructor
4892 // -- rsp[0] : return address
4893 // -- rsp[8] : last argument
4894 // -----------------------------------
4895 if (FLAG_debug_code) {
4896 // The array construct code is only set for the global and natives
4897 // builtin Array functions which always have maps.
4899 // Initial map for the builtin Array function should be a map.
4900 __ movp(rcx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
4901 // Will both indicate a NULL and a Smi.
4902 STATIC_ASSERT(kSmiTag == 0);
4903 Condition not_smi = NegateCondition(masm->CheckSmi(rcx));
4904 __ Check(not_smi, kUnexpectedInitialMapForArrayFunction);
4905 __ CmpObjectType(rcx, MAP_TYPE, rcx);
4906 __ Check(equal, kUnexpectedInitialMapForArrayFunction);
4908 // We should either have undefined in rbx or a valid AllocationSite
4909 __ AssertUndefinedOrAllocationSite(rbx);
4914 __ j(not_equal, &subclassing);
4917 // If the feedback vector is the undefined value call an array constructor
4918 // that doesn't use AllocationSites.
4919 __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex);
4920 __ j(equal, &no_info);
4922 // Only look at the lower 16 bits of the transition info.
4923 __ movp(rdx, FieldOperand(rbx, AllocationSite::kTransitionInfoOffset));
4924 __ SmiToInteger32(rdx, rdx);
4925 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4926 __ andp(rdx, Immediate(AllocationSite::ElementsKindBits::kMask));
4927 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4930 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
4933 __ bind(&subclassing);
4934 __ Pop(rcx); // return address.
4939 switch (argument_count()) {
4942 __ addp(rax, Immediate(2));
4945 __ movp(rax, Immediate(2));
4948 __ movp(rax, Immediate(3));
4953 __ JumpToExternalReference(
4954 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()),
4959 void InternalArrayConstructorStub::GenerateCase(
4960 MacroAssembler* masm, ElementsKind kind) {
4961 Label not_zero_case, not_one_case;
4962 Label normal_sequence;
4965 __ j(not_zero, ¬_zero_case);
4966 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4967 __ TailCallStub(&stub0);
4969 __ bind(¬_zero_case);
4970 __ cmpl(rax, Immediate(1));
4971 __ j(greater, ¬_one_case);
4973 if (IsFastPackedElementsKind(kind)) {
4974 // We might need to create a holey array
4975 // look at the first argument
4976 StackArgumentsAccessor args(rsp, 1, ARGUMENTS_DONT_CONTAIN_RECEIVER);
4977 __ movp(rcx, args.GetArgumentOperand(0));
4979 __ j(zero, &normal_sequence);
4981 InternalArraySingleArgumentConstructorStub
4982 stub1_holey(isolate(), GetHoleyElementsKind(kind));
4983 __ TailCallStub(&stub1_holey);
4986 __ bind(&normal_sequence);
4987 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
4988 __ TailCallStub(&stub1);
4990 __ bind(¬_one_case);
4991 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
4992 __ TailCallStub(&stubN);
4996 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
4997 // ----------- S t a t e -------------
4999 // -- rdi : constructor
5000 // -- rsp[0] : return address
5001 // -- rsp[8] : last argument
5002 // -----------------------------------
5004 if (FLAG_debug_code) {
5005 // The array construct code is only set for the global and natives
5006 // builtin Array functions which always have maps.
5008 // Initial map for the builtin Array function should be a map.
5009 __ movp(rcx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
5010 // Will both indicate a NULL and a Smi.
5011 STATIC_ASSERT(kSmiTag == 0);
5012 Condition not_smi = NegateCondition(masm->CheckSmi(rcx));
5013 __ Check(not_smi, kUnexpectedInitialMapForArrayFunction);
5014 __ CmpObjectType(rcx, MAP_TYPE, rcx);
5015 __ Check(equal, kUnexpectedInitialMapForArrayFunction);
5018 // Figure out the right elements kind
5019 __ movp(rcx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
5021 // Load the map's "bit field 2" into |result|. We only need the first byte,
5022 // but the following masking takes care of that anyway.
5023 __ movzxbp(rcx, FieldOperand(rcx, Map::kBitField2Offset));
5024 // Retrieve elements_kind from bit field 2.
5025 __ DecodeField<Map::ElementsKindBits>(rcx);
5027 if (FLAG_debug_code) {
5029 __ cmpl(rcx, Immediate(FAST_ELEMENTS));
5031 __ cmpl(rcx, Immediate(FAST_HOLEY_ELEMENTS));
5033 kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5037 Label fast_elements_case;
5038 __ cmpl(rcx, Immediate(FAST_ELEMENTS));
5039 __ j(equal, &fast_elements_case);
5040 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5042 __ bind(&fast_elements_case);
5043 GenerateCase(masm, FAST_ELEMENTS);
5047 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5048 Register context_reg = rsi;
5049 Register slot_reg = rbx;
5050 Register result_reg = rax;
5053 // Go up context chain to the script context.
5054 for (int i = 0; i < depth(); ++i) {
5055 __ movp(rdi, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5059 // Load the PropertyCell value at the specified slot.
5060 __ movp(result_reg, ContextOperand(context_reg, slot_reg));
5061 __ movp(result_reg, FieldOperand(result_reg, PropertyCell::kValueOffset));
5063 // Check that value is not the_hole.
5064 __ CompareRoot(result_reg, Heap::kTheHoleValueRootIndex);
5065 __ j(equal, &slow_case, Label::kNear);
5068 // Fallback to the runtime.
5069 __ bind(&slow_case);
5070 __ Integer32ToSmi(slot_reg, slot_reg);
5071 __ PopReturnAddressTo(kScratchRegister);
5073 __ Push(kScratchRegister);
5074 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5078 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5079 Register context_reg = rsi;
5080 Register slot_reg = rbx;
5081 Register value_reg = rax;
5082 Register cell_reg = r8;
5083 Register cell_details_reg = rdx;
5084 Register cell_value_reg = r9;
5085 Label fast_heapobject_case, fast_smi_case, slow_case;
5087 if (FLAG_debug_code) {
5088 __ CompareRoot(value_reg, Heap::kTheHoleValueRootIndex);
5089 __ Check(not_equal, kUnexpectedValue);
5092 // Go up context chain to the script context.
5093 for (int i = 0; i < depth(); ++i) {
5094 __ movp(rdi, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5098 // Load the PropertyCell at the specified slot.
5099 __ movp(cell_reg, ContextOperand(context_reg, slot_reg));
5101 // Load PropertyDetails for the cell (actually only the cell_type, kind and
5102 // READ_ONLY bit of attributes).
5103 __ SmiToInteger32(cell_details_reg,
5104 FieldOperand(cell_reg, PropertyCell::kDetailsOffset));
5105 __ andl(cell_details_reg,
5106 Immediate(PropertyDetails::PropertyCellTypeField::kMask |
5107 PropertyDetails::KindField::kMask |
5108 PropertyDetails::kAttributesReadOnlyMask));
5110 // Check if PropertyCell holds mutable data.
5111 Label not_mutable_data;
5112 __ cmpl(cell_details_reg,
5113 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5114 PropertyCellType::kMutable) |
5115 PropertyDetails::KindField::encode(kData)));
5116 __ j(not_equal, ¬_mutable_data);
5117 __ JumpIfSmi(value_reg, &fast_smi_case);
5118 __ bind(&fast_heapobject_case);
5119 __ movp(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg);
5120 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg,
5121 cell_value_reg, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5123 // RecordWriteField clobbers the value register, so we need to reload.
5124 __ movp(value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset));
5126 __ bind(¬_mutable_data);
5128 // Check if PropertyCell value matches the new value (relevant for Constant,
5129 // ConstantType and Undefined cells).
5130 Label not_same_value;
5131 __ movp(cell_value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset));
5132 __ cmpp(cell_value_reg, value_reg);
5133 __ j(not_equal, ¬_same_value,
5134 FLAG_debug_code ? Label::kFar : Label::kNear);
5135 // Make sure the PropertyCell is not marked READ_ONLY.
5136 __ testl(cell_details_reg,
5137 Immediate(PropertyDetails::kAttributesReadOnlyMask));
5138 __ j(not_zero, &slow_case);
5139 if (FLAG_debug_code) {
5141 // This can only be true for Constant, ConstantType and Undefined cells,
5142 // because we never store the_hole via this stub.
5143 __ cmpl(cell_details_reg,
5144 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5145 PropertyCellType::kConstant) |
5146 PropertyDetails::KindField::encode(kData)));
5148 __ cmpl(cell_details_reg,
5149 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5150 PropertyCellType::kConstantType) |
5151 PropertyDetails::KindField::encode(kData)));
5153 __ cmpl(cell_details_reg,
5154 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5155 PropertyCellType::kUndefined) |
5156 PropertyDetails::KindField::encode(kData)));
5157 __ Check(equal, kUnexpectedValue);
5161 __ bind(¬_same_value);
5163 // Check if PropertyCell contains data with constant type (and is not
5165 __ cmpl(cell_details_reg,
5166 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5167 PropertyCellType::kConstantType) |
5168 PropertyDetails::KindField::encode(kData)));
5169 __ j(not_equal, &slow_case, Label::kNear);
5171 // Now either both old and new values must be SMIs or both must be heap
5172 // objects with same map.
5173 Label value_is_heap_object;
5174 __ JumpIfNotSmi(value_reg, &value_is_heap_object, Label::kNear);
5175 __ JumpIfNotSmi(cell_value_reg, &slow_case, Label::kNear);
5176 // Old and new values are SMIs, no need for a write barrier here.
5177 __ bind(&fast_smi_case);
5178 __ movp(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg);
5180 __ bind(&value_is_heap_object);
5181 __ JumpIfSmi(cell_value_reg, &slow_case, Label::kNear);
5182 Register cell_value_map_reg = cell_value_reg;
5183 __ movp(cell_value_map_reg,
5184 FieldOperand(cell_value_reg, HeapObject::kMapOffset));
5185 __ cmpp(cell_value_map_reg, FieldOperand(value_reg, HeapObject::kMapOffset));
5186 __ j(equal, &fast_heapobject_case);
5188 // Fallback to the runtime.
5189 __ bind(&slow_case);
5190 __ Integer32ToSmi(slot_reg, slot_reg);
5191 __ PopReturnAddressTo(kScratchRegister);
5194 __ Push(kScratchRegister);
5195 __ TailCallRuntime(is_strict(language_mode())
5196 ? Runtime::kStoreGlobalViaContext_Strict
5197 : Runtime::kStoreGlobalViaContext_Sloppy,
5202 static int Offset(ExternalReference ref0, ExternalReference ref1) {
5203 int64_t offset = (ref0.address() - ref1.address());
5204 // Check that fits into int.
5205 DCHECK(static_cast<int>(offset) == offset);
5206 return static_cast<int>(offset);
5210 // Prepares stack to put arguments (aligns and so on). WIN64 calling
5211 // convention requires to put the pointer to the return value slot into
5212 // rcx (rcx must be preserverd until CallApiFunctionAndReturn). Saves
5213 // context (rsi). Clobbers rax. Allocates arg_stack_space * kPointerSize
5214 // inside the exit frame (not GCed) accessible via StackSpaceOperand.
5215 static void PrepareCallApiFunction(MacroAssembler* masm, int arg_stack_space) {
5216 __ EnterApiExitFrame(arg_stack_space);
5220 // Calls an API function. Allocates HandleScope, extracts returned value
5221 // from handle and propagates exceptions. Clobbers r14, r15, rbx and
5222 // caller-save registers. Restores context. On return removes
5223 // stack_space * kPointerSize (GCed).
5224 static void CallApiFunctionAndReturn(MacroAssembler* masm,
5225 Register function_address,
5226 ExternalReference thunk_ref,
5227 Register thunk_last_arg, int stack_space,
5228 Operand* stack_space_operand,
5229 Operand return_value_operand,
5230 Operand* context_restore_operand) {
5232 Label promote_scheduled_exception;
5233 Label delete_allocated_handles;
5234 Label leave_exit_frame;
5237 Isolate* isolate = masm->isolate();
5238 Factory* factory = isolate->factory();
5239 ExternalReference next_address =
5240 ExternalReference::handle_scope_next_address(isolate);
5241 const int kNextOffset = 0;
5242 const int kLimitOffset = Offset(
5243 ExternalReference::handle_scope_limit_address(isolate), next_address);
5244 const int kLevelOffset = Offset(
5245 ExternalReference::handle_scope_level_address(isolate), next_address);
5246 ExternalReference scheduled_exception_address =
5247 ExternalReference::scheduled_exception_address(isolate);
5249 DCHECK(rdx.is(function_address) || r8.is(function_address));
5250 // Allocate HandleScope in callee-save registers.
5251 Register prev_next_address_reg = r14;
5252 Register prev_limit_reg = rbx;
5253 Register base_reg = r15;
5254 __ Move(base_reg, next_address);
5255 __ movp(prev_next_address_reg, Operand(base_reg, kNextOffset));
5256 __ movp(prev_limit_reg, Operand(base_reg, kLimitOffset));
5257 __ addl(Operand(base_reg, kLevelOffset), Immediate(1));
5259 if (FLAG_log_timer_events) {
5260 FrameScope frame(masm, StackFrame::MANUAL);
5261 __ PushSafepointRegisters();
5262 __ PrepareCallCFunction(1);
5263 __ LoadAddress(arg_reg_1, ExternalReference::isolate_address(isolate));
5264 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5266 __ PopSafepointRegisters();
5269 Label profiler_disabled;
5270 Label end_profiler_check;
5271 __ Move(rax, ExternalReference::is_profiling_address(isolate));
5272 __ cmpb(Operand(rax, 0), Immediate(0));
5273 __ j(zero, &profiler_disabled);
5275 // Third parameter is the address of the actual getter function.
5276 __ Move(thunk_last_arg, function_address);
5277 __ Move(rax, thunk_ref);
5278 __ jmp(&end_profiler_check);
5280 __ bind(&profiler_disabled);
5281 // Call the api function!
5282 __ Move(rax, function_address);
5284 __ bind(&end_profiler_check);
5286 // Call the api function!
5289 if (FLAG_log_timer_events) {
5290 FrameScope frame(masm, StackFrame::MANUAL);
5291 __ PushSafepointRegisters();
5292 __ PrepareCallCFunction(1);
5293 __ LoadAddress(arg_reg_1, ExternalReference::isolate_address(isolate));
5294 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5296 __ PopSafepointRegisters();
5299 // Load the value from ReturnValue
5300 __ movp(rax, return_value_operand);
5303 // No more valid handles (the result handle was the last one). Restore
5304 // previous handle scope.
5305 __ subl(Operand(base_reg, kLevelOffset), Immediate(1));
5306 __ movp(Operand(base_reg, kNextOffset), prev_next_address_reg);
5307 __ cmpp(prev_limit_reg, Operand(base_reg, kLimitOffset));
5308 __ j(not_equal, &delete_allocated_handles);
5310 // Leave the API exit frame.
5311 __ bind(&leave_exit_frame);
5312 bool restore_context = context_restore_operand != NULL;
5313 if (restore_context) {
5314 __ movp(rsi, *context_restore_operand);
5316 if (stack_space_operand != nullptr) {
5317 __ movp(rbx, *stack_space_operand);
5319 __ LeaveApiExitFrame(!restore_context);
5321 // Check if the function scheduled an exception.
5322 __ Move(rdi, scheduled_exception_address);
5323 __ Cmp(Operand(rdi, 0), factory->the_hole_value());
5324 __ j(not_equal, &promote_scheduled_exception);
5327 // Check if the function returned a valid JavaScript value.
5329 Register return_value = rax;
5332 __ JumpIfSmi(return_value, &ok, Label::kNear);
5333 __ movp(map, FieldOperand(return_value, HeapObject::kMapOffset));
5335 __ CmpInstanceType(map, LAST_NAME_TYPE);
5336 __ j(below_equal, &ok, Label::kNear);
5338 __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE);
5339 __ j(above_equal, &ok, Label::kNear);
5341 __ CompareRoot(map, Heap::kHeapNumberMapRootIndex);
5342 __ j(equal, &ok, Label::kNear);
5344 __ CompareRoot(return_value, Heap::kUndefinedValueRootIndex);
5345 __ j(equal, &ok, Label::kNear);
5347 __ CompareRoot(return_value, Heap::kTrueValueRootIndex);
5348 __ j(equal, &ok, Label::kNear);
5350 __ CompareRoot(return_value, Heap::kFalseValueRootIndex);
5351 __ j(equal, &ok, Label::kNear);
5353 __ CompareRoot(return_value, Heap::kNullValueRootIndex);
5354 __ j(equal, &ok, Label::kNear);
5356 __ Abort(kAPICallReturnedInvalidObject);
5361 if (stack_space_operand != nullptr) {
5362 DCHECK_EQ(stack_space, 0);
5363 __ PopReturnAddressTo(rcx);
5367 __ ret(stack_space * kPointerSize);
5370 // Re-throw by promoting a scheduled exception.
5371 __ bind(&promote_scheduled_exception);
5372 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5374 // HandleScope limit has changed. Delete allocated extensions.
5375 __ bind(&delete_allocated_handles);
5376 __ movp(Operand(base_reg, kLimitOffset), prev_limit_reg);
5377 __ movp(prev_limit_reg, rax);
5378 __ LoadAddress(arg_reg_1, ExternalReference::isolate_address(isolate));
5380 ExternalReference::delete_handle_scope_extensions(isolate));
5382 __ movp(rax, prev_limit_reg);
5383 __ jmp(&leave_exit_frame);
5387 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5388 const ParameterCount& argc,
5389 bool return_first_arg,
5390 bool call_data_undefined) {
5391 // ----------- S t a t e -------------
5393 // -- rbx : call_data
5395 // -- rdx : api_function_address
5397 // -- rax : number of arguments if argc is a register
5398 // -- rsp[0] : return address
5399 // -- rsp[8] : last argument
5401 // -- rsp[argc * 8] : first argument
5402 // -- rsp[(argc + 1) * 8] : receiver
5403 // -----------------------------------
5405 Register callee = rdi;
5406 Register call_data = rbx;
5407 Register holder = rcx;
5408 Register api_function_address = rdx;
5409 Register context = rsi;
5410 Register return_address = r8;
5412 typedef FunctionCallbackArguments FCA;
5414 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5415 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5416 STATIC_ASSERT(FCA::kDataIndex == 4);
5417 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5418 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5419 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5420 STATIC_ASSERT(FCA::kHolderIndex == 0);
5421 STATIC_ASSERT(FCA::kArgsLength == 7);
5423 DCHECK(argc.is_immediate() || rax.is(argc.reg()));
5425 __ PopReturnAddressTo(return_address);
5435 Register scratch = call_data;
5436 if (!call_data_undefined) {
5437 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5441 // return value default
5444 __ Move(scratch, ExternalReference::isolate_address(masm->isolate()));
5449 __ movp(scratch, rsp);
5450 // Push return address back on stack.
5451 __ PushReturnAddressFrom(return_address);
5453 // load context from callee
5454 __ movp(context, FieldOperand(callee, JSFunction::kContextOffset));
5456 // Allocate the v8::Arguments structure in the arguments' space since
5457 // it's not controlled by GC.
5458 const int kApiStackSpace = 4;
5460 PrepareCallApiFunction(masm, kApiStackSpace);
5462 // FunctionCallbackInfo::implicit_args_.
5463 __ movp(StackSpaceOperand(0), scratch);
5464 if (argc.is_immediate()) {
5465 __ addp(scratch, Immediate((argc.immediate() + FCA::kArgsLength - 1) *
5467 // FunctionCallbackInfo::values_.
5468 __ movp(StackSpaceOperand(1), scratch);
5469 // FunctionCallbackInfo::length_.
5470 __ Set(StackSpaceOperand(2), argc.immediate());
5471 // FunctionCallbackInfo::is_construct_call_.
5472 __ Set(StackSpaceOperand(3), 0);
5474 __ leap(scratch, Operand(scratch, argc.reg(), times_pointer_size,
5475 (FCA::kArgsLength - 1) * kPointerSize));
5476 // FunctionCallbackInfo::values_.
5477 __ movp(StackSpaceOperand(1), scratch);
5478 // FunctionCallbackInfo::length_.
5479 __ movp(StackSpaceOperand(2), argc.reg());
5480 // FunctionCallbackInfo::is_construct_call_.
5481 __ leap(argc.reg(), Operand(argc.reg(), times_pointer_size,
5482 (FCA::kArgsLength + 1) * kPointerSize));
5483 __ movp(StackSpaceOperand(3), argc.reg());
5486 #if defined(__MINGW64__) || defined(_WIN64)
5487 Register arguments_arg = rcx;
5488 Register callback_arg = rdx;
5490 Register arguments_arg = rdi;
5491 Register callback_arg = rsi;
5494 // It's okay if api_function_address == callback_arg
5495 // but not arguments_arg
5496 DCHECK(!api_function_address.is(arguments_arg));
5498 // v8::InvocationCallback's argument.
5499 __ leap(arguments_arg, StackSpaceOperand(0));
5501 ExternalReference thunk_ref =
5502 ExternalReference::invoke_function_callback(masm->isolate());
5504 // Accessor for FunctionCallbackInfo and first js arg.
5505 StackArgumentsAccessor args_from_rbp(rbp, FCA::kArgsLength + 1,
5506 ARGUMENTS_DONT_CONTAIN_RECEIVER);
5507 Operand context_restore_operand = args_from_rbp.GetArgumentOperand(
5508 FCA::kArgsLength - FCA::kContextSaveIndex);
5509 Operand is_construct_call_operand = StackSpaceOperand(3);
5510 Operand return_value_operand = args_from_rbp.GetArgumentOperand(
5511 return_first_arg ? 0 : FCA::kArgsLength - FCA::kReturnValueOffset);
5512 int stack_space = 0;
5513 Operand* stack_space_operand = &is_construct_call_operand;
5514 if (argc.is_immediate()) {
5515 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5516 stack_space_operand = nullptr;
5518 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, callback_arg,
5519 stack_space, stack_space_operand,
5520 return_value_operand, &context_restore_operand);
5524 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5525 bool call_data_undefined = this->call_data_undefined();
5526 CallApiFunctionStubHelper(masm, ParameterCount(rax), false,
5527 call_data_undefined);
5531 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5532 bool is_store = this->is_store();
5533 int argc = this->argc();
5534 bool call_data_undefined = this->call_data_undefined();
5535 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5536 call_data_undefined);
5540 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5541 // ----------- S t a t e -------------
5542 // -- rsp[0] : return address
5544 // -- rsp[16 - kArgsLength*8] : PropertyCallbackArguments object
5546 // -- r8 : api_function_address
5547 // -----------------------------------
5549 #if defined(__MINGW64__) || defined(_WIN64)
5550 Register getter_arg = r8;
5551 Register accessor_info_arg = rdx;
5552 Register name_arg = rcx;
5554 Register getter_arg = rdx;
5555 Register accessor_info_arg = rsi;
5556 Register name_arg = rdi;
5558 Register api_function_address = ApiGetterDescriptor::function_address();
5559 DCHECK(api_function_address.is(r8));
5560 Register scratch = rax;
5562 // v8::Arguments::values_ and handler for name.
5563 const int kStackSpace = PropertyCallbackArguments::kArgsLength + 1;
5565 // Allocate v8::AccessorInfo in non-GCed stack space.
5566 const int kArgStackSpace = 1;
5568 __ leap(name_arg, Operand(rsp, kPCOnStackSize));
5570 PrepareCallApiFunction(masm, kArgStackSpace);
5571 __ leap(scratch, Operand(name_arg, 1 * kPointerSize));
5573 // v8::PropertyAccessorInfo::args_.
5574 __ movp(StackSpaceOperand(0), scratch);
5576 // The context register (rsi) has been saved in PrepareCallApiFunction and
5577 // could be used to pass arguments.
5578 __ leap(accessor_info_arg, StackSpaceOperand(0));
5580 ExternalReference thunk_ref =
5581 ExternalReference::invoke_accessor_getter_callback(isolate());
5583 // It's okay if api_function_address == getter_arg
5584 // but not accessor_info_arg or name_arg
5585 DCHECK(!api_function_address.is(accessor_info_arg) &&
5586 !api_function_address.is(name_arg));
5588 // The name handler is counted as an argument.
5589 StackArgumentsAccessor args(rbp, PropertyCallbackArguments::kArgsLength);
5590 Operand return_value_operand = args.GetArgumentOperand(
5591 PropertyCallbackArguments::kArgsLength - 1 -
5592 PropertyCallbackArguments::kReturnValueOffset);
5593 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, getter_arg,
5594 kStackSpace, nullptr, return_value_operand, NULL);
5600 } // namespace internal
5603 #endif // V8_TARGET_ARCH_X64