blob: b9757fa138ec2572df5b684b685b7499d5aa558a [file] [log] [blame]
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001// Copyright 2012 the V8 project authors. All rights reserved.
ager@chromium.org5c838252010-02-19 08:53:10 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#include "v8.h"
29
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +000030#if defined(V8_TARGET_ARCH_MIPS)
31
ager@chromium.org5c838252010-02-19 08:53:10 +000032#include "ic-inl.h"
karlklose@chromium.org83a47282011-05-11 11:54:09 +000033#include "codegen.h"
ager@chromium.org5c838252010-02-19 08:53:10 +000034#include "stub-cache.h"
35
36namespace v8 {
37namespace internal {
38
39#define __ ACCESS_MASM(masm)
40
41
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000042static void ProbeTable(Isolate* isolate,
43 MacroAssembler* masm,
44 Code::Flags flags,
45 StubCache::Table table,
fschneider@chromium.org35814e52012-03-01 15:43:35 +000046 Register receiver,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000047 Register name,
fschneider@chromium.org35814e52012-03-01 15:43:35 +000048 // Number of the cache entry, not scaled.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000049 Register offset,
50 Register scratch,
fschneider@chromium.org35814e52012-03-01 15:43:35 +000051 Register scratch2,
52 Register offset_scratch) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000053 ExternalReference key_offset(isolate->stub_cache()->key_reference(table));
54 ExternalReference value_offset(isolate->stub_cache()->value_reference(table));
fschneider@chromium.org35814e52012-03-01 15:43:35 +000055 ExternalReference map_offset(isolate->stub_cache()->map_reference(table));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000056
57 uint32_t key_off_addr = reinterpret_cast<uint32_t>(key_offset.address());
58 uint32_t value_off_addr = reinterpret_cast<uint32_t>(value_offset.address());
fschneider@chromium.org35814e52012-03-01 15:43:35 +000059 uint32_t map_off_addr = reinterpret_cast<uint32_t>(map_offset.address());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000060
61 // Check the relative positions of the address fields.
62 ASSERT(value_off_addr > key_off_addr);
63 ASSERT((value_off_addr - key_off_addr) % 4 == 0);
64 ASSERT((value_off_addr - key_off_addr) < (256 * 4));
fschneider@chromium.org35814e52012-03-01 15:43:35 +000065 ASSERT(map_off_addr > key_off_addr);
66 ASSERT((map_off_addr - key_off_addr) % 4 == 0);
67 ASSERT((map_off_addr - key_off_addr) < (256 * 4));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000068
69 Label miss;
fschneider@chromium.org35814e52012-03-01 15:43:35 +000070 Register base_addr = scratch;
71 scratch = no_reg;
72
73 // Multiply by 3 because there are 3 fields per entry (name, code, map).
74 __ sll(offset_scratch, offset, 1);
75 __ Addu(offset_scratch, offset_scratch, offset);
76
77 // Calculate the base address of the entry.
78 __ li(base_addr, Operand(key_offset));
79 __ sll(at, offset_scratch, kPointerSizeLog2);
80 __ Addu(base_addr, base_addr, at);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000081
82 // Check that the key in the entry matches the name.
fschneider@chromium.org35814e52012-03-01 15:43:35 +000083 __ lw(at, MemOperand(base_addr, 0));
84 __ Branch(&miss, ne, name, Operand(at));
85
86 // Check the map matches.
87 __ lw(at, MemOperand(base_addr, map_off_addr - key_off_addr));
88 __ lw(scratch2, FieldMemOperand(receiver, HeapObject::kMapOffset));
89 __ Branch(&miss, ne, at, Operand(scratch2));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000090
91 // Get the code entry from the cache.
fschneider@chromium.org35814e52012-03-01 15:43:35 +000092 Register code = scratch2;
93 scratch2 = no_reg;
94 __ lw(code, MemOperand(base_addr, value_off_addr - key_off_addr));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000095
96 // Check that the flags match what we're looking for.
fschneider@chromium.org35814e52012-03-01 15:43:35 +000097 Register flags_reg = base_addr;
98 base_addr = no_reg;
99 __ lw(flags_reg, FieldMemOperand(code, Code::kFlagsOffset));
100 __ And(flags_reg, flags_reg, Operand(~Code::kFlagsNotUsedInLookup));
101 __ Branch(&miss, ne, flags_reg, Operand(flags));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000102
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000103#ifdef DEBUG
104 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) {
105 __ jmp(&miss);
106 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) {
107 __ jmp(&miss);
108 }
109#endif
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000110
111 // Jump to the first instruction in the code stub.
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000112 __ Addu(at, code, Operand(Code::kHeaderSize - kHeapObjectTag));
113 __ Jump(at);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000114
115 // Miss: fall through.
116 __ bind(&miss);
117}
118
119
120// Helper function used to check that the dictionary doesn't contain
121// the property. This function may return false negatives, so miss_label
122// must always call a backup property check that is complete.
123// This function is safe to call if the receiver has fast properties.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000124// Name must be unique and receiver must be a heap object.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000125static void GenerateDictionaryNegativeLookup(MacroAssembler* masm,
126 Label* miss_label,
127 Register receiver,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000128 Handle<Name> name,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000129 Register scratch0,
130 Register scratch1) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000131 ASSERT(name->IsUniqueName());
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000132 Counters* counters = masm->isolate()->counters();
133 __ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1);
134 __ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
135
136 Label done;
137
138 const int kInterceptorOrAccessCheckNeededMask =
139 (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
140
141 // Bail out if the receiver has a named interceptor or requires access checks.
142 Register map = scratch1;
143 __ lw(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
144 __ lbu(scratch0, FieldMemOperand(map, Map::kBitFieldOffset));
145 __ And(scratch0, scratch0, Operand(kInterceptorOrAccessCheckNeededMask));
146 __ Branch(miss_label, ne, scratch0, Operand(zero_reg));
147
148 // Check that receiver is a JSObject.
149 __ lbu(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset));
150 __ Branch(miss_label, lt, scratch0, Operand(FIRST_SPEC_OBJECT_TYPE));
151
152 // Load properties array.
153 Register properties = scratch0;
154 __ lw(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
155 // Check that the properties array is a dictionary.
156 __ lw(map, FieldMemOperand(properties, HeapObject::kMapOffset));
157 Register tmp = properties;
158 __ LoadRoot(tmp, Heap::kHashTableMapRootIndex);
159 __ Branch(miss_label, ne, map, Operand(tmp));
160
161 // Restore the temporarily used register.
162 __ lw(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
163
164
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000165 NameDictionaryLookupStub::GenerateNegativeLookup(masm,
166 miss_label,
167 &done,
168 receiver,
169 properties,
170 name,
171 scratch1);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000172 __ bind(&done);
173 __ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
174}
175
176
ager@chromium.org5c838252010-02-19 08:53:10 +0000177void StubCache::GenerateProbe(MacroAssembler* masm,
178 Code::Flags flags,
179 Register receiver,
180 Register name,
181 Register scratch,
fschneider@chromium.orge03fb642010-11-01 12:34:09 +0000182 Register extra,
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000183 Register extra2,
184 Register extra3) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000185 Isolate* isolate = masm->isolate();
186 Label miss;
187
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000188 // Make sure that code is valid. The multiplying code relies on the
189 // entry size being 12.
190 ASSERT(sizeof(Entry) == 12);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000191
192 // Make sure the flags does not name a specific type.
193 ASSERT(Code::ExtractTypeFromFlags(flags) == 0);
194
195 // Make sure that there are no register conflicts.
196 ASSERT(!scratch.is(receiver));
197 ASSERT(!scratch.is(name));
198 ASSERT(!extra.is(receiver));
199 ASSERT(!extra.is(name));
200 ASSERT(!extra.is(scratch));
201 ASSERT(!extra2.is(receiver));
202 ASSERT(!extra2.is(name));
203 ASSERT(!extra2.is(scratch));
204 ASSERT(!extra2.is(extra));
205
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000206 // Check register validity.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000207 ASSERT(!scratch.is(no_reg));
208 ASSERT(!extra.is(no_reg));
209 ASSERT(!extra2.is(no_reg));
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000210 ASSERT(!extra3.is(no_reg));
211
212 Counters* counters = masm->isolate()->counters();
213 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1,
214 extra2, extra3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000215
216 // Check that the receiver isn't a smi.
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000217 __ JumpIfSmi(receiver, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000218
219 // Get the map of the receiver and compute the hash.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000220 __ lw(scratch, FieldMemOperand(name, Name::kHashFieldOffset));
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000221 __ lw(at, FieldMemOperand(receiver, HeapObject::kMapOffset));
222 __ Addu(scratch, scratch, at);
223 uint32_t mask = kPrimaryTableSize - 1;
224 // We shift out the last two bits because they are not part of the hash and
225 // they are always 01 for maps.
226 __ srl(scratch, scratch, kHeapObjectTagSize);
227 __ Xor(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask));
228 __ And(scratch, scratch, Operand(mask));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000229
230 // Probe the primary table.
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000231 ProbeTable(isolate,
232 masm,
233 flags,
234 kPrimary,
235 receiver,
236 name,
237 scratch,
238 extra,
239 extra2,
240 extra3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000241
242 // Primary miss: Compute hash for secondary probe.
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000243 __ srl(at, name, kHeapObjectTagSize);
244 __ Subu(scratch, scratch, at);
245 uint32_t mask2 = kSecondaryTableSize - 1;
246 __ Addu(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask2));
247 __ And(scratch, scratch, Operand(mask2));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000248
249 // Probe the secondary table.
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000250 ProbeTable(isolate,
251 masm,
252 flags,
253 kSecondary,
254 receiver,
255 name,
256 scratch,
257 extra,
258 extra2,
259 extra3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000260
261 // Cache miss: Fall-through and let caller handle the miss by
262 // entering the runtime system.
263 __ bind(&miss);
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000264 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1,
265 extra2, extra3);
ager@chromium.org5c838252010-02-19 08:53:10 +0000266}
267
268
269void StubCompiler::GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm,
270 int index,
271 Register prototype) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000272 // Load the global or builtins object from the current context.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000273 __ lw(prototype,
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000274 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
275 // Load the native context from the global or builtins object.
276 __ lw(prototype,
277 FieldMemOperand(prototype, GlobalObject::kNativeContextOffset));
278 // Load the function from the native context.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000279 __ lw(prototype, MemOperand(prototype, Context::SlotOffset(index)));
280 // Load the initial map. The global functions all have initial maps.
281 __ lw(prototype,
282 FieldMemOperand(prototype, JSFunction::kPrototypeOrInitialMapOffset));
283 // Load the prototype from the initial map.
284 __ lw(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
ager@chromium.org5c838252010-02-19 08:53:10 +0000285}
286
287
lrn@chromium.org7516f052011-03-30 08:52:27 +0000288void StubCompiler::GenerateDirectLoadGlobalFunctionPrototype(
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000289 MacroAssembler* masm,
290 int index,
291 Register prototype,
292 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000293 Isolate* isolate = masm->isolate();
294 // Check we're still in the same context.
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000295 __ lw(prototype,
296 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000297 ASSERT(!prototype.is(at));
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000298 __ li(at, isolate->global_object());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000299 __ Branch(miss, ne, prototype, Operand(at));
300 // Get the global function with the given index.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000301 Handle<JSFunction> function(
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000302 JSFunction::cast(isolate->native_context()->get(index)));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000303 // Load its initial map. The global functions all have initial maps.
304 __ li(prototype, Handle<Map>(function->initial_map()));
305 // Load the prototype from the initial map.
306 __ lw(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
lrn@chromium.org7516f052011-03-30 08:52:27 +0000307}
308
309
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000310void StubCompiler::DoGenerateFastPropertyLoad(MacroAssembler* masm,
311 Register dst,
312 Register src,
313 bool inobject,
314 int index) {
315 int offset = index * kPointerSize;
316 if (!inobject) {
317 // Calculate the offset into the properties array.
318 offset = offset + FixedArray::kHeaderSize;
319 __ lw(dst, FieldMemOperand(src, JSObject::kPropertiesOffset));
320 src = dst;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000321 }
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000322 __ lw(dst, FieldMemOperand(src, offset));
ager@chromium.org5c838252010-02-19 08:53:10 +0000323}
324
325
326void StubCompiler::GenerateLoadArrayLength(MacroAssembler* masm,
327 Register receiver,
328 Register scratch,
329 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000330 // Check that the receiver isn't a smi.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000331 __ JumpIfSmi(receiver, miss_label);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000332
333 // Check that the object is a JS array.
334 __ GetObjectType(receiver, scratch, scratch);
335 __ Branch(miss_label, ne, scratch, Operand(JS_ARRAY_TYPE));
336
337 // Load length directly from the JS array.
338 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
339 __ Ret();
340}
341
342
343// Generate code to check if an object is a string. If the object is a
344// heap object, its map's instance type is left in the scratch1 register.
345// If this is not needed, scratch1 and scratch2 may be the same register.
346static void GenerateStringCheck(MacroAssembler* masm,
347 Register receiver,
348 Register scratch1,
349 Register scratch2,
350 Label* smi,
351 Label* non_string_object) {
352 // Check that the receiver isn't a smi.
353 __ JumpIfSmi(receiver, smi, t0);
354
355 // Check that the object is a string.
356 __ lw(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset));
357 __ lbu(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
358 __ And(scratch2, scratch1, Operand(kIsNotStringMask));
359 // The cast is to resolve the overload for the argument of 0x0.
360 __ Branch(non_string_object,
361 ne,
362 scratch2,
363 Operand(static_cast<int32_t>(kStringTag)));
ager@chromium.org5c838252010-02-19 08:53:10 +0000364}
365
366
lrn@chromium.org7516f052011-03-30 08:52:27 +0000367// Generate code to load the length from a string object and return the length.
368// If the receiver object is not a string or a wrapped string object the
369// execution continues at the miss label. The register containing the
370// receiver is potentially clobbered.
371void StubCompiler::GenerateLoadStringLength(MacroAssembler* masm,
372 Register receiver,
373 Register scratch1,
374 Register scratch2,
375 Label* miss,
376 bool support_wrappers) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000377 Label check_wrapper;
378
379 // Check if the object is a string leaving the instance type in the
380 // scratch1 register.
381 GenerateStringCheck(masm, receiver, scratch1, scratch2, miss,
382 support_wrappers ? &check_wrapper : miss);
383
384 // Load length directly from the string.
385 __ lw(v0, FieldMemOperand(receiver, String::kLengthOffset));
386 __ Ret();
387
388 if (support_wrappers) {
389 // Check if the object is a JSValue wrapper.
390 __ bind(&check_wrapper);
391 __ Branch(miss, ne, scratch1, Operand(JS_VALUE_TYPE));
392
393 // Unwrap the value and check if the wrapped value is a string.
394 __ lw(scratch1, FieldMemOperand(receiver, JSValue::kValueOffset));
395 GenerateStringCheck(masm, scratch1, scratch2, scratch2, miss, miss);
396 __ lw(v0, FieldMemOperand(scratch1, String::kLengthOffset));
397 __ Ret();
398 }
lrn@chromium.org7516f052011-03-30 08:52:27 +0000399}
400
401
ager@chromium.org5c838252010-02-19 08:53:10 +0000402void StubCompiler::GenerateLoadFunctionPrototype(MacroAssembler* masm,
403 Register receiver,
404 Register scratch1,
405 Register scratch2,
406 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000407 __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
408 __ mov(v0, scratch1);
409 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +0000410}
411
412
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000413// Generate code to check that a global property cell is empty. Create
414// the property cell at compilation time if no cell exists for the
415// property.
416static void GenerateCheckPropertyCell(MacroAssembler* masm,
417 Handle<GlobalObject> global,
418 Handle<Name> name,
419 Register scratch,
420 Label* miss) {
421 Handle<JSGlobalPropertyCell> cell =
422 GlobalObject::EnsurePropertyCell(global, name);
423 ASSERT(cell->value()->IsTheHole());
424 __ li(scratch, Operand(cell));
425 __ lw(scratch,
426 FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset));
427 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
428 __ Branch(miss, ne, scratch, Operand(at));
429}
430
431
432// Generate StoreTransition code, value is passed in a0 register.
ager@chromium.org5c838252010-02-19 08:53:10 +0000433// After executing generated code, the receiver_reg and name_reg
434// may be clobbered.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000435void StubCompiler::GenerateStoreTransition(MacroAssembler* masm,
436 Handle<JSObject> object,
437 LookupResult* lookup,
438 Handle<Map> transition,
439 Handle<Name> name,
440 Register receiver_reg,
441 Register name_reg,
442 Register value_reg,
443 Register scratch1,
444 Register scratch2,
445 Label* miss_label,
446 Label* miss_restore_name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000447 // a0 : value.
448 Label exit;
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000449
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +0000450 // Check that the map of the object hasn't changed.
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000451 __ CheckMap(receiver_reg, scratch1, Handle<Map>(object->map()), miss_label,
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000452 DO_SMI_CHECK, REQUIRE_EXACT_MAP);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000453
454 // Perform global security token check if needed.
455 if (object->IsJSGlobalProxy()) {
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000456 __ CheckAccessGlobalProxy(receiver_reg, scratch1, miss_label);
457 }
458
459 // Check that we are allowed to write this.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000460 if (object->GetPrototype()->IsJSObject()) {
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000461 JSObject* holder;
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +0000462 // holder == object indicates that no property was found.
463 if (lookup->holder() != *object) {
464 holder = lookup->holder();
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000465 } else {
466 // Find the top object.
467 holder = *object;
468 do {
469 holder = JSObject::cast(holder->GetPrototype());
470 } while (holder->GetPrototype()->IsJSObject());
471 }
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +0000472 Register holder_reg = CheckPrototypes(
473 object, receiver_reg, Handle<JSObject>(holder), name_reg,
474 scratch1, scratch2, name, miss_restore_name);
475 // If no property was found, and the holder (the last object in the
476 // prototype chain) is in slow mode, we need to do a negative lookup on the
477 // holder.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000478 if (lookup->holder() == *object) {
479 if (holder->IsJSGlobalObject()) {
480 GenerateCheckPropertyCell(
481 masm,
482 Handle<GlobalObject>(GlobalObject::cast(holder)),
483 name,
484 scratch1,
485 miss_restore_name);
486 } else if (!holder->HasFastProperties() && !holder->IsJSGlobalProxy()) {
487 GenerateDictionaryNegativeLookup(
488 masm, miss_restore_name, holder_reg, name, scratch1, scratch2);
489 }
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +0000490 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000491 }
492
493 // Stub never generated for non-global objects that require access
494 // checks.
495 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
496
497 // Perform map transition for the receiver if necessary.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000498 if (object->map()->unused_property_fields() == 0) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000499 // The properties must be extended before we can store the value.
500 // We jump to a runtime call that extends the properties array.
501 __ push(receiver_reg);
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000502 __ li(a2, Operand(transition));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000503 __ Push(a2, a0);
504 __ TailCallExternalReference(
505 ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
506 masm->isolate()),
507 3, 1);
508 return;
509 }
510
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000511 // Update the map of the object.
512 __ li(scratch1, Operand(transition));
513 __ sw(scratch1, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
verwaest@chromium.org37141392012-05-31 13:27:02 +0000514
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000515 // Update the write barrier for the map field and pass the now unused
516 // name_reg as scratch register.
517 __ RecordWriteField(receiver_reg,
518 HeapObject::kMapOffset,
519 scratch1,
520 name_reg,
521 kRAHasNotBeenSaved,
522 kDontSaveFPRegs,
523 OMIT_REMEMBERED_SET,
524 OMIT_SMI_CHECK);
525
526 int index = transition->instance_descriptors()->GetFieldIndex(
527 transition->LastAdded());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000528
529 // Adjust for the number of properties stored in the object. Even in the
530 // face of a transition we can use the old map here because the size of the
531 // object and the number of in-object properties is not going to change.
532 index -= object->map()->inobject_properties();
533
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000534 // TODO(verwaest): Share this code as a code stub.
535 if (index < 0) {
536 // Set the property straight into the object.
537 int offset = object->map()->instance_size() + (index * kPointerSize);
538 __ sw(value_reg, FieldMemOperand(receiver_reg, offset));
539
540 // Skip updating write barrier if storing a smi.
541 __ JumpIfSmi(value_reg, &exit);
542
543 // Update the write barrier for the array address.
544 // Pass the now unused name_reg as a scratch register.
545 __ mov(name_reg, value_reg);
546 __ RecordWriteField(receiver_reg,
547 offset,
548 name_reg,
549 scratch1,
550 kRAHasNotBeenSaved,
551 kDontSaveFPRegs);
552 } else {
553 // Write to the properties array.
554 int offset = index * kPointerSize + FixedArray::kHeaderSize;
555 // Get the properties array
556 __ lw(scratch1,
557 FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
558 __ sw(value_reg, FieldMemOperand(scratch1, offset));
559
560 // Skip updating write barrier if storing a smi.
561 __ JumpIfSmi(value_reg, &exit);
562
563 // Update the write barrier for the array address.
564 // Ok to clobber receiver_reg and name_reg, since we return.
565 __ mov(name_reg, value_reg);
566 __ RecordWriteField(scratch1,
567 offset,
568 name_reg,
569 receiver_reg,
570 kRAHasNotBeenSaved,
571 kDontSaveFPRegs);
572 }
573
574 // Return the value (register v0).
575 ASSERT(value_reg.is(a0));
576 __ bind(&exit);
577 __ mov(v0, a0);
578 __ Ret();
579}
580
581
582// Generate StoreField code, value is passed in a0 register.
583// When leaving generated code after success, the receiver_reg and name_reg
584// may be clobbered. Upon branch to miss_label, the receiver and name
585// registers have their original values.
586void StubCompiler::GenerateStoreField(MacroAssembler* masm,
587 Handle<JSObject> object,
588 LookupResult* lookup,
589 Register receiver_reg,
590 Register name_reg,
591 Register value_reg,
592 Register scratch1,
593 Register scratch2,
594 Label* miss_label) {
595 // a0 : value
596 Label exit;
597
598 // Check that the map of the object hasn't changed.
599 __ CheckMap(receiver_reg, scratch1, Handle<Map>(object->map()), miss_label,
600 DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS);
601
602 // Perform global security token check if needed.
603 if (object->IsJSGlobalProxy()) {
604 __ CheckAccessGlobalProxy(receiver_reg, scratch1, miss_label);
605 }
606
607 // Stub never generated for non-global objects that require access
608 // checks.
609 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
610
611 int index = lookup->GetFieldIndex().field_index();
612
613 // Adjust for the number of properties stored in the object. Even in the
614 // face of a transition we can use the old map here because the size of the
615 // object and the number of in-object properties is not going to change.
616 index -= object->map()->inobject_properties();
617
618 // TODO(verwaest): Share this code as a code stub.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000619 if (index < 0) {
620 // Set the property straight into the object.
621 int offset = object->map()->instance_size() + (index * kPointerSize);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000622 __ sw(value_reg, FieldMemOperand(receiver_reg, offset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000623
624 // Skip updating write barrier if storing a smi.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000625 __ JumpIfSmi(value_reg, &exit);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000626
627 // Update the write barrier for the array address.
628 // Pass the now unused name_reg as a scratch register.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000629 __ mov(name_reg, value_reg);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000630 __ RecordWriteField(receiver_reg,
631 offset,
632 name_reg,
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000633 scratch1,
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000634 kRAHasNotBeenSaved,
635 kDontSaveFPRegs);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000636 } else {
637 // Write to the properties array.
638 int offset = index * kPointerSize + FixedArray::kHeaderSize;
639 // Get the properties array.
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000640 __ lw(scratch1,
641 FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000642 __ sw(value_reg, FieldMemOperand(scratch1, offset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000643
644 // Skip updating write barrier if storing a smi.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000645 __ JumpIfSmi(value_reg, &exit);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000646
647 // Update the write barrier for the array address.
648 // Ok to clobber receiver_reg and name_reg, since we return.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000649 __ mov(name_reg, value_reg);
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000650 __ RecordWriteField(scratch1,
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000651 offset,
652 name_reg,
653 receiver_reg,
654 kRAHasNotBeenSaved,
655 kDontSaveFPRegs);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000656 }
657
658 // Return the value (register v0).
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000659 ASSERT(value_reg.is(a0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000660 __ bind(&exit);
661 __ mov(v0, a0);
662 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +0000663}
664
665
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000666void BaseStoreStubCompiler::GenerateRestoreName(MacroAssembler* masm,
667 Label* label,
668 Handle<Name> name) {
669 if (!label->is_unused()) {
670 __ bind(label);
671 __ li(this->name(), Operand(name));
672 }
mstarzinger@chromium.org068ea0a2013-01-30 09:39:44 +0000673}
674
675
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000676static void GenerateCallFunction(MacroAssembler* masm,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000677 Handle<Object> object,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000678 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000679 Label* miss,
680 Code::ExtraICState extra_ic_state) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000681 // ----------- S t a t e -------------
682 // -- a0: receiver
683 // -- a1: function to call
684 // -----------------------------------
685 // Check that the function really is a function.
686 __ JumpIfSmi(a1, miss);
687 __ GetObjectType(a1, a3, a3);
688 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
689
690 // Patch the receiver on the stack with the global proxy if
691 // necessary.
692 if (object->IsGlobalObject()) {
693 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
694 __ sw(a3, MemOperand(sp, arguments.immediate() * kPointerSize));
695 }
696
697 // Invoke the function.
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000698 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state)
699 ? CALL_AS_FUNCTION
700 : CALL_AS_METHOD;
701 __ InvokeFunction(a1, arguments, JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000702}
703
704
705static void PushInterceptorArguments(MacroAssembler* masm,
706 Register receiver,
707 Register holder,
708 Register name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000709 Handle<JSObject> holder_obj) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000710 __ push(name);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000711 Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
712 ASSERT(!masm->isolate()->heap()->InNewSpace(*interceptor));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000713 Register scratch = name;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000714 __ li(scratch, Operand(interceptor));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000715 __ Push(scratch, receiver, holder);
716 __ lw(scratch, FieldMemOperand(scratch, InterceptorInfo::kDataOffset));
717 __ push(scratch);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000718 __ li(scratch, Operand(ExternalReference::isolate_address()));
719 __ push(scratch);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000720}
721
722
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000723static void CompileCallLoadPropertyWithInterceptor(
724 MacroAssembler* masm,
725 Register receiver,
726 Register holder,
727 Register name,
728 Handle<JSObject> holder_obj) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000729 PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
730
731 ExternalReference ref =
732 ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorOnly),
733 masm->isolate());
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000734 __ PrepareCEntryArgs(6);
ulan@chromium.org6ff65142012-03-21 09:52:17 +0000735 __ PrepareCEntryFunction(ref);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000736
737 CEntryStub stub(1);
738 __ CallStub(&stub);
739}
740
741
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000742static const int kFastApiCallArguments = 4;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000743
744
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000745// Reserves space for the extra arguments to API function in the
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000746// caller's frame.
747//
748// These arguments are set by CheckPrototypes and GenerateFastApiDirectCall.
749static void ReserveSpaceForFastApiCall(MacroAssembler* masm,
750 Register scratch) {
751 ASSERT(Smi::FromInt(0) == 0);
752 for (int i = 0; i < kFastApiCallArguments; i++) {
753 __ push(zero_reg);
754 }
755}
756
757
758// Undoes the effects of ReserveSpaceForFastApiCall.
759static void FreeSpaceForFastApiCall(MacroAssembler* masm) {
760 __ Drop(kFastApiCallArguments);
761}
762
763
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000764static void GenerateFastApiDirectCall(MacroAssembler* masm,
765 const CallOptimization& optimization,
766 int argc) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000767 // ----------- S t a t e -------------
768 // -- sp[0] : holder (set by CheckPrototypes)
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000769 // -- sp[4] : callee JS function
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000770 // -- sp[8] : call data
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000771 // -- sp[12] : isolate
772 // -- sp[16] : last JS argument
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000773 // -- ...
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000774 // -- sp[(argc + 3) * 4] : first JS argument
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000775 // -- sp[(argc + 4) * 4] : receiver
776 // -----------------------------------
777 // Get the function and setup the context.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000778 Handle<JSFunction> function = optimization.constant_function();
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000779 __ LoadHeapObject(t1, function);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000780 __ lw(cp, FieldMemOperand(t1, JSFunction::kContextOffset));
781
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000782 // Pass the additional arguments.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000783 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
ulan@chromium.org09d7ab52013-02-25 15:50:35 +0000784 Handle<Object> call_data(api_call_info->data(), masm->isolate());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000785 if (masm->isolate()->heap()->InNewSpace(*call_data)) {
786 __ li(a0, api_call_info);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000787 __ lw(t2, FieldMemOperand(a0, CallHandlerInfo::kDataOffset));
788 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000789 __ li(t2, call_data);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000790 }
791
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000792 __ li(t3, Operand(ExternalReference::isolate_address()));
793 // Store JS function, call data and isolate.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000794 __ sw(t1, MemOperand(sp, 1 * kPointerSize));
795 __ sw(t2, MemOperand(sp, 2 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000796 __ sw(t3, MemOperand(sp, 3 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000797
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000798 // Prepare arguments.
799 __ Addu(a2, sp, Operand(3 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000800
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000801 // Allocate the v8::Arguments structure in the arguments' space since
802 // it's not controlled by GC.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000803 const int kApiStackSpace = 4;
804
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000805 FrameScope frame_scope(masm, StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000806 __ EnterExitFrame(false, kApiStackSpace);
807
808 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
809 // struct from the function (which is currently the case). This means we pass
810 // the first argument in a1 instead of a0. TryCallApiFunctionAndReturn
811 // will handle setting up a0.
812
813 // a1 = v8::Arguments&
814 // Arguments is built at sp + 1 (sp is a reserved spot for ra).
815 __ Addu(a1, sp, kPointerSize);
816
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000817 // v8::Arguments::implicit_args_
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000818 __ sw(a2, MemOperand(a1, 0 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000819 // v8::Arguments::values_
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000820 __ Addu(t0, a2, Operand(argc * kPointerSize));
821 __ sw(t0, MemOperand(a1, 1 * kPointerSize));
822 // v8::Arguments::length_ = argc
823 __ li(t0, Operand(argc));
824 __ sw(t0, MemOperand(a1, 2 * kPointerSize));
825 // v8::Arguments::is_construct_call = 0
826 __ sw(zero_reg, MemOperand(a1, 3 * kPointerSize));
827
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000828 const int kStackUnwindSpace = argc + kFastApiCallArguments + 1;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000829 Address function_address = v8::ToCData<Address>(api_call_info->callback());
830 ApiFunction fun(function_address);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000831 ExternalReference ref =
832 ExternalReference(&fun,
833 ExternalReference::DIRECT_API_CALL,
834 masm->isolate());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000835 AllowExternalCallThatCantCauseGC scope(masm);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000836 __ CallApiFunctionAndReturn(ref, kStackUnwindSpace);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000837}
838
lrn@chromium.org7516f052011-03-30 08:52:27 +0000839class CallInterceptorCompiler BASE_EMBEDDED {
840 public:
841 CallInterceptorCompiler(StubCompiler* stub_compiler,
842 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000843 Register name,
844 Code::ExtraICState extra_ic_state)
lrn@chromium.org7516f052011-03-30 08:52:27 +0000845 : stub_compiler_(stub_compiler),
846 arguments_(arguments),
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000847 name_(name),
848 extra_ic_state_(extra_ic_state) {}
lrn@chromium.org7516f052011-03-30 08:52:27 +0000849
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000850 void Compile(MacroAssembler* masm,
851 Handle<JSObject> object,
852 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000853 Handle<Name> name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000854 LookupResult* lookup,
855 Register receiver,
856 Register scratch1,
857 Register scratch2,
858 Register scratch3,
859 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000860 ASSERT(holder->HasNamedInterceptor());
861 ASSERT(!holder->GetNamedInterceptor()->getter()->IsUndefined());
862
863 // Check that the receiver isn't a smi.
864 __ JumpIfSmi(receiver, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000865 CallOptimization optimization(lookup);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000866 if (optimization.is_constant_call()) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000867 CompileCacheable(masm, object, receiver, scratch1, scratch2, scratch3,
868 holder, lookup, name, optimization, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000869 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000870 CompileRegular(masm, object, receiver, scratch1, scratch2, scratch3,
871 name, holder, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000872 }
873 }
874
875 private:
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000876 void CompileCacheable(MacroAssembler* masm,
877 Handle<JSObject> object,
878 Register receiver,
879 Register scratch1,
880 Register scratch2,
881 Register scratch3,
882 Handle<JSObject> interceptor_holder,
883 LookupResult* lookup,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000884 Handle<Name> name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000885 const CallOptimization& optimization,
886 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000887 ASSERT(optimization.is_constant_call());
888 ASSERT(!lookup->holder()->IsGlobalObject());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000889 Counters* counters = masm->isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000890 int depth1 = kInvalidProtoDepth;
891 int depth2 = kInvalidProtoDepth;
892 bool can_do_fast_api_call = false;
893 if (optimization.is_simple_api_call() &&
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000894 !lookup->holder()->IsGlobalObject()) {
895 depth1 = optimization.GetPrototypeDepthOfExpectedType(
896 object, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000897 if (depth1 == kInvalidProtoDepth) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000898 depth2 = optimization.GetPrototypeDepthOfExpectedType(
899 interceptor_holder, Handle<JSObject>(lookup->holder()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000900 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000901 can_do_fast_api_call =
902 depth1 != kInvalidProtoDepth || depth2 != kInvalidProtoDepth;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000903 }
904
905 __ IncrementCounter(counters->call_const_interceptor(), 1,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000906 scratch1, scratch2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000907
908 if (can_do_fast_api_call) {
909 __ IncrementCounter(counters->call_const_interceptor_fast_api(), 1,
910 scratch1, scratch2);
911 ReserveSpaceForFastApiCall(masm, scratch1);
912 }
913
914 // Check that the maps from receiver to interceptor's holder
915 // haven't changed and thus we can invoke interceptor.
916 Label miss_cleanup;
917 Label* miss = can_do_fast_api_call ? &miss_cleanup : miss_label;
918 Register holder =
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000919 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
920 scratch1, scratch2, scratch3,
921 name, depth1, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000922
923 // Invoke an interceptor and if it provides a value,
924 // branch to |regular_invoke|.
925 Label regular_invoke;
926 LoadWithInterceptor(masm, receiver, holder, interceptor_holder, scratch2,
927 &regular_invoke);
928
929 // Interceptor returned nothing for this property. Try to use cached
930 // constant function.
931
932 // Check that the maps from interceptor's holder to constant function's
933 // holder haven't changed and thus we can use cached constant function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000934 if (*interceptor_holder != lookup->holder()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000935 stub_compiler_->CheckPrototypes(interceptor_holder, receiver,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000936 Handle<JSObject>(lookup->holder()),
937 scratch1, scratch2, scratch3,
938 name, depth2, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000939 } else {
940 // CheckPrototypes has a side effect of fetching a 'holder'
941 // for API (object which is instanceof for the signature). It's
942 // safe to omit it here, as if present, it should be fetched
943 // by the previous CheckPrototypes.
944 ASSERT(depth2 == kInvalidProtoDepth);
945 }
946
947 // Invoke function.
948 if (can_do_fast_api_call) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000949 GenerateFastApiDirectCall(masm, optimization, arguments_.immediate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000950 } else {
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000951 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state_)
952 ? CALL_AS_FUNCTION
953 : CALL_AS_METHOD;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000954 __ InvokeFunction(optimization.constant_function(), arguments_,
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +0000955 JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000956 }
957
958 // Deferred code for fast API call case---clean preallocated space.
959 if (can_do_fast_api_call) {
960 __ bind(&miss_cleanup);
961 FreeSpaceForFastApiCall(masm);
962 __ Branch(miss_label);
963 }
964
965 // Invoke a regular function.
966 __ bind(&regular_invoke);
967 if (can_do_fast_api_call) {
968 FreeSpaceForFastApiCall(masm);
969 }
lrn@chromium.org7516f052011-03-30 08:52:27 +0000970 }
971
972 void CompileRegular(MacroAssembler* masm,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000973 Handle<JSObject> object,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000974 Register receiver,
975 Register scratch1,
976 Register scratch2,
977 Register scratch3,
ulan@chromium.org6e196bf2013-03-13 09:38:22 +0000978 Handle<Name> name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000979 Handle<JSObject> interceptor_holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000980 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000981 Register holder =
982 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000983 scratch1, scratch2, scratch3,
984 name, miss_label);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000985
986 // Call a runtime function to load the interceptor property.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000987 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000988 // Save the name_ register across the call.
989 __ push(name_);
990
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000991 PushInterceptorArguments(masm, receiver, holder, name_, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000992
993 __ CallExternalReference(
994 ExternalReference(
995 IC_Utility(IC::kLoadPropertyWithInterceptorForCall),
996 masm->isolate()),
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000997 6);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000998 // Restore the name_ register.
999 __ pop(name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001000 // Leave the internal frame.
lrn@chromium.org7516f052011-03-30 08:52:27 +00001001 }
1002
1003 void LoadWithInterceptor(MacroAssembler* masm,
1004 Register receiver,
1005 Register holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001006 Handle<JSObject> holder_obj,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001007 Register scratch,
1008 Label* interceptor_succeeded) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001009 {
1010 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001011
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001012 __ Push(holder, name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001013 CompileCallLoadPropertyWithInterceptor(masm,
1014 receiver,
1015 holder,
1016 name_,
1017 holder_obj);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001018 __ pop(name_); // Restore the name.
1019 __ pop(receiver); // Restore the holder.
1020 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001021 // If interceptor returns no-result sentinel, call the constant function.
1022 __ LoadRoot(scratch, Heap::kNoInterceptorResultSentinelRootIndex);
1023 __ Branch(interceptor_succeeded, ne, v0, Operand(scratch));
lrn@chromium.org7516f052011-03-30 08:52:27 +00001024 }
1025
1026 StubCompiler* stub_compiler_;
1027 const ParameterCount& arguments_;
1028 Register name_;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00001029 Code::ExtraICState extra_ic_state_;
lrn@chromium.org7516f052011-03-30 08:52:27 +00001030};
1031
1032
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001033// Calls GenerateCheckPropertyCell for each global object in the prototype chain
1034// from object to (but not including) holder.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001035static void GenerateCheckPropertyCells(MacroAssembler* masm,
1036 Handle<JSObject> object,
1037 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001038 Handle<Name> name,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001039 Register scratch,
1040 Label* miss) {
1041 Handle<JSObject> current = object;
1042 while (!current.is_identical_to(holder)) {
1043 if (current->IsGlobalObject()) {
1044 GenerateCheckPropertyCell(masm,
1045 Handle<GlobalObject>::cast(current),
1046 name,
1047 scratch,
1048 miss);
1049 }
1050 current = Handle<JSObject>(JSObject::cast(current->GetPrototype()));
1051 }
1052}
1053
1054
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001055// Convert and store int passed in register ival to IEEE 754 single precision
1056// floating point value at memory location (dst + 4 * wordoffset)
1057// If FPU is available use it for conversion.
1058static void StoreIntAsFloat(MacroAssembler* masm,
1059 Register dst,
1060 Register wordoffset,
1061 Register ival,
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00001062 Register scratch1) {
1063 __ mtc1(ival, f0);
1064 __ cvt_s_w(f0, f0);
1065 __ sll(scratch1, wordoffset, 2);
1066 __ addu(scratch1, dst, scratch1);
1067 __ swc1(f0, MemOperand(scratch1, 0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001068}
1069
1070
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00001071void StubCompiler::GenerateTailCall(MacroAssembler* masm, Handle<Code> code) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001072 __ Jump(code, RelocInfo::CODE_TARGET);
1073}
1074
1075
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00001076#undef __
1077#define __ ACCESS_MASM(masm())
1078
1079
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001080Register StubCompiler::CheckPrototypes(Handle<JSObject> object,
1081 Register object_reg,
1082 Handle<JSObject> holder,
1083 Register holder_reg,
1084 Register scratch1,
1085 Register scratch2,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001086 Handle<Name> name,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001087 int save_at_depth,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001088 Label* miss,
1089 PrototypeCheckType check) {
1090 Handle<JSObject> first = object;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001091 // Make sure there's no overlap between holder and object registers.
1092 ASSERT(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
1093 ASSERT(!scratch2.is(object_reg) && !scratch2.is(holder_reg)
1094 && !scratch2.is(scratch1));
1095
1096 // Keep track of the current object in register reg.
1097 Register reg = object_reg;
1098 int depth = 0;
1099
1100 if (save_at_depth == depth) {
1101 __ sw(reg, MemOperand(sp));
1102 }
1103
1104 // Check the maps in the prototype chain.
1105 // Traverse the prototype chain from the object and do map checks.
1106 Handle<JSObject> current = object;
1107 while (!current.is_identical_to(holder)) {
1108 ++depth;
1109
1110 // Only global objects and objects that do not require access
1111 // checks are allowed in stubs.
1112 ASSERT(current->IsJSGlobalProxy() || !current->IsAccessCheckNeeded());
1113
1114 Handle<JSObject> prototype(JSObject::cast(current->GetPrototype()));
1115 if (!current->HasFastProperties() &&
1116 !current->IsJSGlobalObject() &&
1117 !current->IsJSGlobalProxy()) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001118 if (!name->IsUniqueName()) {
1119 ASSERT(name->IsString());
1120 name = factory()->InternalizeString(Handle<String>::cast(name));
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001121 }
1122 ASSERT(current->property_dictionary()->FindEntry(*name) ==
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001123 NameDictionary::kNotFound);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001124
1125 GenerateDictionaryNegativeLookup(masm(), miss, reg, name,
1126 scratch1, scratch2);
1127
1128 __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
1129 reg = holder_reg; // From now on the object will be in holder_reg.
1130 __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
1131 } else {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001132 Register map_reg = scratch1;
1133 if (!current.is_identical_to(first) || check == CHECK_ALL_MAPS) {
1134 Handle<Map> current_map(current->map());
1135 // CheckMap implicitly loads the map of |reg| into |map_reg|.
1136 __ CheckMap(reg, map_reg, current_map, miss, DONT_DO_SMI_CHECK,
1137 ALLOW_ELEMENT_TRANSITION_MAPS);
1138 } else {
1139 __ lw(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
1140 }
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001141 // Check access rights to the global object. This has to happen after
1142 // the map check so that we know that the object is actually a global
1143 // object.
1144 if (current->IsJSGlobalProxy()) {
1145 __ CheckAccessGlobalProxy(reg, scratch2, miss);
1146 }
1147 reg = holder_reg; // From now on the object will be in holder_reg.
1148
1149 if (heap()->InNewSpace(*prototype)) {
1150 // The prototype is in new space; we cannot store a reference to it
1151 // in the code. Load it from the map.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001152 __ lw(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset));
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001153 } else {
1154 // The prototype is in old space; load it directly.
1155 __ li(reg, Operand(prototype));
1156 }
1157 }
1158
1159 if (save_at_depth == depth) {
1160 __ sw(reg, MemOperand(sp));
1161 }
1162
1163 // Go to the next object in the prototype chain.
1164 current = prototype;
1165 }
1166
1167 // Log the check depth.
1168 LOG(masm()->isolate(), IntEvent("check-maps-depth", depth + 1));
1169
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001170 if (!holder.is_identical_to(first) || check == CHECK_ALL_MAPS) {
1171 // Check the holder map.
1172 __ CheckMap(reg, scratch1, Handle<Map>(holder->map()), miss,
1173 DONT_DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS);
1174 }
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001175
1176 // Perform security check for access to the global object.
1177 ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded());
1178 if (holder->IsJSGlobalProxy()) {
1179 __ CheckAccessGlobalProxy(reg, scratch1, miss);
1180 }
1181
1182 // If we've skipped any global objects, it's not enough to verify that
1183 // their maps haven't changed. We also need to check that the property
1184 // cell for the property is still empty.
1185 GenerateCheckPropertyCells(masm(), object, holder, name, scratch1, miss);
1186
1187 // Return the register containing the holder.
1188 return reg;
1189}
1190
1191
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001192void BaseLoadStubCompiler::HandlerFrontendFooter(Label* success,
1193 Label* miss) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001194 if (!miss->is_unused()) {
1195 __ Branch(success);
1196 __ bind(miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00001197 TailCallBuiltin(masm(), MissBuiltin(kind()));
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001198 }
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001199}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001200
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001201
1202Register BaseLoadStubCompiler::CallbackHandlerFrontend(
1203 Handle<JSObject> object,
1204 Register object_reg,
1205 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001206 Handle<Name> name,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001207 Label* success,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001208 Handle<ExecutableAccessorInfo> callback) {
1209 Label miss;
1210
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001211 Register reg = HandlerFrontendHeader(object, object_reg, holder, name, &miss);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001212
1213 if (!holder->HasFastProperties() && !holder->IsJSGlobalObject()) {
1214 ASSERT(!reg.is(scratch2()));
1215 ASSERT(!reg.is(scratch3()));
1216 ASSERT(!reg.is(scratch4()));
1217
1218 // Load the properties dictionary.
1219 Register dictionary = scratch4();
1220 __ lw(dictionary, FieldMemOperand(reg, JSObject::kPropertiesOffset));
1221
1222 // Probe the dictionary.
1223 Label probe_done;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001224 NameDictionaryLookupStub::GeneratePositiveLookup(masm(),
1225 &miss,
1226 &probe_done,
1227 dictionary,
1228 this->name(),
1229 scratch2(),
1230 scratch3());
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001231 __ bind(&probe_done);
1232
1233 // If probing finds an entry in the dictionary, scratch3 contains the
1234 // pointer into the dictionary. Check that the value is the callback.
1235 Register pointer = scratch3();
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001236 const int kElementsStartOffset = NameDictionary::kHeaderSize +
1237 NameDictionary::kElementsStartIndex * kPointerSize;
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001238 const int kValueOffset = kElementsStartOffset + kPointerSize;
1239 __ lw(scratch2(), FieldMemOperand(pointer, kValueOffset));
1240 __ Branch(&miss, ne, scratch2(), Operand(callback));
1241 }
1242
1243 HandlerFrontendFooter(success, &miss);
1244 return reg;
1245}
1246
1247
1248void BaseLoadStubCompiler::NonexistentHandlerFrontend(
1249 Handle<JSObject> object,
1250 Handle<JSObject> last,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001251 Handle<Name> name,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001252 Label* success,
1253 Handle<GlobalObject> global) {
1254 Label miss;
1255
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00001256 HandlerFrontendHeader(object, receiver(), last, name, &miss);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001257
1258 // If the last object in the prototype chain is a global object,
1259 // check that the global property cell is empty.
1260 if (!global.is_null()) {
1261 GenerateCheckPropertyCell(masm(), global, name, scratch2(), &miss);
1262 }
1263
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001264 HandlerFrontendFooter(success, &miss);
1265}
1266
1267
1268void BaseLoadStubCompiler::GenerateLoadField(Register reg,
1269 Handle<JSObject> holder,
1270 PropertyIndex index) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001271 GenerateFastPropertyLoad(masm(), v0, reg, holder, index);
1272 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +00001273}
1274
1275
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001276void BaseLoadStubCompiler::GenerateLoadConstant(Handle<JSFunction> value) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001277 // Return the constant value.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001278 __ LoadHeapObject(v0, value);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001279 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +00001280}
1281
1282
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001283void BaseLoadStubCompiler::GenerateLoadCallback(
1284 Register reg,
1285 Handle<ExecutableAccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001286 // Build AccessorInfo::args_ list on the stack and push property name below
1287 // the exit frame to make GC aware of them and store pointers to them.
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001288 __ push(receiver());
1289 __ mov(scratch2(), sp); // scratch2 = AccessorInfo::args_
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001290 if (heap()->InNewSpace(callback->data())) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001291 __ li(scratch3(), callback);
1292 __ lw(scratch3(), FieldMemOperand(scratch3(),
1293 ExecutableAccessorInfo::kDataOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001294 } else {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001295 __ li(scratch3(), Handle<Object>(callback->data(),
1296 callback->GetIsolate()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001297 }
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001298 __ Subu(sp, sp, 4 * kPointerSize);
1299 __ sw(reg, MemOperand(sp, 3 * kPointerSize));
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001300 __ sw(scratch3(), MemOperand(sp, 2 * kPointerSize));
1301 __ li(scratch3(), Operand(ExternalReference::isolate_address()));
1302 __ sw(scratch3(), MemOperand(sp, 1 * kPointerSize));
1303 __ sw(name(), MemOperand(sp, 0 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001304
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001305 __ mov(a2, scratch2()); // Saved in case scratch2 == a1.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001306 __ mov(a1, sp); // a1 (first argument - see note below) = Handle<Name>
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001307
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001308 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
1309 // struct from the function (which is currently the case). This means we pass
1310 // the arguments in a1-a2 instead of a0-a1. TryCallApiFunctionAndReturn
1311 // will handle setting up a0.
1312
1313 const int kApiStackSpace = 1;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001314 FrameScope frame_scope(masm(), StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001315 __ EnterExitFrame(false, kApiStackSpace);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001316
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001317 // Create AccessorInfo instance on the stack above the exit frame with
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001318 // scratch2 (internal::Object** args_) as the data.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001319 __ sw(a2, MemOperand(sp, kPointerSize));
1320 // a2 (second argument - see note above) = AccessorInfo&
1321 __ Addu(a2, sp, kPointerSize);
1322
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001323 const int kStackUnwindSpace = 5;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001324 Address getter_address = v8::ToCData<Address>(callback->getter());
1325 ApiFunction fun(getter_address);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001326 ExternalReference ref =
1327 ExternalReference(&fun,
1328 ExternalReference::DIRECT_GETTER_CALL,
1329 masm()->isolate());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001330 __ CallApiFunctionAndReturn(ref, kStackUnwindSpace);
ager@chromium.org5c838252010-02-19 08:53:10 +00001331}
1332
1333
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001334void BaseLoadStubCompiler::GenerateLoadInterceptor(
1335 Register holder_reg,
1336 Handle<JSObject> object,
1337 Handle<JSObject> interceptor_holder,
1338 LookupResult* lookup,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001339 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001340 ASSERT(interceptor_holder->HasNamedInterceptor());
1341 ASSERT(!interceptor_holder->GetNamedInterceptor()->getter()->IsUndefined());
1342
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001343 // So far the most popular follow ups for interceptor loads are FIELD
1344 // and CALLBACKS, so inline only them, other cases may be added
1345 // later.
1346 bool compile_followup_inline = false;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001347 if (lookup->IsFound() && lookup->IsCacheable()) {
yangguo@chromium.orgde0db002012-06-22 13:44:28 +00001348 if (lookup->IsField()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001349 compile_followup_inline = true;
1350 } else if (lookup->type() == CALLBACKS &&
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00001351 lookup->GetCallbackObject()->IsExecutableAccessorInfo()) {
1352 ExecutableAccessorInfo* callback =
1353 ExecutableAccessorInfo::cast(lookup->GetCallbackObject());
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001354 compile_followup_inline = callback->getter() != NULL &&
1355 callback->IsCompatibleReceiver(*object);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001356 }
1357 }
1358
1359 if (compile_followup_inline) {
1360 // Compile the interceptor call, followed by inline code to load the
1361 // property from further up the prototype chain if the call fails.
1362 // Check that the maps haven't changed.
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001363 ASSERT(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001364
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001365 // Preserve the receiver register explicitly whenever it is different from
1366 // the holder and it is needed should the interceptor return without any
1367 // result. The CALLBACKS case needs the receiver to be passed into C++ code,
1368 // the FIELD case might cause a miss during the prototype check.
1369 bool must_perfrom_prototype_check = *interceptor_holder != lookup->holder();
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001370 bool must_preserve_receiver_reg = !receiver().is(holder_reg) &&
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001371 (lookup->type() == CALLBACKS || must_perfrom_prototype_check);
1372
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001373 // Save necessary data before invoking an interceptor.
1374 // Requires a frame to make GC aware of pushed pointers.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001375 {
1376 FrameScope frame_scope(masm(), StackFrame::INTERNAL);
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001377 if (must_preserve_receiver_reg) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001378 __ Push(receiver(), holder_reg, this->name());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001379 } else {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001380 __ Push(holder_reg, this->name());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001381 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001382 // Invoke an interceptor. Note: map checks from receiver to
1383 // interceptor's holder has been compiled before (see a caller
1384 // of this method).
1385 CompileCallLoadPropertyWithInterceptor(masm(),
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001386 receiver(),
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001387 holder_reg,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001388 this->name(),
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001389 interceptor_holder);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001390 // Check if interceptor provided a value for property. If it's
1391 // the case, return immediately.
1392 Label interceptor_failed;
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001393 __ LoadRoot(scratch1(), Heap::kNoInterceptorResultSentinelRootIndex);
1394 __ Branch(&interceptor_failed, eq, v0, Operand(scratch1()));
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001395 frame_scope.GenerateLeaveFrame();
1396 __ Ret();
1397
1398 __ bind(&interceptor_failed);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001399 __ pop(this->name());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001400 __ pop(holder_reg);
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001401 if (must_preserve_receiver_reg) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001402 __ pop(receiver());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001403 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001404 // Leave the internal frame.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001405 }
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001406 GenerateLoadPostInterceptor(holder_reg, interceptor_holder, name, lookup);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001407 } else { // !compile_followup_inline
1408 // Call the runtime system to load the interceptor.
1409 // Check that the maps haven't changed.
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001410 PushInterceptorArguments(masm(), receiver(), holder_reg,
1411 this->name(), interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001412
1413 ExternalReference ref = ExternalReference(
1414 IC_Utility(IC::kLoadPropertyWithInterceptorForLoad), masm()->isolate());
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001415 __ TailCallExternalReference(ref, 6, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001416 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001417}
1418
1419
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001420void CallStubCompiler::GenerateNameCheck(Handle<Name> name, Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001421 if (kind_ == Code::KEYED_CALL_IC) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001422 __ Branch(miss, ne, a2, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001423 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001424}
1425
1426
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001427void CallStubCompiler::GenerateGlobalReceiverCheck(Handle<JSObject> object,
1428 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001429 Handle<Name> name,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001430 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001431 ASSERT(holder->IsGlobalObject());
1432
1433 // Get the number of arguments.
1434 const int argc = arguments().immediate();
1435
1436 // Get the receiver from the stack.
1437 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1438
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001439 // Check that the maps haven't changed.
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00001440 __ JumpIfSmi(a0, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001441 CheckPrototypes(object, a0, holder, a3, a1, t0, name, miss);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001442}
1443
1444
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001445void CallStubCompiler::GenerateLoadFunctionFromCell(
1446 Handle<JSGlobalPropertyCell> cell,
1447 Handle<JSFunction> function,
1448 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001449 // Get the value from the cell.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001450 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001451 __ lw(a1, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
1452
1453 // Check that the cell contains the same function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001454 if (heap()->InNewSpace(*function)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001455 // We can't embed a pointer to a function in new space so we have
1456 // to verify that the shared function info is unchanged. This has
1457 // the nice side effect that multiple closures based on the same
1458 // function can all use this call IC. Before we load through the
1459 // function, we have to verify that it still is a function.
1460 __ JumpIfSmi(a1, miss);
1461 __ GetObjectType(a1, a3, a3);
1462 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
1463
1464 // Check the shared function info. Make sure it hasn't changed.
1465 __ li(a3, Handle<SharedFunctionInfo>(function->shared()));
1466 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
1467 __ Branch(miss, ne, t0, Operand(a3));
1468 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001469 __ Branch(miss, ne, a1, Operand(function));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001470 }
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001471}
1472
1473
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001474void CallStubCompiler::GenerateMissBranch() {
1475 Handle<Code> code =
danno@chromium.org40cb8782011-05-25 07:58:50 +00001476 isolate()->stub_cache()->ComputeCallMiss(arguments().immediate(),
1477 kind_,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001478 extra_state_);
1479 __ Jump(code, RelocInfo::CODE_TARGET);
1480}
1481
1482
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001483Handle<Code> CallStubCompiler::CompileCallField(Handle<JSObject> object,
1484 Handle<JSObject> holder,
yangguo@chromium.orgfb377212012-11-16 14:43:43 +00001485 PropertyIndex index,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001486 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001487 // ----------- S t a t e -------------
1488 // -- a2 : name
1489 // -- ra : return address
1490 // -----------------------------------
1491 Label miss;
1492
1493 GenerateNameCheck(name, &miss);
1494
1495 const int argc = arguments().immediate();
1496
1497 // Get the receiver of the function from the stack into a0.
1498 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1499 // Check that the receiver isn't a smi.
1500 __ JumpIfSmi(a0, &miss, t0);
1501
1502 // Do the right check and compute the holder register.
1503 Register reg = CheckPrototypes(object, a0, holder, a1, a3, t0, name, &miss);
1504 GenerateFastPropertyLoad(masm(), a1, reg, holder, index);
1505
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001506 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001507
1508 // Handle call cache miss.
1509 __ bind(&miss);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001510 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001511
1512 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00001513 return GetCode(Code::FIELD, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00001514}
1515
1516
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001517Handle<Code> CallStubCompiler::CompileArrayPushCall(
1518 Handle<Object> object,
1519 Handle<JSObject> holder,
1520 Handle<JSGlobalPropertyCell> cell,
1521 Handle<JSFunction> function,
1522 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001523 // ----------- S t a t e -------------
1524 // -- a2 : name
1525 // -- ra : return address
1526 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1527 // -- ...
1528 // -- sp[argc * 4] : receiver
1529 // -----------------------------------
1530
1531 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001532 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001533
1534 Label miss;
1535
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001536 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001537
1538 Register receiver = a1;
1539
1540 // Get the receiver from the stack.
1541 const int argc = arguments().immediate();
1542 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1543
1544 // Check that the receiver isn't a smi.
1545 __ JumpIfSmi(receiver, &miss);
1546
1547 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001548 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, a3, v0, t0,
1549 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001550
1551 if (argc == 0) {
1552 // Nothing to do, just return the length.
1553 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1554 __ Drop(argc + 1);
1555 __ Ret();
1556 } else {
1557 Label call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001558 if (argc == 1) { // Otherwise fall through to call the builtin.
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001559 Label attempt_to_grow_elements, with_write_barrier, check_double;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001560
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001561 Register elements = t2;
1562 Register end_elements = t1;
1563 // Get the elements array of the object.
1564 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1565
1566 // Check that the elements are in fast mode and writable.
1567 __ CheckMap(elements,
1568 v0,
1569 Heap::kFixedArrayMapRootIndex,
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001570 &check_double,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001571 DONT_DO_SMI_CHECK);
1572
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001573 // Get the array's length into v0 and calculate new length.
1574 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1575 STATIC_ASSERT(kSmiTagSize == 1);
1576 STATIC_ASSERT(kSmiTag == 0);
1577 __ Addu(v0, v0, Operand(Smi::FromInt(argc)));
1578
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001579 // Get the elements' length.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001580 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1581
1582 // Check if we could survive without allocation.
1583 __ Branch(&attempt_to_grow_elements, gt, v0, Operand(t0));
1584
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001585 // Check if value is a smi.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001586 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize));
1587 __ JumpIfNotSmi(t0, &with_write_barrier);
1588
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001589 // Save new length.
1590 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1591
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001592 // Store the value.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001593 // We may need a register containing the address end_elements below,
1594 // so write back the value in end_elements.
1595 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1596 __ Addu(end_elements, elements, end_elements);
1597 const int kEndElementsOffset =
1598 FixedArray::kHeaderSize - kHeapObjectTag - argc * kPointerSize;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001599 __ Addu(end_elements, end_elements, kEndElementsOffset);
1600 __ sw(t0, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001601
1602 // Check for a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001603 __ Drop(argc + 1);
1604 __ Ret();
1605
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001606 __ bind(&check_double);
1607
1608 // Check that the elements are in fast mode and writable.
1609 __ CheckMap(elements,
1610 a0,
1611 Heap::kFixedDoubleArrayMapRootIndex,
1612 &call_builtin,
1613 DONT_DO_SMI_CHECK);
1614
1615 // Get the array's length into r0 and calculate new length.
1616 __ lw(a0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1617 STATIC_ASSERT(kSmiTagSize == 1);
1618 STATIC_ASSERT(kSmiTag == 0);
1619 __ Addu(a0, a0, Operand(Smi::FromInt(argc)));
1620
1621 // Get the elements' length.
1622 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1623
1624 // Check if we could survive without allocation.
1625 __ Branch(&call_builtin, gt, a0, Operand(t0));
1626
1627 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize));
1628 __ StoreNumberToDoubleElements(
1629 t0, a0, elements, a3, t1, a2, t5,
1630 &call_builtin, argc * kDoubleSize);
1631
1632 // Save new length.
1633 __ sw(a0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1634
1635 // Check for a smi.
1636 __ Drop(argc + 1);
1637 __ Ret();
1638
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001639 __ bind(&with_write_barrier);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001640
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001641 __ lw(a3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1642
1643 if (FLAG_smi_only_arrays && !FLAG_trace_elements_transitions) {
1644 Label fast_object, not_fast_object;
1645 __ CheckFastObjectElements(a3, t3, &not_fast_object);
1646 __ jmp(&fast_object);
1647 // In case of fast smi-only, convert to fast object, otherwise bail out.
1648 __ bind(&not_fast_object);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001649 __ CheckFastSmiElements(a3, t3, &call_builtin);
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001650
1651 __ lw(t3, FieldMemOperand(t0, HeapObject::kMapOffset));
1652 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex);
1653 __ Branch(&call_builtin, eq, t3, Operand(at));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001654 // edx: receiver
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001655 // a3: map
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001656 Label try_holey_map;
1657 __ LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001658 FAST_ELEMENTS,
1659 a3,
1660 t3,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001661 &try_holey_map);
1662 __ mov(a2, receiver);
1663 ElementsTransitionGenerator::
yangguo@chromium.org28381b42013-01-21 14:39:38 +00001664 GenerateMapChangeElementsTransition(masm(),
1665 DONT_TRACK_ALLOCATION_SITE,
1666 NULL);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001667 __ jmp(&fast_object);
1668
1669 __ bind(&try_holey_map);
1670 __ LoadTransitionedArrayMapConditional(FAST_HOLEY_SMI_ELEMENTS,
1671 FAST_HOLEY_ELEMENTS,
1672 a3,
1673 t3,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001674 &call_builtin);
1675 __ mov(a2, receiver);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001676 ElementsTransitionGenerator::
yangguo@chromium.org28381b42013-01-21 14:39:38 +00001677 GenerateMapChangeElementsTransition(masm(),
1678 DONT_TRACK_ALLOCATION_SITE,
1679 NULL);
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001680 __ bind(&fast_object);
1681 } else {
1682 __ CheckFastObjectElements(a3, a3, &call_builtin);
1683 }
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001684
1685 // Save new length.
1686 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1687
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001688 // Store the value.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001689 // We may need a register containing the address end_elements below,
1690 // so write back the value in end_elements.
1691 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1692 __ Addu(end_elements, elements, end_elements);
1693 __ Addu(end_elements, end_elements, kEndElementsOffset);
1694 __ sw(t0, MemOperand(end_elements));
1695
1696 __ RecordWrite(elements,
1697 end_elements,
1698 t0,
1699 kRAHasNotBeenSaved,
1700 kDontSaveFPRegs,
1701 EMIT_REMEMBERED_SET,
1702 OMIT_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001703 __ Drop(argc + 1);
1704 __ Ret();
1705
1706 __ bind(&attempt_to_grow_elements);
1707 // v0: array's length + 1.
1708 // t0: elements' length.
1709
1710 if (!FLAG_inline_new) {
1711 __ Branch(&call_builtin);
1712 }
1713
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001714 __ lw(a2, MemOperand(sp, (argc - 1) * kPointerSize));
1715 // Growing elements that are SMI-only requires special handling in case
1716 // the new element is non-Smi. For now, delegate to the builtin.
1717 Label no_fast_elements_check;
1718 __ JumpIfSmi(a2, &no_fast_elements_check);
1719 __ lw(t3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1720 __ CheckFastObjectElements(t3, t3, &call_builtin);
1721 __ bind(&no_fast_elements_check);
1722
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001723 ExternalReference new_space_allocation_top =
1724 ExternalReference::new_space_allocation_top_address(
1725 masm()->isolate());
1726 ExternalReference new_space_allocation_limit =
1727 ExternalReference::new_space_allocation_limit_address(
1728 masm()->isolate());
1729
1730 const int kAllocationDelta = 4;
1731 // Load top and check if it is the end of elements.
1732 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1733 __ Addu(end_elements, elements, end_elements);
1734 __ Addu(end_elements, end_elements, Operand(kEndElementsOffset));
1735 __ li(t3, Operand(new_space_allocation_top));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001736 __ lw(a3, MemOperand(t3));
1737 __ Branch(&call_builtin, ne, end_elements, Operand(a3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001738
1739 __ li(t5, Operand(new_space_allocation_limit));
1740 __ lw(t5, MemOperand(t5));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001741 __ Addu(a3, a3, Operand(kAllocationDelta * kPointerSize));
1742 __ Branch(&call_builtin, hi, a3, Operand(t5));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001743
1744 // We fit and could grow elements.
1745 // Update new_space_allocation_top.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001746 __ sw(a3, MemOperand(t3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001747 // Push the argument.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001748 __ sw(a2, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001749 // Fill the rest with holes.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001750 __ LoadRoot(a3, Heap::kTheHoleValueRootIndex);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001751 for (int i = 1; i < kAllocationDelta; i++) {
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001752 __ sw(a3, MemOperand(end_elements, i * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001753 }
1754
1755 // Update elements' and array's sizes.
1756 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1757 __ Addu(t0, t0, Operand(Smi::FromInt(kAllocationDelta)));
1758 __ sw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1759
1760 // Elements are in new space, so write barrier is not required.
1761 __ Drop(argc + 1);
1762 __ Ret();
1763 }
1764 __ bind(&call_builtin);
1765 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPush,
1766 masm()->isolate()),
1767 argc + 1,
1768 1);
1769 }
1770
1771 // Handle call cache miss.
1772 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001773 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001774
1775 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001776 return GetCode(function);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001777}
1778
1779
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001780Handle<Code> CallStubCompiler::CompileArrayPopCall(
1781 Handle<Object> object,
1782 Handle<JSObject> holder,
1783 Handle<JSGlobalPropertyCell> cell,
1784 Handle<JSFunction> function,
1785 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001786 // ----------- S t a t e -------------
1787 // -- a2 : name
1788 // -- ra : return address
1789 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1790 // -- ...
1791 // -- sp[argc * 4] : receiver
1792 // -----------------------------------
1793
1794 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001795 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001796
1797 Label miss, return_undefined, call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001798 Register receiver = a1;
1799 Register elements = a3;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001800 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001801
1802 // Get the receiver from the stack.
1803 const int argc = arguments().immediate();
1804 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001805 // Check that the receiver isn't a smi.
1806 __ JumpIfSmi(receiver, &miss);
1807
1808 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001809 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, elements,
1810 t0, v0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001811
1812 // Get the elements array of the object.
1813 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1814
1815 // Check that the elements are in fast mode and writable.
danno@chromium.org40cb8782011-05-25 07:58:50 +00001816 __ CheckMap(elements,
1817 v0,
1818 Heap::kFixedArrayMapRootIndex,
1819 &call_builtin,
1820 DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001821
1822 // Get the array's length into t0 and calculate new length.
1823 __ lw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1824 __ Subu(t0, t0, Operand(Smi::FromInt(1)));
1825 __ Branch(&return_undefined, lt, t0, Operand(zero_reg));
1826
1827 // Get the last element.
1828 __ LoadRoot(t2, Heap::kTheHoleValueRootIndex);
1829 STATIC_ASSERT(kSmiTagSize == 1);
1830 STATIC_ASSERT(kSmiTag == 0);
1831 // We can't address the last element in one operation. Compute the more
1832 // expensive shift first, and use an offset later on.
1833 __ sll(t1, t0, kPointerSizeLog2 - kSmiTagSize);
1834 __ Addu(elements, elements, t1);
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00001835 __ lw(v0, FieldMemOperand(elements, FixedArray::kHeaderSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001836 __ Branch(&call_builtin, eq, v0, Operand(t2));
1837
1838 // Set the array's length.
1839 __ sw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1840
1841 // Fill with the hole.
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00001842 __ sw(t2, FieldMemOperand(elements, FixedArray::kHeaderSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001843 __ Drop(argc + 1);
1844 __ Ret();
1845
1846 __ bind(&return_undefined);
1847 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
1848 __ Drop(argc + 1);
1849 __ Ret();
1850
1851 __ bind(&call_builtin);
1852 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPop,
1853 masm()->isolate()),
1854 argc + 1,
1855 1);
1856
1857 // Handle call cache miss.
1858 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001859 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001860
1861 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001862 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00001863}
1864
1865
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001866Handle<Code> CallStubCompiler::CompileStringCharCodeAtCall(
1867 Handle<Object> object,
1868 Handle<JSObject> holder,
1869 Handle<JSGlobalPropertyCell> cell,
1870 Handle<JSFunction> function,
1871 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001872 // ----------- S t a t e -------------
1873 // -- a2 : function name
1874 // -- ra : return address
1875 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1876 // -- ...
1877 // -- sp[argc * 4] : receiver
1878 // -----------------------------------
1879
1880 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001881 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001882
1883 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001884 Label miss;
1885 Label name_miss;
1886 Label index_out_of_range;
1887
1888 Label* index_out_of_range_label = &index_out_of_range;
1889
danno@chromium.org40cb8782011-05-25 07:58:50 +00001890 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001891 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00001892 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001893 index_out_of_range_label = &miss;
1894 }
1895
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001896 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001897
1898 // Check that the maps starting from the prototype haven't changed.
1899 GenerateDirectLoadGlobalFunctionPrototype(masm(),
1900 Context::STRING_FUNCTION_INDEX,
1901 v0,
1902 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001903 ASSERT(!object.is_identical_to(holder));
hpayer@chromium.org8432c912013-02-28 15:55:26 +00001904 CheckPrototypes(
1905 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
1906 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001907
1908 Register receiver = a1;
1909 Register index = t1;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001910 Register result = v0;
1911 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1912 if (argc > 0) {
1913 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
1914 } else {
1915 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
1916 }
1917
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001918 StringCharCodeAtGenerator generator(receiver,
1919 index,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001920 result,
1921 &miss, // When not a string.
1922 &miss, // When not a number.
1923 index_out_of_range_label,
1924 STRING_INDEX_IS_NUMBER);
1925 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001926 __ Drop(argc + 1);
1927 __ Ret();
1928
1929 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001930 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001931
1932 if (index_out_of_range.is_linked()) {
1933 __ bind(&index_out_of_range);
1934 __ LoadRoot(v0, Heap::kNanValueRootIndex);
1935 __ Drop(argc + 1);
1936 __ Ret();
1937 }
1938
1939 __ bind(&miss);
1940 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001941 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001942 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001943 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001944
1945 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001946 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00001947}
1948
1949
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001950Handle<Code> CallStubCompiler::CompileStringCharAtCall(
1951 Handle<Object> object,
1952 Handle<JSObject> holder,
1953 Handle<JSGlobalPropertyCell> cell,
1954 Handle<JSFunction> function,
1955 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001956 // ----------- S t a t e -------------
1957 // -- a2 : function name
1958 // -- ra : return address
1959 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1960 // -- ...
1961 // -- sp[argc * 4] : receiver
1962 // -----------------------------------
1963
1964 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001965 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001966
1967 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001968 Label miss;
1969 Label name_miss;
1970 Label index_out_of_range;
1971 Label* index_out_of_range_label = &index_out_of_range;
danno@chromium.org40cb8782011-05-25 07:58:50 +00001972 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001973 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00001974 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001975 index_out_of_range_label = &miss;
1976 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001977 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001978
1979 // Check that the maps starting from the prototype haven't changed.
1980 GenerateDirectLoadGlobalFunctionPrototype(masm(),
1981 Context::STRING_FUNCTION_INDEX,
1982 v0,
1983 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001984 ASSERT(!object.is_identical_to(holder));
hpayer@chromium.org8432c912013-02-28 15:55:26 +00001985 CheckPrototypes(
1986 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
1987 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001988
1989 Register receiver = v0;
1990 Register index = t1;
danno@chromium.orgc612e022011-11-10 11:38:15 +00001991 Register scratch = a3;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001992 Register result = v0;
1993 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1994 if (argc > 0) {
1995 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
1996 } else {
1997 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
1998 }
1999
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002000 StringCharAtGenerator generator(receiver,
2001 index,
danno@chromium.orgc612e022011-11-10 11:38:15 +00002002 scratch,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002003 result,
2004 &miss, // When not a string.
2005 &miss, // When not a number.
2006 index_out_of_range_label,
2007 STRING_INDEX_IS_NUMBER);
2008 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002009 __ Drop(argc + 1);
2010 __ Ret();
2011
2012 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002013 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002014
2015 if (index_out_of_range.is_linked()) {
2016 __ bind(&index_out_of_range);
ulan@chromium.org750145a2013-03-07 15:14:13 +00002017 __ LoadRoot(v0, Heap::kempty_stringRootIndex);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002018 __ Drop(argc + 1);
2019 __ Ret();
2020 }
2021
2022 __ bind(&miss);
2023 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002024 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002025 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002026 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002027
2028 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002029 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002030}
2031
2032
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002033Handle<Code> CallStubCompiler::CompileStringFromCharCodeCall(
2034 Handle<Object> object,
2035 Handle<JSObject> holder,
2036 Handle<JSGlobalPropertyCell> cell,
2037 Handle<JSFunction> function,
2038 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002039 // ----------- S t a t e -------------
2040 // -- a2 : function name
2041 // -- ra : return address
2042 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2043 // -- ...
2044 // -- sp[argc * 4] : receiver
2045 // -----------------------------------
2046
2047 const int argc = arguments().immediate();
2048
2049 // If the object is not a JSObject or we got an unexpected number of
2050 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002051 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002052
2053 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002054 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002055
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002056 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002057 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
2058
2059 STATIC_ASSERT(kSmiTag == 0);
2060 __ JumpIfSmi(a1, &miss);
2061
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002062 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
2063 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002064 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002065 ASSERT(cell->value() == *function);
2066 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2067 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002068 GenerateLoadFunctionFromCell(cell, function, &miss);
2069 }
2070
2071 // Load the char code argument.
2072 Register code = a1;
2073 __ lw(code, MemOperand(sp, 0 * kPointerSize));
2074
2075 // Check the code is a smi.
2076 Label slow;
2077 STATIC_ASSERT(kSmiTag == 0);
2078 __ JumpIfNotSmi(code, &slow);
2079
2080 // Convert the smi code to uint16.
2081 __ And(code, code, Operand(Smi::FromInt(0xffff)));
2082
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002083 StringCharFromCodeGenerator generator(code, v0);
2084 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002085 __ Drop(argc + 1);
2086 __ Ret();
2087
2088 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002089 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002090
2091 // Tail call the full function. We do not have to patch the receiver
2092 // because the function makes no use of it.
2093 __ bind(&slow);
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002094 __ InvokeFunction(
2095 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002096
2097 __ bind(&miss);
2098 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002099 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002100
2101 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002102 return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002103}
2104
2105
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002106Handle<Code> CallStubCompiler::CompileMathFloorCall(
2107 Handle<Object> object,
2108 Handle<JSObject> holder,
2109 Handle<JSGlobalPropertyCell> cell,
2110 Handle<JSFunction> function,
2111 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002112 // ----------- S t a t e -------------
2113 // -- a2 : function name
2114 // -- ra : return address
2115 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2116 // -- ...
2117 // -- sp[argc * 4] : receiver
2118 // -----------------------------------
2119
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002120
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002121 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002122 // If the object is not a JSObject or we got an unexpected number of
2123 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002124 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002125
2126 Label miss, slow;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002127 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002128
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002129 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002130 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002131 STATIC_ASSERT(kSmiTag == 0);
2132 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002133 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2134 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002135 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002136 ASSERT(cell->value() == *function);
2137 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2138 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002139 GenerateLoadFunctionFromCell(cell, function, &miss);
2140 }
2141
2142 // Load the (only) argument into v0.
2143 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2144
2145 // If the argument is a smi, just return.
2146 STATIC_ASSERT(kSmiTag == 0);
2147 __ And(t0, v0, Operand(kSmiTagMask));
2148 __ Drop(argc + 1, eq, t0, Operand(zero_reg));
2149 __ Ret(eq, t0, Operand(zero_reg));
2150
danno@chromium.org40cb8782011-05-25 07:58:50 +00002151 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002152
2153 Label wont_fit_smi, no_fpu_error, restore_fcsr_and_return;
2154
2155 // If fpu is enabled, we use the floor instruction.
2156
2157 // Load the HeapNumber value.
2158 __ ldc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
2159
2160 // Backup FCSR.
2161 __ cfc1(a3, FCSR);
2162 // Clearing FCSR clears the exception mask with no side-effects.
2163 __ ctc1(zero_reg, FCSR);
2164 // Convert the argument to an integer.
2165 __ floor_w_d(f0, f0);
2166
2167 // Start checking for special cases.
2168 // Get the argument exponent and clear the sign bit.
2169 __ lw(t1, FieldMemOperand(v0, HeapNumber::kValueOffset + kPointerSize));
2170 __ And(t2, t1, Operand(~HeapNumber::kSignMask));
2171 __ srl(t2, t2, HeapNumber::kMantissaBitsInTopWord);
2172
2173 // Retrieve FCSR and check for fpu errors.
2174 __ cfc1(t5, FCSR);
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002175 __ And(t5, t5, Operand(kFCSRExceptionFlagMask));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002176 __ Branch(&no_fpu_error, eq, t5, Operand(zero_reg));
2177
2178 // Check for NaN, Infinity, and -Infinity.
2179 // They are invariant through a Math.Floor call, so just
2180 // return the original argument.
2181 __ Subu(t3, t2, Operand(HeapNumber::kExponentMask
2182 >> HeapNumber::kMantissaBitsInTopWord));
2183 __ Branch(&restore_fcsr_and_return, eq, t3, Operand(zero_reg));
2184 // We had an overflow or underflow in the conversion. Check if we
2185 // have a big exponent.
2186 // If greater or equal, the argument is already round and in v0.
2187 __ Branch(&restore_fcsr_and_return, ge, t3,
2188 Operand(HeapNumber::kMantissaBits));
2189 __ Branch(&wont_fit_smi);
2190
2191 __ bind(&no_fpu_error);
2192 // Move the result back to v0.
2193 __ mfc1(v0, f0);
2194 // Check if the result fits into a smi.
2195 __ Addu(a1, v0, Operand(0x40000000));
2196 __ Branch(&wont_fit_smi, lt, a1, Operand(zero_reg));
2197 // Tag the result.
2198 STATIC_ASSERT(kSmiTag == 0);
2199 __ sll(v0, v0, kSmiTagSize);
2200
2201 // Check for -0.
2202 __ Branch(&restore_fcsr_and_return, ne, v0, Operand(zero_reg));
2203 // t1 already holds the HeapNumber exponent.
2204 __ And(t0, t1, Operand(HeapNumber::kSignMask));
2205 // If our HeapNumber is negative it was -0, so load its address and return.
2206 // Else v0 is loaded with 0, so we can also just return.
2207 __ Branch(&restore_fcsr_and_return, eq, t0, Operand(zero_reg));
2208 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2209
2210 __ bind(&restore_fcsr_and_return);
2211 // Restore FCSR and return.
2212 __ ctc1(a3, FCSR);
2213
2214 __ Drop(argc + 1);
2215 __ Ret();
2216
2217 __ bind(&wont_fit_smi);
2218 // Restore FCSR and fall to slow case.
2219 __ ctc1(a3, FCSR);
2220
2221 __ bind(&slow);
2222 // Tail call the full function. We do not have to patch the receiver
2223 // because the function makes no use of it.
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002224 __ InvokeFunction(
2225 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002226
2227 __ bind(&miss);
2228 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002229 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002230
2231 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002232 return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002233}
2234
2235
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002236Handle<Code> CallStubCompiler::CompileMathAbsCall(
2237 Handle<Object> object,
2238 Handle<JSObject> holder,
2239 Handle<JSGlobalPropertyCell> cell,
2240 Handle<JSFunction> function,
2241 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002242 // ----------- S t a t e -------------
2243 // -- a2 : function name
2244 // -- ra : return address
2245 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2246 // -- ...
2247 // -- sp[argc * 4] : receiver
2248 // -----------------------------------
2249
2250 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002251 // If the object is not a JSObject or we got an unexpected number of
2252 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002253 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002254
2255 Label miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002256
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002257 GenerateNameCheck(name, &miss);
2258 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002259 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002260 STATIC_ASSERT(kSmiTag == 0);
2261 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002262 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
2263 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002264 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002265 ASSERT(cell->value() == *function);
2266 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2267 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002268 GenerateLoadFunctionFromCell(cell, function, &miss);
2269 }
2270
2271 // Load the (only) argument into v0.
2272 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2273
2274 // Check if the argument is a smi.
2275 Label not_smi;
2276 STATIC_ASSERT(kSmiTag == 0);
2277 __ JumpIfNotSmi(v0, &not_smi);
2278
2279 // Do bitwise not or do nothing depending on the sign of the
2280 // argument.
2281 __ sra(t0, v0, kBitsPerInt - 1);
2282 __ Xor(a1, v0, t0);
2283
2284 // Add 1 or do nothing depending on the sign of the argument.
2285 __ Subu(v0, a1, t0);
2286
2287 // If the result is still negative, go to the slow case.
2288 // This only happens for the most negative smi.
2289 Label slow;
2290 __ Branch(&slow, lt, v0, Operand(zero_reg));
2291
2292 // Smi case done.
2293 __ Drop(argc + 1);
2294 __ Ret();
2295
2296 // Check if the argument is a heap number and load its exponent and
2297 // sign.
2298 __ bind(&not_smi);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002299 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002300 __ lw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2301
2302 // Check the sign of the argument. If the argument is positive,
2303 // just return it.
2304 Label negative_sign;
2305 __ And(t0, a1, Operand(HeapNumber::kSignMask));
2306 __ Branch(&negative_sign, ne, t0, Operand(zero_reg));
2307 __ Drop(argc + 1);
2308 __ Ret();
2309
2310 // If the argument is negative, clear the sign, and return a new
2311 // number.
2312 __ bind(&negative_sign);
2313 __ Xor(a1, a1, Operand(HeapNumber::kSignMask));
2314 __ lw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2315 __ LoadRoot(t2, Heap::kHeapNumberMapRootIndex);
2316 __ AllocateHeapNumber(v0, t0, t1, t2, &slow);
2317 __ sw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2318 __ sw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2319 __ Drop(argc + 1);
2320 __ Ret();
2321
2322 // Tail call the full function. We do not have to patch the receiver
2323 // because the function makes no use of it.
2324 __ bind(&slow);
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002325 __ InvokeFunction(
2326 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002327
2328 __ bind(&miss);
2329 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002330 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002331
2332 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002333 return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002334}
2335
2336
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002337Handle<Code> CallStubCompiler::CompileFastApiCall(
lrn@chromium.org7516f052011-03-30 08:52:27 +00002338 const CallOptimization& optimization,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002339 Handle<Object> object,
2340 Handle<JSObject> holder,
2341 Handle<JSGlobalPropertyCell> cell,
2342 Handle<JSFunction> function,
2343 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002344
danno@chromium.org40cb8782011-05-25 07:58:50 +00002345 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002346
2347 ASSERT(optimization.is_simple_api_call());
2348 // Bail out if object is a global object as we don't want to
2349 // repatch it to global receiver.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002350 if (object->IsGlobalObject()) return Handle<Code>::null();
2351 if (!cell.is_null()) return Handle<Code>::null();
2352 if (!object->IsJSObject()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002353 int depth = optimization.GetPrototypeDepthOfExpectedType(
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002354 Handle<JSObject>::cast(object), holder);
2355 if (depth == kInvalidProtoDepth) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002356
2357 Label miss, miss_before_stack_reserved;
2358
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002359 GenerateNameCheck(name, &miss_before_stack_reserved);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002360
2361 // Get the receiver from the stack.
2362 const int argc = arguments().immediate();
2363 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2364
2365 // Check that the receiver isn't a smi.
2366 __ JumpIfSmi(a1, &miss_before_stack_reserved);
2367
2368 __ IncrementCounter(counters->call_const(), 1, a0, a3);
2369 __ IncrementCounter(counters->call_const_fast_api(), 1, a0, a3);
2370
2371 ReserveSpaceForFastApiCall(masm(), a0);
2372
2373 // Check that the maps haven't changed and find a Holder as a side effect.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002374 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0, name,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002375 depth, &miss);
2376
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002377 GenerateFastApiDirectCall(masm(), optimization, argc);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002378
2379 __ bind(&miss);
2380 FreeSpaceForFastApiCall(masm());
2381
2382 __ bind(&miss_before_stack_reserved);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002383 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002384
2385 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002386 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002387}
2388
2389
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002390void CallStubCompiler::CompileHandlerFrontend(Handle<Object> object,
2391 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002392 Handle<Name> name,
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002393 CheckType check,
2394 Label* success) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002395 // ----------- S t a t e -------------
2396 // -- a2 : name
2397 // -- ra : return address
2398 // -----------------------------------
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002399 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002400 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002401
2402 // Get the receiver from the stack.
2403 const int argc = arguments().immediate();
2404 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2405
2406 // Check that the receiver isn't a smi.
2407 if (check != NUMBER_CHECK) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002408 __ JumpIfSmi(a1, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002409 }
2410
2411 // Make sure that it's okay not to patch the on stack receiver
2412 // unless we're doing a receiver map check.
2413 ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002414 switch (check) {
2415 case RECEIVER_MAP_CHECK:
2416 __ IncrementCounter(masm()->isolate()->counters()->call_const(),
2417 1, a0, a3);
2418
2419 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002420 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2421 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002422
2423 // Patch the receiver on the stack with the global proxy if
2424 // necessary.
2425 if (object->IsGlobalObject()) {
2426 __ lw(a3, FieldMemOperand(a1, GlobalObject::kGlobalReceiverOffset));
2427 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2428 }
2429 break;
2430
2431 case STRING_CHECK:
ulan@chromium.org750145a2013-03-07 15:14:13 +00002432 // Check that the object is a string.
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002433 __ GetObjectType(a1, a3, a3);
2434 __ Branch(&miss, Ugreater_equal, a3, Operand(FIRST_NONSTRING_TYPE));
2435 // Check that the maps starting from the prototype haven't changed.
2436 GenerateDirectLoadGlobalFunctionPrototype(
2437 masm(), Context::STRING_FUNCTION_INDEX, a0, &miss);
2438 CheckPrototypes(
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002439 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002440 a0, holder, a3, a1, t0, name, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002441 break;
2442
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002443 case SYMBOL_CHECK:
2444 // Check that the object is a symbol.
2445 __ GetObjectType(a1, a1, a3);
2446 __ Branch(&miss, ne, a3, Operand(SYMBOL_TYPE));
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +00002447 // Check that the maps starting from the prototype haven't changed.
2448 GenerateDirectLoadGlobalFunctionPrototype(
2449 masm(), Context::SYMBOL_FUNCTION_INDEX, a0, &miss);
2450 CheckPrototypes(
2451 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
2452 a0, holder, a3, a1, t0, name, &miss);
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002453 break;
2454
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002455 case NUMBER_CHECK: {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002456 Label fast;
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002457 // Check that the object is a smi or a heap number.
2458 __ JumpIfSmi(a1, &fast);
2459 __ GetObjectType(a1, a0, a0);
2460 __ Branch(&miss, ne, a0, Operand(HEAP_NUMBER_TYPE));
2461 __ bind(&fast);
2462 // Check that the maps starting from the prototype haven't changed.
2463 GenerateDirectLoadGlobalFunctionPrototype(
2464 masm(), Context::NUMBER_FUNCTION_INDEX, a0, &miss);
2465 CheckPrototypes(
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002466 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002467 a0, holder, a3, a1, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002468 break;
2469 }
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002470 case BOOLEAN_CHECK: {
2471 Label fast;
2472 // Check that the object is a boolean.
2473 __ LoadRoot(t0, Heap::kTrueValueRootIndex);
2474 __ Branch(&fast, eq, a1, Operand(t0));
2475 __ LoadRoot(t0, Heap::kFalseValueRootIndex);
2476 __ Branch(&miss, ne, a1, Operand(t0));
2477 __ bind(&fast);
2478 // Check that the maps starting from the prototype haven't changed.
2479 GenerateDirectLoadGlobalFunctionPrototype(
2480 masm(), Context::BOOLEAN_FUNCTION_INDEX, a0, &miss);
2481 CheckPrototypes(
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002482 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002483 a0, holder, a3, a1, t0, name, &miss);
2484 break;
2485 }
2486 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002487
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002488 __ jmp(success);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002489
2490 // Handle call cache miss.
2491 __ bind(&miss);
2492
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002493 GenerateMissBranch();
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002494}
2495
2496
2497void CallStubCompiler::CompileHandlerBackend(Handle<JSFunction> function) {
2498 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
2499 ? CALL_AS_FUNCTION
2500 : CALL_AS_METHOD;
2501 __ InvokeFunction(
2502 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), call_kind);
2503}
2504
2505
2506Handle<Code> CallStubCompiler::CompileCallConstant(
2507 Handle<Object> object,
2508 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002509 Handle<Name> name,
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002510 CheckType check,
2511 Handle<JSFunction> function) {
2512 if (HasCustomCallGenerator(function)) {
2513 Handle<Code> code = CompileCustomCall(object, holder,
2514 Handle<JSGlobalPropertyCell>::null(),
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002515 function, Handle<String>::cast(name));
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002516 // A null handle means bail out to the regular compiler code below.
2517 if (!code.is_null()) return code;
2518 }
2519
2520 Label success;
2521
2522 CompileHandlerFrontend(object, holder, name, check, &success);
2523 __ bind(&success);
2524 CompileHandlerBackend(function);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002525
2526 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002527 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002528}
2529
2530
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002531Handle<Code> CallStubCompiler::CompileCallInterceptor(Handle<JSObject> object,
2532 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002533 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002534 // ----------- S t a t e -------------
2535 // -- a2 : name
2536 // -- ra : return address
2537 // -----------------------------------
2538
2539 Label miss;
2540
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002541 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002542
2543 // Get the number of arguments.
2544 const int argc = arguments().immediate();
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002545 LookupResult lookup(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002546 LookupPostInterceptor(holder, name, &lookup);
2547
2548 // Get the receiver from the stack.
2549 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2550
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002551 CallInterceptorCompiler compiler(this, arguments(), a2, extra_state_);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002552 compiler.Compile(masm(), object, holder, name, &lookup, a1, a3, t0, a0,
2553 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002554
2555 // Move returned value, the function to call, to a1.
2556 __ mov(a1, v0);
2557 // Restore receiver.
2558 __ lw(a0, MemOperand(sp, argc * kPointerSize));
2559
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002560 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002561
2562 // Handle call cache miss.
2563 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002564 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002565
2566 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002567 return GetCode(Code::INTERCEPTOR, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002568}
2569
2570
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002571Handle<Code> CallStubCompiler::CompileCallGlobal(
2572 Handle<JSObject> object,
2573 Handle<GlobalObject> holder,
2574 Handle<JSGlobalPropertyCell> cell,
2575 Handle<JSFunction> function,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002576 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002577 // ----------- S t a t e -------------
2578 // -- a2 : name
2579 // -- ra : return address
2580 // -----------------------------------
2581
2582 if (HasCustomCallGenerator(function)) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002583 Handle<Code> code = CompileCustomCall(
2584 object, holder, cell, function, Handle<String>::cast(name));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002585 // A null handle means bail out to the regular compiler code below.
2586 if (!code.is_null()) return code;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002587 }
2588
2589 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002590 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002591
2592 // Get the number of arguments.
2593 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002594 GenerateGlobalReceiverCheck(object, holder, name, &miss);
2595 GenerateLoadFunctionFromCell(cell, function, &miss);
2596
2597 // Patch the receiver on the stack with the global proxy if
2598 // necessary.
2599 if (object->IsGlobalObject()) {
2600 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
2601 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2602 }
2603
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002604 // Set up the context (function already in r1).
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002605 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
2606
2607 // Jump to the cached code (tail call).
2608 Counters* counters = masm()->isolate()->counters();
2609 __ IncrementCounter(counters->call_global_inline(), 1, a3, t0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002610 ParameterCount expected(function->shared()->formal_parameter_count());
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002611 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
danno@chromium.org40cb8782011-05-25 07:58:50 +00002612 ? CALL_AS_FUNCTION
2613 : CALL_AS_METHOD;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002614 // We call indirectly through the code field in the function to
2615 // allow recompilation to take effect without changing any of the
2616 // call sites.
2617 __ lw(a3, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
2618 __ InvokeCode(a3, expected, arguments(), JUMP_FUNCTION,
2619 NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002620
2621 // Handle call cache miss.
2622 __ bind(&miss);
2623 __ IncrementCounter(counters->call_global_inline_miss(), 1, a1, a3);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002624 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002625
2626 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002627 return GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002628}
2629
2630
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002631Handle<Code> StoreStubCompiler::CompileStoreCallback(
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002632 Handle<Name> name,
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002633 Handle<JSObject> object,
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002634 Handle<JSObject> holder,
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00002635 Handle<ExecutableAccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002636 Label miss;
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002637 // Check that the maps haven't changed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002638 __ JumpIfSmi(receiver(), &miss);
2639 CheckPrototypes(object, receiver(), holder,
2640 scratch1(), scratch2(), scratch3(), name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002641
2642 // Stub never generated for non-global objects that require access
2643 // checks.
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002644 ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002645
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002646 __ push(receiver()); // Receiver.
2647 __ li(at, Operand(callback)); // Callback info.
2648 __ Push(at, this->name(), value());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002649
2650 // Do tail-call to the runtime system.
2651 ExternalReference store_callback_property =
2652 ExternalReference(IC_Utility(IC::kStoreCallbackProperty),
2653 masm()->isolate());
2654 __ TailCallExternalReference(store_callback_property, 4, 1);
2655
2656 // Handle store cache miss.
2657 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002658 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002659
2660 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002661 return GetICCode(kind(), Code::CALLBACKS, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002662}
2663
2664
yangguo@chromium.org46839fb2012-08-28 09:06:19 +00002665#undef __
2666#define __ ACCESS_MASM(masm)
2667
2668
2669void StoreStubCompiler::GenerateStoreViaSetter(
2670 MacroAssembler* masm,
2671 Handle<JSFunction> setter) {
2672 // ----------- S t a t e -------------
2673 // -- a0 : value
2674 // -- a1 : receiver
2675 // -- a2 : name
2676 // -- ra : return address
2677 // -----------------------------------
2678 {
2679 FrameScope scope(masm, StackFrame::INTERNAL);
2680
2681 // Save value register, so we can restore it later.
2682 __ push(a0);
2683
2684 if (!setter.is_null()) {
2685 // Call the JavaScript setter with receiver and value on the stack.
2686 __ push(a1);
2687 __ push(a0);
2688 ParameterCount actual(1);
2689 __ InvokeFunction(setter, actual, CALL_FUNCTION, NullCallWrapper(),
2690 CALL_AS_METHOD);
2691 } else {
2692 // If we generate a global code snippet for deoptimization only, remember
2693 // the place to continue after deoptimization.
2694 masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
2695 }
2696
2697 // We have to return the passed value, not the return value of the setter.
2698 __ pop(v0);
2699
2700 // Restore context register.
2701 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2702 }
2703 __ Ret();
2704}
2705
2706
2707#undef __
2708#define __ ACCESS_MASM(masm())
2709
2710
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002711Handle<Code> StoreStubCompiler::CompileStoreInterceptor(
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002712 Handle<JSObject> object,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002713 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002714 Label miss;
2715
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002716 // Check that the map of the object hasn't changed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002717 __ CheckMap(receiver(), scratch1(), Handle<Map>(object->map()), &miss,
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002718 DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002719
2720 // Perform global security token check if needed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002721 if (object->IsJSGlobalProxy()) {
2722 __ CheckAccessGlobalProxy(receiver(), scratch1(), &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002723 }
2724
2725 // Stub is never generated for non-global objects that require access
2726 // checks.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002727 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002728
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002729 __ Push(receiver(), this->name(), value());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002730
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002731 __ li(scratch1(), Operand(Smi::FromInt(strict_mode())));
2732 __ push(scratch1()); // strict mode
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002733
2734 // Do tail-call to the runtime system.
2735 ExternalReference store_ic_property =
2736 ExternalReference(IC_Utility(IC::kStoreInterceptorProperty),
2737 masm()->isolate());
2738 __ TailCallExternalReference(store_ic_property, 4, 1);
2739
2740 // Handle store cache miss.
2741 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002742 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002743
2744 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002745 return GetICCode(kind(), Code::INTERCEPTOR, name);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00002746}
2747
2748
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002749Handle<Code> StoreStubCompiler::CompileStoreGlobal(
2750 Handle<GlobalObject> object,
2751 Handle<JSGlobalPropertyCell> cell,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002752 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002753 Label miss;
2754
2755 // Check that the map of the global has not changed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002756 __ lw(scratch1(), FieldMemOperand(receiver(), HeapObject::kMapOffset));
2757 __ Branch(&miss, ne, scratch1(), Operand(Handle<Map>(object->map())));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002758
2759 // Check that the value in the cell is not the hole. If it is, this
2760 // cell could have been deleted and reintroducing the global needs
2761 // to update the property details in the property dictionary of the
2762 // global object. We bail out to the runtime system to do that.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002763 __ li(scratch1(), Operand(cell));
2764 __ LoadRoot(scratch2(), Heap::kTheHoleValueRootIndex);
2765 __ lw(scratch3(),
2766 FieldMemOperand(scratch1(), JSGlobalPropertyCell::kValueOffset));
2767 __ Branch(&miss, eq, scratch3(), Operand(scratch2()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002768
2769 // Store the value in the cell.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002770 __ sw(value(),
2771 FieldMemOperand(scratch1(), JSGlobalPropertyCell::kValueOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002772 __ mov(v0, a0); // Stored value must be returned in v0.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002773 // Cells are always rescanned, so no write barrier here.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00002774
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002775 Counters* counters = masm()->isolate()->counters();
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002776 __ IncrementCounter(
2777 counters->named_store_global_inline(), 1, scratch1(), scratch2());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002778 __ Ret();
2779
2780 // Handle store cache miss.
2781 __ bind(&miss);
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002782 __ IncrementCounter(
2783 counters->named_store_global_inline_miss(), 1, scratch1(), scratch2());
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002784 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002785
2786 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002787 return GetICCode(kind(), Code::NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002788}
2789
2790
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002791Handle<Code> LoadStubCompiler::CompileLoadNonexistent(
2792 Handle<JSObject> object,
2793 Handle<JSObject> last,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002794 Handle<Name> name,
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002795 Handle<GlobalObject> global) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002796 Label success;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002797
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002798 NonexistentHandlerFrontend(object, last, name, &success, global);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002799
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002800 __ bind(&success);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002801 // Return undefined if maps of the full prototype chain is still the same.
2802 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
2803 __ Ret();
2804
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002805 // Return the generated code.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002806 return GetCode(kind(), Code::NONEXISTENT, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002807}
2808
2809
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002810Register* LoadStubCompiler::registers() {
2811 // receiver, name, scratch1, scratch2, scratch3, scratch4.
2812 static Register registers[] = { a0, a2, a3, a1, t0, t1 };
2813 return registers;
lrn@chromium.org7516f052011-03-30 08:52:27 +00002814}
2815
2816
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002817Register* KeyedLoadStubCompiler::registers() {
2818 // receiver, name, scratch1, scratch2, scratch3, scratch4.
2819 static Register registers[] = { a1, a0, a2, a3, t0, t1 };
2820 return registers;
2821}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002822
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002823
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002824Register* StoreStubCompiler::registers() {
2825 // receiver, name, value, scratch1, scratch2, scratch3.
2826 static Register registers[] = { a1, a2, a0, a3, t0, t1 };
2827 return registers;
2828}
2829
2830
2831Register* KeyedStoreStubCompiler::registers() {
2832 // receiver, name, value, scratch1, scratch2, scratch3.
2833 static Register registers[] = { a2, a1, a0, a3, t0, t1 };
2834 return registers;
2835}
2836
2837
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002838void KeyedLoadStubCompiler::GenerateNameCheck(Handle<Name> name,
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002839 Register name_reg,
2840 Label* miss) {
2841 __ Branch(miss, ne, name_reg, Operand(name));
lrn@chromium.org7516f052011-03-30 08:52:27 +00002842}
2843
2844
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002845void KeyedStoreStubCompiler::GenerateNameCheck(Handle<Name> name,
2846 Register name_reg,
2847 Label* miss) {
2848 __ Branch(miss, ne, name_reg, Operand(name));
2849}
2850
2851
mstarzinger@chromium.orgde886792012-09-11 13:22:37 +00002852#undef __
2853#define __ ACCESS_MASM(masm)
2854
2855
2856void LoadStubCompiler::GenerateLoadViaGetter(MacroAssembler* masm,
2857 Handle<JSFunction> getter) {
2858 // ----------- S t a t e -------------
2859 // -- a0 : receiver
2860 // -- a2 : name
2861 // -- ra : return address
2862 // -----------------------------------
2863 {
2864 FrameScope scope(masm, StackFrame::INTERNAL);
2865
2866 if (!getter.is_null()) {
2867 // Call the JavaScript getter with the receiver on the stack.
2868 __ push(a0);
2869 ParameterCount actual(0);
2870 __ InvokeFunction(getter, actual, CALL_FUNCTION, NullCallWrapper(),
2871 CALL_AS_METHOD);
2872 } else {
2873 // If we generate a global code snippet for deoptimization only, remember
2874 // the place to continue after deoptimization.
2875 masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
2876 }
2877
2878 // Restore context register.
2879 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2880 }
2881 __ Ret();
2882}
2883
2884
2885#undef __
2886#define __ ACCESS_MASM(masm())
2887
2888
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002889Handle<Code> LoadStubCompiler::CompileLoadGlobal(
2890 Handle<JSObject> object,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002891 Handle<GlobalObject> global,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002892 Handle<JSGlobalPropertyCell> cell,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002893 Handle<Name> name,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002894 bool is_dont_delete) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002895 Label success, miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002896
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002897 __ CheckMap(
2898 receiver(), scratch1(), Handle<Map>(object->map()), &miss, DO_SMI_CHECK);
2899 HandlerFrontendHeader(
2900 object, receiver(), Handle<JSObject>::cast(global), name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002901
2902 // Get the value from the cell.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002903 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002904 __ lw(t0, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
2905
2906 // Check for deleted property if property can actually be deleted.
2907 if (!is_dont_delete) {
2908 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
2909 __ Branch(&miss, eq, t0, Operand(at));
2910 }
2911
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002912 HandlerFrontendFooter(&success, &miss);
2913 __ bind(&success);
2914
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002915 Counters* counters = masm()->isolate()->counters();
2916 __ IncrementCounter(counters->named_load_global_stub(), 1, a1, a3);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002917 __ mov(v0, t0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002918 __ Ret();
2919
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002920 // Return the generated code.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002921 return GetICCode(kind(), Code::NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002922}
2923
2924
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002925Handle<Code> BaseLoadStubCompiler::CompilePolymorphicIC(
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002926 MapHandleList* receiver_maps,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002927 CodeHandleList* handlers,
2928 Handle<Name> name,
2929 Code::StubType type,
2930 IcCheckType check) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002931 Label miss;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002932
2933 if (check == PROPERTY) {
2934 GenerateNameCheck(name, this->name(), &miss);
2935 }
2936
2937 __ JumpIfSmi(receiver(), &miss);
2938 Register map_reg = scratch1();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002939
danno@chromium.org40cb8782011-05-25 07:58:50 +00002940 int receiver_count = receiver_maps->length();
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002941 __ lw(map_reg, FieldMemOperand(receiver(), HeapObject::kMapOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00002942 for (int current = 0; current < receiver_count; ++current) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002943 __ Jump(handlers->at(current), RelocInfo::CODE_TARGET,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002944 eq, map_reg, Operand(receiver_maps->at(current)));
danno@chromium.org40cb8782011-05-25 07:58:50 +00002945 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002946
2947 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002948 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002949
2950 // Return the generated code.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002951 InlineCacheState state =
2952 receiver_maps->length() > 1 ? POLYMORPHIC : MONOMORPHIC;
2953 return GetICCode(kind(), type, name, state);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002954}
2955
2956
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002957Handle<Code> KeyedStoreStubCompiler::CompileStorePolymorphic(
2958 MapHandleList* receiver_maps,
2959 CodeHandleList* handler_stubs,
2960 MapHandleList* transitioned_maps) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00002961 Label miss;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002962 __ JumpIfSmi(receiver(), &miss);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002963
2964 int receiver_count = receiver_maps->length();
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002965 __ lw(scratch1(), FieldMemOperand(receiver(), HeapObject::kMapOffset));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00002966 for (int i = 0; i < receiver_count; ++i) {
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002967 if (transitioned_maps->at(i).is_null()) {
2968 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET, eq,
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002969 scratch1(), Operand(receiver_maps->at(i)));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00002970 } else {
2971 Label next_map;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002972 __ Branch(&next_map, ne, scratch1(), Operand(receiver_maps->at(i)));
2973 __ li(transition_map(), Operand(transitioned_maps->at(i)));
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002974 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00002975 __ bind(&next_map);
2976 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00002977 }
2978
2979 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002980 TailCallBuiltin(masm(), MissBuiltin(kind()));
danno@chromium.org40cb8782011-05-25 07:58:50 +00002981
2982 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002983 return GetICCode(
2984 kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002985}
2986
2987
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002988Handle<Code> ConstructStubCompiler::CompileConstructStub(
2989 Handle<JSFunction> function) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002990 // a0 : argc
2991 // a1 : constructor
2992 // ra : return address
2993 // [sp] : last argument
2994 Label generic_stub_call;
2995
2996 // Use t7 for holding undefined which is used in several places below.
2997 __ LoadRoot(t7, Heap::kUndefinedValueRootIndex);
2998
2999#ifdef ENABLE_DEBUGGER_SUPPORT
3000 // Check to see whether there are any break points in the function code. If
3001 // there are jump to the generic constructor stub which calls the actual
3002 // code for the function thereby hitting the break points.
3003 __ lw(t5, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
3004 __ lw(a2, FieldMemOperand(t5, SharedFunctionInfo::kDebugInfoOffset));
3005 __ Branch(&generic_stub_call, ne, a2, Operand(t7));
3006#endif
3007
3008 // Load the initial map and verify that it is in fact a map.
3009 // a1: constructor function
3010 // t7: undefined
3011 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003012 __ JumpIfSmi(a2, &generic_stub_call);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003013 __ GetObjectType(a2, a3, t0);
3014 __ Branch(&generic_stub_call, ne, t0, Operand(MAP_TYPE));
3015
3016#ifdef DEBUG
3017 // Cannot construct functions this way.
3018 // a0: argc
3019 // a1: constructor function
3020 // a2: initial map
3021 // t7: undefined
3022 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceTypeOffset));
3023 __ Check(ne, "Function constructed by construct stub.",
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00003024 a3, Operand(JS_FUNCTION_TYPE));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003025#endif
3026
3027 // Now allocate the JSObject in new space.
3028 // a0: argc
3029 // a1: constructor function
3030 // a2: initial map
3031 // t7: undefined
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00003032 ASSERT(function->has_initial_map());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003033 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceSizeOffset));
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00003034#ifdef DEBUG
3035 int instance_size = function->initial_map()->instance_size();
3036 __ Check(eq, "Instance size of initial map changed.",
3037 a3, Operand(instance_size >> kPointerSizeLog2));
3038#endif
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +00003039 __ Allocate(a3, t4, t5, t6, &generic_stub_call, SIZE_IN_WORDS);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003040
3041 // Allocated the JSObject, now initialize the fields. Map is set to initial
3042 // map and properties and elements are set to empty fixed array.
3043 // a0: argc
3044 // a1: constructor function
3045 // a2: initial map
3046 // a3: object size (in words)
3047 // t4: JSObject (not tagged)
3048 // t7: undefined
3049 __ LoadRoot(t6, Heap::kEmptyFixedArrayRootIndex);
3050 __ mov(t5, t4);
3051 __ sw(a2, MemOperand(t5, JSObject::kMapOffset));
3052 __ sw(t6, MemOperand(t5, JSObject::kPropertiesOffset));
3053 __ sw(t6, MemOperand(t5, JSObject::kElementsOffset));
3054 __ Addu(t5, t5, Operand(3 * kPointerSize));
3055 ASSERT_EQ(0 * kPointerSize, JSObject::kMapOffset);
3056 ASSERT_EQ(1 * kPointerSize, JSObject::kPropertiesOffset);
3057 ASSERT_EQ(2 * kPointerSize, JSObject::kElementsOffset);
3058
3059
3060 // Calculate the location of the first argument. The stack contains only the
3061 // argc arguments.
3062 __ sll(a1, a0, kPointerSizeLog2);
3063 __ Addu(a1, a1, sp);
3064
3065 // Fill all the in-object properties with undefined.
3066 // a0: argc
3067 // a1: first argument
3068 // a3: object size (in words)
3069 // t4: JSObject (not tagged)
3070 // t5: First in-object property of JSObject (not tagged)
3071 // t7: undefined
3072 // Fill the initialized properties with a constant value or a passed argument
3073 // depending on the this.x = ...; assignment in the function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003074 Handle<SharedFunctionInfo> shared(function->shared());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003075 for (int i = 0; i < shared->this_property_assignments_count(); i++) {
3076 if (shared->IsThisPropertyAssignmentArgument(i)) {
3077 Label not_passed, next;
3078 // Check if the argument assigned to the property is actually passed.
3079 int arg_number = shared->GetThisPropertyAssignmentArgument(i);
3080 __ Branch(&not_passed, less_equal, a0, Operand(arg_number));
3081 // Argument passed - find it on the stack.
3082 __ lw(a2, MemOperand(a1, (arg_number + 1) * -kPointerSize));
3083 __ sw(a2, MemOperand(t5));
3084 __ Addu(t5, t5, kPointerSize);
3085 __ jmp(&next);
3086 __ bind(&not_passed);
3087 // Set the property to undefined.
3088 __ sw(t7, MemOperand(t5));
3089 __ Addu(t5, t5, Operand(kPointerSize));
3090 __ bind(&next);
3091 } else {
3092 // Set the property to the constant value.
ulan@chromium.org09d7ab52013-02-25 15:50:35 +00003093 Handle<Object> constant(shared->GetThisPropertyAssignmentConstant(i),
3094 masm()->isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003095 __ li(a2, Operand(constant));
3096 __ sw(a2, MemOperand(t5));
3097 __ Addu(t5, t5, kPointerSize);
3098 }
3099 }
3100
3101 // Fill the unused in-object property fields with undefined.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003102 for (int i = shared->this_property_assignments_count();
3103 i < function->initial_map()->inobject_properties();
3104 i++) {
3105 __ sw(t7, MemOperand(t5));
3106 __ Addu(t5, t5, kPointerSize);
3107 }
3108
3109 // a0: argc
3110 // t4: JSObject (not tagged)
3111 // Move argc to a1 and the JSObject to return to v0 and tag it.
3112 __ mov(a1, a0);
3113 __ mov(v0, t4);
3114 __ Or(v0, v0, Operand(kHeapObjectTag));
3115
3116 // v0: JSObject
3117 // a1: argc
3118 // Remove caller arguments and receiver from the stack and return.
3119 __ sll(t0, a1, kPointerSizeLog2);
3120 __ Addu(sp, sp, t0);
3121 __ Addu(sp, sp, Operand(kPointerSize));
3122 Counters* counters = masm()->isolate()->counters();
3123 __ IncrementCounter(counters->constructed_objects(), 1, a1, a2);
3124 __ IncrementCounter(counters->constructed_objects_stub(), 1, a1, a2);
3125 __ Ret();
3126
3127 // Jump to the generic stub in case the specialized code cannot handle the
3128 // construction.
3129 __ bind(&generic_stub_call);
3130 Handle<Code> generic_construct_stub =
3131 masm()->isolate()->builtins()->JSConstructStubGeneric();
3132 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET);
3133
3134 // Return the generated code.
3135 return GetCode();
3136}
3137
3138
danno@chromium.org40cb8782011-05-25 07:58:50 +00003139#undef __
3140#define __ ACCESS_MASM(masm)
3141
3142
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003143void KeyedLoadStubCompiler::GenerateLoadDictionaryElement(
3144 MacroAssembler* masm) {
3145 // ---------- S t a t e --------------
3146 // -- ra : return address
3147 // -- a0 : key
3148 // -- a1 : receiver
3149 // -----------------------------------
3150 Label slow, miss_force_generic;
3151
3152 Register key = a0;
3153 Register receiver = a1;
3154
3155 __ JumpIfNotSmi(key, &miss_force_generic);
3156 __ lw(t0, FieldMemOperand(receiver, JSObject::kElementsOffset));
3157 __ sra(a2, a0, kSmiTagSize);
3158 __ LoadFromNumberDictionary(&slow, t0, a0, v0, a2, a3, t1);
3159 __ Ret();
3160
3161 // Slow case, key and receiver still in a0 and a1.
3162 __ bind(&slow);
3163 __ IncrementCounter(
3164 masm->isolate()->counters()->keyed_load_external_array_slow(),
3165 1, a2, a3);
3166 // Entry registers are intact.
3167 // ---------- S t a t e --------------
3168 // -- ra : return address
3169 // -- a0 : key
3170 // -- a1 : receiver
3171 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003172 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003173
3174 // Miss case, call the runtime.
3175 __ bind(&miss_force_generic);
3176
3177 // ---------- S t a t e --------------
3178 // -- ra : return address
3179 // -- a0 : key
3180 // -- a1 : receiver
3181 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003182 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_MissForceGeneric);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003183}
3184
3185
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003186static void GenerateSmiKeyCheck(MacroAssembler* masm,
3187 Register key,
3188 Register scratch0,
3189 Register scratch1,
3190 FPURegister double_scratch0,
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003191 FPURegister double_scratch1,
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003192 Label* fail) {
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003193 Label key_ok;
3194 // Check for smi or a smi inside a heap number. We convert the heap
3195 // number and check if the conversion is exact and fits into the smi
3196 // range.
3197 __ JumpIfSmi(key, &key_ok);
3198 __ CheckMap(key,
3199 scratch0,
3200 Heap::kHeapNumberMapRootIndex,
3201 fail,
3202 DONT_DO_SMI_CHECK);
3203 __ ldc1(double_scratch0, FieldMemOperand(key, HeapNumber::kValueOffset));
3204 __ EmitFPUTruncate(kRoundToZero,
3205 scratch0,
3206 double_scratch0,
3207 at,
3208 double_scratch1,
3209 scratch1,
3210 kCheckForInexactConversion);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003211
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003212 __ Branch(fail, ne, scratch1, Operand(zero_reg));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003213
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003214 __ SmiTagCheckOverflow(key, scratch0, scratch1);
3215 __ BranchOnOverflow(fail, scratch1);
3216 __ bind(&key_ok);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003217}
3218
3219
danno@chromium.org40cb8782011-05-25 07:58:50 +00003220void KeyedStoreStubCompiler::GenerateStoreExternalArray(
3221 MacroAssembler* masm,
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003222 ElementsKind elements_kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003223 // ---------- S t a t e --------------
3224 // -- a0 : value
3225 // -- a1 : key
3226 // -- a2 : receiver
3227 // -- ra : return address
3228 // -----------------------------------
3229
danno@chromium.org40cb8782011-05-25 07:58:50 +00003230 Label slow, check_heap_number, miss_force_generic;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003231
3232 // Register usage.
3233 Register value = a0;
3234 Register key = a1;
3235 Register receiver = a2;
3236 // a3 mostly holds the elements array or the destination external array.
3237
danno@chromium.org40cb8782011-05-25 07:58:50 +00003238 // This stub is meant to be tail-jumped to, the receiver must already
3239 // have been verified by the caller to not be a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003240
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003241 // Check that the key is a smi or a heap number convertible to a smi.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003242 GenerateSmiKeyCheck(masm, key, t0, t1, f2, f4, &miss_force_generic);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003243
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003244 __ lw(a3, FieldMemOperand(receiver, JSObject::kElementsOffset));
3245
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003246 // Check that the index is in range.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003247 __ lw(t1, FieldMemOperand(a3, ExternalArray::kLengthOffset));
3248 // Unsigned comparison catches both negative and too-large values.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003249 __ Branch(&miss_force_generic, Ugreater_equal, key, Operand(t1));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003250
3251 // Handle both smis and HeapNumbers in the fast path. Go to the
3252 // runtime for all other kinds of values.
3253 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003254
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003255 if (elements_kind == EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003256 // Double to pixel conversion is only implemented in the runtime for now.
3257 __ JumpIfNotSmi(value, &slow);
3258 } else {
3259 __ JumpIfNotSmi(value, &check_heap_number);
3260 }
3261 __ SmiUntag(t1, value);
3262 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3263
3264 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003265 // t1: value (integer).
3266
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003267 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003268 case EXTERNAL_PIXEL_ELEMENTS: {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003269 // Clamp the value to [0..255].
3270 // v0 is used as a scratch register here.
3271 Label done;
3272 __ li(v0, Operand(255));
3273 // Normal branch: nop in delay slot.
3274 __ Branch(&done, gt, t1, Operand(v0));
3275 // Use delay slot in this branch.
3276 __ Branch(USE_DELAY_SLOT, &done, lt, t1, Operand(zero_reg));
3277 __ mov(v0, zero_reg); // In delay slot.
3278 __ mov(v0, t1); // Value is in range 0..255.
3279 __ bind(&done);
3280 __ mov(t1, v0);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003281
3282 __ srl(t8, key, 1);
3283 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003284 __ sb(t1, MemOperand(t8, 0));
3285 }
3286 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003287 case EXTERNAL_BYTE_ELEMENTS:
3288 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003289 __ srl(t8, key, 1);
3290 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003291 __ sb(t1, MemOperand(t8, 0));
3292 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003293 case EXTERNAL_SHORT_ELEMENTS:
3294 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003295 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003296 __ sh(t1, MemOperand(t8, 0));
3297 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003298 case EXTERNAL_INT_ELEMENTS:
3299 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003300 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003301 __ addu(t8, a3, t8);
3302 __ sw(t1, MemOperand(t8, 0));
3303 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003304 case EXTERNAL_FLOAT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003305 // Perform int-to-float conversion and store to memory.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003306 __ SmiUntag(t0, key);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003307 StoreIntAsFloat(masm, a3, t0, t1, t2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003308 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003309 case EXTERNAL_DOUBLE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003310 __ sll(t8, key, 2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003311 __ addu(a3, a3, t8);
3312 // a3: effective address of the double element
3313 FloatingPointHelper::Destination destination;
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003314 destination = FloatingPointHelper::kFPURegisters;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003315 FloatingPointHelper::ConvertIntToDouble(
danno@chromium.org40cb8782011-05-25 07:58:50 +00003316 masm, t1, destination,
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003317 f0, t2, t3, // These are: double_dst, dst_mantissa, dst_exponent.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003318 t0, f2); // These are: scratch2, single_scratch.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003319 __ sdc1(f0, MemOperand(a3, 0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003320 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003321 case FAST_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003322 case FAST_SMI_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003323 case FAST_DOUBLE_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003324 case FAST_HOLEY_ELEMENTS:
3325 case FAST_HOLEY_SMI_ELEMENTS:
3326 case FAST_HOLEY_DOUBLE_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003327 case DICTIONARY_ELEMENTS:
3328 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003329 UNREACHABLE();
3330 break;
3331 }
3332
3333 // Entry registers are intact, a0 holds the value which is the return value.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003334 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003335 __ Ret();
3336
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003337 if (elements_kind != EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003338 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003339 __ bind(&check_heap_number);
3340 __ GetObjectType(value, t1, t2);
3341 __ Branch(&slow, ne, t2, Operand(HEAP_NUMBER_TYPE));
3342
3343 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3344
3345 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003346
3347 // The WebGL specification leaves the behavior of storing NaN and
3348 // +/-Infinity into integer arrays basically undefined. For more
3349 // reproducible behavior, convert these to zero.
3350
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003351
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003352 __ ldc1(f0, FieldMemOperand(a0, HeapNumber::kValueOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003353
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003354 if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
3355 __ cvt_s_d(f0, f0);
3356 __ sll(t8, key, 1);
3357 __ addu(t8, a3, t8);
3358 __ swc1(f0, MemOperand(t8, 0));
3359 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
3360 __ sll(t8, key, 2);
3361 __ addu(t8, a3, t8);
3362 __ sdc1(f0, MemOperand(t8, 0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003363 } else {
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003364 __ EmitECMATruncate(t3, f0, f2, t2, t1, t5);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003365
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003366 switch (elements_kind) {
3367 case EXTERNAL_BYTE_ELEMENTS:
3368 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
3369 __ srl(t8, key, 1);
3370 __ addu(t8, a3, t8);
3371 __ sb(t3, MemOperand(t8, 0));
3372 break;
3373 case EXTERNAL_SHORT_ELEMENTS:
3374 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
3375 __ addu(t8, a3, key);
3376 __ sh(t3, MemOperand(t8, 0));
3377 break;
3378 case EXTERNAL_INT_ELEMENTS:
3379 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
3380 __ sll(t8, key, 1);
3381 __ addu(t8, a3, t8);
3382 __ sw(t3, MemOperand(t8, 0));
3383 break;
3384 case EXTERNAL_PIXEL_ELEMENTS:
3385 case EXTERNAL_FLOAT_ELEMENTS:
3386 case EXTERNAL_DOUBLE_ELEMENTS:
3387 case FAST_ELEMENTS:
3388 case FAST_SMI_ELEMENTS:
3389 case FAST_DOUBLE_ELEMENTS:
3390 case FAST_HOLEY_ELEMENTS:
3391 case FAST_HOLEY_SMI_ELEMENTS:
3392 case FAST_HOLEY_DOUBLE_ELEMENTS:
3393 case DICTIONARY_ELEMENTS:
3394 case NON_STRICT_ARGUMENTS_ELEMENTS:
3395 UNREACHABLE();
3396 break;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003397 }
3398 }
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003399
3400 // Entry registers are intact, a0 holds the value
3401 // which is the return value.
3402 __ mov(v0, a0);
3403 __ Ret();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003404 }
3405
danno@chromium.org40cb8782011-05-25 07:58:50 +00003406 // Slow case, key and receiver still in a0 and a1.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003407 __ bind(&slow);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003408 __ IncrementCounter(
3409 masm->isolate()->counters()->keyed_load_external_array_slow(),
3410 1, a2, a3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003411 // Entry registers are intact.
3412 // ---------- S t a t e --------------
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003413 // -- ra : return address
danno@chromium.org40cb8782011-05-25 07:58:50 +00003414 // -- a0 : key
3415 // -- a1 : receiver
3416 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003417 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003418
3419 // Miss case, call the runtime.
3420 __ bind(&miss_force_generic);
3421
3422 // ---------- S t a t e --------------
3423 // -- ra : return address
3424 // -- a0 : key
3425 // -- a1 : receiver
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003426 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003427 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003428}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003429
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003430
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003431void KeyedStoreStubCompiler::GenerateStoreFastElement(
3432 MacroAssembler* masm,
3433 bool is_js_array,
yangguo@chromium.org56454712012-02-16 15:33:53 +00003434 ElementsKind elements_kind,
ulan@chromium.org750145a2013-03-07 15:14:13 +00003435 KeyedAccessStoreMode store_mode) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003436 // ----------- S t a t e -------------
3437 // -- a0 : value
3438 // -- a1 : key
3439 // -- a2 : receiver
3440 // -- ra : return address
3441 // -- a3 : scratch
3442 // -- a4 : scratch (elements)
3443 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00003444 Label miss_force_generic, transition_elements_kind, grow, slow;
3445 Label finish_store, check_capacity;
danno@chromium.org40cb8782011-05-25 07:58:50 +00003446
3447 Register value_reg = a0;
3448 Register key_reg = a1;
3449 Register receiver_reg = a2;
yangguo@chromium.org56454712012-02-16 15:33:53 +00003450 Register scratch = t0;
3451 Register elements_reg = a3;
3452 Register length_reg = t1;
3453 Register scratch2 = t2;
danno@chromium.org40cb8782011-05-25 07:58:50 +00003454
3455 // This stub is meant to be tail-jumped to, the receiver must already
3456 // have been verified by the caller to not be a smi.
3457
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003458 // Check that the key is a smi or a heap number convertible to a smi.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003459 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, f4, &miss_force_generic);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003460
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003461 if (IsFastSmiElementsKind(elements_kind)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003462 __ JumpIfNotSmi(value_reg, &transition_elements_kind);
3463 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003464
3465 // Check that the key is within bounds.
yangguo@chromium.org56454712012-02-16 15:33:53 +00003466 __ lw(elements_reg,
3467 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003468 if (is_js_array) {
3469 __ lw(scratch, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3470 } else {
3471 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3472 }
3473 // Compare smis.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003474 if (is_js_array && IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003475 __ Branch(&grow, hs, key_reg, Operand(scratch));
3476 } else {
3477 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch));
3478 }
3479
3480 // Make sure elements is a fast element array, not 'cow'.
3481 __ CheckMap(elements_reg,
3482 scratch,
3483 Heap::kFixedArrayMapRootIndex,
3484 &miss_force_generic,
3485 DONT_DO_SMI_CHECK);
3486
3487 __ bind(&finish_store);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003488
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003489 if (IsFastSmiElementsKind(elements_kind)) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003490 __ Addu(scratch,
3491 elements_reg,
3492 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3493 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
3494 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
3495 __ Addu(scratch, scratch, scratch2);
3496 __ sw(value_reg, MemOperand(scratch));
3497 } else {
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003498 ASSERT(IsFastObjectElementsKind(elements_kind));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003499 __ Addu(scratch,
3500 elements_reg,
3501 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3502 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
3503 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
3504 __ Addu(scratch, scratch, scratch2);
3505 __ sw(value_reg, MemOperand(scratch));
3506 __ mov(receiver_reg, value_reg);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003507 __ RecordWrite(elements_reg, // Object.
3508 scratch, // Address.
3509 receiver_reg, // Value.
3510 kRAHasNotBeenSaved,
3511 kDontSaveFPRegs);
3512 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003513 // value_reg (a0) is preserved.
3514 // Done.
3515 __ Ret();
3516
3517 __ bind(&miss_force_generic);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003518 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003519
3520 __ bind(&transition_elements_kind);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003521 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Miss);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003522
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003523 if (is_js_array && IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003524 // Grow the array by a single element if possible.
3525 __ bind(&grow);
3526
3527 // Make sure the array is only growing by a single element, anything else
3528 // must be handled by the runtime.
3529 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch));
3530
3531 // Check for the empty array, and preallocate a small backing store if
3532 // possible.
3533 __ lw(length_reg,
3534 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3535 __ lw(elements_reg,
3536 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3537 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
3538 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
3539
3540 int size = FixedArray::SizeFor(JSArray::kPreallocatedArrayElements);
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003541 __ Allocate(size, elements_reg, scratch, scratch2, &slow, TAG_OBJECT);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003542
3543 __ LoadRoot(scratch, Heap::kFixedArrayMapRootIndex);
3544 __ sw(scratch, FieldMemOperand(elements_reg, JSObject::kMapOffset));
3545 __ li(scratch, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
3546 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3547 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
3548 for (int i = 1; i < JSArray::kPreallocatedArrayElements; ++i) {
3549 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::SizeFor(i)));
3550 }
3551
3552 // Store the element at index zero.
3553 __ sw(value_reg, FieldMemOperand(elements_reg, FixedArray::SizeFor(0)));
3554
3555 // Install the new backing store in the JSArray.
3556 __ sw(elements_reg,
3557 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3558 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
3559 scratch, kRAHasNotBeenSaved, kDontSaveFPRegs,
3560 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
3561
3562 // Increment the length of the array.
3563 __ li(length_reg, Operand(Smi::FromInt(1)));
3564 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3565 __ Ret();
3566
3567 __ bind(&check_capacity);
3568 // Check for cow elements, in general they are not handled by this stub
3569 __ CheckMap(elements_reg,
3570 scratch,
3571 Heap::kFixedCOWArrayMapRootIndex,
3572 &miss_force_generic,
3573 DONT_DO_SMI_CHECK);
3574
3575 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3576 __ Branch(&slow, hs, length_reg, Operand(scratch));
3577
3578 // Grow the array and finish the store.
3579 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
3580 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3581 __ jmp(&finish_store);
3582
3583 __ bind(&slow);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003584 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003585 }
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00003586}
3587
3588
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00003589void KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(
3590 MacroAssembler* masm,
yangguo@chromium.org56454712012-02-16 15:33:53 +00003591 bool is_js_array,
ulan@chromium.org750145a2013-03-07 15:14:13 +00003592 KeyedAccessStoreMode store_mode) {
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003593 // ----------- S t a t e -------------
3594 // -- a0 : value
3595 // -- a1 : key
3596 // -- a2 : receiver
3597 // -- ra : return address
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003598 // -- a3 : scratch (elements backing store)
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003599 // -- t0 : scratch (elements_reg)
3600 // -- t1 : scratch (mantissa_reg)
3601 // -- t2 : scratch (exponent_reg)
3602 // -- t3 : scratch4
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003603 // -- t4 : scratch
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003604 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00003605 Label miss_force_generic, transition_elements_kind, grow, slow;
3606 Label finish_store, check_capacity;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003607
3608 Register value_reg = a0;
3609 Register key_reg = a1;
3610 Register receiver_reg = a2;
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003611 Register elements_reg = a3;
3612 Register scratch1 = t0;
3613 Register scratch2 = t1;
3614 Register scratch3 = t2;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003615 Register scratch4 = t3;
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003616 Register scratch5 = t4;
yangguo@chromium.org56454712012-02-16 15:33:53 +00003617 Register length_reg = t3;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003618
3619 // This stub is meant to be tail-jumped to, the receiver must already
3620 // have been verified by the caller to not be a smi.
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003621
3622 // Check that the key is a smi or a heap number convertible to a smi.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003623 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, f4, &miss_force_generic);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003624
3625 __ lw(elements_reg,
3626 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3627
3628 // Check that the key is within bounds.
3629 if (is_js_array) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003630 __ lw(scratch1, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003631 } else {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003632 __ lw(scratch1,
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003633 FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3634 }
3635 // Compare smis, unsigned compare catches both negative and out-of-bound
3636 // indexes.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003637 if (IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003638 __ Branch(&grow, hs, key_reg, Operand(scratch1));
3639 } else {
3640 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch1));
3641 }
3642
3643 __ bind(&finish_store);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003644
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003645 __ StoreNumberToDoubleElements(value_reg,
3646 key_reg,
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00003647 // All registers after this are overwritten.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003648 elements_reg,
3649 scratch1,
3650 scratch2,
3651 scratch3,
3652 scratch4,
3653 &transition_elements_kind);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003654
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00003655 __ Ret(USE_DELAY_SLOT);
3656 __ mov(v0, value_reg); // In delay slot.
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003657
3658 // Handle store cache miss, replacing the ic with the generic stub.
3659 __ bind(&miss_force_generic);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003660 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003661
3662 __ bind(&transition_elements_kind);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003663 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Miss);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003664
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003665 if (is_js_array && IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003666 // Grow the array by a single element if possible.
3667 __ bind(&grow);
3668
3669 // Make sure the array is only growing by a single element, anything else
3670 // must be handled by the runtime.
3671 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch1));
3672
3673 // Transition on values that can't be stored in a FixedDoubleArray.
3674 Label value_is_smi;
3675 __ JumpIfSmi(value_reg, &value_is_smi);
3676 __ lw(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
3677 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex);
3678 __ Branch(&transition_elements_kind, ne, scratch1, Operand(at));
3679 __ bind(&value_is_smi);
3680
3681 // Check for the empty array, and preallocate a small backing store if
3682 // possible.
3683 __ lw(length_reg,
3684 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3685 __ lw(elements_reg,
3686 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3687 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
3688 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
3689
3690 int size = FixedDoubleArray::SizeFor(JSArray::kPreallocatedArrayElements);
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003691 __ Allocate(size, elements_reg, scratch1, scratch2, &slow, TAG_OBJECT);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003692
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003693 // Initialize the new FixedDoubleArray.
yangguo@chromium.org56454712012-02-16 15:33:53 +00003694 __ LoadRoot(scratch1, Heap::kFixedDoubleArrayMapRootIndex);
3695 __ sw(scratch1, FieldMemOperand(elements_reg, JSObject::kMapOffset));
3696 __ li(scratch1, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
3697 __ sw(scratch1,
3698 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
3699
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003700 __ mov(scratch1, elements_reg);
3701 __ StoreNumberToDoubleElements(value_reg,
3702 key_reg,
3703 // All registers after this are overwritten.
3704 scratch1,
3705 scratch2,
3706 scratch3,
3707 scratch4,
3708 scratch5,
3709 &transition_elements_kind);
3710
3711 __ li(scratch1, Operand(kHoleNanLower32));
3712 __ li(scratch2, Operand(kHoleNanUpper32));
3713 for (int i = 1; i < JSArray::kPreallocatedArrayElements; i++) {
3714 int offset = FixedDoubleArray::OffsetOfElementAt(i);
3715 __ sw(scratch1, FieldMemOperand(elements_reg, offset));
3716 __ sw(scratch2, FieldMemOperand(elements_reg, offset + kPointerSize));
3717 }
3718
yangguo@chromium.org56454712012-02-16 15:33:53 +00003719 // Install the new backing store in the JSArray.
3720 __ sw(elements_reg,
3721 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3722 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
3723 scratch1, kRAHasNotBeenSaved, kDontSaveFPRegs,
3724 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
3725
3726 // Increment the length of the array.
3727 __ li(length_reg, Operand(Smi::FromInt(1)));
3728 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
danno@chromium.org00379b82012-05-04 09:16:29 +00003729 __ lw(elements_reg,
3730 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003731 __ Ret();
yangguo@chromium.org56454712012-02-16 15:33:53 +00003732
3733 __ bind(&check_capacity);
3734 // Make sure that the backing store can hold additional elements.
3735 __ lw(scratch1,
3736 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
3737 __ Branch(&slow, hs, length_reg, Operand(scratch1));
3738
3739 // Grow the array and finish the store.
3740 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
3741 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3742 __ jmp(&finish_store);
3743
3744 __ bind(&slow);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003745 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003746 }
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00003747}
3748
3749
ager@chromium.org5c838252010-02-19 08:53:10 +00003750#undef __
3751
3752} } // namespace v8::internal
3753
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00003754#endif // V8_TARGET_ARCH_MIPS