blob: b2c78a38d6ff851483f274079a4710c7e5e3b405 [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
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000310void StubCompiler::GenerateFastPropertyLoad(MacroAssembler* masm,
311 Register dst,
312 Register src,
313 bool inobject,
314 int index,
315 Representation representation) {
316 ASSERT(!FLAG_track_double_fields || !representation.IsDouble());
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000317 int offset = index * kPointerSize;
318 if (!inobject) {
319 // Calculate the offset into the properties array.
320 offset = offset + FixedArray::kHeaderSize;
321 __ lw(dst, FieldMemOperand(src, JSObject::kPropertiesOffset));
322 src = dst;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000323 }
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000324 __ lw(dst, FieldMemOperand(src, offset));
ager@chromium.org5c838252010-02-19 08:53:10 +0000325}
326
327
328void StubCompiler::GenerateLoadArrayLength(MacroAssembler* masm,
329 Register receiver,
330 Register scratch,
331 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000332 // Check that the receiver isn't a smi.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000333 __ JumpIfSmi(receiver, miss_label);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000334
335 // Check that the object is a JS array.
336 __ GetObjectType(receiver, scratch, scratch);
337 __ Branch(miss_label, ne, scratch, Operand(JS_ARRAY_TYPE));
338
339 // Load length directly from the JS array.
verwaest@chromium.org8a00e822013-06-10 15:11:22 +0000340 __ Ret(USE_DELAY_SLOT);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000341 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000342}
343
344
345// Generate code to check if an object is a string. If the object is a
346// heap object, its map's instance type is left in the scratch1 register.
347// If this is not needed, scratch1 and scratch2 may be the same register.
348static void GenerateStringCheck(MacroAssembler* masm,
349 Register receiver,
350 Register scratch1,
351 Register scratch2,
352 Label* smi,
353 Label* non_string_object) {
354 // Check that the receiver isn't a smi.
355 __ JumpIfSmi(receiver, smi, t0);
356
357 // Check that the object is a string.
358 __ lw(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset));
359 __ lbu(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
360 __ And(scratch2, scratch1, Operand(kIsNotStringMask));
361 // The cast is to resolve the overload for the argument of 0x0.
362 __ Branch(non_string_object,
363 ne,
364 scratch2,
365 Operand(static_cast<int32_t>(kStringTag)));
ager@chromium.org5c838252010-02-19 08:53:10 +0000366}
367
368
lrn@chromium.org7516f052011-03-30 08:52:27 +0000369// Generate code to load the length from a string object and return the length.
370// If the receiver object is not a string or a wrapped string object the
371// execution continues at the miss label. The register containing the
372// receiver is potentially clobbered.
373void StubCompiler::GenerateLoadStringLength(MacroAssembler* masm,
374 Register receiver,
375 Register scratch1,
376 Register scratch2,
377 Label* miss,
378 bool support_wrappers) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000379 Label check_wrapper;
380
381 // Check if the object is a string leaving the instance type in the
382 // scratch1 register.
383 GenerateStringCheck(masm, receiver, scratch1, scratch2, miss,
384 support_wrappers ? &check_wrapper : miss);
385
386 // Load length directly from the string.
verwaest@chromium.org8a00e822013-06-10 15:11:22 +0000387 __ Ret(USE_DELAY_SLOT);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000388 __ lw(v0, FieldMemOperand(receiver, String::kLengthOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000389
390 if (support_wrappers) {
391 // Check if the object is a JSValue wrapper.
392 __ bind(&check_wrapper);
393 __ Branch(miss, ne, scratch1, Operand(JS_VALUE_TYPE));
394
395 // Unwrap the value and check if the wrapped value is a string.
396 __ lw(scratch1, FieldMemOperand(receiver, JSValue::kValueOffset));
397 GenerateStringCheck(masm, scratch1, scratch2, scratch2, miss, miss);
verwaest@chromium.org8a00e822013-06-10 15:11:22 +0000398 __ Ret(USE_DELAY_SLOT);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000399 __ lw(v0, FieldMemOperand(scratch1, String::kLengthOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000400 }
lrn@chromium.org7516f052011-03-30 08:52:27 +0000401}
402
403
ager@chromium.org5c838252010-02-19 08:53:10 +0000404void StubCompiler::GenerateLoadFunctionPrototype(MacroAssembler* masm,
405 Register receiver,
406 Register scratch1,
407 Register scratch2,
408 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000409 __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
verwaest@chromium.org8a00e822013-06-10 15:11:22 +0000410 __ Ret(USE_DELAY_SLOT);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000411 __ mov(v0, scratch1);
ager@chromium.org5c838252010-02-19 08:53:10 +0000412}
413
414
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000415// Generate code to check that a global property cell is empty. Create
416// the property cell at compilation time if no cell exists for the
417// property.
418static void GenerateCheckPropertyCell(MacroAssembler* masm,
419 Handle<GlobalObject> global,
420 Handle<Name> name,
421 Register scratch,
422 Label* miss) {
423 Handle<JSGlobalPropertyCell> cell =
424 GlobalObject::EnsurePropertyCell(global, name);
425 ASSERT(cell->value()->IsTheHole());
426 __ li(scratch, Operand(cell));
427 __ lw(scratch,
428 FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset));
429 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
430 __ Branch(miss, ne, scratch, Operand(at));
431}
432
433
434// Generate StoreTransition code, value is passed in a0 register.
ager@chromium.org5c838252010-02-19 08:53:10 +0000435// After executing generated code, the receiver_reg and name_reg
436// may be clobbered.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000437void StubCompiler::GenerateStoreTransition(MacroAssembler* masm,
438 Handle<JSObject> object,
439 LookupResult* lookup,
440 Handle<Map> transition,
441 Handle<Name> name,
442 Register receiver_reg,
443 Register name_reg,
444 Register value_reg,
445 Register scratch1,
446 Register scratch2,
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000447 Register scratch3,
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000448 Label* miss_label,
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000449 Label* miss_restore_name,
450 Label* slow) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000451 // a0 : value.
452 Label exit;
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000453
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +0000454 // Check that the map of the object hasn't changed.
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000455 __ CheckMap(receiver_reg, scratch1, Handle<Map>(object->map()), miss_label,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000456 DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000457
458 // Perform global security token check if needed.
459 if (object->IsJSGlobalProxy()) {
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000460 __ CheckAccessGlobalProxy(receiver_reg, scratch1, miss_label);
461 }
462
danno@chromium.orgf005df62013-04-30 16:36:45 +0000463 int descriptor = transition->LastAdded();
464 DescriptorArray* descriptors = transition->instance_descriptors();
465 PropertyDetails details = descriptors->GetDetails(descriptor);
466 Representation representation = details.representation();
467 ASSERT(!representation.IsNone());
468
469 // Ensure no transitions to deprecated maps are followed.
470 __ CheckMapDeprecated(transition, scratch1, miss_label);
471
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000472 // Check that we are allowed to write this.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000473 if (object->GetPrototype()->IsJSObject()) {
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000474 JSObject* holder;
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +0000475 // holder == object indicates that no property was found.
476 if (lookup->holder() != *object) {
477 holder = lookup->holder();
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000478 } else {
479 // Find the top object.
480 holder = *object;
481 do {
482 holder = JSObject::cast(holder->GetPrototype());
483 } while (holder->GetPrototype()->IsJSObject());
484 }
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +0000485 Register holder_reg = CheckPrototypes(
486 object, receiver_reg, Handle<JSObject>(holder), name_reg,
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000487 scratch1, scratch2, name, miss_restore_name, SKIP_RECEIVER);
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +0000488 // If no property was found, and the holder (the last object in the
489 // prototype chain) is in slow mode, we need to do a negative lookup on the
490 // holder.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000491 if (lookup->holder() == *object) {
492 if (holder->IsJSGlobalObject()) {
493 GenerateCheckPropertyCell(
494 masm,
495 Handle<GlobalObject>(GlobalObject::cast(holder)),
496 name,
497 scratch1,
498 miss_restore_name);
499 } else if (!holder->HasFastProperties() && !holder->IsJSGlobalProxy()) {
500 GenerateDictionaryNegativeLookup(
501 masm, miss_restore_name, holder_reg, name, scratch1, scratch2);
502 }
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +0000503 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000504 }
505
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000506 Register storage_reg = name_reg;
507
508 if (FLAG_track_fields && representation.IsSmi()) {
509 __ JumpIfNotSmi(value_reg, miss_restore_name);
ulan@chromium.org906e2fb2013-05-14 08:14:38 +0000510 } else if (FLAG_track_heap_object_fields && representation.IsHeapObject()) {
511 __ JumpIfSmi(value_reg, miss_restore_name);
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000512 } else if (FLAG_track_double_fields && representation.IsDouble()) {
513 Label do_store, heap_number;
514 __ LoadRoot(scratch3, Heap::kHeapNumberMapRootIndex);
515 __ AllocateHeapNumber(storage_reg, scratch1, scratch2, scratch3, slow);
516
517 __ JumpIfNotSmi(value_reg, &heap_number);
518 __ SmiUntag(scratch1, value_reg);
519 __ mtc1(scratch1, f6);
520 __ cvt_d_w(f4, f6);
521 __ jmp(&do_store);
522
523 __ bind(&heap_number);
524 __ CheckMap(value_reg, scratch1, Heap::kHeapNumberMapRootIndex,
525 miss_restore_name, DONT_DO_SMI_CHECK);
526 __ ldc1(f4, FieldMemOperand(value_reg, HeapNumber::kValueOffset));
527
528 __ bind(&do_store);
529 __ sdc1(f4, FieldMemOperand(storage_reg, HeapNumber::kValueOffset));
530 }
531
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000532 // Stub never generated for non-global objects that require access
533 // checks.
534 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
535
536 // Perform map transition for the receiver if necessary.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000537 if (object->map()->unused_property_fields() == 0) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000538 // The properties must be extended before we can store the value.
539 // We jump to a runtime call that extends the properties array.
540 __ push(receiver_reg);
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000541 __ li(a2, Operand(transition));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000542 __ Push(a2, a0);
543 __ TailCallExternalReference(
544 ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
545 masm->isolate()),
546 3, 1);
547 return;
548 }
549
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000550 // Update the map of the object.
551 __ li(scratch1, Operand(transition));
552 __ sw(scratch1, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
verwaest@chromium.org37141392012-05-31 13:27:02 +0000553
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000554 // Update the write barrier for the map field and pass the now unused
555 // name_reg as scratch register.
556 __ RecordWriteField(receiver_reg,
557 HeapObject::kMapOffset,
558 scratch1,
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000559 scratch2,
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000560 kRAHasNotBeenSaved,
561 kDontSaveFPRegs,
562 OMIT_REMEMBERED_SET,
563 OMIT_SMI_CHECK);
564
565 int index = transition->instance_descriptors()->GetFieldIndex(
566 transition->LastAdded());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000567
568 // Adjust for the number of properties stored in the object. Even in the
569 // face of a transition we can use the old map here because the size of the
570 // object and the number of in-object properties is not going to change.
571 index -= object->map()->inobject_properties();
572
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000573 // TODO(verwaest): Share this code as a code stub.
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000574 SmiCheck smi_check = representation.IsTagged()
575 ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000576 if (index < 0) {
577 // Set the property straight into the object.
578 int offset = object->map()->instance_size() + (index * kPointerSize);
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000579 if (FLAG_track_double_fields && representation.IsDouble()) {
580 __ sw(storage_reg, FieldMemOperand(receiver_reg, offset));
581 } else {
582 __ sw(value_reg, FieldMemOperand(receiver_reg, offset));
583 }
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000584
danno@chromium.orgf005df62013-04-30 16:36:45 +0000585 if (!FLAG_track_fields || !representation.IsSmi()) {
586 // Skip updating write barrier if storing a smi.
587 __ JumpIfSmi(value_reg, &exit);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000588
danno@chromium.orgf005df62013-04-30 16:36:45 +0000589 // Update the write barrier for the array address.
590 // Pass the now unused name_reg as a scratch register.
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000591 if (!FLAG_track_double_fields || !representation.IsDouble()) {
592 __ mov(name_reg, value_reg);
593 } else {
594 ASSERT(storage_reg.is(name_reg));
595 }
danno@chromium.orgf005df62013-04-30 16:36:45 +0000596 __ RecordWriteField(receiver_reg,
597 offset,
598 name_reg,
599 scratch1,
600 kRAHasNotBeenSaved,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000601 kDontSaveFPRegs,
602 EMIT_REMEMBERED_SET,
603 smi_check);
danno@chromium.orgf005df62013-04-30 16:36:45 +0000604 }
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000605 } else {
606 // Write to the properties array.
607 int offset = index * kPointerSize + FixedArray::kHeaderSize;
608 // Get the properties array
609 __ lw(scratch1,
610 FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000611 if (FLAG_track_double_fields && representation.IsDouble()) {
612 __ sw(storage_reg, FieldMemOperand(scratch1, offset));
613 } else {
614 __ sw(value_reg, FieldMemOperand(scratch1, offset));
615 }
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000616
danno@chromium.orgf005df62013-04-30 16:36:45 +0000617 if (!FLAG_track_fields || !representation.IsSmi()) {
618 // Skip updating write barrier if storing a smi.
619 __ JumpIfSmi(value_reg, &exit);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000620
danno@chromium.orgf005df62013-04-30 16:36:45 +0000621 // Update the write barrier for the array address.
622 // Ok to clobber receiver_reg and name_reg, since we return.
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000623 if (!FLAG_track_double_fields || !representation.IsDouble()) {
624 __ mov(name_reg, value_reg);
625 } else {
626 ASSERT(storage_reg.is(name_reg));
627 }
danno@chromium.orgf005df62013-04-30 16:36:45 +0000628 __ RecordWriteField(scratch1,
629 offset,
630 name_reg,
631 receiver_reg,
632 kRAHasNotBeenSaved,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000633 kDontSaveFPRegs,
634 EMIT_REMEMBERED_SET,
635 smi_check);
danno@chromium.orgf005df62013-04-30 16:36:45 +0000636 }
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000637 }
638
639 // Return the value (register v0).
640 ASSERT(value_reg.is(a0));
641 __ bind(&exit);
verwaest@chromium.org8a00e822013-06-10 15:11:22 +0000642 __ Ret(USE_DELAY_SLOT);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000643 __ mov(v0, a0);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000644}
645
646
647// Generate StoreField code, value is passed in a0 register.
648// When leaving generated code after success, the receiver_reg and name_reg
649// may be clobbered. Upon branch to miss_label, the receiver and name
650// registers have their original values.
651void StubCompiler::GenerateStoreField(MacroAssembler* masm,
652 Handle<JSObject> object,
653 LookupResult* lookup,
654 Register receiver_reg,
655 Register name_reg,
656 Register value_reg,
657 Register scratch1,
658 Register scratch2,
659 Label* miss_label) {
660 // a0 : value
661 Label exit;
662
663 // Check that the map of the object hasn't changed.
664 __ CheckMap(receiver_reg, scratch1, Handle<Map>(object->map()), miss_label,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000665 DO_SMI_CHECK);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000666
667 // Perform global security token check if needed.
668 if (object->IsJSGlobalProxy()) {
669 __ CheckAccessGlobalProxy(receiver_reg, scratch1, miss_label);
670 }
671
672 // Stub never generated for non-global objects that require access
673 // checks.
674 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
675
676 int index = lookup->GetFieldIndex().field_index();
677
678 // Adjust for the number of properties stored in the object. Even in the
679 // face of a transition we can use the old map here because the size of the
680 // object and the number of in-object properties is not going to change.
681 index -= object->map()->inobject_properties();
682
danno@chromium.orgf005df62013-04-30 16:36:45 +0000683 Representation representation = lookup->representation();
684 ASSERT(!representation.IsNone());
685 if (FLAG_track_fields && representation.IsSmi()) {
686 __ JumpIfNotSmi(value_reg, miss_label);
ulan@chromium.org906e2fb2013-05-14 08:14:38 +0000687 } else if (FLAG_track_heap_object_fields && representation.IsHeapObject()) {
688 __ JumpIfSmi(value_reg, miss_label);
danno@chromium.orgf005df62013-04-30 16:36:45 +0000689 } else if (FLAG_track_double_fields && representation.IsDouble()) {
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000690 // Load the double storage.
691 if (index < 0) {
692 int offset = object->map()->instance_size() + (index * kPointerSize);
693 __ lw(scratch1, FieldMemOperand(receiver_reg, offset));
694 } else {
695 __ lw(scratch1,
696 FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
697 int offset = index * kPointerSize + FixedArray::kHeaderSize;
698 __ lw(scratch1, FieldMemOperand(scratch1, offset));
699 }
700
701 // Store the value into the storage.
702 Label do_store, heap_number;
703 __ JumpIfNotSmi(value_reg, &heap_number);
704 __ SmiUntag(scratch2, value_reg);
705 __ mtc1(scratch2, f6);
706 __ cvt_d_w(f4, f6);
707 __ jmp(&do_store);
708
709 __ bind(&heap_number);
710 __ CheckMap(value_reg, scratch2, Heap::kHeapNumberMapRootIndex,
danno@chromium.orgf005df62013-04-30 16:36:45 +0000711 miss_label, DONT_DO_SMI_CHECK);
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000712 __ ldc1(f4, FieldMemOperand(value_reg, HeapNumber::kValueOffset));
713
danno@chromium.orgf005df62013-04-30 16:36:45 +0000714 __ bind(&do_store);
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000715 __ sdc1(f4, FieldMemOperand(scratch1, HeapNumber::kValueOffset));
716 // Return the value (register v0).
717 ASSERT(value_reg.is(a0));
verwaest@chromium.org8a00e822013-06-10 15:11:22 +0000718 __ Ret(USE_DELAY_SLOT);
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000719 __ mov(v0, a0);
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000720 return;
danno@chromium.orgf005df62013-04-30 16:36:45 +0000721 }
722
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000723 // TODO(verwaest): Share this code as a code stub.
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000724 SmiCheck smi_check = representation.IsTagged()
725 ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000726 if (index < 0) {
727 // Set the property straight into the object.
728 int offset = object->map()->instance_size() + (index * kPointerSize);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000729 __ sw(value_reg, FieldMemOperand(receiver_reg, offset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000730
danno@chromium.orgf005df62013-04-30 16:36:45 +0000731 if (!FLAG_track_fields || !representation.IsSmi()) {
732 // Skip updating write barrier if storing a smi.
733 __ JumpIfSmi(value_reg, &exit);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000734
danno@chromium.orgf005df62013-04-30 16:36:45 +0000735 // Update the write barrier for the array address.
736 // Pass the now unused name_reg as a scratch register.
737 __ mov(name_reg, value_reg);
738 __ RecordWriteField(receiver_reg,
739 offset,
740 name_reg,
741 scratch1,
742 kRAHasNotBeenSaved,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000743 kDontSaveFPRegs,
744 EMIT_REMEMBERED_SET,
745 smi_check);
danno@chromium.orgf005df62013-04-30 16:36:45 +0000746 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000747 } else {
748 // Write to the properties array.
749 int offset = index * kPointerSize + FixedArray::kHeaderSize;
750 // Get the properties array.
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000751 __ lw(scratch1,
752 FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000753 __ sw(value_reg, FieldMemOperand(scratch1, offset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000754
danno@chromium.orgf005df62013-04-30 16:36:45 +0000755 if (!FLAG_track_fields || !representation.IsSmi()) {
756 // Skip updating write barrier if storing a smi.
757 __ JumpIfSmi(value_reg, &exit);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000758
danno@chromium.orgf005df62013-04-30 16:36:45 +0000759 // Update the write barrier for the array address.
760 // Ok to clobber receiver_reg and name_reg, since we return.
761 __ mov(name_reg, value_reg);
762 __ RecordWriteField(scratch1,
763 offset,
764 name_reg,
765 receiver_reg,
766 kRAHasNotBeenSaved,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000767 kDontSaveFPRegs,
768 EMIT_REMEMBERED_SET,
769 smi_check);
danno@chromium.orgf005df62013-04-30 16:36:45 +0000770 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000771 }
772
773 // Return the value (register v0).
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000774 ASSERT(value_reg.is(a0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000775 __ bind(&exit);
verwaest@chromium.org8a00e822013-06-10 15:11:22 +0000776 __ Ret(USE_DELAY_SLOT);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000777 __ mov(v0, a0);
ager@chromium.org5c838252010-02-19 08:53:10 +0000778}
779
780
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000781void BaseStoreStubCompiler::GenerateRestoreName(MacroAssembler* masm,
782 Label* label,
783 Handle<Name> name) {
784 if (!label->is_unused()) {
785 __ bind(label);
786 __ li(this->name(), Operand(name));
787 }
mstarzinger@chromium.org068ea0a2013-01-30 09:39:44 +0000788}
789
790
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000791static void GenerateCallFunction(MacroAssembler* masm,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000792 Handle<Object> object,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000793 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000794 Label* miss,
795 Code::ExtraICState extra_ic_state) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000796 // ----------- S t a t e -------------
797 // -- a0: receiver
798 // -- a1: function to call
799 // -----------------------------------
800 // Check that the function really is a function.
801 __ JumpIfSmi(a1, miss);
802 __ GetObjectType(a1, a3, a3);
803 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
804
805 // Patch the receiver on the stack with the global proxy if
806 // necessary.
807 if (object->IsGlobalObject()) {
808 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
809 __ sw(a3, MemOperand(sp, arguments.immediate() * kPointerSize));
810 }
811
812 // Invoke the function.
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000813 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state)
814 ? CALL_AS_FUNCTION
815 : CALL_AS_METHOD;
816 __ InvokeFunction(a1, arguments, JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000817}
818
819
820static void PushInterceptorArguments(MacroAssembler* masm,
821 Register receiver,
822 Register holder,
823 Register name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000824 Handle<JSObject> holder_obj) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000825 __ push(name);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000826 Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
827 ASSERT(!masm->isolate()->heap()->InNewSpace(*interceptor));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000828 Register scratch = name;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000829 __ li(scratch, Operand(interceptor));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000830 __ Push(scratch, receiver, holder);
831 __ lw(scratch, FieldMemOperand(scratch, InterceptorInfo::kDataOffset));
832 __ push(scratch);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +0000833 __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000834 __ push(scratch);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000835}
836
837
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000838static void CompileCallLoadPropertyWithInterceptor(
839 MacroAssembler* masm,
840 Register receiver,
841 Register holder,
842 Register name,
843 Handle<JSObject> holder_obj) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000844 PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
845
846 ExternalReference ref =
847 ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorOnly),
848 masm->isolate());
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000849 __ PrepareCEntryArgs(6);
ulan@chromium.org6ff65142012-03-21 09:52:17 +0000850 __ PrepareCEntryFunction(ref);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000851
852 CEntryStub stub(1);
853 __ CallStub(&stub);
854}
855
856
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000857static const int kFastApiCallArguments = FunctionCallbackArguments::kArgsLength;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000858
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000859// Reserves space for the extra arguments to API function in the
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000860// caller's frame.
861//
862// These arguments are set by CheckPrototypes and GenerateFastApiDirectCall.
863static void ReserveSpaceForFastApiCall(MacroAssembler* masm,
864 Register scratch) {
865 ASSERT(Smi::FromInt(0) == 0);
866 for (int i = 0; i < kFastApiCallArguments; i++) {
867 __ push(zero_reg);
868 }
869}
870
871
872// Undoes the effects of ReserveSpaceForFastApiCall.
873static void FreeSpaceForFastApiCall(MacroAssembler* masm) {
874 __ Drop(kFastApiCallArguments);
875}
876
877
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000878static void GenerateFastApiDirectCall(MacroAssembler* masm,
879 const CallOptimization& optimization,
880 int argc) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000881 // ----------- S t a t e -------------
882 // -- sp[0] : holder (set by CheckPrototypes)
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000883 // -- sp[4] : callee JS function
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000884 // -- sp[8] : call data
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000885 // -- sp[12] : isolate
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000886 // -- sp[16] : ReturnValue
887 // -- sp[20] : last JS argument
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000888 // -- ...
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000889 // -- sp[(argc + 4) * 4] : first JS argument
890 // -- sp[(argc + 5) * 4] : receiver
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000891 // -----------------------------------
892 // Get the function and setup the context.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000893 Handle<JSFunction> function = optimization.constant_function();
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000894 __ LoadHeapObject(t1, function);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000895 __ lw(cp, FieldMemOperand(t1, JSFunction::kContextOffset));
896
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000897 // Pass the additional arguments.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000898 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
ulan@chromium.org09d7ab52013-02-25 15:50:35 +0000899 Handle<Object> call_data(api_call_info->data(), masm->isolate());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000900 if (masm->isolate()->heap()->InNewSpace(*call_data)) {
901 __ li(a0, api_call_info);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000902 __ lw(t2, FieldMemOperand(a0, CallHandlerInfo::kDataOffset));
903 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000904 __ li(t2, call_data);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000905 }
906
ulan@chromium.org32d7dba2013-04-24 10:59:06 +0000907 __ li(t3, Operand(ExternalReference::isolate_address(masm->isolate())));
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000908 // Store JS function, call data, isolate and ReturnValue.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000909 __ sw(t1, MemOperand(sp, 1 * kPointerSize));
910 __ sw(t2, MemOperand(sp, 2 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000911 __ sw(t3, MemOperand(sp, 3 * kPointerSize));
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000912 __ LoadRoot(t1, Heap::kUndefinedValueRootIndex);
913 __ sw(t1, MemOperand(sp, 4 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000914
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000915 // Prepare arguments.
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000916 __ Addu(a2, sp, Operand(4 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000917
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000918 // Allocate the v8::Arguments structure in the arguments' space since
919 // it's not controlled by GC.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000920 const int kApiStackSpace = 4;
921
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000922 FrameScope frame_scope(masm, StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000923 __ EnterExitFrame(false, kApiStackSpace);
924
925 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
926 // struct from the function (which is currently the case). This means we pass
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +0000927 // the first argument in a1 instead of a0, if returns_handle is true.
928 // CallApiFunctionAndReturn will set up a0.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000929
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000930 Address function_address = v8::ToCData<Address>(api_call_info->callback());
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000931 bool returns_handle =
932 !CallbackTable::ReturnsVoid(masm->isolate(), function_address);
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +0000933
934 Register first_arg = returns_handle ? a1 : a0;
935
936 // first_arg = v8::Arguments&
937 // Arguments is built at sp + 1 (sp is a reserved spot for ra).
938 __ Addu(first_arg, sp, kPointerSize);
939
940 // v8::Arguments::implicit_args_
941 __ sw(a2, MemOperand(first_arg, 0 * kPointerSize));
942 // v8::Arguments::values_
943 __ Addu(t0, a2, Operand(argc * kPointerSize));
944 __ sw(t0, MemOperand(first_arg, 1 * kPointerSize));
945 // v8::Arguments::length_ = argc
946 __ li(t0, Operand(argc));
947 __ sw(t0, MemOperand(first_arg, 2 * kPointerSize));
948 // v8::Arguments::is_construct_call = 0
949 __ sw(zero_reg, MemOperand(first_arg, 3 * kPointerSize));
950
951 const int kStackUnwindSpace = argc + kFastApiCallArguments + 1;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000952 ApiFunction fun(function_address);
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000953 ExternalReference::Type type =
954 returns_handle ?
955 ExternalReference::DIRECT_API_CALL :
956 ExternalReference::DIRECT_API_CALL_NEW;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000957 ExternalReference ref =
958 ExternalReference(&fun,
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000959 type,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000960 masm->isolate());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000961 AllowExternalCallThatCantCauseGC scope(masm);
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000962 __ CallApiFunctionAndReturn(ref,
963 kStackUnwindSpace,
964 returns_handle,
965 kFastApiCallArguments + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000966}
967
lrn@chromium.org7516f052011-03-30 08:52:27 +0000968class CallInterceptorCompiler BASE_EMBEDDED {
969 public:
970 CallInterceptorCompiler(StubCompiler* stub_compiler,
971 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000972 Register name,
973 Code::ExtraICState extra_ic_state)
lrn@chromium.org7516f052011-03-30 08:52:27 +0000974 : stub_compiler_(stub_compiler),
975 arguments_(arguments),
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000976 name_(name),
977 extra_ic_state_(extra_ic_state) {}
lrn@chromium.org7516f052011-03-30 08:52:27 +0000978
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000979 void Compile(MacroAssembler* masm,
980 Handle<JSObject> object,
981 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000982 Handle<Name> name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000983 LookupResult* lookup,
984 Register receiver,
985 Register scratch1,
986 Register scratch2,
987 Register scratch3,
988 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000989 ASSERT(holder->HasNamedInterceptor());
990 ASSERT(!holder->GetNamedInterceptor()->getter()->IsUndefined());
991
992 // Check that the receiver isn't a smi.
993 __ JumpIfSmi(receiver, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000994 CallOptimization optimization(lookup);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000995 if (optimization.is_constant_call()) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000996 CompileCacheable(masm, object, receiver, scratch1, scratch2, scratch3,
997 holder, lookup, name, optimization, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000998 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000999 CompileRegular(masm, object, receiver, scratch1, scratch2, scratch3,
1000 name, holder, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001001 }
1002 }
1003
1004 private:
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001005 void CompileCacheable(MacroAssembler* masm,
1006 Handle<JSObject> object,
1007 Register receiver,
1008 Register scratch1,
1009 Register scratch2,
1010 Register scratch3,
1011 Handle<JSObject> interceptor_holder,
1012 LookupResult* lookup,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001013 Handle<Name> name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001014 const CallOptimization& optimization,
1015 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001016 ASSERT(optimization.is_constant_call());
1017 ASSERT(!lookup->holder()->IsGlobalObject());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001018 Counters* counters = masm->isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001019 int depth1 = kInvalidProtoDepth;
1020 int depth2 = kInvalidProtoDepth;
1021 bool can_do_fast_api_call = false;
1022 if (optimization.is_simple_api_call() &&
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001023 !lookup->holder()->IsGlobalObject()) {
1024 depth1 = optimization.GetPrototypeDepthOfExpectedType(
1025 object, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001026 if (depth1 == kInvalidProtoDepth) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001027 depth2 = optimization.GetPrototypeDepthOfExpectedType(
1028 interceptor_holder, Handle<JSObject>(lookup->holder()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001029 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001030 can_do_fast_api_call =
1031 depth1 != kInvalidProtoDepth || depth2 != kInvalidProtoDepth;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001032 }
1033
1034 __ IncrementCounter(counters->call_const_interceptor(), 1,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001035 scratch1, scratch2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001036
1037 if (can_do_fast_api_call) {
1038 __ IncrementCounter(counters->call_const_interceptor_fast_api(), 1,
1039 scratch1, scratch2);
1040 ReserveSpaceForFastApiCall(masm, scratch1);
1041 }
1042
1043 // Check that the maps from receiver to interceptor's holder
1044 // haven't changed and thus we can invoke interceptor.
1045 Label miss_cleanup;
1046 Label* miss = can_do_fast_api_call ? &miss_cleanup : miss_label;
1047 Register holder =
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001048 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
1049 scratch1, scratch2, scratch3,
1050 name, depth1, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001051
1052 // Invoke an interceptor and if it provides a value,
1053 // branch to |regular_invoke|.
1054 Label regular_invoke;
1055 LoadWithInterceptor(masm, receiver, holder, interceptor_holder, scratch2,
1056 &regular_invoke);
1057
1058 // Interceptor returned nothing for this property. Try to use cached
1059 // constant function.
1060
1061 // Check that the maps from interceptor's holder to constant function's
1062 // holder haven't changed and thus we can use cached constant function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001063 if (*interceptor_holder != lookup->holder()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001064 stub_compiler_->CheckPrototypes(interceptor_holder, receiver,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001065 Handle<JSObject>(lookup->holder()),
1066 scratch1, scratch2, scratch3,
1067 name, depth2, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001068 } else {
1069 // CheckPrototypes has a side effect of fetching a 'holder'
1070 // for API (object which is instanceof for the signature). It's
1071 // safe to omit it here, as if present, it should be fetched
1072 // by the previous CheckPrototypes.
1073 ASSERT(depth2 == kInvalidProtoDepth);
1074 }
1075
1076 // Invoke function.
1077 if (can_do_fast_api_call) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001078 GenerateFastApiDirectCall(masm, optimization, arguments_.immediate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001079 } else {
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00001080 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state_)
1081 ? CALL_AS_FUNCTION
1082 : CALL_AS_METHOD;
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001083 Handle<JSFunction> function = optimization.constant_function();
1084 ParameterCount expected(function);
1085 __ InvokeFunction(function, expected, arguments_,
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001086 JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001087 }
1088
1089 // Deferred code for fast API call case---clean preallocated space.
1090 if (can_do_fast_api_call) {
1091 __ bind(&miss_cleanup);
1092 FreeSpaceForFastApiCall(masm);
1093 __ Branch(miss_label);
1094 }
1095
1096 // Invoke a regular function.
1097 __ bind(&regular_invoke);
1098 if (can_do_fast_api_call) {
1099 FreeSpaceForFastApiCall(masm);
1100 }
lrn@chromium.org7516f052011-03-30 08:52:27 +00001101 }
1102
1103 void CompileRegular(MacroAssembler* masm,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001104 Handle<JSObject> object,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001105 Register receiver,
1106 Register scratch1,
1107 Register scratch2,
1108 Register scratch3,
ulan@chromium.org6e196bf2013-03-13 09:38:22 +00001109 Handle<Name> name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001110 Handle<JSObject> interceptor_holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001111 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001112 Register holder =
1113 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001114 scratch1, scratch2, scratch3,
1115 name, miss_label);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001116
1117 // Call a runtime function to load the interceptor property.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001118 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001119 // Save the name_ register across the call.
1120 __ push(name_);
1121
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001122 PushInterceptorArguments(masm, receiver, holder, name_, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001123
1124 __ CallExternalReference(
1125 ExternalReference(
1126 IC_Utility(IC::kLoadPropertyWithInterceptorForCall),
1127 masm->isolate()),
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001128 6);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001129 // Restore the name_ register.
1130 __ pop(name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001131 // Leave the internal frame.
lrn@chromium.org7516f052011-03-30 08:52:27 +00001132 }
1133
1134 void LoadWithInterceptor(MacroAssembler* masm,
1135 Register receiver,
1136 Register holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001137 Handle<JSObject> holder_obj,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001138 Register scratch,
1139 Label* interceptor_succeeded) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001140 {
1141 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001142
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001143 __ Push(holder, name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001144 CompileCallLoadPropertyWithInterceptor(masm,
1145 receiver,
1146 holder,
1147 name_,
1148 holder_obj);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001149 __ pop(name_); // Restore the name.
1150 __ pop(receiver); // Restore the holder.
1151 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001152 // If interceptor returns no-result sentinel, call the constant function.
1153 __ LoadRoot(scratch, Heap::kNoInterceptorResultSentinelRootIndex);
1154 __ Branch(interceptor_succeeded, ne, v0, Operand(scratch));
lrn@chromium.org7516f052011-03-30 08:52:27 +00001155 }
1156
1157 StubCompiler* stub_compiler_;
1158 const ParameterCount& arguments_;
1159 Register name_;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00001160 Code::ExtraICState extra_ic_state_;
lrn@chromium.org7516f052011-03-30 08:52:27 +00001161};
1162
1163
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001164// Calls GenerateCheckPropertyCell for each global object in the prototype chain
1165// from object to (but not including) holder.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001166static void GenerateCheckPropertyCells(MacroAssembler* masm,
1167 Handle<JSObject> object,
1168 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001169 Handle<Name> name,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001170 Register scratch,
1171 Label* miss) {
1172 Handle<JSObject> current = object;
1173 while (!current.is_identical_to(holder)) {
1174 if (current->IsGlobalObject()) {
1175 GenerateCheckPropertyCell(masm,
1176 Handle<GlobalObject>::cast(current),
1177 name,
1178 scratch,
1179 miss);
1180 }
1181 current = Handle<JSObject>(JSObject::cast(current->GetPrototype()));
1182 }
1183}
1184
1185
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001186// Convert and store int passed in register ival to IEEE 754 single precision
1187// floating point value at memory location (dst + 4 * wordoffset)
1188// If FPU is available use it for conversion.
1189static void StoreIntAsFloat(MacroAssembler* masm,
1190 Register dst,
1191 Register wordoffset,
1192 Register ival,
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00001193 Register scratch1) {
1194 __ mtc1(ival, f0);
1195 __ cvt_s_w(f0, f0);
1196 __ sll(scratch1, wordoffset, 2);
1197 __ addu(scratch1, dst, scratch1);
1198 __ swc1(f0, MemOperand(scratch1, 0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001199}
1200
1201
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00001202void StubCompiler::GenerateTailCall(MacroAssembler* masm, Handle<Code> code) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001203 __ Jump(code, RelocInfo::CODE_TARGET);
1204}
1205
1206
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00001207#undef __
1208#define __ ACCESS_MASM(masm())
1209
1210
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001211Register StubCompiler::CheckPrototypes(Handle<JSObject> object,
1212 Register object_reg,
1213 Handle<JSObject> holder,
1214 Register holder_reg,
1215 Register scratch1,
1216 Register scratch2,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001217 Handle<Name> name,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001218 int save_at_depth,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001219 Label* miss,
1220 PrototypeCheckType check) {
1221 Handle<JSObject> first = object;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001222 // Make sure there's no overlap between holder and object registers.
1223 ASSERT(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
1224 ASSERT(!scratch2.is(object_reg) && !scratch2.is(holder_reg)
1225 && !scratch2.is(scratch1));
1226
1227 // Keep track of the current object in register reg.
1228 Register reg = object_reg;
1229 int depth = 0;
1230
1231 if (save_at_depth == depth) {
1232 __ sw(reg, MemOperand(sp));
1233 }
1234
1235 // Check the maps in the prototype chain.
1236 // Traverse the prototype chain from the object and do map checks.
1237 Handle<JSObject> current = object;
1238 while (!current.is_identical_to(holder)) {
1239 ++depth;
1240
1241 // Only global objects and objects that do not require access
1242 // checks are allowed in stubs.
1243 ASSERT(current->IsJSGlobalProxy() || !current->IsAccessCheckNeeded());
1244
1245 Handle<JSObject> prototype(JSObject::cast(current->GetPrototype()));
1246 if (!current->HasFastProperties() &&
1247 !current->IsJSGlobalObject() &&
1248 !current->IsJSGlobalProxy()) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001249 if (!name->IsUniqueName()) {
1250 ASSERT(name->IsString());
1251 name = factory()->InternalizeString(Handle<String>::cast(name));
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001252 }
1253 ASSERT(current->property_dictionary()->FindEntry(*name) ==
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001254 NameDictionary::kNotFound);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001255
1256 GenerateDictionaryNegativeLookup(masm(), miss, reg, name,
1257 scratch1, scratch2);
1258
1259 __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
1260 reg = holder_reg; // From now on the object will be in holder_reg.
1261 __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
1262 } else {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001263 Register map_reg = scratch1;
1264 if (!current.is_identical_to(first) || check == CHECK_ALL_MAPS) {
1265 Handle<Map> current_map(current->map());
1266 // CheckMap implicitly loads the map of |reg| into |map_reg|.
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +00001267 __ CheckMap(reg, map_reg, current_map, miss, DONT_DO_SMI_CHECK);
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001268 } else {
1269 __ lw(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
1270 }
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001271 // Check access rights to the global object. This has to happen after
1272 // the map check so that we know that the object is actually a global
1273 // object.
1274 if (current->IsJSGlobalProxy()) {
1275 __ CheckAccessGlobalProxy(reg, scratch2, miss);
1276 }
1277 reg = holder_reg; // From now on the object will be in holder_reg.
1278
1279 if (heap()->InNewSpace(*prototype)) {
1280 // The prototype is in new space; we cannot store a reference to it
1281 // in the code. Load it from the map.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001282 __ lw(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset));
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001283 } else {
1284 // The prototype is in old space; load it directly.
1285 __ li(reg, Operand(prototype));
1286 }
1287 }
1288
1289 if (save_at_depth == depth) {
1290 __ sw(reg, MemOperand(sp));
1291 }
1292
1293 // Go to the next object in the prototype chain.
1294 current = prototype;
1295 }
1296
1297 // Log the check depth.
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001298 LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001299
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001300 if (!holder.is_identical_to(first) || check == CHECK_ALL_MAPS) {
1301 // Check the holder map.
1302 __ CheckMap(reg, scratch1, Handle<Map>(holder->map()), miss,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +00001303 DONT_DO_SMI_CHECK);
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001304 }
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001305
1306 // Perform security check for access to the global object.
1307 ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded());
1308 if (holder->IsJSGlobalProxy()) {
1309 __ CheckAccessGlobalProxy(reg, scratch1, miss);
1310 }
1311
1312 // If we've skipped any global objects, it's not enough to verify that
1313 // their maps haven't changed. We also need to check that the property
1314 // cell for the property is still empty.
1315 GenerateCheckPropertyCells(masm(), object, holder, name, scratch1, miss);
1316
1317 // Return the register containing the holder.
1318 return reg;
1319}
1320
1321
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001322void BaseLoadStubCompiler::HandlerFrontendFooter(Label* success,
1323 Label* miss) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001324 if (!miss->is_unused()) {
1325 __ Branch(success);
1326 __ bind(miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00001327 TailCallBuiltin(masm(), MissBuiltin(kind()));
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001328 }
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001329}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001330
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001331
1332Register BaseLoadStubCompiler::CallbackHandlerFrontend(
1333 Handle<JSObject> object,
1334 Register object_reg,
1335 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001336 Handle<Name> name,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001337 Label* success,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001338 Handle<ExecutableAccessorInfo> callback) {
1339 Label miss;
1340
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001341 Register reg = HandlerFrontendHeader(object, object_reg, holder, name, &miss);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001342
1343 if (!holder->HasFastProperties() && !holder->IsJSGlobalObject()) {
1344 ASSERT(!reg.is(scratch2()));
1345 ASSERT(!reg.is(scratch3()));
1346 ASSERT(!reg.is(scratch4()));
1347
1348 // Load the properties dictionary.
1349 Register dictionary = scratch4();
1350 __ lw(dictionary, FieldMemOperand(reg, JSObject::kPropertiesOffset));
1351
1352 // Probe the dictionary.
1353 Label probe_done;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001354 NameDictionaryLookupStub::GeneratePositiveLookup(masm(),
1355 &miss,
1356 &probe_done,
1357 dictionary,
1358 this->name(),
1359 scratch2(),
1360 scratch3());
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001361 __ bind(&probe_done);
1362
1363 // If probing finds an entry in the dictionary, scratch3 contains the
1364 // pointer into the dictionary. Check that the value is the callback.
1365 Register pointer = scratch3();
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001366 const int kElementsStartOffset = NameDictionary::kHeaderSize +
1367 NameDictionary::kElementsStartIndex * kPointerSize;
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001368 const int kValueOffset = kElementsStartOffset + kPointerSize;
1369 __ lw(scratch2(), FieldMemOperand(pointer, kValueOffset));
1370 __ Branch(&miss, ne, scratch2(), Operand(callback));
1371 }
1372
1373 HandlerFrontendFooter(success, &miss);
1374 return reg;
1375}
1376
1377
1378void BaseLoadStubCompiler::NonexistentHandlerFrontend(
1379 Handle<JSObject> object,
1380 Handle<JSObject> last,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001381 Handle<Name> name,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001382 Label* success,
1383 Handle<GlobalObject> global) {
1384 Label miss;
1385
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00001386 HandlerFrontendHeader(object, receiver(), last, name, &miss);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001387
1388 // If the last object in the prototype chain is a global object,
1389 // check that the global property cell is empty.
1390 if (!global.is_null()) {
1391 GenerateCheckPropertyCell(masm(), global, name, scratch2(), &miss);
1392 }
1393
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001394 HandlerFrontendFooter(success, &miss);
1395}
1396
1397
1398void BaseLoadStubCompiler::GenerateLoadField(Register reg,
1399 Handle<JSObject> holder,
ulan@chromium.org57ff8812013-05-10 08:16:55 +00001400 PropertyIndex field,
1401 Representation representation) {
1402 if (!reg.is(receiver())) __ mov(receiver(), reg);
1403 if (kind() == Code::LOAD_IC) {
1404 LoadFieldStub stub(field.is_inobject(holder),
1405 field.translate(holder),
1406 representation);
1407 GenerateTailCall(masm(), stub.GetCode(isolate()));
1408 } else {
1409 KeyedLoadFieldStub stub(field.is_inobject(holder),
1410 field.translate(holder),
1411 representation);
1412 GenerateTailCall(masm(), stub.GetCode(isolate()));
1413 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001414}
1415
1416
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001417void BaseLoadStubCompiler::GenerateLoadConstant(Handle<JSFunction> value) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001418 // Return the constant value.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001419 __ LoadHeapObject(v0, value);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001420 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +00001421}
1422
1423
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001424void BaseLoadStubCompiler::GenerateLoadCallback(
1425 Register reg,
1426 Handle<ExecutableAccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001427 // Build AccessorInfo::args_ list on the stack and push property name below
1428 // the exit frame to make GC aware of them and store pointers to them.
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001429 __ push(receiver());
1430 __ mov(scratch2(), sp); // scratch2 = AccessorInfo::args_
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001431 if (heap()->InNewSpace(callback->data())) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001432 __ li(scratch3(), callback);
1433 __ lw(scratch3(), FieldMemOperand(scratch3(),
1434 ExecutableAccessorInfo::kDataOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001435 } else {
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001436 __ li(scratch3(), Handle<Object>(callback->data(), isolate()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001437 }
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +00001438 __ Subu(sp, sp, 5 * kPointerSize);
1439 __ sw(reg, MemOperand(sp, 4 * kPointerSize));
1440 __ sw(scratch3(), MemOperand(sp, 3 * kPointerSize));
jkummerow@chromium.orgc1184022013-05-28 16:58:15 +00001441 __ LoadRoot(scratch3(), Heap::kUndefinedValueRootIndex);
1442 __ li(scratch4(),
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001443 Operand(ExternalReference::isolate_address(isolate())));
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +00001444 __ sw(scratch3(), MemOperand(sp, 2 * kPointerSize));
1445 __ sw(scratch4(), MemOperand(sp, 1 * kPointerSize));
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001446 __ sw(name(), MemOperand(sp, 0 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001447
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +00001448 Address getter_address = v8::ToCData<Address>(callback->getter());
1449 bool returns_handle =
1450 !CallbackTable::ReturnsVoid(isolate(), getter_address);
1451
1452 Register first_arg = returns_handle ? a1 : a0;
1453 Register second_arg = returns_handle ? a2 : a1;
1454
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001455 __ mov(a2, scratch2()); // Saved in case scratch2 == a1.
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +00001456 __ mov(first_arg, sp); // (first argument - see note below) = Handle<Name>
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001457
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001458 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
1459 // struct from the function (which is currently the case). This means we pass
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +00001460 // the arguments in a1-a2 instead of a0-a1, if returns_handle is true.
1461 // CallApiFunctionAndReturn will set up a0.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001462
1463 const int kApiStackSpace = 1;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001464 FrameScope frame_scope(masm(), StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001465 __ EnterExitFrame(false, kApiStackSpace);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001466
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001467 // Create AccessorInfo instance on the stack above the exit frame with
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001468 // scratch2 (internal::Object** args_) as the data.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001469 __ sw(a2, MemOperand(sp, kPointerSize));
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +00001470 // (second argument - see note above) = AccessorInfo&
1471 __ Addu(second_arg, sp, kPointerSize);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001472
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +00001473 const int kStackUnwindSpace = kFastApiCallArguments + 1;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001474 ApiFunction fun(getter_address);
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +00001475 ExternalReference::Type type =
1476 returns_handle ?
1477 ExternalReference::DIRECT_GETTER_CALL :
1478 ExternalReference::DIRECT_GETTER_CALL_NEW;
1479
1480 ExternalReference ref = ExternalReference(&fun, type, isolate());
1481 __ CallApiFunctionAndReturn(ref,
1482 kStackUnwindSpace,
1483 returns_handle,
jkummerow@chromium.orgc1184022013-05-28 16:58:15 +00001484 4);
ager@chromium.org5c838252010-02-19 08:53:10 +00001485}
1486
1487
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001488void BaseLoadStubCompiler::GenerateLoadInterceptor(
1489 Register holder_reg,
1490 Handle<JSObject> object,
1491 Handle<JSObject> interceptor_holder,
1492 LookupResult* lookup,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001493 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001494 ASSERT(interceptor_holder->HasNamedInterceptor());
1495 ASSERT(!interceptor_holder->GetNamedInterceptor()->getter()->IsUndefined());
1496
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001497 // So far the most popular follow ups for interceptor loads are FIELD
1498 // and CALLBACKS, so inline only them, other cases may be added
1499 // later.
1500 bool compile_followup_inline = false;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001501 if (lookup->IsFound() && lookup->IsCacheable()) {
yangguo@chromium.orgde0db002012-06-22 13:44:28 +00001502 if (lookup->IsField()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001503 compile_followup_inline = true;
1504 } else if (lookup->type() == CALLBACKS &&
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00001505 lookup->GetCallbackObject()->IsExecutableAccessorInfo()) {
1506 ExecutableAccessorInfo* callback =
1507 ExecutableAccessorInfo::cast(lookup->GetCallbackObject());
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001508 compile_followup_inline = callback->getter() != NULL &&
1509 callback->IsCompatibleReceiver(*object);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001510 }
1511 }
1512
1513 if (compile_followup_inline) {
1514 // Compile the interceptor call, followed by inline code to load the
1515 // property from further up the prototype chain if the call fails.
1516 // Check that the maps haven't changed.
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001517 ASSERT(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001518
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001519 // Preserve the receiver register explicitly whenever it is different from
1520 // the holder and it is needed should the interceptor return without any
1521 // result. The CALLBACKS case needs the receiver to be passed into C++ code,
1522 // the FIELD case might cause a miss during the prototype check.
1523 bool must_perfrom_prototype_check = *interceptor_holder != lookup->holder();
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001524 bool must_preserve_receiver_reg = !receiver().is(holder_reg) &&
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001525 (lookup->type() == CALLBACKS || must_perfrom_prototype_check);
1526
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001527 // Save necessary data before invoking an interceptor.
1528 // Requires a frame to make GC aware of pushed pointers.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001529 {
1530 FrameScope frame_scope(masm(), StackFrame::INTERNAL);
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001531 if (must_preserve_receiver_reg) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001532 __ Push(receiver(), holder_reg, this->name());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001533 } else {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001534 __ Push(holder_reg, this->name());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001535 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001536 // Invoke an interceptor. Note: map checks from receiver to
1537 // interceptor's holder has been compiled before (see a caller
1538 // of this method).
1539 CompileCallLoadPropertyWithInterceptor(masm(),
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001540 receiver(),
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001541 holder_reg,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001542 this->name(),
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001543 interceptor_holder);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001544 // Check if interceptor provided a value for property. If it's
1545 // the case, return immediately.
1546 Label interceptor_failed;
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001547 __ LoadRoot(scratch1(), Heap::kNoInterceptorResultSentinelRootIndex);
1548 __ Branch(&interceptor_failed, eq, v0, Operand(scratch1()));
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001549 frame_scope.GenerateLeaveFrame();
1550 __ Ret();
1551
1552 __ bind(&interceptor_failed);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001553 __ pop(this->name());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001554 __ pop(holder_reg);
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001555 if (must_preserve_receiver_reg) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001556 __ pop(receiver());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001557 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001558 // Leave the internal frame.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001559 }
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001560 GenerateLoadPostInterceptor(holder_reg, interceptor_holder, name, lookup);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001561 } else { // !compile_followup_inline
1562 // Call the runtime system to load the interceptor.
1563 // Check that the maps haven't changed.
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001564 PushInterceptorArguments(masm(), receiver(), holder_reg,
1565 this->name(), interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001566
1567 ExternalReference ref = ExternalReference(
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001568 IC_Utility(IC::kLoadPropertyWithInterceptorForLoad), isolate());
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001569 __ TailCallExternalReference(ref, 6, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001570 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001571}
1572
1573
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001574void CallStubCompiler::GenerateNameCheck(Handle<Name> name, Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001575 if (kind_ == Code::KEYED_CALL_IC) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001576 __ Branch(miss, ne, a2, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001577 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001578}
1579
1580
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001581void CallStubCompiler::GenerateGlobalReceiverCheck(Handle<JSObject> object,
1582 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001583 Handle<Name> name,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001584 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001585 ASSERT(holder->IsGlobalObject());
1586
1587 // Get the number of arguments.
1588 const int argc = arguments().immediate();
1589
1590 // Get the receiver from the stack.
1591 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1592
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001593 // Check that the maps haven't changed.
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00001594 __ JumpIfSmi(a0, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001595 CheckPrototypes(object, a0, holder, a3, a1, t0, name, miss);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001596}
1597
1598
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001599void CallStubCompiler::GenerateLoadFunctionFromCell(
1600 Handle<JSGlobalPropertyCell> cell,
1601 Handle<JSFunction> function,
1602 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001603 // Get the value from the cell.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001604 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001605 __ lw(a1, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
1606
1607 // Check that the cell contains the same function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001608 if (heap()->InNewSpace(*function)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001609 // We can't embed a pointer to a function in new space so we have
1610 // to verify that the shared function info is unchanged. This has
1611 // the nice side effect that multiple closures based on the same
1612 // function can all use this call IC. Before we load through the
1613 // function, we have to verify that it still is a function.
1614 __ JumpIfSmi(a1, miss);
1615 __ GetObjectType(a1, a3, a3);
1616 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
1617
1618 // Check the shared function info. Make sure it hasn't changed.
1619 __ li(a3, Handle<SharedFunctionInfo>(function->shared()));
1620 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
1621 __ Branch(miss, ne, t0, Operand(a3));
1622 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001623 __ Branch(miss, ne, a1, Operand(function));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001624 }
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001625}
1626
1627
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001628void CallStubCompiler::GenerateMissBranch() {
1629 Handle<Code> code =
danno@chromium.org40cb8782011-05-25 07:58:50 +00001630 isolate()->stub_cache()->ComputeCallMiss(arguments().immediate(),
1631 kind_,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001632 extra_state_);
1633 __ Jump(code, RelocInfo::CODE_TARGET);
1634}
1635
1636
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001637Handle<Code> CallStubCompiler::CompileCallField(Handle<JSObject> object,
1638 Handle<JSObject> holder,
yangguo@chromium.orgfb377212012-11-16 14:43:43 +00001639 PropertyIndex index,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001640 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001641 // ----------- S t a t e -------------
1642 // -- a2 : name
1643 // -- ra : return address
1644 // -----------------------------------
1645 Label miss;
1646
1647 GenerateNameCheck(name, &miss);
1648
1649 const int argc = arguments().immediate();
1650
1651 // Get the receiver of the function from the stack into a0.
1652 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1653 // Check that the receiver isn't a smi.
1654 __ JumpIfSmi(a0, &miss, t0);
1655
1656 // Do the right check and compute the holder register.
1657 Register reg = CheckPrototypes(object, a0, holder, a1, a3, t0, name, &miss);
ulan@chromium.org57ff8812013-05-10 08:16:55 +00001658 GenerateFastPropertyLoad(masm(), a1, reg, index.is_inobject(holder),
1659 index.translate(holder), Representation::Tagged());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001660
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001661 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001662
1663 // Handle call cache miss.
1664 __ bind(&miss);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001665 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001666
1667 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00001668 return GetCode(Code::FIELD, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00001669}
1670
1671
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001672Handle<Code> CallStubCompiler::CompileArrayPushCall(
1673 Handle<Object> object,
1674 Handle<JSObject> holder,
1675 Handle<JSGlobalPropertyCell> cell,
1676 Handle<JSFunction> function,
1677 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001678 // ----------- S t a t e -------------
1679 // -- a2 : name
1680 // -- ra : return address
1681 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1682 // -- ...
1683 // -- sp[argc * 4] : receiver
1684 // -----------------------------------
1685
1686 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001687 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001688
1689 Label miss;
1690
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001691 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001692
1693 Register receiver = a1;
1694
1695 // Get the receiver from the stack.
1696 const int argc = arguments().immediate();
1697 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1698
1699 // Check that the receiver isn't a smi.
1700 __ JumpIfSmi(receiver, &miss);
1701
1702 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001703 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, a3, v0, t0,
1704 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001705
1706 if (argc == 0) {
1707 // Nothing to do, just return the length.
1708 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00001709 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001710 } else {
1711 Label call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001712 if (argc == 1) { // Otherwise fall through to call the builtin.
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001713 Label attempt_to_grow_elements, with_write_barrier, check_double;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001714
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001715 Register elements = t2;
1716 Register end_elements = t1;
1717 // Get the elements array of the object.
1718 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1719
1720 // Check that the elements are in fast mode and writable.
1721 __ CheckMap(elements,
1722 v0,
1723 Heap::kFixedArrayMapRootIndex,
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001724 &check_double,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001725 DONT_DO_SMI_CHECK);
1726
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001727 // Get the array's length into v0 and calculate new length.
1728 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1729 STATIC_ASSERT(kSmiTagSize == 1);
1730 STATIC_ASSERT(kSmiTag == 0);
1731 __ Addu(v0, v0, Operand(Smi::FromInt(argc)));
1732
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001733 // Get the elements' length.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001734 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1735
1736 // Check if we could survive without allocation.
1737 __ Branch(&attempt_to_grow_elements, gt, v0, Operand(t0));
1738
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001739 // Check if value is a smi.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001740 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize));
1741 __ JumpIfNotSmi(t0, &with_write_barrier);
1742
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001743 // Save new length.
1744 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1745
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001746 // Store the value.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001747 // We may need a register containing the address end_elements below,
1748 // so write back the value in end_elements.
1749 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1750 __ Addu(end_elements, elements, end_elements);
1751 const int kEndElementsOffset =
1752 FixedArray::kHeaderSize - kHeapObjectTag - argc * kPointerSize;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001753 __ Addu(end_elements, end_elements, kEndElementsOffset);
1754 __ sw(t0, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001755
1756 // Check for a smi.
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00001757 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001758
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001759 __ bind(&check_double);
1760
1761 // Check that the elements are in fast mode and writable.
1762 __ CheckMap(elements,
1763 a0,
1764 Heap::kFixedDoubleArrayMapRootIndex,
1765 &call_builtin,
1766 DONT_DO_SMI_CHECK);
1767
1768 // Get the array's length into r0 and calculate new length.
1769 __ lw(a0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1770 STATIC_ASSERT(kSmiTagSize == 1);
1771 STATIC_ASSERT(kSmiTag == 0);
1772 __ Addu(a0, a0, Operand(Smi::FromInt(argc)));
1773
1774 // Get the elements' length.
1775 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1776
1777 // Check if we could survive without allocation.
1778 __ Branch(&call_builtin, gt, a0, Operand(t0));
1779
1780 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize));
1781 __ StoreNumberToDoubleElements(
1782 t0, a0, elements, a3, t1, a2, t5,
1783 &call_builtin, argc * kDoubleSize);
1784
1785 // Save new length.
1786 __ sw(a0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1787
1788 // Check for a smi.
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00001789 __ DropAndRet(argc + 1);
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001790
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001791 __ bind(&with_write_barrier);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001792
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001793 __ lw(a3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1794
1795 if (FLAG_smi_only_arrays && !FLAG_trace_elements_transitions) {
1796 Label fast_object, not_fast_object;
1797 __ CheckFastObjectElements(a3, t3, &not_fast_object);
1798 __ jmp(&fast_object);
1799 // In case of fast smi-only, convert to fast object, otherwise bail out.
1800 __ bind(&not_fast_object);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001801 __ CheckFastSmiElements(a3, t3, &call_builtin);
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001802
1803 __ lw(t3, FieldMemOperand(t0, HeapObject::kMapOffset));
1804 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex);
1805 __ Branch(&call_builtin, eq, t3, Operand(at));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001806 // edx: receiver
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001807 // a3: map
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001808 Label try_holey_map;
1809 __ LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001810 FAST_ELEMENTS,
1811 a3,
1812 t3,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001813 &try_holey_map);
1814 __ mov(a2, receiver);
1815 ElementsTransitionGenerator::
yangguo@chromium.org28381b42013-01-21 14:39:38 +00001816 GenerateMapChangeElementsTransition(masm(),
1817 DONT_TRACK_ALLOCATION_SITE,
1818 NULL);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001819 __ jmp(&fast_object);
1820
1821 __ bind(&try_holey_map);
1822 __ LoadTransitionedArrayMapConditional(FAST_HOLEY_SMI_ELEMENTS,
1823 FAST_HOLEY_ELEMENTS,
1824 a3,
1825 t3,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001826 &call_builtin);
1827 __ mov(a2, receiver);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001828 ElementsTransitionGenerator::
yangguo@chromium.org28381b42013-01-21 14:39:38 +00001829 GenerateMapChangeElementsTransition(masm(),
1830 DONT_TRACK_ALLOCATION_SITE,
1831 NULL);
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001832 __ bind(&fast_object);
1833 } else {
1834 __ CheckFastObjectElements(a3, a3, &call_builtin);
1835 }
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001836
1837 // Save new length.
1838 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1839
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001840 // Store the value.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001841 // We may need a register containing the address end_elements below,
1842 // so write back the value in end_elements.
1843 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1844 __ Addu(end_elements, elements, end_elements);
1845 __ Addu(end_elements, end_elements, kEndElementsOffset);
1846 __ sw(t0, MemOperand(end_elements));
1847
1848 __ RecordWrite(elements,
1849 end_elements,
1850 t0,
1851 kRAHasNotBeenSaved,
1852 kDontSaveFPRegs,
1853 EMIT_REMEMBERED_SET,
1854 OMIT_SMI_CHECK);
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00001855 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001856
1857 __ bind(&attempt_to_grow_elements);
1858 // v0: array's length + 1.
1859 // t0: elements' length.
1860
1861 if (!FLAG_inline_new) {
1862 __ Branch(&call_builtin);
1863 }
1864
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001865 __ lw(a2, MemOperand(sp, (argc - 1) * kPointerSize));
1866 // Growing elements that are SMI-only requires special handling in case
1867 // the new element is non-Smi. For now, delegate to the builtin.
1868 Label no_fast_elements_check;
1869 __ JumpIfSmi(a2, &no_fast_elements_check);
1870 __ lw(t3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1871 __ CheckFastObjectElements(t3, t3, &call_builtin);
1872 __ bind(&no_fast_elements_check);
1873
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001874 ExternalReference new_space_allocation_top =
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001875 ExternalReference::new_space_allocation_top_address(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001876 ExternalReference new_space_allocation_limit =
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001877 ExternalReference::new_space_allocation_limit_address(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001878
1879 const int kAllocationDelta = 4;
1880 // Load top and check if it is the end of elements.
1881 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1882 __ Addu(end_elements, elements, end_elements);
1883 __ Addu(end_elements, end_elements, Operand(kEndElementsOffset));
1884 __ li(t3, Operand(new_space_allocation_top));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001885 __ lw(a3, MemOperand(t3));
1886 __ Branch(&call_builtin, ne, end_elements, Operand(a3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001887
1888 __ li(t5, Operand(new_space_allocation_limit));
1889 __ lw(t5, MemOperand(t5));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001890 __ Addu(a3, a3, Operand(kAllocationDelta * kPointerSize));
1891 __ Branch(&call_builtin, hi, a3, Operand(t5));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001892
1893 // We fit and could grow elements.
1894 // Update new_space_allocation_top.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001895 __ sw(a3, MemOperand(t3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001896 // Push the argument.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001897 __ sw(a2, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001898 // Fill the rest with holes.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001899 __ LoadRoot(a3, Heap::kTheHoleValueRootIndex);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001900 for (int i = 1; i < kAllocationDelta; i++) {
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001901 __ sw(a3, MemOperand(end_elements, i * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001902 }
1903
1904 // Update elements' and array's sizes.
1905 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1906 __ Addu(t0, t0, Operand(Smi::FromInt(kAllocationDelta)));
1907 __ sw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1908
1909 // Elements are in new space, so write barrier is not required.
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00001910 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001911 }
1912 __ bind(&call_builtin);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001913 __ TailCallExternalReference(
1914 ExternalReference(Builtins::c_ArrayPush, isolate()), argc + 1, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001915 }
1916
1917 // Handle call cache miss.
1918 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001919 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001920
1921 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001922 return GetCode(function);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001923}
1924
1925
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001926Handle<Code> CallStubCompiler::CompileArrayPopCall(
1927 Handle<Object> object,
1928 Handle<JSObject> holder,
1929 Handle<JSGlobalPropertyCell> cell,
1930 Handle<JSFunction> function,
1931 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001932 // ----------- S t a t e -------------
1933 // -- a2 : name
1934 // -- ra : return address
1935 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1936 // -- ...
1937 // -- sp[argc * 4] : receiver
1938 // -----------------------------------
1939
1940 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001941 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001942
1943 Label miss, return_undefined, call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001944 Register receiver = a1;
1945 Register elements = a3;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001946 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001947
1948 // Get the receiver from the stack.
1949 const int argc = arguments().immediate();
1950 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001951 // Check that the receiver isn't a smi.
1952 __ JumpIfSmi(receiver, &miss);
1953
1954 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001955 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, elements,
1956 t0, v0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001957
1958 // Get the elements array of the object.
1959 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1960
1961 // Check that the elements are in fast mode and writable.
danno@chromium.org40cb8782011-05-25 07:58:50 +00001962 __ CheckMap(elements,
1963 v0,
1964 Heap::kFixedArrayMapRootIndex,
1965 &call_builtin,
1966 DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001967
1968 // Get the array's length into t0 and calculate new length.
1969 __ lw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1970 __ Subu(t0, t0, Operand(Smi::FromInt(1)));
1971 __ Branch(&return_undefined, lt, t0, Operand(zero_reg));
1972
1973 // Get the last element.
1974 __ LoadRoot(t2, Heap::kTheHoleValueRootIndex);
1975 STATIC_ASSERT(kSmiTagSize == 1);
1976 STATIC_ASSERT(kSmiTag == 0);
1977 // We can't address the last element in one operation. Compute the more
1978 // expensive shift first, and use an offset later on.
1979 __ sll(t1, t0, kPointerSizeLog2 - kSmiTagSize);
1980 __ Addu(elements, elements, t1);
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00001981 __ lw(v0, FieldMemOperand(elements, FixedArray::kHeaderSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001982 __ Branch(&call_builtin, eq, v0, Operand(t2));
1983
1984 // Set the array's length.
1985 __ sw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1986
1987 // Fill with the hole.
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00001988 __ sw(t2, FieldMemOperand(elements, FixedArray::kHeaderSize));
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00001989 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001990
1991 __ bind(&return_undefined);
1992 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00001993 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001994
1995 __ bind(&call_builtin);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001996 __ TailCallExternalReference(
1997 ExternalReference(Builtins::c_ArrayPop, isolate()), argc + 1, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001998
1999 // Handle call cache miss.
2000 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002001 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002002
2003 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002004 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002005}
2006
2007
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002008Handle<Code> CallStubCompiler::CompileStringCharCodeAtCall(
2009 Handle<Object> object,
2010 Handle<JSObject> holder,
2011 Handle<JSGlobalPropertyCell> cell,
2012 Handle<JSFunction> function,
2013 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002014 // ----------- S t a t e -------------
2015 // -- a2 : function name
2016 // -- ra : return address
2017 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2018 // -- ...
2019 // -- sp[argc * 4] : receiver
2020 // -----------------------------------
2021
2022 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002023 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002024
2025 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002026 Label miss;
2027 Label name_miss;
2028 Label index_out_of_range;
2029
2030 Label* index_out_of_range_label = &index_out_of_range;
2031
danno@chromium.org40cb8782011-05-25 07:58:50 +00002032 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002033 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00002034 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002035 index_out_of_range_label = &miss;
2036 }
2037
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002038 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002039
2040 // Check that the maps starting from the prototype haven't changed.
2041 GenerateDirectLoadGlobalFunctionPrototype(masm(),
2042 Context::STRING_FUNCTION_INDEX,
2043 v0,
2044 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002045 ASSERT(!object.is_identical_to(holder));
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002046 CheckPrototypes(
2047 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
2048 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002049
2050 Register receiver = a1;
2051 Register index = t1;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002052 Register result = v0;
2053 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
2054 if (argc > 0) {
2055 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
2056 } else {
2057 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
2058 }
2059
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002060 StringCharCodeAtGenerator generator(receiver,
2061 index,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002062 result,
2063 &miss, // When not a string.
2064 &miss, // When not a number.
2065 index_out_of_range_label,
2066 STRING_INDEX_IS_NUMBER);
2067 generator.GenerateFast(masm());
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002068 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002069
2070 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002071 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002072
2073 if (index_out_of_range.is_linked()) {
2074 __ bind(&index_out_of_range);
2075 __ LoadRoot(v0, Heap::kNanValueRootIndex);
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002076 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002077 }
2078
2079 __ bind(&miss);
2080 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002081 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002082 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002083 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002084
2085 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002086 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002087}
2088
2089
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002090Handle<Code> CallStubCompiler::CompileStringCharAtCall(
2091 Handle<Object> object,
2092 Handle<JSObject> holder,
2093 Handle<JSGlobalPropertyCell> cell,
2094 Handle<JSFunction> function,
2095 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002096 // ----------- S t a t e -------------
2097 // -- a2 : function name
2098 // -- ra : return address
2099 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2100 // -- ...
2101 // -- sp[argc * 4] : receiver
2102 // -----------------------------------
2103
2104 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002105 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002106
2107 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002108 Label miss;
2109 Label name_miss;
2110 Label index_out_of_range;
2111 Label* index_out_of_range_label = &index_out_of_range;
danno@chromium.org40cb8782011-05-25 07:58:50 +00002112 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002113 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00002114 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002115 index_out_of_range_label = &miss;
2116 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002117 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002118
2119 // Check that the maps starting from the prototype haven't changed.
2120 GenerateDirectLoadGlobalFunctionPrototype(masm(),
2121 Context::STRING_FUNCTION_INDEX,
2122 v0,
2123 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002124 ASSERT(!object.is_identical_to(holder));
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002125 CheckPrototypes(
2126 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
2127 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002128
2129 Register receiver = v0;
2130 Register index = t1;
danno@chromium.orgc612e022011-11-10 11:38:15 +00002131 Register scratch = a3;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002132 Register result = v0;
2133 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
2134 if (argc > 0) {
2135 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
2136 } else {
2137 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
2138 }
2139
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002140 StringCharAtGenerator generator(receiver,
2141 index,
danno@chromium.orgc612e022011-11-10 11:38:15 +00002142 scratch,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002143 result,
2144 &miss, // When not a string.
2145 &miss, // When not a number.
2146 index_out_of_range_label,
2147 STRING_INDEX_IS_NUMBER);
2148 generator.GenerateFast(masm());
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002149 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002150
2151 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002152 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002153
2154 if (index_out_of_range.is_linked()) {
2155 __ bind(&index_out_of_range);
ulan@chromium.org750145a2013-03-07 15:14:13 +00002156 __ LoadRoot(v0, Heap::kempty_stringRootIndex);
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002157 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002158 }
2159
2160 __ bind(&miss);
2161 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002162 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002163 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002164 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002165
2166 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002167 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002168}
2169
2170
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002171Handle<Code> CallStubCompiler::CompileStringFromCharCodeCall(
2172 Handle<Object> object,
2173 Handle<JSObject> holder,
2174 Handle<JSGlobalPropertyCell> cell,
2175 Handle<JSFunction> function,
2176 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002177 // ----------- S t a t e -------------
2178 // -- a2 : function name
2179 // -- ra : return address
2180 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2181 // -- ...
2182 // -- sp[argc * 4] : receiver
2183 // -----------------------------------
2184
2185 const int argc = arguments().immediate();
2186
2187 // If the object is not a JSObject or we got an unexpected number of
2188 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002189 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002190
2191 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002192 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002193
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002194 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002195 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
2196
2197 STATIC_ASSERT(kSmiTag == 0);
2198 __ JumpIfSmi(a1, &miss);
2199
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002200 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
2201 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002202 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002203 ASSERT(cell->value() == *function);
2204 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2205 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002206 GenerateLoadFunctionFromCell(cell, function, &miss);
2207 }
2208
2209 // Load the char code argument.
2210 Register code = a1;
2211 __ lw(code, MemOperand(sp, 0 * kPointerSize));
2212
2213 // Check the code is a smi.
2214 Label slow;
2215 STATIC_ASSERT(kSmiTag == 0);
2216 __ JumpIfNotSmi(code, &slow);
2217
2218 // Convert the smi code to uint16.
2219 __ And(code, code, Operand(Smi::FromInt(0xffff)));
2220
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002221 StringCharFromCodeGenerator generator(code, v0);
2222 generator.GenerateFast(masm());
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002223 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002224
2225 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002226 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002227
2228 // Tail call the full function. We do not have to patch the receiver
2229 // because the function makes no use of it.
2230 __ bind(&slow);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002231 ParameterCount expected(function);
2232 __ InvokeFunction(function, expected, arguments(),
2233 JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002234
2235 __ bind(&miss);
2236 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002237 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002238
2239 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002240 return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002241}
2242
2243
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002244Handle<Code> CallStubCompiler::CompileMathFloorCall(
2245 Handle<Object> object,
2246 Handle<JSObject> holder,
2247 Handle<JSGlobalPropertyCell> cell,
2248 Handle<JSFunction> function,
2249 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002250 // ----------- S t a t e -------------
2251 // -- a2 : function name
2252 // -- ra : return address
2253 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2254 // -- ...
2255 // -- sp[argc * 4] : receiver
2256 // -----------------------------------
2257
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002258
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002259 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002260 // If the object is not a JSObject or we got an unexpected number of
2261 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002262 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002263
2264 Label miss, slow;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002265 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002266
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002267 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002268 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002269 STATIC_ASSERT(kSmiTag == 0);
2270 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002271 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2272 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002273 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002274 ASSERT(cell->value() == *function);
2275 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2276 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002277 GenerateLoadFunctionFromCell(cell, function, &miss);
2278 }
2279
2280 // Load the (only) argument into v0.
2281 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2282
2283 // If the argument is a smi, just return.
2284 STATIC_ASSERT(kSmiTag == 0);
2285 __ And(t0, v0, Operand(kSmiTagMask));
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002286 __ DropAndRet(argc + 1, eq, t0, Operand(zero_reg));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002287
danno@chromium.org40cb8782011-05-25 07:58:50 +00002288 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002289
2290 Label wont_fit_smi, no_fpu_error, restore_fcsr_and_return;
2291
2292 // If fpu is enabled, we use the floor instruction.
2293
2294 // Load the HeapNumber value.
2295 __ ldc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
2296
2297 // Backup FCSR.
2298 __ cfc1(a3, FCSR);
2299 // Clearing FCSR clears the exception mask with no side-effects.
2300 __ ctc1(zero_reg, FCSR);
2301 // Convert the argument to an integer.
2302 __ floor_w_d(f0, f0);
2303
2304 // Start checking for special cases.
2305 // Get the argument exponent and clear the sign bit.
2306 __ lw(t1, FieldMemOperand(v0, HeapNumber::kValueOffset + kPointerSize));
2307 __ And(t2, t1, Operand(~HeapNumber::kSignMask));
2308 __ srl(t2, t2, HeapNumber::kMantissaBitsInTopWord);
2309
2310 // Retrieve FCSR and check for fpu errors.
2311 __ cfc1(t5, FCSR);
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002312 __ And(t5, t5, Operand(kFCSRExceptionFlagMask));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002313 __ Branch(&no_fpu_error, eq, t5, Operand(zero_reg));
2314
2315 // Check for NaN, Infinity, and -Infinity.
2316 // They are invariant through a Math.Floor call, so just
2317 // return the original argument.
2318 __ Subu(t3, t2, Operand(HeapNumber::kExponentMask
2319 >> HeapNumber::kMantissaBitsInTopWord));
2320 __ Branch(&restore_fcsr_and_return, eq, t3, Operand(zero_reg));
2321 // We had an overflow or underflow in the conversion. Check if we
2322 // have a big exponent.
2323 // If greater or equal, the argument is already round and in v0.
2324 __ Branch(&restore_fcsr_and_return, ge, t3,
2325 Operand(HeapNumber::kMantissaBits));
2326 __ Branch(&wont_fit_smi);
2327
2328 __ bind(&no_fpu_error);
2329 // Move the result back to v0.
2330 __ mfc1(v0, f0);
2331 // Check if the result fits into a smi.
2332 __ Addu(a1, v0, Operand(0x40000000));
2333 __ Branch(&wont_fit_smi, lt, a1, Operand(zero_reg));
2334 // Tag the result.
2335 STATIC_ASSERT(kSmiTag == 0);
2336 __ sll(v0, v0, kSmiTagSize);
2337
2338 // Check for -0.
2339 __ Branch(&restore_fcsr_and_return, ne, v0, Operand(zero_reg));
2340 // t1 already holds the HeapNumber exponent.
2341 __ And(t0, t1, Operand(HeapNumber::kSignMask));
2342 // If our HeapNumber is negative it was -0, so load its address and return.
2343 // Else v0 is loaded with 0, so we can also just return.
2344 __ Branch(&restore_fcsr_and_return, eq, t0, Operand(zero_reg));
2345 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2346
2347 __ bind(&restore_fcsr_and_return);
2348 // Restore FCSR and return.
2349 __ ctc1(a3, FCSR);
2350
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002351 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002352
2353 __ bind(&wont_fit_smi);
2354 // Restore FCSR and fall to slow case.
2355 __ ctc1(a3, FCSR);
2356
2357 __ bind(&slow);
2358 // Tail call the full function. We do not have to patch the receiver
2359 // because the function makes no use of it.
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002360 ParameterCount expected(function);
2361 __ InvokeFunction(function, expected, arguments(),
2362 JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002363
2364 __ bind(&miss);
2365 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002366 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002367
2368 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002369 return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002370}
2371
2372
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002373Handle<Code> CallStubCompiler::CompileMathAbsCall(
2374 Handle<Object> object,
2375 Handle<JSObject> holder,
2376 Handle<JSGlobalPropertyCell> cell,
2377 Handle<JSFunction> function,
2378 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002379 // ----------- S t a t e -------------
2380 // -- a2 : function name
2381 // -- ra : return address
2382 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2383 // -- ...
2384 // -- sp[argc * 4] : receiver
2385 // -----------------------------------
2386
2387 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002388 // If the object is not a JSObject or we got an unexpected number of
2389 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002390 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002391
2392 Label miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002393
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002394 GenerateNameCheck(name, &miss);
2395 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002396 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002397 STATIC_ASSERT(kSmiTag == 0);
2398 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002399 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
2400 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002401 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002402 ASSERT(cell->value() == *function);
2403 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2404 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002405 GenerateLoadFunctionFromCell(cell, function, &miss);
2406 }
2407
2408 // Load the (only) argument into v0.
2409 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2410
2411 // Check if the argument is a smi.
2412 Label not_smi;
2413 STATIC_ASSERT(kSmiTag == 0);
2414 __ JumpIfNotSmi(v0, &not_smi);
2415
2416 // Do bitwise not or do nothing depending on the sign of the
2417 // argument.
2418 __ sra(t0, v0, kBitsPerInt - 1);
2419 __ Xor(a1, v0, t0);
2420
2421 // Add 1 or do nothing depending on the sign of the argument.
2422 __ Subu(v0, a1, t0);
2423
2424 // If the result is still negative, go to the slow case.
2425 // This only happens for the most negative smi.
2426 Label slow;
2427 __ Branch(&slow, lt, v0, Operand(zero_reg));
2428
2429 // Smi case done.
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002430 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002431
2432 // Check if the argument is a heap number and load its exponent and
2433 // sign.
2434 __ bind(&not_smi);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002435 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002436 __ lw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2437
2438 // Check the sign of the argument. If the argument is positive,
2439 // just return it.
2440 Label negative_sign;
2441 __ And(t0, a1, Operand(HeapNumber::kSignMask));
2442 __ Branch(&negative_sign, ne, t0, Operand(zero_reg));
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002443 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002444
2445 // If the argument is negative, clear the sign, and return a new
2446 // number.
2447 __ bind(&negative_sign);
2448 __ Xor(a1, a1, Operand(HeapNumber::kSignMask));
2449 __ lw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2450 __ LoadRoot(t2, Heap::kHeapNumberMapRootIndex);
2451 __ AllocateHeapNumber(v0, t0, t1, t2, &slow);
2452 __ sw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2453 __ sw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002454 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002455
2456 // Tail call the full function. We do not have to patch the receiver
2457 // because the function makes no use of it.
2458 __ bind(&slow);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002459 ParameterCount expected(function);
2460 __ InvokeFunction(function, expected, arguments(),
2461 JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002462
2463 __ bind(&miss);
2464 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002465 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002466
2467 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002468 return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002469}
2470
2471
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002472Handle<Code> CallStubCompiler::CompileFastApiCall(
lrn@chromium.org7516f052011-03-30 08:52:27 +00002473 const CallOptimization& optimization,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002474 Handle<Object> object,
2475 Handle<JSObject> holder,
2476 Handle<JSGlobalPropertyCell> cell,
2477 Handle<JSFunction> function,
2478 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002479
danno@chromium.org40cb8782011-05-25 07:58:50 +00002480 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002481
2482 ASSERT(optimization.is_simple_api_call());
2483 // Bail out if object is a global object as we don't want to
2484 // repatch it to global receiver.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002485 if (object->IsGlobalObject()) return Handle<Code>::null();
2486 if (!cell.is_null()) return Handle<Code>::null();
2487 if (!object->IsJSObject()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002488 int depth = optimization.GetPrototypeDepthOfExpectedType(
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002489 Handle<JSObject>::cast(object), holder);
2490 if (depth == kInvalidProtoDepth) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002491
2492 Label miss, miss_before_stack_reserved;
2493
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002494 GenerateNameCheck(name, &miss_before_stack_reserved);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002495
2496 // Get the receiver from the stack.
2497 const int argc = arguments().immediate();
2498 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2499
2500 // Check that the receiver isn't a smi.
2501 __ JumpIfSmi(a1, &miss_before_stack_reserved);
2502
2503 __ IncrementCounter(counters->call_const(), 1, a0, a3);
2504 __ IncrementCounter(counters->call_const_fast_api(), 1, a0, a3);
2505
2506 ReserveSpaceForFastApiCall(masm(), a0);
2507
2508 // Check that the maps haven't changed and find a Holder as a side effect.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002509 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0, name,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002510 depth, &miss);
2511
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002512 GenerateFastApiDirectCall(masm(), optimization, argc);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002513
2514 __ bind(&miss);
2515 FreeSpaceForFastApiCall(masm());
2516
2517 __ bind(&miss_before_stack_reserved);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002518 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002519
2520 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002521 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002522}
2523
2524
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002525void CallStubCompiler::CompileHandlerFrontend(Handle<Object> object,
2526 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002527 Handle<Name> name,
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002528 CheckType check,
2529 Label* success) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002530 // ----------- S t a t e -------------
2531 // -- a2 : name
2532 // -- ra : return address
2533 // -----------------------------------
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002534 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002535 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002536
2537 // Get the receiver from the stack.
2538 const int argc = arguments().immediate();
2539 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2540
2541 // Check that the receiver isn't a smi.
2542 if (check != NUMBER_CHECK) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002543 __ JumpIfSmi(a1, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002544 }
2545
2546 // Make sure that it's okay not to patch the on stack receiver
2547 // unless we're doing a receiver map check.
2548 ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002549 switch (check) {
2550 case RECEIVER_MAP_CHECK:
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002551 __ IncrementCounter(isolate()->counters()->call_const(), 1, a0, a3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002552
2553 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002554 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2555 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002556
2557 // Patch the receiver on the stack with the global proxy if
2558 // necessary.
2559 if (object->IsGlobalObject()) {
2560 __ lw(a3, FieldMemOperand(a1, GlobalObject::kGlobalReceiverOffset));
2561 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2562 }
2563 break;
2564
2565 case STRING_CHECK:
ulan@chromium.org750145a2013-03-07 15:14:13 +00002566 // Check that the object is a string.
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002567 __ GetObjectType(a1, a3, a3);
2568 __ Branch(&miss, Ugreater_equal, a3, Operand(FIRST_NONSTRING_TYPE));
2569 // Check that the maps starting from the prototype haven't changed.
2570 GenerateDirectLoadGlobalFunctionPrototype(
2571 masm(), Context::STRING_FUNCTION_INDEX, a0, &miss);
2572 CheckPrototypes(
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002573 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002574 a0, holder, a3, a1, t0, name, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002575 break;
2576
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002577 case SYMBOL_CHECK:
2578 // Check that the object is a symbol.
2579 __ GetObjectType(a1, a1, a3);
2580 __ Branch(&miss, ne, a3, Operand(SYMBOL_TYPE));
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +00002581 // Check that the maps starting from the prototype haven't changed.
2582 GenerateDirectLoadGlobalFunctionPrototype(
2583 masm(), Context::SYMBOL_FUNCTION_INDEX, a0, &miss);
2584 CheckPrototypes(
2585 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
2586 a0, holder, a3, a1, t0, name, &miss);
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002587 break;
2588
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002589 case NUMBER_CHECK: {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002590 Label fast;
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002591 // Check that the object is a smi or a heap number.
2592 __ JumpIfSmi(a1, &fast);
2593 __ GetObjectType(a1, a0, a0);
2594 __ Branch(&miss, ne, a0, Operand(HEAP_NUMBER_TYPE));
2595 __ bind(&fast);
2596 // Check that the maps starting from the prototype haven't changed.
2597 GenerateDirectLoadGlobalFunctionPrototype(
2598 masm(), Context::NUMBER_FUNCTION_INDEX, a0, &miss);
2599 CheckPrototypes(
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002600 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002601 a0, holder, a3, a1, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002602 break;
2603 }
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002604 case BOOLEAN_CHECK: {
2605 Label fast;
2606 // Check that the object is a boolean.
2607 __ LoadRoot(t0, Heap::kTrueValueRootIndex);
2608 __ Branch(&fast, eq, a1, Operand(t0));
2609 __ LoadRoot(t0, Heap::kFalseValueRootIndex);
2610 __ Branch(&miss, ne, a1, Operand(t0));
2611 __ bind(&fast);
2612 // Check that the maps starting from the prototype haven't changed.
2613 GenerateDirectLoadGlobalFunctionPrototype(
2614 masm(), Context::BOOLEAN_FUNCTION_INDEX, a0, &miss);
2615 CheckPrototypes(
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002616 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002617 a0, holder, a3, a1, t0, name, &miss);
2618 break;
2619 }
2620 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002621
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002622 __ jmp(success);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002623
2624 // Handle call cache miss.
2625 __ bind(&miss);
2626
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002627 GenerateMissBranch();
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002628}
2629
2630
2631void CallStubCompiler::CompileHandlerBackend(Handle<JSFunction> function) {
2632 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
2633 ? CALL_AS_FUNCTION
2634 : CALL_AS_METHOD;
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002635 ParameterCount expected(function);
2636 __ InvokeFunction(function, expected, arguments(),
2637 JUMP_FUNCTION, NullCallWrapper(), call_kind);
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002638}
2639
2640
2641Handle<Code> CallStubCompiler::CompileCallConstant(
2642 Handle<Object> object,
2643 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002644 Handle<Name> name,
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002645 CheckType check,
2646 Handle<JSFunction> function) {
2647 if (HasCustomCallGenerator(function)) {
2648 Handle<Code> code = CompileCustomCall(object, holder,
2649 Handle<JSGlobalPropertyCell>::null(),
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002650 function, Handle<String>::cast(name));
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002651 // A null handle means bail out to the regular compiler code below.
2652 if (!code.is_null()) return code;
2653 }
2654
2655 Label success;
2656
2657 CompileHandlerFrontend(object, holder, name, check, &success);
2658 __ bind(&success);
2659 CompileHandlerBackend(function);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002660
2661 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002662 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002663}
2664
2665
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002666Handle<Code> CallStubCompiler::CompileCallInterceptor(Handle<JSObject> object,
2667 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002668 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002669 // ----------- S t a t e -------------
2670 // -- a2 : name
2671 // -- ra : return address
2672 // -----------------------------------
2673
2674 Label miss;
2675
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002676 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002677
2678 // Get the number of arguments.
2679 const int argc = arguments().immediate();
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002680 LookupResult lookup(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002681 LookupPostInterceptor(holder, name, &lookup);
2682
2683 // Get the receiver from the stack.
2684 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2685
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002686 CallInterceptorCompiler compiler(this, arguments(), a2, extra_state_);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002687 compiler.Compile(masm(), object, holder, name, &lookup, a1, a3, t0, a0,
2688 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002689
2690 // Move returned value, the function to call, to a1.
2691 __ mov(a1, v0);
2692 // Restore receiver.
2693 __ lw(a0, MemOperand(sp, argc * kPointerSize));
2694
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002695 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002696
2697 // Handle call cache miss.
2698 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002699 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002700
2701 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002702 return GetCode(Code::INTERCEPTOR, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002703}
2704
2705
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002706Handle<Code> CallStubCompiler::CompileCallGlobal(
2707 Handle<JSObject> object,
2708 Handle<GlobalObject> holder,
2709 Handle<JSGlobalPropertyCell> cell,
2710 Handle<JSFunction> function,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002711 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002712 // ----------- S t a t e -------------
2713 // -- a2 : name
2714 // -- ra : return address
2715 // -----------------------------------
2716
2717 if (HasCustomCallGenerator(function)) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002718 Handle<Code> code = CompileCustomCall(
2719 object, holder, cell, function, Handle<String>::cast(name));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002720 // A null handle means bail out to the regular compiler code below.
2721 if (!code.is_null()) return code;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002722 }
2723
2724 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002725 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002726
2727 // Get the number of arguments.
2728 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002729 GenerateGlobalReceiverCheck(object, holder, name, &miss);
2730 GenerateLoadFunctionFromCell(cell, function, &miss);
2731
2732 // Patch the receiver on the stack with the global proxy if
2733 // necessary.
2734 if (object->IsGlobalObject()) {
2735 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
2736 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2737 }
2738
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002739 // Set up the context (function already in r1).
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002740 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
2741
2742 // Jump to the cached code (tail call).
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002743 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002744 __ IncrementCounter(counters->call_global_inline(), 1, a3, t0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002745 ParameterCount expected(function->shared()->formal_parameter_count());
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002746 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
danno@chromium.org40cb8782011-05-25 07:58:50 +00002747 ? CALL_AS_FUNCTION
2748 : CALL_AS_METHOD;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002749 // We call indirectly through the code field in the function to
2750 // allow recompilation to take effect without changing any of the
2751 // call sites.
2752 __ lw(a3, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
2753 __ InvokeCode(a3, expected, arguments(), JUMP_FUNCTION,
2754 NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002755
2756 // Handle call cache miss.
2757 __ bind(&miss);
2758 __ IncrementCounter(counters->call_global_inline_miss(), 1, a1, a3);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002759 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002760
2761 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002762 return GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002763}
2764
2765
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002766Handle<Code> StoreStubCompiler::CompileStoreCallback(
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002767 Handle<Name> name,
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002768 Handle<JSObject> object,
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002769 Handle<JSObject> holder,
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00002770 Handle<ExecutableAccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002771 Label miss;
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002772 // Check that the maps haven't changed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002773 __ JumpIfSmi(receiver(), &miss);
2774 CheckPrototypes(object, receiver(), holder,
2775 scratch1(), scratch2(), scratch3(), name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002776
2777 // Stub never generated for non-global objects that require access
2778 // checks.
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002779 ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002780
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002781 __ push(receiver()); // Receiver.
2782 __ li(at, Operand(callback)); // Callback info.
2783 __ Push(at, this->name(), value());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002784
2785 // Do tail-call to the runtime system.
2786 ExternalReference store_callback_property =
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002787 ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002788 __ TailCallExternalReference(store_callback_property, 4, 1);
2789
2790 // Handle store cache miss.
2791 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002792 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002793
2794 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002795 return GetICCode(kind(), Code::CALLBACKS, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002796}
2797
2798
yangguo@chromium.org46839fb2012-08-28 09:06:19 +00002799#undef __
2800#define __ ACCESS_MASM(masm)
2801
2802
2803void StoreStubCompiler::GenerateStoreViaSetter(
2804 MacroAssembler* masm,
2805 Handle<JSFunction> setter) {
2806 // ----------- S t a t e -------------
2807 // -- a0 : value
2808 // -- a1 : receiver
2809 // -- a2 : name
2810 // -- ra : return address
2811 // -----------------------------------
2812 {
2813 FrameScope scope(masm, StackFrame::INTERNAL);
2814
2815 // Save value register, so we can restore it later.
2816 __ push(a0);
2817
2818 if (!setter.is_null()) {
2819 // Call the JavaScript setter with receiver and value on the stack.
2820 __ push(a1);
2821 __ push(a0);
2822 ParameterCount actual(1);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002823 ParameterCount expected(setter);
2824 __ InvokeFunction(setter, expected, actual,
2825 CALL_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
yangguo@chromium.org46839fb2012-08-28 09:06:19 +00002826 } else {
2827 // If we generate a global code snippet for deoptimization only, remember
2828 // the place to continue after deoptimization.
2829 masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
2830 }
2831
2832 // We have to return the passed value, not the return value of the setter.
2833 __ pop(v0);
2834
2835 // Restore context register.
2836 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2837 }
2838 __ Ret();
2839}
2840
2841
2842#undef __
2843#define __ ACCESS_MASM(masm())
2844
2845
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002846Handle<Code> StoreStubCompiler::CompileStoreInterceptor(
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002847 Handle<JSObject> object,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002848 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002849 Label miss;
2850
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002851 // Check that the map of the object hasn't changed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002852 __ CheckMap(receiver(), scratch1(), Handle<Map>(object->map()), &miss,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +00002853 DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002854
2855 // Perform global security token check if needed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002856 if (object->IsJSGlobalProxy()) {
2857 __ CheckAccessGlobalProxy(receiver(), scratch1(), &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002858 }
2859
2860 // Stub is never generated for non-global objects that require access
2861 // checks.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002862 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002863
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002864 __ Push(receiver(), this->name(), value());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002865
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002866 __ li(scratch1(), Operand(Smi::FromInt(strict_mode())));
2867 __ push(scratch1()); // strict mode
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002868
2869 // Do tail-call to the runtime system.
2870 ExternalReference store_ic_property =
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002871 ExternalReference(IC_Utility(IC::kStoreInterceptorProperty), isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002872 __ TailCallExternalReference(store_ic_property, 4, 1);
2873
2874 // Handle store cache miss.
2875 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002876 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002877
2878 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002879 return GetICCode(kind(), Code::INTERCEPTOR, name);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00002880}
2881
2882
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002883Handle<Code> StoreStubCompiler::CompileStoreGlobal(
2884 Handle<GlobalObject> object,
2885 Handle<JSGlobalPropertyCell> cell,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002886 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002887 Label miss;
2888
2889 // Check that the map of the global has not changed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002890 __ lw(scratch1(), FieldMemOperand(receiver(), HeapObject::kMapOffset));
2891 __ Branch(&miss, ne, scratch1(), Operand(Handle<Map>(object->map())));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002892
2893 // Check that the value in the cell is not the hole. If it is, this
2894 // cell could have been deleted and reintroducing the global needs
2895 // to update the property details in the property dictionary of the
2896 // global object. We bail out to the runtime system to do that.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002897 __ li(scratch1(), Operand(cell));
2898 __ LoadRoot(scratch2(), Heap::kTheHoleValueRootIndex);
2899 __ lw(scratch3(),
2900 FieldMemOperand(scratch1(), JSGlobalPropertyCell::kValueOffset));
2901 __ Branch(&miss, eq, scratch3(), Operand(scratch2()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002902
2903 // Store the value in the cell.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002904 __ sw(value(),
2905 FieldMemOperand(scratch1(), JSGlobalPropertyCell::kValueOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002906 __ mov(v0, a0); // Stored value must be returned in v0.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002907 // Cells are always rescanned, so no write barrier here.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00002908
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002909 Counters* counters = isolate()->counters();
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002910 __ IncrementCounter(
2911 counters->named_store_global_inline(), 1, scratch1(), scratch2());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002912 __ Ret();
2913
2914 // Handle store cache miss.
2915 __ bind(&miss);
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002916 __ IncrementCounter(
2917 counters->named_store_global_inline_miss(), 1, scratch1(), scratch2());
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002918 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002919
2920 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002921 return GetICCode(kind(), Code::NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002922}
2923
2924
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002925Handle<Code> LoadStubCompiler::CompileLoadNonexistent(
2926 Handle<JSObject> object,
2927 Handle<JSObject> last,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002928 Handle<Name> name,
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002929 Handle<GlobalObject> global) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002930 Label success;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002931
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002932 NonexistentHandlerFrontend(object, last, name, &success, global);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002933
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002934 __ bind(&success);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002935 // Return undefined if maps of the full prototype chain is still the same.
2936 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
2937 __ Ret();
2938
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002939 // Return the generated code.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002940 return GetCode(kind(), Code::NONEXISTENT, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002941}
2942
2943
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002944Register* LoadStubCompiler::registers() {
2945 // receiver, name, scratch1, scratch2, scratch3, scratch4.
2946 static Register registers[] = { a0, a2, a3, a1, t0, t1 };
2947 return registers;
lrn@chromium.org7516f052011-03-30 08:52:27 +00002948}
2949
2950
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002951Register* KeyedLoadStubCompiler::registers() {
2952 // receiver, name, scratch1, scratch2, scratch3, scratch4.
2953 static Register registers[] = { a1, a0, a2, a3, t0, t1 };
2954 return registers;
2955}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002956
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002957
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002958Register* StoreStubCompiler::registers() {
2959 // receiver, name, value, scratch1, scratch2, scratch3.
2960 static Register registers[] = { a1, a2, a0, a3, t0, t1 };
2961 return registers;
2962}
2963
2964
2965Register* KeyedStoreStubCompiler::registers() {
2966 // receiver, name, value, scratch1, scratch2, scratch3.
2967 static Register registers[] = { a2, a1, a0, a3, t0, t1 };
2968 return registers;
2969}
2970
2971
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002972void KeyedLoadStubCompiler::GenerateNameCheck(Handle<Name> name,
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002973 Register name_reg,
2974 Label* miss) {
2975 __ Branch(miss, ne, name_reg, Operand(name));
lrn@chromium.org7516f052011-03-30 08:52:27 +00002976}
2977
2978
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002979void KeyedStoreStubCompiler::GenerateNameCheck(Handle<Name> name,
2980 Register name_reg,
2981 Label* miss) {
2982 __ Branch(miss, ne, name_reg, Operand(name));
2983}
2984
2985
mstarzinger@chromium.orgde886792012-09-11 13:22:37 +00002986#undef __
2987#define __ ACCESS_MASM(masm)
2988
2989
2990void LoadStubCompiler::GenerateLoadViaGetter(MacroAssembler* masm,
2991 Handle<JSFunction> getter) {
2992 // ----------- S t a t e -------------
2993 // -- a0 : receiver
2994 // -- a2 : name
2995 // -- ra : return address
2996 // -----------------------------------
2997 {
2998 FrameScope scope(masm, StackFrame::INTERNAL);
2999
3000 if (!getter.is_null()) {
3001 // Call the JavaScript getter with the receiver on the stack.
3002 __ push(a0);
3003 ParameterCount actual(0);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00003004 ParameterCount expected(getter);
3005 __ InvokeFunction(getter, expected, actual,
3006 CALL_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
mstarzinger@chromium.orgde886792012-09-11 13:22:37 +00003007 } else {
3008 // If we generate a global code snippet for deoptimization only, remember
3009 // the place to continue after deoptimization.
3010 masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
3011 }
3012
3013 // Restore context register.
3014 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
3015 }
3016 __ Ret();
3017}
3018
3019
3020#undef __
3021#define __ ACCESS_MASM(masm())
3022
3023
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003024Handle<Code> LoadStubCompiler::CompileLoadGlobal(
3025 Handle<JSObject> object,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00003026 Handle<GlobalObject> global,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003027 Handle<JSGlobalPropertyCell> cell,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003028 Handle<Name> name,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003029 bool is_dont_delete) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00003030 Label success, miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003031
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003032 __ CheckMap(
3033 receiver(), scratch1(), Handle<Map>(object->map()), &miss, DO_SMI_CHECK);
3034 HandlerFrontendHeader(
3035 object, receiver(), Handle<JSObject>::cast(global), name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003036
3037 // Get the value from the cell.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003038 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003039 __ lw(t0, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
3040
3041 // Check for deleted property if property can actually be deleted.
3042 if (!is_dont_delete) {
3043 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
3044 __ Branch(&miss, eq, t0, Operand(at));
3045 }
3046
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00003047 HandlerFrontendFooter(&success, &miss);
3048 __ bind(&success);
3049
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00003050 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003051 __ IncrementCounter(counters->named_load_global_stub(), 1, a1, a3);
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00003052 __ Ret(USE_DELAY_SLOT);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00003053 __ mov(v0, t0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003054
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003055 // Return the generated code.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003056 return GetICCode(kind(), Code::NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003057}
3058
3059
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00003060Handle<Code> BaseLoadStubCompiler::CompilePolymorphicIC(
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003061 MapHandleList* receiver_maps,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003062 CodeHandleList* handlers,
3063 Handle<Name> name,
3064 Code::StubType type,
3065 IcCheckType check) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003066 Label miss;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003067
3068 if (check == PROPERTY) {
3069 GenerateNameCheck(name, this->name(), &miss);
3070 }
3071
3072 __ JumpIfSmi(receiver(), &miss);
3073 Register map_reg = scratch1();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003074
danno@chromium.org40cb8782011-05-25 07:58:50 +00003075 int receiver_count = receiver_maps->length();
danno@chromium.orgf005df62013-04-30 16:36:45 +00003076 int number_of_handled_maps = 0;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003077 __ lw(map_reg, FieldMemOperand(receiver(), HeapObject::kMapOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003078 for (int current = 0; current < receiver_count; ++current) {
danno@chromium.orgf005df62013-04-30 16:36:45 +00003079 Handle<Map> map = receiver_maps->at(current);
3080 if (!map->is_deprecated()) {
3081 number_of_handled_maps++;
3082 __ Jump(handlers->at(current), RelocInfo::CODE_TARGET,
3083 eq, map_reg, Operand(receiver_maps->at(current)));
3084 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003085 }
danno@chromium.orgf005df62013-04-30 16:36:45 +00003086 ASSERT(number_of_handled_maps != 0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003087
3088 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003089 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003090
3091 // Return the generated code.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003092 InlineCacheState state =
danno@chromium.orgf005df62013-04-30 16:36:45 +00003093 number_of_handled_maps > 1 ? POLYMORPHIC : MONOMORPHIC;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003094 return GetICCode(kind(), type, name, state);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003095}
3096
3097
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003098Handle<Code> KeyedStoreStubCompiler::CompileStorePolymorphic(
3099 MapHandleList* receiver_maps,
3100 CodeHandleList* handler_stubs,
3101 MapHandleList* transitioned_maps) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003102 Label miss;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003103 __ JumpIfSmi(receiver(), &miss);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003104
3105 int receiver_count = receiver_maps->length();
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003106 __ lw(scratch1(), FieldMemOperand(receiver(), HeapObject::kMapOffset));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003107 for (int i = 0; i < receiver_count; ++i) {
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003108 if (transitioned_maps->at(i).is_null()) {
3109 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET, eq,
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003110 scratch1(), Operand(receiver_maps->at(i)));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003111 } else {
3112 Label next_map;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003113 __ Branch(&next_map, ne, scratch1(), Operand(receiver_maps->at(i)));
3114 __ li(transition_map(), Operand(transitioned_maps->at(i)));
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003115 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003116 __ bind(&next_map);
3117 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003118 }
3119
3120 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003121 TailCallBuiltin(masm(), MissBuiltin(kind()));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003122
3123 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003124 return GetICCode(
3125 kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003126}
3127
3128
danno@chromium.org40cb8782011-05-25 07:58:50 +00003129#undef __
3130#define __ ACCESS_MASM(masm)
3131
3132
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003133void KeyedLoadStubCompiler::GenerateLoadDictionaryElement(
3134 MacroAssembler* masm) {
3135 // ---------- S t a t e --------------
3136 // -- ra : return address
3137 // -- a0 : key
3138 // -- a1 : receiver
3139 // -----------------------------------
3140 Label slow, miss_force_generic;
3141
3142 Register key = a0;
3143 Register receiver = a1;
3144
3145 __ JumpIfNotSmi(key, &miss_force_generic);
3146 __ lw(t0, FieldMemOperand(receiver, JSObject::kElementsOffset));
3147 __ sra(a2, a0, kSmiTagSize);
3148 __ LoadFromNumberDictionary(&slow, t0, a0, v0, a2, a3, t1);
3149 __ Ret();
3150
3151 // Slow case, key and receiver still in a0 and a1.
3152 __ bind(&slow);
3153 __ IncrementCounter(
3154 masm->isolate()->counters()->keyed_load_external_array_slow(),
3155 1, a2, a3);
3156 // Entry registers are intact.
3157 // ---------- S t a t e --------------
3158 // -- ra : return address
3159 // -- a0 : key
3160 // -- a1 : receiver
3161 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003162 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003163
3164 // Miss case, call the runtime.
3165 __ bind(&miss_force_generic);
3166
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_MissForceGeneric);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003173}
3174
3175
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003176static void GenerateSmiKeyCheck(MacroAssembler* masm,
3177 Register key,
3178 Register scratch0,
3179 Register scratch1,
3180 FPURegister double_scratch0,
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003181 FPURegister double_scratch1,
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003182 Label* fail) {
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003183 Label key_ok;
3184 // Check for smi or a smi inside a heap number. We convert the heap
3185 // number and check if the conversion is exact and fits into the smi
3186 // range.
3187 __ JumpIfSmi(key, &key_ok);
3188 __ CheckMap(key,
3189 scratch0,
3190 Heap::kHeapNumberMapRootIndex,
3191 fail,
3192 DONT_DO_SMI_CHECK);
3193 __ ldc1(double_scratch0, FieldMemOperand(key, HeapNumber::kValueOffset));
3194 __ EmitFPUTruncate(kRoundToZero,
3195 scratch0,
3196 double_scratch0,
3197 at,
3198 double_scratch1,
3199 scratch1,
3200 kCheckForInexactConversion);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003201
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003202 __ Branch(fail, ne, scratch1, Operand(zero_reg));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003203
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003204 __ SmiTagCheckOverflow(key, scratch0, scratch1);
3205 __ BranchOnOverflow(fail, scratch1);
3206 __ bind(&key_ok);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003207}
3208
3209
danno@chromium.org40cb8782011-05-25 07:58:50 +00003210void KeyedStoreStubCompiler::GenerateStoreExternalArray(
3211 MacroAssembler* masm,
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003212 ElementsKind elements_kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003213 // ---------- S t a t e --------------
3214 // -- a0 : value
3215 // -- a1 : key
3216 // -- a2 : receiver
3217 // -- ra : return address
3218 // -----------------------------------
3219
danno@chromium.org40cb8782011-05-25 07:58:50 +00003220 Label slow, check_heap_number, miss_force_generic;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003221
3222 // Register usage.
3223 Register value = a0;
3224 Register key = a1;
3225 Register receiver = a2;
3226 // a3 mostly holds the elements array or the destination external array.
3227
danno@chromium.org40cb8782011-05-25 07:58:50 +00003228 // This stub is meant to be tail-jumped to, the receiver must already
3229 // have been verified by the caller to not be a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003230
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003231 // Check that the key is a smi or a heap number convertible to a smi.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003232 GenerateSmiKeyCheck(masm, key, t0, t1, f2, f4, &miss_force_generic);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003233
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003234 __ lw(a3, FieldMemOperand(receiver, JSObject::kElementsOffset));
3235
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003236 // Check that the index is in range.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003237 __ lw(t1, FieldMemOperand(a3, ExternalArray::kLengthOffset));
3238 // Unsigned comparison catches both negative and too-large values.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003239 __ Branch(&miss_force_generic, Ugreater_equal, key, Operand(t1));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003240
3241 // Handle both smis and HeapNumbers in the fast path. Go to the
3242 // runtime for all other kinds of values.
3243 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003244
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003245 if (elements_kind == EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003246 // Double to pixel conversion is only implemented in the runtime for now.
3247 __ JumpIfNotSmi(value, &slow);
3248 } else {
3249 __ JumpIfNotSmi(value, &check_heap_number);
3250 }
3251 __ SmiUntag(t1, value);
3252 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3253
3254 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003255 // t1: value (integer).
3256
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003257 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003258 case EXTERNAL_PIXEL_ELEMENTS: {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003259 // Clamp the value to [0..255].
3260 // v0 is used as a scratch register here.
3261 Label done;
3262 __ li(v0, Operand(255));
3263 // Normal branch: nop in delay slot.
3264 __ Branch(&done, gt, t1, Operand(v0));
3265 // Use delay slot in this branch.
3266 __ Branch(USE_DELAY_SLOT, &done, lt, t1, Operand(zero_reg));
3267 __ mov(v0, zero_reg); // In delay slot.
3268 __ mov(v0, t1); // Value is in range 0..255.
3269 __ bind(&done);
3270 __ mov(t1, v0);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003271
3272 __ srl(t8, key, 1);
3273 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003274 __ sb(t1, MemOperand(t8, 0));
3275 }
3276 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003277 case EXTERNAL_BYTE_ELEMENTS:
3278 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003279 __ srl(t8, key, 1);
3280 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003281 __ sb(t1, MemOperand(t8, 0));
3282 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003283 case EXTERNAL_SHORT_ELEMENTS:
3284 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003285 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003286 __ sh(t1, MemOperand(t8, 0));
3287 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003288 case EXTERNAL_INT_ELEMENTS:
3289 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003290 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003291 __ addu(t8, a3, t8);
3292 __ sw(t1, MemOperand(t8, 0));
3293 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003294 case EXTERNAL_FLOAT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003295 // Perform int-to-float conversion and store to memory.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003296 __ SmiUntag(t0, key);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003297 StoreIntAsFloat(masm, a3, t0, t1, t2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003298 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003299 case EXTERNAL_DOUBLE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003300 __ sll(t8, key, 2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003301 __ addu(a3, a3, t8);
3302 // a3: effective address of the double element
3303 FloatingPointHelper::Destination destination;
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003304 destination = FloatingPointHelper::kFPURegisters;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003305 FloatingPointHelper::ConvertIntToDouble(
danno@chromium.org40cb8782011-05-25 07:58:50 +00003306 masm, t1, destination,
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003307 f0, t2, t3, // These are: double_dst, dst_mantissa, dst_exponent.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003308 t0, f2); // These are: scratch2, single_scratch.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003309 __ sdc1(f0, MemOperand(a3, 0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003310 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003311 case FAST_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003312 case FAST_SMI_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003313 case FAST_DOUBLE_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003314 case FAST_HOLEY_ELEMENTS:
3315 case FAST_HOLEY_SMI_ELEMENTS:
3316 case FAST_HOLEY_DOUBLE_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003317 case DICTIONARY_ELEMENTS:
3318 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003319 UNREACHABLE();
3320 break;
3321 }
3322
3323 // Entry registers are intact, a0 holds the value which is the return value.
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00003324 __ Ret(USE_DELAY_SLOT);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003325 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003326
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003327 if (elements_kind != EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003328 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003329 __ bind(&check_heap_number);
3330 __ GetObjectType(value, t1, t2);
3331 __ Branch(&slow, ne, t2, Operand(HEAP_NUMBER_TYPE));
3332
3333 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3334
3335 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003336
3337 // The WebGL specification leaves the behavior of storing NaN and
3338 // +/-Infinity into integer arrays basically undefined. For more
3339 // reproducible behavior, convert these to zero.
3340
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003341
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003342 __ ldc1(f0, FieldMemOperand(a0, HeapNumber::kValueOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003343
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003344 if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
3345 __ cvt_s_d(f0, f0);
3346 __ sll(t8, key, 1);
3347 __ addu(t8, a3, t8);
3348 __ swc1(f0, MemOperand(t8, 0));
3349 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
3350 __ sll(t8, key, 2);
3351 __ addu(t8, a3, t8);
3352 __ sdc1(f0, MemOperand(t8, 0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003353 } else {
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003354 __ EmitECMATruncate(t3, f0, f2, t2, t1, t5);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003355
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003356 switch (elements_kind) {
3357 case EXTERNAL_BYTE_ELEMENTS:
3358 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
3359 __ srl(t8, key, 1);
3360 __ addu(t8, a3, t8);
3361 __ sb(t3, MemOperand(t8, 0));
3362 break;
3363 case EXTERNAL_SHORT_ELEMENTS:
3364 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
3365 __ addu(t8, a3, key);
3366 __ sh(t3, MemOperand(t8, 0));
3367 break;
3368 case EXTERNAL_INT_ELEMENTS:
3369 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
3370 __ sll(t8, key, 1);
3371 __ addu(t8, a3, t8);
3372 __ sw(t3, MemOperand(t8, 0));
3373 break;
3374 case EXTERNAL_PIXEL_ELEMENTS:
3375 case EXTERNAL_FLOAT_ELEMENTS:
3376 case EXTERNAL_DOUBLE_ELEMENTS:
3377 case FAST_ELEMENTS:
3378 case FAST_SMI_ELEMENTS:
3379 case FAST_DOUBLE_ELEMENTS:
3380 case FAST_HOLEY_ELEMENTS:
3381 case FAST_HOLEY_SMI_ELEMENTS:
3382 case FAST_HOLEY_DOUBLE_ELEMENTS:
3383 case DICTIONARY_ELEMENTS:
3384 case NON_STRICT_ARGUMENTS_ELEMENTS:
3385 UNREACHABLE();
3386 break;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003387 }
3388 }
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003389
3390 // Entry registers are intact, a0 holds the value
3391 // which is the return value.
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00003392 __ Ret(USE_DELAY_SLOT);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003393 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003394 }
3395
danno@chromium.org40cb8782011-05-25 07:58:50 +00003396 // Slow case, key and receiver still in a0 and a1.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003397 __ bind(&slow);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003398 __ IncrementCounter(
3399 masm->isolate()->counters()->keyed_load_external_array_slow(),
3400 1, a2, a3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003401 // Entry registers are intact.
3402 // ---------- S t a t e --------------
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003403 // -- ra : return address
danno@chromium.org40cb8782011-05-25 07:58:50 +00003404 // -- a0 : key
3405 // -- a1 : receiver
3406 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003407 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003408
3409 // Miss case, call the runtime.
3410 __ bind(&miss_force_generic);
3411
3412 // ---------- S t a t e --------------
3413 // -- ra : return address
3414 // -- a0 : key
3415 // -- a1 : receiver
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003416 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003417 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003418}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003419
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003420
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003421void KeyedStoreStubCompiler::GenerateStoreFastElement(
3422 MacroAssembler* masm,
3423 bool is_js_array,
yangguo@chromium.org56454712012-02-16 15:33:53 +00003424 ElementsKind elements_kind,
ulan@chromium.org750145a2013-03-07 15:14:13 +00003425 KeyedAccessStoreMode store_mode) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003426 // ----------- S t a t e -------------
3427 // -- a0 : value
3428 // -- a1 : key
3429 // -- a2 : receiver
3430 // -- ra : return address
3431 // -- a3 : scratch
3432 // -- a4 : scratch (elements)
3433 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00003434 Label miss_force_generic, transition_elements_kind, grow, slow;
3435 Label finish_store, check_capacity;
danno@chromium.org40cb8782011-05-25 07:58:50 +00003436
3437 Register value_reg = a0;
3438 Register key_reg = a1;
3439 Register receiver_reg = a2;
yangguo@chromium.org56454712012-02-16 15:33:53 +00003440 Register scratch = t0;
3441 Register elements_reg = a3;
3442 Register length_reg = t1;
3443 Register scratch2 = t2;
danno@chromium.org40cb8782011-05-25 07:58:50 +00003444
3445 // This stub is meant to be tail-jumped to, the receiver must already
3446 // have been verified by the caller to not be a smi.
3447
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003448 // Check that the key is a smi or a heap number convertible to a smi.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003449 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, f4, &miss_force_generic);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003450
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003451 if (IsFastSmiElementsKind(elements_kind)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003452 __ JumpIfNotSmi(value_reg, &transition_elements_kind);
3453 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003454
3455 // Check that the key is within bounds.
yangguo@chromium.org56454712012-02-16 15:33:53 +00003456 __ lw(elements_reg,
3457 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003458 if (is_js_array) {
3459 __ lw(scratch, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3460 } else {
3461 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3462 }
3463 // Compare smis.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003464 if (is_js_array && IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003465 __ Branch(&grow, hs, key_reg, Operand(scratch));
3466 } else {
3467 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch));
3468 }
3469
3470 // Make sure elements is a fast element array, not 'cow'.
3471 __ CheckMap(elements_reg,
3472 scratch,
3473 Heap::kFixedArrayMapRootIndex,
3474 &miss_force_generic,
3475 DONT_DO_SMI_CHECK);
3476
3477 __ bind(&finish_store);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003478
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003479 if (IsFastSmiElementsKind(elements_kind)) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003480 __ Addu(scratch,
3481 elements_reg,
3482 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3483 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
3484 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
3485 __ Addu(scratch, scratch, scratch2);
3486 __ sw(value_reg, MemOperand(scratch));
3487 } else {
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003488 ASSERT(IsFastObjectElementsKind(elements_kind));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003489 __ Addu(scratch,
3490 elements_reg,
3491 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3492 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
3493 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
3494 __ Addu(scratch, scratch, scratch2);
3495 __ sw(value_reg, MemOperand(scratch));
3496 __ mov(receiver_reg, value_reg);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003497 __ RecordWrite(elements_reg, // Object.
3498 scratch, // Address.
3499 receiver_reg, // Value.
3500 kRAHasNotBeenSaved,
3501 kDontSaveFPRegs);
3502 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003503 // value_reg (a0) is preserved.
3504 // Done.
3505 __ Ret();
3506
3507 __ bind(&miss_force_generic);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003508 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003509
3510 __ bind(&transition_elements_kind);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003511 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Miss);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003512
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003513 if (is_js_array && IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003514 // Grow the array by a single element if possible.
3515 __ bind(&grow);
3516
3517 // Make sure the array is only growing by a single element, anything else
3518 // must be handled by the runtime.
3519 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch));
3520
3521 // Check for the empty array, and preallocate a small backing store if
3522 // possible.
3523 __ lw(length_reg,
3524 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3525 __ lw(elements_reg,
3526 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3527 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
3528 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
3529
3530 int size = FixedArray::SizeFor(JSArray::kPreallocatedArrayElements);
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003531 __ Allocate(size, elements_reg, scratch, scratch2, &slow, TAG_OBJECT);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003532
3533 __ LoadRoot(scratch, Heap::kFixedArrayMapRootIndex);
3534 __ sw(scratch, FieldMemOperand(elements_reg, JSObject::kMapOffset));
3535 __ li(scratch, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
3536 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3537 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
3538 for (int i = 1; i < JSArray::kPreallocatedArrayElements; ++i) {
3539 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::SizeFor(i)));
3540 }
3541
3542 // Store the element at index zero.
3543 __ sw(value_reg, FieldMemOperand(elements_reg, FixedArray::SizeFor(0)));
3544
3545 // Install the new backing store in the JSArray.
3546 __ sw(elements_reg,
3547 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3548 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
3549 scratch, kRAHasNotBeenSaved, kDontSaveFPRegs,
3550 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
3551
3552 // Increment the length of the array.
3553 __ li(length_reg, Operand(Smi::FromInt(1)));
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00003554 __ Ret(USE_DELAY_SLOT);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003555 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
yangguo@chromium.org56454712012-02-16 15:33:53 +00003556
3557 __ bind(&check_capacity);
3558 // Check for cow elements, in general they are not handled by this stub
3559 __ CheckMap(elements_reg,
3560 scratch,
3561 Heap::kFixedCOWArrayMapRootIndex,
3562 &miss_force_generic,
3563 DONT_DO_SMI_CHECK);
3564
3565 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3566 __ Branch(&slow, hs, length_reg, Operand(scratch));
3567
3568 // Grow the array and finish the store.
3569 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
3570 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3571 __ jmp(&finish_store);
3572
3573 __ bind(&slow);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003574 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003575 }
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00003576}
3577
3578
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00003579void KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(
3580 MacroAssembler* masm,
yangguo@chromium.org56454712012-02-16 15:33:53 +00003581 bool is_js_array,
ulan@chromium.org750145a2013-03-07 15:14:13 +00003582 KeyedAccessStoreMode store_mode) {
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003583 // ----------- S t a t e -------------
3584 // -- a0 : value
3585 // -- a1 : key
3586 // -- a2 : receiver
3587 // -- ra : return address
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003588 // -- a3 : scratch (elements backing store)
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003589 // -- t0 : scratch (elements_reg)
3590 // -- t1 : scratch (mantissa_reg)
3591 // -- t2 : scratch (exponent_reg)
3592 // -- t3 : scratch4
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003593 // -- t4 : scratch
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003594 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00003595 Label miss_force_generic, transition_elements_kind, grow, slow;
3596 Label finish_store, check_capacity;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003597
3598 Register value_reg = a0;
3599 Register key_reg = a1;
3600 Register receiver_reg = a2;
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003601 Register elements_reg = a3;
3602 Register scratch1 = t0;
3603 Register scratch2 = t1;
3604 Register scratch3 = t2;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003605 Register scratch4 = t3;
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003606 Register scratch5 = t4;
yangguo@chromium.org56454712012-02-16 15:33:53 +00003607 Register length_reg = t3;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003608
3609 // This stub is meant to be tail-jumped to, the receiver must already
3610 // have been verified by the caller to not be a smi.
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003611
3612 // Check that the key is a smi or a heap number convertible to a smi.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003613 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, f4, &miss_force_generic);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003614
3615 __ lw(elements_reg,
3616 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3617
3618 // Check that the key is within bounds.
3619 if (is_js_array) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003620 __ lw(scratch1, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003621 } else {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003622 __ lw(scratch1,
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003623 FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3624 }
3625 // Compare smis, unsigned compare catches both negative and out-of-bound
3626 // indexes.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003627 if (IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003628 __ Branch(&grow, hs, key_reg, Operand(scratch1));
3629 } else {
3630 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch1));
3631 }
3632
3633 __ bind(&finish_store);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003634
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003635 __ StoreNumberToDoubleElements(value_reg,
3636 key_reg,
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00003637 // All registers after this are overwritten.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003638 elements_reg,
3639 scratch1,
3640 scratch2,
3641 scratch3,
3642 scratch4,
3643 &transition_elements_kind);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003644
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00003645 __ Ret(USE_DELAY_SLOT);
3646 __ mov(v0, value_reg); // In delay slot.
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003647
3648 // Handle store cache miss, replacing the ic with the generic stub.
3649 __ bind(&miss_force_generic);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003650 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003651
3652 __ bind(&transition_elements_kind);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003653 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Miss);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003654
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003655 if (is_js_array && IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003656 // Grow the array by a single element if possible.
3657 __ bind(&grow);
3658
3659 // Make sure the array is only growing by a single element, anything else
3660 // must be handled by the runtime.
3661 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch1));
3662
3663 // Transition on values that can't be stored in a FixedDoubleArray.
3664 Label value_is_smi;
3665 __ JumpIfSmi(value_reg, &value_is_smi);
3666 __ lw(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
3667 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex);
3668 __ Branch(&transition_elements_kind, ne, scratch1, Operand(at));
3669 __ bind(&value_is_smi);
3670
3671 // Check for the empty array, and preallocate a small backing store if
3672 // possible.
3673 __ lw(length_reg,
3674 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3675 __ lw(elements_reg,
3676 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3677 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
3678 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
3679
3680 int size = FixedDoubleArray::SizeFor(JSArray::kPreallocatedArrayElements);
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003681 __ Allocate(size, elements_reg, scratch1, scratch2, &slow, TAG_OBJECT);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003682
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003683 // Initialize the new FixedDoubleArray.
yangguo@chromium.org56454712012-02-16 15:33:53 +00003684 __ LoadRoot(scratch1, Heap::kFixedDoubleArrayMapRootIndex);
3685 __ sw(scratch1, FieldMemOperand(elements_reg, JSObject::kMapOffset));
3686 __ li(scratch1, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
3687 __ sw(scratch1,
3688 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
3689
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003690 __ mov(scratch1, elements_reg);
3691 __ StoreNumberToDoubleElements(value_reg,
3692 key_reg,
3693 // All registers after this are overwritten.
3694 scratch1,
3695 scratch2,
3696 scratch3,
3697 scratch4,
3698 scratch5,
3699 &transition_elements_kind);
3700
3701 __ li(scratch1, Operand(kHoleNanLower32));
3702 __ li(scratch2, Operand(kHoleNanUpper32));
3703 for (int i = 1; i < JSArray::kPreallocatedArrayElements; i++) {
3704 int offset = FixedDoubleArray::OffsetOfElementAt(i);
3705 __ sw(scratch1, FieldMemOperand(elements_reg, offset));
3706 __ sw(scratch2, FieldMemOperand(elements_reg, offset + kPointerSize));
3707 }
3708
yangguo@chromium.org56454712012-02-16 15:33:53 +00003709 // Install the new backing store in the JSArray.
3710 __ sw(elements_reg,
3711 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3712 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
3713 scratch1, kRAHasNotBeenSaved, kDontSaveFPRegs,
3714 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
3715
3716 // Increment the length of the array.
3717 __ li(length_reg, Operand(Smi::FromInt(1)));
3718 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00003719 __ Ret(USE_DELAY_SLOT);
danno@chromium.org00379b82012-05-04 09:16:29 +00003720 __ lw(elements_reg,
3721 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
yangguo@chromium.org56454712012-02-16 15:33:53 +00003722
3723 __ bind(&check_capacity);
3724 // Make sure that the backing store can hold additional elements.
3725 __ lw(scratch1,
3726 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
3727 __ Branch(&slow, hs, length_reg, Operand(scratch1));
3728
3729 // Grow the array and finish the store.
3730 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
3731 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3732 __ jmp(&finish_store);
3733
3734 __ bind(&slow);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003735 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003736 }
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00003737}
3738
3739
ager@chromium.org5c838252010-02-19 08:53:10 +00003740#undef __
3741
3742} } // namespace v8::internal
3743
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00003744#endif // V8_TARGET_ARCH_MIPS