blob: d5cf6de9059aaf4dabf260cd37eba799041ffbdf [file] [log] [blame]
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001// Copyright 2012 the V8 project authors. All rights reserved.
ager@chromium.org5c838252010-02-19 08:53:10 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#include "v8.h"
29
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +000030#if defined(V8_TARGET_ARCH_MIPS)
31
ager@chromium.org5c838252010-02-19 08:53:10 +000032#include "ic-inl.h"
karlklose@chromium.org83a47282011-05-11 11:54:09 +000033#include "codegen.h"
ager@chromium.org5c838252010-02-19 08:53:10 +000034#include "stub-cache.h"
35
36namespace v8 {
37namespace internal {
38
39#define __ ACCESS_MASM(masm)
40
41
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000042static void ProbeTable(Isolate* isolate,
43 MacroAssembler* masm,
44 Code::Flags flags,
45 StubCache::Table table,
fschneider@chromium.org35814e52012-03-01 15:43:35 +000046 Register receiver,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000047 Register name,
fschneider@chromium.org35814e52012-03-01 15:43:35 +000048 // Number of the cache entry, not scaled.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000049 Register offset,
50 Register scratch,
fschneider@chromium.org35814e52012-03-01 15:43:35 +000051 Register scratch2,
52 Register offset_scratch) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000053 ExternalReference key_offset(isolate->stub_cache()->key_reference(table));
54 ExternalReference value_offset(isolate->stub_cache()->value_reference(table));
fschneider@chromium.org35814e52012-03-01 15:43:35 +000055 ExternalReference map_offset(isolate->stub_cache()->map_reference(table));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000056
57 uint32_t key_off_addr = reinterpret_cast<uint32_t>(key_offset.address());
58 uint32_t value_off_addr = reinterpret_cast<uint32_t>(value_offset.address());
fschneider@chromium.org35814e52012-03-01 15:43:35 +000059 uint32_t map_off_addr = reinterpret_cast<uint32_t>(map_offset.address());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000060
61 // Check the relative positions of the address fields.
62 ASSERT(value_off_addr > key_off_addr);
63 ASSERT((value_off_addr - key_off_addr) % 4 == 0);
64 ASSERT((value_off_addr - key_off_addr) < (256 * 4));
fschneider@chromium.org35814e52012-03-01 15:43:35 +000065 ASSERT(map_off_addr > key_off_addr);
66 ASSERT((map_off_addr - key_off_addr) % 4 == 0);
67 ASSERT((map_off_addr - key_off_addr) < (256 * 4));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000068
69 Label miss;
fschneider@chromium.org35814e52012-03-01 15:43:35 +000070 Register base_addr = scratch;
71 scratch = no_reg;
72
73 // Multiply by 3 because there are 3 fields per entry (name, code, map).
74 __ sll(offset_scratch, offset, 1);
75 __ Addu(offset_scratch, offset_scratch, offset);
76
77 // Calculate the base address of the entry.
78 __ li(base_addr, Operand(key_offset));
79 __ sll(at, offset_scratch, kPointerSizeLog2);
80 __ Addu(base_addr, base_addr, at);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000081
82 // Check that the key in the entry matches the name.
fschneider@chromium.org35814e52012-03-01 15:43:35 +000083 __ lw(at, MemOperand(base_addr, 0));
84 __ Branch(&miss, ne, name, Operand(at));
85
86 // Check the map matches.
87 __ lw(at, MemOperand(base_addr, map_off_addr - key_off_addr));
88 __ lw(scratch2, FieldMemOperand(receiver, HeapObject::kMapOffset));
89 __ Branch(&miss, ne, at, Operand(scratch2));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000090
91 // Get the code entry from the cache.
fschneider@chromium.org35814e52012-03-01 15:43:35 +000092 Register code = scratch2;
93 scratch2 = no_reg;
94 __ lw(code, MemOperand(base_addr, value_off_addr - key_off_addr));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000095
96 // Check that the flags match what we're looking for.
fschneider@chromium.org35814e52012-03-01 15:43:35 +000097 Register flags_reg = base_addr;
98 base_addr = no_reg;
99 __ lw(flags_reg, FieldMemOperand(code, Code::kFlagsOffset));
100 __ And(flags_reg, flags_reg, Operand(~Code::kFlagsNotUsedInLookup));
101 __ Branch(&miss, ne, flags_reg, Operand(flags));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000102
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000103#ifdef DEBUG
104 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) {
105 __ jmp(&miss);
106 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) {
107 __ jmp(&miss);
108 }
109#endif
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000110
111 // Jump to the first instruction in the code stub.
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000112 __ Addu(at, code, Operand(Code::kHeaderSize - kHeapObjectTag));
113 __ Jump(at);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000114
115 // Miss: fall through.
116 __ bind(&miss);
117}
118
119
120// Helper function used to check that the dictionary doesn't contain
121// the property. This function may return false negatives, so miss_label
122// must always call a backup property check that is complete.
123// This function is safe to call if the receiver has fast properties.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000124// Name must be unique and receiver must be a heap object.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000125static void GenerateDictionaryNegativeLookup(MacroAssembler* masm,
126 Label* miss_label,
127 Register receiver,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000128 Handle<Name> name,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000129 Register scratch0,
130 Register scratch1) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000131 ASSERT(name->IsUniqueName());
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000132 Counters* counters = masm->isolate()->counters();
133 __ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1);
134 __ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
135
136 Label done;
137
138 const int kInterceptorOrAccessCheckNeededMask =
139 (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
140
141 // Bail out if the receiver has a named interceptor or requires access checks.
142 Register map = scratch1;
143 __ lw(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
144 __ lbu(scratch0, FieldMemOperand(map, Map::kBitFieldOffset));
145 __ And(scratch0, scratch0, Operand(kInterceptorOrAccessCheckNeededMask));
146 __ Branch(miss_label, ne, scratch0, Operand(zero_reg));
147
148 // Check that receiver is a JSObject.
149 __ lbu(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset));
150 __ Branch(miss_label, lt, scratch0, Operand(FIRST_SPEC_OBJECT_TYPE));
151
152 // Load properties array.
153 Register properties = scratch0;
154 __ lw(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
155 // Check that the properties array is a dictionary.
156 __ lw(map, FieldMemOperand(properties, HeapObject::kMapOffset));
157 Register tmp = properties;
158 __ LoadRoot(tmp, Heap::kHashTableMapRootIndex);
159 __ Branch(miss_label, ne, map, Operand(tmp));
160
161 // Restore the temporarily used register.
162 __ lw(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
163
164
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000165 NameDictionaryLookupStub::GenerateNegativeLookup(masm,
166 miss_label,
167 &done,
168 receiver,
169 properties,
170 name,
171 scratch1);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000172 __ bind(&done);
173 __ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
174}
175
176
ager@chromium.org5c838252010-02-19 08:53:10 +0000177void StubCache::GenerateProbe(MacroAssembler* masm,
178 Code::Flags flags,
179 Register receiver,
180 Register name,
181 Register scratch,
fschneider@chromium.orge03fb642010-11-01 12:34:09 +0000182 Register extra,
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000183 Register extra2,
184 Register extra3) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000185 Isolate* isolate = masm->isolate();
186 Label miss;
187
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000188 // Make sure that code is valid. The multiplying code relies on the
189 // entry size being 12.
190 ASSERT(sizeof(Entry) == 12);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000191
192 // Make sure the flags does not name a specific type.
193 ASSERT(Code::ExtractTypeFromFlags(flags) == 0);
194
195 // Make sure that there are no register conflicts.
196 ASSERT(!scratch.is(receiver));
197 ASSERT(!scratch.is(name));
198 ASSERT(!extra.is(receiver));
199 ASSERT(!extra.is(name));
200 ASSERT(!extra.is(scratch));
201 ASSERT(!extra2.is(receiver));
202 ASSERT(!extra2.is(name));
203 ASSERT(!extra2.is(scratch));
204 ASSERT(!extra2.is(extra));
205
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000206 // Check register validity.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000207 ASSERT(!scratch.is(no_reg));
208 ASSERT(!extra.is(no_reg));
209 ASSERT(!extra2.is(no_reg));
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000210 ASSERT(!extra3.is(no_reg));
211
212 Counters* counters = masm->isolate()->counters();
213 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1,
214 extra2, extra3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000215
216 // Check that the receiver isn't a smi.
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000217 __ JumpIfSmi(receiver, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000218
219 // Get the map of the receiver and compute the hash.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000220 __ lw(scratch, FieldMemOperand(name, Name::kHashFieldOffset));
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000221 __ lw(at, FieldMemOperand(receiver, HeapObject::kMapOffset));
222 __ Addu(scratch, scratch, at);
223 uint32_t mask = kPrimaryTableSize - 1;
224 // We shift out the last two bits because they are not part of the hash and
225 // they are always 01 for maps.
226 __ srl(scratch, scratch, kHeapObjectTagSize);
227 __ Xor(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask));
228 __ And(scratch, scratch, Operand(mask));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000229
230 // Probe the primary table.
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000231 ProbeTable(isolate,
232 masm,
233 flags,
234 kPrimary,
235 receiver,
236 name,
237 scratch,
238 extra,
239 extra2,
240 extra3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000241
242 // Primary miss: Compute hash for secondary probe.
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000243 __ srl(at, name, kHeapObjectTagSize);
244 __ Subu(scratch, scratch, at);
245 uint32_t mask2 = kSecondaryTableSize - 1;
246 __ Addu(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask2));
247 __ And(scratch, scratch, Operand(mask2));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000248
249 // Probe the secondary table.
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000250 ProbeTable(isolate,
251 masm,
252 flags,
253 kSecondary,
254 receiver,
255 name,
256 scratch,
257 extra,
258 extra2,
259 extra3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000260
261 // Cache miss: Fall-through and let caller handle the miss by
262 // entering the runtime system.
263 __ bind(&miss);
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000264 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1,
265 extra2, extra3);
ager@chromium.org5c838252010-02-19 08:53:10 +0000266}
267
268
269void StubCompiler::GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm,
270 int index,
271 Register prototype) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000272 // Load the global or builtins object from the current context.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000273 __ lw(prototype,
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000274 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
275 // Load the native context from the global or builtins object.
276 __ lw(prototype,
277 FieldMemOperand(prototype, GlobalObject::kNativeContextOffset));
278 // Load the function from the native context.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000279 __ lw(prototype, MemOperand(prototype, Context::SlotOffset(index)));
280 // Load the initial map. The global functions all have initial maps.
281 __ lw(prototype,
282 FieldMemOperand(prototype, JSFunction::kPrototypeOrInitialMapOffset));
283 // Load the prototype from the initial map.
284 __ lw(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
ager@chromium.org5c838252010-02-19 08:53:10 +0000285}
286
287
lrn@chromium.org7516f052011-03-30 08:52:27 +0000288void StubCompiler::GenerateDirectLoadGlobalFunctionPrototype(
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000289 MacroAssembler* masm,
290 int index,
291 Register prototype,
292 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000293 Isolate* isolate = masm->isolate();
294 // Check we're still in the same context.
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000295 __ lw(prototype,
296 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000297 ASSERT(!prototype.is(at));
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000298 __ li(at, isolate->global_object());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000299 __ Branch(miss, ne, prototype, Operand(at));
300 // Get the global function with the given index.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000301 Handle<JSFunction> function(
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000302 JSFunction::cast(isolate->native_context()->get(index)));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000303 // Load its initial map. The global functions all have initial maps.
304 __ li(prototype, Handle<Map>(function->initial_map()));
305 // Load the prototype from the initial map.
306 __ lw(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
lrn@chromium.org7516f052011-03-30 08:52:27 +0000307}
308
309
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000310void StubCompiler::DoGenerateFastPropertyLoad(MacroAssembler* masm,
311 Register dst,
312 Register src,
313 bool inobject,
314 int index) {
315 int offset = index * kPointerSize;
316 if (!inobject) {
317 // Calculate the offset into the properties array.
318 offset = offset + FixedArray::kHeaderSize;
319 __ lw(dst, FieldMemOperand(src, JSObject::kPropertiesOffset));
320 src = dst;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000321 }
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000322 __ lw(dst, FieldMemOperand(src, offset));
ager@chromium.org5c838252010-02-19 08:53:10 +0000323}
324
325
326void StubCompiler::GenerateLoadArrayLength(MacroAssembler* masm,
327 Register receiver,
328 Register scratch,
329 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000330 // Check that the receiver isn't a smi.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000331 __ JumpIfSmi(receiver, miss_label);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000332
333 // Check that the object is a JS array.
334 __ GetObjectType(receiver, scratch, scratch);
335 __ Branch(miss_label, ne, scratch, Operand(JS_ARRAY_TYPE));
336
337 // Load length directly from the JS array.
338 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
339 __ Ret();
340}
341
342
343// Generate code to check if an object is a string. If the object is a
344// heap object, its map's instance type is left in the scratch1 register.
345// If this is not needed, scratch1 and scratch2 may be the same register.
346static void GenerateStringCheck(MacroAssembler* masm,
347 Register receiver,
348 Register scratch1,
349 Register scratch2,
350 Label* smi,
351 Label* non_string_object) {
352 // Check that the receiver isn't a smi.
353 __ JumpIfSmi(receiver, smi, t0);
354
355 // Check that the object is a string.
356 __ lw(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset));
357 __ lbu(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
358 __ And(scratch2, scratch1, Operand(kIsNotStringMask));
359 // The cast is to resolve the overload for the argument of 0x0.
360 __ Branch(non_string_object,
361 ne,
362 scratch2,
363 Operand(static_cast<int32_t>(kStringTag)));
ager@chromium.org5c838252010-02-19 08:53:10 +0000364}
365
366
lrn@chromium.org7516f052011-03-30 08:52:27 +0000367// Generate code to load the length from a string object and return the length.
368// If the receiver object is not a string or a wrapped string object the
369// execution continues at the miss label. The register containing the
370// receiver is potentially clobbered.
371void StubCompiler::GenerateLoadStringLength(MacroAssembler* masm,
372 Register receiver,
373 Register scratch1,
374 Register scratch2,
375 Label* miss,
376 bool support_wrappers) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000377 Label check_wrapper;
378
379 // Check if the object is a string leaving the instance type in the
380 // scratch1 register.
381 GenerateStringCheck(masm, receiver, scratch1, scratch2, miss,
382 support_wrappers ? &check_wrapper : miss);
383
384 // Load length directly from the string.
385 __ lw(v0, FieldMemOperand(receiver, String::kLengthOffset));
386 __ Ret();
387
388 if (support_wrappers) {
389 // Check if the object is a JSValue wrapper.
390 __ bind(&check_wrapper);
391 __ Branch(miss, ne, scratch1, Operand(JS_VALUE_TYPE));
392
393 // Unwrap the value and check if the wrapped value is a string.
394 __ lw(scratch1, FieldMemOperand(receiver, JSValue::kValueOffset));
395 GenerateStringCheck(masm, scratch1, scratch2, scratch2, miss, miss);
396 __ lw(v0, FieldMemOperand(scratch1, String::kLengthOffset));
397 __ Ret();
398 }
lrn@chromium.org7516f052011-03-30 08:52:27 +0000399}
400
401
ager@chromium.org5c838252010-02-19 08:53:10 +0000402void StubCompiler::GenerateLoadFunctionPrototype(MacroAssembler* masm,
403 Register receiver,
404 Register scratch1,
405 Register scratch2,
406 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000407 __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
408 __ mov(v0, scratch1);
409 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +0000410}
411
412
lrn@chromium.org7516f052011-03-30 08:52:27 +0000413// Generate StoreField code, value is passed in a0 register.
ager@chromium.org5c838252010-02-19 08:53:10 +0000414// After executing generated code, the receiver_reg and name_reg
415// may be clobbered.
416void StubCompiler::GenerateStoreField(MacroAssembler* masm,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000417 Handle<JSObject> object,
ager@chromium.org5c838252010-02-19 08:53:10 +0000418 int index,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000419 Handle<Map> transition,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000420 Handle<Name> name,
ager@chromium.org5c838252010-02-19 08:53:10 +0000421 Register receiver_reg,
422 Register name_reg,
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000423 Register value_reg,
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000424 Register scratch1,
425 Register scratch2,
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000426 Label* miss_label,
427 Label* miss_restore_name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000428 // a0 : value.
429 Label exit;
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000430
431 LookupResult lookup(masm->isolate());
432 object->Lookup(*name, &lookup);
433 if (lookup.IsFound() && (lookup.IsReadOnly() || !lookup.IsCacheable())) {
434 // In sloppy mode, we could just return the value and be done. However, we
435 // might be in strict mode, where we have to throw. Since we cannot tell,
436 // go into slow case unconditionally.
437 __ jmp(miss_label);
438 return;
439 }
440
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +0000441 // Check that the map of the object hasn't changed.
jkummerow@chromium.org28faa982012-04-13 09:58:30 +0000442 CompareMapMode mode = transition.is_null() ? ALLOW_ELEMENT_TRANSITION_MAPS
443 : REQUIRE_EXACT_MAP;
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000444 __ CheckMap(receiver_reg, scratch1, Handle<Map>(object->map()), miss_label,
jkummerow@chromium.org28faa982012-04-13 09:58:30 +0000445 DO_SMI_CHECK, mode);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000446
447 // Perform global security token check if needed.
448 if (object->IsJSGlobalProxy()) {
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000449 __ CheckAccessGlobalProxy(receiver_reg, scratch1, miss_label);
450 }
451
452 // Check that we are allowed to write this.
453 if (!transition.is_null() && object->GetPrototype()->IsJSObject()) {
454 JSObject* holder;
455 if (lookup.IsFound()) {
456 holder = lookup.holder();
457 } else {
458 // Find the top object.
459 holder = *object;
460 do {
461 holder = JSObject::cast(holder->GetPrototype());
462 } while (holder->GetPrototype()->IsJSObject());
463 }
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000464 CheckPrototypes(object, receiver_reg, Handle<JSObject>(holder), name_reg,
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000465 scratch1, scratch2, name, miss_restore_name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000466 }
467
468 // Stub never generated for non-global objects that require access
469 // checks.
470 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
471
472 // Perform map transition for the receiver if necessary.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000473 if (!transition.is_null() && (object->map()->unused_property_fields() == 0)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000474 // The properties must be extended before we can store the value.
475 // We jump to a runtime call that extends the properties array.
476 __ push(receiver_reg);
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000477 __ li(a2, Operand(transition));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000478 __ Push(a2, a0);
479 __ TailCallExternalReference(
480 ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
481 masm->isolate()),
482 3, 1);
483 return;
484 }
485
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000486 if (!transition.is_null()) {
verwaest@chromium.org37141392012-05-31 13:27:02 +0000487 // Update the map of the object.
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000488 __ li(scratch1, Operand(transition));
489 __ sw(scratch1, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
verwaest@chromium.org37141392012-05-31 13:27:02 +0000490
491 // Update the write barrier for the map field and pass the now unused
492 // name_reg as scratch register.
493 __ RecordWriteField(receiver_reg,
494 HeapObject::kMapOffset,
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000495 scratch1,
verwaest@chromium.org37141392012-05-31 13:27:02 +0000496 name_reg,
497 kRAHasNotBeenSaved,
498 kDontSaveFPRegs,
499 OMIT_REMEMBERED_SET,
500 OMIT_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000501 }
502
503 // Adjust for the number of properties stored in the object. Even in the
504 // face of a transition we can use the old map here because the size of the
505 // object and the number of in-object properties is not going to change.
506 index -= object->map()->inobject_properties();
507
508 if (index < 0) {
509 // Set the property straight into the object.
510 int offset = object->map()->instance_size() + (index * kPointerSize);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000511 __ sw(value_reg, FieldMemOperand(receiver_reg, offset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000512
513 // Skip updating write barrier if storing a smi.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000514 __ JumpIfSmi(value_reg, &exit);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000515
516 // Update the write barrier for the array address.
517 // Pass the now unused name_reg as a scratch register.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000518 __ mov(name_reg, value_reg);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000519 __ RecordWriteField(receiver_reg,
520 offset,
521 name_reg,
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000522 scratch1,
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000523 kRAHasNotBeenSaved,
524 kDontSaveFPRegs);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000525 } else {
526 // Write to the properties array.
527 int offset = index * kPointerSize + FixedArray::kHeaderSize;
528 // Get the properties array.
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000529 __ lw(scratch1,
530 FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000531 __ sw(value_reg, FieldMemOperand(scratch1, offset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000532
533 // Skip updating write barrier if storing a smi.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000534 __ JumpIfSmi(value_reg, &exit);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000535
536 // Update the write barrier for the array address.
537 // Ok to clobber receiver_reg and name_reg, since we return.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000538 __ mov(name_reg, value_reg);
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000539 __ RecordWriteField(scratch1,
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000540 offset,
541 name_reg,
542 receiver_reg,
543 kRAHasNotBeenSaved,
544 kDontSaveFPRegs);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000545 }
546
547 // Return the value (register v0).
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000548 ASSERT(value_reg.is(a0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000549 __ bind(&exit);
550 __ mov(v0, a0);
551 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +0000552}
553
554
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000555void BaseStoreStubCompiler::GenerateRestoreName(MacroAssembler* masm,
556 Label* label,
557 Handle<Name> name) {
558 if (!label->is_unused()) {
559 __ bind(label);
560 __ li(this->name(), Operand(name));
561 }
mstarzinger@chromium.org068ea0a2013-01-30 09:39:44 +0000562}
563
564
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000565static void GenerateCallFunction(MacroAssembler* masm,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000566 Handle<Object> object,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000567 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000568 Label* miss,
569 Code::ExtraICState extra_ic_state) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000570 // ----------- S t a t e -------------
571 // -- a0: receiver
572 // -- a1: function to call
573 // -----------------------------------
574 // Check that the function really is a function.
575 __ JumpIfSmi(a1, miss);
576 __ GetObjectType(a1, a3, a3);
577 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
578
579 // Patch the receiver on the stack with the global proxy if
580 // necessary.
581 if (object->IsGlobalObject()) {
582 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
583 __ sw(a3, MemOperand(sp, arguments.immediate() * kPointerSize));
584 }
585
586 // Invoke the function.
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000587 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state)
588 ? CALL_AS_FUNCTION
589 : CALL_AS_METHOD;
590 __ InvokeFunction(a1, arguments, JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000591}
592
593
594static void PushInterceptorArguments(MacroAssembler* masm,
595 Register receiver,
596 Register holder,
597 Register name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000598 Handle<JSObject> holder_obj) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000599 __ push(name);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000600 Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
601 ASSERT(!masm->isolate()->heap()->InNewSpace(*interceptor));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000602 Register scratch = name;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000603 __ li(scratch, Operand(interceptor));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000604 __ Push(scratch, receiver, holder);
605 __ lw(scratch, FieldMemOperand(scratch, InterceptorInfo::kDataOffset));
606 __ push(scratch);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000607 __ li(scratch, Operand(ExternalReference::isolate_address()));
608 __ push(scratch);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000609}
610
611
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000612static void CompileCallLoadPropertyWithInterceptor(
613 MacroAssembler* masm,
614 Register receiver,
615 Register holder,
616 Register name,
617 Handle<JSObject> holder_obj) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000618 PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
619
620 ExternalReference ref =
621 ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorOnly),
622 masm->isolate());
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000623 __ PrepareCEntryArgs(6);
ulan@chromium.org6ff65142012-03-21 09:52:17 +0000624 __ PrepareCEntryFunction(ref);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000625
626 CEntryStub stub(1);
627 __ CallStub(&stub);
628}
629
630
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000631static const int kFastApiCallArguments = 4;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000632
633
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000634// Reserves space for the extra arguments to API function in the
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000635// caller's frame.
636//
637// These arguments are set by CheckPrototypes and GenerateFastApiDirectCall.
638static void ReserveSpaceForFastApiCall(MacroAssembler* masm,
639 Register scratch) {
640 ASSERT(Smi::FromInt(0) == 0);
641 for (int i = 0; i < kFastApiCallArguments; i++) {
642 __ push(zero_reg);
643 }
644}
645
646
647// Undoes the effects of ReserveSpaceForFastApiCall.
648static void FreeSpaceForFastApiCall(MacroAssembler* masm) {
649 __ Drop(kFastApiCallArguments);
650}
651
652
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000653static void GenerateFastApiDirectCall(MacroAssembler* masm,
654 const CallOptimization& optimization,
655 int argc) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000656 // ----------- S t a t e -------------
657 // -- sp[0] : holder (set by CheckPrototypes)
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000658 // -- sp[4] : callee JS function
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000659 // -- sp[8] : call data
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000660 // -- sp[12] : isolate
661 // -- sp[16] : last JS argument
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000662 // -- ...
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000663 // -- sp[(argc + 3) * 4] : first JS argument
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000664 // -- sp[(argc + 4) * 4] : receiver
665 // -----------------------------------
666 // Get the function and setup the context.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000667 Handle<JSFunction> function = optimization.constant_function();
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000668 __ LoadHeapObject(t1, function);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000669 __ lw(cp, FieldMemOperand(t1, JSFunction::kContextOffset));
670
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000671 // Pass the additional arguments.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000672 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
ulan@chromium.org09d7ab52013-02-25 15:50:35 +0000673 Handle<Object> call_data(api_call_info->data(), masm->isolate());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000674 if (masm->isolate()->heap()->InNewSpace(*call_data)) {
675 __ li(a0, api_call_info);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000676 __ lw(t2, FieldMemOperand(a0, CallHandlerInfo::kDataOffset));
677 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000678 __ li(t2, call_data);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000679 }
680
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000681 __ li(t3, Operand(ExternalReference::isolate_address()));
682 // Store JS function, call data and isolate.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000683 __ sw(t1, MemOperand(sp, 1 * kPointerSize));
684 __ sw(t2, MemOperand(sp, 2 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000685 __ sw(t3, MemOperand(sp, 3 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000686
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000687 // Prepare arguments.
688 __ Addu(a2, sp, Operand(3 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000689
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000690 // Allocate the v8::Arguments structure in the arguments' space since
691 // it's not controlled by GC.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000692 const int kApiStackSpace = 4;
693
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000694 FrameScope frame_scope(masm, StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000695 __ EnterExitFrame(false, kApiStackSpace);
696
697 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
698 // struct from the function (which is currently the case). This means we pass
699 // the first argument in a1 instead of a0. TryCallApiFunctionAndReturn
700 // will handle setting up a0.
701
702 // a1 = v8::Arguments&
703 // Arguments is built at sp + 1 (sp is a reserved spot for ra).
704 __ Addu(a1, sp, kPointerSize);
705
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000706 // v8::Arguments::implicit_args_
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000707 __ sw(a2, MemOperand(a1, 0 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000708 // v8::Arguments::values_
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000709 __ Addu(t0, a2, Operand(argc * kPointerSize));
710 __ sw(t0, MemOperand(a1, 1 * kPointerSize));
711 // v8::Arguments::length_ = argc
712 __ li(t0, Operand(argc));
713 __ sw(t0, MemOperand(a1, 2 * kPointerSize));
714 // v8::Arguments::is_construct_call = 0
715 __ sw(zero_reg, MemOperand(a1, 3 * kPointerSize));
716
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000717 const int kStackUnwindSpace = argc + kFastApiCallArguments + 1;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000718 Address function_address = v8::ToCData<Address>(api_call_info->callback());
719 ApiFunction fun(function_address);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000720 ExternalReference ref =
721 ExternalReference(&fun,
722 ExternalReference::DIRECT_API_CALL,
723 masm->isolate());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000724 AllowExternalCallThatCantCauseGC scope(masm);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000725 __ CallApiFunctionAndReturn(ref, kStackUnwindSpace);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000726}
727
lrn@chromium.org7516f052011-03-30 08:52:27 +0000728class CallInterceptorCompiler BASE_EMBEDDED {
729 public:
730 CallInterceptorCompiler(StubCompiler* stub_compiler,
731 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000732 Register name,
733 Code::ExtraICState extra_ic_state)
lrn@chromium.org7516f052011-03-30 08:52:27 +0000734 : stub_compiler_(stub_compiler),
735 arguments_(arguments),
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000736 name_(name),
737 extra_ic_state_(extra_ic_state) {}
lrn@chromium.org7516f052011-03-30 08:52:27 +0000738
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000739 void Compile(MacroAssembler* masm,
740 Handle<JSObject> object,
741 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000742 Handle<Name> name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000743 LookupResult* lookup,
744 Register receiver,
745 Register scratch1,
746 Register scratch2,
747 Register scratch3,
748 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000749 ASSERT(holder->HasNamedInterceptor());
750 ASSERT(!holder->GetNamedInterceptor()->getter()->IsUndefined());
751
752 // Check that the receiver isn't a smi.
753 __ JumpIfSmi(receiver, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000754 CallOptimization optimization(lookup);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000755 if (optimization.is_constant_call()) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000756 CompileCacheable(masm, object, receiver, scratch1, scratch2, scratch3,
757 holder, lookup, name, optimization, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000758 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000759 CompileRegular(masm, object, receiver, scratch1, scratch2, scratch3,
760 name, holder, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000761 }
762 }
763
764 private:
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000765 void CompileCacheable(MacroAssembler* masm,
766 Handle<JSObject> object,
767 Register receiver,
768 Register scratch1,
769 Register scratch2,
770 Register scratch3,
771 Handle<JSObject> interceptor_holder,
772 LookupResult* lookup,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000773 Handle<Name> name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000774 const CallOptimization& optimization,
775 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000776 ASSERT(optimization.is_constant_call());
777 ASSERT(!lookup->holder()->IsGlobalObject());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000778 Counters* counters = masm->isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000779 int depth1 = kInvalidProtoDepth;
780 int depth2 = kInvalidProtoDepth;
781 bool can_do_fast_api_call = false;
782 if (optimization.is_simple_api_call() &&
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000783 !lookup->holder()->IsGlobalObject()) {
784 depth1 = optimization.GetPrototypeDepthOfExpectedType(
785 object, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000786 if (depth1 == kInvalidProtoDepth) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000787 depth2 = optimization.GetPrototypeDepthOfExpectedType(
788 interceptor_holder, Handle<JSObject>(lookup->holder()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000789 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000790 can_do_fast_api_call =
791 depth1 != kInvalidProtoDepth || depth2 != kInvalidProtoDepth;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000792 }
793
794 __ IncrementCounter(counters->call_const_interceptor(), 1,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000795 scratch1, scratch2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000796
797 if (can_do_fast_api_call) {
798 __ IncrementCounter(counters->call_const_interceptor_fast_api(), 1,
799 scratch1, scratch2);
800 ReserveSpaceForFastApiCall(masm, scratch1);
801 }
802
803 // Check that the maps from receiver to interceptor's holder
804 // haven't changed and thus we can invoke interceptor.
805 Label miss_cleanup;
806 Label* miss = can_do_fast_api_call ? &miss_cleanup : miss_label;
807 Register holder =
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000808 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
809 scratch1, scratch2, scratch3,
810 name, depth1, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000811
812 // Invoke an interceptor and if it provides a value,
813 // branch to |regular_invoke|.
814 Label regular_invoke;
815 LoadWithInterceptor(masm, receiver, holder, interceptor_holder, scratch2,
816 &regular_invoke);
817
818 // Interceptor returned nothing for this property. Try to use cached
819 // constant function.
820
821 // Check that the maps from interceptor's holder to constant function's
822 // holder haven't changed and thus we can use cached constant function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000823 if (*interceptor_holder != lookup->holder()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000824 stub_compiler_->CheckPrototypes(interceptor_holder, receiver,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000825 Handle<JSObject>(lookup->holder()),
826 scratch1, scratch2, scratch3,
827 name, depth2, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000828 } else {
829 // CheckPrototypes has a side effect of fetching a 'holder'
830 // for API (object which is instanceof for the signature). It's
831 // safe to omit it here, as if present, it should be fetched
832 // by the previous CheckPrototypes.
833 ASSERT(depth2 == kInvalidProtoDepth);
834 }
835
836 // Invoke function.
837 if (can_do_fast_api_call) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000838 GenerateFastApiDirectCall(masm, optimization, arguments_.immediate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000839 } else {
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000840 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state_)
841 ? CALL_AS_FUNCTION
842 : CALL_AS_METHOD;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000843 __ InvokeFunction(optimization.constant_function(), arguments_,
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +0000844 JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000845 }
846
847 // Deferred code for fast API call case---clean preallocated space.
848 if (can_do_fast_api_call) {
849 __ bind(&miss_cleanup);
850 FreeSpaceForFastApiCall(masm);
851 __ Branch(miss_label);
852 }
853
854 // Invoke a regular function.
855 __ bind(&regular_invoke);
856 if (can_do_fast_api_call) {
857 FreeSpaceForFastApiCall(masm);
858 }
lrn@chromium.org7516f052011-03-30 08:52:27 +0000859 }
860
861 void CompileRegular(MacroAssembler* masm,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000862 Handle<JSObject> object,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000863 Register receiver,
864 Register scratch1,
865 Register scratch2,
866 Register scratch3,
ulan@chromium.org6e196bf2013-03-13 09:38:22 +0000867 Handle<Name> name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000868 Handle<JSObject> interceptor_holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000869 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000870 Register holder =
871 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000872 scratch1, scratch2, scratch3,
873 name, miss_label);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000874
875 // Call a runtime function to load the interceptor property.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000876 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000877 // Save the name_ register across the call.
878 __ push(name_);
879
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000880 PushInterceptorArguments(masm, receiver, holder, name_, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000881
882 __ CallExternalReference(
883 ExternalReference(
884 IC_Utility(IC::kLoadPropertyWithInterceptorForCall),
885 masm->isolate()),
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000886 6);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000887 // Restore the name_ register.
888 __ pop(name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000889 // Leave the internal frame.
lrn@chromium.org7516f052011-03-30 08:52:27 +0000890 }
891
892 void LoadWithInterceptor(MacroAssembler* masm,
893 Register receiver,
894 Register holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000895 Handle<JSObject> holder_obj,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000896 Register scratch,
897 Label* interceptor_succeeded) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000898 {
899 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000900
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000901 __ Push(holder, name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000902 CompileCallLoadPropertyWithInterceptor(masm,
903 receiver,
904 holder,
905 name_,
906 holder_obj);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000907 __ pop(name_); // Restore the name.
908 __ pop(receiver); // Restore the holder.
909 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000910 // If interceptor returns no-result sentinel, call the constant function.
911 __ LoadRoot(scratch, Heap::kNoInterceptorResultSentinelRootIndex);
912 __ Branch(interceptor_succeeded, ne, v0, Operand(scratch));
lrn@chromium.org7516f052011-03-30 08:52:27 +0000913 }
914
915 StubCompiler* stub_compiler_;
916 const ParameterCount& arguments_;
917 Register name_;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000918 Code::ExtraICState extra_ic_state_;
lrn@chromium.org7516f052011-03-30 08:52:27 +0000919};
920
921
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000922
923// Generate code to check that a global property cell is empty. Create
924// the property cell at compilation time if no cell exists for the
925// property.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000926static void GenerateCheckPropertyCell(MacroAssembler* masm,
927 Handle<GlobalObject> global,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000928 Handle<Name> name,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000929 Register scratch,
930 Label* miss) {
931 Handle<JSGlobalPropertyCell> cell =
932 GlobalObject::EnsurePropertyCell(global, name);
933 ASSERT(cell->value()->IsTheHole());
934 __ li(scratch, Operand(cell));
935 __ lw(scratch,
936 FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset));
937 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
938 __ Branch(miss, ne, scratch, Operand(at));
939}
940
941
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000942// Calls GenerateCheckPropertyCell for each global object in the prototype chain
943// from object to (but not including) holder.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000944static void GenerateCheckPropertyCells(MacroAssembler* masm,
945 Handle<JSObject> object,
946 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000947 Handle<Name> name,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000948 Register scratch,
949 Label* miss) {
950 Handle<JSObject> current = object;
951 while (!current.is_identical_to(holder)) {
952 if (current->IsGlobalObject()) {
953 GenerateCheckPropertyCell(masm,
954 Handle<GlobalObject>::cast(current),
955 name,
956 scratch,
957 miss);
958 }
959 current = Handle<JSObject>(JSObject::cast(current->GetPrototype()));
960 }
961}
962
963
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000964// Convert and store int passed in register ival to IEEE 754 single precision
965// floating point value at memory location (dst + 4 * wordoffset)
966// If FPU is available use it for conversion.
967static void StoreIntAsFloat(MacroAssembler* masm,
968 Register dst,
969 Register wordoffset,
970 Register ival,
971 Register fval,
972 Register scratch1,
973 Register scratch2) {
974 if (CpuFeatures::IsSupported(FPU)) {
ulan@chromium.org750145a2013-03-07 15:14:13 +0000975 CpuFeatureScope scope(masm, FPU);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000976 __ mtc1(ival, f0);
977 __ cvt_s_w(f0, f0);
978 __ sll(scratch1, wordoffset, 2);
979 __ addu(scratch1, dst, scratch1);
980 __ swc1(f0, MemOperand(scratch1, 0));
981 } else {
982 // FPU is not available, do manual conversions.
983
984 Label not_special, done;
985 // Move sign bit from source to destination. This works because the sign
986 // bit in the exponent word of the double has the same position and polarity
987 // as the 2's complement sign bit in a Smi.
988 ASSERT(kBinary32SignMask == 0x80000000u);
989
990 __ And(fval, ival, Operand(kBinary32SignMask));
991 // Negate value if it is negative.
992 __ subu(scratch1, zero_reg, ival);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +0000993 __ Movn(ival, scratch1, fval);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000994
995 // We have -1, 0 or 1, which we treat specially. Register ival contains
996 // absolute value: it is either equal to 1 (special case of -1 and 1),
997 // greater than 1 (not a special case) or less than 1 (special case of 0).
998 __ Branch(&not_special, gt, ival, Operand(1));
999
1000 // For 1 or -1 we need to or in the 0 exponent (biased).
1001 static const uint32_t exponent_word_for_1 =
1002 kBinary32ExponentBias << kBinary32ExponentShift;
1003
1004 __ Xor(scratch1, ival, Operand(1));
1005 __ li(scratch2, exponent_word_for_1);
1006 __ or_(scratch2, fval, scratch2);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00001007 __ Movz(fval, scratch2, scratch1); // Only if ival is equal to 1.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001008 __ Branch(&done);
1009
1010 __ bind(&not_special);
1011 // Count leading zeros.
1012 // Gets the wrong answer for 0, but we already checked for that case above.
1013 Register zeros = scratch2;
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00001014 __ Clz(zeros, ival);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001015
1016 // Compute exponent and or it into the exponent register.
1017 __ li(scratch1, (kBitsPerInt - 1) + kBinary32ExponentBias);
1018 __ subu(scratch1, scratch1, zeros);
1019
1020 __ sll(scratch1, scratch1, kBinary32ExponentShift);
1021 __ or_(fval, fval, scratch1);
1022
1023 // Shift up the source chopping the top bit off.
1024 __ Addu(zeros, zeros, Operand(1));
1025 // This wouldn't work for 1 and -1 as the shift would be 32 which means 0.
1026 __ sllv(ival, ival, zeros);
1027 // And the top (top 20 bits).
1028 __ srl(scratch1, ival, kBitsPerInt - kBinary32MantissaBits);
1029 __ or_(fval, fval, scratch1);
1030
1031 __ bind(&done);
1032
1033 __ sll(scratch1, wordoffset, 2);
1034 __ addu(scratch1, dst, scratch1);
1035 __ sw(fval, MemOperand(scratch1, 0));
1036 }
1037}
1038
1039
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00001040void StubCompiler::GenerateTailCall(MacroAssembler* masm, Handle<Code> code) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001041 __ Jump(code, RelocInfo::CODE_TARGET);
1042}
1043
1044
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00001045#undef __
1046#define __ ACCESS_MASM(masm())
1047
1048
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001049Register StubCompiler::CheckPrototypes(Handle<JSObject> object,
1050 Register object_reg,
1051 Handle<JSObject> holder,
1052 Register holder_reg,
1053 Register scratch1,
1054 Register scratch2,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001055 Handle<Name> name,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001056 int save_at_depth,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001057 Label* miss,
1058 PrototypeCheckType check) {
1059 Handle<JSObject> first = object;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001060 // Make sure there's no overlap between holder and object registers.
1061 ASSERT(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
1062 ASSERT(!scratch2.is(object_reg) && !scratch2.is(holder_reg)
1063 && !scratch2.is(scratch1));
1064
1065 // Keep track of the current object in register reg.
1066 Register reg = object_reg;
1067 int depth = 0;
1068
1069 if (save_at_depth == depth) {
1070 __ sw(reg, MemOperand(sp));
1071 }
1072
1073 // Check the maps in the prototype chain.
1074 // Traverse the prototype chain from the object and do map checks.
1075 Handle<JSObject> current = object;
1076 while (!current.is_identical_to(holder)) {
1077 ++depth;
1078
1079 // Only global objects and objects that do not require access
1080 // checks are allowed in stubs.
1081 ASSERT(current->IsJSGlobalProxy() || !current->IsAccessCheckNeeded());
1082
1083 Handle<JSObject> prototype(JSObject::cast(current->GetPrototype()));
1084 if (!current->HasFastProperties() &&
1085 !current->IsJSGlobalObject() &&
1086 !current->IsJSGlobalProxy()) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001087 if (!name->IsUniqueName()) {
1088 ASSERT(name->IsString());
1089 name = factory()->InternalizeString(Handle<String>::cast(name));
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001090 }
1091 ASSERT(current->property_dictionary()->FindEntry(*name) ==
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001092 NameDictionary::kNotFound);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001093
1094 GenerateDictionaryNegativeLookup(masm(), miss, reg, name,
1095 scratch1, scratch2);
1096
1097 __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
1098 reg = holder_reg; // From now on the object will be in holder_reg.
1099 __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
1100 } else {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001101 Register map_reg = scratch1;
1102 if (!current.is_identical_to(first) || check == CHECK_ALL_MAPS) {
1103 Handle<Map> current_map(current->map());
1104 // CheckMap implicitly loads the map of |reg| into |map_reg|.
1105 __ CheckMap(reg, map_reg, current_map, miss, DONT_DO_SMI_CHECK,
1106 ALLOW_ELEMENT_TRANSITION_MAPS);
1107 } else {
1108 __ lw(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
1109 }
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001110 // Check access rights to the global object. This has to happen after
1111 // the map check so that we know that the object is actually a global
1112 // object.
1113 if (current->IsJSGlobalProxy()) {
1114 __ CheckAccessGlobalProxy(reg, scratch2, miss);
1115 }
1116 reg = holder_reg; // From now on the object will be in holder_reg.
1117
1118 if (heap()->InNewSpace(*prototype)) {
1119 // The prototype is in new space; we cannot store a reference to it
1120 // in the code. Load it from the map.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001121 __ lw(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset));
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001122 } else {
1123 // The prototype is in old space; load it directly.
1124 __ li(reg, Operand(prototype));
1125 }
1126 }
1127
1128 if (save_at_depth == depth) {
1129 __ sw(reg, MemOperand(sp));
1130 }
1131
1132 // Go to the next object in the prototype chain.
1133 current = prototype;
1134 }
1135
1136 // Log the check depth.
1137 LOG(masm()->isolate(), IntEvent("check-maps-depth", depth + 1));
1138
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001139 if (!holder.is_identical_to(first) || check == CHECK_ALL_MAPS) {
1140 // Check the holder map.
1141 __ CheckMap(reg, scratch1, Handle<Map>(holder->map()), miss,
1142 DONT_DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS);
1143 }
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001144
1145 // Perform security check for access to the global object.
1146 ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded());
1147 if (holder->IsJSGlobalProxy()) {
1148 __ CheckAccessGlobalProxy(reg, scratch1, miss);
1149 }
1150
1151 // If we've skipped any global objects, it's not enough to verify that
1152 // their maps haven't changed. We also need to check that the property
1153 // cell for the property is still empty.
1154 GenerateCheckPropertyCells(masm(), object, holder, name, scratch1, miss);
1155
1156 // Return the register containing the holder.
1157 return reg;
1158}
1159
1160
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001161void BaseLoadStubCompiler::HandlerFrontendFooter(Label* success,
1162 Label* miss) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001163 if (!miss->is_unused()) {
1164 __ Branch(success);
1165 __ bind(miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00001166 TailCallBuiltin(masm(), MissBuiltin(kind()));
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001167 }
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001168}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001169
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001170
1171Register BaseLoadStubCompiler::CallbackHandlerFrontend(
1172 Handle<JSObject> object,
1173 Register object_reg,
1174 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001175 Handle<Name> name,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001176 Label* success,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001177 Handle<ExecutableAccessorInfo> callback) {
1178 Label miss;
1179
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001180 Register reg = HandlerFrontendHeader(object, object_reg, holder, name, &miss);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001181
1182 if (!holder->HasFastProperties() && !holder->IsJSGlobalObject()) {
1183 ASSERT(!reg.is(scratch2()));
1184 ASSERT(!reg.is(scratch3()));
1185 ASSERT(!reg.is(scratch4()));
1186
1187 // Load the properties dictionary.
1188 Register dictionary = scratch4();
1189 __ lw(dictionary, FieldMemOperand(reg, JSObject::kPropertiesOffset));
1190
1191 // Probe the dictionary.
1192 Label probe_done;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001193 NameDictionaryLookupStub::GeneratePositiveLookup(masm(),
1194 &miss,
1195 &probe_done,
1196 dictionary,
1197 this->name(),
1198 scratch2(),
1199 scratch3());
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001200 __ bind(&probe_done);
1201
1202 // If probing finds an entry in the dictionary, scratch3 contains the
1203 // pointer into the dictionary. Check that the value is the callback.
1204 Register pointer = scratch3();
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001205 const int kElementsStartOffset = NameDictionary::kHeaderSize +
1206 NameDictionary::kElementsStartIndex * kPointerSize;
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001207 const int kValueOffset = kElementsStartOffset + kPointerSize;
1208 __ lw(scratch2(), FieldMemOperand(pointer, kValueOffset));
1209 __ Branch(&miss, ne, scratch2(), Operand(callback));
1210 }
1211
1212 HandlerFrontendFooter(success, &miss);
1213 return reg;
1214}
1215
1216
1217void BaseLoadStubCompiler::NonexistentHandlerFrontend(
1218 Handle<JSObject> object,
1219 Handle<JSObject> last,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001220 Handle<Name> name,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001221 Label* success,
1222 Handle<GlobalObject> global) {
1223 Label miss;
1224
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001225 Register reg = HandlerFrontendHeader(object, receiver(), last, name, &miss);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001226
1227 // If the last object in the prototype chain is a global object,
1228 // check that the global property cell is empty.
1229 if (!global.is_null()) {
1230 GenerateCheckPropertyCell(masm(), global, name, scratch2(), &miss);
1231 }
1232
1233 if (!last->HasFastProperties()) {
1234 __ lw(scratch2(), FieldMemOperand(reg, HeapObject::kMapOffset));
1235 __ lw(scratch2(), FieldMemOperand(scratch2(), Map::kPrototypeOffset));
1236 __ Branch(&miss, ne, scratch2(),
1237 Operand(isolate()->factory()->null_value()));
1238 }
1239
1240 HandlerFrontendFooter(success, &miss);
1241}
1242
1243
1244void BaseLoadStubCompiler::GenerateLoadField(Register reg,
1245 Handle<JSObject> holder,
1246 PropertyIndex index) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001247 GenerateFastPropertyLoad(masm(), v0, reg, holder, index);
1248 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +00001249}
1250
1251
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001252void BaseLoadStubCompiler::GenerateLoadConstant(Handle<JSFunction> value) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001253 // Return the constant value.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001254 __ LoadHeapObject(v0, value);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001255 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +00001256}
1257
1258
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001259void BaseLoadStubCompiler::GenerateLoadCallback(
1260 Register reg,
1261 Handle<ExecutableAccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001262 // Build AccessorInfo::args_ list on the stack and push property name below
1263 // the exit frame to make GC aware of them and store pointers to them.
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001264 __ push(receiver());
1265 __ mov(scratch2(), sp); // scratch2 = AccessorInfo::args_
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001266 if (heap()->InNewSpace(callback->data())) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001267 __ li(scratch3(), callback);
1268 __ lw(scratch3(), FieldMemOperand(scratch3(),
1269 ExecutableAccessorInfo::kDataOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001270 } else {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001271 __ li(scratch3(), Handle<Object>(callback->data(),
1272 callback->GetIsolate()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001273 }
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001274 __ Subu(sp, sp, 4 * kPointerSize);
1275 __ sw(reg, MemOperand(sp, 3 * kPointerSize));
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001276 __ sw(scratch3(), MemOperand(sp, 2 * kPointerSize));
1277 __ li(scratch3(), Operand(ExternalReference::isolate_address()));
1278 __ sw(scratch3(), MemOperand(sp, 1 * kPointerSize));
1279 __ sw(name(), MemOperand(sp, 0 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001280
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001281 __ mov(a2, scratch2()); // Saved in case scratch2 == a1.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001282 __ mov(a1, sp); // a1 (first argument - see note below) = Handle<Name>
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001283
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001284 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
1285 // struct from the function (which is currently the case). This means we pass
1286 // the arguments in a1-a2 instead of a0-a1. TryCallApiFunctionAndReturn
1287 // will handle setting up a0.
1288
1289 const int kApiStackSpace = 1;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001290 FrameScope frame_scope(masm(), StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001291 __ EnterExitFrame(false, kApiStackSpace);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001292
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001293 // Create AccessorInfo instance on the stack above the exit frame with
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001294 // scratch2 (internal::Object** args_) as the data.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001295 __ sw(a2, MemOperand(sp, kPointerSize));
1296 // a2 (second argument - see note above) = AccessorInfo&
1297 __ Addu(a2, sp, kPointerSize);
1298
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001299 const int kStackUnwindSpace = 5;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001300 Address getter_address = v8::ToCData<Address>(callback->getter());
1301 ApiFunction fun(getter_address);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001302 ExternalReference ref =
1303 ExternalReference(&fun,
1304 ExternalReference::DIRECT_GETTER_CALL,
1305 masm()->isolate());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001306 __ CallApiFunctionAndReturn(ref, kStackUnwindSpace);
ager@chromium.org5c838252010-02-19 08:53:10 +00001307}
1308
1309
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001310void BaseLoadStubCompiler::GenerateLoadInterceptor(
1311 Register holder_reg,
1312 Handle<JSObject> object,
1313 Handle<JSObject> interceptor_holder,
1314 LookupResult* lookup,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001315 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001316 ASSERT(interceptor_holder->HasNamedInterceptor());
1317 ASSERT(!interceptor_holder->GetNamedInterceptor()->getter()->IsUndefined());
1318
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001319 // So far the most popular follow ups for interceptor loads are FIELD
1320 // and CALLBACKS, so inline only them, other cases may be added
1321 // later.
1322 bool compile_followup_inline = false;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001323 if (lookup->IsFound() && lookup->IsCacheable()) {
yangguo@chromium.orgde0db002012-06-22 13:44:28 +00001324 if (lookup->IsField()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001325 compile_followup_inline = true;
1326 } else if (lookup->type() == CALLBACKS &&
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00001327 lookup->GetCallbackObject()->IsExecutableAccessorInfo()) {
1328 ExecutableAccessorInfo* callback =
1329 ExecutableAccessorInfo::cast(lookup->GetCallbackObject());
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001330 compile_followup_inline = callback->getter() != NULL &&
1331 callback->IsCompatibleReceiver(*object);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001332 }
1333 }
1334
1335 if (compile_followup_inline) {
1336 // Compile the interceptor call, followed by inline code to load the
1337 // property from further up the prototype chain if the call fails.
1338 // Check that the maps haven't changed.
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001339 ASSERT(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001340
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001341 // Preserve the receiver register explicitly whenever it is different from
1342 // the holder and it is needed should the interceptor return without any
1343 // result. The CALLBACKS case needs the receiver to be passed into C++ code,
1344 // the FIELD case might cause a miss during the prototype check.
1345 bool must_perfrom_prototype_check = *interceptor_holder != lookup->holder();
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001346 bool must_preserve_receiver_reg = !receiver().is(holder_reg) &&
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001347 (lookup->type() == CALLBACKS || must_perfrom_prototype_check);
1348
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001349 // Save necessary data before invoking an interceptor.
1350 // Requires a frame to make GC aware of pushed pointers.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001351 {
1352 FrameScope frame_scope(masm(), StackFrame::INTERNAL);
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001353 if (must_preserve_receiver_reg) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001354 __ Push(receiver(), holder_reg, this->name());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001355 } else {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001356 __ Push(holder_reg, this->name());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001357 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001358 // Invoke an interceptor. Note: map checks from receiver to
1359 // interceptor's holder has been compiled before (see a caller
1360 // of this method).
1361 CompileCallLoadPropertyWithInterceptor(masm(),
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001362 receiver(),
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001363 holder_reg,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001364 this->name(),
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001365 interceptor_holder);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001366 // Check if interceptor provided a value for property. If it's
1367 // the case, return immediately.
1368 Label interceptor_failed;
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001369 __ LoadRoot(scratch1(), Heap::kNoInterceptorResultSentinelRootIndex);
1370 __ Branch(&interceptor_failed, eq, v0, Operand(scratch1()));
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001371 frame_scope.GenerateLeaveFrame();
1372 __ Ret();
1373
1374 __ bind(&interceptor_failed);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001375 __ pop(this->name());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001376 __ pop(holder_reg);
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001377 if (must_preserve_receiver_reg) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001378 __ pop(receiver());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001379 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001380 // Leave the internal frame.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001381 }
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001382 GenerateLoadPostInterceptor(holder_reg, interceptor_holder, name, lookup);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001383 } else { // !compile_followup_inline
1384 // Call the runtime system to load the interceptor.
1385 // Check that the maps haven't changed.
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001386 PushInterceptorArguments(masm(), receiver(), holder_reg,
1387 this->name(), interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001388
1389 ExternalReference ref = ExternalReference(
1390 IC_Utility(IC::kLoadPropertyWithInterceptorForLoad), masm()->isolate());
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001391 __ TailCallExternalReference(ref, 6, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001392 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001393}
1394
1395
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001396void CallStubCompiler::GenerateNameCheck(Handle<Name> name, Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001397 if (kind_ == Code::KEYED_CALL_IC) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001398 __ Branch(miss, ne, a2, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001399 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001400}
1401
1402
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001403void CallStubCompiler::GenerateGlobalReceiverCheck(Handle<JSObject> object,
1404 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001405 Handle<Name> name,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001406 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001407 ASSERT(holder->IsGlobalObject());
1408
1409 // Get the number of arguments.
1410 const int argc = arguments().immediate();
1411
1412 // Get the receiver from the stack.
1413 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1414
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001415 // Check that the maps haven't changed.
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00001416 __ JumpIfSmi(a0, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001417 CheckPrototypes(object, a0, holder, a3, a1, t0, name, miss);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001418}
1419
1420
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001421void CallStubCompiler::GenerateLoadFunctionFromCell(
1422 Handle<JSGlobalPropertyCell> cell,
1423 Handle<JSFunction> function,
1424 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001425 // Get the value from the cell.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001426 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001427 __ lw(a1, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
1428
1429 // Check that the cell contains the same function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001430 if (heap()->InNewSpace(*function)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001431 // We can't embed a pointer to a function in new space so we have
1432 // to verify that the shared function info is unchanged. This has
1433 // the nice side effect that multiple closures based on the same
1434 // function can all use this call IC. Before we load through the
1435 // function, we have to verify that it still is a function.
1436 __ JumpIfSmi(a1, miss);
1437 __ GetObjectType(a1, a3, a3);
1438 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
1439
1440 // Check the shared function info. Make sure it hasn't changed.
1441 __ li(a3, Handle<SharedFunctionInfo>(function->shared()));
1442 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
1443 __ Branch(miss, ne, t0, Operand(a3));
1444 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001445 __ Branch(miss, ne, a1, Operand(function));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001446 }
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001447}
1448
1449
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001450void CallStubCompiler::GenerateMissBranch() {
1451 Handle<Code> code =
danno@chromium.org40cb8782011-05-25 07:58:50 +00001452 isolate()->stub_cache()->ComputeCallMiss(arguments().immediate(),
1453 kind_,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001454 extra_state_);
1455 __ Jump(code, RelocInfo::CODE_TARGET);
1456}
1457
1458
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001459Handle<Code> CallStubCompiler::CompileCallField(Handle<JSObject> object,
1460 Handle<JSObject> holder,
yangguo@chromium.orgfb377212012-11-16 14:43:43 +00001461 PropertyIndex index,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001462 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001463 // ----------- S t a t e -------------
1464 // -- a2 : name
1465 // -- ra : return address
1466 // -----------------------------------
1467 Label miss;
1468
1469 GenerateNameCheck(name, &miss);
1470
1471 const int argc = arguments().immediate();
1472
1473 // Get the receiver of the function from the stack into a0.
1474 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1475 // Check that the receiver isn't a smi.
1476 __ JumpIfSmi(a0, &miss, t0);
1477
1478 // Do the right check and compute the holder register.
1479 Register reg = CheckPrototypes(object, a0, holder, a1, a3, t0, name, &miss);
1480 GenerateFastPropertyLoad(masm(), a1, reg, holder, index);
1481
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001482 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001483
1484 // Handle call cache miss.
1485 __ bind(&miss);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001486 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001487
1488 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00001489 return GetCode(Code::FIELD, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00001490}
1491
1492
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001493Handle<Code> CallStubCompiler::CompileArrayPushCall(
1494 Handle<Object> object,
1495 Handle<JSObject> holder,
1496 Handle<JSGlobalPropertyCell> cell,
1497 Handle<JSFunction> function,
1498 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001499 // ----------- S t a t e -------------
1500 // -- a2 : name
1501 // -- ra : return address
1502 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1503 // -- ...
1504 // -- sp[argc * 4] : receiver
1505 // -----------------------------------
1506
1507 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001508 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001509
1510 Label miss;
1511
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001512 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001513
1514 Register receiver = a1;
1515
1516 // Get the receiver from the stack.
1517 const int argc = arguments().immediate();
1518 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1519
1520 // Check that the receiver isn't a smi.
1521 __ JumpIfSmi(receiver, &miss);
1522
1523 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001524 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, a3, v0, t0,
1525 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001526
1527 if (argc == 0) {
1528 // Nothing to do, just return the length.
1529 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1530 __ Drop(argc + 1);
1531 __ Ret();
1532 } else {
1533 Label call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001534 if (argc == 1) { // Otherwise fall through to call the builtin.
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001535 Label attempt_to_grow_elements, with_write_barrier, check_double;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001536
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001537 Register elements = t2;
1538 Register end_elements = t1;
1539 // Get the elements array of the object.
1540 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1541
1542 // Check that the elements are in fast mode and writable.
1543 __ CheckMap(elements,
1544 v0,
1545 Heap::kFixedArrayMapRootIndex,
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001546 &check_double,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001547 DONT_DO_SMI_CHECK);
1548
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001549 // Get the array's length into v0 and calculate new length.
1550 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1551 STATIC_ASSERT(kSmiTagSize == 1);
1552 STATIC_ASSERT(kSmiTag == 0);
1553 __ Addu(v0, v0, Operand(Smi::FromInt(argc)));
1554
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001555 // Get the elements' length.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001556 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1557
1558 // Check if we could survive without allocation.
1559 __ Branch(&attempt_to_grow_elements, gt, v0, Operand(t0));
1560
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001561 // Check if value is a smi.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001562 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize));
1563 __ JumpIfNotSmi(t0, &with_write_barrier);
1564
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001565 // Save new length.
1566 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1567
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001568 // Store the value.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001569 // We may need a register containing the address end_elements below,
1570 // so write back the value in end_elements.
1571 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1572 __ Addu(end_elements, elements, end_elements);
1573 const int kEndElementsOffset =
1574 FixedArray::kHeaderSize - kHeapObjectTag - argc * kPointerSize;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001575 __ Addu(end_elements, end_elements, kEndElementsOffset);
1576 __ sw(t0, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001577
1578 // Check for a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001579 __ Drop(argc + 1);
1580 __ Ret();
1581
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001582 __ bind(&check_double);
1583
1584 // Check that the elements are in fast mode and writable.
1585 __ CheckMap(elements,
1586 a0,
1587 Heap::kFixedDoubleArrayMapRootIndex,
1588 &call_builtin,
1589 DONT_DO_SMI_CHECK);
1590
1591 // Get the array's length into r0 and calculate new length.
1592 __ lw(a0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1593 STATIC_ASSERT(kSmiTagSize == 1);
1594 STATIC_ASSERT(kSmiTag == 0);
1595 __ Addu(a0, a0, Operand(Smi::FromInt(argc)));
1596
1597 // Get the elements' length.
1598 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1599
1600 // Check if we could survive without allocation.
1601 __ Branch(&call_builtin, gt, a0, Operand(t0));
1602
1603 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize));
1604 __ StoreNumberToDoubleElements(
1605 t0, a0, elements, a3, t1, a2, t5,
1606 &call_builtin, argc * kDoubleSize);
1607
1608 // Save new length.
1609 __ sw(a0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1610
1611 // Check for a smi.
1612 __ Drop(argc + 1);
1613 __ Ret();
1614
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001615 __ bind(&with_write_barrier);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001616
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001617 __ lw(a3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1618
1619 if (FLAG_smi_only_arrays && !FLAG_trace_elements_transitions) {
1620 Label fast_object, not_fast_object;
1621 __ CheckFastObjectElements(a3, t3, &not_fast_object);
1622 __ jmp(&fast_object);
1623 // In case of fast smi-only, convert to fast object, otherwise bail out.
1624 __ bind(&not_fast_object);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001625 __ CheckFastSmiElements(a3, t3, &call_builtin);
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001626
1627 __ lw(t3, FieldMemOperand(t0, HeapObject::kMapOffset));
1628 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex);
1629 __ Branch(&call_builtin, eq, t3, Operand(at));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001630 // edx: receiver
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001631 // a3: map
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001632 Label try_holey_map;
1633 __ LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001634 FAST_ELEMENTS,
1635 a3,
1636 t3,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001637 &try_holey_map);
1638 __ mov(a2, receiver);
1639 ElementsTransitionGenerator::
yangguo@chromium.org28381b42013-01-21 14:39:38 +00001640 GenerateMapChangeElementsTransition(masm(),
1641 DONT_TRACK_ALLOCATION_SITE,
1642 NULL);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001643 __ jmp(&fast_object);
1644
1645 __ bind(&try_holey_map);
1646 __ LoadTransitionedArrayMapConditional(FAST_HOLEY_SMI_ELEMENTS,
1647 FAST_HOLEY_ELEMENTS,
1648 a3,
1649 t3,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001650 &call_builtin);
1651 __ mov(a2, receiver);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001652 ElementsTransitionGenerator::
yangguo@chromium.org28381b42013-01-21 14:39:38 +00001653 GenerateMapChangeElementsTransition(masm(),
1654 DONT_TRACK_ALLOCATION_SITE,
1655 NULL);
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001656 __ bind(&fast_object);
1657 } else {
1658 __ CheckFastObjectElements(a3, a3, &call_builtin);
1659 }
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001660
1661 // Save new length.
1662 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1663
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001664 // Store the value.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001665 // We may need a register containing the address end_elements below,
1666 // so write back the value in end_elements.
1667 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1668 __ Addu(end_elements, elements, end_elements);
1669 __ Addu(end_elements, end_elements, kEndElementsOffset);
1670 __ sw(t0, MemOperand(end_elements));
1671
1672 __ RecordWrite(elements,
1673 end_elements,
1674 t0,
1675 kRAHasNotBeenSaved,
1676 kDontSaveFPRegs,
1677 EMIT_REMEMBERED_SET,
1678 OMIT_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001679 __ Drop(argc + 1);
1680 __ Ret();
1681
1682 __ bind(&attempt_to_grow_elements);
1683 // v0: array's length + 1.
1684 // t0: elements' length.
1685
1686 if (!FLAG_inline_new) {
1687 __ Branch(&call_builtin);
1688 }
1689
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001690 __ lw(a2, MemOperand(sp, (argc - 1) * kPointerSize));
1691 // Growing elements that are SMI-only requires special handling in case
1692 // the new element is non-Smi. For now, delegate to the builtin.
1693 Label no_fast_elements_check;
1694 __ JumpIfSmi(a2, &no_fast_elements_check);
1695 __ lw(t3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1696 __ CheckFastObjectElements(t3, t3, &call_builtin);
1697 __ bind(&no_fast_elements_check);
1698
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001699 ExternalReference new_space_allocation_top =
1700 ExternalReference::new_space_allocation_top_address(
1701 masm()->isolate());
1702 ExternalReference new_space_allocation_limit =
1703 ExternalReference::new_space_allocation_limit_address(
1704 masm()->isolate());
1705
1706 const int kAllocationDelta = 4;
1707 // Load top and check if it is the end of elements.
1708 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1709 __ Addu(end_elements, elements, end_elements);
1710 __ Addu(end_elements, end_elements, Operand(kEndElementsOffset));
1711 __ li(t3, Operand(new_space_allocation_top));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001712 __ lw(a3, MemOperand(t3));
1713 __ Branch(&call_builtin, ne, end_elements, Operand(a3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001714
1715 __ li(t5, Operand(new_space_allocation_limit));
1716 __ lw(t5, MemOperand(t5));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001717 __ Addu(a3, a3, Operand(kAllocationDelta * kPointerSize));
1718 __ Branch(&call_builtin, hi, a3, Operand(t5));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001719
1720 // We fit and could grow elements.
1721 // Update new_space_allocation_top.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001722 __ sw(a3, MemOperand(t3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001723 // Push the argument.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001724 __ sw(a2, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001725 // Fill the rest with holes.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001726 __ LoadRoot(a3, Heap::kTheHoleValueRootIndex);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001727 for (int i = 1; i < kAllocationDelta; i++) {
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001728 __ sw(a3, MemOperand(end_elements, i * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001729 }
1730
1731 // Update elements' and array's sizes.
1732 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1733 __ Addu(t0, t0, Operand(Smi::FromInt(kAllocationDelta)));
1734 __ sw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1735
1736 // Elements are in new space, so write barrier is not required.
1737 __ Drop(argc + 1);
1738 __ Ret();
1739 }
1740 __ bind(&call_builtin);
1741 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPush,
1742 masm()->isolate()),
1743 argc + 1,
1744 1);
1745 }
1746
1747 // Handle call cache miss.
1748 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001749 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001750
1751 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001752 return GetCode(function);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001753}
1754
1755
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001756Handle<Code> CallStubCompiler::CompileArrayPopCall(
1757 Handle<Object> object,
1758 Handle<JSObject> holder,
1759 Handle<JSGlobalPropertyCell> cell,
1760 Handle<JSFunction> function,
1761 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001762 // ----------- S t a t e -------------
1763 // -- a2 : name
1764 // -- ra : return address
1765 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1766 // -- ...
1767 // -- sp[argc * 4] : receiver
1768 // -----------------------------------
1769
1770 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001771 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001772
1773 Label miss, return_undefined, call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001774 Register receiver = a1;
1775 Register elements = a3;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001776 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001777
1778 // Get the receiver from the stack.
1779 const int argc = arguments().immediate();
1780 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001781 // Check that the receiver isn't a smi.
1782 __ JumpIfSmi(receiver, &miss);
1783
1784 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001785 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, elements,
1786 t0, v0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001787
1788 // Get the elements array of the object.
1789 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1790
1791 // Check that the elements are in fast mode and writable.
danno@chromium.org40cb8782011-05-25 07:58:50 +00001792 __ CheckMap(elements,
1793 v0,
1794 Heap::kFixedArrayMapRootIndex,
1795 &call_builtin,
1796 DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001797
1798 // Get the array's length into t0 and calculate new length.
1799 __ lw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1800 __ Subu(t0, t0, Operand(Smi::FromInt(1)));
1801 __ Branch(&return_undefined, lt, t0, Operand(zero_reg));
1802
1803 // Get the last element.
1804 __ LoadRoot(t2, Heap::kTheHoleValueRootIndex);
1805 STATIC_ASSERT(kSmiTagSize == 1);
1806 STATIC_ASSERT(kSmiTag == 0);
1807 // We can't address the last element in one operation. Compute the more
1808 // expensive shift first, and use an offset later on.
1809 __ sll(t1, t0, kPointerSizeLog2 - kSmiTagSize);
1810 __ Addu(elements, elements, t1);
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00001811 __ lw(v0, FieldMemOperand(elements, FixedArray::kHeaderSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001812 __ Branch(&call_builtin, eq, v0, Operand(t2));
1813
1814 // Set the array's length.
1815 __ sw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1816
1817 // Fill with the hole.
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00001818 __ sw(t2, FieldMemOperand(elements, FixedArray::kHeaderSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001819 __ Drop(argc + 1);
1820 __ Ret();
1821
1822 __ bind(&return_undefined);
1823 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
1824 __ Drop(argc + 1);
1825 __ Ret();
1826
1827 __ bind(&call_builtin);
1828 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPop,
1829 masm()->isolate()),
1830 argc + 1,
1831 1);
1832
1833 // Handle call cache miss.
1834 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001835 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001836
1837 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001838 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00001839}
1840
1841
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001842Handle<Code> CallStubCompiler::CompileStringCharCodeAtCall(
1843 Handle<Object> object,
1844 Handle<JSObject> holder,
1845 Handle<JSGlobalPropertyCell> cell,
1846 Handle<JSFunction> function,
1847 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001848 // ----------- S t a t e -------------
1849 // -- a2 : function name
1850 // -- ra : return address
1851 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1852 // -- ...
1853 // -- sp[argc * 4] : receiver
1854 // -----------------------------------
1855
1856 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001857 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001858
1859 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001860 Label miss;
1861 Label name_miss;
1862 Label index_out_of_range;
1863
1864 Label* index_out_of_range_label = &index_out_of_range;
1865
danno@chromium.org40cb8782011-05-25 07:58:50 +00001866 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001867 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00001868 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001869 index_out_of_range_label = &miss;
1870 }
1871
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001872 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001873
1874 // Check that the maps starting from the prototype haven't changed.
1875 GenerateDirectLoadGlobalFunctionPrototype(masm(),
1876 Context::STRING_FUNCTION_INDEX,
1877 v0,
1878 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001879 ASSERT(!object.is_identical_to(holder));
hpayer@chromium.org8432c912013-02-28 15:55:26 +00001880 CheckPrototypes(
1881 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
1882 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001883
1884 Register receiver = a1;
1885 Register index = t1;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001886 Register result = v0;
1887 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1888 if (argc > 0) {
1889 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
1890 } else {
1891 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
1892 }
1893
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001894 StringCharCodeAtGenerator generator(receiver,
1895 index,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001896 result,
1897 &miss, // When not a string.
1898 &miss, // When not a number.
1899 index_out_of_range_label,
1900 STRING_INDEX_IS_NUMBER);
1901 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001902 __ Drop(argc + 1);
1903 __ Ret();
1904
1905 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001906 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001907
1908 if (index_out_of_range.is_linked()) {
1909 __ bind(&index_out_of_range);
1910 __ LoadRoot(v0, Heap::kNanValueRootIndex);
1911 __ Drop(argc + 1);
1912 __ Ret();
1913 }
1914
1915 __ bind(&miss);
1916 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001917 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001918 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001919 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001920
1921 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001922 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00001923}
1924
1925
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001926Handle<Code> CallStubCompiler::CompileStringCharAtCall(
1927 Handle<Object> object,
1928 Handle<JSObject> holder,
1929 Handle<JSGlobalPropertyCell> cell,
1930 Handle<JSFunction> function,
1931 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001932 // ----------- S t a t e -------------
1933 // -- a2 : function name
1934 // -- ra : return address
1935 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1936 // -- ...
1937 // -- sp[argc * 4] : receiver
1938 // -----------------------------------
1939
1940 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001941 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001942
1943 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001944 Label miss;
1945 Label name_miss;
1946 Label index_out_of_range;
1947 Label* index_out_of_range_label = &index_out_of_range;
danno@chromium.org40cb8782011-05-25 07:58:50 +00001948 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001949 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00001950 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001951 index_out_of_range_label = &miss;
1952 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001953 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001954
1955 // Check that the maps starting from the prototype haven't changed.
1956 GenerateDirectLoadGlobalFunctionPrototype(masm(),
1957 Context::STRING_FUNCTION_INDEX,
1958 v0,
1959 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001960 ASSERT(!object.is_identical_to(holder));
hpayer@chromium.org8432c912013-02-28 15:55:26 +00001961 CheckPrototypes(
1962 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
1963 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001964
1965 Register receiver = v0;
1966 Register index = t1;
danno@chromium.orgc612e022011-11-10 11:38:15 +00001967 Register scratch = a3;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001968 Register result = v0;
1969 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1970 if (argc > 0) {
1971 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
1972 } else {
1973 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
1974 }
1975
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001976 StringCharAtGenerator generator(receiver,
1977 index,
danno@chromium.orgc612e022011-11-10 11:38:15 +00001978 scratch,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001979 result,
1980 &miss, // When not a string.
1981 &miss, // When not a number.
1982 index_out_of_range_label,
1983 STRING_INDEX_IS_NUMBER);
1984 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001985 __ Drop(argc + 1);
1986 __ Ret();
1987
1988 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001989 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001990
1991 if (index_out_of_range.is_linked()) {
1992 __ bind(&index_out_of_range);
ulan@chromium.org750145a2013-03-07 15:14:13 +00001993 __ LoadRoot(v0, Heap::kempty_stringRootIndex);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001994 __ Drop(argc + 1);
1995 __ Ret();
1996 }
1997
1998 __ bind(&miss);
1999 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002000 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002001 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002002 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002003
2004 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002005 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002006}
2007
2008
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002009Handle<Code> CallStubCompiler::CompileStringFromCharCodeCall(
2010 Handle<Object> object,
2011 Handle<JSObject> holder,
2012 Handle<JSGlobalPropertyCell> cell,
2013 Handle<JSFunction> function,
2014 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002015 // ----------- S t a t e -------------
2016 // -- a2 : function name
2017 // -- ra : return address
2018 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2019 // -- ...
2020 // -- sp[argc * 4] : receiver
2021 // -----------------------------------
2022
2023 const int argc = arguments().immediate();
2024
2025 // If the object is not a JSObject or we got an unexpected number of
2026 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002027 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002028
2029 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002030 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002031
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002032 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002033 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
2034
2035 STATIC_ASSERT(kSmiTag == 0);
2036 __ JumpIfSmi(a1, &miss);
2037
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002038 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
2039 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002040 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002041 ASSERT(cell->value() == *function);
2042 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2043 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002044 GenerateLoadFunctionFromCell(cell, function, &miss);
2045 }
2046
2047 // Load the char code argument.
2048 Register code = a1;
2049 __ lw(code, MemOperand(sp, 0 * kPointerSize));
2050
2051 // Check the code is a smi.
2052 Label slow;
2053 STATIC_ASSERT(kSmiTag == 0);
2054 __ JumpIfNotSmi(code, &slow);
2055
2056 // Convert the smi code to uint16.
2057 __ And(code, code, Operand(Smi::FromInt(0xffff)));
2058
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002059 StringCharFromCodeGenerator generator(code, v0);
2060 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002061 __ Drop(argc + 1);
2062 __ Ret();
2063
2064 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002065 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002066
2067 // Tail call the full function. We do not have to patch the receiver
2068 // because the function makes no use of it.
2069 __ bind(&slow);
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002070 __ InvokeFunction(
2071 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002072
2073 __ bind(&miss);
2074 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002075 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002076
2077 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002078 return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002079}
2080
2081
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002082Handle<Code> CallStubCompiler::CompileMathFloorCall(
2083 Handle<Object> object,
2084 Handle<JSObject> holder,
2085 Handle<JSGlobalPropertyCell> cell,
2086 Handle<JSFunction> function,
2087 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002088 // ----------- S t a t e -------------
2089 // -- a2 : function name
2090 // -- ra : return address
2091 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2092 // -- ...
2093 // -- sp[argc * 4] : receiver
2094 // -----------------------------------
2095
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002096 if (!CpuFeatures::IsSupported(FPU)) {
2097 return Handle<Code>::null();
2098 }
2099
ulan@chromium.org750145a2013-03-07 15:14:13 +00002100 CpuFeatureScope scope_fpu(masm(), FPU);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002101 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002102 // If the object is not a JSObject or we got an unexpected number of
2103 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002104 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002105
2106 Label miss, slow;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002107 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002108
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002109 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002110 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002111 STATIC_ASSERT(kSmiTag == 0);
2112 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002113 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2114 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002115 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002116 ASSERT(cell->value() == *function);
2117 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2118 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002119 GenerateLoadFunctionFromCell(cell, function, &miss);
2120 }
2121
2122 // Load the (only) argument into v0.
2123 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2124
2125 // If the argument is a smi, just return.
2126 STATIC_ASSERT(kSmiTag == 0);
2127 __ And(t0, v0, Operand(kSmiTagMask));
2128 __ Drop(argc + 1, eq, t0, Operand(zero_reg));
2129 __ Ret(eq, t0, Operand(zero_reg));
2130
danno@chromium.org40cb8782011-05-25 07:58:50 +00002131 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002132
2133 Label wont_fit_smi, no_fpu_error, restore_fcsr_and_return;
2134
2135 // If fpu is enabled, we use the floor instruction.
2136
2137 // Load the HeapNumber value.
2138 __ ldc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
2139
2140 // Backup FCSR.
2141 __ cfc1(a3, FCSR);
2142 // Clearing FCSR clears the exception mask with no side-effects.
2143 __ ctc1(zero_reg, FCSR);
2144 // Convert the argument to an integer.
2145 __ floor_w_d(f0, f0);
2146
2147 // Start checking for special cases.
2148 // Get the argument exponent and clear the sign bit.
2149 __ lw(t1, FieldMemOperand(v0, HeapNumber::kValueOffset + kPointerSize));
2150 __ And(t2, t1, Operand(~HeapNumber::kSignMask));
2151 __ srl(t2, t2, HeapNumber::kMantissaBitsInTopWord);
2152
2153 // Retrieve FCSR and check for fpu errors.
2154 __ cfc1(t5, FCSR);
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002155 __ And(t5, t5, Operand(kFCSRExceptionFlagMask));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002156 __ Branch(&no_fpu_error, eq, t5, Operand(zero_reg));
2157
2158 // Check for NaN, Infinity, and -Infinity.
2159 // They are invariant through a Math.Floor call, so just
2160 // return the original argument.
2161 __ Subu(t3, t2, Operand(HeapNumber::kExponentMask
2162 >> HeapNumber::kMantissaBitsInTopWord));
2163 __ Branch(&restore_fcsr_and_return, eq, t3, Operand(zero_reg));
2164 // We had an overflow or underflow in the conversion. Check if we
2165 // have a big exponent.
2166 // If greater or equal, the argument is already round and in v0.
2167 __ Branch(&restore_fcsr_and_return, ge, t3,
2168 Operand(HeapNumber::kMantissaBits));
2169 __ Branch(&wont_fit_smi);
2170
2171 __ bind(&no_fpu_error);
2172 // Move the result back to v0.
2173 __ mfc1(v0, f0);
2174 // Check if the result fits into a smi.
2175 __ Addu(a1, v0, Operand(0x40000000));
2176 __ Branch(&wont_fit_smi, lt, a1, Operand(zero_reg));
2177 // Tag the result.
2178 STATIC_ASSERT(kSmiTag == 0);
2179 __ sll(v0, v0, kSmiTagSize);
2180
2181 // Check for -0.
2182 __ Branch(&restore_fcsr_and_return, ne, v0, Operand(zero_reg));
2183 // t1 already holds the HeapNumber exponent.
2184 __ And(t0, t1, Operand(HeapNumber::kSignMask));
2185 // If our HeapNumber is negative it was -0, so load its address and return.
2186 // Else v0 is loaded with 0, so we can also just return.
2187 __ Branch(&restore_fcsr_and_return, eq, t0, Operand(zero_reg));
2188 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2189
2190 __ bind(&restore_fcsr_and_return);
2191 // Restore FCSR and return.
2192 __ ctc1(a3, FCSR);
2193
2194 __ Drop(argc + 1);
2195 __ Ret();
2196
2197 __ bind(&wont_fit_smi);
2198 // Restore FCSR and fall to slow case.
2199 __ ctc1(a3, FCSR);
2200
2201 __ bind(&slow);
2202 // Tail call the full function. We do not have to patch the receiver
2203 // because the function makes no use of it.
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002204 __ InvokeFunction(
2205 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002206
2207 __ bind(&miss);
2208 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002209 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002210
2211 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002212 return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002213}
2214
2215
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002216Handle<Code> CallStubCompiler::CompileMathAbsCall(
2217 Handle<Object> object,
2218 Handle<JSObject> holder,
2219 Handle<JSGlobalPropertyCell> cell,
2220 Handle<JSFunction> function,
2221 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002222 // ----------- S t a t e -------------
2223 // -- a2 : function name
2224 // -- ra : return address
2225 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2226 // -- ...
2227 // -- sp[argc * 4] : receiver
2228 // -----------------------------------
2229
2230 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002231 // If the object is not a JSObject or we got an unexpected number of
2232 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002233 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002234
2235 Label miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002236
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002237 GenerateNameCheck(name, &miss);
2238 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002239 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002240 STATIC_ASSERT(kSmiTag == 0);
2241 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002242 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
2243 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002244 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002245 ASSERT(cell->value() == *function);
2246 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2247 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002248 GenerateLoadFunctionFromCell(cell, function, &miss);
2249 }
2250
2251 // Load the (only) argument into v0.
2252 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2253
2254 // Check if the argument is a smi.
2255 Label not_smi;
2256 STATIC_ASSERT(kSmiTag == 0);
2257 __ JumpIfNotSmi(v0, &not_smi);
2258
2259 // Do bitwise not or do nothing depending on the sign of the
2260 // argument.
2261 __ sra(t0, v0, kBitsPerInt - 1);
2262 __ Xor(a1, v0, t0);
2263
2264 // Add 1 or do nothing depending on the sign of the argument.
2265 __ Subu(v0, a1, t0);
2266
2267 // If the result is still negative, go to the slow case.
2268 // This only happens for the most negative smi.
2269 Label slow;
2270 __ Branch(&slow, lt, v0, Operand(zero_reg));
2271
2272 // Smi case done.
2273 __ Drop(argc + 1);
2274 __ Ret();
2275
2276 // Check if the argument is a heap number and load its exponent and
2277 // sign.
2278 __ bind(&not_smi);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002279 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002280 __ lw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2281
2282 // Check the sign of the argument. If the argument is positive,
2283 // just return it.
2284 Label negative_sign;
2285 __ And(t0, a1, Operand(HeapNumber::kSignMask));
2286 __ Branch(&negative_sign, ne, t0, Operand(zero_reg));
2287 __ Drop(argc + 1);
2288 __ Ret();
2289
2290 // If the argument is negative, clear the sign, and return a new
2291 // number.
2292 __ bind(&negative_sign);
2293 __ Xor(a1, a1, Operand(HeapNumber::kSignMask));
2294 __ lw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2295 __ LoadRoot(t2, Heap::kHeapNumberMapRootIndex);
2296 __ AllocateHeapNumber(v0, t0, t1, t2, &slow);
2297 __ sw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2298 __ sw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2299 __ Drop(argc + 1);
2300 __ Ret();
2301
2302 // Tail call the full function. We do not have to patch the receiver
2303 // because the function makes no use of it.
2304 __ bind(&slow);
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002305 __ InvokeFunction(
2306 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002307
2308 __ bind(&miss);
2309 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002310 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002311
2312 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002313 return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002314}
2315
2316
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002317Handle<Code> CallStubCompiler::CompileFastApiCall(
lrn@chromium.org7516f052011-03-30 08:52:27 +00002318 const CallOptimization& optimization,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002319 Handle<Object> object,
2320 Handle<JSObject> holder,
2321 Handle<JSGlobalPropertyCell> cell,
2322 Handle<JSFunction> function,
2323 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002324
danno@chromium.org40cb8782011-05-25 07:58:50 +00002325 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002326
2327 ASSERT(optimization.is_simple_api_call());
2328 // Bail out if object is a global object as we don't want to
2329 // repatch it to global receiver.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002330 if (object->IsGlobalObject()) return Handle<Code>::null();
2331 if (!cell.is_null()) return Handle<Code>::null();
2332 if (!object->IsJSObject()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002333 int depth = optimization.GetPrototypeDepthOfExpectedType(
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002334 Handle<JSObject>::cast(object), holder);
2335 if (depth == kInvalidProtoDepth) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002336
2337 Label miss, miss_before_stack_reserved;
2338
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002339 GenerateNameCheck(name, &miss_before_stack_reserved);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002340
2341 // Get the receiver from the stack.
2342 const int argc = arguments().immediate();
2343 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2344
2345 // Check that the receiver isn't a smi.
2346 __ JumpIfSmi(a1, &miss_before_stack_reserved);
2347
2348 __ IncrementCounter(counters->call_const(), 1, a0, a3);
2349 __ IncrementCounter(counters->call_const_fast_api(), 1, a0, a3);
2350
2351 ReserveSpaceForFastApiCall(masm(), a0);
2352
2353 // Check that the maps haven't changed and find a Holder as a side effect.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002354 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0, name,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002355 depth, &miss);
2356
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002357 GenerateFastApiDirectCall(masm(), optimization, argc);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002358
2359 __ bind(&miss);
2360 FreeSpaceForFastApiCall(masm());
2361
2362 __ bind(&miss_before_stack_reserved);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002363 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002364
2365 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002366 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002367}
2368
2369
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002370void CallStubCompiler::CompileHandlerFrontend(Handle<Object> object,
2371 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002372 Handle<Name> name,
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002373 CheckType check,
2374 Label* success) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002375 // ----------- S t a t e -------------
2376 // -- a2 : name
2377 // -- ra : return address
2378 // -----------------------------------
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002379 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002380 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002381
2382 // Get the receiver from the stack.
2383 const int argc = arguments().immediate();
2384 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2385
2386 // Check that the receiver isn't a smi.
2387 if (check != NUMBER_CHECK) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002388 __ JumpIfSmi(a1, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002389 }
2390
2391 // Make sure that it's okay not to patch the on stack receiver
2392 // unless we're doing a receiver map check.
2393 ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002394 switch (check) {
2395 case RECEIVER_MAP_CHECK:
2396 __ IncrementCounter(masm()->isolate()->counters()->call_const(),
2397 1, a0, a3);
2398
2399 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002400 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2401 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002402
2403 // Patch the receiver on the stack with the global proxy if
2404 // necessary.
2405 if (object->IsGlobalObject()) {
2406 __ lw(a3, FieldMemOperand(a1, GlobalObject::kGlobalReceiverOffset));
2407 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2408 }
2409 break;
2410
2411 case STRING_CHECK:
ulan@chromium.org750145a2013-03-07 15:14:13 +00002412 // Check that the object is a string.
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002413 __ GetObjectType(a1, a3, a3);
2414 __ Branch(&miss, Ugreater_equal, a3, Operand(FIRST_NONSTRING_TYPE));
2415 // Check that the maps starting from the prototype haven't changed.
2416 GenerateDirectLoadGlobalFunctionPrototype(
2417 masm(), Context::STRING_FUNCTION_INDEX, a0, &miss);
2418 CheckPrototypes(
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002419 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002420 a0, holder, a3, a1, t0, name, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002421 break;
2422
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002423 case SYMBOL_CHECK:
2424 // Check that the object is a symbol.
2425 __ GetObjectType(a1, a1, a3);
2426 __ Branch(&miss, ne, a3, Operand(SYMBOL_TYPE));
2427 break;
2428
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002429 case NUMBER_CHECK: {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002430 Label fast;
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002431 // Check that the object is a smi or a heap number.
2432 __ JumpIfSmi(a1, &fast);
2433 __ GetObjectType(a1, a0, a0);
2434 __ Branch(&miss, ne, a0, Operand(HEAP_NUMBER_TYPE));
2435 __ bind(&fast);
2436 // Check that the maps starting from the prototype haven't changed.
2437 GenerateDirectLoadGlobalFunctionPrototype(
2438 masm(), Context::NUMBER_FUNCTION_INDEX, a0, &miss);
2439 CheckPrototypes(
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002440 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002441 a0, holder, a3, a1, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002442 break;
2443 }
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002444 case BOOLEAN_CHECK: {
2445 Label fast;
2446 // Check that the object is a boolean.
2447 __ LoadRoot(t0, Heap::kTrueValueRootIndex);
2448 __ Branch(&fast, eq, a1, Operand(t0));
2449 __ LoadRoot(t0, Heap::kFalseValueRootIndex);
2450 __ Branch(&miss, ne, a1, Operand(t0));
2451 __ bind(&fast);
2452 // Check that the maps starting from the prototype haven't changed.
2453 GenerateDirectLoadGlobalFunctionPrototype(
2454 masm(), Context::BOOLEAN_FUNCTION_INDEX, a0, &miss);
2455 CheckPrototypes(
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002456 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002457 a0, holder, a3, a1, t0, name, &miss);
2458 break;
2459 }
2460 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002461
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002462 __ jmp(success);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002463
2464 // Handle call cache miss.
2465 __ bind(&miss);
2466
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002467 GenerateMissBranch();
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002468}
2469
2470
2471void CallStubCompiler::CompileHandlerBackend(Handle<JSFunction> function) {
2472 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
2473 ? CALL_AS_FUNCTION
2474 : CALL_AS_METHOD;
2475 __ InvokeFunction(
2476 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), call_kind);
2477}
2478
2479
2480Handle<Code> CallStubCompiler::CompileCallConstant(
2481 Handle<Object> object,
2482 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002483 Handle<Name> name,
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002484 CheckType check,
2485 Handle<JSFunction> function) {
2486 if (HasCustomCallGenerator(function)) {
2487 Handle<Code> code = CompileCustomCall(object, holder,
2488 Handle<JSGlobalPropertyCell>::null(),
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002489 function, Handle<String>::cast(name));
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002490 // A null handle means bail out to the regular compiler code below.
2491 if (!code.is_null()) return code;
2492 }
2493
2494 Label success;
2495
2496 CompileHandlerFrontend(object, holder, name, check, &success);
2497 __ bind(&success);
2498 CompileHandlerBackend(function);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002499
2500 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002501 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002502}
2503
2504
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002505Handle<Code> CallStubCompiler::CompileCallInterceptor(Handle<JSObject> object,
2506 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002507 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002508 // ----------- S t a t e -------------
2509 // -- a2 : name
2510 // -- ra : return address
2511 // -----------------------------------
2512
2513 Label miss;
2514
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002515 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002516
2517 // Get the number of arguments.
2518 const int argc = arguments().immediate();
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002519 LookupResult lookup(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002520 LookupPostInterceptor(holder, name, &lookup);
2521
2522 // Get the receiver from the stack.
2523 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2524
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002525 CallInterceptorCompiler compiler(this, arguments(), a2, extra_state_);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002526 compiler.Compile(masm(), object, holder, name, &lookup, a1, a3, t0, a0,
2527 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002528
2529 // Move returned value, the function to call, to a1.
2530 __ mov(a1, v0);
2531 // Restore receiver.
2532 __ lw(a0, MemOperand(sp, argc * kPointerSize));
2533
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002534 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002535
2536 // Handle call cache miss.
2537 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002538 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002539
2540 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002541 return GetCode(Code::INTERCEPTOR, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002542}
2543
2544
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002545Handle<Code> CallStubCompiler::CompileCallGlobal(
2546 Handle<JSObject> object,
2547 Handle<GlobalObject> holder,
2548 Handle<JSGlobalPropertyCell> cell,
2549 Handle<JSFunction> function,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002550 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002551 // ----------- S t a t e -------------
2552 // -- a2 : name
2553 // -- ra : return address
2554 // -----------------------------------
2555
2556 if (HasCustomCallGenerator(function)) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002557 Handle<Code> code = CompileCustomCall(
2558 object, holder, cell, function, Handle<String>::cast(name));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002559 // A null handle means bail out to the regular compiler code below.
2560 if (!code.is_null()) return code;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002561 }
2562
2563 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002564 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002565
2566 // Get the number of arguments.
2567 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002568 GenerateGlobalReceiverCheck(object, holder, name, &miss);
2569 GenerateLoadFunctionFromCell(cell, function, &miss);
2570
2571 // Patch the receiver on the stack with the global proxy if
2572 // necessary.
2573 if (object->IsGlobalObject()) {
2574 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
2575 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2576 }
2577
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002578 // Set up the context (function already in r1).
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002579 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
2580
2581 // Jump to the cached code (tail call).
2582 Counters* counters = masm()->isolate()->counters();
2583 __ IncrementCounter(counters->call_global_inline(), 1, a3, t0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002584 ParameterCount expected(function->shared()->formal_parameter_count());
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002585 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
danno@chromium.org40cb8782011-05-25 07:58:50 +00002586 ? CALL_AS_FUNCTION
2587 : CALL_AS_METHOD;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002588 // We call indirectly through the code field in the function to
2589 // allow recompilation to take effect without changing any of the
2590 // call sites.
2591 __ lw(a3, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
2592 __ InvokeCode(a3, expected, arguments(), JUMP_FUNCTION,
2593 NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002594
2595 // Handle call cache miss.
2596 __ bind(&miss);
2597 __ IncrementCounter(counters->call_global_inline_miss(), 1, a1, a3);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002598 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002599
2600 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002601 return GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002602}
2603
2604
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002605Handle<Code> StoreStubCompiler::CompileStoreCallback(
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002606 Handle<Name> name,
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002607 Handle<JSObject> object,
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002608 Handle<JSObject> holder,
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00002609 Handle<ExecutableAccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002610 Label miss;
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002611 // Check that the maps haven't changed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002612 __ JumpIfSmi(receiver(), &miss);
2613 CheckPrototypes(object, receiver(), holder,
2614 scratch1(), scratch2(), scratch3(), name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002615
2616 // Stub never generated for non-global objects that require access
2617 // checks.
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002618 ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002619
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002620 __ push(receiver()); // Receiver.
2621 __ li(at, Operand(callback)); // Callback info.
2622 __ Push(at, this->name(), value());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002623
2624 // Do tail-call to the runtime system.
2625 ExternalReference store_callback_property =
2626 ExternalReference(IC_Utility(IC::kStoreCallbackProperty),
2627 masm()->isolate());
2628 __ TailCallExternalReference(store_callback_property, 4, 1);
2629
2630 // Handle store cache miss.
2631 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002632 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002633
2634 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002635 return GetICCode(kind(), Code::CALLBACKS, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002636}
2637
2638
yangguo@chromium.org46839fb2012-08-28 09:06:19 +00002639#undef __
2640#define __ ACCESS_MASM(masm)
2641
2642
2643void StoreStubCompiler::GenerateStoreViaSetter(
2644 MacroAssembler* masm,
2645 Handle<JSFunction> setter) {
2646 // ----------- S t a t e -------------
2647 // -- a0 : value
2648 // -- a1 : receiver
2649 // -- a2 : name
2650 // -- ra : return address
2651 // -----------------------------------
2652 {
2653 FrameScope scope(masm, StackFrame::INTERNAL);
2654
2655 // Save value register, so we can restore it later.
2656 __ push(a0);
2657
2658 if (!setter.is_null()) {
2659 // Call the JavaScript setter with receiver and value on the stack.
2660 __ push(a1);
2661 __ push(a0);
2662 ParameterCount actual(1);
2663 __ InvokeFunction(setter, actual, CALL_FUNCTION, NullCallWrapper(),
2664 CALL_AS_METHOD);
2665 } else {
2666 // If we generate a global code snippet for deoptimization only, remember
2667 // the place to continue after deoptimization.
2668 masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
2669 }
2670
2671 // We have to return the passed value, not the return value of the setter.
2672 __ pop(v0);
2673
2674 // Restore context register.
2675 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2676 }
2677 __ Ret();
2678}
2679
2680
2681#undef __
2682#define __ ACCESS_MASM(masm())
2683
2684
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002685Handle<Code> StoreStubCompiler::CompileStoreInterceptor(
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002686 Handle<JSObject> object,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002687 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002688 Label miss;
2689
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002690 // Check that the map of the object hasn't changed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002691 __ CheckMap(receiver(), scratch1(), Handle<Map>(object->map()), &miss,
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002692 DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002693
2694 // Perform global security token check if needed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002695 if (object->IsJSGlobalProxy()) {
2696 __ CheckAccessGlobalProxy(receiver(), scratch1(), &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002697 }
2698
2699 // Stub is never generated for non-global objects that require access
2700 // checks.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002701 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002702
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002703 __ Push(receiver(), this->name(), value());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002704
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002705 __ li(scratch1(), Operand(Smi::FromInt(strict_mode())));
2706 __ push(scratch1()); // strict mode
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002707
2708 // Do tail-call to the runtime system.
2709 ExternalReference store_ic_property =
2710 ExternalReference(IC_Utility(IC::kStoreInterceptorProperty),
2711 masm()->isolate());
2712 __ TailCallExternalReference(store_ic_property, 4, 1);
2713
2714 // Handle store cache miss.
2715 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002716 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002717
2718 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002719 return GetICCode(kind(), Code::INTERCEPTOR, name);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00002720}
2721
2722
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002723Handle<Code> StoreStubCompiler::CompileStoreGlobal(
2724 Handle<GlobalObject> object,
2725 Handle<JSGlobalPropertyCell> cell,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002726 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002727 Label miss;
2728
2729 // Check that the map of the global has not changed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002730 __ lw(scratch1(), FieldMemOperand(receiver(), HeapObject::kMapOffset));
2731 __ Branch(&miss, ne, scratch1(), Operand(Handle<Map>(object->map())));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002732
2733 // Check that the value in the cell is not the hole. If it is, this
2734 // cell could have been deleted and reintroducing the global needs
2735 // to update the property details in the property dictionary of the
2736 // global object. We bail out to the runtime system to do that.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002737 __ li(scratch1(), Operand(cell));
2738 __ LoadRoot(scratch2(), Heap::kTheHoleValueRootIndex);
2739 __ lw(scratch3(),
2740 FieldMemOperand(scratch1(), JSGlobalPropertyCell::kValueOffset));
2741 __ Branch(&miss, eq, scratch3(), Operand(scratch2()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002742
2743 // Store the value in the cell.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002744 __ sw(value(),
2745 FieldMemOperand(scratch1(), JSGlobalPropertyCell::kValueOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002746 __ mov(v0, a0); // Stored value must be returned in v0.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002747 // Cells are always rescanned, so no write barrier here.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00002748
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002749 Counters* counters = masm()->isolate()->counters();
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002750 __ IncrementCounter(
2751 counters->named_store_global_inline(), 1, scratch1(), scratch2());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002752 __ Ret();
2753
2754 // Handle store cache miss.
2755 __ bind(&miss);
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002756 __ IncrementCounter(
2757 counters->named_store_global_inline_miss(), 1, scratch1(), scratch2());
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002758 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002759
2760 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002761 return GetICCode(kind(), Code::NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002762}
2763
2764
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002765Handle<Code> LoadStubCompiler::CompileLoadNonexistent(
2766 Handle<JSObject> object,
2767 Handle<JSObject> last,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002768 Handle<Name> name,
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002769 Handle<GlobalObject> global) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002770 Label success;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002771
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002772 NonexistentHandlerFrontend(object, last, name, &success, global);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002773
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002774 __ bind(&success);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002775 // Return undefined if maps of the full prototype chain is still the same.
2776 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
2777 __ Ret();
2778
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002779 // Return the generated code.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002780 return GetCode(kind(), Code::NONEXISTENT, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002781}
2782
2783
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002784Register* LoadStubCompiler::registers() {
2785 // receiver, name, scratch1, scratch2, scratch3, scratch4.
2786 static Register registers[] = { a0, a2, a3, a1, t0, t1 };
2787 return registers;
lrn@chromium.org7516f052011-03-30 08:52:27 +00002788}
2789
2790
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002791Register* KeyedLoadStubCompiler::registers() {
2792 // receiver, name, scratch1, scratch2, scratch3, scratch4.
2793 static Register registers[] = { a1, a0, a2, a3, t0, t1 };
2794 return registers;
2795}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002796
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002797
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002798Register* StoreStubCompiler::registers() {
2799 // receiver, name, value, scratch1, scratch2, scratch3.
2800 static Register registers[] = { a1, a2, a0, a3, t0, t1 };
2801 return registers;
2802}
2803
2804
2805Register* KeyedStoreStubCompiler::registers() {
2806 // receiver, name, value, scratch1, scratch2, scratch3.
2807 static Register registers[] = { a2, a1, a0, a3, t0, t1 };
2808 return registers;
2809}
2810
2811
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002812void KeyedLoadStubCompiler::GenerateNameCheck(Handle<Name> name,
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002813 Register name_reg,
2814 Label* miss) {
2815 __ Branch(miss, ne, name_reg, Operand(name));
lrn@chromium.org7516f052011-03-30 08:52:27 +00002816}
2817
2818
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002819void KeyedStoreStubCompiler::GenerateNameCheck(Handle<Name> name,
2820 Register name_reg,
2821 Label* miss) {
2822 __ Branch(miss, ne, name_reg, Operand(name));
2823}
2824
2825
mstarzinger@chromium.orgde886792012-09-11 13:22:37 +00002826#undef __
2827#define __ ACCESS_MASM(masm)
2828
2829
2830void LoadStubCompiler::GenerateLoadViaGetter(MacroAssembler* masm,
2831 Handle<JSFunction> getter) {
2832 // ----------- S t a t e -------------
2833 // -- a0 : receiver
2834 // -- a2 : name
2835 // -- ra : return address
2836 // -----------------------------------
2837 {
2838 FrameScope scope(masm, StackFrame::INTERNAL);
2839
2840 if (!getter.is_null()) {
2841 // Call the JavaScript getter with the receiver on the stack.
2842 __ push(a0);
2843 ParameterCount actual(0);
2844 __ InvokeFunction(getter, actual, CALL_FUNCTION, NullCallWrapper(),
2845 CALL_AS_METHOD);
2846 } else {
2847 // If we generate a global code snippet for deoptimization only, remember
2848 // the place to continue after deoptimization.
2849 masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
2850 }
2851
2852 // Restore context register.
2853 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2854 }
2855 __ Ret();
2856}
2857
2858
2859#undef __
2860#define __ ACCESS_MASM(masm())
2861
2862
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002863Handle<Code> LoadStubCompiler::CompileLoadGlobal(
2864 Handle<JSObject> object,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002865 Handle<GlobalObject> global,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002866 Handle<JSGlobalPropertyCell> cell,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002867 Handle<Name> name,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002868 bool is_dont_delete) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002869 Label success, miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002870
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002871 __ CheckMap(
2872 receiver(), scratch1(), Handle<Map>(object->map()), &miss, DO_SMI_CHECK);
2873 HandlerFrontendHeader(
2874 object, receiver(), Handle<JSObject>::cast(global), name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002875
2876 // Get the value from the cell.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002877 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002878 __ lw(t0, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
2879
2880 // Check for deleted property if property can actually be deleted.
2881 if (!is_dont_delete) {
2882 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
2883 __ Branch(&miss, eq, t0, Operand(at));
2884 }
2885
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002886 HandlerFrontendFooter(&success, &miss);
2887 __ bind(&success);
2888
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002889 Counters* counters = masm()->isolate()->counters();
2890 __ IncrementCounter(counters->named_load_global_stub(), 1, a1, a3);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002891 __ mov(v0, t0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002892 __ Ret();
2893
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002894 // Return the generated code.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002895 return GetICCode(kind(), Code::NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002896}
2897
2898
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002899Handle<Code> BaseLoadStubCompiler::CompilePolymorphicIC(
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002900 MapHandleList* receiver_maps,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002901 CodeHandleList* handlers,
2902 Handle<Name> name,
2903 Code::StubType type,
2904 IcCheckType check) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002905 Label miss;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002906
2907 if (check == PROPERTY) {
2908 GenerateNameCheck(name, this->name(), &miss);
2909 }
2910
2911 __ JumpIfSmi(receiver(), &miss);
2912 Register map_reg = scratch1();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002913
danno@chromium.org40cb8782011-05-25 07:58:50 +00002914 int receiver_count = receiver_maps->length();
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002915 __ lw(map_reg, FieldMemOperand(receiver(), HeapObject::kMapOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00002916 for (int current = 0; current < receiver_count; ++current) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002917 __ Jump(handlers->at(current), RelocInfo::CODE_TARGET,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002918 eq, map_reg, Operand(receiver_maps->at(current)));
danno@chromium.org40cb8782011-05-25 07:58:50 +00002919 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002920
2921 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002922 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002923
2924 // Return the generated code.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002925 InlineCacheState state =
2926 receiver_maps->length() > 1 ? POLYMORPHIC : MONOMORPHIC;
2927 return GetICCode(kind(), type, name, state);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002928}
2929
2930
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002931Handle<Code> KeyedStoreStubCompiler::CompileStorePolymorphic(
2932 MapHandleList* receiver_maps,
2933 CodeHandleList* handler_stubs,
2934 MapHandleList* transitioned_maps) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00002935 Label miss;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002936 __ JumpIfSmi(receiver(), &miss);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002937
2938 int receiver_count = receiver_maps->length();
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002939 __ lw(scratch1(), FieldMemOperand(receiver(), HeapObject::kMapOffset));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00002940 for (int i = 0; i < receiver_count; ++i) {
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002941 if (transitioned_maps->at(i).is_null()) {
2942 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET, eq,
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002943 scratch1(), Operand(receiver_maps->at(i)));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00002944 } else {
2945 Label next_map;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002946 __ Branch(&next_map, ne, scratch1(), Operand(receiver_maps->at(i)));
2947 __ li(transition_map(), Operand(transitioned_maps->at(i)));
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002948 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00002949 __ bind(&next_map);
2950 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00002951 }
2952
2953 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002954 TailCallBuiltin(masm(), MissBuiltin(kind()));
danno@chromium.org40cb8782011-05-25 07:58:50 +00002955
2956 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002957 return GetICCode(
2958 kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002959}
2960
2961
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002962Handle<Code> ConstructStubCompiler::CompileConstructStub(
2963 Handle<JSFunction> function) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002964 // a0 : argc
2965 // a1 : constructor
2966 // ra : return address
2967 // [sp] : last argument
2968 Label generic_stub_call;
2969
2970 // Use t7 for holding undefined which is used in several places below.
2971 __ LoadRoot(t7, Heap::kUndefinedValueRootIndex);
2972
2973#ifdef ENABLE_DEBUGGER_SUPPORT
2974 // Check to see whether there are any break points in the function code. If
2975 // there are jump to the generic constructor stub which calls the actual
2976 // code for the function thereby hitting the break points.
2977 __ lw(t5, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2978 __ lw(a2, FieldMemOperand(t5, SharedFunctionInfo::kDebugInfoOffset));
2979 __ Branch(&generic_stub_call, ne, a2, Operand(t7));
2980#endif
2981
2982 // Load the initial map and verify that it is in fact a map.
2983 // a1: constructor function
2984 // t7: undefined
2985 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002986 __ JumpIfSmi(a2, &generic_stub_call);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002987 __ GetObjectType(a2, a3, t0);
2988 __ Branch(&generic_stub_call, ne, t0, Operand(MAP_TYPE));
2989
2990#ifdef DEBUG
2991 // Cannot construct functions this way.
2992 // a0: argc
2993 // a1: constructor function
2994 // a2: initial map
2995 // t7: undefined
2996 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceTypeOffset));
2997 __ Check(ne, "Function constructed by construct stub.",
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00002998 a3, Operand(JS_FUNCTION_TYPE));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002999#endif
3000
3001 // Now allocate the JSObject in new space.
3002 // a0: argc
3003 // a1: constructor function
3004 // a2: initial map
3005 // t7: undefined
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00003006 ASSERT(function->has_initial_map());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003007 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceSizeOffset));
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00003008#ifdef DEBUG
3009 int instance_size = function->initial_map()->instance_size();
3010 __ Check(eq, "Instance size of initial map changed.",
3011 a3, Operand(instance_size >> kPointerSizeLog2));
3012#endif
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003013 __ AllocateInNewSpace(a3, t4, t5, t6, &generic_stub_call, SIZE_IN_WORDS);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003014
3015 // Allocated the JSObject, now initialize the fields. Map is set to initial
3016 // map and properties and elements are set to empty fixed array.
3017 // a0: argc
3018 // a1: constructor function
3019 // a2: initial map
3020 // a3: object size (in words)
3021 // t4: JSObject (not tagged)
3022 // t7: undefined
3023 __ LoadRoot(t6, Heap::kEmptyFixedArrayRootIndex);
3024 __ mov(t5, t4);
3025 __ sw(a2, MemOperand(t5, JSObject::kMapOffset));
3026 __ sw(t6, MemOperand(t5, JSObject::kPropertiesOffset));
3027 __ sw(t6, MemOperand(t5, JSObject::kElementsOffset));
3028 __ Addu(t5, t5, Operand(3 * kPointerSize));
3029 ASSERT_EQ(0 * kPointerSize, JSObject::kMapOffset);
3030 ASSERT_EQ(1 * kPointerSize, JSObject::kPropertiesOffset);
3031 ASSERT_EQ(2 * kPointerSize, JSObject::kElementsOffset);
3032
3033
3034 // Calculate the location of the first argument. The stack contains only the
3035 // argc arguments.
3036 __ sll(a1, a0, kPointerSizeLog2);
3037 __ Addu(a1, a1, sp);
3038
3039 // Fill all the in-object properties with undefined.
3040 // a0: argc
3041 // a1: first argument
3042 // a3: object size (in words)
3043 // t4: JSObject (not tagged)
3044 // t5: First in-object property of JSObject (not tagged)
3045 // t7: undefined
3046 // Fill the initialized properties with a constant value or a passed argument
3047 // depending on the this.x = ...; assignment in the function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003048 Handle<SharedFunctionInfo> shared(function->shared());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003049 for (int i = 0; i < shared->this_property_assignments_count(); i++) {
3050 if (shared->IsThisPropertyAssignmentArgument(i)) {
3051 Label not_passed, next;
3052 // Check if the argument assigned to the property is actually passed.
3053 int arg_number = shared->GetThisPropertyAssignmentArgument(i);
3054 __ Branch(&not_passed, less_equal, a0, Operand(arg_number));
3055 // Argument passed - find it on the stack.
3056 __ lw(a2, MemOperand(a1, (arg_number + 1) * -kPointerSize));
3057 __ sw(a2, MemOperand(t5));
3058 __ Addu(t5, t5, kPointerSize);
3059 __ jmp(&next);
3060 __ bind(&not_passed);
3061 // Set the property to undefined.
3062 __ sw(t7, MemOperand(t5));
3063 __ Addu(t5, t5, Operand(kPointerSize));
3064 __ bind(&next);
3065 } else {
3066 // Set the property to the constant value.
ulan@chromium.org09d7ab52013-02-25 15:50:35 +00003067 Handle<Object> constant(shared->GetThisPropertyAssignmentConstant(i),
3068 masm()->isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003069 __ li(a2, Operand(constant));
3070 __ sw(a2, MemOperand(t5));
3071 __ Addu(t5, t5, kPointerSize);
3072 }
3073 }
3074
3075 // Fill the unused in-object property fields with undefined.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003076 for (int i = shared->this_property_assignments_count();
3077 i < function->initial_map()->inobject_properties();
3078 i++) {
3079 __ sw(t7, MemOperand(t5));
3080 __ Addu(t5, t5, kPointerSize);
3081 }
3082
3083 // a0: argc
3084 // t4: JSObject (not tagged)
3085 // Move argc to a1 and the JSObject to return to v0 and tag it.
3086 __ mov(a1, a0);
3087 __ mov(v0, t4);
3088 __ Or(v0, v0, Operand(kHeapObjectTag));
3089
3090 // v0: JSObject
3091 // a1: argc
3092 // Remove caller arguments and receiver from the stack and return.
3093 __ sll(t0, a1, kPointerSizeLog2);
3094 __ Addu(sp, sp, t0);
3095 __ Addu(sp, sp, Operand(kPointerSize));
3096 Counters* counters = masm()->isolate()->counters();
3097 __ IncrementCounter(counters->constructed_objects(), 1, a1, a2);
3098 __ IncrementCounter(counters->constructed_objects_stub(), 1, a1, a2);
3099 __ Ret();
3100
3101 // Jump to the generic stub in case the specialized code cannot handle the
3102 // construction.
3103 __ bind(&generic_stub_call);
3104 Handle<Code> generic_construct_stub =
3105 masm()->isolate()->builtins()->JSConstructStubGeneric();
3106 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET);
3107
3108 // Return the generated code.
3109 return GetCode();
3110}
3111
3112
danno@chromium.org40cb8782011-05-25 07:58:50 +00003113#undef __
3114#define __ ACCESS_MASM(masm)
3115
3116
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003117void KeyedLoadStubCompiler::GenerateLoadDictionaryElement(
3118 MacroAssembler* masm) {
3119 // ---------- S t a t e --------------
3120 // -- ra : return address
3121 // -- a0 : key
3122 // -- a1 : receiver
3123 // -----------------------------------
3124 Label slow, miss_force_generic;
3125
3126 Register key = a0;
3127 Register receiver = a1;
3128
3129 __ JumpIfNotSmi(key, &miss_force_generic);
3130 __ lw(t0, FieldMemOperand(receiver, JSObject::kElementsOffset));
3131 __ sra(a2, a0, kSmiTagSize);
3132 __ LoadFromNumberDictionary(&slow, t0, a0, v0, a2, a3, t1);
3133 __ Ret();
3134
3135 // Slow case, key and receiver still in a0 and a1.
3136 __ bind(&slow);
3137 __ IncrementCounter(
3138 masm->isolate()->counters()->keyed_load_external_array_slow(),
3139 1, a2, a3);
3140 // Entry registers are intact.
3141 // ---------- S t a t e --------------
3142 // -- ra : return address
3143 // -- a0 : key
3144 // -- a1 : receiver
3145 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003146 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003147
3148 // Miss case, call the runtime.
3149 __ bind(&miss_force_generic);
3150
3151 // ---------- S t a t e --------------
3152 // -- ra : return address
3153 // -- a0 : key
3154 // -- a1 : receiver
3155 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003156 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_MissForceGeneric);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003157}
3158
3159
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003160static bool IsElementTypeSigned(ElementsKind elements_kind) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003161 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003162 case EXTERNAL_BYTE_ELEMENTS:
3163 case EXTERNAL_SHORT_ELEMENTS:
3164 case EXTERNAL_INT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003165 return true;
3166
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003167 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
3168 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
3169 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
3170 case EXTERNAL_PIXEL_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003171 return false;
3172
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003173 case EXTERNAL_FLOAT_ELEMENTS:
3174 case EXTERNAL_DOUBLE_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003175 case FAST_SMI_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003176 case FAST_ELEMENTS:
3177 case FAST_DOUBLE_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003178 case FAST_HOLEY_SMI_ELEMENTS:
3179 case FAST_HOLEY_ELEMENTS:
3180 case FAST_HOLEY_DOUBLE_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003181 case DICTIONARY_ELEMENTS:
3182 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003183 UNREACHABLE();
3184 return false;
3185 }
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003186 return false;
lrn@chromium.org7516f052011-03-30 08:52:27 +00003187}
3188
3189
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003190static void GenerateSmiKeyCheck(MacroAssembler* masm,
3191 Register key,
3192 Register scratch0,
3193 Register scratch1,
3194 FPURegister double_scratch0,
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003195 FPURegister double_scratch1,
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003196 Label* fail) {
3197 if (CpuFeatures::IsSupported(FPU)) {
ulan@chromium.org750145a2013-03-07 15:14:13 +00003198 CpuFeatureScope scope(masm, FPU);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003199 Label key_ok;
3200 // Check for smi or a smi inside a heap number. We convert the heap
3201 // number and check if the conversion is exact and fits into the smi
3202 // range.
3203 __ JumpIfSmi(key, &key_ok);
3204 __ CheckMap(key,
3205 scratch0,
3206 Heap::kHeapNumberMapRootIndex,
3207 fail,
3208 DONT_DO_SMI_CHECK);
3209 __ ldc1(double_scratch0, FieldMemOperand(key, HeapNumber::kValueOffset));
3210 __ EmitFPUTruncate(kRoundToZero,
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003211 scratch0,
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003212 double_scratch0,
3213 at,
3214 double_scratch1,
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003215 scratch1,
3216 kCheckForInexactConversion);
3217
3218 __ Branch(fail, ne, scratch1, Operand(zero_reg));
3219
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003220 __ SmiTagCheckOverflow(key, scratch0, scratch1);
3221 __ BranchOnOverflow(fail, scratch1);
3222 __ bind(&key_ok);
3223 } else {
3224 // Check that the key is a smi.
3225 __ JumpIfNotSmi(key, fail);
3226 }
3227}
3228
3229
danno@chromium.org40cb8782011-05-25 07:58:50 +00003230void KeyedStoreStubCompiler::GenerateStoreExternalArray(
3231 MacroAssembler* masm,
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003232 ElementsKind elements_kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003233 // ---------- S t a t e --------------
3234 // -- a0 : value
3235 // -- a1 : key
3236 // -- a2 : receiver
3237 // -- ra : return address
3238 // -----------------------------------
3239
danno@chromium.org40cb8782011-05-25 07:58:50 +00003240 Label slow, check_heap_number, miss_force_generic;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003241
3242 // Register usage.
3243 Register value = a0;
3244 Register key = a1;
3245 Register receiver = a2;
3246 // a3 mostly holds the elements array or the destination external array.
3247
danno@chromium.org40cb8782011-05-25 07:58:50 +00003248 // This stub is meant to be tail-jumped to, the receiver must already
3249 // have been verified by the caller to not be a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003250
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003251 // Check that the key is a smi or a heap number convertible to a smi.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003252 GenerateSmiKeyCheck(masm, key, t0, t1, f2, f4, &miss_force_generic);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003253
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003254 __ lw(a3, FieldMemOperand(receiver, JSObject::kElementsOffset));
3255
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003256 // Check that the index is in range.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003257 __ lw(t1, FieldMemOperand(a3, ExternalArray::kLengthOffset));
3258 // Unsigned comparison catches both negative and too-large values.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003259 __ Branch(&miss_force_generic, Ugreater_equal, key, Operand(t1));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003260
3261 // Handle both smis and HeapNumbers in the fast path. Go to the
3262 // runtime for all other kinds of values.
3263 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003264
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003265 if (elements_kind == EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003266 // Double to pixel conversion is only implemented in the runtime for now.
3267 __ JumpIfNotSmi(value, &slow);
3268 } else {
3269 __ JumpIfNotSmi(value, &check_heap_number);
3270 }
3271 __ SmiUntag(t1, value);
3272 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3273
3274 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003275 // t1: value (integer).
3276
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003277 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003278 case EXTERNAL_PIXEL_ELEMENTS: {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003279 // Clamp the value to [0..255].
3280 // v0 is used as a scratch register here.
3281 Label done;
3282 __ li(v0, Operand(255));
3283 // Normal branch: nop in delay slot.
3284 __ Branch(&done, gt, t1, Operand(v0));
3285 // Use delay slot in this branch.
3286 __ Branch(USE_DELAY_SLOT, &done, lt, t1, Operand(zero_reg));
3287 __ mov(v0, zero_reg); // In delay slot.
3288 __ mov(v0, t1); // Value is in range 0..255.
3289 __ bind(&done);
3290 __ mov(t1, v0);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003291
3292 __ srl(t8, key, 1);
3293 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003294 __ sb(t1, MemOperand(t8, 0));
3295 }
3296 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003297 case EXTERNAL_BYTE_ELEMENTS:
3298 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003299 __ srl(t8, key, 1);
3300 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003301 __ sb(t1, MemOperand(t8, 0));
3302 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003303 case EXTERNAL_SHORT_ELEMENTS:
3304 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003305 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003306 __ sh(t1, MemOperand(t8, 0));
3307 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003308 case EXTERNAL_INT_ELEMENTS:
3309 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003310 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003311 __ addu(t8, a3, t8);
3312 __ sw(t1, MemOperand(t8, 0));
3313 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003314 case EXTERNAL_FLOAT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003315 // Perform int-to-float conversion and store to memory.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003316 __ SmiUntag(t0, key);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003317 StoreIntAsFloat(masm, a3, t0, t1, t2, t3, t4);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003318 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003319 case EXTERNAL_DOUBLE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003320 __ sll(t8, key, 2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003321 __ addu(a3, a3, t8);
3322 // a3: effective address of the double element
3323 FloatingPointHelper::Destination destination;
3324 if (CpuFeatures::IsSupported(FPU)) {
3325 destination = FloatingPointHelper::kFPURegisters;
3326 } else {
3327 destination = FloatingPointHelper::kCoreRegisters;
3328 }
3329 FloatingPointHelper::ConvertIntToDouble(
danno@chromium.org40cb8782011-05-25 07:58:50 +00003330 masm, t1, destination,
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003331 f0, t2, t3, // These are: double_dst, dst_mantissa, dst_exponent.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003332 t0, f2); // These are: scratch2, single_scratch.
3333 if (destination == FloatingPointHelper::kFPURegisters) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003334 CpuFeatureScope scope(masm, FPU);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003335 __ sdc1(f0, MemOperand(a3, 0));
3336 } else {
3337 __ sw(t2, MemOperand(a3, 0));
3338 __ sw(t3, MemOperand(a3, Register::kSizeInBytes));
3339 }
3340 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003341 case FAST_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003342 case FAST_SMI_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003343 case FAST_DOUBLE_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003344 case FAST_HOLEY_ELEMENTS:
3345 case FAST_HOLEY_SMI_ELEMENTS:
3346 case FAST_HOLEY_DOUBLE_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003347 case DICTIONARY_ELEMENTS:
3348 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003349 UNREACHABLE();
3350 break;
3351 }
3352
3353 // Entry registers are intact, a0 holds the value which is the return value.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003354 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003355 __ Ret();
3356
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003357 if (elements_kind != EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003358 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003359 __ bind(&check_heap_number);
3360 __ GetObjectType(value, t1, t2);
3361 __ Branch(&slow, ne, t2, Operand(HEAP_NUMBER_TYPE));
3362
3363 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3364
3365 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003366
3367 // The WebGL specification leaves the behavior of storing NaN and
3368 // +/-Infinity into integer arrays basically undefined. For more
3369 // reproducible behavior, convert these to zero.
3370
3371 if (CpuFeatures::IsSupported(FPU)) {
ulan@chromium.org750145a2013-03-07 15:14:13 +00003372 CpuFeatureScope scope(masm, FPU);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003373
3374 __ ldc1(f0, FieldMemOperand(a0, HeapNumber::kValueOffset));
3375
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003376 if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003377 __ cvt_s_d(f0, f0);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003378 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003379 __ addu(t8, a3, t8);
3380 __ swc1(f0, MemOperand(t8, 0));
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003381 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003382 __ sll(t8, key, 2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003383 __ addu(t8, a3, t8);
3384 __ sdc1(f0, MemOperand(t8, 0));
3385 } else {
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00003386 __ EmitECMATruncate(t3, f0, f2, t2, t1, t5);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003387
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003388 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003389 case EXTERNAL_BYTE_ELEMENTS:
3390 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003391 __ srl(t8, key, 1);
3392 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003393 __ sb(t3, MemOperand(t8, 0));
3394 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003395 case EXTERNAL_SHORT_ELEMENTS:
3396 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003397 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003398 __ sh(t3, MemOperand(t8, 0));
3399 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003400 case EXTERNAL_INT_ELEMENTS:
3401 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003402 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003403 __ addu(t8, a3, t8);
3404 __ sw(t3, MemOperand(t8, 0));
3405 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003406 case EXTERNAL_PIXEL_ELEMENTS:
3407 case EXTERNAL_FLOAT_ELEMENTS:
3408 case EXTERNAL_DOUBLE_ELEMENTS:
3409 case FAST_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003410 case FAST_SMI_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003411 case FAST_DOUBLE_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003412 case FAST_HOLEY_ELEMENTS:
3413 case FAST_HOLEY_SMI_ELEMENTS:
3414 case FAST_HOLEY_DOUBLE_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003415 case DICTIONARY_ELEMENTS:
3416 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003417 UNREACHABLE();
3418 break;
3419 }
3420 }
3421
3422 // Entry registers are intact, a0 holds the value
3423 // which is the return value.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003424 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003425 __ Ret();
3426 } else {
3427 // FPU is not available, do manual conversions.
3428
3429 __ lw(t3, FieldMemOperand(value, HeapNumber::kExponentOffset));
3430 __ lw(t4, FieldMemOperand(value, HeapNumber::kMantissaOffset));
3431
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003432 if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003433 Label done, nan_or_infinity_or_zero;
3434 static const int kMantissaInHiWordShift =
3435 kBinary32MantissaBits - HeapNumber::kMantissaBitsInTopWord;
3436
3437 static const int kMantissaInLoWordShift =
3438 kBitsPerInt - kMantissaInHiWordShift;
3439
3440 // Test for all special exponent values: zeros, subnormal numbers, NaNs
3441 // and infinities. All these should be converted to 0.
3442 __ li(t5, HeapNumber::kExponentMask);
3443 __ and_(t6, t3, t5);
3444 __ Branch(&nan_or_infinity_or_zero, eq, t6, Operand(zero_reg));
3445
3446 __ xor_(t1, t6, t5);
3447 __ li(t2, kBinary32ExponentMask);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00003448 __ Movz(t6, t2, t1); // Only if t6 is equal to t5.
rossberg@chromium.org400388e2012-06-06 09:29:22 +00003449 __ Branch(&nan_or_infinity_or_zero, eq, t1, Operand(zero_reg));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003450
3451 // Rebias exponent.
3452 __ srl(t6, t6, HeapNumber::kExponentShift);
3453 __ Addu(t6,
3454 t6,
3455 Operand(kBinary32ExponentBias - HeapNumber::kExponentBias));
3456
3457 __ li(t1, Operand(kBinary32MaxExponent));
3458 __ Slt(t1, t1, t6);
3459 __ And(t2, t3, Operand(HeapNumber::kSignMask));
3460 __ Or(t2, t2, Operand(kBinary32ExponentMask));
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00003461 __ Movn(t3, t2, t1); // Only if t6 is gt kBinary32MaxExponent.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003462 __ Branch(&done, gt, t6, Operand(kBinary32MaxExponent));
3463
3464 __ Slt(t1, t6, Operand(kBinary32MinExponent));
3465 __ And(t2, t3, Operand(HeapNumber::kSignMask));
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00003466 __ Movn(t3, t2, t1); // Only if t6 is lt kBinary32MinExponent.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003467 __ Branch(&done, lt, t6, Operand(kBinary32MinExponent));
3468
3469 __ And(t7, t3, Operand(HeapNumber::kSignMask));
3470 __ And(t3, t3, Operand(HeapNumber::kMantissaMask));
3471 __ sll(t3, t3, kMantissaInHiWordShift);
3472 __ or_(t7, t7, t3);
3473 __ srl(t4, t4, kMantissaInLoWordShift);
3474 __ or_(t7, t7, t4);
3475 __ sll(t6, t6, kBinary32ExponentShift);
3476 __ or_(t3, t7, t6);
3477
3478 __ bind(&done);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003479 __ sll(t9, key, 1);
rossberg@chromium.org400388e2012-06-06 09:29:22 +00003480 __ addu(t9, a3, t9);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003481 __ sw(t3, MemOperand(t9, 0));
3482
3483 // Entry registers are intact, a0 holds the value which is the return
3484 // value.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003485 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003486 __ Ret();
3487
3488 __ bind(&nan_or_infinity_or_zero);
3489 __ And(t7, t3, Operand(HeapNumber::kSignMask));
3490 __ And(t3, t3, Operand(HeapNumber::kMantissaMask));
3491 __ or_(t6, t6, t7);
3492 __ sll(t3, t3, kMantissaInHiWordShift);
3493 __ or_(t6, t6, t3);
3494 __ srl(t4, t4, kMantissaInLoWordShift);
3495 __ or_(t3, t6, t4);
3496 __ Branch(&done);
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003497 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
rossberg@chromium.org400388e2012-06-06 09:29:22 +00003498 __ sll(t8, key, 2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003499 __ addu(t8, a3, t8);
3500 // t8: effective address of destination element.
3501 __ sw(t4, MemOperand(t8, 0));
3502 __ sw(t3, MemOperand(t8, Register::kSizeInBytes));
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003503 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003504 __ Ret();
3505 } else {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003506 bool is_signed_type = IsElementTypeSigned(elements_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003507 int meaningfull_bits = is_signed_type ? (kBitsPerInt - 1) : kBitsPerInt;
3508 int32_t min_value = is_signed_type ? 0x80000000 : 0x00000000;
3509
3510 Label done, sign;
3511
3512 // Test for all special exponent values: zeros, subnormal numbers, NaNs
3513 // and infinities. All these should be converted to 0.
3514 __ li(t5, HeapNumber::kExponentMask);
3515 __ and_(t6, t3, t5);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00003516 __ Movz(t3, zero_reg, t6); // Only if t6 is equal to zero.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003517 __ Branch(&done, eq, t6, Operand(zero_reg));
3518
3519 __ xor_(t2, t6, t5);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00003520 __ Movz(t3, zero_reg, t2); // Only if t6 is equal to t5.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003521 __ Branch(&done, eq, t6, Operand(t5));
3522
3523 // Unbias exponent.
3524 __ srl(t6, t6, HeapNumber::kExponentShift);
3525 __ Subu(t6, t6, Operand(HeapNumber::kExponentBias));
3526 // If exponent is negative then result is 0.
3527 __ slt(t2, t6, zero_reg);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00003528 __ Movn(t3, zero_reg, t2); // Only if exponent is negative.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003529 __ Branch(&done, lt, t6, Operand(zero_reg));
3530
3531 // If exponent is too big then result is minimal value.
3532 __ slti(t1, t6, meaningfull_bits - 1);
3533 __ li(t2, min_value);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00003534 __ Movz(t3, t2, t1); // Only if t6 is ge meaningfull_bits - 1.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003535 __ Branch(&done, ge, t6, Operand(meaningfull_bits - 1));
3536
3537 __ And(t5, t3, Operand(HeapNumber::kSignMask));
3538 __ And(t3, t3, Operand(HeapNumber::kMantissaMask));
3539 __ Or(t3, t3, Operand(1u << HeapNumber::kMantissaBitsInTopWord));
3540
3541 __ li(t9, HeapNumber::kMantissaBitsInTopWord);
3542 __ subu(t6, t9, t6);
3543 __ slt(t1, t6, zero_reg);
3544 __ srlv(t2, t3, t6);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00003545 __ Movz(t3, t2, t1); // Only if t6 is positive.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003546 __ Branch(&sign, ge, t6, Operand(zero_reg));
3547
3548 __ subu(t6, zero_reg, t6);
3549 __ sllv(t3, t3, t6);
3550 __ li(t9, meaningfull_bits);
3551 __ subu(t6, t9, t6);
3552 __ srlv(t4, t4, t6);
3553 __ or_(t3, t3, t4);
3554
3555 __ bind(&sign);
3556 __ subu(t2, t3, zero_reg);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00003557 __ Movz(t3, t2, t5); // Only if t5 is zero.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003558
3559 __ bind(&done);
3560
3561 // Result is in t3.
3562 // This switch block should be exactly the same as above (FPU mode).
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003563 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003564 case EXTERNAL_BYTE_ELEMENTS:
3565 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003566 __ srl(t8, key, 1);
3567 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003568 __ sb(t3, MemOperand(t8, 0));
3569 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003570 case EXTERNAL_SHORT_ELEMENTS:
3571 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003572 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003573 __ sh(t3, MemOperand(t8, 0));
3574 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003575 case EXTERNAL_INT_ELEMENTS:
3576 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003577 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003578 __ addu(t8, a3, t8);
3579 __ sw(t3, MemOperand(t8, 0));
3580 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003581 case EXTERNAL_PIXEL_ELEMENTS:
3582 case EXTERNAL_FLOAT_ELEMENTS:
3583 case EXTERNAL_DOUBLE_ELEMENTS:
3584 case FAST_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003585 case FAST_SMI_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003586 case FAST_DOUBLE_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003587 case FAST_HOLEY_ELEMENTS:
3588 case FAST_HOLEY_SMI_ELEMENTS:
3589 case FAST_HOLEY_DOUBLE_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003590 case DICTIONARY_ELEMENTS:
3591 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003592 UNREACHABLE();
3593 break;
3594 }
3595 }
3596 }
3597 }
3598
danno@chromium.org40cb8782011-05-25 07:58:50 +00003599 // Slow case, key and receiver still in a0 and a1.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003600 __ bind(&slow);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003601 __ IncrementCounter(
3602 masm->isolate()->counters()->keyed_load_external_array_slow(),
3603 1, a2, a3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003604 // Entry registers are intact.
3605 // ---------- S t a t e --------------
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003606 // -- ra : return address
danno@chromium.org40cb8782011-05-25 07:58:50 +00003607 // -- a0 : key
3608 // -- a1 : receiver
3609 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003610 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003611
3612 // Miss case, call the runtime.
3613 __ bind(&miss_force_generic);
3614
3615 // ---------- S t a t e --------------
3616 // -- ra : return address
3617 // -- a0 : key
3618 // -- a1 : receiver
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003619 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003620 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003621}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003622
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003623
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003624void KeyedStoreStubCompiler::GenerateStoreFastElement(
3625 MacroAssembler* masm,
3626 bool is_js_array,
yangguo@chromium.org56454712012-02-16 15:33:53 +00003627 ElementsKind elements_kind,
ulan@chromium.org750145a2013-03-07 15:14:13 +00003628 KeyedAccessStoreMode store_mode) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003629 // ----------- S t a t e -------------
3630 // -- a0 : value
3631 // -- a1 : key
3632 // -- a2 : receiver
3633 // -- ra : return address
3634 // -- a3 : scratch
3635 // -- a4 : scratch (elements)
3636 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00003637 Label miss_force_generic, transition_elements_kind, grow, slow;
3638 Label finish_store, check_capacity;
danno@chromium.org40cb8782011-05-25 07:58:50 +00003639
3640 Register value_reg = a0;
3641 Register key_reg = a1;
3642 Register receiver_reg = a2;
yangguo@chromium.org56454712012-02-16 15:33:53 +00003643 Register scratch = t0;
3644 Register elements_reg = a3;
3645 Register length_reg = t1;
3646 Register scratch2 = t2;
danno@chromium.org40cb8782011-05-25 07:58:50 +00003647
3648 // This stub is meant to be tail-jumped to, the receiver must already
3649 // have been verified by the caller to not be a smi.
3650
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003651 // Check that the key is a smi or a heap number convertible to a smi.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003652 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, f4, &miss_force_generic);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003653
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003654 if (IsFastSmiElementsKind(elements_kind)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003655 __ JumpIfNotSmi(value_reg, &transition_elements_kind);
3656 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003657
3658 // Check that the key is within bounds.
yangguo@chromium.org56454712012-02-16 15:33:53 +00003659 __ lw(elements_reg,
3660 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003661 if (is_js_array) {
3662 __ lw(scratch, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3663 } else {
3664 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3665 }
3666 // Compare smis.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003667 if (is_js_array && IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003668 __ Branch(&grow, hs, key_reg, Operand(scratch));
3669 } else {
3670 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch));
3671 }
3672
3673 // Make sure elements is a fast element array, not 'cow'.
3674 __ CheckMap(elements_reg,
3675 scratch,
3676 Heap::kFixedArrayMapRootIndex,
3677 &miss_force_generic,
3678 DONT_DO_SMI_CHECK);
3679
3680 __ bind(&finish_store);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003681
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003682 if (IsFastSmiElementsKind(elements_kind)) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003683 __ Addu(scratch,
3684 elements_reg,
3685 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3686 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
3687 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
3688 __ Addu(scratch, scratch, scratch2);
3689 __ sw(value_reg, MemOperand(scratch));
3690 } else {
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003691 ASSERT(IsFastObjectElementsKind(elements_kind));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003692 __ Addu(scratch,
3693 elements_reg,
3694 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3695 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
3696 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
3697 __ Addu(scratch, scratch, scratch2);
3698 __ sw(value_reg, MemOperand(scratch));
3699 __ mov(receiver_reg, value_reg);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003700 __ RecordWrite(elements_reg, // Object.
3701 scratch, // Address.
3702 receiver_reg, // Value.
3703 kRAHasNotBeenSaved,
3704 kDontSaveFPRegs);
3705 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003706 // value_reg (a0) is preserved.
3707 // Done.
3708 __ Ret();
3709
3710 __ bind(&miss_force_generic);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003711 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003712
3713 __ bind(&transition_elements_kind);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003714 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Miss);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003715
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003716 if (is_js_array && IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003717 // Grow the array by a single element if possible.
3718 __ bind(&grow);
3719
3720 // Make sure the array is only growing by a single element, anything else
3721 // must be handled by the runtime.
3722 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch));
3723
3724 // Check for the empty array, and preallocate a small backing store if
3725 // possible.
3726 __ lw(length_reg,
3727 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3728 __ lw(elements_reg,
3729 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3730 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
3731 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
3732
3733 int size = FixedArray::SizeFor(JSArray::kPreallocatedArrayElements);
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003734 __ Allocate(size, elements_reg, scratch, scratch2, &slow, TAG_OBJECT);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003735
3736 __ LoadRoot(scratch, Heap::kFixedArrayMapRootIndex);
3737 __ sw(scratch, FieldMemOperand(elements_reg, JSObject::kMapOffset));
3738 __ li(scratch, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
3739 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3740 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
3741 for (int i = 1; i < JSArray::kPreallocatedArrayElements; ++i) {
3742 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::SizeFor(i)));
3743 }
3744
3745 // Store the element at index zero.
3746 __ sw(value_reg, FieldMemOperand(elements_reg, FixedArray::SizeFor(0)));
3747
3748 // Install the new backing store in the JSArray.
3749 __ sw(elements_reg,
3750 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3751 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
3752 scratch, kRAHasNotBeenSaved, kDontSaveFPRegs,
3753 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
3754
3755 // Increment the length of the array.
3756 __ li(length_reg, Operand(Smi::FromInt(1)));
3757 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3758 __ Ret();
3759
3760 __ bind(&check_capacity);
3761 // Check for cow elements, in general they are not handled by this stub
3762 __ CheckMap(elements_reg,
3763 scratch,
3764 Heap::kFixedCOWArrayMapRootIndex,
3765 &miss_force_generic,
3766 DONT_DO_SMI_CHECK);
3767
3768 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3769 __ Branch(&slow, hs, length_reg, Operand(scratch));
3770
3771 // Grow the array and finish the store.
3772 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
3773 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3774 __ jmp(&finish_store);
3775
3776 __ bind(&slow);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003777 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003778 }
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00003779}
3780
3781
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00003782void KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(
3783 MacroAssembler* masm,
yangguo@chromium.org56454712012-02-16 15:33:53 +00003784 bool is_js_array,
ulan@chromium.org750145a2013-03-07 15:14:13 +00003785 KeyedAccessStoreMode store_mode) {
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003786 // ----------- S t a t e -------------
3787 // -- a0 : value
3788 // -- a1 : key
3789 // -- a2 : receiver
3790 // -- ra : return address
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003791 // -- a3 : scratch (elements backing store)
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003792 // -- t0 : scratch (elements_reg)
3793 // -- t1 : scratch (mantissa_reg)
3794 // -- t2 : scratch (exponent_reg)
3795 // -- t3 : scratch4
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003796 // -- t4 : scratch
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003797 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00003798 Label miss_force_generic, transition_elements_kind, grow, slow;
3799 Label finish_store, check_capacity;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003800
3801 Register value_reg = a0;
3802 Register key_reg = a1;
3803 Register receiver_reg = a2;
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003804 Register elements_reg = a3;
3805 Register scratch1 = t0;
3806 Register scratch2 = t1;
3807 Register scratch3 = t2;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003808 Register scratch4 = t3;
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003809 Register scratch5 = t4;
yangguo@chromium.org56454712012-02-16 15:33:53 +00003810 Register length_reg = t3;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003811
3812 // This stub is meant to be tail-jumped to, the receiver must already
3813 // have been verified by the caller to not be a smi.
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003814
3815 // Check that the key is a smi or a heap number convertible to a smi.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003816 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, f4, &miss_force_generic);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003817
3818 __ lw(elements_reg,
3819 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3820
3821 // Check that the key is within bounds.
3822 if (is_js_array) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003823 __ lw(scratch1, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003824 } else {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003825 __ lw(scratch1,
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003826 FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3827 }
3828 // Compare smis, unsigned compare catches both negative and out-of-bound
3829 // indexes.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003830 if (IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003831 __ Branch(&grow, hs, key_reg, Operand(scratch1));
3832 } else {
3833 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch1));
3834 }
3835
3836 __ bind(&finish_store);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003837
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003838 __ StoreNumberToDoubleElements(value_reg,
3839 key_reg,
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00003840 // All registers after this are overwritten.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003841 elements_reg,
3842 scratch1,
3843 scratch2,
3844 scratch3,
3845 scratch4,
3846 &transition_elements_kind);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003847
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00003848 __ Ret(USE_DELAY_SLOT);
3849 __ mov(v0, value_reg); // In delay slot.
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003850
3851 // Handle store cache miss, replacing the ic with the generic stub.
3852 __ bind(&miss_force_generic);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003853 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003854
3855 __ bind(&transition_elements_kind);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003856 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Miss);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003857
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003858 if (is_js_array && IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003859 // Grow the array by a single element if possible.
3860 __ bind(&grow);
3861
3862 // Make sure the array is only growing by a single element, anything else
3863 // must be handled by the runtime.
3864 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch1));
3865
3866 // Transition on values that can't be stored in a FixedDoubleArray.
3867 Label value_is_smi;
3868 __ JumpIfSmi(value_reg, &value_is_smi);
3869 __ lw(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
3870 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex);
3871 __ Branch(&transition_elements_kind, ne, scratch1, Operand(at));
3872 __ bind(&value_is_smi);
3873
3874 // Check for the empty array, and preallocate a small backing store if
3875 // possible.
3876 __ lw(length_reg,
3877 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3878 __ lw(elements_reg,
3879 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3880 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
3881 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
3882
3883 int size = FixedDoubleArray::SizeFor(JSArray::kPreallocatedArrayElements);
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003884 __ Allocate(size, elements_reg, scratch1, scratch2, &slow, TAG_OBJECT);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003885
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003886 // Initialize the new FixedDoubleArray.
yangguo@chromium.org56454712012-02-16 15:33:53 +00003887 __ LoadRoot(scratch1, Heap::kFixedDoubleArrayMapRootIndex);
3888 __ sw(scratch1, FieldMemOperand(elements_reg, JSObject::kMapOffset));
3889 __ li(scratch1, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
3890 __ sw(scratch1,
3891 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
3892
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003893 __ mov(scratch1, elements_reg);
3894 __ StoreNumberToDoubleElements(value_reg,
3895 key_reg,
3896 // All registers after this are overwritten.
3897 scratch1,
3898 scratch2,
3899 scratch3,
3900 scratch4,
3901 scratch5,
3902 &transition_elements_kind);
3903
3904 __ li(scratch1, Operand(kHoleNanLower32));
3905 __ li(scratch2, Operand(kHoleNanUpper32));
3906 for (int i = 1; i < JSArray::kPreallocatedArrayElements; i++) {
3907 int offset = FixedDoubleArray::OffsetOfElementAt(i);
3908 __ sw(scratch1, FieldMemOperand(elements_reg, offset));
3909 __ sw(scratch2, FieldMemOperand(elements_reg, offset + kPointerSize));
3910 }
3911
yangguo@chromium.org56454712012-02-16 15:33:53 +00003912 // Install the new backing store in the JSArray.
3913 __ sw(elements_reg,
3914 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3915 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
3916 scratch1, kRAHasNotBeenSaved, kDontSaveFPRegs,
3917 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
3918
3919 // Increment the length of the array.
3920 __ li(length_reg, Operand(Smi::FromInt(1)));
3921 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
danno@chromium.org00379b82012-05-04 09:16:29 +00003922 __ lw(elements_reg,
3923 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003924 __ Ret();
yangguo@chromium.org56454712012-02-16 15:33:53 +00003925
3926 __ bind(&check_capacity);
3927 // Make sure that the backing store can hold additional elements.
3928 __ lw(scratch1,
3929 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
3930 __ Branch(&slow, hs, length_reg, Operand(scratch1));
3931
3932 // Grow the array and finish the store.
3933 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
3934 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3935 __ jmp(&finish_store);
3936
3937 __ bind(&slow);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003938 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003939 }
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00003940}
3941
3942
ager@chromium.org5c838252010-02-19 08:53:10 +00003943#undef __
3944
3945} } // namespace v8::internal
3946
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00003947#endif // V8_TARGET_ARCH_MIPS