blob: be32744b2e8fd7b5ac9fa3467995545915c88efc [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
palfia@homejinni.com79d0bf72013-06-10 19:35:04 +0000886 // -- sp[16] : ReturnValue default value
887 // -- sp[20] : ReturnValue
888 // -- sp[24] : last JS argument
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000889 // -- ...
palfia@homejinni.com79d0bf72013-06-10 19:35:04 +0000890 // -- sp[(argc + 5) * 4] : first JS argument
891 // -- sp[(argc + 6) * 4] : receiver
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000892 // -----------------------------------
893 // Get the function and setup the context.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000894 Handle<JSFunction> function = optimization.constant_function();
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000895 __ LoadHeapObject(t1, function);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000896 __ lw(cp, FieldMemOperand(t1, JSFunction::kContextOffset));
897
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000898 // Pass the additional arguments.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000899 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
ulan@chromium.org09d7ab52013-02-25 15:50:35 +0000900 Handle<Object> call_data(api_call_info->data(), masm->isolate());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000901 if (masm->isolate()->heap()->InNewSpace(*call_data)) {
902 __ li(a0, api_call_info);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000903 __ lw(t2, FieldMemOperand(a0, CallHandlerInfo::kDataOffset));
904 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000905 __ li(t2, call_data);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000906 }
907
ulan@chromium.org32d7dba2013-04-24 10:59:06 +0000908 __ li(t3, Operand(ExternalReference::isolate_address(masm->isolate())));
palfia@homejinni.com79d0bf72013-06-10 19:35:04 +0000909 // Store JS function, call data, isolate ReturnValue default and ReturnValue.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000910 __ sw(t1, MemOperand(sp, 1 * kPointerSize));
911 __ sw(t2, MemOperand(sp, 2 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000912 __ sw(t3, MemOperand(sp, 3 * kPointerSize));
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000913 __ LoadRoot(t1, Heap::kUndefinedValueRootIndex);
914 __ sw(t1, MemOperand(sp, 4 * kPointerSize));
palfia@homejinni.com79d0bf72013-06-10 19:35:04 +0000915 __ sw(t1, MemOperand(sp, 5 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000916
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000917 // Prepare arguments.
palfia@homejinni.com79d0bf72013-06-10 19:35:04 +0000918 __ Addu(a2, sp, Operand(5 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000919
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000920 // Allocate the v8::Arguments structure in the arguments' space since
921 // it's not controlled by GC.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000922 const int kApiStackSpace = 4;
923
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000924 FrameScope frame_scope(masm, StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000925 __ EnterExitFrame(false, kApiStackSpace);
926
927 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
928 // struct from the function (which is currently the case). This means we pass
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +0000929 // the first argument in a1 instead of a0, if returns_handle is true.
930 // CallApiFunctionAndReturn will set up a0.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000931
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000932 Address function_address = v8::ToCData<Address>(api_call_info->callback());
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000933 bool returns_handle =
934 !CallbackTable::ReturnsVoid(masm->isolate(), function_address);
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +0000935
936 Register first_arg = returns_handle ? a1 : a0;
937
938 // first_arg = v8::Arguments&
939 // Arguments is built at sp + 1 (sp is a reserved spot for ra).
940 __ Addu(first_arg, sp, kPointerSize);
941
942 // v8::Arguments::implicit_args_
943 __ sw(a2, MemOperand(first_arg, 0 * kPointerSize));
944 // v8::Arguments::values_
945 __ Addu(t0, a2, Operand(argc * kPointerSize));
946 __ sw(t0, MemOperand(first_arg, 1 * kPointerSize));
947 // v8::Arguments::length_ = argc
948 __ li(t0, Operand(argc));
949 __ sw(t0, MemOperand(first_arg, 2 * kPointerSize));
950 // v8::Arguments::is_construct_call = 0
951 __ sw(zero_reg, MemOperand(first_arg, 3 * kPointerSize));
952
953 const int kStackUnwindSpace = argc + kFastApiCallArguments + 1;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000954 ApiFunction fun(function_address);
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000955 ExternalReference::Type type =
956 returns_handle ?
957 ExternalReference::DIRECT_API_CALL :
958 ExternalReference::DIRECT_API_CALL_NEW;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000959 ExternalReference ref =
960 ExternalReference(&fun,
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000961 type,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000962 masm->isolate());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000963 AllowExternalCallThatCantCauseGC scope(masm);
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000964 __ CallApiFunctionAndReturn(ref,
965 kStackUnwindSpace,
966 returns_handle,
967 kFastApiCallArguments + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000968}
969
lrn@chromium.org7516f052011-03-30 08:52:27 +0000970class CallInterceptorCompiler BASE_EMBEDDED {
971 public:
972 CallInterceptorCompiler(StubCompiler* stub_compiler,
973 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000974 Register name,
975 Code::ExtraICState extra_ic_state)
lrn@chromium.org7516f052011-03-30 08:52:27 +0000976 : stub_compiler_(stub_compiler),
977 arguments_(arguments),
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000978 name_(name),
979 extra_ic_state_(extra_ic_state) {}
lrn@chromium.org7516f052011-03-30 08:52:27 +0000980
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000981 void Compile(MacroAssembler* masm,
982 Handle<JSObject> object,
983 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000984 Handle<Name> name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000985 LookupResult* lookup,
986 Register receiver,
987 Register scratch1,
988 Register scratch2,
989 Register scratch3,
990 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000991 ASSERT(holder->HasNamedInterceptor());
992 ASSERT(!holder->GetNamedInterceptor()->getter()->IsUndefined());
993
994 // Check that the receiver isn't a smi.
995 __ JumpIfSmi(receiver, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000996 CallOptimization optimization(lookup);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000997 if (optimization.is_constant_call()) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000998 CompileCacheable(masm, object, receiver, scratch1, scratch2, scratch3,
999 holder, lookup, name, optimization, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001000 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001001 CompileRegular(masm, object, receiver, scratch1, scratch2, scratch3,
1002 name, holder, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001003 }
1004 }
1005
1006 private:
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001007 void CompileCacheable(MacroAssembler* masm,
1008 Handle<JSObject> object,
1009 Register receiver,
1010 Register scratch1,
1011 Register scratch2,
1012 Register scratch3,
1013 Handle<JSObject> interceptor_holder,
1014 LookupResult* lookup,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001015 Handle<Name> name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001016 const CallOptimization& optimization,
1017 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001018 ASSERT(optimization.is_constant_call());
1019 ASSERT(!lookup->holder()->IsGlobalObject());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001020 Counters* counters = masm->isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001021 int depth1 = kInvalidProtoDepth;
1022 int depth2 = kInvalidProtoDepth;
1023 bool can_do_fast_api_call = false;
1024 if (optimization.is_simple_api_call() &&
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001025 !lookup->holder()->IsGlobalObject()) {
1026 depth1 = optimization.GetPrototypeDepthOfExpectedType(
1027 object, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001028 if (depth1 == kInvalidProtoDepth) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001029 depth2 = optimization.GetPrototypeDepthOfExpectedType(
1030 interceptor_holder, Handle<JSObject>(lookup->holder()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001031 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001032 can_do_fast_api_call =
1033 depth1 != kInvalidProtoDepth || depth2 != kInvalidProtoDepth;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001034 }
1035
1036 __ IncrementCounter(counters->call_const_interceptor(), 1,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001037 scratch1, scratch2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001038
1039 if (can_do_fast_api_call) {
1040 __ IncrementCounter(counters->call_const_interceptor_fast_api(), 1,
1041 scratch1, scratch2);
1042 ReserveSpaceForFastApiCall(masm, scratch1);
1043 }
1044
1045 // Check that the maps from receiver to interceptor's holder
1046 // haven't changed and thus we can invoke interceptor.
1047 Label miss_cleanup;
1048 Label* miss = can_do_fast_api_call ? &miss_cleanup : miss_label;
1049 Register holder =
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001050 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
1051 scratch1, scratch2, scratch3,
1052 name, depth1, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001053
1054 // Invoke an interceptor and if it provides a value,
1055 // branch to |regular_invoke|.
1056 Label regular_invoke;
1057 LoadWithInterceptor(masm, receiver, holder, interceptor_holder, scratch2,
1058 &regular_invoke);
1059
1060 // Interceptor returned nothing for this property. Try to use cached
1061 // constant function.
1062
1063 // Check that the maps from interceptor's holder to constant function's
1064 // holder haven't changed and thus we can use cached constant function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001065 if (*interceptor_holder != lookup->holder()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001066 stub_compiler_->CheckPrototypes(interceptor_holder, receiver,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001067 Handle<JSObject>(lookup->holder()),
1068 scratch1, scratch2, scratch3,
1069 name, depth2, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001070 } else {
1071 // CheckPrototypes has a side effect of fetching a 'holder'
1072 // for API (object which is instanceof for the signature). It's
1073 // safe to omit it here, as if present, it should be fetched
1074 // by the previous CheckPrototypes.
1075 ASSERT(depth2 == kInvalidProtoDepth);
1076 }
1077
1078 // Invoke function.
1079 if (can_do_fast_api_call) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001080 GenerateFastApiDirectCall(masm, optimization, arguments_.immediate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001081 } else {
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00001082 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state_)
1083 ? CALL_AS_FUNCTION
1084 : CALL_AS_METHOD;
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001085 Handle<JSFunction> function = optimization.constant_function();
1086 ParameterCount expected(function);
1087 __ InvokeFunction(function, expected, arguments_,
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001088 JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001089 }
1090
1091 // Deferred code for fast API call case---clean preallocated space.
1092 if (can_do_fast_api_call) {
1093 __ bind(&miss_cleanup);
1094 FreeSpaceForFastApiCall(masm);
1095 __ Branch(miss_label);
1096 }
1097
1098 // Invoke a regular function.
1099 __ bind(&regular_invoke);
1100 if (can_do_fast_api_call) {
1101 FreeSpaceForFastApiCall(masm);
1102 }
lrn@chromium.org7516f052011-03-30 08:52:27 +00001103 }
1104
1105 void CompileRegular(MacroAssembler* masm,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001106 Handle<JSObject> object,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001107 Register receiver,
1108 Register scratch1,
1109 Register scratch2,
1110 Register scratch3,
ulan@chromium.org6e196bf2013-03-13 09:38:22 +00001111 Handle<Name> name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001112 Handle<JSObject> interceptor_holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001113 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001114 Register holder =
1115 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001116 scratch1, scratch2, scratch3,
1117 name, miss_label);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001118
1119 // Call a runtime function to load the interceptor property.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001120 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001121 // Save the name_ register across the call.
1122 __ push(name_);
1123
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001124 PushInterceptorArguments(masm, receiver, holder, name_, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001125
1126 __ CallExternalReference(
1127 ExternalReference(
1128 IC_Utility(IC::kLoadPropertyWithInterceptorForCall),
1129 masm->isolate()),
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001130 6);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001131 // Restore the name_ register.
1132 __ pop(name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001133 // Leave the internal frame.
lrn@chromium.org7516f052011-03-30 08:52:27 +00001134 }
1135
1136 void LoadWithInterceptor(MacroAssembler* masm,
1137 Register receiver,
1138 Register holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001139 Handle<JSObject> holder_obj,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001140 Register scratch,
1141 Label* interceptor_succeeded) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001142 {
1143 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001144
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001145 __ Push(holder, name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001146 CompileCallLoadPropertyWithInterceptor(masm,
1147 receiver,
1148 holder,
1149 name_,
1150 holder_obj);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001151 __ pop(name_); // Restore the name.
1152 __ pop(receiver); // Restore the holder.
1153 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001154 // If interceptor returns no-result sentinel, call the constant function.
1155 __ LoadRoot(scratch, Heap::kNoInterceptorResultSentinelRootIndex);
1156 __ Branch(interceptor_succeeded, ne, v0, Operand(scratch));
lrn@chromium.org7516f052011-03-30 08:52:27 +00001157 }
1158
1159 StubCompiler* stub_compiler_;
1160 const ParameterCount& arguments_;
1161 Register name_;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00001162 Code::ExtraICState extra_ic_state_;
lrn@chromium.org7516f052011-03-30 08:52:27 +00001163};
1164
1165
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001166// Calls GenerateCheckPropertyCell for each global object in the prototype chain
1167// from object to (but not including) holder.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001168static void GenerateCheckPropertyCells(MacroAssembler* masm,
1169 Handle<JSObject> object,
1170 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001171 Handle<Name> name,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001172 Register scratch,
1173 Label* miss) {
1174 Handle<JSObject> current = object;
1175 while (!current.is_identical_to(holder)) {
1176 if (current->IsGlobalObject()) {
1177 GenerateCheckPropertyCell(masm,
1178 Handle<GlobalObject>::cast(current),
1179 name,
1180 scratch,
1181 miss);
1182 }
1183 current = Handle<JSObject>(JSObject::cast(current->GetPrototype()));
1184 }
1185}
1186
1187
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001188// Convert and store int passed in register ival to IEEE 754 single precision
1189// floating point value at memory location (dst + 4 * wordoffset)
1190// If FPU is available use it for conversion.
1191static void StoreIntAsFloat(MacroAssembler* masm,
1192 Register dst,
1193 Register wordoffset,
1194 Register ival,
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00001195 Register scratch1) {
1196 __ mtc1(ival, f0);
1197 __ cvt_s_w(f0, f0);
1198 __ sll(scratch1, wordoffset, 2);
1199 __ addu(scratch1, dst, scratch1);
1200 __ swc1(f0, MemOperand(scratch1, 0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001201}
1202
1203
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00001204void StubCompiler::GenerateTailCall(MacroAssembler* masm, Handle<Code> code) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001205 __ Jump(code, RelocInfo::CODE_TARGET);
1206}
1207
1208
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00001209#undef __
1210#define __ ACCESS_MASM(masm())
1211
1212
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001213Register StubCompiler::CheckPrototypes(Handle<JSObject> object,
1214 Register object_reg,
1215 Handle<JSObject> holder,
1216 Register holder_reg,
1217 Register scratch1,
1218 Register scratch2,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001219 Handle<Name> name,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001220 int save_at_depth,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001221 Label* miss,
1222 PrototypeCheckType check) {
1223 Handle<JSObject> first = object;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001224 // Make sure there's no overlap between holder and object registers.
1225 ASSERT(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
1226 ASSERT(!scratch2.is(object_reg) && !scratch2.is(holder_reg)
1227 && !scratch2.is(scratch1));
1228
1229 // Keep track of the current object in register reg.
1230 Register reg = object_reg;
1231 int depth = 0;
1232
1233 if (save_at_depth == depth) {
1234 __ sw(reg, MemOperand(sp));
1235 }
1236
1237 // Check the maps in the prototype chain.
1238 // Traverse the prototype chain from the object and do map checks.
1239 Handle<JSObject> current = object;
1240 while (!current.is_identical_to(holder)) {
1241 ++depth;
1242
1243 // Only global objects and objects that do not require access
1244 // checks are allowed in stubs.
1245 ASSERT(current->IsJSGlobalProxy() || !current->IsAccessCheckNeeded());
1246
1247 Handle<JSObject> prototype(JSObject::cast(current->GetPrototype()));
1248 if (!current->HasFastProperties() &&
1249 !current->IsJSGlobalObject() &&
1250 !current->IsJSGlobalProxy()) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001251 if (!name->IsUniqueName()) {
1252 ASSERT(name->IsString());
1253 name = factory()->InternalizeString(Handle<String>::cast(name));
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001254 }
1255 ASSERT(current->property_dictionary()->FindEntry(*name) ==
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001256 NameDictionary::kNotFound);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001257
1258 GenerateDictionaryNegativeLookup(masm(), miss, reg, name,
1259 scratch1, scratch2);
1260
1261 __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
1262 reg = holder_reg; // From now on the object will be in holder_reg.
1263 __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
1264 } else {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001265 Register map_reg = scratch1;
1266 if (!current.is_identical_to(first) || check == CHECK_ALL_MAPS) {
1267 Handle<Map> current_map(current->map());
1268 // CheckMap implicitly loads the map of |reg| into |map_reg|.
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +00001269 __ CheckMap(reg, map_reg, current_map, miss, DONT_DO_SMI_CHECK);
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001270 } else {
1271 __ lw(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
1272 }
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001273 // Check access rights to the global object. This has to happen after
1274 // the map check so that we know that the object is actually a global
1275 // object.
1276 if (current->IsJSGlobalProxy()) {
1277 __ CheckAccessGlobalProxy(reg, scratch2, miss);
1278 }
1279 reg = holder_reg; // From now on the object will be in holder_reg.
1280
1281 if (heap()->InNewSpace(*prototype)) {
1282 // The prototype is in new space; we cannot store a reference to it
1283 // in the code. Load it from the map.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001284 __ lw(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset));
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001285 } else {
1286 // The prototype is in old space; load it directly.
1287 __ li(reg, Operand(prototype));
1288 }
1289 }
1290
1291 if (save_at_depth == depth) {
1292 __ sw(reg, MemOperand(sp));
1293 }
1294
1295 // Go to the next object in the prototype chain.
1296 current = prototype;
1297 }
1298
1299 // Log the check depth.
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001300 LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001301
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001302 if (!holder.is_identical_to(first) || check == CHECK_ALL_MAPS) {
1303 // Check the holder map.
1304 __ CheckMap(reg, scratch1, Handle<Map>(holder->map()), miss,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +00001305 DONT_DO_SMI_CHECK);
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001306 }
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001307
1308 // Perform security check for access to the global object.
1309 ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded());
1310 if (holder->IsJSGlobalProxy()) {
1311 __ CheckAccessGlobalProxy(reg, scratch1, miss);
1312 }
1313
1314 // If we've skipped any global objects, it's not enough to verify that
1315 // their maps haven't changed. We also need to check that the property
1316 // cell for the property is still empty.
1317 GenerateCheckPropertyCells(masm(), object, holder, name, scratch1, miss);
1318
1319 // Return the register containing the holder.
1320 return reg;
1321}
1322
1323
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001324void BaseLoadStubCompiler::HandlerFrontendFooter(Label* success,
1325 Label* miss) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001326 if (!miss->is_unused()) {
1327 __ Branch(success);
1328 __ bind(miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00001329 TailCallBuiltin(masm(), MissBuiltin(kind()));
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001330 }
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001331}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001332
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001333
1334Register BaseLoadStubCompiler::CallbackHandlerFrontend(
1335 Handle<JSObject> object,
1336 Register object_reg,
1337 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001338 Handle<Name> name,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001339 Label* success,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001340 Handle<ExecutableAccessorInfo> callback) {
1341 Label miss;
1342
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001343 Register reg = HandlerFrontendHeader(object, object_reg, holder, name, &miss);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001344
1345 if (!holder->HasFastProperties() && !holder->IsJSGlobalObject()) {
1346 ASSERT(!reg.is(scratch2()));
1347 ASSERT(!reg.is(scratch3()));
1348 ASSERT(!reg.is(scratch4()));
1349
1350 // Load the properties dictionary.
1351 Register dictionary = scratch4();
1352 __ lw(dictionary, FieldMemOperand(reg, JSObject::kPropertiesOffset));
1353
1354 // Probe the dictionary.
1355 Label probe_done;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001356 NameDictionaryLookupStub::GeneratePositiveLookup(masm(),
1357 &miss,
1358 &probe_done,
1359 dictionary,
1360 this->name(),
1361 scratch2(),
1362 scratch3());
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001363 __ bind(&probe_done);
1364
1365 // If probing finds an entry in the dictionary, scratch3 contains the
1366 // pointer into the dictionary. Check that the value is the callback.
1367 Register pointer = scratch3();
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001368 const int kElementsStartOffset = NameDictionary::kHeaderSize +
1369 NameDictionary::kElementsStartIndex * kPointerSize;
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001370 const int kValueOffset = kElementsStartOffset + kPointerSize;
1371 __ lw(scratch2(), FieldMemOperand(pointer, kValueOffset));
1372 __ Branch(&miss, ne, scratch2(), Operand(callback));
1373 }
1374
1375 HandlerFrontendFooter(success, &miss);
1376 return reg;
1377}
1378
1379
1380void BaseLoadStubCompiler::NonexistentHandlerFrontend(
1381 Handle<JSObject> object,
1382 Handle<JSObject> last,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001383 Handle<Name> name,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001384 Label* success,
1385 Handle<GlobalObject> global) {
1386 Label miss;
1387
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00001388 HandlerFrontendHeader(object, receiver(), last, name, &miss);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001389
1390 // If the last object in the prototype chain is a global object,
1391 // check that the global property cell is empty.
1392 if (!global.is_null()) {
1393 GenerateCheckPropertyCell(masm(), global, name, scratch2(), &miss);
1394 }
1395
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001396 HandlerFrontendFooter(success, &miss);
1397}
1398
1399
1400void BaseLoadStubCompiler::GenerateLoadField(Register reg,
1401 Handle<JSObject> holder,
ulan@chromium.org57ff8812013-05-10 08:16:55 +00001402 PropertyIndex field,
1403 Representation representation) {
1404 if (!reg.is(receiver())) __ mov(receiver(), reg);
1405 if (kind() == Code::LOAD_IC) {
1406 LoadFieldStub stub(field.is_inobject(holder),
1407 field.translate(holder),
1408 representation);
1409 GenerateTailCall(masm(), stub.GetCode(isolate()));
1410 } else {
1411 KeyedLoadFieldStub stub(field.is_inobject(holder),
1412 field.translate(holder),
1413 representation);
1414 GenerateTailCall(masm(), stub.GetCode(isolate()));
1415 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001416}
1417
1418
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001419void BaseLoadStubCompiler::GenerateLoadConstant(Handle<JSFunction> value) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001420 // Return the constant value.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001421 __ LoadHeapObject(v0, value);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001422 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +00001423}
1424
1425
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001426void BaseLoadStubCompiler::GenerateLoadCallback(
1427 Register reg,
1428 Handle<ExecutableAccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001429 // Build AccessorInfo::args_ list on the stack and push property name below
1430 // the exit frame to make GC aware of them and store pointers to them.
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001431 __ push(receiver());
1432 __ mov(scratch2(), sp); // scratch2 = AccessorInfo::args_
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001433 if (heap()->InNewSpace(callback->data())) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001434 __ li(scratch3(), callback);
1435 __ lw(scratch3(), FieldMemOperand(scratch3(),
1436 ExecutableAccessorInfo::kDataOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001437 } else {
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001438 __ li(scratch3(), Handle<Object>(callback->data(), isolate()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001439 }
palfia@homejinni.com79d0bf72013-06-10 19:35:04 +00001440 __ Subu(sp, sp, 6 * kPointerSize);
1441 __ sw(reg, MemOperand(sp, 5 * kPointerSize));
1442 __ sw(scratch3(), MemOperand(sp, 4 * kPointerSize));
jkummerow@chromium.orgc1184022013-05-28 16:58:15 +00001443 __ LoadRoot(scratch3(), Heap::kUndefinedValueRootIndex);
palfia@homejinni.com79d0bf72013-06-10 19:35:04 +00001444 __ sw(scratch3(), MemOperand(sp, 3 * kPointerSize));
1445 __ sw(scratch3(), MemOperand(sp, 2 * kPointerSize));
jkummerow@chromium.orgc1184022013-05-28 16:58:15 +00001446 __ li(scratch4(),
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001447 Operand(ExternalReference::isolate_address(isolate())));
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +00001448 __ sw(scratch4(), MemOperand(sp, 1 * kPointerSize));
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001449 __ sw(name(), MemOperand(sp, 0 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001450
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +00001451 Address getter_address = v8::ToCData<Address>(callback->getter());
1452 bool returns_handle =
1453 !CallbackTable::ReturnsVoid(isolate(), getter_address);
1454
1455 Register first_arg = returns_handle ? a1 : a0;
1456 Register second_arg = returns_handle ? a2 : a1;
1457
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001458 __ mov(a2, scratch2()); // Saved in case scratch2 == a1.
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +00001459 __ mov(first_arg, sp); // (first argument - see note below) = Handle<Name>
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001460
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001461 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
1462 // struct from the function (which is currently the case). This means we pass
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +00001463 // the arguments in a1-a2 instead of a0-a1, if returns_handle is true.
1464 // CallApiFunctionAndReturn will set up a0.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001465
1466 const int kApiStackSpace = 1;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001467 FrameScope frame_scope(masm(), StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001468 __ EnterExitFrame(false, kApiStackSpace);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001469
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001470 // Create AccessorInfo instance on the stack above the exit frame with
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001471 // scratch2 (internal::Object** args_) as the data.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001472 __ sw(a2, MemOperand(sp, kPointerSize));
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +00001473 // (second argument - see note above) = AccessorInfo&
1474 __ Addu(second_arg, sp, kPointerSize);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001475
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +00001476 const int kStackUnwindSpace = kFastApiCallArguments + 1;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001477 ApiFunction fun(getter_address);
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +00001478 ExternalReference::Type type =
1479 returns_handle ?
1480 ExternalReference::DIRECT_GETTER_CALL :
1481 ExternalReference::DIRECT_GETTER_CALL_NEW;
1482
1483 ExternalReference ref = ExternalReference(&fun, type, isolate());
1484 __ CallApiFunctionAndReturn(ref,
1485 kStackUnwindSpace,
1486 returns_handle,
palfia@homejinni.com79d0bf72013-06-10 19:35:04 +00001487 5);
ager@chromium.org5c838252010-02-19 08:53:10 +00001488}
1489
1490
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001491void BaseLoadStubCompiler::GenerateLoadInterceptor(
1492 Register holder_reg,
1493 Handle<JSObject> object,
1494 Handle<JSObject> interceptor_holder,
1495 LookupResult* lookup,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001496 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001497 ASSERT(interceptor_holder->HasNamedInterceptor());
1498 ASSERT(!interceptor_holder->GetNamedInterceptor()->getter()->IsUndefined());
1499
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001500 // So far the most popular follow ups for interceptor loads are FIELD
1501 // and CALLBACKS, so inline only them, other cases may be added
1502 // later.
1503 bool compile_followup_inline = false;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001504 if (lookup->IsFound() && lookup->IsCacheable()) {
yangguo@chromium.orgde0db002012-06-22 13:44:28 +00001505 if (lookup->IsField()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001506 compile_followup_inline = true;
1507 } else if (lookup->type() == CALLBACKS &&
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00001508 lookup->GetCallbackObject()->IsExecutableAccessorInfo()) {
1509 ExecutableAccessorInfo* callback =
1510 ExecutableAccessorInfo::cast(lookup->GetCallbackObject());
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001511 compile_followup_inline = callback->getter() != NULL &&
1512 callback->IsCompatibleReceiver(*object);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001513 }
1514 }
1515
1516 if (compile_followup_inline) {
1517 // Compile the interceptor call, followed by inline code to load the
1518 // property from further up the prototype chain if the call fails.
1519 // Check that the maps haven't changed.
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001520 ASSERT(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001521
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001522 // Preserve the receiver register explicitly whenever it is different from
1523 // the holder and it is needed should the interceptor return without any
1524 // result. The CALLBACKS case needs the receiver to be passed into C++ code,
1525 // the FIELD case might cause a miss during the prototype check.
1526 bool must_perfrom_prototype_check = *interceptor_holder != lookup->holder();
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001527 bool must_preserve_receiver_reg = !receiver().is(holder_reg) &&
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001528 (lookup->type() == CALLBACKS || must_perfrom_prototype_check);
1529
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001530 // Save necessary data before invoking an interceptor.
1531 // Requires a frame to make GC aware of pushed pointers.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001532 {
1533 FrameScope frame_scope(masm(), StackFrame::INTERNAL);
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001534 if (must_preserve_receiver_reg) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001535 __ Push(receiver(), holder_reg, this->name());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001536 } else {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001537 __ Push(holder_reg, this->name());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001538 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001539 // Invoke an interceptor. Note: map checks from receiver to
1540 // interceptor's holder has been compiled before (see a caller
1541 // of this method).
1542 CompileCallLoadPropertyWithInterceptor(masm(),
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001543 receiver(),
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001544 holder_reg,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001545 this->name(),
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001546 interceptor_holder);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001547 // Check if interceptor provided a value for property. If it's
1548 // the case, return immediately.
1549 Label interceptor_failed;
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001550 __ LoadRoot(scratch1(), Heap::kNoInterceptorResultSentinelRootIndex);
1551 __ Branch(&interceptor_failed, eq, v0, Operand(scratch1()));
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001552 frame_scope.GenerateLeaveFrame();
1553 __ Ret();
1554
1555 __ bind(&interceptor_failed);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001556 __ pop(this->name());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001557 __ pop(holder_reg);
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001558 if (must_preserve_receiver_reg) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001559 __ pop(receiver());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001560 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001561 // Leave the internal frame.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001562 }
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001563 GenerateLoadPostInterceptor(holder_reg, interceptor_holder, name, lookup);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001564 } else { // !compile_followup_inline
1565 // Call the runtime system to load the interceptor.
1566 // Check that the maps haven't changed.
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001567 PushInterceptorArguments(masm(), receiver(), holder_reg,
1568 this->name(), interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001569
1570 ExternalReference ref = ExternalReference(
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001571 IC_Utility(IC::kLoadPropertyWithInterceptorForLoad), isolate());
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001572 __ TailCallExternalReference(ref, 6, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001573 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001574}
1575
1576
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001577void CallStubCompiler::GenerateNameCheck(Handle<Name> name, Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001578 if (kind_ == Code::KEYED_CALL_IC) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001579 __ Branch(miss, ne, a2, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001580 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001581}
1582
1583
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001584void CallStubCompiler::GenerateGlobalReceiverCheck(Handle<JSObject> object,
1585 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001586 Handle<Name> name,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001587 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001588 ASSERT(holder->IsGlobalObject());
1589
1590 // Get the number of arguments.
1591 const int argc = arguments().immediate();
1592
1593 // Get the receiver from the stack.
1594 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1595
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001596 // Check that the maps haven't changed.
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00001597 __ JumpIfSmi(a0, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001598 CheckPrototypes(object, a0, holder, a3, a1, t0, name, miss);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001599}
1600
1601
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001602void CallStubCompiler::GenerateLoadFunctionFromCell(
1603 Handle<JSGlobalPropertyCell> cell,
1604 Handle<JSFunction> function,
1605 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001606 // Get the value from the cell.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001607 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001608 __ lw(a1, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
1609
1610 // Check that the cell contains the same function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001611 if (heap()->InNewSpace(*function)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001612 // We can't embed a pointer to a function in new space so we have
1613 // to verify that the shared function info is unchanged. This has
1614 // the nice side effect that multiple closures based on the same
1615 // function can all use this call IC. Before we load through the
1616 // function, we have to verify that it still is a function.
1617 __ JumpIfSmi(a1, miss);
1618 __ GetObjectType(a1, a3, a3);
1619 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
1620
1621 // Check the shared function info. Make sure it hasn't changed.
1622 __ li(a3, Handle<SharedFunctionInfo>(function->shared()));
1623 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
1624 __ Branch(miss, ne, t0, Operand(a3));
1625 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001626 __ Branch(miss, ne, a1, Operand(function));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001627 }
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001628}
1629
1630
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001631void CallStubCompiler::GenerateMissBranch() {
1632 Handle<Code> code =
danno@chromium.org40cb8782011-05-25 07:58:50 +00001633 isolate()->stub_cache()->ComputeCallMiss(arguments().immediate(),
1634 kind_,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001635 extra_state_);
1636 __ Jump(code, RelocInfo::CODE_TARGET);
1637}
1638
1639
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001640Handle<Code> CallStubCompiler::CompileCallField(Handle<JSObject> object,
1641 Handle<JSObject> holder,
yangguo@chromium.orgfb377212012-11-16 14:43:43 +00001642 PropertyIndex index,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001643 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001644 // ----------- S t a t e -------------
1645 // -- a2 : name
1646 // -- ra : return address
1647 // -----------------------------------
1648 Label miss;
1649
1650 GenerateNameCheck(name, &miss);
1651
1652 const int argc = arguments().immediate();
1653
1654 // Get the receiver of the function from the stack into a0.
1655 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1656 // Check that the receiver isn't a smi.
1657 __ JumpIfSmi(a0, &miss, t0);
1658
1659 // Do the right check and compute the holder register.
1660 Register reg = CheckPrototypes(object, a0, holder, a1, a3, t0, name, &miss);
ulan@chromium.org57ff8812013-05-10 08:16:55 +00001661 GenerateFastPropertyLoad(masm(), a1, reg, index.is_inobject(holder),
1662 index.translate(holder), Representation::Tagged());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001663
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001664 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001665
1666 // Handle call cache miss.
1667 __ bind(&miss);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001668 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001669
1670 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00001671 return GetCode(Code::FIELD, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00001672}
1673
1674
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001675Handle<Code> CallStubCompiler::CompileArrayPushCall(
1676 Handle<Object> object,
1677 Handle<JSObject> holder,
1678 Handle<JSGlobalPropertyCell> cell,
1679 Handle<JSFunction> function,
1680 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001681 // ----------- S t a t e -------------
1682 // -- a2 : name
1683 // -- ra : return address
1684 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1685 // -- ...
1686 // -- sp[argc * 4] : receiver
1687 // -----------------------------------
1688
1689 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001690 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001691
1692 Label miss;
1693
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001694 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001695
1696 Register receiver = a1;
1697
1698 // Get the receiver from the stack.
1699 const int argc = arguments().immediate();
1700 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1701
1702 // Check that the receiver isn't a smi.
1703 __ JumpIfSmi(receiver, &miss);
1704
1705 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001706 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, a3, v0, t0,
1707 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001708
1709 if (argc == 0) {
1710 // Nothing to do, just return the length.
1711 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00001712 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001713 } else {
1714 Label call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001715 if (argc == 1) { // Otherwise fall through to call the builtin.
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001716 Label attempt_to_grow_elements, with_write_barrier, check_double;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001717
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001718 Register elements = t2;
1719 Register end_elements = t1;
1720 // Get the elements array of the object.
1721 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1722
1723 // Check that the elements are in fast mode and writable.
1724 __ CheckMap(elements,
1725 v0,
1726 Heap::kFixedArrayMapRootIndex,
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001727 &check_double,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001728 DONT_DO_SMI_CHECK);
1729
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001730 // Get the array's length into v0 and calculate new length.
1731 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1732 STATIC_ASSERT(kSmiTagSize == 1);
1733 STATIC_ASSERT(kSmiTag == 0);
1734 __ Addu(v0, v0, Operand(Smi::FromInt(argc)));
1735
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001736 // Get the elements' length.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001737 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1738
1739 // Check if we could survive without allocation.
1740 __ Branch(&attempt_to_grow_elements, gt, v0, Operand(t0));
1741
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001742 // Check if value is a smi.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001743 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize));
1744 __ JumpIfNotSmi(t0, &with_write_barrier);
1745
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001746 // Save new length.
1747 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1748
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001749 // Store the value.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001750 // We may need a register containing the address end_elements below,
1751 // so write back the value in end_elements.
1752 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1753 __ Addu(end_elements, elements, end_elements);
1754 const int kEndElementsOffset =
1755 FixedArray::kHeaderSize - kHeapObjectTag - argc * kPointerSize;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001756 __ Addu(end_elements, end_elements, kEndElementsOffset);
1757 __ sw(t0, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001758
1759 // Check for a smi.
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00001760 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001761
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001762 __ bind(&check_double);
1763
1764 // Check that the elements are in fast mode and writable.
1765 __ CheckMap(elements,
1766 a0,
1767 Heap::kFixedDoubleArrayMapRootIndex,
1768 &call_builtin,
1769 DONT_DO_SMI_CHECK);
1770
1771 // Get the array's length into r0 and calculate new length.
1772 __ lw(a0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1773 STATIC_ASSERT(kSmiTagSize == 1);
1774 STATIC_ASSERT(kSmiTag == 0);
1775 __ Addu(a0, a0, Operand(Smi::FromInt(argc)));
1776
1777 // Get the elements' length.
1778 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1779
1780 // Check if we could survive without allocation.
1781 __ Branch(&call_builtin, gt, a0, Operand(t0));
1782
1783 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize));
1784 __ StoreNumberToDoubleElements(
1785 t0, a0, elements, a3, t1, a2, t5,
1786 &call_builtin, argc * kDoubleSize);
1787
1788 // Save new length.
1789 __ sw(a0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1790
1791 // Check for a smi.
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00001792 __ DropAndRet(argc + 1);
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001793
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001794 __ bind(&with_write_barrier);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001795
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001796 __ lw(a3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1797
1798 if (FLAG_smi_only_arrays && !FLAG_trace_elements_transitions) {
1799 Label fast_object, not_fast_object;
1800 __ CheckFastObjectElements(a3, t3, &not_fast_object);
1801 __ jmp(&fast_object);
1802 // In case of fast smi-only, convert to fast object, otherwise bail out.
1803 __ bind(&not_fast_object);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001804 __ CheckFastSmiElements(a3, t3, &call_builtin);
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001805
1806 __ lw(t3, FieldMemOperand(t0, HeapObject::kMapOffset));
1807 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex);
1808 __ Branch(&call_builtin, eq, t3, Operand(at));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001809 // edx: receiver
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001810 // a3: map
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001811 Label try_holey_map;
1812 __ LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001813 FAST_ELEMENTS,
1814 a3,
1815 t3,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001816 &try_holey_map);
1817 __ mov(a2, receiver);
1818 ElementsTransitionGenerator::
yangguo@chromium.org28381b42013-01-21 14:39:38 +00001819 GenerateMapChangeElementsTransition(masm(),
1820 DONT_TRACK_ALLOCATION_SITE,
1821 NULL);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001822 __ jmp(&fast_object);
1823
1824 __ bind(&try_holey_map);
1825 __ LoadTransitionedArrayMapConditional(FAST_HOLEY_SMI_ELEMENTS,
1826 FAST_HOLEY_ELEMENTS,
1827 a3,
1828 t3,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001829 &call_builtin);
1830 __ mov(a2, receiver);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001831 ElementsTransitionGenerator::
yangguo@chromium.org28381b42013-01-21 14:39:38 +00001832 GenerateMapChangeElementsTransition(masm(),
1833 DONT_TRACK_ALLOCATION_SITE,
1834 NULL);
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001835 __ bind(&fast_object);
1836 } else {
1837 __ CheckFastObjectElements(a3, a3, &call_builtin);
1838 }
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001839
1840 // Save new length.
1841 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1842
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001843 // Store the value.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001844 // We may need a register containing the address end_elements below,
1845 // so write back the value in end_elements.
1846 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1847 __ Addu(end_elements, elements, end_elements);
1848 __ Addu(end_elements, end_elements, kEndElementsOffset);
1849 __ sw(t0, MemOperand(end_elements));
1850
1851 __ RecordWrite(elements,
1852 end_elements,
1853 t0,
1854 kRAHasNotBeenSaved,
1855 kDontSaveFPRegs,
1856 EMIT_REMEMBERED_SET,
1857 OMIT_SMI_CHECK);
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00001858 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001859
1860 __ bind(&attempt_to_grow_elements);
1861 // v0: array's length + 1.
1862 // t0: elements' length.
1863
1864 if (!FLAG_inline_new) {
1865 __ Branch(&call_builtin);
1866 }
1867
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001868 __ lw(a2, MemOperand(sp, (argc - 1) * kPointerSize));
1869 // Growing elements that are SMI-only requires special handling in case
1870 // the new element is non-Smi. For now, delegate to the builtin.
1871 Label no_fast_elements_check;
1872 __ JumpIfSmi(a2, &no_fast_elements_check);
1873 __ lw(t3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1874 __ CheckFastObjectElements(t3, t3, &call_builtin);
1875 __ bind(&no_fast_elements_check);
1876
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001877 ExternalReference new_space_allocation_top =
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001878 ExternalReference::new_space_allocation_top_address(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001879 ExternalReference new_space_allocation_limit =
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001880 ExternalReference::new_space_allocation_limit_address(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001881
1882 const int kAllocationDelta = 4;
1883 // Load top and check if it is the end of elements.
1884 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1885 __ Addu(end_elements, elements, end_elements);
1886 __ Addu(end_elements, end_elements, Operand(kEndElementsOffset));
1887 __ li(t3, Operand(new_space_allocation_top));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001888 __ lw(a3, MemOperand(t3));
1889 __ Branch(&call_builtin, ne, end_elements, Operand(a3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001890
1891 __ li(t5, Operand(new_space_allocation_limit));
1892 __ lw(t5, MemOperand(t5));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001893 __ Addu(a3, a3, Operand(kAllocationDelta * kPointerSize));
1894 __ Branch(&call_builtin, hi, a3, Operand(t5));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001895
1896 // We fit and could grow elements.
1897 // Update new_space_allocation_top.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001898 __ sw(a3, MemOperand(t3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001899 // Push the argument.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001900 __ sw(a2, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001901 // Fill the rest with holes.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001902 __ LoadRoot(a3, Heap::kTheHoleValueRootIndex);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001903 for (int i = 1; i < kAllocationDelta; i++) {
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001904 __ sw(a3, MemOperand(end_elements, i * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001905 }
1906
1907 // Update elements' and array's sizes.
1908 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1909 __ Addu(t0, t0, Operand(Smi::FromInt(kAllocationDelta)));
1910 __ sw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1911
1912 // Elements are in new space, so write barrier is not required.
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00001913 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001914 }
1915 __ bind(&call_builtin);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001916 __ TailCallExternalReference(
1917 ExternalReference(Builtins::c_ArrayPush, isolate()), argc + 1, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001918 }
1919
1920 // Handle call cache miss.
1921 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001922 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001923
1924 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001925 return GetCode(function);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001926}
1927
1928
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001929Handle<Code> CallStubCompiler::CompileArrayPopCall(
1930 Handle<Object> object,
1931 Handle<JSObject> holder,
1932 Handle<JSGlobalPropertyCell> cell,
1933 Handle<JSFunction> function,
1934 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001935 // ----------- S t a t e -------------
1936 // -- a2 : name
1937 // -- ra : return address
1938 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1939 // -- ...
1940 // -- sp[argc * 4] : receiver
1941 // -----------------------------------
1942
1943 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001944 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001945
1946 Label miss, return_undefined, call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001947 Register receiver = a1;
1948 Register elements = a3;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001949 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001950
1951 // Get the receiver from the stack.
1952 const int argc = arguments().immediate();
1953 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001954 // Check that the receiver isn't a smi.
1955 __ JumpIfSmi(receiver, &miss);
1956
1957 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001958 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, elements,
1959 t0, v0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001960
1961 // Get the elements array of the object.
1962 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1963
1964 // Check that the elements are in fast mode and writable.
danno@chromium.org40cb8782011-05-25 07:58:50 +00001965 __ CheckMap(elements,
1966 v0,
1967 Heap::kFixedArrayMapRootIndex,
1968 &call_builtin,
1969 DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001970
1971 // Get the array's length into t0 and calculate new length.
1972 __ lw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1973 __ Subu(t0, t0, Operand(Smi::FromInt(1)));
1974 __ Branch(&return_undefined, lt, t0, Operand(zero_reg));
1975
1976 // Get the last element.
1977 __ LoadRoot(t2, Heap::kTheHoleValueRootIndex);
1978 STATIC_ASSERT(kSmiTagSize == 1);
1979 STATIC_ASSERT(kSmiTag == 0);
1980 // We can't address the last element in one operation. Compute the more
1981 // expensive shift first, and use an offset later on.
1982 __ sll(t1, t0, kPointerSizeLog2 - kSmiTagSize);
1983 __ Addu(elements, elements, t1);
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00001984 __ lw(v0, FieldMemOperand(elements, FixedArray::kHeaderSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001985 __ Branch(&call_builtin, eq, v0, Operand(t2));
1986
1987 // Set the array's length.
1988 __ sw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1989
1990 // Fill with the hole.
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00001991 __ sw(t2, FieldMemOperand(elements, FixedArray::kHeaderSize));
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00001992 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001993
1994 __ bind(&return_undefined);
1995 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00001996 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001997
1998 __ bind(&call_builtin);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001999 __ TailCallExternalReference(
2000 ExternalReference(Builtins::c_ArrayPop, isolate()), argc + 1, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002001
2002 // Handle call cache miss.
2003 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002004 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002005
2006 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002007 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002008}
2009
2010
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002011Handle<Code> CallStubCompiler::CompileStringCharCodeAtCall(
2012 Handle<Object> object,
2013 Handle<JSObject> holder,
2014 Handle<JSGlobalPropertyCell> cell,
2015 Handle<JSFunction> function,
2016 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002017 // ----------- S t a t e -------------
2018 // -- a2 : function name
2019 // -- ra : return address
2020 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2021 // -- ...
2022 // -- sp[argc * 4] : receiver
2023 // -----------------------------------
2024
2025 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002026 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002027
2028 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002029 Label miss;
2030 Label name_miss;
2031 Label index_out_of_range;
2032
2033 Label* index_out_of_range_label = &index_out_of_range;
2034
danno@chromium.org40cb8782011-05-25 07:58:50 +00002035 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002036 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00002037 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002038 index_out_of_range_label = &miss;
2039 }
2040
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002041 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002042
2043 // Check that the maps starting from the prototype haven't changed.
2044 GenerateDirectLoadGlobalFunctionPrototype(masm(),
2045 Context::STRING_FUNCTION_INDEX,
2046 v0,
2047 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002048 ASSERT(!object.is_identical_to(holder));
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002049 CheckPrototypes(
2050 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
2051 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002052
2053 Register receiver = a1;
2054 Register index = t1;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002055 Register result = v0;
2056 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
2057 if (argc > 0) {
2058 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
2059 } else {
2060 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
2061 }
2062
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002063 StringCharCodeAtGenerator generator(receiver,
2064 index,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002065 result,
2066 &miss, // When not a string.
2067 &miss, // When not a number.
2068 index_out_of_range_label,
2069 STRING_INDEX_IS_NUMBER);
2070 generator.GenerateFast(masm());
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002071 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002072
2073 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002074 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002075
2076 if (index_out_of_range.is_linked()) {
2077 __ bind(&index_out_of_range);
2078 __ LoadRoot(v0, Heap::kNanValueRootIndex);
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002079 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002080 }
2081
2082 __ bind(&miss);
2083 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002084 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002085 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002086 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002087
2088 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002089 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002090}
2091
2092
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002093Handle<Code> CallStubCompiler::CompileStringCharAtCall(
2094 Handle<Object> object,
2095 Handle<JSObject> holder,
2096 Handle<JSGlobalPropertyCell> cell,
2097 Handle<JSFunction> function,
2098 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002099 // ----------- S t a t e -------------
2100 // -- a2 : function name
2101 // -- ra : return address
2102 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2103 // -- ...
2104 // -- sp[argc * 4] : receiver
2105 // -----------------------------------
2106
2107 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002108 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002109
2110 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002111 Label miss;
2112 Label name_miss;
2113 Label index_out_of_range;
2114 Label* index_out_of_range_label = &index_out_of_range;
danno@chromium.org40cb8782011-05-25 07:58:50 +00002115 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002116 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00002117 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002118 index_out_of_range_label = &miss;
2119 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002120 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002121
2122 // Check that the maps starting from the prototype haven't changed.
2123 GenerateDirectLoadGlobalFunctionPrototype(masm(),
2124 Context::STRING_FUNCTION_INDEX,
2125 v0,
2126 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002127 ASSERT(!object.is_identical_to(holder));
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002128 CheckPrototypes(
2129 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
2130 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002131
2132 Register receiver = v0;
2133 Register index = t1;
danno@chromium.orgc612e022011-11-10 11:38:15 +00002134 Register scratch = a3;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002135 Register result = v0;
2136 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
2137 if (argc > 0) {
2138 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
2139 } else {
2140 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
2141 }
2142
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002143 StringCharAtGenerator generator(receiver,
2144 index,
danno@chromium.orgc612e022011-11-10 11:38:15 +00002145 scratch,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002146 result,
2147 &miss, // When not a string.
2148 &miss, // When not a number.
2149 index_out_of_range_label,
2150 STRING_INDEX_IS_NUMBER);
2151 generator.GenerateFast(masm());
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002152 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002153
2154 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002155 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002156
2157 if (index_out_of_range.is_linked()) {
2158 __ bind(&index_out_of_range);
ulan@chromium.org750145a2013-03-07 15:14:13 +00002159 __ LoadRoot(v0, Heap::kempty_stringRootIndex);
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002160 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002161 }
2162
2163 __ bind(&miss);
2164 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002165 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002166 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002167 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002168
2169 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002170 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002171}
2172
2173
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002174Handle<Code> CallStubCompiler::CompileStringFromCharCodeCall(
2175 Handle<Object> object,
2176 Handle<JSObject> holder,
2177 Handle<JSGlobalPropertyCell> cell,
2178 Handle<JSFunction> function,
2179 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002180 // ----------- S t a t e -------------
2181 // -- a2 : function name
2182 // -- ra : return address
2183 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2184 // -- ...
2185 // -- sp[argc * 4] : receiver
2186 // -----------------------------------
2187
2188 const int argc = arguments().immediate();
2189
2190 // If the object is not a JSObject or we got an unexpected number of
2191 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002192 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002193
2194 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002195 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002196
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002197 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002198 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
2199
2200 STATIC_ASSERT(kSmiTag == 0);
2201 __ JumpIfSmi(a1, &miss);
2202
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002203 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
2204 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002205 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002206 ASSERT(cell->value() == *function);
2207 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2208 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002209 GenerateLoadFunctionFromCell(cell, function, &miss);
2210 }
2211
2212 // Load the char code argument.
2213 Register code = a1;
2214 __ lw(code, MemOperand(sp, 0 * kPointerSize));
2215
2216 // Check the code is a smi.
2217 Label slow;
2218 STATIC_ASSERT(kSmiTag == 0);
2219 __ JumpIfNotSmi(code, &slow);
2220
2221 // Convert the smi code to uint16.
2222 __ And(code, code, Operand(Smi::FromInt(0xffff)));
2223
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002224 StringCharFromCodeGenerator generator(code, v0);
2225 generator.GenerateFast(masm());
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002226 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002227
2228 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002229 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002230
2231 // Tail call the full function. We do not have to patch the receiver
2232 // because the function makes no use of it.
2233 __ bind(&slow);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002234 ParameterCount expected(function);
2235 __ InvokeFunction(function, expected, arguments(),
2236 JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002237
2238 __ bind(&miss);
2239 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002240 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002241
2242 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002243 return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002244}
2245
2246
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002247Handle<Code> CallStubCompiler::CompileMathFloorCall(
2248 Handle<Object> object,
2249 Handle<JSObject> holder,
2250 Handle<JSGlobalPropertyCell> cell,
2251 Handle<JSFunction> function,
2252 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002253 // ----------- S t a t e -------------
2254 // -- a2 : function name
2255 // -- ra : return address
2256 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2257 // -- ...
2258 // -- sp[argc * 4] : receiver
2259 // -----------------------------------
2260
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002261
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002262 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002263 // If the object is not a JSObject or we got an unexpected number of
2264 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002265 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002266
2267 Label miss, slow;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002268 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002269
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002270 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002271 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002272 STATIC_ASSERT(kSmiTag == 0);
2273 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002274 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2275 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002276 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002277 ASSERT(cell->value() == *function);
2278 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2279 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002280 GenerateLoadFunctionFromCell(cell, function, &miss);
2281 }
2282
2283 // Load the (only) argument into v0.
2284 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2285
2286 // If the argument is a smi, just return.
2287 STATIC_ASSERT(kSmiTag == 0);
2288 __ And(t0, v0, Operand(kSmiTagMask));
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002289 __ DropAndRet(argc + 1, eq, t0, Operand(zero_reg));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002290
danno@chromium.org40cb8782011-05-25 07:58:50 +00002291 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002292
2293 Label wont_fit_smi, no_fpu_error, restore_fcsr_and_return;
2294
2295 // If fpu is enabled, we use the floor instruction.
2296
2297 // Load the HeapNumber value.
2298 __ ldc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
2299
2300 // Backup FCSR.
2301 __ cfc1(a3, FCSR);
2302 // Clearing FCSR clears the exception mask with no side-effects.
2303 __ ctc1(zero_reg, FCSR);
2304 // Convert the argument to an integer.
2305 __ floor_w_d(f0, f0);
2306
2307 // Start checking for special cases.
2308 // Get the argument exponent and clear the sign bit.
2309 __ lw(t1, FieldMemOperand(v0, HeapNumber::kValueOffset + kPointerSize));
2310 __ And(t2, t1, Operand(~HeapNumber::kSignMask));
2311 __ srl(t2, t2, HeapNumber::kMantissaBitsInTopWord);
2312
2313 // Retrieve FCSR and check for fpu errors.
2314 __ cfc1(t5, FCSR);
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002315 __ And(t5, t5, Operand(kFCSRExceptionFlagMask));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002316 __ Branch(&no_fpu_error, eq, t5, Operand(zero_reg));
2317
2318 // Check for NaN, Infinity, and -Infinity.
2319 // They are invariant through a Math.Floor call, so just
2320 // return the original argument.
2321 __ Subu(t3, t2, Operand(HeapNumber::kExponentMask
2322 >> HeapNumber::kMantissaBitsInTopWord));
2323 __ Branch(&restore_fcsr_and_return, eq, t3, Operand(zero_reg));
2324 // We had an overflow or underflow in the conversion. Check if we
2325 // have a big exponent.
2326 // If greater or equal, the argument is already round and in v0.
2327 __ Branch(&restore_fcsr_and_return, ge, t3,
2328 Operand(HeapNumber::kMantissaBits));
2329 __ Branch(&wont_fit_smi);
2330
2331 __ bind(&no_fpu_error);
2332 // Move the result back to v0.
2333 __ mfc1(v0, f0);
2334 // Check if the result fits into a smi.
2335 __ Addu(a1, v0, Operand(0x40000000));
2336 __ Branch(&wont_fit_smi, lt, a1, Operand(zero_reg));
2337 // Tag the result.
2338 STATIC_ASSERT(kSmiTag == 0);
2339 __ sll(v0, v0, kSmiTagSize);
2340
2341 // Check for -0.
2342 __ Branch(&restore_fcsr_and_return, ne, v0, Operand(zero_reg));
2343 // t1 already holds the HeapNumber exponent.
2344 __ And(t0, t1, Operand(HeapNumber::kSignMask));
2345 // If our HeapNumber is negative it was -0, so load its address and return.
2346 // Else v0 is loaded with 0, so we can also just return.
2347 __ Branch(&restore_fcsr_and_return, eq, t0, Operand(zero_reg));
2348 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2349
2350 __ bind(&restore_fcsr_and_return);
2351 // Restore FCSR and return.
2352 __ ctc1(a3, FCSR);
2353
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002354 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002355
2356 __ bind(&wont_fit_smi);
2357 // Restore FCSR and fall to slow case.
2358 __ ctc1(a3, FCSR);
2359
2360 __ bind(&slow);
2361 // Tail call the full function. We do not have to patch the receiver
2362 // because the function makes no use of it.
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002363 ParameterCount expected(function);
2364 __ InvokeFunction(function, expected, arguments(),
2365 JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002366
2367 __ bind(&miss);
2368 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002369 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002370
2371 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002372 return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002373}
2374
2375
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002376Handle<Code> CallStubCompiler::CompileMathAbsCall(
2377 Handle<Object> object,
2378 Handle<JSObject> holder,
2379 Handle<JSGlobalPropertyCell> cell,
2380 Handle<JSFunction> function,
2381 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002382 // ----------- S t a t e -------------
2383 // -- a2 : function name
2384 // -- ra : return address
2385 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2386 // -- ...
2387 // -- sp[argc * 4] : receiver
2388 // -----------------------------------
2389
2390 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002391 // If the object is not a JSObject or we got an unexpected number of
2392 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002393 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002394
2395 Label miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002396
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002397 GenerateNameCheck(name, &miss);
2398 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002399 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002400 STATIC_ASSERT(kSmiTag == 0);
2401 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002402 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
2403 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002404 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002405 ASSERT(cell->value() == *function);
2406 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2407 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002408 GenerateLoadFunctionFromCell(cell, function, &miss);
2409 }
2410
2411 // Load the (only) argument into v0.
2412 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2413
2414 // Check if the argument is a smi.
2415 Label not_smi;
2416 STATIC_ASSERT(kSmiTag == 0);
2417 __ JumpIfNotSmi(v0, &not_smi);
2418
2419 // Do bitwise not or do nothing depending on the sign of the
2420 // argument.
2421 __ sra(t0, v0, kBitsPerInt - 1);
2422 __ Xor(a1, v0, t0);
2423
2424 // Add 1 or do nothing depending on the sign of the argument.
2425 __ Subu(v0, a1, t0);
2426
2427 // If the result is still negative, go to the slow case.
2428 // This only happens for the most negative smi.
2429 Label slow;
2430 __ Branch(&slow, lt, v0, Operand(zero_reg));
2431
2432 // Smi case done.
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002433 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002434
2435 // Check if the argument is a heap number and load its exponent and
2436 // sign.
2437 __ bind(&not_smi);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002438 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002439 __ lw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2440
2441 // Check the sign of the argument. If the argument is positive,
2442 // just return it.
2443 Label negative_sign;
2444 __ And(t0, a1, Operand(HeapNumber::kSignMask));
2445 __ Branch(&negative_sign, ne, t0, Operand(zero_reg));
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002446 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002447
2448 // If the argument is negative, clear the sign, and return a new
2449 // number.
2450 __ bind(&negative_sign);
2451 __ Xor(a1, a1, Operand(HeapNumber::kSignMask));
2452 __ lw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2453 __ LoadRoot(t2, Heap::kHeapNumberMapRootIndex);
2454 __ AllocateHeapNumber(v0, t0, t1, t2, &slow);
2455 __ sw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2456 __ sw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00002457 __ DropAndRet(argc + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002458
2459 // Tail call the full function. We do not have to patch the receiver
2460 // because the function makes no use of it.
2461 __ bind(&slow);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002462 ParameterCount expected(function);
2463 __ InvokeFunction(function, expected, arguments(),
2464 JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002465
2466 __ bind(&miss);
2467 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002468 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002469
2470 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002471 return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002472}
2473
2474
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002475Handle<Code> CallStubCompiler::CompileFastApiCall(
lrn@chromium.org7516f052011-03-30 08:52:27 +00002476 const CallOptimization& optimization,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002477 Handle<Object> object,
2478 Handle<JSObject> holder,
2479 Handle<JSGlobalPropertyCell> cell,
2480 Handle<JSFunction> function,
2481 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002482
danno@chromium.org40cb8782011-05-25 07:58:50 +00002483 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002484
2485 ASSERT(optimization.is_simple_api_call());
2486 // Bail out if object is a global object as we don't want to
2487 // repatch it to global receiver.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002488 if (object->IsGlobalObject()) return Handle<Code>::null();
2489 if (!cell.is_null()) return Handle<Code>::null();
2490 if (!object->IsJSObject()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002491 int depth = optimization.GetPrototypeDepthOfExpectedType(
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002492 Handle<JSObject>::cast(object), holder);
2493 if (depth == kInvalidProtoDepth) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002494
2495 Label miss, miss_before_stack_reserved;
2496
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002497 GenerateNameCheck(name, &miss_before_stack_reserved);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002498
2499 // Get the receiver from the stack.
2500 const int argc = arguments().immediate();
2501 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2502
2503 // Check that the receiver isn't a smi.
2504 __ JumpIfSmi(a1, &miss_before_stack_reserved);
2505
2506 __ IncrementCounter(counters->call_const(), 1, a0, a3);
2507 __ IncrementCounter(counters->call_const_fast_api(), 1, a0, a3);
2508
2509 ReserveSpaceForFastApiCall(masm(), a0);
2510
2511 // Check that the maps haven't changed and find a Holder as a side effect.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002512 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0, name,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002513 depth, &miss);
2514
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002515 GenerateFastApiDirectCall(masm(), optimization, argc);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002516
2517 __ bind(&miss);
2518 FreeSpaceForFastApiCall(masm());
2519
2520 __ bind(&miss_before_stack_reserved);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002521 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002522
2523 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002524 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002525}
2526
2527
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002528void CallStubCompiler::CompileHandlerFrontend(Handle<Object> object,
2529 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002530 Handle<Name> name,
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002531 CheckType check,
2532 Label* success) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002533 // ----------- S t a t e -------------
2534 // -- a2 : name
2535 // -- ra : return address
2536 // -----------------------------------
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002537 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002538 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002539
2540 // Get the receiver from the stack.
2541 const int argc = arguments().immediate();
2542 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2543
2544 // Check that the receiver isn't a smi.
2545 if (check != NUMBER_CHECK) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002546 __ JumpIfSmi(a1, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002547 }
2548
2549 // Make sure that it's okay not to patch the on stack receiver
2550 // unless we're doing a receiver map check.
2551 ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002552 switch (check) {
2553 case RECEIVER_MAP_CHECK:
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002554 __ IncrementCounter(isolate()->counters()->call_const(), 1, a0, a3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002555
2556 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002557 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2558 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002559
2560 // Patch the receiver on the stack with the global proxy if
2561 // necessary.
2562 if (object->IsGlobalObject()) {
2563 __ lw(a3, FieldMemOperand(a1, GlobalObject::kGlobalReceiverOffset));
2564 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2565 }
2566 break;
2567
2568 case STRING_CHECK:
ulan@chromium.org750145a2013-03-07 15:14:13 +00002569 // Check that the object is a string.
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002570 __ GetObjectType(a1, a3, a3);
2571 __ Branch(&miss, Ugreater_equal, a3, Operand(FIRST_NONSTRING_TYPE));
2572 // Check that the maps starting from the prototype haven't changed.
2573 GenerateDirectLoadGlobalFunctionPrototype(
2574 masm(), Context::STRING_FUNCTION_INDEX, a0, &miss);
2575 CheckPrototypes(
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002576 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002577 a0, holder, a3, a1, t0, name, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002578 break;
2579
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002580 case SYMBOL_CHECK:
2581 // Check that the object is a symbol.
2582 __ GetObjectType(a1, a1, a3);
2583 __ Branch(&miss, ne, a3, Operand(SYMBOL_TYPE));
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +00002584 // Check that the maps starting from the prototype haven't changed.
2585 GenerateDirectLoadGlobalFunctionPrototype(
2586 masm(), Context::SYMBOL_FUNCTION_INDEX, a0, &miss);
2587 CheckPrototypes(
2588 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
2589 a0, holder, a3, a1, t0, name, &miss);
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002590 break;
2591
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002592 case NUMBER_CHECK: {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002593 Label fast;
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002594 // Check that the object is a smi or a heap number.
2595 __ JumpIfSmi(a1, &fast);
2596 __ GetObjectType(a1, a0, a0);
2597 __ Branch(&miss, ne, a0, Operand(HEAP_NUMBER_TYPE));
2598 __ bind(&fast);
2599 // Check that the maps starting from the prototype haven't changed.
2600 GenerateDirectLoadGlobalFunctionPrototype(
2601 masm(), Context::NUMBER_FUNCTION_INDEX, a0, &miss);
2602 CheckPrototypes(
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002603 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002604 a0, holder, a3, a1, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002605 break;
2606 }
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002607 case BOOLEAN_CHECK: {
2608 Label fast;
2609 // Check that the object is a boolean.
2610 __ LoadRoot(t0, Heap::kTrueValueRootIndex);
2611 __ Branch(&fast, eq, a1, Operand(t0));
2612 __ LoadRoot(t0, Heap::kFalseValueRootIndex);
2613 __ Branch(&miss, ne, a1, Operand(t0));
2614 __ bind(&fast);
2615 // Check that the maps starting from the prototype haven't changed.
2616 GenerateDirectLoadGlobalFunctionPrototype(
2617 masm(), Context::BOOLEAN_FUNCTION_INDEX, a0, &miss);
2618 CheckPrototypes(
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002619 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002620 a0, holder, a3, a1, t0, name, &miss);
2621 break;
2622 }
2623 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002624
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002625 __ jmp(success);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002626
2627 // Handle call cache miss.
2628 __ bind(&miss);
2629
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002630 GenerateMissBranch();
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002631}
2632
2633
2634void CallStubCompiler::CompileHandlerBackend(Handle<JSFunction> function) {
2635 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
2636 ? CALL_AS_FUNCTION
2637 : CALL_AS_METHOD;
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002638 ParameterCount expected(function);
2639 __ InvokeFunction(function, expected, arguments(),
2640 JUMP_FUNCTION, NullCallWrapper(), call_kind);
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002641}
2642
2643
2644Handle<Code> CallStubCompiler::CompileCallConstant(
2645 Handle<Object> object,
2646 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002647 Handle<Name> name,
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002648 CheckType check,
2649 Handle<JSFunction> function) {
2650 if (HasCustomCallGenerator(function)) {
2651 Handle<Code> code = CompileCustomCall(object, holder,
2652 Handle<JSGlobalPropertyCell>::null(),
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002653 function, Handle<String>::cast(name));
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002654 // A null handle means bail out to the regular compiler code below.
2655 if (!code.is_null()) return code;
2656 }
2657
2658 Label success;
2659
2660 CompileHandlerFrontend(object, holder, name, check, &success);
2661 __ bind(&success);
2662 CompileHandlerBackend(function);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002663
2664 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002665 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002666}
2667
2668
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002669Handle<Code> CallStubCompiler::CompileCallInterceptor(Handle<JSObject> object,
2670 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002671 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002672 // ----------- S t a t e -------------
2673 // -- a2 : name
2674 // -- ra : return address
2675 // -----------------------------------
2676
2677 Label miss;
2678
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002679 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002680
2681 // Get the number of arguments.
2682 const int argc = arguments().immediate();
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002683 LookupResult lookup(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002684 LookupPostInterceptor(holder, name, &lookup);
2685
2686 // Get the receiver from the stack.
2687 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2688
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002689 CallInterceptorCompiler compiler(this, arguments(), a2, extra_state_);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002690 compiler.Compile(masm(), object, holder, name, &lookup, a1, a3, t0, a0,
2691 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002692
2693 // Move returned value, the function to call, to a1.
2694 __ mov(a1, v0);
2695 // Restore receiver.
2696 __ lw(a0, MemOperand(sp, argc * kPointerSize));
2697
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002698 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002699
2700 // Handle call cache miss.
2701 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002702 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002703
2704 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002705 return GetCode(Code::INTERCEPTOR, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002706}
2707
2708
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002709Handle<Code> CallStubCompiler::CompileCallGlobal(
2710 Handle<JSObject> object,
2711 Handle<GlobalObject> holder,
2712 Handle<JSGlobalPropertyCell> cell,
2713 Handle<JSFunction> function,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002714 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002715 // ----------- S t a t e -------------
2716 // -- a2 : name
2717 // -- ra : return address
2718 // -----------------------------------
2719
2720 if (HasCustomCallGenerator(function)) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002721 Handle<Code> code = CompileCustomCall(
2722 object, holder, cell, function, Handle<String>::cast(name));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002723 // A null handle means bail out to the regular compiler code below.
2724 if (!code.is_null()) return code;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002725 }
2726
2727 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002728 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002729
2730 // Get the number of arguments.
2731 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002732 GenerateGlobalReceiverCheck(object, holder, name, &miss);
2733 GenerateLoadFunctionFromCell(cell, function, &miss);
2734
2735 // Patch the receiver on the stack with the global proxy if
2736 // necessary.
2737 if (object->IsGlobalObject()) {
2738 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
2739 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2740 }
2741
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002742 // Set up the context (function already in r1).
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002743 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
2744
2745 // Jump to the cached code (tail call).
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002746 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002747 __ IncrementCounter(counters->call_global_inline(), 1, a3, t0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002748 ParameterCount expected(function->shared()->formal_parameter_count());
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002749 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
danno@chromium.org40cb8782011-05-25 07:58:50 +00002750 ? CALL_AS_FUNCTION
2751 : CALL_AS_METHOD;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002752 // We call indirectly through the code field in the function to
2753 // allow recompilation to take effect without changing any of the
2754 // call sites.
2755 __ lw(a3, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
2756 __ InvokeCode(a3, expected, arguments(), JUMP_FUNCTION,
2757 NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002758
2759 // Handle call cache miss.
2760 __ bind(&miss);
2761 __ IncrementCounter(counters->call_global_inline_miss(), 1, a1, a3);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002762 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002763
2764 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002765 return GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002766}
2767
2768
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002769Handle<Code> StoreStubCompiler::CompileStoreCallback(
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002770 Handle<Name> name,
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002771 Handle<JSObject> object,
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002772 Handle<JSObject> holder,
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00002773 Handle<ExecutableAccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002774 Label miss;
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002775 // Check that the maps haven't changed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002776 __ JumpIfSmi(receiver(), &miss);
2777 CheckPrototypes(object, receiver(), holder,
2778 scratch1(), scratch2(), scratch3(), name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002779
2780 // Stub never generated for non-global objects that require access
2781 // checks.
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002782 ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002783
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002784 __ push(receiver()); // Receiver.
2785 __ li(at, Operand(callback)); // Callback info.
2786 __ Push(at, this->name(), value());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002787
2788 // Do tail-call to the runtime system.
2789 ExternalReference store_callback_property =
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002790 ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002791 __ TailCallExternalReference(store_callback_property, 4, 1);
2792
2793 // Handle store cache miss.
2794 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002795 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002796
2797 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002798 return GetICCode(kind(), Code::CALLBACKS, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002799}
2800
2801
yangguo@chromium.org46839fb2012-08-28 09:06:19 +00002802#undef __
2803#define __ ACCESS_MASM(masm)
2804
2805
2806void StoreStubCompiler::GenerateStoreViaSetter(
2807 MacroAssembler* masm,
2808 Handle<JSFunction> setter) {
2809 // ----------- S t a t e -------------
2810 // -- a0 : value
2811 // -- a1 : receiver
2812 // -- a2 : name
2813 // -- ra : return address
2814 // -----------------------------------
2815 {
2816 FrameScope scope(masm, StackFrame::INTERNAL);
2817
2818 // Save value register, so we can restore it later.
2819 __ push(a0);
2820
2821 if (!setter.is_null()) {
2822 // Call the JavaScript setter with receiver and value on the stack.
2823 __ push(a1);
2824 __ push(a0);
2825 ParameterCount actual(1);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002826 ParameterCount expected(setter);
2827 __ InvokeFunction(setter, expected, actual,
2828 CALL_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
yangguo@chromium.org46839fb2012-08-28 09:06:19 +00002829 } else {
2830 // If we generate a global code snippet for deoptimization only, remember
2831 // the place to continue after deoptimization.
2832 masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
2833 }
2834
2835 // We have to return the passed value, not the return value of the setter.
2836 __ pop(v0);
2837
2838 // Restore context register.
2839 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2840 }
2841 __ Ret();
2842}
2843
2844
2845#undef __
2846#define __ ACCESS_MASM(masm())
2847
2848
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002849Handle<Code> StoreStubCompiler::CompileStoreInterceptor(
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002850 Handle<JSObject> object,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002851 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002852 Label miss;
2853
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002854 // Check that the map of the object hasn't changed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002855 __ CheckMap(receiver(), scratch1(), Handle<Map>(object->map()), &miss,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +00002856 DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002857
2858 // Perform global security token check if needed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002859 if (object->IsJSGlobalProxy()) {
2860 __ CheckAccessGlobalProxy(receiver(), scratch1(), &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002861 }
2862
2863 // Stub is never generated for non-global objects that require access
2864 // checks.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002865 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002866
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002867 __ Push(receiver(), this->name(), value());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002868
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002869 __ li(scratch1(), Operand(Smi::FromInt(strict_mode())));
2870 __ push(scratch1()); // strict mode
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002871
2872 // Do tail-call to the runtime system.
2873 ExternalReference store_ic_property =
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002874 ExternalReference(IC_Utility(IC::kStoreInterceptorProperty), isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002875 __ TailCallExternalReference(store_ic_property, 4, 1);
2876
2877 // Handle store cache miss.
2878 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002879 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002880
2881 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002882 return GetICCode(kind(), Code::INTERCEPTOR, name);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00002883}
2884
2885
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002886Handle<Code> StoreStubCompiler::CompileStoreGlobal(
2887 Handle<GlobalObject> object,
2888 Handle<JSGlobalPropertyCell> cell,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002889 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002890 Label miss;
2891
2892 // Check that the map of the global has not changed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002893 __ lw(scratch1(), FieldMemOperand(receiver(), HeapObject::kMapOffset));
2894 __ Branch(&miss, ne, scratch1(), Operand(Handle<Map>(object->map())));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002895
2896 // Check that the value in the cell is not the hole. If it is, this
2897 // cell could have been deleted and reintroducing the global needs
2898 // to update the property details in the property dictionary of the
2899 // global object. We bail out to the runtime system to do that.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002900 __ li(scratch1(), Operand(cell));
2901 __ LoadRoot(scratch2(), Heap::kTheHoleValueRootIndex);
2902 __ lw(scratch3(),
2903 FieldMemOperand(scratch1(), JSGlobalPropertyCell::kValueOffset));
2904 __ Branch(&miss, eq, scratch3(), Operand(scratch2()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002905
2906 // Store the value in the cell.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002907 __ sw(value(),
2908 FieldMemOperand(scratch1(), JSGlobalPropertyCell::kValueOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002909 __ mov(v0, a0); // Stored value must be returned in v0.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002910 // Cells are always rescanned, so no write barrier here.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00002911
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002912 Counters* counters = isolate()->counters();
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002913 __ IncrementCounter(
2914 counters->named_store_global_inline(), 1, scratch1(), scratch2());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002915 __ Ret();
2916
2917 // Handle store cache miss.
2918 __ bind(&miss);
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002919 __ IncrementCounter(
2920 counters->named_store_global_inline_miss(), 1, scratch1(), scratch2());
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002921 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002922
2923 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002924 return GetICCode(kind(), Code::NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002925}
2926
2927
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002928Handle<Code> LoadStubCompiler::CompileLoadNonexistent(
2929 Handle<JSObject> object,
2930 Handle<JSObject> last,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002931 Handle<Name> name,
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002932 Handle<GlobalObject> global) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002933 Label success;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002934
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002935 NonexistentHandlerFrontend(object, last, name, &success, global);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002936
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002937 __ bind(&success);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002938 // Return undefined if maps of the full prototype chain is still the same.
2939 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
2940 __ Ret();
2941
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002942 // Return the generated code.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002943 return GetCode(kind(), Code::NONEXISTENT, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002944}
2945
2946
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002947Register* LoadStubCompiler::registers() {
2948 // receiver, name, scratch1, scratch2, scratch3, scratch4.
2949 static Register registers[] = { a0, a2, a3, a1, t0, t1 };
2950 return registers;
lrn@chromium.org7516f052011-03-30 08:52:27 +00002951}
2952
2953
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002954Register* KeyedLoadStubCompiler::registers() {
2955 // receiver, name, scratch1, scratch2, scratch3, scratch4.
2956 static Register registers[] = { a1, a0, a2, a3, t0, t1 };
2957 return registers;
2958}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002959
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002960
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002961Register* StoreStubCompiler::registers() {
2962 // receiver, name, value, scratch1, scratch2, scratch3.
2963 static Register registers[] = { a1, a2, a0, a3, t0, t1 };
2964 return registers;
2965}
2966
2967
2968Register* KeyedStoreStubCompiler::registers() {
2969 // receiver, name, value, scratch1, scratch2, scratch3.
2970 static Register registers[] = { a2, a1, a0, a3, t0, t1 };
2971 return registers;
2972}
2973
2974
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002975void KeyedLoadStubCompiler::GenerateNameCheck(Handle<Name> name,
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002976 Register name_reg,
2977 Label* miss) {
2978 __ Branch(miss, ne, name_reg, Operand(name));
lrn@chromium.org7516f052011-03-30 08:52:27 +00002979}
2980
2981
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002982void KeyedStoreStubCompiler::GenerateNameCheck(Handle<Name> name,
2983 Register name_reg,
2984 Label* miss) {
2985 __ Branch(miss, ne, name_reg, Operand(name));
2986}
2987
2988
mstarzinger@chromium.orgde886792012-09-11 13:22:37 +00002989#undef __
2990#define __ ACCESS_MASM(masm)
2991
2992
2993void LoadStubCompiler::GenerateLoadViaGetter(MacroAssembler* masm,
2994 Handle<JSFunction> getter) {
2995 // ----------- S t a t e -------------
2996 // -- a0 : receiver
2997 // -- a2 : name
2998 // -- ra : return address
2999 // -----------------------------------
3000 {
3001 FrameScope scope(masm, StackFrame::INTERNAL);
3002
3003 if (!getter.is_null()) {
3004 // Call the JavaScript getter with the receiver on the stack.
3005 __ push(a0);
3006 ParameterCount actual(0);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00003007 ParameterCount expected(getter);
3008 __ InvokeFunction(getter, expected, actual,
3009 CALL_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
mstarzinger@chromium.orgde886792012-09-11 13:22:37 +00003010 } else {
3011 // If we generate a global code snippet for deoptimization only, remember
3012 // the place to continue after deoptimization.
3013 masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
3014 }
3015
3016 // Restore context register.
3017 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
3018 }
3019 __ Ret();
3020}
3021
3022
3023#undef __
3024#define __ ACCESS_MASM(masm())
3025
3026
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003027Handle<Code> LoadStubCompiler::CompileLoadGlobal(
3028 Handle<JSObject> object,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00003029 Handle<GlobalObject> global,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003030 Handle<JSGlobalPropertyCell> cell,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003031 Handle<Name> name,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003032 bool is_dont_delete) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00003033 Label success, miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003034
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003035 __ CheckMap(
3036 receiver(), scratch1(), Handle<Map>(object->map()), &miss, DO_SMI_CHECK);
3037 HandlerFrontendHeader(
3038 object, receiver(), Handle<JSObject>::cast(global), name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003039
3040 // Get the value from the cell.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003041 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003042 __ lw(t0, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
3043
3044 // Check for deleted property if property can actually be deleted.
3045 if (!is_dont_delete) {
3046 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
3047 __ Branch(&miss, eq, t0, Operand(at));
3048 }
3049
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00003050 HandlerFrontendFooter(&success, &miss);
3051 __ bind(&success);
3052
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00003053 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003054 __ IncrementCounter(counters->named_load_global_stub(), 1, a1, a3);
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00003055 __ Ret(USE_DELAY_SLOT);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00003056 __ mov(v0, t0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003057
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003058 // Return the generated code.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003059 return GetICCode(kind(), Code::NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003060}
3061
3062
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00003063Handle<Code> BaseLoadStubCompiler::CompilePolymorphicIC(
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003064 MapHandleList* receiver_maps,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003065 CodeHandleList* handlers,
3066 Handle<Name> name,
3067 Code::StubType type,
3068 IcCheckType check) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003069 Label miss;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003070
3071 if (check == PROPERTY) {
3072 GenerateNameCheck(name, this->name(), &miss);
3073 }
3074
3075 __ JumpIfSmi(receiver(), &miss);
3076 Register map_reg = scratch1();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003077
danno@chromium.org40cb8782011-05-25 07:58:50 +00003078 int receiver_count = receiver_maps->length();
danno@chromium.orgf005df62013-04-30 16:36:45 +00003079 int number_of_handled_maps = 0;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003080 __ lw(map_reg, FieldMemOperand(receiver(), HeapObject::kMapOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003081 for (int current = 0; current < receiver_count; ++current) {
danno@chromium.orgf005df62013-04-30 16:36:45 +00003082 Handle<Map> map = receiver_maps->at(current);
3083 if (!map->is_deprecated()) {
3084 number_of_handled_maps++;
3085 __ Jump(handlers->at(current), RelocInfo::CODE_TARGET,
3086 eq, map_reg, Operand(receiver_maps->at(current)));
3087 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003088 }
danno@chromium.orgf005df62013-04-30 16:36:45 +00003089 ASSERT(number_of_handled_maps != 0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003090
3091 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003092 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003093
3094 // Return the generated code.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003095 InlineCacheState state =
danno@chromium.orgf005df62013-04-30 16:36:45 +00003096 number_of_handled_maps > 1 ? POLYMORPHIC : MONOMORPHIC;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003097 return GetICCode(kind(), type, name, state);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003098}
3099
3100
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003101Handle<Code> KeyedStoreStubCompiler::CompileStorePolymorphic(
3102 MapHandleList* receiver_maps,
3103 CodeHandleList* handler_stubs,
3104 MapHandleList* transitioned_maps) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003105 Label miss;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003106 __ JumpIfSmi(receiver(), &miss);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003107
3108 int receiver_count = receiver_maps->length();
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003109 __ lw(scratch1(), FieldMemOperand(receiver(), HeapObject::kMapOffset));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003110 for (int i = 0; i < receiver_count; ++i) {
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003111 if (transitioned_maps->at(i).is_null()) {
3112 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET, eq,
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003113 scratch1(), Operand(receiver_maps->at(i)));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003114 } else {
3115 Label next_map;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003116 __ Branch(&next_map, ne, scratch1(), Operand(receiver_maps->at(i)));
3117 __ li(transition_map(), Operand(transitioned_maps->at(i)));
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003118 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003119 __ bind(&next_map);
3120 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003121 }
3122
3123 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003124 TailCallBuiltin(masm(), MissBuiltin(kind()));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003125
3126 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003127 return GetICCode(
3128 kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003129}
3130
3131
danno@chromium.org40cb8782011-05-25 07:58:50 +00003132#undef __
3133#define __ ACCESS_MASM(masm)
3134
3135
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003136void KeyedLoadStubCompiler::GenerateLoadDictionaryElement(
3137 MacroAssembler* masm) {
3138 // ---------- S t a t e --------------
3139 // -- ra : return address
3140 // -- a0 : key
3141 // -- a1 : receiver
3142 // -----------------------------------
3143 Label slow, miss_force_generic;
3144
3145 Register key = a0;
3146 Register receiver = a1;
3147
3148 __ JumpIfNotSmi(key, &miss_force_generic);
3149 __ lw(t0, FieldMemOperand(receiver, JSObject::kElementsOffset));
3150 __ sra(a2, a0, kSmiTagSize);
3151 __ LoadFromNumberDictionary(&slow, t0, a0, v0, a2, a3, t1);
3152 __ Ret();
3153
3154 // Slow case, key and receiver still in a0 and a1.
3155 __ bind(&slow);
3156 __ IncrementCounter(
3157 masm->isolate()->counters()->keyed_load_external_array_slow(),
3158 1, a2, a3);
3159 // Entry registers are intact.
3160 // ---------- S t a t e --------------
3161 // -- ra : return address
3162 // -- a0 : key
3163 // -- a1 : receiver
3164 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003165 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003166
3167 // Miss case, call the runtime.
3168 __ bind(&miss_force_generic);
3169
3170 // ---------- S t a t e --------------
3171 // -- ra : return address
3172 // -- a0 : key
3173 // -- a1 : receiver
3174 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003175 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_MissForceGeneric);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003176}
3177
3178
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003179static void GenerateSmiKeyCheck(MacroAssembler* masm,
3180 Register key,
3181 Register scratch0,
3182 Register scratch1,
3183 FPURegister double_scratch0,
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003184 FPURegister double_scratch1,
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003185 Label* fail) {
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003186 Label key_ok;
3187 // Check for smi or a smi inside a heap number. We convert the heap
3188 // number and check if the conversion is exact and fits into the smi
3189 // range.
3190 __ JumpIfSmi(key, &key_ok);
3191 __ CheckMap(key,
3192 scratch0,
3193 Heap::kHeapNumberMapRootIndex,
3194 fail,
3195 DONT_DO_SMI_CHECK);
3196 __ ldc1(double_scratch0, FieldMemOperand(key, HeapNumber::kValueOffset));
3197 __ EmitFPUTruncate(kRoundToZero,
3198 scratch0,
3199 double_scratch0,
3200 at,
3201 double_scratch1,
3202 scratch1,
3203 kCheckForInexactConversion);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003204
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003205 __ Branch(fail, ne, scratch1, Operand(zero_reg));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003206
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003207 __ SmiTagCheckOverflow(key, scratch0, scratch1);
3208 __ BranchOnOverflow(fail, scratch1);
3209 __ bind(&key_ok);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003210}
3211
3212
danno@chromium.org40cb8782011-05-25 07:58:50 +00003213void KeyedStoreStubCompiler::GenerateStoreExternalArray(
3214 MacroAssembler* masm,
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003215 ElementsKind elements_kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003216 // ---------- S t a t e --------------
3217 // -- a0 : value
3218 // -- a1 : key
3219 // -- a2 : receiver
3220 // -- ra : return address
3221 // -----------------------------------
3222
danno@chromium.org40cb8782011-05-25 07:58:50 +00003223 Label slow, check_heap_number, miss_force_generic;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003224
3225 // Register usage.
3226 Register value = a0;
3227 Register key = a1;
3228 Register receiver = a2;
3229 // a3 mostly holds the elements array or the destination external array.
3230
danno@chromium.org40cb8782011-05-25 07:58:50 +00003231 // This stub is meant to be tail-jumped to, the receiver must already
3232 // have been verified by the caller to not be a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003233
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003234 // Check that the key is a smi or a heap number convertible to a smi.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003235 GenerateSmiKeyCheck(masm, key, t0, t1, f2, f4, &miss_force_generic);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003236
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003237 __ lw(a3, FieldMemOperand(receiver, JSObject::kElementsOffset));
3238
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003239 // Check that the index is in range.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003240 __ lw(t1, FieldMemOperand(a3, ExternalArray::kLengthOffset));
3241 // Unsigned comparison catches both negative and too-large values.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003242 __ Branch(&miss_force_generic, Ugreater_equal, key, Operand(t1));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003243
3244 // Handle both smis and HeapNumbers in the fast path. Go to the
3245 // runtime for all other kinds of values.
3246 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003247
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003248 if (elements_kind == EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003249 // Double to pixel conversion is only implemented in the runtime for now.
3250 __ JumpIfNotSmi(value, &slow);
3251 } else {
3252 __ JumpIfNotSmi(value, &check_heap_number);
3253 }
3254 __ SmiUntag(t1, value);
3255 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3256
3257 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003258 // t1: value (integer).
3259
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003260 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003261 case EXTERNAL_PIXEL_ELEMENTS: {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003262 // Clamp the value to [0..255].
3263 // v0 is used as a scratch register here.
3264 Label done;
3265 __ li(v0, Operand(255));
3266 // Normal branch: nop in delay slot.
3267 __ Branch(&done, gt, t1, Operand(v0));
3268 // Use delay slot in this branch.
3269 __ Branch(USE_DELAY_SLOT, &done, lt, t1, Operand(zero_reg));
3270 __ mov(v0, zero_reg); // In delay slot.
3271 __ mov(v0, t1); // Value is in range 0..255.
3272 __ bind(&done);
3273 __ mov(t1, v0);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003274
3275 __ srl(t8, key, 1);
3276 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003277 __ sb(t1, MemOperand(t8, 0));
3278 }
3279 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003280 case EXTERNAL_BYTE_ELEMENTS:
3281 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003282 __ srl(t8, key, 1);
3283 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003284 __ sb(t1, MemOperand(t8, 0));
3285 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003286 case EXTERNAL_SHORT_ELEMENTS:
3287 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003288 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003289 __ sh(t1, MemOperand(t8, 0));
3290 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003291 case EXTERNAL_INT_ELEMENTS:
3292 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003293 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003294 __ addu(t8, a3, t8);
3295 __ sw(t1, MemOperand(t8, 0));
3296 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003297 case EXTERNAL_FLOAT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003298 // Perform int-to-float conversion and store to memory.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003299 __ SmiUntag(t0, key);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003300 StoreIntAsFloat(masm, a3, t0, t1, t2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003301 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003302 case EXTERNAL_DOUBLE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003303 __ sll(t8, key, 2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003304 __ addu(a3, a3, t8);
3305 // a3: effective address of the double element
3306 FloatingPointHelper::Destination destination;
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003307 destination = FloatingPointHelper::kFPURegisters;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003308 FloatingPointHelper::ConvertIntToDouble(
danno@chromium.org40cb8782011-05-25 07:58:50 +00003309 masm, t1, destination,
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003310 f0, t2, t3, // These are: double_dst, dst_mantissa, dst_exponent.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003311 t0, f2); // These are: scratch2, single_scratch.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003312 __ sdc1(f0, MemOperand(a3, 0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003313 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003314 case FAST_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003315 case FAST_SMI_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003316 case FAST_DOUBLE_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003317 case FAST_HOLEY_ELEMENTS:
3318 case FAST_HOLEY_SMI_ELEMENTS:
3319 case FAST_HOLEY_DOUBLE_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003320 case DICTIONARY_ELEMENTS:
3321 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003322 UNREACHABLE();
3323 break;
3324 }
3325
3326 // Entry registers are intact, a0 holds the value which is the return value.
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00003327 __ Ret(USE_DELAY_SLOT);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003328 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003329
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003330 if (elements_kind != EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003331 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003332 __ bind(&check_heap_number);
3333 __ GetObjectType(value, t1, t2);
3334 __ Branch(&slow, ne, t2, Operand(HEAP_NUMBER_TYPE));
3335
3336 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3337
3338 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003339
3340 // The WebGL specification leaves the behavior of storing NaN and
3341 // +/-Infinity into integer arrays basically undefined. For more
3342 // reproducible behavior, convert these to zero.
3343
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003344
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003345 __ ldc1(f0, FieldMemOperand(a0, HeapNumber::kValueOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003346
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003347 if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
3348 __ cvt_s_d(f0, f0);
3349 __ sll(t8, key, 1);
3350 __ addu(t8, a3, t8);
3351 __ swc1(f0, MemOperand(t8, 0));
3352 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
3353 __ sll(t8, key, 2);
3354 __ addu(t8, a3, t8);
3355 __ sdc1(f0, MemOperand(t8, 0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003356 } else {
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003357 __ EmitECMATruncate(t3, f0, f2, t2, t1, t5);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003358
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003359 switch (elements_kind) {
3360 case EXTERNAL_BYTE_ELEMENTS:
3361 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
3362 __ srl(t8, key, 1);
3363 __ addu(t8, a3, t8);
3364 __ sb(t3, MemOperand(t8, 0));
3365 break;
3366 case EXTERNAL_SHORT_ELEMENTS:
3367 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
3368 __ addu(t8, a3, key);
3369 __ sh(t3, MemOperand(t8, 0));
3370 break;
3371 case EXTERNAL_INT_ELEMENTS:
3372 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
3373 __ sll(t8, key, 1);
3374 __ addu(t8, a3, t8);
3375 __ sw(t3, MemOperand(t8, 0));
3376 break;
3377 case EXTERNAL_PIXEL_ELEMENTS:
3378 case EXTERNAL_FLOAT_ELEMENTS:
3379 case EXTERNAL_DOUBLE_ELEMENTS:
3380 case FAST_ELEMENTS:
3381 case FAST_SMI_ELEMENTS:
3382 case FAST_DOUBLE_ELEMENTS:
3383 case FAST_HOLEY_ELEMENTS:
3384 case FAST_HOLEY_SMI_ELEMENTS:
3385 case FAST_HOLEY_DOUBLE_ELEMENTS:
3386 case DICTIONARY_ELEMENTS:
3387 case NON_STRICT_ARGUMENTS_ELEMENTS:
3388 UNREACHABLE();
3389 break;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003390 }
3391 }
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003392
3393 // Entry registers are intact, a0 holds the value
3394 // which is the return value.
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00003395 __ Ret(USE_DELAY_SLOT);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003396 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003397 }
3398
danno@chromium.org40cb8782011-05-25 07:58:50 +00003399 // Slow case, key and receiver still in a0 and a1.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003400 __ bind(&slow);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003401 __ IncrementCounter(
3402 masm->isolate()->counters()->keyed_load_external_array_slow(),
3403 1, a2, a3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003404 // Entry registers are intact.
3405 // ---------- S t a t e --------------
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003406 // -- ra : return address
danno@chromium.org40cb8782011-05-25 07:58:50 +00003407 // -- a0 : key
3408 // -- a1 : receiver
3409 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003410 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003411
3412 // Miss case, call the runtime.
3413 __ bind(&miss_force_generic);
3414
3415 // ---------- S t a t e --------------
3416 // -- ra : return address
3417 // -- a0 : key
3418 // -- a1 : receiver
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003419 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003420 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003421}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003422
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003423
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003424void KeyedStoreStubCompiler::GenerateStoreFastElement(
3425 MacroAssembler* masm,
3426 bool is_js_array,
yangguo@chromium.org56454712012-02-16 15:33:53 +00003427 ElementsKind elements_kind,
ulan@chromium.org750145a2013-03-07 15:14:13 +00003428 KeyedAccessStoreMode store_mode) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003429 // ----------- S t a t e -------------
3430 // -- a0 : value
3431 // -- a1 : key
3432 // -- a2 : receiver
3433 // -- ra : return address
3434 // -- a3 : scratch
3435 // -- a4 : scratch (elements)
3436 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00003437 Label miss_force_generic, transition_elements_kind, grow, slow;
3438 Label finish_store, check_capacity;
danno@chromium.org40cb8782011-05-25 07:58:50 +00003439
3440 Register value_reg = a0;
3441 Register key_reg = a1;
3442 Register receiver_reg = a2;
yangguo@chromium.org56454712012-02-16 15:33:53 +00003443 Register scratch = t0;
3444 Register elements_reg = a3;
3445 Register length_reg = t1;
3446 Register scratch2 = t2;
danno@chromium.org40cb8782011-05-25 07:58:50 +00003447
3448 // This stub is meant to be tail-jumped to, the receiver must already
3449 // have been verified by the caller to not be a smi.
3450
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003451 // Check that the key is a smi or a heap number convertible to a smi.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003452 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, f4, &miss_force_generic);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003453
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003454 if (IsFastSmiElementsKind(elements_kind)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003455 __ JumpIfNotSmi(value_reg, &transition_elements_kind);
3456 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003457
3458 // Check that the key is within bounds.
yangguo@chromium.org56454712012-02-16 15:33:53 +00003459 __ lw(elements_reg,
3460 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003461 if (is_js_array) {
3462 __ lw(scratch, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3463 } else {
3464 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3465 }
3466 // Compare smis.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003467 if (is_js_array && IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003468 __ Branch(&grow, hs, key_reg, Operand(scratch));
3469 } else {
3470 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch));
3471 }
3472
3473 // Make sure elements is a fast element array, not 'cow'.
3474 __ CheckMap(elements_reg,
3475 scratch,
3476 Heap::kFixedArrayMapRootIndex,
3477 &miss_force_generic,
3478 DONT_DO_SMI_CHECK);
3479
3480 __ bind(&finish_store);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003481
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003482 if (IsFastSmiElementsKind(elements_kind)) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003483 __ Addu(scratch,
3484 elements_reg,
3485 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3486 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
3487 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
3488 __ Addu(scratch, scratch, scratch2);
3489 __ sw(value_reg, MemOperand(scratch));
3490 } else {
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003491 ASSERT(IsFastObjectElementsKind(elements_kind));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003492 __ Addu(scratch,
3493 elements_reg,
3494 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3495 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
3496 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
3497 __ Addu(scratch, scratch, scratch2);
3498 __ sw(value_reg, MemOperand(scratch));
3499 __ mov(receiver_reg, value_reg);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003500 __ RecordWrite(elements_reg, // Object.
3501 scratch, // Address.
3502 receiver_reg, // Value.
3503 kRAHasNotBeenSaved,
3504 kDontSaveFPRegs);
3505 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003506 // value_reg (a0) is preserved.
3507 // Done.
3508 __ Ret();
3509
3510 __ bind(&miss_force_generic);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003511 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003512
3513 __ bind(&transition_elements_kind);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003514 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Miss);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003515
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003516 if (is_js_array && IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003517 // Grow the array by a single element if possible.
3518 __ bind(&grow);
3519
3520 // Make sure the array is only growing by a single element, anything else
3521 // must be handled by the runtime.
3522 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch));
3523
3524 // Check for the empty array, and preallocate a small backing store if
3525 // possible.
3526 __ lw(length_reg,
3527 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3528 __ lw(elements_reg,
3529 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3530 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
3531 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
3532
3533 int size = FixedArray::SizeFor(JSArray::kPreallocatedArrayElements);
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003534 __ Allocate(size, elements_reg, scratch, scratch2, &slow, TAG_OBJECT);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003535
3536 __ LoadRoot(scratch, Heap::kFixedArrayMapRootIndex);
3537 __ sw(scratch, FieldMemOperand(elements_reg, JSObject::kMapOffset));
3538 __ li(scratch, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
3539 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3540 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
3541 for (int i = 1; i < JSArray::kPreallocatedArrayElements; ++i) {
3542 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::SizeFor(i)));
3543 }
3544
3545 // Store the element at index zero.
3546 __ sw(value_reg, FieldMemOperand(elements_reg, FixedArray::SizeFor(0)));
3547
3548 // Install the new backing store in the JSArray.
3549 __ sw(elements_reg,
3550 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3551 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
3552 scratch, kRAHasNotBeenSaved, kDontSaveFPRegs,
3553 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
3554
3555 // Increment the length of the array.
3556 __ li(length_reg, Operand(Smi::FromInt(1)));
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00003557 __ Ret(USE_DELAY_SLOT);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003558 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
yangguo@chromium.org56454712012-02-16 15:33:53 +00003559
3560 __ bind(&check_capacity);
3561 // Check for cow elements, in general they are not handled by this stub
3562 __ CheckMap(elements_reg,
3563 scratch,
3564 Heap::kFixedCOWArrayMapRootIndex,
3565 &miss_force_generic,
3566 DONT_DO_SMI_CHECK);
3567
3568 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3569 __ Branch(&slow, hs, length_reg, Operand(scratch));
3570
3571 // Grow the array and finish the store.
3572 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
3573 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3574 __ jmp(&finish_store);
3575
3576 __ bind(&slow);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003577 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003578 }
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00003579}
3580
3581
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00003582void KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(
3583 MacroAssembler* masm,
yangguo@chromium.org56454712012-02-16 15:33:53 +00003584 bool is_js_array,
ulan@chromium.org750145a2013-03-07 15:14:13 +00003585 KeyedAccessStoreMode store_mode) {
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003586 // ----------- S t a t e -------------
3587 // -- a0 : value
3588 // -- a1 : key
3589 // -- a2 : receiver
3590 // -- ra : return address
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003591 // -- a3 : scratch (elements backing store)
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003592 // -- t0 : scratch (elements_reg)
3593 // -- t1 : scratch (mantissa_reg)
3594 // -- t2 : scratch (exponent_reg)
3595 // -- t3 : scratch4
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003596 // -- t4 : scratch
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003597 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00003598 Label miss_force_generic, transition_elements_kind, grow, slow;
3599 Label finish_store, check_capacity;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003600
3601 Register value_reg = a0;
3602 Register key_reg = a1;
3603 Register receiver_reg = a2;
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003604 Register elements_reg = a3;
3605 Register scratch1 = t0;
3606 Register scratch2 = t1;
3607 Register scratch3 = t2;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003608 Register scratch4 = t3;
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003609 Register scratch5 = t4;
yangguo@chromium.org56454712012-02-16 15:33:53 +00003610 Register length_reg = t3;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003611
3612 // This stub is meant to be tail-jumped to, the receiver must already
3613 // have been verified by the caller to not be a smi.
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003614
3615 // Check that the key is a smi or a heap number convertible to a smi.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003616 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, f4, &miss_force_generic);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003617
3618 __ lw(elements_reg,
3619 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3620
3621 // Check that the key is within bounds.
3622 if (is_js_array) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003623 __ lw(scratch1, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003624 } else {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003625 __ lw(scratch1,
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003626 FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3627 }
3628 // Compare smis, unsigned compare catches both negative and out-of-bound
3629 // indexes.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003630 if (IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003631 __ Branch(&grow, hs, key_reg, Operand(scratch1));
3632 } else {
3633 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch1));
3634 }
3635
3636 __ bind(&finish_store);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003637
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003638 __ StoreNumberToDoubleElements(value_reg,
3639 key_reg,
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00003640 // All registers after this are overwritten.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003641 elements_reg,
3642 scratch1,
3643 scratch2,
3644 scratch3,
3645 scratch4,
3646 &transition_elements_kind);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003647
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00003648 __ Ret(USE_DELAY_SLOT);
3649 __ mov(v0, value_reg); // In delay slot.
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003650
3651 // Handle store cache miss, replacing the ic with the generic stub.
3652 __ bind(&miss_force_generic);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003653 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003654
3655 __ bind(&transition_elements_kind);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003656 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Miss);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003657
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003658 if (is_js_array && IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003659 // Grow the array by a single element if possible.
3660 __ bind(&grow);
3661
3662 // Make sure the array is only growing by a single element, anything else
3663 // must be handled by the runtime.
3664 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch1));
3665
3666 // Transition on values that can't be stored in a FixedDoubleArray.
3667 Label value_is_smi;
3668 __ JumpIfSmi(value_reg, &value_is_smi);
3669 __ lw(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
3670 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex);
3671 __ Branch(&transition_elements_kind, ne, scratch1, Operand(at));
3672 __ bind(&value_is_smi);
3673
3674 // Check for the empty array, and preallocate a small backing store if
3675 // possible.
3676 __ lw(length_reg,
3677 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3678 __ lw(elements_reg,
3679 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3680 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
3681 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
3682
3683 int size = FixedDoubleArray::SizeFor(JSArray::kPreallocatedArrayElements);
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003684 __ Allocate(size, elements_reg, scratch1, scratch2, &slow, TAG_OBJECT);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003685
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003686 // Initialize the new FixedDoubleArray.
yangguo@chromium.org56454712012-02-16 15:33:53 +00003687 __ LoadRoot(scratch1, Heap::kFixedDoubleArrayMapRootIndex);
3688 __ sw(scratch1, FieldMemOperand(elements_reg, JSObject::kMapOffset));
3689 __ li(scratch1, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
3690 __ sw(scratch1,
3691 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
3692
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003693 __ mov(scratch1, elements_reg);
3694 __ StoreNumberToDoubleElements(value_reg,
3695 key_reg,
3696 // All registers after this are overwritten.
3697 scratch1,
3698 scratch2,
3699 scratch3,
3700 scratch4,
3701 scratch5,
3702 &transition_elements_kind);
3703
3704 __ li(scratch1, Operand(kHoleNanLower32));
3705 __ li(scratch2, Operand(kHoleNanUpper32));
3706 for (int i = 1; i < JSArray::kPreallocatedArrayElements; i++) {
3707 int offset = FixedDoubleArray::OffsetOfElementAt(i);
3708 __ sw(scratch1, FieldMemOperand(elements_reg, offset));
3709 __ sw(scratch2, FieldMemOperand(elements_reg, offset + kPointerSize));
3710 }
3711
yangguo@chromium.org56454712012-02-16 15:33:53 +00003712 // Install the new backing store in the JSArray.
3713 __ sw(elements_reg,
3714 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3715 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
3716 scratch1, kRAHasNotBeenSaved, kDontSaveFPRegs,
3717 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
3718
3719 // Increment the length of the array.
3720 __ li(length_reg, Operand(Smi::FromInt(1)));
3721 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
verwaest@chromium.org8a00e822013-06-10 15:11:22 +00003722 __ Ret(USE_DELAY_SLOT);
danno@chromium.org00379b82012-05-04 09:16:29 +00003723 __ lw(elements_reg,
3724 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
yangguo@chromium.org56454712012-02-16 15:33:53 +00003725
3726 __ bind(&check_capacity);
3727 // Make sure that the backing store can hold additional elements.
3728 __ lw(scratch1,
3729 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
3730 __ Branch(&slow, hs, length_reg, Operand(scratch1));
3731
3732 // Grow the array and finish the store.
3733 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
3734 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3735 __ jmp(&finish_store);
3736
3737 __ bind(&slow);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003738 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003739 }
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00003740}
3741
3742
ager@chromium.org5c838252010-02-19 08:53:10 +00003743#undef __
3744
3745} } // namespace v8::internal
3746
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00003747#endif // V8_TARGET_ARCH_MIPS