blob: b711ce9d204f5a5e88b853571fd7103d845e30bf [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01004
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005#if V8_TARGET_ARCH_IA32
Kristian Monsen80d68ea2010-09-08 11:05:35 +01006
Ben Murdochda12d292016-06-02 14:46:10 +01007#include "src/code-stubs.h"
8#include "src/api-arguments.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/base/bits.h"
10#include "src/bootstrapper.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011#include "src/codegen.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000012#include "src/ia32/code-stubs-ia32.h"
13#include "src/ia32/frames-ia32.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000014#include "src/ic/handler-compiler.h"
15#include "src/ic/ic.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000016#include "src/ic/stub-cache.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000017#include "src/isolate.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000018#include "src/regexp/jsregexp.h"
19#include "src/regexp/regexp-macro-assembler.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040020#include "src/runtime/runtime.h"
Kristian Monsen80d68ea2010-09-08 11:05:35 +010021
22namespace v8 {
23namespace internal {
24
Ben Murdochb8a8cc12014-11-26 15:28:44 +000025
26static void InitializeArrayConstructorDescriptor(
27 Isolate* isolate, CodeStubDescriptor* descriptor,
28 int constant_stack_parameter_count) {
29 // register state
30 // eax -- number of arguments
31 // edi -- function
32 // ebx -- allocation site with elements kind
33 Address deopt_handler = Runtime::FunctionForId(
34 Runtime::kArrayConstructor)->entry;
35
36 if (constant_stack_parameter_count == 0) {
37 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
38 JS_FUNCTION_STUB_MODE);
39 } else {
40 descriptor->Initialize(eax, deopt_handler, constant_stack_parameter_count,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000041 JS_FUNCTION_STUB_MODE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000042 }
43}
44
45
46static void InitializeInternalArrayConstructorDescriptor(
47 Isolate* isolate, CodeStubDescriptor* descriptor,
48 int constant_stack_parameter_count) {
49 // register state
50 // eax -- number of arguments
51 // edi -- constructor function
52 Address deopt_handler = Runtime::FunctionForId(
53 Runtime::kInternalArrayConstructor)->entry;
54
55 if (constant_stack_parameter_count == 0) {
56 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
57 JS_FUNCTION_STUB_MODE);
58 } else {
59 descriptor->Initialize(eax, deopt_handler, constant_stack_parameter_count,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000060 JS_FUNCTION_STUB_MODE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000061 }
62}
63
64
Ben Murdochb8a8cc12014-11-26 15:28:44 +000065void ArraySingleArgumentConstructorStub::InitializeDescriptor(
66 CodeStubDescriptor* descriptor) {
67 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
68}
69
70
71void ArrayNArgumentsConstructorStub::InitializeDescriptor(
72 CodeStubDescriptor* descriptor) {
73 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
74}
75
76
Ben Murdochda12d292016-06-02 14:46:10 +010077void FastArrayPushStub::InitializeDescriptor(CodeStubDescriptor* descriptor) {
78 Address deopt_handler = Runtime::FunctionForId(Runtime::kArrayPush)->entry;
79 descriptor->Initialize(eax, deopt_handler, -1, JS_FUNCTION_STUB_MODE);
80}
Ben Murdochb8a8cc12014-11-26 15:28:44 +000081
82void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
83 CodeStubDescriptor* descriptor) {
84 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
85}
86
87
88void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
89 CodeStubDescriptor* descriptor) {
90 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
91}
92
93
Kristian Monsen80d68ea2010-09-08 11:05:35 +010094#define __ ACCESS_MASM(masm)
Steve Block1e0659c2011-05-24 12:43:12 +010095
Ben Murdochb8a8cc12014-11-26 15:28:44 +000096
97void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
98 ExternalReference miss) {
99 // Update the static counter each time a new code stub is generated.
100 isolate()->counters()->code_stubs()->Increment();
101
102 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000103 int param_count = descriptor.GetRegisterParameterCount();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000104 {
105 // Call the runtime system in a fresh internal frame.
106 FrameScope scope(masm, StackFrame::INTERNAL);
107 DCHECK(param_count == 0 ||
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000108 eax.is(descriptor.GetRegisterParameter(param_count - 1)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000109 // Push arguments
110 for (int i = 0; i < param_count; ++i) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000111 __ push(descriptor.GetRegisterParameter(i));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000112 }
113 __ CallExternalReference(miss, param_count);
114 }
115
Steve Block1e0659c2011-05-24 12:43:12 +0100116 __ ret(0);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000117}
118
119
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100120void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
121 // We don't allow a GC during a store buffer overflow so there is no need to
122 // store the registers in any particular way, but we do have to store and
123 // restore them.
124 __ pushad();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000125 if (save_doubles()) {
126 __ sub(esp, Immediate(kDoubleSize * XMMRegister::kMaxNumRegisters));
127 for (int i = 0; i < XMMRegister::kMaxNumRegisters; i++) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100128 XMMRegister reg = XMMRegister::from_code(i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000129 __ movsd(Operand(esp, i * kDoubleSize), reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100130 }
131 }
132 const int argument_count = 1;
133
134 AllowExternalCallThatCantCauseGC scope(masm);
135 __ PrepareCallCFunction(argument_count, ecx);
136 __ mov(Operand(esp, 0 * kPointerSize),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000137 Immediate(ExternalReference::isolate_address(isolate())));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100138 __ CallCFunction(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000139 ExternalReference::store_buffer_overflow_function(isolate()),
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100140 argument_count);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000141 if (save_doubles()) {
142 for (int i = 0; i < XMMRegister::kMaxNumRegisters; i++) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100143 XMMRegister reg = XMMRegister::from_code(i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000144 __ movsd(reg, Operand(esp, i * kDoubleSize));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100145 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000146 __ add(esp, Immediate(kDoubleSize * XMMRegister::kMaxNumRegisters));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100147 }
148 __ popad();
149 __ ret(0);
150}
151
152
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100153class FloatingPointHelper : public AllStatic {
154 public:
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100155 enum ArgLocation {
156 ARGS_ON_STACK,
157 ARGS_IN_REGISTERS
158 };
159
160 // Code pattern for loading a floating point value. Input value must
161 // be either a smi or a heap number object (fp value). Requirements:
162 // operand in register number. Returns operand as floating point number
163 // on FPU stack.
164 static void LoadFloatOperand(MacroAssembler* masm, Register number);
165
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100166 // Test if operands are smi or number objects (fp). Requirements:
167 // operand_1 in eax, operand_2 in edx; falls through on float
168 // operands, jumps to the non_float label otherwise.
169 static void CheckFloatOperands(MacroAssembler* masm,
170 Label* non_float,
171 Register scratch);
172
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100173 // Test if operands are numbers (smi or HeapNumber objects), and load
174 // them into xmm0 and xmm1 if they are. Jump to label not_numbers if
175 // either operand is not a number. Operands are in edx and eax.
176 // Leaves operands unchanged.
177 static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100178};
179
180
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000181void DoubleToIStub::Generate(MacroAssembler* masm) {
182 Register input_reg = this->source();
183 Register final_result_reg = this->destination();
184 DCHECK(is_truncating());
185
186 Label check_negative, process_64_bits, done, done_no_stash;
187
188 int double_offset = offset();
189
190 // Account for return address and saved regs if input is esp.
191 if (input_reg.is(esp)) double_offset += 3 * kPointerSize;
192
193 MemOperand mantissa_operand(MemOperand(input_reg, double_offset));
194 MemOperand exponent_operand(MemOperand(input_reg,
195 double_offset + kDoubleSize / 2));
196
197 Register scratch1;
198 {
199 Register scratch_candidates[3] = { ebx, edx, edi };
200 for (int i = 0; i < 3; i++) {
201 scratch1 = scratch_candidates[i];
202 if (!final_result_reg.is(scratch1) && !input_reg.is(scratch1)) break;
203 }
204 }
205 // Since we must use ecx for shifts below, use some other register (eax)
206 // to calculate the result if ecx is the requested return register.
207 Register result_reg = final_result_reg.is(ecx) ? eax : final_result_reg;
208 // Save ecx if it isn't the return register and therefore volatile, or if it
209 // is the return register, then save the temp register we use in its stead for
210 // the result.
211 Register save_reg = final_result_reg.is(ecx) ? eax : ecx;
212 __ push(scratch1);
213 __ push(save_reg);
214
215 bool stash_exponent_copy = !input_reg.is(esp);
216 __ mov(scratch1, mantissa_operand);
217 if (CpuFeatures::IsSupported(SSE3)) {
218 CpuFeatureScope scope(masm, SSE3);
Ben Murdoch257744e2011-11-30 15:57:28 +0000219 // Load x87 register with heap number.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000220 __ fld_d(mantissa_operand);
221 }
222 __ mov(ecx, exponent_operand);
223 if (stash_exponent_copy) __ push(ecx);
224
225 __ and_(ecx, HeapNumber::kExponentMask);
226 __ shr(ecx, HeapNumber::kExponentShift);
227 __ lea(result_reg, MemOperand(ecx, -HeapNumber::kExponentBias));
228 __ cmp(result_reg, Immediate(HeapNumber::kMantissaBits));
229 __ j(below, &process_64_bits);
230
231 // Result is entirely in lower 32-bits of mantissa
232 int delta = HeapNumber::kExponentBias + Double::kPhysicalSignificandSize;
233 if (CpuFeatures::IsSupported(SSE3)) {
234 __ fstp(0);
235 }
236 __ sub(ecx, Immediate(delta));
237 __ xor_(result_reg, result_reg);
238 __ cmp(ecx, Immediate(31));
239 __ j(above, &done);
240 __ shl_cl(scratch1);
241 __ jmp(&check_negative);
242
243 __ bind(&process_64_bits);
244 if (CpuFeatures::IsSupported(SSE3)) {
245 CpuFeatureScope scope(masm, SSE3);
246 if (stash_exponent_copy) {
247 // Already a copy of the exponent on the stack, overwrite it.
248 STATIC_ASSERT(kDoubleSize == 2 * kPointerSize);
249 __ sub(esp, Immediate(kDoubleSize / 2));
250 } else {
251 // Reserve space for 64 bit answer.
252 __ sub(esp, Immediate(kDoubleSize)); // Nolint.
253 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000254 // Do conversion, which cannot fail because we checked the exponent.
255 __ fisttp_d(Operand(esp, 0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000256 __ mov(result_reg, Operand(esp, 0)); // Load low word of answer as result
257 __ add(esp, Immediate(kDoubleSize));
258 __ jmp(&done_no_stash);
Ben Murdoch257744e2011-11-30 15:57:28 +0000259 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000260 // Result must be extracted from shifted 32-bit mantissa
261 __ sub(ecx, Immediate(delta));
262 __ neg(ecx);
263 if (stash_exponent_copy) {
264 __ mov(result_reg, MemOperand(esp, 0));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100265 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000266 __ mov(result_reg, exponent_operand);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100267 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000268 __ and_(result_reg,
269 Immediate(static_cast<uint32_t>(Double::kSignificandMask >> 32)));
270 __ add(result_reg,
271 Immediate(static_cast<uint32_t>(Double::kHiddenBit >> 32)));
Ben Murdochda12d292016-06-02 14:46:10 +0100272 __ shrd_cl(scratch1, result_reg);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000273 __ shr_cl(result_reg);
274 __ test(ecx, Immediate(32));
275 __ cmov(not_equal, scratch1, result_reg);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100276 }
277
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000278 // If the double was negative, negate the integer result.
279 __ bind(&check_negative);
280 __ mov(result_reg, scratch1);
281 __ neg(result_reg);
282 if (stash_exponent_copy) {
283 __ cmp(MemOperand(esp, 0), Immediate(0));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100284 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000285 __ cmp(exponent_operand, Immediate(0));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100286 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000287 __ cmov(greater, result_reg, scratch1);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100288
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000289 // Restore registers
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100290 __ bind(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000291 if (stash_exponent_copy) {
292 __ add(esp, Immediate(kDoubleSize / 2));
293 }
294 __ bind(&done_no_stash);
295 if (!final_result_reg.is(result_reg)) {
296 DCHECK(final_result_reg.is(ecx));
297 __ mov(final_result_reg, result_reg);
298 }
299 __ pop(save_reg);
300 __ pop(scratch1);
301 __ ret(0);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100302}
303
304
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100305void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm,
306 Register number) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000307 Label load_smi, done;
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100308
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000309 __ JumpIfSmi(number, &load_smi, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100310 __ fld_d(FieldOperand(number, HeapNumber::kValueOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +0000311 __ jmp(&done, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100312
313 __ bind(&load_smi);
314 __ SmiUntag(number);
315 __ push(number);
316 __ fild_s(Operand(esp, 0));
317 __ pop(number);
318
319 __ bind(&done);
320}
321
322
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100323void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm,
324 Label* not_numbers) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000325 Label load_smi_edx, load_eax, load_smi_eax, load_float_eax, done;
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100326 // Load operand in edx into xmm0, or branch to not_numbers.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000327 __ JumpIfSmi(edx, &load_smi_edx, Label::kNear);
Steve Block44f0eee2011-05-26 01:26:41 +0100328 Factory* factory = masm->isolate()->factory();
329 __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100330 __ j(not_equal, not_numbers); // Argument in edx is not a number.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000331 __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100332 __ bind(&load_eax);
333 // Load operand in eax into xmm1, or branch to not_numbers.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000334 __ JumpIfSmi(eax, &load_smi_eax, Label::kNear);
Steve Block44f0eee2011-05-26 01:26:41 +0100335 __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map());
Ben Murdoch257744e2011-11-30 15:57:28 +0000336 __ j(equal, &load_float_eax, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100337 __ jmp(not_numbers); // Argument in eax is not a number.
338 __ bind(&load_smi_edx);
339 __ SmiUntag(edx); // Untag smi before converting to float.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000340 __ Cvtsi2sd(xmm0, edx);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100341 __ SmiTag(edx); // Retag smi for heap number overwriting test.
342 __ jmp(&load_eax);
343 __ bind(&load_smi_eax);
344 __ SmiUntag(eax); // Untag smi before converting to float.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000345 __ Cvtsi2sd(xmm1, eax);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100346 __ SmiTag(eax); // Retag smi for heap number overwriting test.
Ben Murdoch257744e2011-11-30 15:57:28 +0000347 __ jmp(&done, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100348 __ bind(&load_float_eax);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000349 __ movsd(xmm1, FieldOperand(eax, HeapNumber::kValueOffset));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100350 __ bind(&done);
351}
352
353
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100354void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm,
355 Label* non_float,
356 Register scratch) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000357 Label test_other, done;
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100358 // Test if both operands are floats or smi -> scratch=k_is_float;
359 // Otherwise scratch = k_not_float.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000360 __ JumpIfSmi(edx, &test_other, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100361 __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset));
Steve Block44f0eee2011-05-26 01:26:41 +0100362 Factory* factory = masm->isolate()->factory();
363 __ cmp(scratch, factory->heap_number_map());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100364 __ j(not_equal, non_float); // argument in edx is not a number -> NaN
365
366 __ bind(&test_other);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000367 __ JumpIfSmi(eax, &done, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100368 __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset));
Steve Block44f0eee2011-05-26 01:26:41 +0100369 __ cmp(scratch, factory->heap_number_map());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100370 __ j(not_equal, non_float); // argument in eax is not a number -> NaN
371
372 // Fall-through: Both operands are numbers.
373 __ bind(&done);
374}
375
376
Ben Murdochb0fe1622011-05-05 13:52:32 +0100377void MathPowStub::Generate(MacroAssembler* masm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000378 Factory* factory = isolate()->factory();
379 const Register exponent = MathPowTaggedDescriptor::exponent();
380 DCHECK(exponent.is(eax));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100381 const Register base = edx;
382 const Register scratch = ecx;
383 const XMMRegister double_result = xmm3;
384 const XMMRegister double_base = xmm2;
385 const XMMRegister double_exponent = xmm1;
386 const XMMRegister double_scratch = xmm4;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100387
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100388 Label call_runtime, done, exponent_not_smi, int_exponent;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100389
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100390 // Save 1 in double_result - we need this several times later on.
391 __ mov(scratch, Immediate(1));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000392 __ Cvtsi2sd(double_result, scratch);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100393
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000394 if (exponent_type() == ON_STACK) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100395 Label base_is_smi, unpack_exponent;
396 // The exponent and base are supplied as arguments on the stack.
397 // This can only happen if the stub is called from non-optimized code.
398 // Load input parameters from stack.
399 __ mov(base, Operand(esp, 2 * kPointerSize));
400 __ mov(exponent, Operand(esp, 1 * kPointerSize));
401
402 __ JumpIfSmi(base, &base_is_smi, Label::kNear);
403 __ cmp(FieldOperand(base, HeapObject::kMapOffset),
404 factory->heap_number_map());
405 __ j(not_equal, &call_runtime);
406
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000407 __ movsd(double_base, FieldOperand(base, HeapNumber::kValueOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100408 __ jmp(&unpack_exponent, Label::kNear);
409
410 __ bind(&base_is_smi);
411 __ SmiUntag(base);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000412 __ Cvtsi2sd(double_base, base);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100413
414 __ bind(&unpack_exponent);
415 __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear);
416 __ SmiUntag(exponent);
417 __ jmp(&int_exponent);
418
419 __ bind(&exponent_not_smi);
420 __ cmp(FieldOperand(exponent, HeapObject::kMapOffset),
421 factory->heap_number_map());
422 __ j(not_equal, &call_runtime);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000423 __ movsd(double_exponent,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100424 FieldOperand(exponent, HeapNumber::kValueOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000425 } else if (exponent_type() == TAGGED) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100426 __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear);
427 __ SmiUntag(exponent);
428 __ jmp(&int_exponent);
429
430 __ bind(&exponent_not_smi);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000431 __ movsd(double_exponent,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100432 FieldOperand(exponent, HeapNumber::kValueOffset));
433 }
434
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000435 if (exponent_type() != INTEGER) {
436 Label fast_power, try_arithmetic_simplification;
437 __ DoubleToI(exponent, double_exponent, double_scratch,
438 TREAT_MINUS_ZERO_AS_ZERO, &try_arithmetic_simplification,
439 &try_arithmetic_simplification,
440 &try_arithmetic_simplification);
441 __ jmp(&int_exponent);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100442
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000443 __ bind(&try_arithmetic_simplification);
444 // Skip to runtime if possibly NaN (indicated by the indefinite integer).
445 __ cvttsd2si(exponent, Operand(double_exponent));
446 __ cmp(exponent, Immediate(0x1));
447 __ j(overflow, &call_runtime);
448
449 if (exponent_type() == ON_STACK) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100450 // Detect square root case. Crankshaft detects constant +/-0.5 at
451 // compile time and uses DoMathPowHalf instead. We then skip this check
452 // for non-constant cases of +/-0.5 as these hardly occur.
453 Label continue_sqrt, continue_rsqrt, not_plus_half;
454 // Test for 0.5.
455 // Load double_scratch with 0.5.
456 __ mov(scratch, Immediate(0x3F000000u));
457 __ movd(double_scratch, scratch);
458 __ cvtss2sd(double_scratch, double_scratch);
459 // Already ruled out NaNs for exponent.
460 __ ucomisd(double_scratch, double_exponent);
461 __ j(not_equal, &not_plus_half, Label::kNear);
462
463 // Calculates square root of base. Check for the special case of
464 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
465 // According to IEEE-754, single-precision -Infinity has the highest
466 // 9 bits set and the lowest 23 bits cleared.
467 __ mov(scratch, 0xFF800000u);
468 __ movd(double_scratch, scratch);
469 __ cvtss2sd(double_scratch, double_scratch);
470 __ ucomisd(double_base, double_scratch);
471 // Comparing -Infinity with NaN results in "unordered", which sets the
472 // zero flag as if both were equal. However, it also sets the carry flag.
473 __ j(not_equal, &continue_sqrt, Label::kNear);
474 __ j(carry, &continue_sqrt, Label::kNear);
475
476 // Set result to Infinity in the special case.
477 __ xorps(double_result, double_result);
478 __ subsd(double_result, double_scratch);
479 __ jmp(&done);
480
481 __ bind(&continue_sqrt);
482 // sqrtsd returns -0 when input is -0. ECMA spec requires +0.
483 __ xorps(double_scratch, double_scratch);
484 __ addsd(double_scratch, double_base); // Convert -0 to +0.
485 __ sqrtsd(double_result, double_scratch);
486 __ jmp(&done);
487
488 // Test for -0.5.
489 __ bind(&not_plus_half);
490 // Load double_exponent with -0.5 by substracting 1.
491 __ subsd(double_scratch, double_result);
492 // Already ruled out NaNs for exponent.
493 __ ucomisd(double_scratch, double_exponent);
494 __ j(not_equal, &fast_power, Label::kNear);
495
496 // Calculates reciprocal of square root of base. Check for the special
497 // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
498 // According to IEEE-754, single-precision -Infinity has the highest
499 // 9 bits set and the lowest 23 bits cleared.
500 __ mov(scratch, 0xFF800000u);
501 __ movd(double_scratch, scratch);
502 __ cvtss2sd(double_scratch, double_scratch);
503 __ ucomisd(double_base, double_scratch);
504 // Comparing -Infinity with NaN results in "unordered", which sets the
505 // zero flag as if both were equal. However, it also sets the carry flag.
506 __ j(not_equal, &continue_rsqrt, Label::kNear);
507 __ j(carry, &continue_rsqrt, Label::kNear);
508
509 // Set result to 0 in the special case.
510 __ xorps(double_result, double_result);
511 __ jmp(&done);
512
513 __ bind(&continue_rsqrt);
514 // sqrtsd returns -0 when input is -0. ECMA spec requires +0.
515 __ xorps(double_exponent, double_exponent);
516 __ addsd(double_exponent, double_base); // Convert -0 to +0.
517 __ sqrtsd(double_exponent, double_exponent);
518 __ divsd(double_result, double_exponent);
519 __ jmp(&done);
520 }
521
522 // Using FPU instructions to calculate power.
523 Label fast_power_failed;
524 __ bind(&fast_power);
525 __ fnclex(); // Clear flags to catch exceptions later.
526 // Transfer (B)ase and (E)xponent onto the FPU register stack.
527 __ sub(esp, Immediate(kDoubleSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000528 __ movsd(Operand(esp, 0), double_exponent);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100529 __ fld_d(Operand(esp, 0)); // E
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000530 __ movsd(Operand(esp, 0), double_base);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100531 __ fld_d(Operand(esp, 0)); // B, E
532
533 // Exponent is in st(1) and base is in st(0)
534 // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B)
535 // FYL2X calculates st(1) * log2(st(0))
536 __ fyl2x(); // X
537 __ fld(0); // X, X
538 __ frndint(); // rnd(X), X
539 __ fsub(1); // rnd(X), X-rnd(X)
540 __ fxch(1); // X - rnd(X), rnd(X)
541 // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1
542 __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X)
543 __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000544 __ faddp(1); // 2^(X-rnd(X)), rnd(X)
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100545 // FSCALE calculates st(0) * 2^st(1)
546 __ fscale(); // 2^X, rnd(X)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000547 __ fstp(1); // 2^X
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100548 // Bail out to runtime in case of exceptions in the status word.
549 __ fnstsw_ax();
Ben Murdochda12d292016-06-02 14:46:10 +0100550 __ test_b(eax,
551 Immediate(0x5F)); // We check for all but precision exception.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100552 __ j(not_zero, &fast_power_failed, Label::kNear);
553 __ fstp_d(Operand(esp, 0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000554 __ movsd(double_result, Operand(esp, 0));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100555 __ add(esp, Immediate(kDoubleSize));
556 __ jmp(&done);
557
558 __ bind(&fast_power_failed);
559 __ fninit();
560 __ add(esp, Immediate(kDoubleSize));
561 __ jmp(&call_runtime);
562 }
563
564 // Calculate power with integer exponent.
565 __ bind(&int_exponent);
566 const XMMRegister double_scratch2 = double_exponent;
567 __ mov(scratch, exponent); // Back up exponent.
568 __ movsd(double_scratch, double_base); // Back up base.
569 __ movsd(double_scratch2, double_result); // Load double_exponent with 1.
Ben Murdochb0fe1622011-05-05 13:52:32 +0100570
571 // Get absolute value of exponent.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000572 Label no_neg, while_true, while_false;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100573 __ test(scratch, scratch);
574 __ j(positive, &no_neg, Label::kNear);
575 __ neg(scratch);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100576 __ bind(&no_neg);
577
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000578 __ j(zero, &while_false, Label::kNear);
579 __ shr(scratch, 1);
580 // Above condition means CF==0 && ZF==0. This means that the
581 // bit that has been shifted out is 0 and the result is not 0.
582 __ j(above, &while_true, Label::kNear);
583 __ movsd(double_result, double_scratch);
584 __ j(zero, &while_false, Label::kNear);
585
Ben Murdoch85b71792012-04-11 18:30:58 +0100586 __ bind(&while_true);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100587 __ shr(scratch, 1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100588 __ mulsd(double_scratch, double_scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000589 __ j(above, &while_true, Label::kNear);
590 __ mulsd(double_result, double_scratch);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100591 __ j(not_zero, &while_true);
592
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000593 __ bind(&while_false);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100594 // scratch has the original value of the exponent - if the exponent is
595 // negative, return 1/result.
596 __ test(exponent, exponent);
597 __ j(positive, &done);
598 __ divsd(double_scratch2, double_result);
599 __ movsd(double_result, double_scratch2);
600 // Test whether result is zero. Bail out to check for subnormal result.
601 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
602 __ xorps(double_scratch2, double_scratch2);
603 __ ucomisd(double_scratch2, double_result); // Result cannot be NaN.
604 // double_exponent aliased as double_scratch2 has already been overwritten
605 // and may not have contained the exponent value in the first place when the
606 // exponent is a smi. We reset it with exponent value before bailing out.
607 __ j(not_equal, &done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000608 __ Cvtsi2sd(double_exponent, exponent);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100609
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100610 // Returning or bailing out.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000611 if (exponent_type() == ON_STACK) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100612 // The arguments are still on the stack.
613 __ bind(&call_runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000614 __ TailCallRuntime(Runtime::kMathPowRT);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100615
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100616 // The stub is called from non-optimized code, which expects the result
617 // as heap number in exponent.
618 __ bind(&done);
619 __ AllocateHeapNumber(eax, scratch, base, &call_runtime);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000620 __ movsd(FieldOperand(eax, HeapNumber::kValueOffset), double_result);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100621 __ ret(2 * kPointerSize);
622 } else {
623 __ bind(&call_runtime);
624 {
625 AllowExternalCallThatCantCauseGC scope(masm);
626 __ PrepareCallCFunction(4, scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000627 __ movsd(Operand(esp, 0 * kDoubleSize), double_base);
628 __ movsd(Operand(esp, 1 * kDoubleSize), double_exponent);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100629 __ CallCFunction(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000630 ExternalReference::power_double_double_function(isolate()), 4);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100631 }
632 // Return value is in st(0) on ia32.
633 // Store it into the (fixed) result register.
634 __ sub(esp, Immediate(kDoubleSize));
635 __ fstp_d(Operand(esp, 0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000636 __ movsd(double_result, Operand(esp, 0));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100637 __ add(esp, Immediate(kDoubleSize));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100638
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100639 __ bind(&done);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100640 __ ret(0);
641 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100642}
643
644
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000645void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
646 Label miss;
647 Register receiver = LoadDescriptor::ReceiverRegister();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000648 // With careful management, we won't have to save slot and vector on
649 // the stack. Simply handle the possibly missing case first.
650 // TODO(mvstanton): this code can be more efficient.
651 __ cmp(FieldOperand(receiver, JSFunction::kPrototypeOrInitialMapOffset),
652 Immediate(isolate()->factory()->the_hole_value()));
653 __ j(equal, &miss);
654 __ TryGetFunctionPrototype(receiver, eax, ebx, &miss);
655 __ ret(0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000656
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000657 __ bind(&miss);
658 PropertyAccessCompiler::TailCallBuiltin(
659 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
660}
661
662
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400663void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
664 // Return address is on the stack.
665 Label miss;
666
667 Register receiver = LoadDescriptor::ReceiverRegister();
668 Register index = LoadDescriptor::NameRegister();
669 Register scratch = edi;
670 DCHECK(!scratch.is(receiver) && !scratch.is(index));
671 Register result = eax;
672 DCHECK(!result.is(scratch));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000673 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
674 result.is(LoadDescriptor::SlotRegister()));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400675
676 // StringCharAtGenerator doesn't use the result register until it's passed
677 // the different miss possibilities. If it did, we would have a conflict
678 // when FLAG_vector_ics is true.
679 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
680 &miss, // When not a string.
681 &miss, // When not a number.
682 &miss, // When index out of range.
683 STRING_INDEX_IS_ARRAY_INDEX,
684 RECEIVER_IS_STRING);
685 char_at_generator.GenerateFast(masm);
686 __ ret(0);
687
688 StubRuntimeCallHelper call_helper;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000689 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400690
691 __ bind(&miss);
692 PropertyAccessCompiler::TailCallBuiltin(
693 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
694}
695
696
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100697void RegExpExecStub::Generate(MacroAssembler* masm) {
698 // Just jump directly to runtime if native RegExp is not selected at compile
699 // time or if regexp entry in generated code is turned off runtime switch or
700 // at compilation.
701#ifdef V8_INTERPRETED_REGEXP
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000702 __ TailCallRuntime(Runtime::kRegExpExec);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100703#else // V8_INTERPRETED_REGEXP
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100704
705 // Stack frame on entry.
706 // esp[0]: return address
707 // esp[4]: last_match_info (expected JSArray)
708 // esp[8]: previous index
709 // esp[12]: subject string
710 // esp[16]: JSRegExp object
711
712 static const int kLastMatchInfoOffset = 1 * kPointerSize;
713 static const int kPreviousIndexOffset = 2 * kPointerSize;
714 static const int kSubjectOffset = 3 * kPointerSize;
715 static const int kJSRegExpOffset = 4 * kPointerSize;
716
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000717 Label runtime;
718 Factory* factory = isolate()->factory();
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100719
720 // Ensure that a RegExp stack is allocated.
721 ExternalReference address_of_regexp_stack_memory_address =
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000722 ExternalReference::address_of_regexp_stack_memory_address(isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100723 ExternalReference address_of_regexp_stack_memory_size =
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000724 ExternalReference::address_of_regexp_stack_memory_size(isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100725 __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100726 __ test(ebx, ebx);
Ben Murdoch257744e2011-11-30 15:57:28 +0000727 __ j(zero, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100728
729 // Check that the first argument is a JSRegExp object.
730 __ mov(eax, Operand(esp, kJSRegExpOffset));
731 STATIC_ASSERT(kSmiTag == 0);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000732 __ JumpIfSmi(eax, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100733 __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx);
734 __ j(not_equal, &runtime);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000735
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100736 // Check that the RegExp has been compiled (data contains a fixed array).
737 __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset));
738 if (FLAG_debug_code) {
739 __ test(ecx, Immediate(kSmiTagMask));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000740 __ Check(not_zero, kUnexpectedTypeForRegExpDataFixedArrayExpected);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100741 __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000742 __ Check(equal, kUnexpectedTypeForRegExpDataFixedArrayExpected);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100743 }
744
745 // ecx: RegExp data (FixedArray)
746 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
747 __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100748 __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP)));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100749 __ j(not_equal, &runtime);
750
751 // ecx: RegExp data (FixedArray)
752 // Check that the number of captures fit in the static offsets vector buffer.
753 __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000754 // Check (number_of_captures + 1) * 2 <= offsets vector size
755 // Or number_of_captures * 2 <= offsets vector size - 2
756 // Multiplying by 2 comes for free since edx is smi-tagged.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100757 STATIC_ASSERT(kSmiTag == 0);
758 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000759 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
760 __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100761 __ j(above, &runtime);
762
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000763 // Reset offset for possibly sliced string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000764 __ Move(edi, Immediate(0));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100765 __ mov(eax, Operand(esp, kSubjectOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000766 __ JumpIfSmi(eax, &runtime);
767 __ mov(edx, eax); // Make a copy of the original subject string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000768
769 // eax: subject string
770 // edx: subject string
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000771 // ecx: RegExp data (FixedArray)
772 // Handle subject string according to its encoding and representation:
773 // (1) Sequential two byte? If yes, go to (9).
Ben Murdoch097c5b22016-05-18 11:27:45 +0100774 // (2) Sequential one byte? If yes, go to (5).
775 // (3) Sequential or cons? If not, go to (6).
776 // (4) Cons string. If the string is flat, replace subject with first string
777 // and go to (1). Otherwise bail out to runtime.
778 // (5) One byte sequential. Load regexp code for one byte.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000779 // (E) Carry on.
780 /// [...]
781
782 // Deferred code at the end of the stub:
Ben Murdoch097c5b22016-05-18 11:27:45 +0100783 // (6) Long external string? If not, go to (10).
784 // (7) External string. Make it, offset-wise, look like a sequential string.
785 // (8) Is the external string one byte? If yes, go to (5).
786 // (9) Two byte sequential. Load regexp code for two byte. Go to (E).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000787 // (10) Short external string or not a string? If yes, bail out to runtime.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100788 // (11) Sliced string. Replace subject with parent. Go to (1).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000789
Ben Murdoch097c5b22016-05-18 11:27:45 +0100790 Label seq_one_byte_string /* 5 */, seq_two_byte_string /* 9 */,
791 external_string /* 7 */, check_underlying /* 1 */,
792 not_seq_nor_cons /* 6 */, check_code /* E */, not_long_external /* 10 */;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000793
Ben Murdoch097c5b22016-05-18 11:27:45 +0100794 __ bind(&check_underlying);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000795 // (1) Sequential two byte? If yes, go to (9).
Ben Murdoch097c5b22016-05-18 11:27:45 +0100796 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
797 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
798
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100799 __ and_(ebx, kIsNotStringMask |
800 kStringRepresentationMask |
801 kStringEncodingMask |
802 kShortExternalStringMask);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100803 STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000804 __ j(zero, &seq_two_byte_string); // Go to (9).
805
Ben Murdoch097c5b22016-05-18 11:27:45 +0100806 // (2) Sequential one byte? If yes, go to (5).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000807 // Any other sequential string must be one byte.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100808 __ and_(ebx, Immediate(kIsNotStringMask |
809 kStringRepresentationMask |
810 kShortExternalStringMask));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100811 __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (5).
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100812
Ben Murdoch097c5b22016-05-18 11:27:45 +0100813 // (3) Sequential or cons? If not, go to (6).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000814 // We check whether the subject string is a cons, since sequential strings
815 // have already been covered.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000816 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
817 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100818 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
819 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
820 __ cmp(ebx, Immediate(kExternalStringTag));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100821 __ j(greater_equal, &not_seq_nor_cons); // Go to (6).
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100822
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000823 // (4) Cons string. Check that it's flat.
824 // Replace subject with first string and reload instance type.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000825 __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100826 __ j(not_equal, &runtime);
827 __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100828 __ jmp(&check_underlying);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100829
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000830 // eax: sequential subject string (or look-alike, external string)
831 // edx: original subject string
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100832 // ecx: RegExp data (FixedArray)
Ben Murdoch097c5b22016-05-18 11:27:45 +0100833 // (5) One byte sequential. Load regexp code for one byte.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000834 __ bind(&seq_one_byte_string);
835 // Load previous index and check range before edx is overwritten. We have
836 // to use edx instead of eax here because it might have been only made to
837 // look like a sequential string when it actually is an external string.
838 __ mov(ebx, Operand(esp, kPreviousIndexOffset));
839 __ JumpIfNotSmi(ebx, &runtime);
840 __ cmp(ebx, FieldOperand(edx, String::kLengthOffset));
841 __ j(above_equal, &runtime);
842 __ mov(edx, FieldOperand(ecx, JSRegExp::kDataOneByteCodeOffset));
843 __ Move(ecx, Immediate(1)); // Type is one byte.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100844
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000845 // (E) Carry on. String handling is done.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100846 __ bind(&check_code);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000847 // edx: irregexp code
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100848 // Check that the irregexp code has been generated for the actual string
849 // encoding. If it has, the field contains a code object otherwise it contains
Ben Murdoch257744e2011-11-30 15:57:28 +0000850 // a smi (code flushing support).
851 __ JumpIfSmi(edx, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100852
853 // eax: subject string
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000854 // ebx: previous index (smi)
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100855 // edx: code
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000856 // ecx: encoding of subject string (1 if one_byte, 0 if two_byte);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100857 // All checks done. Now push arguments for native regexp code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000858 Counters* counters = isolate()->counters();
Steve Block44f0eee2011-05-26 01:26:41 +0100859 __ IncrementCounter(counters->regexp_entry_native(), 1);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100860
Steve Block44f0eee2011-05-26 01:26:41 +0100861 // Isolates: note we add an additional parameter here (isolate pointer).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000862 static const int kRegExpExecuteArguments = 9;
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100863 __ EnterApiExitFrame(kRegExpExecuteArguments);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100864
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000865 // Argument 9: Pass current isolate address.
866 __ mov(Operand(esp, 8 * kPointerSize),
867 Immediate(ExternalReference::isolate_address(isolate())));
Steve Block44f0eee2011-05-26 01:26:41 +0100868
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000869 // Argument 8: Indicate that this is a direct call from JavaScript.
870 __ mov(Operand(esp, 7 * kPointerSize), Immediate(1));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100871
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000872 // Argument 7: Start (high end) of backtracking stack memory area.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000873 __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address));
874 __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000875 __ mov(Operand(esp, 6 * kPointerSize), esi);
876
877 // Argument 6: Set the number of capture registers to zero to force global
878 // regexps to behave as non-global. This does not affect non-global regexps.
879 __ mov(Operand(esp, 5 * kPointerSize), Immediate(0));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100880
881 // Argument 5: static offsets vector buffer.
882 __ mov(Operand(esp, 4 * kPointerSize),
Steve Block44f0eee2011-05-26 01:26:41 +0100883 Immediate(ExternalReference::address_of_static_offsets_vector(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000884 isolate())));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100885
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000886 // Argument 2: Previous index.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000887 __ SmiUntag(ebx);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000888 __ mov(Operand(esp, 1 * kPointerSize), ebx);
889
890 // Argument 1: Original subject string.
891 // The original subject is in the previous stack frame. Therefore we have to
892 // use ebp, which points exactly to one pointer size below the previous esp.
893 // (Because creating a new stack frame pushes the previous ebp onto the stack
894 // and thereby moves up esp by one kPointerSize.)
895 __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize));
896 __ mov(Operand(esp, 0 * kPointerSize), esi);
897
898 // esi: original subject string
899 // eax: underlying subject string
900 // ebx: previous index
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000901 // ecx: encoding of subject string (1 if one_byte 0 if two_byte);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000902 // edx: code
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100903 // Argument 4: End of string data
904 // Argument 3: Start of string data
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000905 // Prepare start and end index of the input.
906 // Load the length from the original sliced string if that is the case.
907 __ mov(esi, FieldOperand(esi, String::kLengthOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100908 __ add(esi, edi); // Calculate input end wrt offset.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100909 __ SmiUntag(edi);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100910 __ add(ebx, edi); // Calculate input start wrt offset.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000911
912 // ebx: start index of the input string
913 // esi: end index of the input string
914 Label setup_two_byte, setup_rest;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100915 __ test(ecx, ecx);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000916 __ j(zero, &setup_two_byte, Label::kNear);
917 __ SmiUntag(esi);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000918 __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100919 __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000920 __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100921 __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3.
Ben Murdoch257744e2011-11-30 15:57:28 +0000922 __ jmp(&setup_rest, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100923
924 __ bind(&setup_two_byte);
925 STATIC_ASSERT(kSmiTag == 0);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000926 STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2).
927 __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100928 __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4.
929 __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize));
930 __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3.
931
932 __ bind(&setup_rest);
933
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100934 // Locate the code entry and call it.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100935 __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag));
936 __ call(edx);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100937
938 // Drop arguments and come back to JS mode.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000939 __ LeaveApiExitFrame(true);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100940
941 // Check the result.
942 Label success;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000943 __ cmp(eax, 1);
944 // We expect exactly one result since we force the called regexp to behave
945 // as non-global.
Ben Murdoch257744e2011-11-30 15:57:28 +0000946 __ j(equal, &success);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100947 Label failure;
948 __ cmp(eax, NativeRegExpMacroAssembler::FAILURE);
Ben Murdoch257744e2011-11-30 15:57:28 +0000949 __ j(equal, &failure);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100950 __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION);
951 // If not exception it can only be retry. Handle that in the runtime system.
952 __ j(not_equal, &runtime);
953 // Result must now be exception. If there is no pending exception already a
954 // stack overflow (on the backtrack stack) was detected in RegExp code but
955 // haven't created the exception yet. Handle that in the runtime system.
956 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
Ben Murdoch589d6972011-11-30 16:04:58 +0000957 ExternalReference pending_exception(Isolate::kPendingExceptionAddress,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000958 isolate());
959 __ mov(edx, Immediate(isolate()->factory()->the_hole_value()));
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100960 __ mov(eax, Operand::StaticVariable(pending_exception));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100961 __ cmp(edx, eax);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100962 __ j(equal, &runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000963
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100964 // For exception, throw the exception again.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000965 __ TailCallRuntime(Runtime::kRegExpExecReThrow);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100966
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100967 __ bind(&failure);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100968 // For failure to match, return null.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100969 __ mov(eax, factory->null_value());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100970 __ ret(4 * kPointerSize);
971
972 // Load RegExp data.
973 __ bind(&success);
974 __ mov(eax, Operand(esp, kJSRegExpOffset));
975 __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset));
976 __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset));
977 // Calculate number of capture registers (number_of_captures + 1) * 2.
978 STATIC_ASSERT(kSmiTag == 0);
979 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100980 __ add(edx, Immediate(2)); // edx was a smi.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100981
982 // edx: Number of capture registers
983 // Load last_match_info which is still known to be a fast case JSArray.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000984 // Check that the fourth object is a JSArray object.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100985 __ mov(eax, Operand(esp, kLastMatchInfoOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000986 __ JumpIfSmi(eax, &runtime);
987 __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx);
988 __ j(not_equal, &runtime);
989 // Check that the JSArray is in fast case.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100990 __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000991 __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset));
992 __ cmp(eax, factory->fixed_array_map());
993 __ j(not_equal, &runtime);
994 // Check that the last match info has space for the capture registers and the
995 // additional information.
996 __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset));
997 __ SmiUntag(eax);
998 __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead));
999 __ cmp(edx, eax);
1000 __ j(greater, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001001
1002 // ebx: last_match_info backing store (FixedArray)
1003 // edx: number of capture registers
1004 // Store the capture count.
1005 __ SmiTag(edx); // Number of capture registers to smi.
1006 __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx);
1007 __ SmiUntag(edx); // Number of capture registers back from smi.
1008 // Store last subject and last input.
1009 __ mov(eax, Operand(esp, kSubjectOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001010 __ mov(ecx, eax);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001011 __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001012 __ RecordWriteField(ebx,
1013 RegExpImpl::kLastSubjectOffset,
1014 eax,
1015 edi,
1016 kDontSaveFPRegs);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001017 __ mov(eax, ecx);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001018 __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001019 __ RecordWriteField(ebx,
1020 RegExpImpl::kLastInputOffset,
1021 eax,
1022 edi,
1023 kDontSaveFPRegs);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001024
1025 // Get the static offsets vector filled by the native regexp code.
1026 ExternalReference address_of_static_offsets_vector =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001027 ExternalReference::address_of_static_offsets_vector(isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001028 __ mov(ecx, Immediate(address_of_static_offsets_vector));
1029
1030 // ebx: last_match_info backing store (FixedArray)
1031 // ecx: offsets vector
1032 // edx: number of capture registers
Ben Murdoch257744e2011-11-30 15:57:28 +00001033 Label next_capture, done;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001034 // Capture register counter starts from number of capture registers and
1035 // counts down until wraping after zero.
1036 __ bind(&next_capture);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001037 __ sub(edx, Immediate(1));
Ben Murdoch257744e2011-11-30 15:57:28 +00001038 __ j(negative, &done, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001039 // Read the value from the static offsets vector buffer.
1040 __ mov(edi, Operand(ecx, edx, times_int_size, 0));
1041 __ SmiTag(edi);
1042 // Store the smi value in the last match info.
1043 __ mov(FieldOperand(ebx,
1044 edx,
1045 times_pointer_size,
1046 RegExpImpl::kFirstCaptureOffset),
1047 edi);
1048 __ jmp(&next_capture);
1049 __ bind(&done);
1050
1051 // Return last match info.
1052 __ mov(eax, Operand(esp, kLastMatchInfoOffset));
1053 __ ret(4 * kPointerSize);
1054
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001055 // Do the runtime call to execute the regexp.
1056 __ bind(&runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001057 __ TailCallRuntime(Runtime::kRegExpExec);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001058
1059 // Deferred code for string handling.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001060 // (6) Long external string? If not, go to (10).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001061 __ bind(&not_seq_nor_cons);
1062 // Compare flags are still set from (3).
1063 __ j(greater, &not_long_external, Label::kNear); // Go to (10).
1064
Ben Murdoch097c5b22016-05-18 11:27:45 +01001065 // (7) External string. Short external strings have been ruled out.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001066 __ bind(&external_string);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001067 // Reload instance type.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001068 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
1069 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
1070 if (FLAG_debug_code) {
1071 // Assert that we do not have a cons or slice (indirect strings) here.
1072 // Sequential strings have already been ruled out.
Ben Murdochda12d292016-06-02 14:46:10 +01001073 __ test_b(ebx, Immediate(kIsIndirectStringMask));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001074 __ Assert(zero, kExternalStringExpectedButNotFound);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001075 }
1076 __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset));
1077 // Move the pointer so that offset-wise, it looks like a sequential string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001078 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001079 __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
1080 STATIC_ASSERT(kTwoByteStringTag == 0);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001081 // (8) Is the external string one byte? If yes, go to (5).
Ben Murdochda12d292016-06-02 14:46:10 +01001082 __ test_b(ebx, Immediate(kStringEncodingMask));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001083 __ j(not_zero, &seq_one_byte_string); // Go to (5).
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001084
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001085 // eax: sequential subject string (or look-alike, external string)
1086 // edx: original subject string
1087 // ecx: RegExp data (FixedArray)
Ben Murdoch097c5b22016-05-18 11:27:45 +01001088 // (9) Two byte sequential. Load regexp code for two byte. Go to (E).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001089 __ bind(&seq_two_byte_string);
1090 // Load previous index and check range before edx is overwritten. We have
1091 // to use edx instead of eax here because it might have been only made to
1092 // look like a sequential string when it actually is an external string.
1093 __ mov(ebx, Operand(esp, kPreviousIndexOffset));
1094 __ JumpIfNotSmi(ebx, &runtime);
1095 __ cmp(ebx, FieldOperand(edx, String::kLengthOffset));
1096 __ j(above_equal, &runtime);
1097 __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset));
1098 __ Move(ecx, Immediate(0)); // Type is two byte.
1099 __ jmp(&check_code); // Go to (E).
1100
1101 // (10) Not a string or a short external string? If yes, bail out to runtime.
1102 __ bind(&not_long_external);
1103 // Catch non-string subject or short external string.
1104 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
1105 __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag));
1106 __ j(not_zero, &runtime);
1107
Ben Murdoch097c5b22016-05-18 11:27:45 +01001108 // (11) Sliced string. Replace subject with parent. Go to (1).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001109 // Load offset into edi and replace subject string with parent.
1110 __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset));
1111 __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001112 __ jmp(&check_underlying); // Go to (1).
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001113#endif // V8_INTERPRETED_REGEXP
1114}
1115
1116
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001117static int NegativeComparisonResult(Condition cc) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001118 DCHECK(cc != equal);
1119 DCHECK((cc == less) || (cc == less_equal)
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001120 || (cc == greater) || (cc == greater_equal));
1121 return (cc == greater || cc == greater_equal) ? LESS : GREATER;
1122}
1123
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001124
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001125static void CheckInputType(MacroAssembler* masm, Register input,
1126 CompareICState::State expected, Label* fail) {
1127 Label ok;
1128 if (expected == CompareICState::SMI) {
1129 __ JumpIfNotSmi(input, fail);
1130 } else if (expected == CompareICState::NUMBER) {
1131 __ JumpIfSmi(input, &ok);
1132 __ cmp(FieldOperand(input, HeapObject::kMapOffset),
1133 Immediate(masm->isolate()->factory()->heap_number_map()));
1134 __ j(not_equal, fail);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001135 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001136 // We could be strict about internalized/non-internalized here, but as long as
1137 // hydrogen doesn't care, the stub doesn't have to care either.
1138 __ bind(&ok);
1139}
1140
1141
1142static void BranchIfNotInternalizedString(MacroAssembler* masm,
1143 Label* label,
1144 Register object,
1145 Register scratch) {
1146 __ JumpIfSmi(object, label);
1147 __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset));
1148 __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset));
1149 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
1150 __ test(scratch, Immediate(kIsNotStringMask | kIsNotInternalizedMask));
1151 __ j(not_zero, label);
1152}
1153
1154
1155void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001156 Label runtime_call, check_unequal_objects;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001157 Condition cc = GetCondition();
1158
1159 Label miss;
1160 CheckInputType(masm, edx, left(), &miss);
1161 CheckInputType(masm, eax, right(), &miss);
1162
1163 // Compare two smis.
1164 Label non_smi, smi_done;
1165 __ mov(ecx, edx);
1166 __ or_(ecx, eax);
1167 __ JumpIfNotSmi(ecx, &non_smi, Label::kNear);
1168 __ sub(edx, eax); // Return on the result of the subtraction.
1169 __ j(no_overflow, &smi_done, Label::kNear);
1170 __ not_(edx); // Correct sign in case of overflow. edx is never 0 here.
1171 __ bind(&smi_done);
1172 __ mov(eax, edx);
1173 __ ret(0);
1174 __ bind(&non_smi);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001175
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001176 // NOTICE! This code is only reached after a smi-fast-case check, so
1177 // it is certain that at least one operand isn't a smi.
1178
1179 // Identical objects can be compared fast, but there are some tricky cases
1180 // for NaN and undefined.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001181 Label generic_heap_number_comparison;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001182 {
1183 Label not_identical;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001184 __ cmp(eax, edx);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001185 __ j(not_equal, &not_identical);
1186
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001187 if (cc != equal) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001188 // Check for undefined. undefined OP undefined is false even though
1189 // undefined == undefined.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001190 __ cmp(edx, isolate()->factory()->undefined_value());
Ben Murdoch097c5b22016-05-18 11:27:45 +01001191 Label check_for_nan;
1192 __ j(not_equal, &check_for_nan, Label::kNear);
1193 __ Move(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc))));
1194 __ ret(0);
1195 __ bind(&check_for_nan);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001196 }
1197
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001198 // Test for NaN. Compare heap numbers in a general way,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001199 // to handle NaNs correctly.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001200 __ cmp(FieldOperand(edx, HeapObject::kMapOffset),
1201 Immediate(isolate()->factory()->heap_number_map()));
1202 __ j(equal, &generic_heap_number_comparison, Label::kNear);
1203 if (cc != equal) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001204 __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset));
1205 __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001206 // Call runtime on identical JSObjects. Otherwise return equal.
Ben Murdochda12d292016-06-02 14:46:10 +01001207 __ cmpb(ecx, Immediate(FIRST_JS_RECEIVER_TYPE));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001208 __ j(above_equal, &runtime_call, Label::kFar);
1209 // Call runtime on identical symbols since we need to throw a TypeError.
Ben Murdochda12d292016-06-02 14:46:10 +01001210 __ cmpb(ecx, Immediate(SYMBOL_TYPE));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001211 __ j(equal, &runtime_call, Label::kFar);
1212 // Call runtime on identical SIMD values since we must throw a TypeError.
Ben Murdochda12d292016-06-02 14:46:10 +01001213 __ cmpb(ecx, Immediate(SIMD128_VALUE_TYPE));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001214 __ j(equal, &runtime_call, Label::kFar);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001215 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001216 __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
1217 __ ret(0);
1218
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001219
1220 __ bind(&not_identical);
1221 }
1222
1223 // Strict equality can quickly decide whether objects are equal.
1224 // Non-strict object equality is slower, so it is handled later in the stub.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001225 if (cc == equal && strict()) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001226 Label slow; // Fallthrough label.
Ben Murdoch257744e2011-11-30 15:57:28 +00001227 Label not_smis;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001228 // If we're doing a strict equality comparison, we don't have to do
1229 // type conversion, so we generate code to do fast comparison for objects
1230 // and oddballs. Non-smi numbers and strings still go through the usual
1231 // slow-case code.
1232 // If either is a Smi (we know that not both are), then they can only
1233 // be equal if the other is a HeapNumber. If so, use the slow case.
1234 STATIC_ASSERT(kSmiTag == 0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001235 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001236 __ mov(ecx, Immediate(kSmiTagMask));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001237 __ and_(ecx, eax);
1238 __ test(ecx, edx);
Ben Murdoch257744e2011-11-30 15:57:28 +00001239 __ j(not_zero, &not_smis, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001240 // One operand is a smi.
1241
1242 // Check whether the non-smi is a heap number.
1243 STATIC_ASSERT(kSmiTagMask == 1);
1244 // ecx still holds eax & kSmiTag, which is either zero or one.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001245 __ sub(ecx, Immediate(0x01));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001246 __ mov(ebx, edx);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001247 __ xor_(ebx, eax);
1248 __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx.
1249 __ xor_(ebx, eax);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001250 // if eax was smi, ebx is now edx, else eax.
1251
1252 // Check if the non-smi operand is a heap number.
1253 __ cmp(FieldOperand(ebx, HeapObject::kMapOffset),
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001254 Immediate(isolate()->factory()->heap_number_map()));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001255 // If heap number, handle it in the slow case.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001256 __ j(equal, &slow, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001257 // Return non-equal (ebx is not zero)
1258 __ mov(eax, ebx);
1259 __ ret(0);
1260
1261 __ bind(&not_smis);
1262 // If either operand is a JSObject or an oddball value, then they are not
1263 // equal since their pointers are different
1264 // There is no test for undetectability in strict equality.
1265
1266 // Get the type of the first operand.
1267 // If the first object is a JS object, we have done pointer comparison.
Ben Murdoch257744e2011-11-30 15:57:28 +00001268 Label first_non_object;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001269 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
1270 __ CmpObjectType(eax, FIRST_JS_RECEIVER_TYPE, ecx);
Ben Murdoch257744e2011-11-30 15:57:28 +00001271 __ j(below, &first_non_object, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001272
1273 // Return non-zero (eax is not zero)
Ben Murdoch257744e2011-11-30 15:57:28 +00001274 Label return_not_equal;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001275 STATIC_ASSERT(kHeapObjectTag != 0);
1276 __ bind(&return_not_equal);
1277 __ ret(0);
1278
1279 __ bind(&first_non_object);
1280 // Check for oddballs: true, false, null, undefined.
1281 __ CmpInstanceType(ecx, ODDBALL_TYPE);
1282 __ j(equal, &return_not_equal);
1283
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001284 __ CmpObjectType(edx, FIRST_JS_RECEIVER_TYPE, ecx);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001285 __ j(above_equal, &return_not_equal);
1286
1287 // Check for oddballs: true, false, null, undefined.
1288 __ CmpInstanceType(ecx, ODDBALL_TYPE);
1289 __ j(equal, &return_not_equal);
1290
1291 // Fall through to the general case.
1292 __ bind(&slow);
1293 }
1294
1295 // Generate the number comparison code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001296 Label non_number_comparison;
1297 Label unordered;
1298 __ bind(&generic_heap_number_comparison);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001299
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001300 FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison);
1301 __ ucomisd(xmm0, xmm1);
1302 // Don't base result on EFLAGS when a NaN is involved.
1303 __ j(parity_even, &unordered, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001304
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001305 __ mov(eax, 0); // equal
1306 __ mov(ecx, Immediate(Smi::FromInt(1)));
1307 __ cmov(above, eax, ecx);
1308 __ mov(ecx, Immediate(Smi::FromInt(-1)));
1309 __ cmov(below, eax, ecx);
1310 __ ret(0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001311
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001312 // If one of the numbers was NaN, then the result is always false.
1313 // The cc is never not-equal.
1314 __ bind(&unordered);
1315 DCHECK(cc != not_equal);
1316 if (cc == less || cc == less_equal) {
1317 __ mov(eax, Immediate(Smi::FromInt(1)));
1318 } else {
1319 __ mov(eax, Immediate(Smi::FromInt(-1)));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001320 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001321 __ ret(0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001322
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001323 // The number comparison code did not provide a valid result.
1324 __ bind(&non_number_comparison);
1325
1326 // Fast negative check for internalized-to-internalized equality.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001327 Label check_for_strings;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001328 if (cc == equal) {
1329 BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx);
1330 BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001331
1332 // We've already checked for object identity, so if both operands
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001333 // are internalized they aren't equal. Register eax already holds a
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001334 // non-zero value, which indicates not equal, so just return.
1335 __ ret(0);
1336 }
1337
1338 __ bind(&check_for_strings);
1339
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001340 __ JumpIfNotBothSequentialOneByteStrings(edx, eax, ecx, ebx,
1341 &check_unequal_objects);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001342
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001343 // Inline comparison of one-byte strings.
1344 if (cc == equal) {
1345 StringHelper::GenerateFlatOneByteStringEquals(masm, edx, eax, ecx, ebx);
Ben Murdoch257744e2011-11-30 15:57:28 +00001346 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001347 StringHelper::GenerateCompareFlatOneByteStrings(masm, edx, eax, ecx, ebx,
1348 edi);
Ben Murdoch257744e2011-11-30 15:57:28 +00001349 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001350#ifdef DEBUG
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001351 __ Abort(kUnexpectedFallThroughFromStringComparison);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001352#endif
1353
1354 __ bind(&check_unequal_objects);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001355 if (cc == equal && !strict()) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001356 // Non-strict equality. Objects are unequal if
1357 // they are both JSObjects and not undetectable,
1358 // and their pointers are different.
Ben Murdochda12d292016-06-02 14:46:10 +01001359 Label return_equal, return_unequal, undetectable;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001360 // At most one is a smi, so we can test for smi by adding the two.
1361 // A smi plus a heap object has the low bit set, a heap object plus
1362 // a heap object has the low bit clear.
1363 STATIC_ASSERT(kSmiTag == 0);
1364 STATIC_ASSERT(kSmiTagMask == 1);
1365 __ lea(ecx, Operand(eax, edx, times_1, 0));
1366 __ test(ecx, Immediate(kSmiTagMask));
Ben Murdochda12d292016-06-02 14:46:10 +01001367 __ j(not_zero, &runtime_call);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001368
1369 __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset));
1370 __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset));
1371
1372 __ test_b(FieldOperand(ebx, Map::kBitFieldOffset),
Ben Murdochda12d292016-06-02 14:46:10 +01001373 Immediate(1 << Map::kIsUndetectable));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001374 __ j(not_zero, &undetectable, Label::kNear);
1375 __ test_b(FieldOperand(ecx, Map::kBitFieldOffset),
Ben Murdochda12d292016-06-02 14:46:10 +01001376 Immediate(1 << Map::kIsUndetectable));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001377 __ j(not_zero, &return_unequal, Label::kNear);
1378
1379 __ CmpInstanceType(ebx, FIRST_JS_RECEIVER_TYPE);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001380 __ j(below, &runtime_call, Label::kNear);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001381 __ CmpInstanceType(ecx, FIRST_JS_RECEIVER_TYPE);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001382 __ j(below, &runtime_call, Label::kNear);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001383
1384 __ bind(&return_unequal);
1385 // Return non-equal by returning the non-zero object pointer in eax.
1386 __ ret(0); // eax, edx were pushed
1387
1388 __ bind(&undetectable);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001389 __ test_b(FieldOperand(ecx, Map::kBitFieldOffset),
Ben Murdochda12d292016-06-02 14:46:10 +01001390 Immediate(1 << Map::kIsUndetectable));
Ben Murdoch257744e2011-11-30 15:57:28 +00001391 __ j(zero, &return_unequal, Label::kNear);
Ben Murdochda12d292016-06-02 14:46:10 +01001392
1393 // If both sides are JSReceivers, then the result is false according to
1394 // the HTML specification, which says that only comparisons with null or
1395 // undefined are affected by special casing for document.all.
1396 __ CmpInstanceType(ebx, ODDBALL_TYPE);
1397 __ j(zero, &return_equal, Label::kNear);
1398 __ CmpInstanceType(ecx, ODDBALL_TYPE);
1399 __ j(not_zero, &return_unequal, Label::kNear);
1400
1401 __ bind(&return_equal);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001402 __ Move(eax, Immediate(EQUAL));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001403 __ ret(0); // eax, edx were pushed
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001404 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001405 __ bind(&runtime_call);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001406
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001407 if (cc == equal) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001408 {
1409 FrameScope scope(masm, StackFrame::INTERNAL);
1410 __ Push(edx);
1411 __ Push(eax);
1412 __ CallRuntime(strict() ? Runtime::kStrictEqual : Runtime::kEqual);
1413 }
1414 // Turn true into 0 and false into some non-zero value.
1415 STATIC_ASSERT(EQUAL == 0);
1416 __ sub(eax, Immediate(isolate()->factory()->true_value()));
1417 __ Ret();
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001418 } else {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001419 // Push arguments below the return address.
1420 __ pop(ecx);
1421 __ push(edx);
1422 __ push(eax);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001423 __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc))));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001424 __ push(ecx);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001425 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
1426 // tagged as a small integer.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001427 __ TailCallRuntime(Runtime::kCompare);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001428 }
1429
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001430 __ bind(&miss);
1431 GenerateMiss(masm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001432}
1433
1434
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001435static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
1436 // eax : number of arguments to the construct function
1437 // ebx : feedback vector
1438 // edx : slot in feedback vector (Smi)
1439 // edi : the function to call
1440
1441 {
1442 FrameScope scope(masm, StackFrame::INTERNAL);
1443
1444 // Number-of-arguments register must be smi-tagged to call out.
1445 __ SmiTag(eax);
1446 __ push(eax);
1447 __ push(edi);
1448 __ push(edx);
1449 __ push(ebx);
1450
1451 __ CallStub(stub);
1452
1453 __ pop(ebx);
1454 __ pop(edx);
1455 __ pop(edi);
1456 __ pop(eax);
1457 __ SmiUntag(eax);
1458 }
1459}
1460
1461
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001462static void GenerateRecordCallTarget(MacroAssembler* masm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001463 // Cache the called function in a feedback vector slot. Cache states
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001464 // are uninitialized, monomorphic (indicated by a JSFunction), and
1465 // megamorphic.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001466 // eax : number of arguments to the construct function
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001467 // ebx : feedback vector
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001468 // edx : slot in feedback vector (Smi)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001469 // edi : the function to call
1470 Isolate* isolate = masm->isolate();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001471 Label initialize, done, miss, megamorphic, not_array_function;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001472
1473 // Load the cache state into ecx.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001474 __ mov(ecx, FieldOperand(ebx, edx, times_half_pointer_size,
1475 FixedArray::kHeaderSize));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001476
1477 // A monomorphic cache hit or an already megamorphic state: invoke the
1478 // function without changing the state.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001479 // We don't know if ecx is a WeakCell or a Symbol, but it's harmless to read
1480 // at this position in a symbol (see static asserts in
1481 // type-feedback-vector.h).
1482 Label check_allocation_site;
1483 __ cmp(edi, FieldOperand(ecx, WeakCell::kValueOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001484 __ j(equal, &done, Label::kFar);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001485 __ CompareRoot(ecx, Heap::kmegamorphic_symbolRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001486 __ j(equal, &done, Label::kFar);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001487 __ CompareRoot(FieldOperand(ecx, HeapObject::kMapOffset),
1488 Heap::kWeakCellMapRootIndex);
1489 __ j(not_equal, &check_allocation_site);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001490
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001491 // If the weak cell is cleared, we have a new chance to become monomorphic.
1492 __ JumpIfSmi(FieldOperand(ecx, WeakCell::kValueOffset), &initialize);
1493 __ jmp(&megamorphic);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001494
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001495 __ bind(&check_allocation_site);
1496 // If we came here, we need to see if we are the array function.
1497 // If we didn't have a matching function, and we didn't find the megamorph
1498 // sentinel, then we have in the slot either some other function or an
1499 // AllocationSite.
1500 __ CompareRoot(FieldOperand(ecx, 0), Heap::kAllocationSiteMapRootIndex);
1501 __ j(not_equal, &miss);
1502
1503 // Make sure the function is the Array() function
1504 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx);
1505 __ cmp(edi, ecx);
1506 __ j(not_equal, &megamorphic);
1507 __ jmp(&done, Label::kFar);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001508
1509 __ bind(&miss);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001510
1511 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
1512 // megamorphic.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001513 __ CompareRoot(ecx, Heap::kuninitialized_symbolRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001514 __ j(equal, &initialize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001515 // MegamorphicSentinel is an immortal immovable object (undefined) so no
1516 // write-barrier is needed.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001517 __ bind(&megamorphic);
1518 __ mov(
1519 FieldOperand(ebx, edx, times_half_pointer_size, FixedArray::kHeaderSize),
1520 Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate)));
1521 __ jmp(&done, Label::kFar);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001522
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001523 // An uninitialized cache is patched with the function or sentinel to
1524 // indicate the ElementsKind if function is the Array constructor.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001525 __ bind(&initialize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001526 // Make sure the function is the Array() function
1527 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx);
1528 __ cmp(edi, ecx);
1529 __ j(not_equal, &not_array_function);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001530
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001531 // The target function is the Array constructor,
1532 // Create an AllocationSite if we don't already have it, store it in the
1533 // slot.
1534 CreateAllocationSiteStub create_stub(isolate);
1535 CallStubInRecordCallTarget(masm, &create_stub);
1536 __ jmp(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001537
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001538 __ bind(&not_array_function);
1539 CreateWeakCellStub weak_cell_stub(isolate);
1540 CallStubInRecordCallTarget(masm, &weak_cell_stub);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001541 __ bind(&done);
1542}
1543
1544
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001545void CallConstructStub::Generate(MacroAssembler* masm) {
1546 // eax : number of arguments
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001547 // ebx : feedback vector
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001548 // edx : slot in feedback vector (Smi, for RecordCallTarget)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001549 // edi : constructor function
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001550
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001551 Label non_function;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001552 // Check that function is not a smi.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001553 __ JumpIfSmi(edi, &non_function);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001554 // Check that function is a JSFunction.
1555 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001556 __ j(not_equal, &non_function);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001557
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001558 GenerateRecordCallTarget(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001559
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001560 Label feedback_register_initialized;
1561 // Put the AllocationSite from the feedback vector into ebx, or undefined.
1562 __ mov(ebx, FieldOperand(ebx, edx, times_half_pointer_size,
1563 FixedArray::kHeaderSize));
1564 Handle<Map> allocation_site_map = isolate()->factory()->allocation_site_map();
1565 __ cmp(FieldOperand(ebx, 0), Immediate(allocation_site_map));
1566 __ j(equal, &feedback_register_initialized);
1567 __ mov(ebx, isolate()->factory()->undefined_value());
1568 __ bind(&feedback_register_initialized);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001569
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001570 __ AssertUndefinedOrAllocationSite(ebx);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001571
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001572 // Pass new target to construct stub.
1573 __ mov(edx, edi);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001574
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001575 // Tail call to the function-specific construct stub (still in the caller
1576 // context at this point).
1577 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
1578 __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kConstructStubOffset));
1579 __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize));
1580 __ jmp(ecx);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001581
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001582 __ bind(&non_function);
1583 __ mov(edx, edi);
1584 __ Jump(isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001585}
1586
1587
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001588void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001589 // edi - function
1590 // edx - slot id
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001591 // ebx - vector
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001592 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx);
1593 __ cmp(edi, ecx);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001594 __ j(not_equal, miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001595
1596 __ mov(eax, arg_count());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001597 // Reload ecx.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001598 __ mov(ecx, FieldOperand(ebx, edx, times_half_pointer_size,
1599 FixedArray::kHeaderSize));
1600
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001601 // Increment the call count for monomorphic function calls.
1602 __ add(FieldOperand(ebx, edx, times_half_pointer_size,
1603 FixedArray::kHeaderSize + kPointerSize),
1604 Immediate(Smi::FromInt(CallICNexus::kCallCountIncrement)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001605
1606 __ mov(ebx, ecx);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001607 __ mov(edx, edi);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001608 ArrayConstructorStub stub(masm->isolate(), arg_count());
1609 __ TailCallStub(&stub);
1610
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001611 // Unreachable.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001612}
1613
1614
1615void CallICStub::Generate(MacroAssembler* masm) {
1616 // edi - function
1617 // edx - slot id
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001618 // ebx - vector
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001619 Isolate* isolate = masm->isolate();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001620 Label extra_checks_or_miss, call, call_function;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001621 int argc = arg_count();
1622 ParameterCount actual(argc);
1623
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001624 // The checks. First, does edi match the recorded monomorphic target?
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001625 __ mov(ecx, FieldOperand(ebx, edx, times_half_pointer_size,
1626 FixedArray::kHeaderSize));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001627
1628 // We don't know that we have a weak cell. We might have a private symbol
1629 // or an AllocationSite, but the memory is safe to examine.
1630 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
1631 // FixedArray.
1632 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
1633 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
1634 // computed, meaning that it can't appear to be a pointer. If the low bit is
1635 // 0, then hash is computed, but the 0 bit prevents the field from appearing
1636 // to be a pointer.
1637 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
1638 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
1639 WeakCell::kValueOffset &&
1640 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
1641
1642 __ cmp(edi, FieldOperand(ecx, WeakCell::kValueOffset));
1643 __ j(not_equal, &extra_checks_or_miss);
1644
1645 // The compare above could have been a SMI/SMI comparison. Guard against this
1646 // convincing us that we have a monomorphic JSFunction.
1647 __ JumpIfSmi(edi, &extra_checks_or_miss);
1648
1649 // Increment the call count for monomorphic function calls.
1650 __ add(FieldOperand(ebx, edx, times_half_pointer_size,
1651 FixedArray::kHeaderSize + kPointerSize),
1652 Immediate(Smi::FromInt(CallICNexus::kCallCountIncrement)));
1653
1654 __ bind(&call_function);
1655 __ Set(eax, argc);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001656 __ Jump(masm->isolate()->builtins()->CallFunction(convert_mode(),
1657 tail_call_mode()),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001658 RelocInfo::CODE_TARGET);
1659
1660 __ bind(&extra_checks_or_miss);
1661 Label uninitialized, miss, not_allocation_site;
1662
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001663 __ cmp(ecx, Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate)));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001664 __ j(equal, &call);
1665
1666 // Check if we have an allocation site.
1667 __ CompareRoot(FieldOperand(ecx, HeapObject::kMapOffset),
1668 Heap::kAllocationSiteMapRootIndex);
1669 __ j(not_equal, &not_allocation_site);
1670
1671 // We have an allocation site.
1672 HandleArrayCase(masm, &miss);
1673
1674 __ bind(&not_allocation_site);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001675
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001676 // The following cases attempt to handle MISS cases without going to the
1677 // runtime.
1678 if (FLAG_trace_ic) {
1679 __ jmp(&miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001680 }
1681
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001682 __ cmp(ecx, Immediate(TypeFeedbackVector::UninitializedSentinel(isolate)));
1683 __ j(equal, &uninitialized);
1684
1685 // We are going megamorphic. If the feedback is a JSFunction, it is fine
1686 // to handle it here. More complex cases are dealt with in the runtime.
1687 __ AssertNotSmi(ecx);
1688 __ CmpObjectType(ecx, JS_FUNCTION_TYPE, ecx);
1689 __ j(not_equal, &miss);
1690 __ mov(
1691 FieldOperand(ebx, edx, times_half_pointer_size, FixedArray::kHeaderSize),
1692 Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate)));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001693
1694 __ bind(&call);
1695 __ Set(eax, argc);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001696 __ Jump(masm->isolate()->builtins()->Call(convert_mode(), tail_call_mode()),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001697 RelocInfo::CODE_TARGET);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001698
1699 __ bind(&uninitialized);
1700
1701 // We are going monomorphic, provided we actually have a JSFunction.
1702 __ JumpIfSmi(edi, &miss);
1703
1704 // Goto miss case if we do not have a function.
1705 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx);
1706 __ j(not_equal, &miss);
1707
1708 // Make sure the function is not the Array() function, which requires special
1709 // behavior on MISS.
1710 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx);
1711 __ cmp(edi, ecx);
1712 __ j(equal, &miss);
1713
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001714 // Make sure the function belongs to the same native context.
1715 __ mov(ecx, FieldOperand(edi, JSFunction::kContextOffset));
1716 __ mov(ecx, ContextOperand(ecx, Context::NATIVE_CONTEXT_INDEX));
1717 __ cmp(ecx, NativeContextOperand());
1718 __ j(not_equal, &miss);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001719
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001720 // Initialize the call counter.
1721 __ mov(FieldOperand(ebx, edx, times_half_pointer_size,
1722 FixedArray::kHeaderSize + kPointerSize),
1723 Immediate(Smi::FromInt(CallICNexus::kCallCountIncrement)));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001724
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001725 // Store the function. Use a stub since we need a frame for allocation.
1726 // ebx - vector
1727 // edx - slot
1728 // edi - function
1729 {
1730 FrameScope scope(masm, StackFrame::INTERNAL);
1731 CreateWeakCellStub create_stub(isolate);
1732 __ push(edi);
1733 __ CallStub(&create_stub);
1734 __ pop(edi);
1735 }
1736
1737 __ jmp(&call_function);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001738
1739 // We are here because tracing is on or we encountered a MISS case we can't
1740 // handle here.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001741 __ bind(&miss);
1742 GenerateMiss(masm);
1743
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001744 __ jmp(&call);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001745
1746 // Unreachable
1747 __ int3();
1748}
1749
1750
1751void CallICStub::GenerateMiss(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001752 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001753
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001754 // Push the function and feedback info.
1755 __ push(edi);
1756 __ push(ebx);
1757 __ push(edx);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001758
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001759 // Call the entry.
1760 __ CallRuntime(Runtime::kCallIC_Miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001761
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001762 // Move result to edi and exit the internal frame.
1763 __ mov(edi, eax);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001764}
1765
1766
Steve Block44f0eee2011-05-26 01:26:41 +01001767bool CEntryStub::NeedsImmovableCode() {
1768 return false;
1769}
1770
1771
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001772void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
1773 CEntryStub::GenerateAheadOfTime(isolate);
1774 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1775 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001776 // It is important that the store buffer overflow stubs are generated first.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001777 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1778 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001779 CreateWeakCellStub::GenerateAheadOfTime(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001780 BinaryOpICStub::GenerateAheadOfTime(isolate);
1781 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001782 StoreFastElementStub::GenerateAheadOfTime(isolate);
1783 TypeofStub::GenerateAheadOfTime(isolate);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001784}
1785
1786
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001787void CodeStub::GenerateFPStubs(Isolate* isolate) {
1788 // Generate if not already in cache.
1789 CEntryStub(isolate, 1, kSaveFPRegs).GetCode();
1790 isolate->set_fp_stubs_generated(true);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001791}
1792
1793
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001794void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1795 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1796 stub.GetCode();
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001797}
1798
1799
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001800void CEntryStub::Generate(MacroAssembler* masm) {
1801 // eax: number of arguments including receiver
1802 // ebx: pointer to C function (C callee-saved)
1803 // ebp: frame pointer (restored after C call)
1804 // esp: stack pointer (restored after C call)
1805 // esi: current context (C callee-saved)
1806 // edi: JS function of the caller (C callee-saved)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001807 //
1808 // If argv_in_register():
1809 // ecx: pointer to the first argument
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001810
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001811 ProfileEntryHookStub::MaybeCallEntryHook(masm);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001812
Ben Murdoch097c5b22016-05-18 11:27:45 +01001813 // Reserve space on the stack for the three arguments passed to the call. If
1814 // result size is greater than can be returned in registers, also reserve
1815 // space for the hidden argument for the result location, and space for the
1816 // result itself.
1817 int arg_stack_space = result_size() < 3 ? 3 : 4 + result_size();
1818
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001819 // Enter the exit frame that transitions from JavaScript to C++.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001820 if (argv_in_register()) {
1821 DCHECK(!save_doubles());
Ben Murdoch097c5b22016-05-18 11:27:45 +01001822 __ EnterApiExitFrame(arg_stack_space);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001823
1824 // Move argc and argv into the correct registers.
1825 __ mov(esi, ecx);
1826 __ mov(edi, eax);
1827 } else {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001828 __ EnterExitFrame(arg_stack_space, save_doubles());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001829 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001830
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001831 // ebx: pointer to C function (C callee-saved)
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001832 // ebp: frame pointer (restored after C call)
1833 // esp: stack pointer (restored after C call)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001834 // edi: number of arguments including receiver (C callee-saved)
1835 // esi: pointer to the first argument (C callee-saved)
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001836
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001837 // Result returned in eax, or eax+edx if result size is 2.
1838
1839 // Check stack alignment.
1840 if (FLAG_debug_code) {
1841 __ CheckStackAlignment();
1842 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001843 // Call C function.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001844 if (result_size() <= 2) {
1845 __ mov(Operand(esp, 0 * kPointerSize), edi); // argc.
1846 __ mov(Operand(esp, 1 * kPointerSize), esi); // argv.
1847 __ mov(Operand(esp, 2 * kPointerSize),
1848 Immediate(ExternalReference::isolate_address(isolate())));
1849 } else {
1850 DCHECK_EQ(3, result_size());
1851 // Pass a pointer to the result location as the first argument.
1852 __ lea(eax, Operand(esp, 4 * kPointerSize));
1853 __ mov(Operand(esp, 0 * kPointerSize), eax);
1854 __ mov(Operand(esp, 1 * kPointerSize), edi); // argc.
1855 __ mov(Operand(esp, 2 * kPointerSize), esi); // argv.
1856 __ mov(Operand(esp, 3 * kPointerSize),
1857 Immediate(ExternalReference::isolate_address(isolate())));
1858 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001859 __ call(ebx);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001860
1861 if (result_size() > 2) {
1862 DCHECK_EQ(3, result_size());
1863#ifndef _WIN32
1864 // Restore the "hidden" argument on the stack which was popped by caller.
1865 __ sub(esp, Immediate(kPointerSize));
1866#endif
1867 // Read result values stored on stack. Result is stored above the arguments.
1868 __ mov(kReturnRegister0, Operand(esp, 4 * kPointerSize));
1869 __ mov(kReturnRegister1, Operand(esp, 5 * kPointerSize));
1870 __ mov(kReturnRegister2, Operand(esp, 6 * kPointerSize));
1871 }
1872 // Result is in eax, edx:eax or edi:edx:eax - do not destroy these registers!
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001873
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001874 // Check result for exception sentinel.
1875 Label exception_returned;
1876 __ cmp(eax, isolate()->factory()->exception());
1877 __ j(equal, &exception_returned);
1878
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001879 // Check that there is no pending exception, otherwise we
1880 // should have returned the exception sentinel.
1881 if (FLAG_debug_code) {
1882 __ push(edx);
1883 __ mov(edx, Immediate(isolate()->factory()->the_hole_value()));
1884 Label okay;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001885 ExternalReference pending_exception_address(
1886 Isolate::kPendingExceptionAddress, isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001887 __ cmp(edx, Operand::StaticVariable(pending_exception_address));
1888 // Cannot use check here as it attempts to generate call into runtime.
1889 __ j(equal, &okay, Label::kNear);
1890 __ int3();
1891 __ bind(&okay);
1892 __ pop(edx);
1893 }
1894
1895 // Exit the JavaScript to C++ exit frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001896 __ LeaveExitFrame(save_doubles(), !argv_in_register());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001897 __ ret(0);
1898
1899 // Handling of exception.
1900 __ bind(&exception_returned);
1901
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001902 ExternalReference pending_handler_context_address(
1903 Isolate::kPendingHandlerContextAddress, isolate());
1904 ExternalReference pending_handler_code_address(
1905 Isolate::kPendingHandlerCodeAddress, isolate());
1906 ExternalReference pending_handler_offset_address(
1907 Isolate::kPendingHandlerOffsetAddress, isolate());
1908 ExternalReference pending_handler_fp_address(
1909 Isolate::kPendingHandlerFPAddress, isolate());
1910 ExternalReference pending_handler_sp_address(
1911 Isolate::kPendingHandlerSPAddress, isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001912
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001913 // Ask the runtime for help to determine the handler. This will set eax to
1914 // contain the current pending exception, don't clobber it.
1915 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1916 isolate());
1917 {
1918 FrameScope scope(masm, StackFrame::MANUAL);
1919 __ PrepareCallCFunction(3, eax);
1920 __ mov(Operand(esp, 0 * kPointerSize), Immediate(0)); // argc.
1921 __ mov(Operand(esp, 1 * kPointerSize), Immediate(0)); // argv.
1922 __ mov(Operand(esp, 2 * kPointerSize),
1923 Immediate(ExternalReference::isolate_address(isolate())));
1924 __ CallCFunction(find_handler, 3);
1925 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001926
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001927 // Retrieve the handler context, SP and FP.
1928 __ mov(esi, Operand::StaticVariable(pending_handler_context_address));
1929 __ mov(esp, Operand::StaticVariable(pending_handler_sp_address));
1930 __ mov(ebp, Operand::StaticVariable(pending_handler_fp_address));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001931
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001932 // If the handler is a JS frame, restore the context to the frame. Note that
1933 // the context will be set to (esi == 0) for non-JS frames.
1934 Label skip;
1935 __ test(esi, esi);
1936 __ j(zero, &skip, Label::kNear);
1937 __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi);
1938 __ bind(&skip);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001939
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001940 // Compute the handler entry address and jump to it.
1941 __ mov(edi, Operand::StaticVariable(pending_handler_code_address));
1942 __ mov(edx, Operand::StaticVariable(pending_handler_offset_address));
1943 __ lea(edi, FieldOperand(edi, edx, times_1, Code::kHeaderSize));
1944 __ jmp(edi);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001945}
1946
1947
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001948void JSEntryStub::Generate(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001949 Label invoke, handler_entry, exit;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001950 Label not_outermost_js, not_outermost_js_2;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001951
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001952 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1953
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001954 // Set up frame.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001955 __ push(ebp);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001956 __ mov(ebp, esp);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001957
1958 // Push marker in two places.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001959 int marker = type();
Ben Murdochda12d292016-06-02 14:46:10 +01001960 __ push(Immediate(Smi::FromInt(marker))); // marker
1961 ExternalReference context_address(Isolate::kContextAddress, isolate());
1962 __ push(Operand::StaticVariable(context_address)); // context
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001963 // Save callee-saved registers (C calling conventions).
1964 __ push(edi);
1965 __ push(esi);
1966 __ push(ebx);
1967
1968 // Save copies of the top frame descriptor on the stack.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001969 ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001970 __ push(Operand::StaticVariable(c_entry_fp));
1971
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001972 // If this is the outermost JS call, set js_entry_sp value.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001973 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001974 __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001975 __ j(not_equal, &not_outermost_js, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001976 __ mov(Operand::StaticVariable(js_entry_sp), ebp);
Steve Block053d10c2011-06-13 19:13:29 +01001977 __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001978 __ jmp(&invoke, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001979 __ bind(&not_outermost_js);
Steve Block053d10c2011-06-13 19:13:29 +01001980 __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001981
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001982 // Jump to a faked try block that does the invoke, with a faked catch
1983 // block that sets the pending exception.
1984 __ jmp(&invoke);
1985 __ bind(&handler_entry);
1986 handler_offset_ = handler_entry.pos();
1987 // Caught exception: Store result (exception) in the pending exception
1988 // field in the JSEnv and return a failure sentinel.
Ben Murdoch589d6972011-11-30 16:04:58 +00001989 ExternalReference pending_exception(Isolate::kPendingExceptionAddress,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001990 isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001991 __ mov(Operand::StaticVariable(pending_exception), eax);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001992 __ mov(eax, Immediate(isolate()->factory()->exception()));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001993 __ jmp(&exit);
1994
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001995 // Invoke: Link this frame into the handler chain.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001996 __ bind(&invoke);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001997 __ PushStackHandler();
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001998
1999 // Clear any pending exceptions.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002000 __ mov(edx, Immediate(isolate()->factory()->the_hole_value()));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002001 __ mov(Operand::StaticVariable(pending_exception), edx);
2002
2003 // Fake a receiver (NULL).
2004 __ push(Immediate(0)); // receiver
2005
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002006 // Invoke the function by calling through JS entry trampoline builtin and
2007 // pop the faked function when we return. Notice that we cannot store a
2008 // reference to the trampoline code directly in this stub, because the
2009 // builtin stubs may not have been generated yet.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002010 if (type() == StackFrame::ENTRY_CONSTRUCT) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002011 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002012 isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002013 __ mov(edx, Immediate(construct_entry));
2014 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002015 ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002016 __ mov(edx, Immediate(entry));
2017 }
2018 __ mov(edx, Operand(edx, 0)); // deref address
2019 __ lea(edx, FieldOperand(edx, Code::kHeaderSize));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002020 __ call(edx);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002021
2022 // Unlink this frame from the handler chain.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002023 __ PopStackHandler();
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002024
Steve Block053d10c2011-06-13 19:13:29 +01002025 __ bind(&exit);
Steve Block053d10c2011-06-13 19:13:29 +01002026 // Check if the current stack frame is marked as the outermost JS frame.
2027 __ pop(ebx);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002028 __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002029 __ j(not_equal, &not_outermost_js_2);
2030 __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0));
2031 __ bind(&not_outermost_js_2);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002032
2033 // Restore the top frame descriptor from the stack.
Steve Block44f0eee2011-05-26 01:26:41 +01002034 __ pop(Operand::StaticVariable(ExternalReference(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002035 Isolate::kCEntryFPAddress, isolate())));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002036
2037 // Restore callee-saved registers (C calling conventions).
2038 __ pop(ebx);
2039 __ pop(esi);
2040 __ pop(edi);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002041 __ add(esp, Immediate(2 * kPointerSize)); // remove markers
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002042
2043 // Restore frame pointer and return.
2044 __ pop(ebp);
2045 __ ret(0);
2046}
2047
2048
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002049// -------------------------------------------------------------------------
2050// StringCharCodeAtGenerator
2051
2052void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002053 // If the receiver is a smi trigger the non-string case.
2054 STATIC_ASSERT(kSmiTag == 0);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002055 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2056 __ JumpIfSmi(object_, receiver_not_string_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002057
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002058 // Fetch the instance type of the receiver into result register.
2059 __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset));
2060 __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset));
2061 // If the receiver is not a string trigger the non-string case.
2062 __ test(result_, Immediate(kIsNotStringMask));
2063 __ j(not_zero, receiver_not_string_);
2064 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002065
2066 // If the index is non-smi trigger the non-smi case.
2067 STATIC_ASSERT(kSmiTag == 0);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002068 __ JumpIfNotSmi(index_, &index_not_smi_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002069 __ bind(&got_smi_index_);
2070
2071 // Check for index out of range.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002072 __ cmp(index_, FieldOperand(object_, String::kLengthOffset));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002073 __ j(above_equal, index_out_of_range_);
2074
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002075 __ SmiUntag(index_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002076
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002077 Factory* factory = masm->isolate()->factory();
2078 StringCharLoadGenerator::Generate(
2079 masm, factory, object_, index_, result_, &call_runtime_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002080
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002081 __ SmiTag(result_);
2082 __ bind(&exit_);
2083}
2084
2085
2086void StringCharCodeAtGenerator::GenerateSlow(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002087 MacroAssembler* masm, EmbedMode embed_mode,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002088 const RuntimeCallHelper& call_helper) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002089 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002090
2091 // Index is not a smi.
2092 __ bind(&index_not_smi_);
2093 // If index is a heap number, try converting it to an integer.
Steve Block44f0eee2011-05-26 01:26:41 +01002094 __ CheckMap(index_,
2095 masm->isolate()->factory()->heap_number_map(),
2096 index_not_number_,
Ben Murdoch257744e2011-11-30 15:57:28 +00002097 DONT_DO_SMI_CHECK);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002098 call_helper.BeforeCall(masm);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002099 if (embed_mode == PART_OF_IC_HANDLER) {
2100 __ push(LoadWithVectorDescriptor::VectorRegister());
2101 __ push(LoadDescriptor::SlotRegister());
2102 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002103 __ push(object_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002104 __ push(index_); // Consumed by runtime conversion function.
2105 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002106 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002107 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002108 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002109 // NumberToSmi discards numbers that are not exact integers.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002110 __ CallRuntime(Runtime::kNumberToSmi);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002111 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002112 if (!index_.is(eax)) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002113 // Save the conversion result before the pop instructions below
2114 // have a chance to overwrite it.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002115 __ mov(index_, eax);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002116 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002117 __ pop(object_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002118 if (embed_mode == PART_OF_IC_HANDLER) {
2119 __ pop(LoadDescriptor::SlotRegister());
2120 __ pop(LoadWithVectorDescriptor::VectorRegister());
2121 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002122 // Reload the instance type.
2123 __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset));
2124 __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset));
2125 call_helper.AfterCall(masm);
2126 // If index is still not a smi, it must be out of range.
2127 STATIC_ASSERT(kSmiTag == 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002128 __ JumpIfNotSmi(index_, index_out_of_range_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002129 // Otherwise, return to the fast path.
2130 __ jmp(&got_smi_index_);
2131
2132 // Call runtime. We get here when the receiver is a string and the
2133 // index is a number, but the code of getting the actual character
2134 // is too complex (e.g., when the string needs to be flattened).
2135 __ bind(&call_runtime_);
2136 call_helper.BeforeCall(masm);
2137 __ push(object_);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002138 __ SmiTag(index_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002139 __ push(index_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002140 __ CallRuntime(Runtime::kStringCharCodeAtRT);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002141 if (!result_.is(eax)) {
2142 __ mov(result_, eax);
2143 }
2144 call_helper.AfterCall(masm);
2145 __ jmp(&exit_);
2146
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002147 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002148}
2149
2150
2151// -------------------------------------------------------------------------
2152// StringCharFromCodeGenerator
2153
2154void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
2155 // Fast case of Heap::LookupSingleCharacterStringFromCode.
2156 STATIC_ASSERT(kSmiTag == 0);
2157 STATIC_ASSERT(kSmiShiftSize == 0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002158 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
2159 __ test(code_, Immediate(kSmiTagMask |
2160 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
Ben Murdoch257744e2011-11-30 15:57:28 +00002161 __ j(not_zero, &slow_case_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002162
Steve Block44f0eee2011-05-26 01:26:41 +01002163 Factory* factory = masm->isolate()->factory();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002164 __ Move(result_, Immediate(factory->single_character_string_cache()));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002165 STATIC_ASSERT(kSmiTag == 0);
2166 STATIC_ASSERT(kSmiTagSize == 1);
2167 STATIC_ASSERT(kSmiShiftSize == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002168 // At this point code register contains smi tagged one byte char code.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002169 __ mov(result_, FieldOperand(result_,
2170 code_, times_half_pointer_size,
2171 FixedArray::kHeaderSize));
Steve Block44f0eee2011-05-26 01:26:41 +01002172 __ cmp(result_, factory->undefined_value());
Ben Murdoch257744e2011-11-30 15:57:28 +00002173 __ j(equal, &slow_case_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002174 __ bind(&exit_);
2175}
2176
2177
2178void StringCharFromCodeGenerator::GenerateSlow(
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002179 MacroAssembler* masm,
2180 const RuntimeCallHelper& call_helper) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002181 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002182
2183 __ bind(&slow_case_);
2184 call_helper.BeforeCall(masm);
2185 __ push(code_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002186 __ CallRuntime(Runtime::kStringCharFromCode);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002187 if (!result_.is(eax)) {
2188 __ mov(result_, eax);
2189 }
2190 call_helper.AfterCall(masm);
2191 __ jmp(&exit_);
2192
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002193 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002194}
2195
2196
2197void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
2198 Register dest,
2199 Register src,
2200 Register count,
2201 Register scratch,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002202 String::Encoding encoding) {
2203 DCHECK(!scratch.is(dest));
2204 DCHECK(!scratch.is(src));
2205 DCHECK(!scratch.is(count));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002206
2207 // Nothing to do for zero characters.
2208 Label done;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002209 __ test(count, count);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002210 __ j(zero, &done);
2211
2212 // Make count the number of bytes to copy.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002213 if (encoding == String::TWO_BYTE_ENCODING) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002214 __ shl(count, 1);
2215 }
2216
Ben Murdoch257744e2011-11-30 15:57:28 +00002217 Label loop;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002218 __ bind(&loop);
2219 __ mov_b(scratch, Operand(src, 0));
2220 __ mov_b(Operand(dest, 0), scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002221 __ inc(src);
2222 __ inc(dest);
2223 __ dec(count);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002224 __ j(not_zero, &loop);
2225
2226 __ bind(&done);
2227}
2228
2229
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002230void SubStringStub::Generate(MacroAssembler* masm) {
2231 Label runtime;
2232
2233 // Stack frame on entry.
2234 // esp[0]: return address
2235 // esp[4]: to
2236 // esp[8]: from
2237 // esp[12]: string
2238
2239 // Make sure first argument is a string.
2240 __ mov(eax, Operand(esp, 3 * kPointerSize));
2241 STATIC_ASSERT(kSmiTag == 0);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002242 __ JumpIfSmi(eax, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002243 Condition is_string = masm->IsObjectStringType(eax, ebx, ebx);
2244 __ j(NegateCondition(is_string), &runtime);
2245
2246 // eax: string
2247 // ebx: instance type
2248
2249 // Calculate length of sub string using the smi values.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002250 __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002251 __ JumpIfNotSmi(ecx, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002252 __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002253 __ JumpIfNotSmi(edx, &runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002254 __ sub(ecx, edx);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002255 __ cmp(ecx, FieldOperand(eax, String::kLengthOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002256 Label not_original_string;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002257 // Shorter than original string's length: an actual substring.
2258 __ j(below, &not_original_string, Label::kNear);
2259 // Longer than original string's length or negative: unsafe arguments.
2260 __ j(above, &runtime);
2261 // Return original string.
2262 Counters* counters = isolate()->counters();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002263 __ IncrementCounter(counters->sub_string_native(), 1);
2264 __ ret(3 * kPointerSize);
2265 __ bind(&not_original_string);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002266
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002267 Label single_char;
2268 __ cmp(ecx, Immediate(Smi::FromInt(1)));
2269 __ j(equal, &single_char);
2270
Ben Murdochc7cc0282012-03-05 14:35:55 +00002271 // eax: string
2272 // ebx: instance type
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002273 // ecx: sub string length (smi)
Ben Murdochc7cc0282012-03-05 14:35:55 +00002274 // edx: from index (smi)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002275 // Deal with different string types: update the index if necessary
2276 // and put the underlying string into edi.
2277 Label underlying_unpacked, sliced_string, seq_or_external_string;
2278 // If the string is not indirect, it can only be sequential or external.
2279 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
2280 STATIC_ASSERT(kIsIndirectStringMask != 0);
2281 __ test(ebx, Immediate(kIsIndirectStringMask));
2282 __ j(zero, &seq_or_external_string, Label::kNear);
Ben Murdochc7cc0282012-03-05 14:35:55 +00002283
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002284 Factory* factory = isolate()->factory();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002285 __ test(ebx, Immediate(kSlicedNotConsMask));
2286 __ j(not_zero, &sliced_string, Label::kNear);
2287 // Cons string. Check whether it is flat, then fetch first part.
2288 // Flat cons strings have an empty second part.
2289 __ cmp(FieldOperand(eax, ConsString::kSecondOffset),
2290 factory->empty_string());
2291 __ j(not_equal, &runtime);
2292 __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset));
2293 // Update instance type.
2294 __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002295 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002296 __ jmp(&underlying_unpacked, Label::kNear);
2297
2298 __ bind(&sliced_string);
2299 // Sliced string. Fetch parent and adjust start index by offset.
2300 __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset));
2301 __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset));
2302 // Update instance type.
2303 __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset));
2304 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
2305 __ jmp(&underlying_unpacked, Label::kNear);
2306
2307 __ bind(&seq_or_external_string);
2308 // Sequential or external string. Just move string to the expected register.
2309 __ mov(edi, eax);
2310
2311 __ bind(&underlying_unpacked);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002312
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002313 if (FLAG_string_slices) {
2314 Label copy_routine;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002315 // edi: underlying subject string
2316 // ebx: instance type of underlying subject string
2317 // edx: adjusted start index (smi)
2318 // ecx: length (smi)
2319 __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength)));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002320 // Short slice. Copy instead of slicing.
2321 __ j(less, &copy_routine);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002322 // Allocate new sliced string. At this point we do not reload the instance
2323 // type including the string encoding because we simply rely on the info
2324 // provided by the original string. It does not matter if the original
2325 // string's encoding is wrong because we always have to recheck encoding of
2326 // the newly created string's parent anyways due to externalized strings.
2327 Label two_byte_slice, set_slice_header;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002328 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
Ben Murdoch589d6972011-11-30 16:04:58 +00002329 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
2330 __ test(ebx, Immediate(kStringEncodingMask));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002331 __ j(zero, &two_byte_slice, Label::kNear);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002332 __ AllocateOneByteSlicedString(eax, ebx, no_reg, &runtime);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002333 __ jmp(&set_slice_header, Label::kNear);
2334 __ bind(&two_byte_slice);
Ben Murdoch589d6972011-11-30 16:04:58 +00002335 __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002336 __ bind(&set_slice_header);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002337 __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002338 __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset),
2339 Immediate(String::kEmptyHashField));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002340 __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi);
2341 __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx);
2342 __ IncrementCounter(counters->sub_string_native(), 1);
2343 __ ret(3 * kPointerSize);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002344
2345 __ bind(&copy_routine);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002346 }
2347
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002348 // edi: underlying subject string
2349 // ebx: instance type of underlying subject string
2350 // edx: adjusted start index (smi)
2351 // ecx: length (smi)
2352 // The subject string can only be external or sequential string of either
2353 // encoding at this point.
2354 Label two_byte_sequential, runtime_drop_two, sequential_string;
2355 STATIC_ASSERT(kExternalStringTag != 0);
2356 STATIC_ASSERT(kSeqStringTag == 0);
Ben Murdochda12d292016-06-02 14:46:10 +01002357 __ test_b(ebx, Immediate(kExternalStringTag));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002358 __ j(zero, &sequential_string);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002359
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002360 // Handle external string.
2361 // Rule out short external strings.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002362 STATIC_ASSERT(kShortExternalStringTag != 0);
Ben Murdochda12d292016-06-02 14:46:10 +01002363 __ test_b(ebx, Immediate(kShortExternalStringMask));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002364 __ j(not_zero, &runtime);
2365 __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset));
2366 // Move the pointer so that offset-wise, it looks like a sequential string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002367 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002368 __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2369
2370 __ bind(&sequential_string);
2371 // Stash away (adjusted) index and (underlying) string.
2372 __ push(edx);
2373 __ push(edi);
2374 __ SmiUntag(ecx);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002375 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
Ben Murdochda12d292016-06-02 14:46:10 +01002376 __ test_b(ebx, Immediate(kStringEncodingMask));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002377 __ j(zero, &two_byte_sequential);
2378
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002379 // Sequential one byte string. Allocate the result.
2380 __ AllocateOneByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002381
2382 // eax: result string
2383 // ecx: result string length
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002384 // Locate first character of result.
2385 __ mov(edi, eax);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002386 __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002387 // Load string argument and locate character of sub string start.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002388 __ pop(edx);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002389 __ pop(ebx);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002390 __ SmiUntag(ebx);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002391 __ lea(edx, FieldOperand(edx, ebx, times_1, SeqOneByteString::kHeaderSize));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002392
2393 // eax: result string
2394 // ecx: result length
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002395 // edi: first character of result
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002396 // edx: character of sub string start
2397 StringHelper::GenerateCopyCharacters(
2398 masm, edi, edx, ecx, ebx, String::ONE_BYTE_ENCODING);
Steve Block44f0eee2011-05-26 01:26:41 +01002399 __ IncrementCounter(counters->sub_string_native(), 1);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002400 __ ret(3 * kPointerSize);
2401
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002402 __ bind(&two_byte_sequential);
2403 // Sequential two-byte string. Allocate the result.
2404 __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002405
2406 // eax: result string
2407 // ecx: result string length
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002408 // Locate first character of result.
2409 __ mov(edi, eax);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002410 __ add(edi,
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002411 Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2412 // Load string argument and locate character of sub string start.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002413 __ pop(edx);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002414 __ pop(ebx);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002415 // As from is a smi it is 2 times the value which matches the size of a two
2416 // byte character.
2417 STATIC_ASSERT(kSmiTag == 0);
2418 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002419 __ lea(edx, FieldOperand(edx, ebx, times_1, SeqTwoByteString::kHeaderSize));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002420
2421 // eax: result string
2422 // ecx: result length
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002423 // edi: first character of result
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002424 // edx: character of sub string start
2425 StringHelper::GenerateCopyCharacters(
2426 masm, edi, edx, ecx, ebx, String::TWO_BYTE_ENCODING);
Steve Block44f0eee2011-05-26 01:26:41 +01002427 __ IncrementCounter(counters->sub_string_native(), 1);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002428 __ ret(3 * kPointerSize);
2429
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002430 // Drop pushed values on the stack before tail call.
2431 __ bind(&runtime_drop_two);
2432 __ Drop(2);
2433
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002434 // Just jump to runtime to create the sub string.
2435 __ bind(&runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002436 __ TailCallRuntime(Runtime::kSubString);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002437
2438 __ bind(&single_char);
2439 // eax: string
2440 // ebx: instance type
2441 // ecx: sub string length (smi)
2442 // edx: from index (smi)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002443 StringCharAtGenerator generator(eax, edx, ecx, eax, &runtime, &runtime,
2444 &runtime, STRING_INDEX_IS_NUMBER,
2445 RECEIVER_IS_STRING);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002446 generator.GenerateFast(masm);
2447 __ ret(3 * kPointerSize);
2448 generator.SkipSlow(masm, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002449}
2450
2451
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002452void ToNumberStub::Generate(MacroAssembler* masm) {
2453 // The ToNumber stub takes one argument in eax.
2454 Label not_smi;
2455 __ JumpIfNotSmi(eax, &not_smi, Label::kNear);
2456 __ Ret();
2457 __ bind(&not_smi);
2458
2459 Label not_heap_number;
2460 __ CompareMap(eax, masm->isolate()->factory()->heap_number_map());
2461 __ j(not_equal, &not_heap_number, Label::kNear);
2462 __ Ret();
2463 __ bind(&not_heap_number);
2464
Ben Murdochda12d292016-06-02 14:46:10 +01002465 NonNumberToNumberStub stub(masm->isolate());
2466 __ TailCallStub(&stub);
2467}
2468
2469void NonNumberToNumberStub::Generate(MacroAssembler* masm) {
2470 // The NonNumberToNumber stub takes one argument in eax.
2471 __ AssertNotNumber(eax);
2472
2473 Label not_string;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002474 __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edi);
2475 // eax: object
2476 // edi: object map
2477 __ j(above_equal, &not_string, Label::kNear);
Ben Murdochda12d292016-06-02 14:46:10 +01002478 StringToNumberStub stub(masm->isolate());
2479 __ TailCallStub(&stub);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002480 __ bind(&not_string);
2481
2482 Label not_oddball;
2483 __ CmpInstanceType(edi, ODDBALL_TYPE);
2484 __ j(not_equal, &not_oddball, Label::kNear);
2485 __ mov(eax, FieldOperand(eax, Oddball::kToNumberOffset));
2486 __ Ret();
2487 __ bind(&not_oddball);
2488
2489 __ pop(ecx); // Pop return address.
2490 __ push(eax); // Push argument.
2491 __ push(ecx); // Push return address.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002492 __ TailCallRuntime(Runtime::kToNumber);
2493}
2494
Ben Murdochda12d292016-06-02 14:46:10 +01002495void StringToNumberStub::Generate(MacroAssembler* masm) {
2496 // The StringToNumber stub takes one argument in eax.
2497 __ AssertString(eax);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002498
Ben Murdochda12d292016-06-02 14:46:10 +01002499 // Check if string has a cached array index.
2500 Label runtime;
2501 __ test(FieldOperand(eax, String::kHashFieldOffset),
2502 Immediate(String::kContainsCachedArrayIndexMask));
2503 __ j(not_zero, &runtime, Label::kNear);
2504 __ mov(eax, FieldOperand(eax, String::kHashFieldOffset));
2505 __ IndexFromHash(eax, eax);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002506 __ Ret();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002507
Ben Murdochda12d292016-06-02 14:46:10 +01002508 __ bind(&runtime);
2509 __ PopReturnAddressTo(ecx); // Pop return address.
2510 __ Push(eax); // Push argument.
2511 __ PushReturnAddressFrom(ecx); // Push return address.
2512 __ TailCallRuntime(Runtime::kStringToNumber);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002513}
2514
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002515void ToStringStub::Generate(MacroAssembler* masm) {
2516 // The ToString stub takes one argument in eax.
2517 Label is_number;
2518 __ JumpIfSmi(eax, &is_number, Label::kNear);
2519
2520 Label not_string;
2521 __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edi);
2522 // eax: receiver
2523 // edi: receiver map
2524 __ j(above_equal, &not_string, Label::kNear);
2525 __ Ret();
2526 __ bind(&not_string);
2527
2528 Label not_heap_number;
2529 __ CompareMap(eax, masm->isolate()->factory()->heap_number_map());
2530 __ j(not_equal, &not_heap_number, Label::kNear);
2531 __ bind(&is_number);
2532 NumberToStringStub stub(isolate());
2533 __ TailCallStub(&stub);
2534 __ bind(&not_heap_number);
2535
2536 Label not_oddball;
2537 __ CmpInstanceType(edi, ODDBALL_TYPE);
2538 __ j(not_equal, &not_oddball, Label::kNear);
2539 __ mov(eax, FieldOperand(eax, Oddball::kToStringOffset));
2540 __ Ret();
2541 __ bind(&not_oddball);
2542
2543 __ pop(ecx); // Pop return address.
2544 __ push(eax); // Push argument.
2545 __ push(ecx); // Push return address.
2546 __ TailCallRuntime(Runtime::kToString);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002547}
2548
2549
Ben Murdoch097c5b22016-05-18 11:27:45 +01002550void ToNameStub::Generate(MacroAssembler* masm) {
2551 // The ToName stub takes one argument in eax.
2552 Label is_number;
2553 __ JumpIfSmi(eax, &is_number, Label::kNear);
2554
2555 Label not_name;
2556 STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
2557 __ CmpObjectType(eax, LAST_NAME_TYPE, edi);
2558 // eax: receiver
2559 // edi: receiver map
2560 __ j(above, &not_name, Label::kNear);
2561 __ Ret();
2562 __ bind(&not_name);
2563
2564 Label not_heap_number;
2565 __ CompareMap(eax, masm->isolate()->factory()->heap_number_map());
2566 __ j(not_equal, &not_heap_number, Label::kNear);
2567 __ bind(&is_number);
2568 NumberToStringStub stub(isolate());
2569 __ TailCallStub(&stub);
2570 __ bind(&not_heap_number);
2571
2572 Label not_oddball;
2573 __ CmpInstanceType(edi, ODDBALL_TYPE);
2574 __ j(not_equal, &not_oddball, Label::kNear);
2575 __ mov(eax, FieldOperand(eax, Oddball::kToStringOffset));
2576 __ Ret();
2577 __ bind(&not_oddball);
2578
2579 __ pop(ecx); // Pop return address.
2580 __ push(eax); // Push argument.
2581 __ push(ecx); // Push return address.
2582 __ TailCallRuntime(Runtime::kToName);
2583}
2584
2585
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002586void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
2587 Register left,
2588 Register right,
2589 Register scratch1,
2590 Register scratch2) {
Ben Murdoch257744e2011-11-30 15:57:28 +00002591 Register length = scratch1;
2592
2593 // Compare lengths.
2594 Label strings_not_equal, check_zero_length;
2595 __ mov(length, FieldOperand(left, String::kLengthOffset));
2596 __ cmp(length, FieldOperand(right, String::kLengthOffset));
2597 __ j(equal, &check_zero_length, Label::kNear);
2598 __ bind(&strings_not_equal);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002599 __ Move(eax, Immediate(Smi::FromInt(NOT_EQUAL)));
Ben Murdoch257744e2011-11-30 15:57:28 +00002600 __ ret(0);
2601
2602 // Check if the length is zero.
2603 Label compare_chars;
2604 __ bind(&check_zero_length);
2605 STATIC_ASSERT(kSmiTag == 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002606 __ test(length, length);
Ben Murdoch257744e2011-11-30 15:57:28 +00002607 __ j(not_zero, &compare_chars, Label::kNear);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002608 __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
Ben Murdoch257744e2011-11-30 15:57:28 +00002609 __ ret(0);
2610
2611 // Compare characters.
2612 __ bind(&compare_chars);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002613 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2,
2614 &strings_not_equal, Label::kNear);
Ben Murdoch257744e2011-11-30 15:57:28 +00002615
2616 // Characters are equal.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002617 __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
Ben Murdoch257744e2011-11-30 15:57:28 +00002618 __ ret(0);
2619}
2620
2621
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002622void StringHelper::GenerateCompareFlatOneByteStrings(
2623 MacroAssembler* masm, Register left, Register right, Register scratch1,
2624 Register scratch2, Register scratch3) {
Steve Block44f0eee2011-05-26 01:26:41 +01002625 Counters* counters = masm->isolate()->counters();
2626 __ IncrementCounter(counters->string_compare_native(), 1);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002627
2628 // Find minimum length.
Ben Murdoch257744e2011-11-30 15:57:28 +00002629 Label left_shorter;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002630 __ mov(scratch1, FieldOperand(left, String::kLengthOffset));
2631 __ mov(scratch3, scratch1);
2632 __ sub(scratch3, FieldOperand(right, String::kLengthOffset));
2633
2634 Register length_delta = scratch3;
2635
Ben Murdoch257744e2011-11-30 15:57:28 +00002636 __ j(less_equal, &left_shorter, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002637 // Right string is shorter. Change scratch1 to be length of right string.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002638 __ sub(scratch1, length_delta);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002639 __ bind(&left_shorter);
2640
2641 Register min_length = scratch1;
2642
2643 // If either length is zero, just compare lengths.
Ben Murdoch257744e2011-11-30 15:57:28 +00002644 Label compare_lengths;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002645 __ test(min_length, min_length);
Ben Murdoch257744e2011-11-30 15:57:28 +00002646 __ j(zero, &compare_lengths, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002647
Ben Murdoch257744e2011-11-30 15:57:28 +00002648 // Compare characters.
2649 Label result_not_equal;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002650 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
2651 &result_not_equal, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002652
2653 // Compare lengths - strings up to min-length are equal.
2654 __ bind(&compare_lengths);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002655 __ test(length_delta, length_delta);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002656 Label length_not_equal;
2657 __ j(not_zero, &length_not_equal, Label::kNear);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002658
2659 // Result is EQUAL.
2660 STATIC_ASSERT(EQUAL == 0);
2661 STATIC_ASSERT(kSmiTag == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002662 __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002663 __ ret(0);
2664
Ben Murdoch257744e2011-11-30 15:57:28 +00002665 Label result_greater;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002666 Label result_less;
2667 __ bind(&length_not_equal);
Ben Murdoch257744e2011-11-30 15:57:28 +00002668 __ j(greater, &result_greater, Label::kNear);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002669 __ jmp(&result_less, Label::kNear);
2670 __ bind(&result_not_equal);
2671 __ j(above, &result_greater, Label::kNear);
2672 __ bind(&result_less);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002673
2674 // Result is LESS.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002675 __ Move(eax, Immediate(Smi::FromInt(LESS)));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002676 __ ret(0);
2677
2678 // Result is GREATER.
2679 __ bind(&result_greater);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002680 __ Move(eax, Immediate(Smi::FromInt(GREATER)));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002681 __ ret(0);
2682}
2683
2684
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002685void StringHelper::GenerateOneByteCharsCompareLoop(
2686 MacroAssembler* masm, Register left, Register right, Register length,
2687 Register scratch, Label* chars_not_equal,
Ben Murdoch257744e2011-11-30 15:57:28 +00002688 Label::Distance chars_not_equal_near) {
2689 // Change index to run from -length to -1 by adding length to string
2690 // start. This means that loop ends when index reaches zero, which
2691 // doesn't need an additional compare.
2692 __ SmiUntag(length);
2693 __ lea(left,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002694 FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize));
Ben Murdoch257744e2011-11-30 15:57:28 +00002695 __ lea(right,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002696 FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize));
Ben Murdoch257744e2011-11-30 15:57:28 +00002697 __ neg(length);
2698 Register index = length; // index = -length;
2699
2700 // Compare loop.
2701 Label loop;
2702 __ bind(&loop);
2703 __ mov_b(scratch, Operand(left, index, times_1, 0));
2704 __ cmpb(scratch, Operand(right, index, times_1, 0));
2705 __ j(not_equal, chars_not_equal, chars_not_equal_near);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002706 __ inc(index);
Ben Murdoch257744e2011-11-30 15:57:28 +00002707 __ j(not_zero, &loop);
2708}
2709
2710
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002711void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
2712 // ----------- S t a t e -------------
2713 // -- edx : left
2714 // -- eax : right
2715 // -- esp[0] : return address
2716 // -----------------------------------
2717
2718 // Load ecx with the allocation site. We stick an undefined dummy value here
2719 // and replace it with the real allocation site later when we instantiate this
2720 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
2721 __ mov(ecx, handle(isolate()->heap()->undefined_value()));
2722
2723 // Make sure that we actually patched the allocation site.
2724 if (FLAG_debug_code) {
2725 __ test(ecx, Immediate(kSmiTagMask));
2726 __ Assert(not_equal, kExpectedAllocationSite);
2727 __ cmp(FieldOperand(ecx, HeapObject::kMapOffset),
2728 isolate()->factory()->allocation_site_map());
2729 __ Assert(equal, kExpectedAllocationSite);
2730 }
2731
2732 // Tail call into the stub that handles binary operations with allocation
2733 // sites.
2734 BinaryOpWithAllocationSiteStub stub(isolate(), state());
2735 __ TailCallStub(&stub);
2736}
2737
2738
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002739void CompareICStub::GenerateBooleans(MacroAssembler* masm) {
2740 DCHECK_EQ(CompareICState::BOOLEAN, state());
2741 Label miss;
2742 Label::Distance const miss_distance =
2743 masm->emit_debug_code() ? Label::kFar : Label::kNear;
2744
2745 __ JumpIfSmi(edx, &miss, miss_distance);
2746 __ mov(ecx, FieldOperand(edx, HeapObject::kMapOffset));
2747 __ JumpIfSmi(eax, &miss, miss_distance);
2748 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
2749 __ JumpIfNotRoot(ecx, Heap::kBooleanMapRootIndex, &miss, miss_distance);
2750 __ JumpIfNotRoot(ebx, Heap::kBooleanMapRootIndex, &miss, miss_distance);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002751 if (!Token::IsEqualityOp(op())) {
2752 __ mov(eax, FieldOperand(eax, Oddball::kToNumberOffset));
2753 __ AssertSmi(eax);
2754 __ mov(edx, FieldOperand(edx, Oddball::kToNumberOffset));
2755 __ AssertSmi(edx);
2756 __ push(eax);
2757 __ mov(eax, edx);
2758 __ pop(edx);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002759 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01002760 __ sub(eax, edx);
2761 __ Ret();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002762
2763 __ bind(&miss);
2764 GenerateMiss(masm);
2765}
2766
2767
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002768void CompareICStub::GenerateSmis(MacroAssembler* masm) {
2769 DCHECK(state() == CompareICState::SMI);
Ben Murdoch257744e2011-11-30 15:57:28 +00002770 Label miss;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002771 __ mov(ecx, edx);
2772 __ or_(ecx, eax);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002773 __ JumpIfNotSmi(ecx, &miss, Label::kNear);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002774
2775 if (GetCondition() == equal) {
2776 // For equality we do not care about the sign of the result.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002777 __ sub(eax, edx);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002778 } else {
Ben Murdoch257744e2011-11-30 15:57:28 +00002779 Label done;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002780 __ sub(edx, eax);
Ben Murdoch257744e2011-11-30 15:57:28 +00002781 __ j(no_overflow, &done, Label::kNear);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002782 // Correct sign of result in case of overflow.
2783 __ not_(edx);
2784 __ bind(&done);
2785 __ mov(eax, edx);
2786 }
2787 __ ret(0);
2788
2789 __ bind(&miss);
2790 GenerateMiss(masm);
2791}
2792
2793
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002794void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
2795 DCHECK(state() == CompareICState::NUMBER);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002796
Ben Murdoch257744e2011-11-30 15:57:28 +00002797 Label generic_stub;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002798 Label unordered, maybe_undefined1, maybe_undefined2;
Ben Murdoch257744e2011-11-30 15:57:28 +00002799 Label miss;
Ben Murdochb0fe1622011-05-05 13:52:32 +01002800
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002801 if (left() == CompareICState::SMI) {
2802 __ JumpIfNotSmi(edx, &miss);
2803 }
2804 if (right() == CompareICState::SMI) {
2805 __ JumpIfNotSmi(eax, &miss);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002806 }
2807
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002808 // Load left and right operand.
2809 Label done, left, left_smi, right_smi;
2810 __ JumpIfSmi(eax, &right_smi, Label::kNear);
2811 __ cmp(FieldOperand(eax, HeapObject::kMapOffset),
2812 isolate()->factory()->heap_number_map());
2813 __ j(not_equal, &maybe_undefined1, Label::kNear);
2814 __ movsd(xmm1, FieldOperand(eax, HeapNumber::kValueOffset));
2815 __ jmp(&left, Label::kNear);
2816 __ bind(&right_smi);
2817 __ mov(ecx, eax); // Can't clobber eax because we can still jump away.
2818 __ SmiUntag(ecx);
2819 __ Cvtsi2sd(xmm1, ecx);
2820
2821 __ bind(&left);
2822 __ JumpIfSmi(edx, &left_smi, Label::kNear);
2823 __ cmp(FieldOperand(edx, HeapObject::kMapOffset),
2824 isolate()->factory()->heap_number_map());
2825 __ j(not_equal, &maybe_undefined2, Label::kNear);
2826 __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset));
2827 __ jmp(&done);
2828 __ bind(&left_smi);
2829 __ mov(ecx, edx); // Can't clobber edx because we can still jump away.
2830 __ SmiUntag(ecx);
2831 __ Cvtsi2sd(xmm0, ecx);
2832
2833 __ bind(&done);
2834 // Compare operands.
2835 __ ucomisd(xmm0, xmm1);
2836
2837 // Don't base result on EFLAGS when a NaN is involved.
2838 __ j(parity_even, &unordered, Label::kNear);
2839
2840 // Return a result of -1, 0, or 1, based on EFLAGS.
2841 // Performing mov, because xor would destroy the flag register.
2842 __ mov(eax, 0); // equal
2843 __ mov(ecx, Immediate(Smi::FromInt(1)));
2844 __ cmov(above, eax, ecx);
2845 __ mov(ecx, Immediate(Smi::FromInt(-1)));
2846 __ cmov(below, eax, ecx);
2847 __ ret(0);
2848
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002849 __ bind(&unordered);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002850 __ bind(&generic_stub);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002851 CompareICStub stub(isolate(), op(), CompareICState::GENERIC,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002852 CompareICState::GENERIC, CompareICState::GENERIC);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002853 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET);
2854
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002855 __ bind(&maybe_undefined1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002856 if (Token::IsOrderedRelationalCompareOp(op())) {
2857 __ cmp(eax, Immediate(isolate()->factory()->undefined_value()));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002858 __ j(not_equal, &miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002859 __ JumpIfSmi(edx, &unordered);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002860 __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx);
2861 __ j(not_equal, &maybe_undefined2, Label::kNear);
2862 __ jmp(&unordered);
2863 }
2864
2865 __ bind(&maybe_undefined2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002866 if (Token::IsOrderedRelationalCompareOp(op())) {
2867 __ cmp(edx, Immediate(isolate()->factory()->undefined_value()));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002868 __ j(equal, &unordered);
2869 }
2870
Ben Murdochb0fe1622011-05-05 13:52:32 +01002871 __ bind(&miss);
2872 GenerateMiss(masm);
2873}
2874
2875
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002876void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
2877 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
2878 DCHECK(GetCondition() == equal);
Ben Murdoch257744e2011-11-30 15:57:28 +00002879
2880 // Registers containing left and right operands respectively.
2881 Register left = edx;
2882 Register right = eax;
2883 Register tmp1 = ecx;
2884 Register tmp2 = ebx;
2885
2886 // Check that both operands are heap objects.
2887 Label miss;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002888 __ mov(tmp1, left);
Ben Murdoch257744e2011-11-30 15:57:28 +00002889 STATIC_ASSERT(kSmiTag == 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002890 __ and_(tmp1, right);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002891 __ JumpIfSmi(tmp1, &miss, Label::kNear);
Ben Murdoch257744e2011-11-30 15:57:28 +00002892
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002893 // Check that both operands are internalized strings.
Ben Murdoch257744e2011-11-30 15:57:28 +00002894 __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset));
2895 __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset));
2896 __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
2897 __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002898 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
2899 __ or_(tmp1, tmp2);
2900 __ test(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask));
2901 __ j(not_zero, &miss, Label::kNear);
Ben Murdoch257744e2011-11-30 15:57:28 +00002902
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002903 // Internalized strings are compared by identity.
Ben Murdoch257744e2011-11-30 15:57:28 +00002904 Label done;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002905 __ cmp(left, right);
Ben Murdoch257744e2011-11-30 15:57:28 +00002906 // Make sure eax is non-zero. At this point input operands are
2907 // guaranteed to be non-zero.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002908 DCHECK(right.is(eax));
Ben Murdoch257744e2011-11-30 15:57:28 +00002909 __ j(not_equal, &done, Label::kNear);
2910 STATIC_ASSERT(EQUAL == 0);
2911 STATIC_ASSERT(kSmiTag == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002912 __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
Ben Murdoch257744e2011-11-30 15:57:28 +00002913 __ bind(&done);
2914 __ ret(0);
2915
2916 __ bind(&miss);
2917 GenerateMiss(masm);
2918}
2919
2920
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002921void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
2922 DCHECK(state() == CompareICState::UNIQUE_NAME);
2923 DCHECK(GetCondition() == equal);
2924
2925 // Registers containing left and right operands respectively.
2926 Register left = edx;
2927 Register right = eax;
2928 Register tmp1 = ecx;
2929 Register tmp2 = ebx;
2930
2931 // Check that both operands are heap objects.
2932 Label miss;
2933 __ mov(tmp1, left);
2934 STATIC_ASSERT(kSmiTag == 0);
2935 __ and_(tmp1, right);
2936 __ JumpIfSmi(tmp1, &miss, Label::kNear);
2937
2938 // Check that both operands are unique names. This leaves the instance
2939 // types loaded in tmp1 and tmp2.
2940 __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset));
2941 __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset));
2942 __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
2943 __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
2944
2945 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss, Label::kNear);
2946 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss, Label::kNear);
2947
2948 // Unique names are compared by identity.
2949 Label done;
2950 __ cmp(left, right);
2951 // Make sure eax is non-zero. At this point input operands are
2952 // guaranteed to be non-zero.
2953 DCHECK(right.is(eax));
2954 __ j(not_equal, &done, Label::kNear);
2955 STATIC_ASSERT(EQUAL == 0);
2956 STATIC_ASSERT(kSmiTag == 0);
2957 __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
2958 __ bind(&done);
2959 __ ret(0);
2960
2961 __ bind(&miss);
2962 GenerateMiss(masm);
2963}
2964
2965
2966void CompareICStub::GenerateStrings(MacroAssembler* masm) {
2967 DCHECK(state() == CompareICState::STRING);
Ben Murdoch257744e2011-11-30 15:57:28 +00002968 Label miss;
2969
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002970 bool equality = Token::IsEqualityOp(op());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002971
Ben Murdoch257744e2011-11-30 15:57:28 +00002972 // Registers containing left and right operands respectively.
2973 Register left = edx;
2974 Register right = eax;
2975 Register tmp1 = ecx;
2976 Register tmp2 = ebx;
2977 Register tmp3 = edi;
2978
2979 // Check that both operands are heap objects.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002980 __ mov(tmp1, left);
Ben Murdoch257744e2011-11-30 15:57:28 +00002981 STATIC_ASSERT(kSmiTag == 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002982 __ and_(tmp1, right);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002983 __ JumpIfSmi(tmp1, &miss);
Ben Murdoch257744e2011-11-30 15:57:28 +00002984
2985 // Check that both operands are strings. This leaves the instance
2986 // types loaded in tmp1 and tmp2.
2987 __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset));
2988 __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset));
2989 __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
2990 __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
2991 __ mov(tmp3, tmp1);
2992 STATIC_ASSERT(kNotStringTag != 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002993 __ or_(tmp3, tmp2);
Ben Murdoch257744e2011-11-30 15:57:28 +00002994 __ test(tmp3, Immediate(kIsNotStringMask));
2995 __ j(not_zero, &miss);
2996
2997 // Fast check for identical strings.
2998 Label not_same;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002999 __ cmp(left, right);
Ben Murdoch257744e2011-11-30 15:57:28 +00003000 __ j(not_equal, &not_same, Label::kNear);
3001 STATIC_ASSERT(EQUAL == 0);
3002 STATIC_ASSERT(kSmiTag == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003003 __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
Ben Murdoch257744e2011-11-30 15:57:28 +00003004 __ ret(0);
3005
3006 // Handle not identical strings.
3007 __ bind(&not_same);
3008
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003009 // Check that both strings are internalized. If they are, we're done
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003010 // because we already know they are not identical. But in the case of
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003011 // non-equality compare, we still need to determine the order. We
3012 // also know they are both strings.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003013 if (equality) {
3014 Label do_compare;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003015 STATIC_ASSERT(kInternalizedTag == 0);
3016 __ or_(tmp1, tmp2);
3017 __ test(tmp1, Immediate(kIsNotInternalizedMask));
3018 __ j(not_zero, &do_compare, Label::kNear);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003019 // Make sure eax is non-zero. At this point input operands are
3020 // guaranteed to be non-zero.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003021 DCHECK(right.is(eax));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003022 __ ret(0);
3023 __ bind(&do_compare);
3024 }
Ben Murdoch257744e2011-11-30 15:57:28 +00003025
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003026 // Check that both strings are sequential one-byte.
Ben Murdoch257744e2011-11-30 15:57:28 +00003027 Label runtime;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003028 __ JumpIfNotBothSequentialOneByteStrings(left, right, tmp1, tmp2, &runtime);
Ben Murdoch257744e2011-11-30 15:57:28 +00003029
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003030 // Compare flat one byte strings. Returns when done.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003031 if (equality) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003032 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1,
3033 tmp2);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003034 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003035 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3036 tmp2, tmp3);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003037 }
Ben Murdoch257744e2011-11-30 15:57:28 +00003038
3039 // Handle more complex cases in runtime.
3040 __ bind(&runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003041 if (equality) {
Ben Murdochda12d292016-06-02 14:46:10 +01003042 {
3043 FrameScope scope(masm, StackFrame::INTERNAL);
3044 __ Push(left);
3045 __ Push(right);
3046 __ CallRuntime(Runtime::kStringEqual);
3047 }
3048 __ sub(eax, Immediate(masm->isolate()->factory()->true_value()));
3049 __ Ret();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003050 } else {
Ben Murdochda12d292016-06-02 14:46:10 +01003051 __ pop(tmp1); // Return address.
3052 __ push(left);
3053 __ push(right);
3054 __ push(tmp1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003055 __ TailCallRuntime(Runtime::kStringCompare);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003056 }
Ben Murdoch257744e2011-11-30 15:57:28 +00003057
3058 __ bind(&miss);
3059 GenerateMiss(masm);
3060}
3061
3062
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003063void CompareICStub::GenerateReceivers(MacroAssembler* masm) {
3064 DCHECK_EQ(CompareICState::RECEIVER, state());
Ben Murdoch257744e2011-11-30 15:57:28 +00003065 Label miss;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003066 __ mov(ecx, edx);
3067 __ and_(ecx, eax);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00003068 __ JumpIfSmi(ecx, &miss, Label::kNear);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003069
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003070 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
3071 __ CmpObjectType(eax, FIRST_JS_RECEIVER_TYPE, ecx);
3072 __ j(below, &miss, Label::kNear);
3073 __ CmpObjectType(edx, FIRST_JS_RECEIVER_TYPE, ecx);
3074 __ j(below, &miss, Label::kNear);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003075
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003076 DCHECK_EQ(equal, GetCondition());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003077 __ sub(eax, edx);
3078 __ ret(0);
3079
3080 __ bind(&miss);
3081 GenerateMiss(masm);
3082}
3083
3084
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003085void CompareICStub::GenerateKnownReceivers(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003086 Label miss;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003087 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003088 __ mov(ecx, edx);
3089 __ and_(ecx, eax);
3090 __ JumpIfSmi(ecx, &miss, Label::kNear);
3091
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003092 __ GetWeakValue(edi, cell);
3093 __ cmp(edi, FieldOperand(eax, HeapObject::kMapOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003094 __ j(not_equal, &miss, Label::kNear);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003095 __ cmp(edi, FieldOperand(edx, HeapObject::kMapOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003096 __ j(not_equal, &miss, Label::kNear);
3097
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003098 if (Token::IsEqualityOp(op())) {
3099 __ sub(eax, edx);
3100 __ ret(0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003101 } else {
3102 __ PopReturnAddressTo(ecx);
3103 __ Push(edx);
3104 __ Push(eax);
3105 __ Push(Immediate(Smi::FromInt(NegativeComparisonResult(GetCondition()))));
3106 __ PushReturnAddressFrom(ecx);
3107 __ TailCallRuntime(Runtime::kCompare);
3108 }
Ben Murdochc7cc0282012-03-05 14:35:55 +00003109
3110 __ bind(&miss);
3111 GenerateMiss(masm);
3112}
3113
3114
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003115void CompareICStub::GenerateMiss(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003116 {
3117 // Call the runtime system in a fresh internal frame.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003118 FrameScope scope(masm, StackFrame::INTERNAL);
3119 __ push(edx); // Preserve edx and eax.
3120 __ push(eax);
3121 __ push(edx); // And also use them as the arguments.
3122 __ push(eax);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003123 __ push(Immediate(Smi::FromInt(op())));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003124 __ CallRuntime(Runtime::kCompareIC_Miss);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003125 // Compute the entry point of the rewritten stub.
3126 __ lea(edi, FieldOperand(eax, Code::kHeaderSize));
3127 __ pop(eax);
3128 __ pop(edx);
3129 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01003130
Ben Murdochb0fe1622011-05-05 13:52:32 +01003131 // Do a tail call to the rewritten stub.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003132 __ jmp(edi);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003133}
3134
3135
Ben Murdoch257744e2011-11-30 15:57:28 +00003136// Helper function used to check that the dictionary doesn't contain
3137// the property. This function may return false negatives, so miss_label
3138// must always call a backup property check that is complete.
3139// This function is safe to call if the receiver has fast properties.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003140// Name must be a unique name and receiver must be a heap object.
3141void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3142 Label* miss,
3143 Label* done,
3144 Register properties,
3145 Handle<Name> name,
3146 Register r0) {
3147 DCHECK(name->IsUniqueName());
Ben Murdoch257744e2011-11-30 15:57:28 +00003148
3149 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3150 // not equal to the name and kProbes-th slot is not used (its name is the
3151 // undefined value), it guarantees the hash table doesn't contain the
3152 // property. It's true even if some slots represent deleted properties
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003153 // (their names are the hole value).
Ben Murdoch257744e2011-11-30 15:57:28 +00003154 for (int i = 0; i < kInlinedProbes; i++) {
3155 // Compute the masked index: (hash + i + i * i) & mask.
3156 Register index = r0;
3157 // Capacity is smi 2^n.
3158 __ mov(index, FieldOperand(properties, kCapacityOffset));
3159 __ dec(index);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003160 __ and_(index,
3161 Immediate(Smi::FromInt(name->Hash() +
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003162 NameDictionary::GetProbeOffset(i))));
Ben Murdoch257744e2011-11-30 15:57:28 +00003163
3164 // Scale the index by multiplying by the entry size.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003165 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Ben Murdoch257744e2011-11-30 15:57:28 +00003166 __ lea(index, Operand(index, index, times_2, 0)); // index *= 3.
3167 Register entity_name = r0;
3168 // Having undefined at this place means the name is not contained.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003169 STATIC_ASSERT(kSmiTagSize == 1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003170 __ mov(entity_name, Operand(properties, index, times_half_pointer_size,
3171 kElementsStartOffset - kHeapObjectTag));
3172 __ cmp(entity_name, masm->isolate()->factory()->undefined_value());
3173 __ j(equal, done);
3174
3175 // Stop if found the property.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003176 __ cmp(entity_name, Handle<Name>(name));
Ben Murdoch257744e2011-11-30 15:57:28 +00003177 __ j(equal, miss);
3178
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003179 Label good;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003180 // Check for the hole and skip.
3181 __ cmp(entity_name, masm->isolate()->factory()->the_hole_value());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003182 __ j(equal, &good, Label::kNear);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003183
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003184 // Check if the entry name is not a unique name.
Ben Murdoch257744e2011-11-30 15:57:28 +00003185 __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003186 __ JumpIfNotUniqueNameInstanceType(
3187 FieldOperand(entity_name, Map::kInstanceTypeOffset), miss);
3188 __ bind(&good);
Ben Murdoch257744e2011-11-30 15:57:28 +00003189 }
3190
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003191 NameDictionaryLookupStub stub(masm->isolate(), properties, r0, r0,
3192 NEGATIVE_LOOKUP);
Ben Murdoch257744e2011-11-30 15:57:28 +00003193 __ push(Immediate(Handle<Object>(name)));
3194 __ push(Immediate(name->Hash()));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003195 __ CallStub(&stub);
3196 __ test(r0, r0);
Ben Murdoch257744e2011-11-30 15:57:28 +00003197 __ j(not_zero, miss);
3198 __ jmp(done);
Ben Murdoch257744e2011-11-30 15:57:28 +00003199}
3200
3201
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003202// Probe the name dictionary in the |elements| register. Jump to the
Ben Murdoch257744e2011-11-30 15:57:28 +00003203// |done| label if a property with the given name is found leaving the
3204// index into the dictionary in |r0|. Jump to the |miss| label
3205// otherwise.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003206void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3207 Label* miss,
3208 Label* done,
3209 Register elements,
3210 Register name,
3211 Register r0,
3212 Register r1) {
3213 DCHECK(!elements.is(r0));
3214 DCHECK(!elements.is(r1));
3215 DCHECK(!name.is(r0));
3216 DCHECK(!name.is(r1));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003217
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003218 __ AssertName(name);
Ben Murdoch257744e2011-11-30 15:57:28 +00003219
3220 __ mov(r1, FieldOperand(elements, kCapacityOffset));
3221 __ shr(r1, kSmiTagSize); // convert smi to int
3222 __ dec(r1);
3223
3224 // Generate an unrolled loop that performs a few probes before
3225 // giving up. Measurements done on Gmail indicate that 2 probes
3226 // cover ~93% of loads from dictionaries.
3227 for (int i = 0; i < kInlinedProbes; i++) {
3228 // Compute the masked index: (hash + i + i * i) & mask.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003229 __ mov(r0, FieldOperand(name, Name::kHashFieldOffset));
3230 __ shr(r0, Name::kHashShift);
Ben Murdoch257744e2011-11-30 15:57:28 +00003231 if (i > 0) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003232 __ add(r0, Immediate(NameDictionary::GetProbeOffset(i)));
Ben Murdoch257744e2011-11-30 15:57:28 +00003233 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003234 __ and_(r0, r1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003235
3236 // Scale the index by multiplying by the entry size.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003237 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Ben Murdoch257744e2011-11-30 15:57:28 +00003238 __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3
3239
3240 // Check if the key is identical to the name.
3241 __ cmp(name, Operand(elements,
3242 r0,
3243 times_4,
3244 kElementsStartOffset - kHeapObjectTag));
3245 __ j(equal, done);
3246 }
3247
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003248 NameDictionaryLookupStub stub(masm->isolate(), elements, r1, r0,
3249 POSITIVE_LOOKUP);
Ben Murdoch257744e2011-11-30 15:57:28 +00003250 __ push(name);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003251 __ mov(r0, FieldOperand(name, Name::kHashFieldOffset));
3252 __ shr(r0, Name::kHashShift);
Ben Murdoch257744e2011-11-30 15:57:28 +00003253 __ push(r0);
3254 __ CallStub(&stub);
3255
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003256 __ test(r1, r1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003257 __ j(zero, miss);
3258 __ jmp(done);
3259}
3260
3261
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003262void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003263 // This stub overrides SometimesSetsUpAFrame() to return false. That means
3264 // we cannot call anything that could cause a GC from this stub.
Ben Murdoch257744e2011-11-30 15:57:28 +00003265 // Stack frame on entry:
3266 // esp[0 * kPointerSize]: return address.
3267 // esp[1 * kPointerSize]: key's hash.
3268 // esp[2 * kPointerSize]: key.
3269 // Registers:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003270 // dictionary_: NameDictionary to probe.
Ben Murdoch257744e2011-11-30 15:57:28 +00003271 // result_: used as scratch.
3272 // index_: will hold an index of entry if lookup is successful.
3273 // might alias with result_.
3274 // Returns:
3275 // result_ is zero if lookup failed, non zero otherwise.
3276
3277 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
3278
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003279 Register scratch = result();
Ben Murdoch257744e2011-11-30 15:57:28 +00003280
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003281 __ mov(scratch, FieldOperand(dictionary(), kCapacityOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003282 __ dec(scratch);
3283 __ SmiUntag(scratch);
3284 __ push(scratch);
3285
3286 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3287 // not equal to the name and kProbes-th slot is not used (its name is the
3288 // undefined value), it guarantees the hash table doesn't contain the
3289 // property. It's true even if some slots represent deleted properties
3290 // (their names are the null value).
3291 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
3292 // Compute the masked index: (hash + i + i * i) & mask.
3293 __ mov(scratch, Operand(esp, 2 * kPointerSize));
3294 if (i > 0) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003295 __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i)));
Ben Murdoch257744e2011-11-30 15:57:28 +00003296 }
3297 __ and_(scratch, Operand(esp, 0));
3298
3299 // Scale the index by multiplying by the entry size.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003300 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003301 __ lea(index(), Operand(scratch, scratch, times_2, 0)); // index *= 3.
Ben Murdoch257744e2011-11-30 15:57:28 +00003302
3303 // Having undefined at this place means the name is not contained.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003304 STATIC_ASSERT(kSmiTagSize == 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003305 __ mov(scratch, Operand(dictionary(), index(), times_pointer_size,
Ben Murdoch257744e2011-11-30 15:57:28 +00003306 kElementsStartOffset - kHeapObjectTag));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003307 __ cmp(scratch, isolate()->factory()->undefined_value());
Ben Murdoch257744e2011-11-30 15:57:28 +00003308 __ j(equal, &not_in_dictionary);
3309
3310 // Stop if found the property.
3311 __ cmp(scratch, Operand(esp, 3 * kPointerSize));
3312 __ j(equal, &in_dictionary);
3313
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003314 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
3315 // If we hit a key that is not a unique name during negative
3316 // lookup we have to bailout as this key might be equal to the
Ben Murdoch257744e2011-11-30 15:57:28 +00003317 // key we are looking for.
3318
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003319 // Check if the entry name is not a unique name.
Ben Murdoch257744e2011-11-30 15:57:28 +00003320 __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003321 __ JumpIfNotUniqueNameInstanceType(
3322 FieldOperand(scratch, Map::kInstanceTypeOffset),
3323 &maybe_in_dictionary);
Ben Murdoch257744e2011-11-30 15:57:28 +00003324 }
3325 }
3326
3327 __ bind(&maybe_in_dictionary);
3328 // If we are doing negative lookup then probing failure should be
3329 // treated as a lookup success. For positive lookup probing failure
3330 // should be treated as lookup failure.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003331 if (mode() == POSITIVE_LOOKUP) {
3332 __ mov(result(), Immediate(0));
Ben Murdoch257744e2011-11-30 15:57:28 +00003333 __ Drop(1);
3334 __ ret(2 * kPointerSize);
3335 }
3336
3337 __ bind(&in_dictionary);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003338 __ mov(result(), Immediate(1));
Ben Murdoch257744e2011-11-30 15:57:28 +00003339 __ Drop(1);
3340 __ ret(2 * kPointerSize);
3341
3342 __ bind(&not_in_dictionary);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003343 __ mov(result(), Immediate(0));
Ben Murdoch257744e2011-11-30 15:57:28 +00003344 __ Drop(1);
3345 __ ret(2 * kPointerSize);
3346}
3347
3348
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003349void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
3350 Isolate* isolate) {
3351 StoreBufferOverflowStub stub(isolate, kDontSaveFPRegs);
3352 stub.GetCode();
3353 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
3354 stub2.GetCode();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003355}
3356
3357
3358// Takes the input in 3 registers: address_ value_ and object_. A pointer to
3359// the value has just been written into the object, now this stub makes sure
3360// we keep the GC informed. The word in the object where the value has been
3361// written is in the address register.
3362void RecordWriteStub::Generate(MacroAssembler* masm) {
3363 Label skip_to_incremental_noncompacting;
3364 Label skip_to_incremental_compacting;
3365
3366 // The first two instructions are generated with labels so as to get the
3367 // offset fixed up correctly by the bind(Label*) call. We patch it back and
3368 // forth between a compare instructions (a nop in this position) and the
3369 // real branch when we start and stop incremental heap marking.
3370 __ jmp(&skip_to_incremental_noncompacting, Label::kNear);
3371 __ jmp(&skip_to_incremental_compacting, Label::kFar);
3372
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003373 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3374 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003375 MacroAssembler::kReturnAtEnd);
3376 } else {
3377 __ ret(0);
3378 }
3379
3380 __ bind(&skip_to_incremental_noncompacting);
3381 GenerateIncremental(masm, INCREMENTAL);
3382
3383 __ bind(&skip_to_incremental_compacting);
3384 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
3385
3386 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
3387 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
3388 masm->set_byte_at(0, kTwoByteNopInstruction);
3389 masm->set_byte_at(2, kFiveByteNopInstruction);
3390}
3391
3392
3393void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
3394 regs_.Save(masm);
3395
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003396 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003397 Label dont_need_remembered_set;
3398
3399 __ mov(regs_.scratch0(), Operand(regs_.address(), 0));
3400 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
3401 regs_.scratch0(),
3402 &dont_need_remembered_set);
3403
Ben Murdoch097c5b22016-05-18 11:27:45 +01003404 __ JumpIfInNewSpace(regs_.object(), regs_.scratch0(),
3405 &dont_need_remembered_set);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003406
3407 // First notify the incremental marker if necessary, then update the
3408 // remembered set.
3409 CheckNeedsToInformIncrementalMarker(
3410 masm,
3411 kUpdateRememberedSetOnNoNeedToInformIncrementalMarker,
3412 mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003413 InformIncrementalMarker(masm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003414 regs_.Restore(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003415 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003416 MacroAssembler::kReturnAtEnd);
3417
3418 __ bind(&dont_need_remembered_set);
3419 }
3420
3421 CheckNeedsToInformIncrementalMarker(
3422 masm,
3423 kReturnOnNoNeedToInformIncrementalMarker,
3424 mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003425 InformIncrementalMarker(masm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003426 regs_.Restore(masm);
3427 __ ret(0);
3428}
3429
3430
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003431void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
3432 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003433 int argument_count = 3;
3434 __ PrepareCallCFunction(argument_count, regs_.scratch0());
3435 __ mov(Operand(esp, 0 * kPointerSize), regs_.object());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003436 __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003437 __ mov(Operand(esp, 2 * kPointerSize),
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003438 Immediate(ExternalReference::isolate_address(isolate())));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003439
3440 AllowExternalCallThatCantCauseGC scope(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003441 __ CallCFunction(
3442 ExternalReference::incremental_marking_record_write_function(isolate()),
3443 argument_count);
3444
3445 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003446}
3447
3448
3449void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
3450 MacroAssembler* masm,
3451 OnNoNeedToInformIncrementalMarker on_no_need,
3452 Mode mode) {
3453 Label object_is_black, need_incremental, need_incremental_pop_object;
3454
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003455 __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask));
3456 __ and_(regs_.scratch0(), regs_.object());
3457 __ mov(regs_.scratch1(),
3458 Operand(regs_.scratch0(),
3459 MemoryChunk::kWriteBarrierCounterOffset));
3460 __ sub(regs_.scratch1(), Immediate(1));
3461 __ mov(Operand(regs_.scratch0(),
3462 MemoryChunk::kWriteBarrierCounterOffset),
3463 regs_.scratch1());
3464 __ j(negative, &need_incremental);
3465
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003466 // Let's look at the color of the object: If it is not black we don't have
3467 // to inform the incremental marker.
3468 __ JumpIfBlack(regs_.object(),
3469 regs_.scratch0(),
3470 regs_.scratch1(),
3471 &object_is_black,
3472 Label::kNear);
3473
3474 regs_.Restore(masm);
3475 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003476 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003477 MacroAssembler::kReturnAtEnd);
3478 } else {
3479 __ ret(0);
3480 }
3481
3482 __ bind(&object_is_black);
3483
3484 // Get the value from the slot.
3485 __ mov(regs_.scratch0(), Operand(regs_.address(), 0));
3486
3487 if (mode == INCREMENTAL_COMPACTION) {
3488 Label ensure_not_white;
3489
3490 __ CheckPageFlag(regs_.scratch0(), // Contains value.
3491 regs_.scratch1(), // Scratch.
3492 MemoryChunk::kEvacuationCandidateMask,
3493 zero,
3494 &ensure_not_white,
3495 Label::kNear);
3496
3497 __ CheckPageFlag(regs_.object(),
3498 regs_.scratch1(), // Scratch.
3499 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
3500 not_zero,
3501 &ensure_not_white,
3502 Label::kNear);
3503
3504 __ jmp(&need_incremental);
3505
3506 __ bind(&ensure_not_white);
3507 }
3508
3509 // We need an extra register for this, so we push the object register
3510 // temporarily.
3511 __ push(regs_.object());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003512 __ JumpIfWhite(regs_.scratch0(), // The value.
3513 regs_.scratch1(), // Scratch.
3514 regs_.object(), // Scratch.
3515 &need_incremental_pop_object, Label::kNear);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003516 __ pop(regs_.object());
3517
3518 regs_.Restore(masm);
3519 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003520 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003521 MacroAssembler::kReturnAtEnd);
3522 } else {
3523 __ ret(0);
3524 }
3525
3526 __ bind(&need_incremental_pop_object);
3527 __ pop(regs_.object());
3528
3529 __ bind(&need_incremental);
3530
3531 // Fall through when we need to inform the incremental marker.
3532}
3533
3534
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003535void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
3536 CEntryStub ces(isolate(), 1, kSaveFPRegs);
3537 __ call(ces.GetCode(), RelocInfo::CODE_TARGET);
3538 int parameter_count_offset =
Ben Murdochda12d292016-06-02 14:46:10 +01003539 StubFailureTrampolineFrameConstants::kArgumentsLengthOffset;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003540 __ mov(ebx, MemOperand(ebp, parameter_count_offset));
3541 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
3542 __ pop(ecx);
3543 int additional_offset =
3544 function_mode() == JS_FUNCTION_STUB_MODE ? kPointerSize : 0;
3545 __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset));
3546 __ jmp(ecx); // Return to IC Miss stub, continuation still on stack.
3547}
3548
3549
3550void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003551 __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister());
3552 LoadICStub stub(isolate(), state());
3553 stub.GenerateForTrampoline(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003554}
3555
3556
3557void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003558 __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister());
3559 KeyedLoadICStub stub(isolate(), state());
3560 stub.GenerateForTrampoline(masm);
3561}
3562
3563
3564static void HandleArrayCases(MacroAssembler* masm, Register receiver,
3565 Register key, Register vector, Register slot,
3566 Register feedback, bool is_polymorphic,
3567 Label* miss) {
3568 // feedback initially contains the feedback array
3569 Label next, next_loop, prepare_next;
3570 Label load_smi_map, compare_map;
3571 Label start_polymorphic;
3572
3573 __ push(receiver);
3574 __ push(vector);
3575
3576 Register receiver_map = receiver;
3577 Register cached_map = vector;
3578
3579 // Receiver might not be a heap object.
3580 __ JumpIfSmi(receiver, &load_smi_map);
3581 __ mov(receiver_map, FieldOperand(receiver, 0));
3582 __ bind(&compare_map);
3583 __ mov(cached_map, FieldOperand(feedback, FixedArray::OffsetOfElementAt(0)));
3584
3585 // A named keyed load might have a 2 element array, all other cases can count
3586 // on an array with at least 2 {map, handler} pairs, so they can go right
3587 // into polymorphic array handling.
3588 __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
3589 __ j(not_equal, is_polymorphic ? &start_polymorphic : &next);
3590
3591 // found, now call handler.
3592 Register handler = feedback;
3593 __ mov(handler, FieldOperand(feedback, FixedArray::OffsetOfElementAt(1)));
3594 __ pop(vector);
3595 __ pop(receiver);
3596 __ lea(handler, FieldOperand(handler, Code::kHeaderSize));
3597 __ jmp(handler);
3598
3599 if (!is_polymorphic) {
3600 __ bind(&next);
3601 __ cmp(FieldOperand(feedback, FixedArray::kLengthOffset),
3602 Immediate(Smi::FromInt(2)));
3603 __ j(not_equal, &start_polymorphic);
3604 __ pop(vector);
3605 __ pop(receiver);
3606 __ jmp(miss);
3607 }
3608
3609 // Polymorphic, we have to loop from 2 to N
3610 __ bind(&start_polymorphic);
3611 __ push(key);
3612 Register counter = key;
3613 __ mov(counter, Immediate(Smi::FromInt(2)));
3614 __ bind(&next_loop);
3615 __ mov(cached_map, FieldOperand(feedback, counter, times_half_pointer_size,
3616 FixedArray::kHeaderSize));
3617 __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
3618 __ j(not_equal, &prepare_next);
3619 __ mov(handler, FieldOperand(feedback, counter, times_half_pointer_size,
3620 FixedArray::kHeaderSize + kPointerSize));
3621 __ pop(key);
3622 __ pop(vector);
3623 __ pop(receiver);
3624 __ lea(handler, FieldOperand(handler, Code::kHeaderSize));
3625 __ jmp(handler);
3626
3627 __ bind(&prepare_next);
3628 __ add(counter, Immediate(Smi::FromInt(2)));
3629 __ cmp(counter, FieldOperand(feedback, FixedArray::kLengthOffset));
3630 __ j(less, &next_loop);
3631
3632 // We exhausted our array of map handler pairs.
3633 __ pop(key);
3634 __ pop(vector);
3635 __ pop(receiver);
3636 __ jmp(miss);
3637
3638 __ bind(&load_smi_map);
3639 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
3640 __ jmp(&compare_map);
3641}
3642
3643
3644static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
3645 Register key, Register vector, Register slot,
3646 Register weak_cell, Label* miss) {
3647 // feedback initially contains the feedback array
3648 Label compare_smi_map;
3649
3650 // Move the weak map into the weak_cell register.
3651 Register ic_map = weak_cell;
3652 __ mov(ic_map, FieldOperand(weak_cell, WeakCell::kValueOffset));
3653
3654 // Receiver might not be a heap object.
3655 __ JumpIfSmi(receiver, &compare_smi_map);
3656 __ cmp(ic_map, FieldOperand(receiver, 0));
3657 __ j(not_equal, miss);
3658 Register handler = weak_cell;
3659 __ mov(handler, FieldOperand(vector, slot, times_half_pointer_size,
3660 FixedArray::kHeaderSize + kPointerSize));
3661 __ lea(handler, FieldOperand(handler, Code::kHeaderSize));
3662 __ jmp(handler);
3663
3664 // In microbenchmarks, it made sense to unroll this code so that the call to
3665 // the handler is duplicated for a HeapObject receiver and a Smi receiver.
3666 __ bind(&compare_smi_map);
3667 __ CompareRoot(ic_map, Heap::kHeapNumberMapRootIndex);
3668 __ j(not_equal, miss);
3669 __ mov(handler, FieldOperand(vector, slot, times_half_pointer_size,
3670 FixedArray::kHeaderSize + kPointerSize));
3671 __ lea(handler, FieldOperand(handler, Code::kHeaderSize));
3672 __ jmp(handler);
3673}
3674
3675
3676void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
3677
3678
3679void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
3680 GenerateImpl(masm, true);
3681}
3682
3683
3684void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
3685 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // edx
3686 Register name = LoadWithVectorDescriptor::NameRegister(); // ecx
3687 Register vector = LoadWithVectorDescriptor::VectorRegister(); // ebx
3688 Register slot = LoadWithVectorDescriptor::SlotRegister(); // eax
3689 Register scratch = edi;
3690 __ mov(scratch, FieldOperand(vector, slot, times_half_pointer_size,
3691 FixedArray::kHeaderSize));
3692
3693 // Is it a weak cell?
3694 Label try_array;
3695 Label not_array, smi_key, key_okay, miss;
3696 __ CompareRoot(FieldOperand(scratch, 0), Heap::kWeakCellMapRootIndex);
3697 __ j(not_equal, &try_array);
3698 HandleMonomorphicCase(masm, receiver, name, vector, slot, scratch, &miss);
3699
3700 // Is it a fixed array?
3701 __ bind(&try_array);
3702 __ CompareRoot(FieldOperand(scratch, 0), Heap::kFixedArrayMapRootIndex);
3703 __ j(not_equal, &not_array);
3704 HandleArrayCases(masm, receiver, name, vector, slot, scratch, true, &miss);
3705
3706 __ bind(&not_array);
3707 __ CompareRoot(scratch, Heap::kmegamorphic_symbolRootIndex);
3708 __ j(not_equal, &miss);
3709 __ push(slot);
3710 __ push(vector);
Ben Murdochc5610432016-08-08 18:44:38 +01003711 Code::Flags code_flags =
3712 Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(Code::LOAD_IC));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003713 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
3714 receiver, name, vector, scratch);
3715 __ pop(vector);
3716 __ pop(slot);
3717
3718 __ bind(&miss);
3719 LoadIC::GenerateMiss(masm);
3720}
3721
3722
3723void KeyedLoadICStub::Generate(MacroAssembler* masm) {
3724 GenerateImpl(masm, false);
3725}
3726
3727
3728void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
3729 GenerateImpl(masm, true);
3730}
3731
3732
3733void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
3734 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // edx
3735 Register key = LoadWithVectorDescriptor::NameRegister(); // ecx
3736 Register vector = LoadWithVectorDescriptor::VectorRegister(); // ebx
3737 Register slot = LoadWithVectorDescriptor::SlotRegister(); // eax
3738 Register feedback = edi;
3739 __ mov(feedback, FieldOperand(vector, slot, times_half_pointer_size,
3740 FixedArray::kHeaderSize));
3741 // Is it a weak cell?
3742 Label try_array;
3743 Label not_array, smi_key, key_okay, miss;
3744 __ CompareRoot(FieldOperand(feedback, 0), Heap::kWeakCellMapRootIndex);
3745 __ j(not_equal, &try_array);
3746 HandleMonomorphicCase(masm, receiver, key, vector, slot, feedback, &miss);
3747
3748 __ bind(&try_array);
3749 // Is it a fixed array?
3750 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex);
3751 __ j(not_equal, &not_array);
3752
3753 // We have a polymorphic element handler.
3754 Label polymorphic, try_poly_name;
3755 __ bind(&polymorphic);
3756 HandleArrayCases(masm, receiver, key, vector, slot, feedback, true, &miss);
3757
3758 __ bind(&not_array);
3759 // Is it generic?
3760 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
3761 __ j(not_equal, &try_poly_name);
3762 Handle<Code> megamorphic_stub =
3763 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
3764 __ jmp(megamorphic_stub, RelocInfo::CODE_TARGET);
3765
3766 __ bind(&try_poly_name);
3767 // We might have a name in feedback, and a fixed array in the next slot.
3768 __ cmp(key, feedback);
3769 __ j(not_equal, &miss);
3770 // If the name comparison succeeded, we know we have a fixed array with
3771 // at least one map/handler pair.
3772 __ mov(feedback, FieldOperand(vector, slot, times_half_pointer_size,
3773 FixedArray::kHeaderSize + kPointerSize));
3774 HandleArrayCases(masm, receiver, key, vector, slot, feedback, false, &miss);
3775
3776 __ bind(&miss);
3777 KeyedLoadIC::GenerateMiss(masm);
3778}
3779
3780
3781void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
3782 __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister());
3783 VectorStoreICStub stub(isolate(), state());
3784 stub.GenerateForTrampoline(masm);
3785}
3786
3787
3788void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
3789 __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister());
3790 VectorKeyedStoreICStub stub(isolate(), state());
3791 stub.GenerateForTrampoline(masm);
3792}
3793
3794
3795void VectorStoreICStub::Generate(MacroAssembler* masm) {
3796 GenerateImpl(masm, false);
3797}
3798
3799
3800void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
3801 GenerateImpl(masm, true);
3802}
3803
3804
3805// value is on the stack already.
3806static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register receiver,
3807 Register key, Register vector,
3808 Register slot, Register feedback,
3809 bool is_polymorphic, Label* miss) {
3810 // feedback initially contains the feedback array
3811 Label next, next_loop, prepare_next;
3812 Label load_smi_map, compare_map;
3813 Label start_polymorphic;
3814 Label pop_and_miss;
3815 ExternalReference virtual_register =
3816 ExternalReference::virtual_handler_register(masm->isolate());
3817
3818 __ push(receiver);
3819 __ push(vector);
3820
3821 Register receiver_map = receiver;
3822 Register cached_map = vector;
3823
3824 // Receiver might not be a heap object.
3825 __ JumpIfSmi(receiver, &load_smi_map);
3826 __ mov(receiver_map, FieldOperand(receiver, 0));
3827 __ bind(&compare_map);
3828 __ mov(cached_map, FieldOperand(feedback, FixedArray::OffsetOfElementAt(0)));
3829
3830 // A named keyed store might have a 2 element array, all other cases can count
3831 // on an array with at least 2 {map, handler} pairs, so they can go right
3832 // into polymorphic array handling.
3833 __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
3834 __ j(not_equal, &start_polymorphic);
3835
3836 // found, now call handler.
3837 Register handler = feedback;
3838 DCHECK(handler.is(VectorStoreICDescriptor::ValueRegister()));
3839 __ mov(handler, FieldOperand(feedback, FixedArray::OffsetOfElementAt(1)));
3840 __ pop(vector);
3841 __ pop(receiver);
3842 __ lea(handler, FieldOperand(handler, Code::kHeaderSize));
3843 __ mov(Operand::StaticVariable(virtual_register), handler);
3844 __ pop(handler); // Pop "value".
3845 __ jmp(Operand::StaticVariable(virtual_register));
3846
3847 // Polymorphic, we have to loop from 2 to N
3848 __ bind(&start_polymorphic);
3849 __ push(key);
3850 Register counter = key;
3851 __ mov(counter, Immediate(Smi::FromInt(2)));
3852
3853 if (!is_polymorphic) {
3854 // If is_polymorphic is false, we may only have a two element array.
3855 // Check against length now in that case.
3856 __ cmp(counter, FieldOperand(feedback, FixedArray::kLengthOffset));
3857 __ j(greater_equal, &pop_and_miss);
3858 }
3859
3860 __ bind(&next_loop);
3861 __ mov(cached_map, FieldOperand(feedback, counter, times_half_pointer_size,
3862 FixedArray::kHeaderSize));
3863 __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
3864 __ j(not_equal, &prepare_next);
3865 __ mov(handler, FieldOperand(feedback, counter, times_half_pointer_size,
3866 FixedArray::kHeaderSize + kPointerSize));
3867 __ lea(handler, FieldOperand(handler, Code::kHeaderSize));
3868 __ pop(key);
3869 __ pop(vector);
3870 __ pop(receiver);
3871 __ mov(Operand::StaticVariable(virtual_register), handler);
3872 __ pop(handler); // Pop "value".
3873 __ jmp(Operand::StaticVariable(virtual_register));
3874
3875 __ bind(&prepare_next);
3876 __ add(counter, Immediate(Smi::FromInt(2)));
3877 __ cmp(counter, FieldOperand(feedback, FixedArray::kLengthOffset));
3878 __ j(less, &next_loop);
3879
3880 // We exhausted our array of map handler pairs.
3881 __ bind(&pop_and_miss);
3882 __ pop(key);
3883 __ pop(vector);
3884 __ pop(receiver);
3885 __ jmp(miss);
3886
3887 __ bind(&load_smi_map);
3888 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
3889 __ jmp(&compare_map);
3890}
3891
3892
3893static void HandleMonomorphicStoreCase(MacroAssembler* masm, Register receiver,
3894 Register key, Register vector,
3895 Register slot, Register weak_cell,
3896 Label* miss) {
3897 // The store ic value is on the stack.
3898 DCHECK(weak_cell.is(VectorStoreICDescriptor::ValueRegister()));
3899 ExternalReference virtual_register =
3900 ExternalReference::virtual_handler_register(masm->isolate());
3901
3902 // feedback initially contains the feedback array
3903 Label compare_smi_map;
3904
3905 // Move the weak map into the weak_cell register.
3906 Register ic_map = weak_cell;
3907 __ mov(ic_map, FieldOperand(weak_cell, WeakCell::kValueOffset));
3908
3909 // Receiver might not be a heap object.
3910 __ JumpIfSmi(receiver, &compare_smi_map);
3911 __ cmp(ic_map, FieldOperand(receiver, 0));
3912 __ j(not_equal, miss);
3913 __ mov(weak_cell, FieldOperand(vector, slot, times_half_pointer_size,
3914 FixedArray::kHeaderSize + kPointerSize));
3915 __ lea(weak_cell, FieldOperand(weak_cell, Code::kHeaderSize));
3916 // Put the store ic value back in it's register.
3917 __ mov(Operand::StaticVariable(virtual_register), weak_cell);
3918 __ pop(weak_cell); // Pop "value".
3919 // jump to the handler.
3920 __ jmp(Operand::StaticVariable(virtual_register));
3921
3922 // In microbenchmarks, it made sense to unroll this code so that the call to
3923 // the handler is duplicated for a HeapObject receiver and a Smi receiver.
3924 __ bind(&compare_smi_map);
3925 __ CompareRoot(ic_map, Heap::kHeapNumberMapRootIndex);
3926 __ j(not_equal, miss);
3927 __ mov(weak_cell, FieldOperand(vector, slot, times_half_pointer_size,
3928 FixedArray::kHeaderSize + kPointerSize));
3929 __ lea(weak_cell, FieldOperand(weak_cell, Code::kHeaderSize));
3930 __ mov(Operand::StaticVariable(virtual_register), weak_cell);
3931 __ pop(weak_cell); // Pop "value".
3932 // jump to the handler.
3933 __ jmp(Operand::StaticVariable(virtual_register));
3934}
3935
3936
3937void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
3938 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // edx
3939 Register key = VectorStoreICDescriptor::NameRegister(); // ecx
3940 Register value = VectorStoreICDescriptor::ValueRegister(); // eax
3941 Register vector = VectorStoreICDescriptor::VectorRegister(); // ebx
3942 Register slot = VectorStoreICDescriptor::SlotRegister(); // edi
3943 Label miss;
3944
3945 __ push(value);
3946
3947 Register scratch = value;
3948 __ mov(scratch, FieldOperand(vector, slot, times_half_pointer_size,
3949 FixedArray::kHeaderSize));
3950
3951 // Is it a weak cell?
3952 Label try_array;
3953 Label not_array, smi_key, key_okay;
3954 __ CompareRoot(FieldOperand(scratch, 0), Heap::kWeakCellMapRootIndex);
3955 __ j(not_equal, &try_array);
3956 HandleMonomorphicStoreCase(masm, receiver, key, vector, slot, scratch, &miss);
3957
3958 // Is it a fixed array?
3959 __ bind(&try_array);
3960 __ CompareRoot(FieldOperand(scratch, 0), Heap::kFixedArrayMapRootIndex);
3961 __ j(not_equal, &not_array);
3962 HandlePolymorphicStoreCase(masm, receiver, key, vector, slot, scratch, true,
3963 &miss);
3964
3965 __ bind(&not_array);
3966 __ CompareRoot(scratch, Heap::kmegamorphic_symbolRootIndex);
3967 __ j(not_equal, &miss);
3968
3969 __ pop(value);
3970 __ push(slot);
3971 __ push(vector);
Ben Murdochc5610432016-08-08 18:44:38 +01003972 Code::Flags code_flags =
3973 Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(Code::STORE_IC));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003974 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::STORE_IC, code_flags,
3975 receiver, key, slot, no_reg);
3976 __ pop(vector);
3977 __ pop(slot);
3978 Label no_pop_miss;
3979 __ jmp(&no_pop_miss);
3980
3981 __ bind(&miss);
3982 __ pop(value);
3983 __ bind(&no_pop_miss);
3984 StoreIC::GenerateMiss(masm);
3985}
3986
3987
3988void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
3989 GenerateImpl(masm, false);
3990}
3991
3992
3993void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
3994 GenerateImpl(masm, true);
3995}
3996
3997
3998static void HandlePolymorphicKeyedStoreCase(MacroAssembler* masm,
3999 Register receiver, Register key,
4000 Register vector, Register slot,
4001 Register feedback, Label* miss) {
4002 // feedback initially contains the feedback array
4003 Label next, next_loop, prepare_next;
4004 Label load_smi_map, compare_map;
4005 Label transition_call;
4006 Label pop_and_miss;
4007 ExternalReference virtual_register =
4008 ExternalReference::virtual_handler_register(masm->isolate());
4009 ExternalReference virtual_slot =
4010 ExternalReference::virtual_slot_register(masm->isolate());
4011
4012 __ push(receiver);
4013 __ push(vector);
4014
4015 Register receiver_map = receiver;
4016 Register cached_map = vector;
4017 Register value = StoreDescriptor::ValueRegister();
4018
4019 // Receiver might not be a heap object.
4020 __ JumpIfSmi(receiver, &load_smi_map);
4021 __ mov(receiver_map, FieldOperand(receiver, 0));
4022 __ bind(&compare_map);
4023
4024 // Polymorphic, we have to loop from 0 to N - 1
4025 __ push(key);
4026 // Current stack layout:
4027 // - esp[0] -- key
4028 // - esp[4] -- vector
4029 // - esp[8] -- receiver
4030 // - esp[12] -- value
4031 // - esp[16] -- return address
4032 //
4033 // Required stack layout for handler call:
4034 // - esp[0] -- return address
4035 // - receiver, key, value, vector, slot in registers.
4036 // - handler in virtual register.
4037 Register counter = key;
4038 __ mov(counter, Immediate(Smi::FromInt(0)));
4039 __ bind(&next_loop);
4040 __ mov(cached_map, FieldOperand(feedback, counter, times_half_pointer_size,
4041 FixedArray::kHeaderSize));
4042 __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4043 __ j(not_equal, &prepare_next);
4044 __ mov(cached_map, FieldOperand(feedback, counter, times_half_pointer_size,
4045 FixedArray::kHeaderSize + kPointerSize));
4046 __ CompareRoot(cached_map, Heap::kUndefinedValueRootIndex);
4047 __ j(not_equal, &transition_call);
4048 __ mov(feedback, FieldOperand(feedback, counter, times_half_pointer_size,
4049 FixedArray::kHeaderSize + 2 * kPointerSize));
4050 __ pop(key);
4051 __ pop(vector);
4052 __ pop(receiver);
4053 __ lea(feedback, FieldOperand(feedback, Code::kHeaderSize));
4054 __ mov(Operand::StaticVariable(virtual_register), feedback);
4055 __ pop(value);
4056 __ jmp(Operand::StaticVariable(virtual_register));
4057
4058 __ bind(&transition_call);
4059 // Current stack layout:
4060 // - esp[0] -- key
4061 // - esp[4] -- vector
4062 // - esp[8] -- receiver
4063 // - esp[12] -- value
4064 // - esp[16] -- return address
4065 //
4066 // Required stack layout for handler call:
4067 // - esp[0] -- return address
4068 // - receiver, key, value, map, vector in registers.
4069 // - handler and slot in virtual registers.
4070 __ mov(Operand::StaticVariable(virtual_slot), slot);
4071 __ mov(feedback, FieldOperand(feedback, counter, times_half_pointer_size,
4072 FixedArray::kHeaderSize + 2 * kPointerSize));
4073 __ lea(feedback, FieldOperand(feedback, Code::kHeaderSize));
4074 __ mov(Operand::StaticVariable(virtual_register), feedback);
4075
4076 __ mov(cached_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4077 // The weak cell may have been cleared.
4078 __ JumpIfSmi(cached_map, &pop_and_miss);
4079 DCHECK(!cached_map.is(VectorStoreTransitionDescriptor::MapRegister()));
4080 __ mov(VectorStoreTransitionDescriptor::MapRegister(), cached_map);
4081
4082 // Pop key into place.
4083 __ pop(key);
4084 __ pop(vector);
4085 __ pop(receiver);
4086 __ pop(value);
4087 __ jmp(Operand::StaticVariable(virtual_register));
4088
4089 __ bind(&prepare_next);
4090 __ add(counter, Immediate(Smi::FromInt(3)));
4091 __ cmp(counter, FieldOperand(feedback, FixedArray::kLengthOffset));
4092 __ j(less, &next_loop);
4093
4094 // We exhausted our array of map handler pairs.
4095 __ bind(&pop_and_miss);
4096 __ pop(key);
4097 __ pop(vector);
4098 __ pop(receiver);
4099 __ jmp(miss);
4100
4101 __ bind(&load_smi_map);
4102 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4103 __ jmp(&compare_map);
4104}
4105
4106
4107void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4108 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // edx
4109 Register key = VectorStoreICDescriptor::NameRegister(); // ecx
4110 Register value = VectorStoreICDescriptor::ValueRegister(); // eax
4111 Register vector = VectorStoreICDescriptor::VectorRegister(); // ebx
4112 Register slot = VectorStoreICDescriptor::SlotRegister(); // edi
4113 Label miss;
4114
4115 __ push(value);
4116
4117 Register scratch = value;
4118 __ mov(scratch, FieldOperand(vector, slot, times_half_pointer_size,
4119 FixedArray::kHeaderSize));
4120
4121 // Is it a weak cell?
4122 Label try_array;
4123 Label not_array, smi_key, key_okay;
4124 __ CompareRoot(FieldOperand(scratch, 0), Heap::kWeakCellMapRootIndex);
4125 __ j(not_equal, &try_array);
4126 HandleMonomorphicStoreCase(masm, receiver, key, vector, slot, scratch, &miss);
4127
4128 // Is it a fixed array?
4129 __ bind(&try_array);
4130 __ CompareRoot(FieldOperand(scratch, 0), Heap::kFixedArrayMapRootIndex);
4131 __ j(not_equal, &not_array);
4132 HandlePolymorphicKeyedStoreCase(masm, receiver, key, vector, slot, scratch,
4133 &miss);
4134
4135 __ bind(&not_array);
4136 Label try_poly_name;
4137 __ CompareRoot(scratch, Heap::kmegamorphic_symbolRootIndex);
4138 __ j(not_equal, &try_poly_name);
4139
4140 __ pop(value);
4141
4142 Handle<Code> megamorphic_stub =
4143 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4144 __ jmp(megamorphic_stub, RelocInfo::CODE_TARGET);
4145
4146 __ bind(&try_poly_name);
4147 // We might have a name in feedback, and a fixed array in the next slot.
4148 __ cmp(key, scratch);
4149 __ j(not_equal, &miss);
4150 // If the name comparison succeeded, we know we have a fixed array with
4151 // at least one map/handler pair.
4152 __ mov(scratch, FieldOperand(vector, slot, times_half_pointer_size,
4153 FixedArray::kHeaderSize + kPointerSize));
4154 HandlePolymorphicStoreCase(masm, receiver, key, vector, slot, scratch, false,
4155 &miss);
4156
4157 __ bind(&miss);
4158 __ pop(value);
4159 KeyedStoreIC::GenerateMiss(masm);
4160}
4161
4162
4163void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4164 __ EmitLoadTypeFeedbackVector(ebx);
4165 CallICStub stub(isolate(), state());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004166 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET);
4167}
4168
4169
4170void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4171 if (masm->isolate()->function_entry_hook() != NULL) {
4172 ProfileEntryHookStub stub(masm->isolate());
4173 masm->CallStub(&stub);
4174 }
4175}
4176
4177
4178void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4179 // Save volatile registers.
4180 const int kNumSavedRegisters = 3;
4181 __ push(eax);
4182 __ push(ecx);
4183 __ push(edx);
4184
4185 // Calculate and push the original stack pointer.
4186 __ lea(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize));
4187 __ push(eax);
4188
4189 // Retrieve our return address and use it to calculate the calling
4190 // function's address.
4191 __ mov(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize));
4192 __ sub(eax, Immediate(Assembler::kCallInstructionLength));
4193 __ push(eax);
4194
4195 // Call the entry hook.
4196 DCHECK(isolate()->function_entry_hook() != NULL);
4197 __ call(FUNCTION_ADDR(isolate()->function_entry_hook()),
4198 RelocInfo::RUNTIME_ENTRY);
4199 __ add(esp, Immediate(2 * kPointerSize));
4200
4201 // Restore ecx.
4202 __ pop(edx);
4203 __ pop(ecx);
4204 __ pop(eax);
4205
4206 __ ret(0);
4207}
4208
4209
4210template<class T>
4211static void CreateArrayDispatch(MacroAssembler* masm,
4212 AllocationSiteOverrideMode mode) {
4213 if (mode == DISABLE_ALLOCATION_SITES) {
4214 T stub(masm->isolate(),
4215 GetInitialFastElementsKind(),
4216 mode);
4217 __ TailCallStub(&stub);
4218 } else if (mode == DONT_OVERRIDE) {
4219 int last_index = GetSequenceIndexFromFastElementsKind(
4220 TERMINAL_FAST_ELEMENTS_KIND);
4221 for (int i = 0; i <= last_index; ++i) {
4222 Label next;
4223 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4224 __ cmp(edx, kind);
4225 __ j(not_equal, &next);
4226 T stub(masm->isolate(), kind);
4227 __ TailCallStub(&stub);
4228 __ bind(&next);
4229 }
4230
4231 // If we reached this point there is a problem.
4232 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4233 } else {
4234 UNREACHABLE();
4235 }
4236}
4237
4238
4239static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4240 AllocationSiteOverrideMode mode) {
4241 // ebx - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4242 // edx - kind (if mode != DISABLE_ALLOCATION_SITES)
4243 // eax - number of arguments
4244 // edi - constructor?
4245 // esp[0] - return address
4246 // esp[4] - last argument
4247 Label normal_sequence;
4248 if (mode == DONT_OVERRIDE) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004249 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4250 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4251 STATIC_ASSERT(FAST_ELEMENTS == 2);
4252 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4253 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4254 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004255
4256 // is the low bit set? If so, we are holey and that is good.
Ben Murdochda12d292016-06-02 14:46:10 +01004257 __ test_b(edx, Immediate(1));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004258 __ j(not_zero, &normal_sequence);
4259 }
4260
4261 // look at the first argument
4262 __ mov(ecx, Operand(esp, kPointerSize));
4263 __ test(ecx, ecx);
4264 __ j(zero, &normal_sequence);
4265
4266 if (mode == DISABLE_ALLOCATION_SITES) {
4267 ElementsKind initial = GetInitialFastElementsKind();
4268 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4269
4270 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4271 holey_initial,
4272 DISABLE_ALLOCATION_SITES);
4273 __ TailCallStub(&stub_holey);
4274
4275 __ bind(&normal_sequence);
4276 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4277 initial,
4278 DISABLE_ALLOCATION_SITES);
4279 __ TailCallStub(&stub);
4280 } else if (mode == DONT_OVERRIDE) {
4281 // We are going to create a holey array, but our kind is non-holey.
4282 // Fix kind and retry.
4283 __ inc(edx);
4284
4285 if (FLAG_debug_code) {
4286 Handle<Map> allocation_site_map =
4287 masm->isolate()->factory()->allocation_site_map();
4288 __ cmp(FieldOperand(ebx, 0), Immediate(allocation_site_map));
4289 __ Assert(equal, kExpectedAllocationSite);
4290 }
4291
4292 // Save the resulting elements kind in type info. We can't just store r3
4293 // in the AllocationSite::transition_info field because elements kind is
4294 // restricted to a portion of the field...upper bits need to be left alone.
4295 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4296 __ add(FieldOperand(ebx, AllocationSite::kTransitionInfoOffset),
4297 Immediate(Smi::FromInt(kFastElementsKindPackedToHoley)));
4298
4299 __ bind(&normal_sequence);
4300 int last_index = GetSequenceIndexFromFastElementsKind(
4301 TERMINAL_FAST_ELEMENTS_KIND);
4302 for (int i = 0; i <= last_index; ++i) {
4303 Label next;
4304 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4305 __ cmp(edx, kind);
4306 __ j(not_equal, &next);
4307 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4308 __ TailCallStub(&stub);
4309 __ bind(&next);
4310 }
4311
4312 // If we reached this point there is a problem.
4313 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4314 } else {
4315 UNREACHABLE();
4316 }
4317}
4318
4319
4320template<class T>
4321static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4322 int to_index = GetSequenceIndexFromFastElementsKind(
4323 TERMINAL_FAST_ELEMENTS_KIND);
4324 for (int i = 0; i <= to_index; ++i) {
4325 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4326 T stub(isolate, kind);
4327 stub.GetCode();
4328 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4329 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4330 stub1.GetCode();
4331 }
4332 }
4333}
4334
4335
4336void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4337 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4338 isolate);
4339 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4340 isolate);
4341 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4342 isolate);
4343}
4344
4345
4346void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4347 Isolate* isolate) {
4348 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4349 for (int i = 0; i < 2; i++) {
4350 // For internal arrays we only need a few things
4351 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4352 stubh1.GetCode();
4353 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4354 stubh2.GetCode();
4355 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4356 stubh3.GetCode();
4357 }
4358}
4359
4360
4361void ArrayConstructorStub::GenerateDispatchToArrayStub(
4362 MacroAssembler* masm,
4363 AllocationSiteOverrideMode mode) {
4364 if (argument_count() == ANY) {
4365 Label not_zero_case, not_one_case;
4366 __ test(eax, eax);
4367 __ j(not_zero, &not_zero_case);
4368 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4369
4370 __ bind(&not_zero_case);
4371 __ cmp(eax, 1);
4372 __ j(greater, &not_one_case);
4373 CreateArrayDispatchOneArgument(masm, mode);
4374
4375 __ bind(&not_one_case);
4376 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4377 } else if (argument_count() == NONE) {
4378 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4379 } else if (argument_count() == ONE) {
4380 CreateArrayDispatchOneArgument(masm, mode);
4381 } else if (argument_count() == MORE_THAN_ONE) {
4382 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4383 } else {
4384 UNREACHABLE();
4385 }
4386}
4387
4388
4389void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4390 // ----------- S t a t e -------------
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004391 // -- eax : argc (only if argument_count() is ANY or MORE_THAN_ONE)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004392 // -- ebx : AllocationSite or undefined
4393 // -- edi : constructor
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004394 // -- edx : Original constructor
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004395 // -- esp[0] : return address
4396 // -- esp[4] : last argument
4397 // -----------------------------------
4398 if (FLAG_debug_code) {
4399 // The array construct code is only set for the global and natives
4400 // builtin Array functions which always have maps.
4401
4402 // Initial map for the builtin Array function should be a map.
4403 __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset));
4404 // Will both indicate a NULL and a Smi.
4405 __ test(ecx, Immediate(kSmiTagMask));
4406 __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction);
4407 __ CmpObjectType(ecx, MAP_TYPE, ecx);
4408 __ Assert(equal, kUnexpectedInitialMapForArrayFunction);
4409
4410 // We should either have undefined in ebx or a valid AllocationSite
4411 __ AssertUndefinedOrAllocationSite(ebx);
4412 }
4413
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004414 Label subclassing;
4415
4416 // Enter the context of the Array function.
4417 __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset));
4418
4419 __ cmp(edx, edi);
4420 __ j(not_equal, &subclassing);
4421
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004422 Label no_info;
4423 // If the feedback vector is the undefined value call an array constructor
4424 // that doesn't use AllocationSites.
4425 __ cmp(ebx, isolate()->factory()->undefined_value());
4426 __ j(equal, &no_info);
4427
4428 // Only look at the lower 16 bits of the transition info.
4429 __ mov(edx, FieldOperand(ebx, AllocationSite::kTransitionInfoOffset));
4430 __ SmiUntag(edx);
4431 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4432 __ and_(edx, Immediate(AllocationSite::ElementsKindBits::kMask));
4433 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4434
4435 __ bind(&no_info);
4436 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004437
4438 // Subclassing.
4439 __ bind(&subclassing);
4440 switch (argument_count()) {
4441 case ANY:
4442 case MORE_THAN_ONE:
4443 __ mov(Operand(esp, eax, times_pointer_size, kPointerSize), edi);
4444 __ add(eax, Immediate(3));
4445 break;
4446 case NONE:
4447 __ mov(Operand(esp, 1 * kPointerSize), edi);
4448 __ mov(eax, Immediate(3));
4449 break;
4450 case ONE:
4451 __ mov(Operand(esp, 2 * kPointerSize), edi);
4452 __ mov(eax, Immediate(4));
4453 break;
4454 }
4455 __ PopReturnAddressTo(ecx);
4456 __ Push(edx);
4457 __ Push(ebx);
4458 __ PushReturnAddressFrom(ecx);
4459 __ JumpToExternalReference(ExternalReference(Runtime::kNewArray, isolate()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004460}
4461
4462
4463void InternalArrayConstructorStub::GenerateCase(
4464 MacroAssembler* masm, ElementsKind kind) {
4465 Label not_zero_case, not_one_case;
4466 Label normal_sequence;
4467
4468 __ test(eax, eax);
4469 __ j(not_zero, &not_zero_case);
4470 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4471 __ TailCallStub(&stub0);
4472
4473 __ bind(&not_zero_case);
4474 __ cmp(eax, 1);
4475 __ j(greater, &not_one_case);
4476
4477 if (IsFastPackedElementsKind(kind)) {
4478 // We might need to create a holey array
4479 // look at the first argument
4480 __ mov(ecx, Operand(esp, kPointerSize));
4481 __ test(ecx, ecx);
4482 __ j(zero, &normal_sequence);
4483
4484 InternalArraySingleArgumentConstructorStub
4485 stub1_holey(isolate(), GetHoleyElementsKind(kind));
4486 __ TailCallStub(&stub1_holey);
4487 }
4488
4489 __ bind(&normal_sequence);
4490 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
4491 __ TailCallStub(&stub1);
4492
4493 __ bind(&not_one_case);
4494 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
4495 __ TailCallStub(&stubN);
4496}
4497
4498
4499void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
4500 // ----------- S t a t e -------------
4501 // -- eax : argc
4502 // -- edi : constructor
4503 // -- esp[0] : return address
4504 // -- esp[4] : last argument
4505 // -----------------------------------
4506
4507 if (FLAG_debug_code) {
4508 // The array construct code is only set for the global and natives
4509 // builtin Array functions which always have maps.
4510
4511 // Initial map for the builtin Array function should be a map.
4512 __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset));
4513 // Will both indicate a NULL and a Smi.
4514 __ test(ecx, Immediate(kSmiTagMask));
4515 __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction);
4516 __ CmpObjectType(ecx, MAP_TYPE, ecx);
4517 __ Assert(equal, kUnexpectedInitialMapForArrayFunction);
4518 }
4519
4520 // Figure out the right elements kind
4521 __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset));
4522
4523 // Load the map's "bit field 2" into |result|. We only need the first byte,
4524 // but the following masking takes care of that anyway.
4525 __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset));
4526 // Retrieve elements_kind from bit field 2.
4527 __ DecodeField<Map::ElementsKindBits>(ecx);
4528
4529 if (FLAG_debug_code) {
4530 Label done;
4531 __ cmp(ecx, Immediate(FAST_ELEMENTS));
4532 __ j(equal, &done);
4533 __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS));
4534 __ Assert(equal,
4535 kInvalidElementsKindForInternalArrayOrInternalPackedArray);
4536 __ bind(&done);
4537 }
4538
4539 Label fast_elements_case;
4540 __ cmp(ecx, Immediate(FAST_ELEMENTS));
4541 __ j(equal, &fast_elements_case);
4542 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
4543
4544 __ bind(&fast_elements_case);
4545 GenerateCase(masm, FAST_ELEMENTS);
4546}
4547
4548
Ben Murdoch097c5b22016-05-18 11:27:45 +01004549void FastNewObjectStub::Generate(MacroAssembler* masm) {
4550 // ----------- S t a t e -------------
4551 // -- edi : target
4552 // -- edx : new target
4553 // -- esi : context
4554 // -- esp[0] : return address
4555 // -----------------------------------
4556 __ AssertFunction(edi);
4557 __ AssertReceiver(edx);
4558
4559 // Verify that the new target is a JSFunction.
4560 Label new_object;
4561 __ CmpObjectType(edx, JS_FUNCTION_TYPE, ebx);
4562 __ j(not_equal, &new_object);
4563
4564 // Load the initial map and verify that it's in fact a map.
4565 __ mov(ecx, FieldOperand(edx, JSFunction::kPrototypeOrInitialMapOffset));
4566 __ JumpIfSmi(ecx, &new_object);
4567 __ CmpObjectType(ecx, MAP_TYPE, ebx);
4568 __ j(not_equal, &new_object);
4569
4570 // Fall back to runtime if the target differs from the new target's
4571 // initial map constructor.
4572 __ cmp(edi, FieldOperand(ecx, Map::kConstructorOrBackPointerOffset));
4573 __ j(not_equal, &new_object);
4574
4575 // Allocate the JSObject on the heap.
4576 Label allocate, done_allocate;
4577 __ movzx_b(ebx, FieldOperand(ecx, Map::kInstanceSizeOffset));
4578 __ lea(ebx, Operand(ebx, times_pointer_size, 0));
4579 __ Allocate(ebx, eax, edi, no_reg, &allocate, NO_ALLOCATION_FLAGS);
4580 __ bind(&done_allocate);
4581
4582 // Initialize the JSObject fields.
Ben Murdochc5610432016-08-08 18:44:38 +01004583 __ mov(FieldOperand(eax, JSObject::kMapOffset), ecx);
4584 __ mov(FieldOperand(eax, JSObject::kPropertiesOffset),
Ben Murdoch097c5b22016-05-18 11:27:45 +01004585 masm->isolate()->factory()->empty_fixed_array());
Ben Murdochc5610432016-08-08 18:44:38 +01004586 __ mov(FieldOperand(eax, JSObject::kElementsOffset),
Ben Murdoch097c5b22016-05-18 11:27:45 +01004587 masm->isolate()->factory()->empty_fixed_array());
4588 STATIC_ASSERT(JSObject::kHeaderSize == 3 * kPointerSize);
Ben Murdochc5610432016-08-08 18:44:38 +01004589 __ lea(ebx, FieldOperand(eax, JSObject::kHeaderSize));
Ben Murdoch097c5b22016-05-18 11:27:45 +01004590
4591 // ----------- S t a t e -------------
Ben Murdochc5610432016-08-08 18:44:38 +01004592 // -- eax : result (tagged)
Ben Murdoch097c5b22016-05-18 11:27:45 +01004593 // -- ebx : result fields (untagged)
4594 // -- edi : result end (untagged)
4595 // -- ecx : initial map
4596 // -- esi : context
4597 // -- esp[0] : return address
4598 // -----------------------------------
4599
4600 // Perform in-object slack tracking if requested.
4601 Label slack_tracking;
4602 STATIC_ASSERT(Map::kNoSlackTracking == 0);
4603 __ test(FieldOperand(ecx, Map::kBitField3Offset),
4604 Immediate(Map::ConstructionCounter::kMask));
4605 __ j(not_zero, &slack_tracking, Label::kNear);
4606 {
4607 // Initialize all in-object fields with undefined.
4608 __ LoadRoot(edx, Heap::kUndefinedValueRootIndex);
4609 __ InitializeFieldsWithFiller(ebx, edi, edx);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004610 __ Ret();
4611 }
4612 __ bind(&slack_tracking);
4613 {
4614 // Decrease generous allocation count.
4615 STATIC_ASSERT(Map::ConstructionCounter::kNext == 32);
4616 __ sub(FieldOperand(ecx, Map::kBitField3Offset),
4617 Immediate(1 << Map::ConstructionCounter::kShift));
4618
4619 // Initialize the in-object fields with undefined.
4620 __ movzx_b(edx, FieldOperand(ecx, Map::kUnusedPropertyFieldsOffset));
4621 __ neg(edx);
4622 __ lea(edx, Operand(edi, edx, times_pointer_size, 0));
4623 __ LoadRoot(edi, Heap::kUndefinedValueRootIndex);
4624 __ InitializeFieldsWithFiller(ebx, edx, edi);
4625
4626 // Initialize the remaining (reserved) fields with one pointer filler map.
4627 __ movzx_b(edx, FieldOperand(ecx, Map::kUnusedPropertyFieldsOffset));
4628 __ lea(edx, Operand(ebx, edx, times_pointer_size, 0));
4629 __ LoadRoot(edi, Heap::kOnePointerFillerMapRootIndex);
4630 __ InitializeFieldsWithFiller(ebx, edx, edi);
4631
Ben Murdoch097c5b22016-05-18 11:27:45 +01004632 // Check if we can finalize the instance size.
4633 Label finalize;
4634 STATIC_ASSERT(Map::kSlackTrackingCounterEnd == 1);
4635 __ test(FieldOperand(ecx, Map::kBitField3Offset),
4636 Immediate(Map::ConstructionCounter::kMask));
4637 __ j(zero, &finalize, Label::kNear);
4638 __ Ret();
4639
4640 // Finalize the instance size.
4641 __ bind(&finalize);
4642 {
4643 FrameScope scope(masm, StackFrame::INTERNAL);
4644 __ Push(eax);
4645 __ Push(ecx);
4646 __ CallRuntime(Runtime::kFinalizeInstanceSize);
4647 __ Pop(eax);
4648 }
4649 __ Ret();
4650 }
4651
4652 // Fall back to %AllocateInNewSpace.
4653 __ bind(&allocate);
4654 {
4655 FrameScope scope(masm, StackFrame::INTERNAL);
4656 __ SmiTag(ebx);
4657 __ Push(ecx);
4658 __ Push(ebx);
4659 __ CallRuntime(Runtime::kAllocateInNewSpace);
4660 __ Pop(ecx);
4661 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01004662 __ movzx_b(ebx, FieldOperand(ecx, Map::kInstanceSizeOffset));
4663 __ lea(edi, Operand(eax, ebx, times_pointer_size, 0));
Ben Murdochc5610432016-08-08 18:44:38 +01004664 STATIC_ASSERT(kHeapObjectTag == 1);
4665 __ dec(edi);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004666 __ jmp(&done_allocate);
4667
4668 // Fall back to %NewObject.
4669 __ bind(&new_object);
4670 __ PopReturnAddressTo(ecx);
4671 __ Push(edi);
4672 __ Push(edx);
4673 __ PushReturnAddressFrom(ecx);
4674 __ TailCallRuntime(Runtime::kNewObject);
4675}
4676
4677
4678void FastNewRestParameterStub::Generate(MacroAssembler* masm) {
4679 // ----------- S t a t e -------------
4680 // -- edi : function
4681 // -- esi : context
4682 // -- ebp : frame pointer
4683 // -- esp[0] : return address
4684 // -----------------------------------
4685 __ AssertFunction(edi);
4686
Ben Murdochc5610432016-08-08 18:44:38 +01004687 // Make edx point to the JavaScript frame.
4688 __ mov(edx, ebp);
4689 if (skip_stub_frame()) {
4690 // For Ignition we need to skip the handler/stub frame to reach the
4691 // JavaScript frame for the function.
Ben Murdoch097c5b22016-05-18 11:27:45 +01004692 __ mov(edx, Operand(edx, StandardFrameConstants::kCallerFPOffset));
Ben Murdochc5610432016-08-08 18:44:38 +01004693 }
4694 if (FLAG_debug_code) {
4695 Label ok;
Ben Murdochda12d292016-06-02 14:46:10 +01004696 __ cmp(edi, Operand(edx, StandardFrameConstants::kFunctionOffset));
Ben Murdochc5610432016-08-08 18:44:38 +01004697 __ j(equal, &ok);
4698 __ Abort(kInvalidFrameForFastNewRestArgumentsStub);
4699 __ bind(&ok);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004700 }
4701
4702 // Check if we have rest parameters (only possible if we have an
4703 // arguments adaptor frame below the function frame).
4704 Label no_rest_parameters;
4705 __ mov(ebx, Operand(edx, StandardFrameConstants::kCallerFPOffset));
Ben Murdochda12d292016-06-02 14:46:10 +01004706 __ cmp(Operand(ebx, CommonFrameConstants::kContextOrFrameTypeOffset),
Ben Murdoch097c5b22016-05-18 11:27:45 +01004707 Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
4708 __ j(not_equal, &no_rest_parameters, Label::kNear);
4709
4710 // Check if the arguments adaptor frame contains more arguments than
4711 // specified by the function's internal formal parameter count.
4712 Label rest_parameters;
4713 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
4714 __ mov(eax, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset));
4715 __ sub(eax,
4716 FieldOperand(ecx, SharedFunctionInfo::kFormalParameterCountOffset));
4717 __ j(greater, &rest_parameters);
4718
4719 // Return an empty rest parameter array.
4720 __ bind(&no_rest_parameters);
4721 {
4722 // ----------- S t a t e -------------
4723 // -- esi : context
4724 // -- esp[0] : return address
4725 // -----------------------------------
4726
4727 // Allocate an empty rest parameter array.
4728 Label allocate, done_allocate;
Ben Murdochc5610432016-08-08 18:44:38 +01004729 __ Allocate(JSArray::kSize, eax, edx, ecx, &allocate, NO_ALLOCATION_FLAGS);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004730 __ bind(&done_allocate);
4731
4732 // Setup the rest parameter array in rax.
4733 __ LoadGlobalFunction(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, ecx);
4734 __ mov(FieldOperand(eax, JSArray::kMapOffset), ecx);
4735 __ mov(ecx, isolate()->factory()->empty_fixed_array());
4736 __ mov(FieldOperand(eax, JSArray::kPropertiesOffset), ecx);
4737 __ mov(FieldOperand(eax, JSArray::kElementsOffset), ecx);
4738 __ mov(FieldOperand(eax, JSArray::kLengthOffset),
4739 Immediate(Smi::FromInt(0)));
4740 STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize);
4741 __ Ret();
4742
4743 // Fall back to %AllocateInNewSpace.
4744 __ bind(&allocate);
4745 {
4746 FrameScope scope(masm, StackFrame::INTERNAL);
4747 __ Push(Smi::FromInt(JSArray::kSize));
4748 __ CallRuntime(Runtime::kAllocateInNewSpace);
4749 }
4750 __ jmp(&done_allocate);
4751 }
4752
4753 __ bind(&rest_parameters);
4754 {
4755 // Compute the pointer to the first rest parameter (skippping the receiver).
4756 __ lea(ebx,
4757 Operand(ebx, eax, times_half_pointer_size,
4758 StandardFrameConstants::kCallerSPOffset - 1 * kPointerSize));
4759
4760 // ----------- S t a t e -------------
4761 // -- esi : context
4762 // -- eax : number of rest parameters (tagged)
4763 // -- ebx : pointer to first rest parameters
4764 // -- esp[0] : return address
4765 // -----------------------------------
4766
4767 // Allocate space for the rest parameter array plus the backing store.
4768 Label allocate, done_allocate;
4769 __ lea(ecx, Operand(eax, times_half_pointer_size,
4770 JSArray::kSize + FixedArray::kHeaderSize));
Ben Murdochc5610432016-08-08 18:44:38 +01004771 __ Allocate(ecx, edx, edi, no_reg, &allocate, NO_ALLOCATION_FLAGS);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004772 __ bind(&done_allocate);
4773
4774 // Setup the elements array in edx.
4775 __ mov(FieldOperand(edx, FixedArray::kMapOffset),
4776 isolate()->factory()->fixed_array_map());
4777 __ mov(FieldOperand(edx, FixedArray::kLengthOffset), eax);
4778 {
4779 Label loop, done_loop;
4780 __ Move(ecx, Smi::FromInt(0));
4781 __ bind(&loop);
4782 __ cmp(ecx, eax);
4783 __ j(equal, &done_loop, Label::kNear);
4784 __ mov(edi, Operand(ebx, 0 * kPointerSize));
4785 __ mov(FieldOperand(edx, ecx, times_half_pointer_size,
4786 FixedArray::kHeaderSize),
4787 edi);
4788 __ sub(ebx, Immediate(1 * kPointerSize));
4789 __ add(ecx, Immediate(Smi::FromInt(1)));
4790 __ jmp(&loop);
4791 __ bind(&done_loop);
4792 }
4793
4794 // Setup the rest parameter array in edi.
4795 __ lea(edi,
4796 Operand(edx, eax, times_half_pointer_size, FixedArray::kHeaderSize));
4797 __ LoadGlobalFunction(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, ecx);
4798 __ mov(FieldOperand(edi, JSArray::kMapOffset), ecx);
4799 __ mov(FieldOperand(edi, JSArray::kPropertiesOffset),
4800 isolate()->factory()->empty_fixed_array());
4801 __ mov(FieldOperand(edi, JSArray::kElementsOffset), edx);
4802 __ mov(FieldOperand(edi, JSArray::kLengthOffset), eax);
4803 STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize);
4804 __ mov(eax, edi);
4805 __ Ret();
4806
4807 // Fall back to %AllocateInNewSpace.
4808 __ bind(&allocate);
4809 {
4810 FrameScope scope(masm, StackFrame::INTERNAL);
4811 __ SmiTag(ecx);
4812 __ Push(eax);
4813 __ Push(ebx);
4814 __ Push(ecx);
4815 __ CallRuntime(Runtime::kAllocateInNewSpace);
4816 __ mov(edx, eax);
4817 __ Pop(ebx);
4818 __ Pop(eax);
4819 }
4820 __ jmp(&done_allocate);
4821 }
4822}
4823
4824
4825void FastNewSloppyArgumentsStub::Generate(MacroAssembler* masm) {
4826 // ----------- S t a t e -------------
4827 // -- edi : function
4828 // -- esi : context
4829 // -- ebp : frame pointer
4830 // -- esp[0] : return address
4831 // -----------------------------------
4832 __ AssertFunction(edi);
4833
Ben Murdochc5610432016-08-08 18:44:38 +01004834 // Make ecx point to the JavaScript frame.
4835 __ mov(ecx, ebp);
4836 if (skip_stub_frame()) {
4837 // For Ignition we need to skip the handler/stub frame to reach the
4838 // JavaScript frame for the function.
4839 __ mov(ecx, Operand(ecx, StandardFrameConstants::kCallerFPOffset));
4840 }
4841 if (FLAG_debug_code) {
4842 Label ok;
4843 __ cmp(edi, Operand(ecx, StandardFrameConstants::kFunctionOffset));
4844 __ j(equal, &ok);
4845 __ Abort(kInvalidFrameForFastNewSloppyArgumentsStub);
4846 __ bind(&ok);
4847 }
4848
Ben Murdoch097c5b22016-05-18 11:27:45 +01004849 // TODO(bmeurer): Cleanup to match the FastNewStrictArgumentsStub.
Ben Murdochc5610432016-08-08 18:44:38 +01004850 __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
4851 __ mov(ebx,
4852 FieldOperand(ebx, SharedFunctionInfo::kFormalParameterCountOffset));
4853 __ lea(edx, Operand(ecx, ebx, times_half_pointer_size,
Ben Murdoch097c5b22016-05-18 11:27:45 +01004854 StandardFrameConstants::kCallerSPOffset));
4855
Ben Murdochc5610432016-08-08 18:44:38 +01004856 // ebx : number of parameters (tagged)
Ben Murdoch097c5b22016-05-18 11:27:45 +01004857 // edx : parameters pointer
4858 // edi : function
Ben Murdochc5610432016-08-08 18:44:38 +01004859 // ecx : JavaScript frame pointer.
Ben Murdoch097c5b22016-05-18 11:27:45 +01004860 // esp[0] : return address
4861
4862 // Check if the calling frame is an arguments adaptor frame.
4863 Label adaptor_frame, try_allocate, runtime;
Ben Murdochc5610432016-08-08 18:44:38 +01004864 __ mov(eax, Operand(ecx, StandardFrameConstants::kCallerFPOffset));
4865 __ mov(eax, Operand(eax, CommonFrameConstants::kContextOrFrameTypeOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01004866 __ cmp(eax, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
4867 __ j(equal, &adaptor_frame, Label::kNear);
4868
4869 // No adaptor, parameter count = argument count.
Ben Murdochc5610432016-08-08 18:44:38 +01004870 __ mov(ecx, ebx);
4871 __ push(ebx);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004872 __ jmp(&try_allocate, Label::kNear);
4873
4874 // We have an adaptor frame. Patch the parameters pointer.
4875 __ bind(&adaptor_frame);
Ben Murdochc5610432016-08-08 18:44:38 +01004876 __ push(ebx);
4877 __ mov(edx, Operand(ecx, StandardFrameConstants::kCallerFPOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01004878 __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset));
4879 __ lea(edx, Operand(edx, ecx, times_2,
4880 StandardFrameConstants::kCallerSPOffset));
4881
4882 // ebx = parameter count (tagged)
4883 // ecx = argument count (smi-tagged)
4884 // Compute the mapped parameter count = min(ebx, ecx) in ebx.
4885 __ cmp(ebx, ecx);
4886 __ j(less_equal, &try_allocate, Label::kNear);
4887 __ mov(ebx, ecx);
4888
4889 // Save mapped parameter count and function.
4890 __ bind(&try_allocate);
4891 __ push(edi);
4892 __ push(ebx);
4893
4894 // Compute the sizes of backing store, parameter map, and arguments object.
4895 // 1. Parameter map, has 2 extra words containing context and backing store.
4896 const int kParameterMapHeaderSize =
4897 FixedArray::kHeaderSize + 2 * kPointerSize;
4898 Label no_parameter_map;
4899 __ test(ebx, ebx);
4900 __ j(zero, &no_parameter_map, Label::kNear);
4901 __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize));
4902 __ bind(&no_parameter_map);
4903
4904 // 2. Backing store.
4905 __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize));
4906
4907 // 3. Arguments object.
4908 __ add(ebx, Immediate(JSSloppyArgumentsObject::kSize));
4909
4910 // Do the allocation of all three objects in one go.
Ben Murdochc5610432016-08-08 18:44:38 +01004911 __ Allocate(ebx, eax, edi, no_reg, &runtime, NO_ALLOCATION_FLAGS);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004912
4913 // eax = address of new object(s) (tagged)
4914 // ecx = argument count (smi-tagged)
4915 // esp[0] = mapped parameter count (tagged)
4916 // esp[4] = function
4917 // esp[8] = parameter count (tagged)
4918 // Get the arguments map from the current native context into edi.
4919 Label has_mapped_parameters, instantiate;
4920 __ mov(edi, NativeContextOperand());
4921 __ mov(ebx, Operand(esp, 0 * kPointerSize));
4922 __ test(ebx, ebx);
4923 __ j(not_zero, &has_mapped_parameters, Label::kNear);
4924 __ mov(
4925 edi,
4926 Operand(edi, Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX)));
4927 __ jmp(&instantiate, Label::kNear);
4928
4929 __ bind(&has_mapped_parameters);
4930 __ mov(edi, Operand(edi, Context::SlotOffset(
4931 Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX)));
4932 __ bind(&instantiate);
4933
4934 // eax = address of new object (tagged)
4935 // ebx = mapped parameter count (tagged)
4936 // ecx = argument count (smi-tagged)
4937 // edi = address of arguments map (tagged)
4938 // esp[0] = mapped parameter count (tagged)
4939 // esp[4] = function
4940 // esp[8] = parameter count (tagged)
4941 // Copy the JS object part.
4942 __ mov(FieldOperand(eax, JSObject::kMapOffset), edi);
4943 __ mov(FieldOperand(eax, JSObject::kPropertiesOffset),
4944 masm->isolate()->factory()->empty_fixed_array());
4945 __ mov(FieldOperand(eax, JSObject::kElementsOffset),
4946 masm->isolate()->factory()->empty_fixed_array());
4947
4948 // Set up the callee in-object property.
4949 STATIC_ASSERT(JSSloppyArgumentsObject::kCalleeIndex == 1);
4950 __ mov(edi, Operand(esp, 1 * kPointerSize));
4951 __ AssertNotSmi(edi);
4952 __ mov(FieldOperand(eax, JSSloppyArgumentsObject::kCalleeOffset), edi);
4953
4954 // Use the length (smi tagged) and set that as an in-object property too.
4955 __ AssertSmi(ecx);
4956 __ mov(FieldOperand(eax, JSSloppyArgumentsObject::kLengthOffset), ecx);
4957
4958 // Set up the elements pointer in the allocated arguments object.
4959 // If we allocated a parameter map, edi will point there, otherwise to the
4960 // backing store.
4961 __ lea(edi, Operand(eax, JSSloppyArgumentsObject::kSize));
4962 __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi);
4963
4964 // eax = address of new object (tagged)
4965 // ebx = mapped parameter count (tagged)
4966 // ecx = argument count (tagged)
4967 // edx = address of receiver argument
4968 // edi = address of parameter map or backing store (tagged)
4969 // esp[0] = mapped parameter count (tagged)
4970 // esp[4] = function
4971 // esp[8] = parameter count (tagged)
4972 // Free two registers.
4973 __ push(edx);
4974 __ push(eax);
4975
4976 // Initialize parameter map. If there are no mapped arguments, we're done.
4977 Label skip_parameter_map;
4978 __ test(ebx, ebx);
4979 __ j(zero, &skip_parameter_map);
4980
4981 __ mov(FieldOperand(edi, FixedArray::kMapOffset),
4982 Immediate(isolate()->factory()->sloppy_arguments_elements_map()));
4983 __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2))));
4984 __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax);
4985 __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi);
4986 __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize));
4987 __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax);
4988
4989 // Copy the parameter slots and the holes in the arguments.
4990 // We need to fill in mapped_parameter_count slots. They index the context,
4991 // where parameters are stored in reverse order, at
4992 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
4993 // The mapped parameter thus need to get indices
4994 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
4995 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
4996 // We loop from right to left.
4997 Label parameters_loop, parameters_test;
4998 __ push(ecx);
4999 __ mov(eax, Operand(esp, 3 * kPointerSize));
5000 __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
5001 __ add(ebx, Operand(esp, 5 * kPointerSize));
5002 __ sub(ebx, eax);
5003 __ mov(ecx, isolate()->factory()->the_hole_value());
5004 __ mov(edx, edi);
5005 __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize));
5006 // eax = loop variable (tagged)
5007 // ebx = mapping index (tagged)
5008 // ecx = the hole value
5009 // edx = address of parameter map (tagged)
5010 // edi = address of backing store (tagged)
5011 // esp[0] = argument count (tagged)
5012 // esp[4] = address of new object (tagged)
5013 // esp[8] = address of receiver argument
5014 // esp[12] = mapped parameter count (tagged)
5015 // esp[16] = function
5016 // esp[20] = parameter count (tagged)
5017 __ jmp(&parameters_test, Label::kNear);
5018
5019 __ bind(&parameters_loop);
5020 __ sub(eax, Immediate(Smi::FromInt(1)));
5021 __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx);
5022 __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx);
5023 __ add(ebx, Immediate(Smi::FromInt(1)));
5024 __ bind(&parameters_test);
5025 __ test(eax, eax);
5026 __ j(not_zero, &parameters_loop, Label::kNear);
5027 __ pop(ecx);
5028
5029 __ bind(&skip_parameter_map);
5030
5031 // ecx = argument count (tagged)
5032 // edi = address of backing store (tagged)
5033 // esp[0] = address of new object (tagged)
5034 // esp[4] = address of receiver argument
5035 // esp[8] = mapped parameter count (tagged)
5036 // esp[12] = function
5037 // esp[16] = parameter count (tagged)
5038 // Copy arguments header and remaining slots (if there are any).
5039 __ mov(FieldOperand(edi, FixedArray::kMapOffset),
5040 Immediate(isolate()->factory()->fixed_array_map()));
5041 __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx);
5042
5043 Label arguments_loop, arguments_test;
5044 __ mov(ebx, Operand(esp, 2 * kPointerSize));
5045 __ mov(edx, Operand(esp, 1 * kPointerSize));
5046 __ sub(edx, ebx); // Is there a smarter way to do negative scaling?
5047 __ sub(edx, ebx);
5048 __ jmp(&arguments_test, Label::kNear);
5049
5050 __ bind(&arguments_loop);
5051 __ sub(edx, Immediate(kPointerSize));
5052 __ mov(eax, Operand(edx, 0));
5053 __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax);
5054 __ add(ebx, Immediate(Smi::FromInt(1)));
5055
5056 __ bind(&arguments_test);
5057 __ cmp(ebx, ecx);
5058 __ j(less, &arguments_loop, Label::kNear);
5059
5060 // Restore.
5061 __ pop(eax); // Address of arguments object.
5062 __ Drop(4);
5063
5064 // Return.
5065 __ ret(0);
5066
5067 // Do the runtime call to allocate the arguments object.
5068 __ bind(&runtime);
5069 __ pop(eax); // Remove saved mapped parameter count.
5070 __ pop(edi); // Pop saved function.
5071 __ pop(eax); // Remove saved parameter count.
5072 __ pop(eax); // Pop return address.
5073 __ push(edi); // Push function.
5074 __ push(edx); // Push parameters pointer.
5075 __ push(ecx); // Push parameter count.
5076 __ push(eax); // Push return address.
5077 __ TailCallRuntime(Runtime::kNewSloppyArguments);
5078}
5079
5080
5081void FastNewStrictArgumentsStub::Generate(MacroAssembler* masm) {
5082 // ----------- S t a t e -------------
5083 // -- edi : function
5084 // -- esi : context
5085 // -- ebp : frame pointer
5086 // -- esp[0] : return address
5087 // -----------------------------------
5088 __ AssertFunction(edi);
5089
Ben Murdochc5610432016-08-08 18:44:38 +01005090 // Make edx point to the JavaScript frame.
5091 __ mov(edx, ebp);
5092 if (skip_stub_frame()) {
5093 // For Ignition we need to skip the handler/stub frame to reach the
5094 // JavaScript frame for the function.
Ben Murdoch097c5b22016-05-18 11:27:45 +01005095 __ mov(edx, Operand(edx, StandardFrameConstants::kCallerFPOffset));
Ben Murdochc5610432016-08-08 18:44:38 +01005096 }
5097 if (FLAG_debug_code) {
5098 Label ok;
Ben Murdochda12d292016-06-02 14:46:10 +01005099 __ cmp(edi, Operand(edx, StandardFrameConstants::kFunctionOffset));
Ben Murdochc5610432016-08-08 18:44:38 +01005100 __ j(equal, &ok);
5101 __ Abort(kInvalidFrameForFastNewStrictArgumentsStub);
5102 __ bind(&ok);
Ben Murdoch097c5b22016-05-18 11:27:45 +01005103 }
5104
5105 // Check if we have an arguments adaptor frame below the function frame.
5106 Label arguments_adaptor, arguments_done;
5107 __ mov(ebx, Operand(edx, StandardFrameConstants::kCallerFPOffset));
Ben Murdochda12d292016-06-02 14:46:10 +01005108 __ cmp(Operand(ebx, CommonFrameConstants::kContextOrFrameTypeOffset),
Ben Murdoch097c5b22016-05-18 11:27:45 +01005109 Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
5110 __ j(equal, &arguments_adaptor, Label::kNear);
5111 {
5112 __ mov(eax, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
5113 __ mov(eax,
5114 FieldOperand(eax, SharedFunctionInfo::kFormalParameterCountOffset));
5115 __ lea(ebx,
5116 Operand(edx, eax, times_half_pointer_size,
5117 StandardFrameConstants::kCallerSPOffset - 1 * kPointerSize));
5118 }
5119 __ jmp(&arguments_done, Label::kNear);
5120 __ bind(&arguments_adaptor);
5121 {
5122 __ mov(eax, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset));
5123 __ lea(ebx,
5124 Operand(ebx, eax, times_half_pointer_size,
5125 StandardFrameConstants::kCallerSPOffset - 1 * kPointerSize));
5126 }
5127 __ bind(&arguments_done);
5128
5129 // ----------- S t a t e -------------
5130 // -- eax : number of arguments (tagged)
5131 // -- ebx : pointer to the first argument
5132 // -- esi : context
5133 // -- esp[0] : return address
5134 // -----------------------------------
5135
5136 // Allocate space for the strict arguments object plus the backing store.
5137 Label allocate, done_allocate;
5138 __ lea(ecx,
5139 Operand(eax, times_half_pointer_size,
5140 JSStrictArgumentsObject::kSize + FixedArray::kHeaderSize));
Ben Murdochc5610432016-08-08 18:44:38 +01005141 __ Allocate(ecx, edx, edi, no_reg, &allocate, NO_ALLOCATION_FLAGS);
Ben Murdoch097c5b22016-05-18 11:27:45 +01005142 __ bind(&done_allocate);
5143
5144 // Setup the elements array in edx.
5145 __ mov(FieldOperand(edx, FixedArray::kMapOffset),
5146 isolate()->factory()->fixed_array_map());
5147 __ mov(FieldOperand(edx, FixedArray::kLengthOffset), eax);
5148 {
5149 Label loop, done_loop;
5150 __ Move(ecx, Smi::FromInt(0));
5151 __ bind(&loop);
5152 __ cmp(ecx, eax);
5153 __ j(equal, &done_loop, Label::kNear);
5154 __ mov(edi, Operand(ebx, 0 * kPointerSize));
5155 __ mov(FieldOperand(edx, ecx, times_half_pointer_size,
5156 FixedArray::kHeaderSize),
5157 edi);
5158 __ sub(ebx, Immediate(1 * kPointerSize));
5159 __ add(ecx, Immediate(Smi::FromInt(1)));
5160 __ jmp(&loop);
5161 __ bind(&done_loop);
5162 }
5163
5164 // Setup the rest parameter array in edi.
5165 __ lea(edi,
5166 Operand(edx, eax, times_half_pointer_size, FixedArray::kHeaderSize));
5167 __ LoadGlobalFunction(Context::STRICT_ARGUMENTS_MAP_INDEX, ecx);
5168 __ mov(FieldOperand(edi, JSStrictArgumentsObject::kMapOffset), ecx);
5169 __ mov(FieldOperand(edi, JSStrictArgumentsObject::kPropertiesOffset),
5170 isolate()->factory()->empty_fixed_array());
5171 __ mov(FieldOperand(edi, JSStrictArgumentsObject::kElementsOffset), edx);
5172 __ mov(FieldOperand(edi, JSStrictArgumentsObject::kLengthOffset), eax);
5173 STATIC_ASSERT(JSStrictArgumentsObject::kSize == 4 * kPointerSize);
5174 __ mov(eax, edi);
5175 __ Ret();
5176
5177 // Fall back to %AllocateInNewSpace.
5178 __ bind(&allocate);
5179 {
5180 FrameScope scope(masm, StackFrame::INTERNAL);
5181 __ SmiTag(ecx);
5182 __ Push(eax);
5183 __ Push(ebx);
5184 __ Push(ecx);
5185 __ CallRuntime(Runtime::kAllocateInNewSpace);
5186 __ mov(edx, eax);
5187 __ Pop(ebx);
5188 __ Pop(eax);
5189 }
5190 __ jmp(&done_allocate);
5191}
5192
5193
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005194void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5195 Register context_reg = esi;
5196 Register slot_reg = ebx;
5197 Register result_reg = eax;
5198 Label slow_case;
5199
5200 // Go up context chain to the script context.
5201 for (int i = 0; i < depth(); ++i) {
5202 __ mov(result_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5203 context_reg = result_reg;
5204 }
5205
5206 // Load the PropertyCell value at the specified slot.
5207 __ mov(result_reg, ContextOperand(context_reg, slot_reg));
5208 __ mov(result_reg, FieldOperand(result_reg, PropertyCell::kValueOffset));
5209
5210 // Check that value is not the_hole.
5211 __ CompareRoot(result_reg, Heap::kTheHoleValueRootIndex);
5212 __ j(equal, &slow_case, Label::kNear);
5213 __ Ret();
5214
5215 // Fallback to the runtime.
5216 __ bind(&slow_case);
5217 __ SmiTag(slot_reg);
5218 __ Pop(result_reg); // Pop return address.
5219 __ Push(slot_reg);
5220 __ Push(result_reg); // Push return address.
5221 __ TailCallRuntime(Runtime::kLoadGlobalViaContext);
5222}
5223
5224
5225void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5226 Register context_reg = esi;
5227 Register slot_reg = ebx;
5228 Register value_reg = eax;
5229 Register cell_reg = edi;
5230 Register cell_details_reg = edx;
5231 Register cell_value_reg = ecx;
5232 Label fast_heapobject_case, fast_smi_case, slow_case;
5233
5234 if (FLAG_debug_code) {
5235 __ CompareRoot(value_reg, Heap::kTheHoleValueRootIndex);
5236 __ Check(not_equal, kUnexpectedValue);
5237 }
5238
5239 // Go up context chain to the script context.
5240 for (int i = 0; i < depth(); ++i) {
5241 __ mov(cell_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5242 context_reg = cell_reg;
5243 }
5244
5245 // Load the PropertyCell at the specified slot.
5246 __ mov(cell_reg, ContextOperand(context_reg, slot_reg));
5247
5248 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5249 __ mov(cell_details_reg,
5250 FieldOperand(cell_reg, PropertyCell::kDetailsOffset));
5251 __ SmiUntag(cell_details_reg);
5252 __ and_(cell_details_reg,
5253 Immediate(PropertyDetails::PropertyCellTypeField::kMask |
5254 PropertyDetails::KindField::kMask |
5255 PropertyDetails::kAttributesReadOnlyMask));
5256
5257 // Check if PropertyCell holds mutable data.
5258 Label not_mutable_data;
5259 __ cmp(cell_details_reg,
5260 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5261 PropertyCellType::kMutable) |
5262 PropertyDetails::KindField::encode(kData)));
5263 __ j(not_equal, &not_mutable_data);
5264 __ JumpIfSmi(value_reg, &fast_smi_case);
5265 __ bind(&fast_heapobject_case);
5266 __ mov(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg);
5267 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg,
5268 cell_details_reg, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5269 OMIT_SMI_CHECK);
5270 // RecordWriteField clobbers the value register, so we need to reload.
5271 __ mov(value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset));
5272 __ Ret();
5273 __ bind(&not_mutable_data);
5274
5275 // Check if PropertyCell value matches the new value (relevant for Constant,
5276 // ConstantType and Undefined cells).
5277 Label not_same_value;
5278 __ mov(cell_value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset));
5279 __ cmp(cell_value_reg, value_reg);
5280 __ j(not_equal, &not_same_value,
5281 FLAG_debug_code ? Label::kFar : Label::kNear);
5282 // Make sure the PropertyCell is not marked READ_ONLY.
5283 __ test(cell_details_reg,
5284 Immediate(PropertyDetails::kAttributesReadOnlyMask));
5285 __ j(not_zero, &slow_case);
5286 if (FLAG_debug_code) {
5287 Label done;
5288 // This can only be true for Constant, ConstantType and Undefined cells,
5289 // because we never store the_hole via this stub.
5290 __ cmp(cell_details_reg,
5291 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5292 PropertyCellType::kConstant) |
5293 PropertyDetails::KindField::encode(kData)));
5294 __ j(equal, &done);
5295 __ cmp(cell_details_reg,
5296 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5297 PropertyCellType::kConstantType) |
5298 PropertyDetails::KindField::encode(kData)));
5299 __ j(equal, &done);
5300 __ cmp(cell_details_reg,
5301 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5302 PropertyCellType::kUndefined) |
5303 PropertyDetails::KindField::encode(kData)));
5304 __ Check(equal, kUnexpectedValue);
5305 __ bind(&done);
5306 }
5307 __ Ret();
5308 __ bind(&not_same_value);
5309
5310 // Check if PropertyCell contains data with constant type (and is not
5311 // READ_ONLY).
5312 __ cmp(cell_details_reg,
5313 Immediate(PropertyDetails::PropertyCellTypeField::encode(
5314 PropertyCellType::kConstantType) |
5315 PropertyDetails::KindField::encode(kData)));
5316 __ j(not_equal, &slow_case, Label::kNear);
5317
5318 // Now either both old and new values must be SMIs or both must be heap
5319 // objects with same map.
5320 Label value_is_heap_object;
5321 __ JumpIfNotSmi(value_reg, &value_is_heap_object, Label::kNear);
5322 __ JumpIfNotSmi(cell_value_reg, &slow_case, Label::kNear);
5323 // Old and new values are SMIs, no need for a write barrier here.
5324 __ bind(&fast_smi_case);
5325 __ mov(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg);
5326 __ Ret();
5327 __ bind(&value_is_heap_object);
5328 __ JumpIfSmi(cell_value_reg, &slow_case, Label::kNear);
5329 Register cell_value_map_reg = cell_value_reg;
5330 __ mov(cell_value_map_reg,
5331 FieldOperand(cell_value_reg, HeapObject::kMapOffset));
5332 __ cmp(cell_value_map_reg, FieldOperand(value_reg, HeapObject::kMapOffset));
5333 __ j(equal, &fast_heapobject_case);
5334
5335 // Fallback to the runtime.
5336 __ bind(&slow_case);
5337 __ SmiTag(slot_reg);
5338 __ Pop(cell_reg); // Pop return address.
5339 __ Push(slot_reg);
5340 __ Push(value_reg);
5341 __ Push(cell_reg); // Push return address.
5342 __ TailCallRuntime(is_strict(language_mode())
5343 ? Runtime::kStoreGlobalViaContext_Strict
5344 : Runtime::kStoreGlobalViaContext_Sloppy);
5345}
5346
5347
5348// Generates an Operand for saving parameters after PrepareCallApiFunction.
5349static Operand ApiParameterOperand(int index) {
5350 return Operand(esp, index * kPointerSize);
5351}
5352
5353
5354// Prepares stack to put arguments (aligns and so on). Reserves
5355// space for return value if needed (assumes the return value is a handle).
5356// Arguments must be stored in ApiParameterOperand(0), ApiParameterOperand(1)
5357// etc. Saves context (esi). If space was reserved for return value then
5358// stores the pointer to the reserved slot into esi.
5359static void PrepareCallApiFunction(MacroAssembler* masm, int argc) {
5360 __ EnterApiExitFrame(argc);
5361 if (__ emit_debug_code()) {
5362 __ mov(esi, Immediate(bit_cast<int32_t>(kZapValue)));
5363 }
5364}
5365
5366
5367// Calls an API function. Allocates HandleScope, extracts returned value
5368// from handle and propagates exceptions. Clobbers ebx, edi and
5369// caller-save registers. Restores context. On return removes
5370// stack_space * kPointerSize (GCed).
5371static void CallApiFunctionAndReturn(MacroAssembler* masm,
5372 Register function_address,
5373 ExternalReference thunk_ref,
5374 Operand thunk_last_arg, int stack_space,
5375 Operand* stack_space_operand,
5376 Operand return_value_operand,
5377 Operand* context_restore_operand) {
5378 Isolate* isolate = masm->isolate();
5379
5380 ExternalReference next_address =
5381 ExternalReference::handle_scope_next_address(isolate);
5382 ExternalReference limit_address =
5383 ExternalReference::handle_scope_limit_address(isolate);
5384 ExternalReference level_address =
5385 ExternalReference::handle_scope_level_address(isolate);
5386
5387 DCHECK(edx.is(function_address));
5388 // Allocate HandleScope in callee-save registers.
5389 __ mov(ebx, Operand::StaticVariable(next_address));
5390 __ mov(edi, Operand::StaticVariable(limit_address));
5391 __ add(Operand::StaticVariable(level_address), Immediate(1));
5392
5393 if (FLAG_log_timer_events) {
5394 FrameScope frame(masm, StackFrame::MANUAL);
5395 __ PushSafepointRegisters();
5396 __ PrepareCallCFunction(1, eax);
5397 __ mov(Operand(esp, 0),
5398 Immediate(ExternalReference::isolate_address(isolate)));
5399 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5400 1);
5401 __ PopSafepointRegisters();
5402 }
5403
5404
5405 Label profiler_disabled;
5406 Label end_profiler_check;
5407 __ mov(eax, Immediate(ExternalReference::is_profiling_address(isolate)));
Ben Murdochda12d292016-06-02 14:46:10 +01005408 __ cmpb(Operand(eax, 0), Immediate(0));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005409 __ j(zero, &profiler_disabled);
5410
5411 // Additional parameter is the address of the actual getter function.
5412 __ mov(thunk_last_arg, function_address);
5413 // Call the api function.
5414 __ mov(eax, Immediate(thunk_ref));
5415 __ call(eax);
5416 __ jmp(&end_profiler_check);
5417
5418 __ bind(&profiler_disabled);
5419 // Call the api function.
5420 __ call(function_address);
5421 __ bind(&end_profiler_check);
5422
5423 if (FLAG_log_timer_events) {
5424 FrameScope frame(masm, StackFrame::MANUAL);
5425 __ PushSafepointRegisters();
5426 __ PrepareCallCFunction(1, eax);
5427 __ mov(Operand(esp, 0),
5428 Immediate(ExternalReference::isolate_address(isolate)));
5429 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5430 1);
5431 __ PopSafepointRegisters();
5432 }
5433
5434 Label prologue;
5435 // Load the value from ReturnValue
5436 __ mov(eax, return_value_operand);
5437
5438 Label promote_scheduled_exception;
5439 Label delete_allocated_handles;
5440 Label leave_exit_frame;
5441
5442 __ bind(&prologue);
5443 // No more valid handles (the result handle was the last one). Restore
5444 // previous handle scope.
5445 __ mov(Operand::StaticVariable(next_address), ebx);
5446 __ sub(Operand::StaticVariable(level_address), Immediate(1));
5447 __ Assert(above_equal, kInvalidHandleScopeLevel);
5448 __ cmp(edi, Operand::StaticVariable(limit_address));
5449 __ j(not_equal, &delete_allocated_handles);
5450
5451 // Leave the API exit frame.
5452 __ bind(&leave_exit_frame);
5453 bool restore_context = context_restore_operand != NULL;
5454 if (restore_context) {
5455 __ mov(esi, *context_restore_operand);
5456 }
5457 if (stack_space_operand != nullptr) {
5458 __ mov(ebx, *stack_space_operand);
5459 }
5460 __ LeaveApiExitFrame(!restore_context);
5461
5462 // Check if the function scheduled an exception.
5463 ExternalReference scheduled_exception_address =
5464 ExternalReference::scheduled_exception_address(isolate);
5465 __ cmp(Operand::StaticVariable(scheduled_exception_address),
5466 Immediate(isolate->factory()->the_hole_value()));
5467 __ j(not_equal, &promote_scheduled_exception);
5468
5469#if DEBUG
5470 // Check if the function returned a valid JavaScript value.
5471 Label ok;
5472 Register return_value = eax;
5473 Register map = ecx;
5474
5475 __ JumpIfSmi(return_value, &ok, Label::kNear);
5476 __ mov(map, FieldOperand(return_value, HeapObject::kMapOffset));
5477
5478 __ CmpInstanceType(map, LAST_NAME_TYPE);
5479 __ j(below_equal, &ok, Label::kNear);
5480
5481 __ CmpInstanceType(map, FIRST_JS_RECEIVER_TYPE);
5482 __ j(above_equal, &ok, Label::kNear);
5483
5484 __ cmp(map, isolate->factory()->heap_number_map());
5485 __ j(equal, &ok, Label::kNear);
5486
5487 __ cmp(return_value, isolate->factory()->undefined_value());
5488 __ j(equal, &ok, Label::kNear);
5489
5490 __ cmp(return_value, isolate->factory()->true_value());
5491 __ j(equal, &ok, Label::kNear);
5492
5493 __ cmp(return_value, isolate->factory()->false_value());
5494 __ j(equal, &ok, Label::kNear);
5495
5496 __ cmp(return_value, isolate->factory()->null_value());
5497 __ j(equal, &ok, Label::kNear);
5498
5499 __ Abort(kAPICallReturnedInvalidObject);
5500
5501 __ bind(&ok);
5502#endif
5503
5504 if (stack_space_operand != nullptr) {
5505 DCHECK_EQ(0, stack_space);
5506 __ pop(ecx);
5507 __ add(esp, ebx);
5508 __ jmp(ecx);
5509 } else {
5510 __ ret(stack_space * kPointerSize);
5511 }
5512
5513 // Re-throw by promoting a scheduled exception.
5514 __ bind(&promote_scheduled_exception);
5515 __ TailCallRuntime(Runtime::kPromoteScheduledException);
5516
5517 // HandleScope limit has changed. Delete allocated extensions.
5518 ExternalReference delete_extensions =
5519 ExternalReference::delete_handle_scope_extensions(isolate);
5520 __ bind(&delete_allocated_handles);
5521 __ mov(Operand::StaticVariable(limit_address), edi);
5522 __ mov(edi, eax);
5523 __ mov(Operand(esp, 0),
5524 Immediate(ExternalReference::isolate_address(isolate)));
5525 __ mov(eax, Immediate(delete_extensions));
5526 __ call(eax);
5527 __ mov(eax, edi);
5528 __ jmp(&leave_exit_frame);
5529}
5530
Ben Murdochda12d292016-06-02 14:46:10 +01005531void CallApiCallbackStub::Generate(MacroAssembler* masm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005532 // ----------- S t a t e -------------
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005533 // -- edi : callee
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005534 // -- ebx : call_data
5535 // -- ecx : holder
5536 // -- edx : api_function_address
5537 // -- esi : context
5538 // --
5539 // -- esp[0] : return address
5540 // -- esp[4] : last argument
5541 // -- ...
5542 // -- esp[argc * 4] : first argument
5543 // -- esp[(argc + 1) * 4] : receiver
5544 // -----------------------------------
5545
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005546 Register callee = edi;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005547 Register call_data = ebx;
5548 Register holder = ecx;
5549 Register api_function_address = edx;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005550 Register context = esi;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005551 Register return_address = eax;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005552
5553 typedef FunctionCallbackArguments FCA;
5554
5555 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5556 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5557 STATIC_ASSERT(FCA::kDataIndex == 4);
5558 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5559 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5560 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5561 STATIC_ASSERT(FCA::kHolderIndex == 0);
Ben Murdochc5610432016-08-08 18:44:38 +01005562 STATIC_ASSERT(FCA::kNewTargetIndex == 7);
5563 STATIC_ASSERT(FCA::kArgsLength == 8);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005564
Ben Murdochda12d292016-06-02 14:46:10 +01005565 __ pop(return_address);
Ben Murdochc5610432016-08-08 18:44:38 +01005566
5567 // new target
5568 __ PushRoot(Heap::kUndefinedValueRootIndex);
5569
Ben Murdochda12d292016-06-02 14:46:10 +01005570 // context save.
5571 __ push(context);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005572
5573 // callee
5574 __ push(callee);
5575
5576 // call data
5577 __ push(call_data);
5578
5579 Register scratch = call_data;
Ben Murdochda12d292016-06-02 14:46:10 +01005580 if (!call_data_undefined()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005581 // return value
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005582 __ push(Immediate(masm->isolate()->factory()->undefined_value()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005583 // return value default
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005584 __ push(Immediate(masm->isolate()->factory()->undefined_value()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005585 } else {
5586 // return value
5587 __ push(scratch);
5588 // return value default
5589 __ push(scratch);
5590 }
5591 // isolate
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005592 __ push(Immediate(reinterpret_cast<int>(masm->isolate())));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005593 // holder
5594 __ push(holder);
5595
5596 __ mov(scratch, esp);
5597
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005598 // push return address
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005599 __ push(return_address);
5600
Ben Murdochda12d292016-06-02 14:46:10 +01005601 if (!is_lazy()) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01005602 // load context from callee
5603 __ mov(context, FieldOperand(callee, JSFunction::kContextOffset));
5604 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005605
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005606 // API function gets reference to the v8::Arguments. If CPU profiler
5607 // is enabled wrapper function will be called and we need to pass
5608 // address of the callback as additional parameter, always allocate
5609 // space for it.
5610 const int kApiArgc = 1 + 1;
5611
5612 // Allocate the v8::Arguments structure in the arguments' space since
5613 // it's not controlled by GC.
Ben Murdochc5610432016-08-08 18:44:38 +01005614 const int kApiStackSpace = 3;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005615
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005616 PrepareCallApiFunction(masm, kApiArgc + kApiStackSpace);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005617
5618 // FunctionCallbackInfo::implicit_args_.
5619 __ mov(ApiParameterOperand(2), scratch);
Ben Murdochda12d292016-06-02 14:46:10 +01005620 __ add(scratch, Immediate((argc() + FCA::kArgsLength - 1) * kPointerSize));
5621 // FunctionCallbackInfo::values_.
5622 __ mov(ApiParameterOperand(3), scratch);
5623 // FunctionCallbackInfo::length_.
5624 __ Move(ApiParameterOperand(4), Immediate(argc()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005625
5626 // v8::InvocationCallback's argument.
5627 __ lea(scratch, ApiParameterOperand(2));
5628 __ mov(ApiParameterOperand(0), scratch);
5629
5630 ExternalReference thunk_ref =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005631 ExternalReference::invoke_function_callback(masm->isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005632
5633 Operand context_restore_operand(ebp,
5634 (2 + FCA::kContextSaveIndex) * kPointerSize);
5635 // Stores return the first js argument
5636 int return_value_offset = 0;
Ben Murdochda12d292016-06-02 14:46:10 +01005637 if (is_store()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005638 return_value_offset = 2 + FCA::kArgsLength;
5639 } else {
5640 return_value_offset = 2 + FCA::kReturnValueOffset;
5641 }
5642 Operand return_value_operand(ebp, return_value_offset * kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005643 int stack_space = 0;
Ben Murdochc5610432016-08-08 18:44:38 +01005644 Operand length_operand = ApiParameterOperand(4);
5645 Operand* stack_space_operand = &length_operand;
Ben Murdochda12d292016-06-02 14:46:10 +01005646 stack_space = argc() + FCA::kArgsLength + 1;
5647 stack_space_operand = nullptr;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005648 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5649 ApiParameterOperand(1), stack_space,
5650 stack_space_operand, return_value_operand,
5651 &context_restore_operand);
5652}
5653
5654
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005655void CallApiGetterStub::Generate(MacroAssembler* masm) {
Ben Murdochc5610432016-08-08 18:44:38 +01005656 // Build v8::PropertyCallbackInfo::args_ array on the stack and push property
5657 // name below the exit frame to make GC aware of them.
5658 STATIC_ASSERT(PropertyCallbackArguments::kShouldThrowOnErrorIndex == 0);
5659 STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 1);
5660 STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 2);
5661 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 3);
5662 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 4);
5663 STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 5);
5664 STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 6);
5665 STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 7);
5666
5667 Register receiver = ApiGetterDescriptor::ReceiverRegister();
5668 Register holder = ApiGetterDescriptor::HolderRegister();
5669 Register callback = ApiGetterDescriptor::CallbackRegister();
5670 Register scratch = ebx;
5671 DCHECK(!AreAliased(receiver, holder, callback, scratch));
5672
5673 __ pop(scratch); // Pop return address to extend the frame.
5674 __ push(receiver);
5675 __ push(FieldOperand(callback, AccessorInfo::kDataOffset));
5676 __ PushRoot(Heap::kUndefinedValueRootIndex); // ReturnValue
5677 // ReturnValue default value
5678 __ PushRoot(Heap::kUndefinedValueRootIndex);
5679 __ push(Immediate(ExternalReference::isolate_address(isolate())));
5680 __ push(holder);
5681 __ push(Immediate(Smi::FromInt(0))); // should_throw_on_error -> false
5682 __ push(FieldOperand(callback, AccessorInfo::kNameOffset));
5683 __ push(scratch); // Restore return address.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005684
Ben Murdoch097c5b22016-05-18 11:27:45 +01005685 // v8::PropertyCallbackInfo::args_ array and name handle.
5686 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5687
5688 // Allocate v8::PropertyCallbackInfo object, arguments for callback and
5689 // space for optional callback address parameter (in case CPU profiler is
5690 // active) in non-GCed stack space.
5691 const int kApiArgc = 3 + 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005692
Ben Murdoch097c5b22016-05-18 11:27:45 +01005693 // Load address of v8::PropertyAccessorInfo::args_ array.
5694 __ lea(scratch, Operand(esp, 2 * kPointerSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005695
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005696 PrepareCallApiFunction(masm, kApiArgc);
Ben Murdoch097c5b22016-05-18 11:27:45 +01005697 // Create v8::PropertyCallbackInfo object on the stack and initialize
5698 // it's args_ field.
5699 Operand info_object = ApiParameterOperand(3);
5700 __ mov(info_object, scratch);
5701
Ben Murdochc5610432016-08-08 18:44:38 +01005702 // Name as handle.
Ben Murdoch097c5b22016-05-18 11:27:45 +01005703 __ sub(scratch, Immediate(kPointerSize));
Ben Murdochc5610432016-08-08 18:44:38 +01005704 __ mov(ApiParameterOperand(0), scratch);
5705 // Arguments pointer.
Ben Murdoch097c5b22016-05-18 11:27:45 +01005706 __ lea(scratch, info_object);
Ben Murdochc5610432016-08-08 18:44:38 +01005707 __ mov(ApiParameterOperand(1), scratch);
Ben Murdoch097c5b22016-05-18 11:27:45 +01005708 // Reserve space for optional callback address parameter.
5709 Operand thunk_last_arg = ApiParameterOperand(2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005710
5711 ExternalReference thunk_ref =
5712 ExternalReference::invoke_accessor_getter_callback(isolate());
5713
Ben Murdochc5610432016-08-08 18:44:38 +01005714 __ mov(scratch, FieldOperand(callback, AccessorInfo::kJsGetterOffset));
5715 Register function_address = edx;
5716 __ mov(function_address,
5717 FieldOperand(scratch, Foreign::kForeignAddressOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01005718 // +3 is to skip prolog, return address and name handle.
5719 Operand return_value_operand(
5720 ebp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize);
Ben Murdochc5610432016-08-08 18:44:38 +01005721 CallApiFunctionAndReturn(masm, function_address, thunk_ref, thunk_last_arg,
5722 kStackUnwindSpace, nullptr, return_value_operand,
5723 NULL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005724}
5725
Kristian Monsen80d68ea2010-09-08 11:05:35 +01005726#undef __
5727
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005728} // namespace internal
5729} // namespace v8
Kristian Monsen80d68ea2010-09-08 11:05:35 +01005730
5731#endif // V8_TARGET_ARCH_IA32