blob: 967ce4a605b43ae6fff48cc923b4606d41a5f8fa [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.
124// Name must be a symbol 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,
128 Handle<String> name,
129 Register scratch0,
130 Register scratch1) {
131 ASSERT(name->IsSymbol());
132 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
165 StringDictionaryLookupStub::GenerateNegativeLookup(masm,
166 miss_label,
167 &done,
168 receiver,
169 properties,
170 name,
171 scratch1);
172 __ 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.
220 __ lw(scratch, FieldMemOperand(name, String::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.
273 __ lw(prototype, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX)));
274 // Load the global context from the global or builtins object.
275 __ lw(prototype,
276 FieldMemOperand(prototype, GlobalObject::kGlobalContextOffset));
277 // Load the function from the global context.
278 __ lw(prototype, MemOperand(prototype, Context::SlotOffset(index)));
279 // Load the initial map. The global functions all have initial maps.
280 __ lw(prototype,
281 FieldMemOperand(prototype, JSFunction::kPrototypeOrInitialMapOffset));
282 // Load the prototype from the initial map.
283 __ lw(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
ager@chromium.org5c838252010-02-19 08:53:10 +0000284}
285
286
lrn@chromium.org7516f052011-03-30 08:52:27 +0000287void StubCompiler::GenerateDirectLoadGlobalFunctionPrototype(
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000288 MacroAssembler* masm,
289 int index,
290 Register prototype,
291 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000292 Isolate* isolate = masm->isolate();
293 // Check we're still in the same context.
294 __ lw(prototype, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX)));
295 ASSERT(!prototype.is(at));
296 __ li(at, isolate->global());
297 __ Branch(miss, ne, prototype, Operand(at));
298 // Get the global function with the given index.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000299 Handle<JSFunction> function(
300 JSFunction::cast(isolate->global_context()->get(index)));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000301 // Load its initial map. The global functions all have initial maps.
302 __ li(prototype, Handle<Map>(function->initial_map()));
303 // Load the prototype from the initial map.
304 __ lw(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
lrn@chromium.org7516f052011-03-30 08:52:27 +0000305}
306
307
ager@chromium.org5c838252010-02-19 08:53:10 +0000308// Load a fast property out of a holder object (src). In-object properties
309// are loaded directly otherwise the property is loaded from the properties
310// fixed array.
311void StubCompiler::GenerateFastPropertyLoad(MacroAssembler* masm,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000312 Register dst,
313 Register src,
314 Handle<JSObject> holder,
315 int index) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000316 // Adjust for the number of properties stored in the holder.
317 index -= holder->map()->inobject_properties();
318 if (index < 0) {
319 // Get the property straight out of the holder.
320 int offset = holder->map()->instance_size() + (index * kPointerSize);
321 __ lw(dst, FieldMemOperand(src, offset));
322 } else {
323 // Calculate the offset into the properties array.
324 int offset = index * kPointerSize + FixedArray::kHeaderSize;
325 __ lw(dst, FieldMemOperand(src, JSObject::kPropertiesOffset));
326 __ lw(dst, FieldMemOperand(dst, offset));
327 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000328}
329
330
331void StubCompiler::GenerateLoadArrayLength(MacroAssembler* masm,
332 Register receiver,
333 Register scratch,
334 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000335 // Check that the receiver isn't a smi.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000336 __ JumpIfSmi(receiver, miss_label);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000337
338 // Check that the object is a JS array.
339 __ GetObjectType(receiver, scratch, scratch);
340 __ Branch(miss_label, ne, scratch, Operand(JS_ARRAY_TYPE));
341
342 // Load length directly from the JS array.
343 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
344 __ Ret();
345}
346
347
348// Generate code to check if an object is a string. If the object is a
349// heap object, its map's instance type is left in the scratch1 register.
350// If this is not needed, scratch1 and scratch2 may be the same register.
351static void GenerateStringCheck(MacroAssembler* masm,
352 Register receiver,
353 Register scratch1,
354 Register scratch2,
355 Label* smi,
356 Label* non_string_object) {
357 // Check that the receiver isn't a smi.
358 __ JumpIfSmi(receiver, smi, t0);
359
360 // Check that the object is a string.
361 __ lw(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset));
362 __ lbu(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
363 __ And(scratch2, scratch1, Operand(kIsNotStringMask));
364 // The cast is to resolve the overload for the argument of 0x0.
365 __ Branch(non_string_object,
366 ne,
367 scratch2,
368 Operand(static_cast<int32_t>(kStringTag)));
ager@chromium.org5c838252010-02-19 08:53:10 +0000369}
370
371
lrn@chromium.org7516f052011-03-30 08:52:27 +0000372// Generate code to load the length from a string object and return the length.
373// If the receiver object is not a string or a wrapped string object the
374// execution continues at the miss label. The register containing the
375// receiver is potentially clobbered.
376void StubCompiler::GenerateLoadStringLength(MacroAssembler* masm,
377 Register receiver,
378 Register scratch1,
379 Register scratch2,
380 Label* miss,
381 bool support_wrappers) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000382 Label check_wrapper;
383
384 // Check if the object is a string leaving the instance type in the
385 // scratch1 register.
386 GenerateStringCheck(masm, receiver, scratch1, scratch2, miss,
387 support_wrappers ? &check_wrapper : miss);
388
389 // Load length directly from the string.
390 __ lw(v0, FieldMemOperand(receiver, String::kLengthOffset));
391 __ Ret();
392
393 if (support_wrappers) {
394 // Check if the object is a JSValue wrapper.
395 __ bind(&check_wrapper);
396 __ Branch(miss, ne, scratch1, Operand(JS_VALUE_TYPE));
397
398 // Unwrap the value and check if the wrapped value is a string.
399 __ lw(scratch1, FieldMemOperand(receiver, JSValue::kValueOffset));
400 GenerateStringCheck(masm, scratch1, scratch2, scratch2, miss, miss);
401 __ lw(v0, FieldMemOperand(scratch1, String::kLengthOffset));
402 __ Ret();
403 }
lrn@chromium.org7516f052011-03-30 08:52:27 +0000404}
405
406
ager@chromium.org5c838252010-02-19 08:53:10 +0000407void StubCompiler::GenerateLoadFunctionPrototype(MacroAssembler* masm,
408 Register receiver,
409 Register scratch1,
410 Register scratch2,
411 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000412 __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
413 __ mov(v0, scratch1);
414 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +0000415}
416
417
lrn@chromium.org7516f052011-03-30 08:52:27 +0000418// Generate StoreField code, value is passed in a0 register.
ager@chromium.org5c838252010-02-19 08:53:10 +0000419// After executing generated code, the receiver_reg and name_reg
420// may be clobbered.
421void StubCompiler::GenerateStoreField(MacroAssembler* masm,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000422 Handle<JSObject> object,
ager@chromium.org5c838252010-02-19 08:53:10 +0000423 int index,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000424 Handle<Map> transition,
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000425 Handle<String> name,
ager@chromium.org5c838252010-02-19 08:53:10 +0000426 Register receiver_reg,
427 Register name_reg,
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000428 Register scratch1,
429 Register scratch2,
ager@chromium.org5c838252010-02-19 08:53:10 +0000430 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000431 // a0 : value.
432 Label exit;
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000433
434 LookupResult lookup(masm->isolate());
435 object->Lookup(*name, &lookup);
436 if (lookup.IsFound() && (lookup.IsReadOnly() || !lookup.IsCacheable())) {
437 // In sloppy mode, we could just return the value and be done. However, we
438 // might be in strict mode, where we have to throw. Since we cannot tell,
439 // go into slow case unconditionally.
440 __ jmp(miss_label);
441 return;
442 }
443
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +0000444 // Check that the map of the object hasn't changed.
jkummerow@chromium.org28faa982012-04-13 09:58:30 +0000445 CompareMapMode mode = transition.is_null() ? ALLOW_ELEMENT_TRANSITION_MAPS
446 : REQUIRE_EXACT_MAP;
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000447 __ CheckMap(receiver_reg, scratch1, Handle<Map>(object->map()), miss_label,
jkummerow@chromium.org28faa982012-04-13 09:58:30 +0000448 DO_SMI_CHECK, mode);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000449
450 // Perform global security token check if needed.
451 if (object->IsJSGlobalProxy()) {
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000452 __ CheckAccessGlobalProxy(receiver_reg, scratch1, miss_label);
453 }
454
455 // Check that we are allowed to write this.
456 if (!transition.is_null() && object->GetPrototype()->IsJSObject()) {
457 JSObject* holder;
458 if (lookup.IsFound()) {
459 holder = lookup.holder();
460 } else {
461 // Find the top object.
462 holder = *object;
463 do {
464 holder = JSObject::cast(holder->GetPrototype());
465 } while (holder->GetPrototype()->IsJSObject());
466 }
467 // We need an extra register, push
468 __ push(name_reg);
469 Label miss_pop, done_check;
470 CheckPrototypes(object, receiver_reg, Handle<JSObject>(holder), name_reg,
471 scratch1, scratch2, name, &miss_pop);
472 __ jmp(&done_check);
473 __ bind(&miss_pop);
474 __ pop(name_reg);
475 __ jmp(miss_label);
476 __ bind(&done_check);
477 __ pop(name_reg);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000478 }
479
480 // Stub never generated for non-global objects that require access
481 // checks.
482 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
483
484 // Perform map transition for the receiver if necessary.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000485 if (!transition.is_null() && (object->map()->unused_property_fields() == 0)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000486 // The properties must be extended before we can store the value.
487 // We jump to a runtime call that extends the properties array.
488 __ push(receiver_reg);
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000489 __ li(a2, Operand(transition));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000490 __ Push(a2, a0);
491 __ TailCallExternalReference(
492 ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
493 masm->isolate()),
494 3, 1);
495 return;
496 }
497
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000498 if (!transition.is_null()) {
verwaest@chromium.org37141392012-05-31 13:27:02 +0000499 // Update the map of the object.
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000500 __ li(scratch1, Operand(transition));
501 __ sw(scratch1, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
verwaest@chromium.org37141392012-05-31 13:27:02 +0000502
503 // Update the write barrier for the map field and pass the now unused
504 // name_reg as scratch register.
505 __ RecordWriteField(receiver_reg,
506 HeapObject::kMapOffset,
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000507 scratch1,
verwaest@chromium.org37141392012-05-31 13:27:02 +0000508 name_reg,
509 kRAHasNotBeenSaved,
510 kDontSaveFPRegs,
511 OMIT_REMEMBERED_SET,
512 OMIT_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000513 }
514
515 // Adjust for the number of properties stored in the object. Even in the
516 // face of a transition we can use the old map here because the size of the
517 // object and the number of in-object properties is not going to change.
518 index -= object->map()->inobject_properties();
519
520 if (index < 0) {
521 // Set the property straight into the object.
522 int offset = object->map()->instance_size() + (index * kPointerSize);
523 __ sw(a0, FieldMemOperand(receiver_reg, offset));
524
525 // Skip updating write barrier if storing a smi.
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000526 __ JumpIfSmi(a0, &exit, scratch1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000527
528 // Update the write barrier for the array address.
529 // Pass the now unused name_reg as a scratch register.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000530 __ mov(name_reg, a0);
531 __ RecordWriteField(receiver_reg,
532 offset,
533 name_reg,
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000534 scratch1,
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000535 kRAHasNotBeenSaved,
536 kDontSaveFPRegs);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000537 } else {
538 // Write to the properties array.
539 int offset = index * kPointerSize + FixedArray::kHeaderSize;
540 // Get the properties array.
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000541 __ lw(scratch1,
542 FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
543 __ sw(a0, FieldMemOperand(scratch1, offset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000544
545 // Skip updating write barrier if storing a smi.
546 __ JumpIfSmi(a0, &exit);
547
548 // Update the write barrier for the array address.
549 // Ok to clobber receiver_reg and name_reg, since we return.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000550 __ mov(name_reg, a0);
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000551 __ RecordWriteField(scratch1,
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000552 offset,
553 name_reg,
554 receiver_reg,
555 kRAHasNotBeenSaved,
556 kDontSaveFPRegs);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000557 }
558
559 // Return the value (register v0).
560 __ bind(&exit);
561 __ mov(v0, a0);
562 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +0000563}
564
565
566void StubCompiler::GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000567 ASSERT(kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000568 Handle<Code> code = (kind == Code::LOAD_IC)
569 ? masm->isolate()->builtins()->LoadIC_Miss()
570 : masm->isolate()->builtins()->KeyedLoadIC_Miss();
571 __ Jump(code, RelocInfo::CODE_TARGET);
ager@chromium.org5c838252010-02-19 08:53:10 +0000572}
573
574
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000575static void GenerateCallFunction(MacroAssembler* masm,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000576 Handle<Object> object,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000577 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000578 Label* miss,
579 Code::ExtraICState extra_ic_state) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000580 // ----------- S t a t e -------------
581 // -- a0: receiver
582 // -- a1: function to call
583 // -----------------------------------
584 // Check that the function really is a function.
585 __ JumpIfSmi(a1, miss);
586 __ GetObjectType(a1, a3, a3);
587 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
588
589 // Patch the receiver on the stack with the global proxy if
590 // necessary.
591 if (object->IsGlobalObject()) {
592 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
593 __ sw(a3, MemOperand(sp, arguments.immediate() * kPointerSize));
594 }
595
596 // Invoke the function.
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000597 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state)
598 ? CALL_AS_FUNCTION
599 : CALL_AS_METHOD;
600 __ InvokeFunction(a1, arguments, JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000601}
602
603
604static void PushInterceptorArguments(MacroAssembler* masm,
605 Register receiver,
606 Register holder,
607 Register name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000608 Handle<JSObject> holder_obj) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000609 __ push(name);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000610 Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
611 ASSERT(!masm->isolate()->heap()->InNewSpace(*interceptor));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000612 Register scratch = name;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000613 __ li(scratch, Operand(interceptor));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000614 __ Push(scratch, receiver, holder);
615 __ lw(scratch, FieldMemOperand(scratch, InterceptorInfo::kDataOffset));
616 __ push(scratch);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000617 __ li(scratch, Operand(ExternalReference::isolate_address()));
618 __ push(scratch);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000619}
620
621
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000622static void CompileCallLoadPropertyWithInterceptor(
623 MacroAssembler* masm,
624 Register receiver,
625 Register holder,
626 Register name,
627 Handle<JSObject> holder_obj) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000628 PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
629
630 ExternalReference ref =
631 ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorOnly),
632 masm->isolate());
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000633 __ PrepareCEntryArgs(6);
ulan@chromium.org6ff65142012-03-21 09:52:17 +0000634 __ PrepareCEntryFunction(ref);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000635
636 CEntryStub stub(1);
637 __ CallStub(&stub);
638}
639
640
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000641static const int kFastApiCallArguments = 4;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000642
643
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000644// Reserves space for the extra arguments to API function in the
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000645// caller's frame.
646//
647// These arguments are set by CheckPrototypes and GenerateFastApiDirectCall.
648static void ReserveSpaceForFastApiCall(MacroAssembler* masm,
649 Register scratch) {
650 ASSERT(Smi::FromInt(0) == 0);
651 for (int i = 0; i < kFastApiCallArguments; i++) {
652 __ push(zero_reg);
653 }
654}
655
656
657// Undoes the effects of ReserveSpaceForFastApiCall.
658static void FreeSpaceForFastApiCall(MacroAssembler* masm) {
659 __ Drop(kFastApiCallArguments);
660}
661
662
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000663static void GenerateFastApiDirectCall(MacroAssembler* masm,
664 const CallOptimization& optimization,
665 int argc) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000666 // ----------- S t a t e -------------
667 // -- sp[0] : holder (set by CheckPrototypes)
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000668 // -- sp[4] : callee JS function
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000669 // -- sp[8] : call data
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000670 // -- sp[12] : isolate
671 // -- sp[16] : last JS argument
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000672 // -- ...
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000673 // -- sp[(argc + 3) * 4] : first JS argument
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000674 // -- sp[(argc + 4) * 4] : receiver
675 // -----------------------------------
676 // Get the function and setup the context.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000677 Handle<JSFunction> function = optimization.constant_function();
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000678 __ LoadHeapObject(t1, function);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000679 __ lw(cp, FieldMemOperand(t1, JSFunction::kContextOffset));
680
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000681 // Pass the additional arguments.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000682 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
683 Handle<Object> call_data(api_call_info->data());
684 if (masm->isolate()->heap()->InNewSpace(*call_data)) {
685 __ li(a0, api_call_info);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000686 __ lw(t2, FieldMemOperand(a0, CallHandlerInfo::kDataOffset));
687 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000688 __ li(t2, call_data);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000689 }
690
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000691 __ li(t3, Operand(ExternalReference::isolate_address()));
692 // Store JS function, call data and isolate.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000693 __ sw(t1, MemOperand(sp, 1 * kPointerSize));
694 __ sw(t2, MemOperand(sp, 2 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000695 __ sw(t3, MemOperand(sp, 3 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000696
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000697 // Prepare arguments.
698 __ Addu(a2, sp, Operand(3 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000699
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000700 // Allocate the v8::Arguments structure in the arguments' space since
701 // it's not controlled by GC.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000702 const int kApiStackSpace = 4;
703
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000704 FrameScope frame_scope(masm, StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000705 __ EnterExitFrame(false, kApiStackSpace);
706
707 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
708 // struct from the function (which is currently the case). This means we pass
709 // the first argument in a1 instead of a0. TryCallApiFunctionAndReturn
710 // will handle setting up a0.
711
712 // a1 = v8::Arguments&
713 // Arguments is built at sp + 1 (sp is a reserved spot for ra).
714 __ Addu(a1, sp, kPointerSize);
715
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000716 // v8::Arguments::implicit_args_
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000717 __ sw(a2, MemOperand(a1, 0 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000718 // v8::Arguments::values_
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000719 __ Addu(t0, a2, Operand(argc * kPointerSize));
720 __ sw(t0, MemOperand(a1, 1 * kPointerSize));
721 // v8::Arguments::length_ = argc
722 __ li(t0, Operand(argc));
723 __ sw(t0, MemOperand(a1, 2 * kPointerSize));
724 // v8::Arguments::is_construct_call = 0
725 __ sw(zero_reg, MemOperand(a1, 3 * kPointerSize));
726
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000727 const int kStackUnwindSpace = argc + kFastApiCallArguments + 1;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000728 Address function_address = v8::ToCData<Address>(api_call_info->callback());
729 ApiFunction fun(function_address);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000730 ExternalReference ref =
731 ExternalReference(&fun,
732 ExternalReference::DIRECT_API_CALL,
733 masm->isolate());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000734 AllowExternalCallThatCantCauseGC scope(masm);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000735 __ CallApiFunctionAndReturn(ref, kStackUnwindSpace);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000736}
737
lrn@chromium.org7516f052011-03-30 08:52:27 +0000738class CallInterceptorCompiler BASE_EMBEDDED {
739 public:
740 CallInterceptorCompiler(StubCompiler* stub_compiler,
741 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000742 Register name,
743 Code::ExtraICState extra_ic_state)
lrn@chromium.org7516f052011-03-30 08:52:27 +0000744 : stub_compiler_(stub_compiler),
745 arguments_(arguments),
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000746 name_(name),
747 extra_ic_state_(extra_ic_state) {}
lrn@chromium.org7516f052011-03-30 08:52:27 +0000748
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000749 void Compile(MacroAssembler* masm,
750 Handle<JSObject> object,
751 Handle<JSObject> holder,
752 Handle<String> name,
753 LookupResult* lookup,
754 Register receiver,
755 Register scratch1,
756 Register scratch2,
757 Register scratch3,
758 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000759 ASSERT(holder->HasNamedInterceptor());
760 ASSERT(!holder->GetNamedInterceptor()->getter()->IsUndefined());
761
762 // Check that the receiver isn't a smi.
763 __ JumpIfSmi(receiver, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000764 CallOptimization optimization(lookup);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000765 if (optimization.is_constant_call()) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000766 CompileCacheable(masm, object, receiver, scratch1, scratch2, scratch3,
767 holder, lookup, name, optimization, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000768 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000769 CompileRegular(masm, object, receiver, scratch1, scratch2, scratch3,
770 name, holder, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000771 }
772 }
773
774 private:
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000775 void CompileCacheable(MacroAssembler* masm,
776 Handle<JSObject> object,
777 Register receiver,
778 Register scratch1,
779 Register scratch2,
780 Register scratch3,
781 Handle<JSObject> interceptor_holder,
782 LookupResult* lookup,
783 Handle<String> name,
784 const CallOptimization& optimization,
785 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000786 ASSERT(optimization.is_constant_call());
787 ASSERT(!lookup->holder()->IsGlobalObject());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000788 Counters* counters = masm->isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000789 int depth1 = kInvalidProtoDepth;
790 int depth2 = kInvalidProtoDepth;
791 bool can_do_fast_api_call = false;
792 if (optimization.is_simple_api_call() &&
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000793 !lookup->holder()->IsGlobalObject()) {
794 depth1 = optimization.GetPrototypeDepthOfExpectedType(
795 object, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000796 if (depth1 == kInvalidProtoDepth) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000797 depth2 = optimization.GetPrototypeDepthOfExpectedType(
798 interceptor_holder, Handle<JSObject>(lookup->holder()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000799 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000800 can_do_fast_api_call =
801 depth1 != kInvalidProtoDepth || depth2 != kInvalidProtoDepth;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000802 }
803
804 __ IncrementCounter(counters->call_const_interceptor(), 1,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000805 scratch1, scratch2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000806
807 if (can_do_fast_api_call) {
808 __ IncrementCounter(counters->call_const_interceptor_fast_api(), 1,
809 scratch1, scratch2);
810 ReserveSpaceForFastApiCall(masm, scratch1);
811 }
812
813 // Check that the maps from receiver to interceptor's holder
814 // haven't changed and thus we can invoke interceptor.
815 Label miss_cleanup;
816 Label* miss = can_do_fast_api_call ? &miss_cleanup : miss_label;
817 Register holder =
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000818 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
819 scratch1, scratch2, scratch3,
820 name, depth1, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000821
822 // Invoke an interceptor and if it provides a value,
823 // branch to |regular_invoke|.
824 Label regular_invoke;
825 LoadWithInterceptor(masm, receiver, holder, interceptor_holder, scratch2,
826 &regular_invoke);
827
828 // Interceptor returned nothing for this property. Try to use cached
829 // constant function.
830
831 // Check that the maps from interceptor's holder to constant function's
832 // holder haven't changed and thus we can use cached constant function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000833 if (*interceptor_holder != lookup->holder()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000834 stub_compiler_->CheckPrototypes(interceptor_holder, receiver,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000835 Handle<JSObject>(lookup->holder()),
836 scratch1, scratch2, scratch3,
837 name, depth2, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000838 } else {
839 // CheckPrototypes has a side effect of fetching a 'holder'
840 // for API (object which is instanceof for the signature). It's
841 // safe to omit it here, as if present, it should be fetched
842 // by the previous CheckPrototypes.
843 ASSERT(depth2 == kInvalidProtoDepth);
844 }
845
846 // Invoke function.
847 if (can_do_fast_api_call) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000848 GenerateFastApiDirectCall(masm, optimization, arguments_.immediate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000849 } else {
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000850 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state_)
851 ? CALL_AS_FUNCTION
852 : CALL_AS_METHOD;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000853 __ InvokeFunction(optimization.constant_function(), arguments_,
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +0000854 JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000855 }
856
857 // Deferred code for fast API call case---clean preallocated space.
858 if (can_do_fast_api_call) {
859 __ bind(&miss_cleanup);
860 FreeSpaceForFastApiCall(masm);
861 __ Branch(miss_label);
862 }
863
864 // Invoke a regular function.
865 __ bind(&regular_invoke);
866 if (can_do_fast_api_call) {
867 FreeSpaceForFastApiCall(masm);
868 }
lrn@chromium.org7516f052011-03-30 08:52:27 +0000869 }
870
871 void CompileRegular(MacroAssembler* masm,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000872 Handle<JSObject> object,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000873 Register receiver,
874 Register scratch1,
875 Register scratch2,
876 Register scratch3,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000877 Handle<String> name,
878 Handle<JSObject> interceptor_holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000879 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000880 Register holder =
881 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000882 scratch1, scratch2, scratch3,
883 name, miss_label);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000884
885 // Call a runtime function to load the interceptor property.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000886 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000887 // Save the name_ register across the call.
888 __ push(name_);
889
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000890 PushInterceptorArguments(masm, receiver, holder, name_, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000891
892 __ CallExternalReference(
893 ExternalReference(
894 IC_Utility(IC::kLoadPropertyWithInterceptorForCall),
895 masm->isolate()),
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000896 6);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000897 // Restore the name_ register.
898 __ pop(name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000899 // Leave the internal frame.
lrn@chromium.org7516f052011-03-30 08:52:27 +0000900 }
901
902 void LoadWithInterceptor(MacroAssembler* masm,
903 Register receiver,
904 Register holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000905 Handle<JSObject> holder_obj,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000906 Register scratch,
907 Label* interceptor_succeeded) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000908 {
909 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000910
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000911 __ Push(holder, name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000912 CompileCallLoadPropertyWithInterceptor(masm,
913 receiver,
914 holder,
915 name_,
916 holder_obj);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000917 __ pop(name_); // Restore the name.
918 __ pop(receiver); // Restore the holder.
919 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000920 // If interceptor returns no-result sentinel, call the constant function.
921 __ LoadRoot(scratch, Heap::kNoInterceptorResultSentinelRootIndex);
922 __ Branch(interceptor_succeeded, ne, v0, Operand(scratch));
lrn@chromium.org7516f052011-03-30 08:52:27 +0000923 }
924
925 StubCompiler* stub_compiler_;
926 const ParameterCount& arguments_;
927 Register name_;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000928 Code::ExtraICState extra_ic_state_;
lrn@chromium.org7516f052011-03-30 08:52:27 +0000929};
930
931
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000932
933// Generate code to check that a global property cell is empty. Create
934// the property cell at compilation time if no cell exists for the
935// property.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000936static void GenerateCheckPropertyCell(MacroAssembler* masm,
937 Handle<GlobalObject> global,
938 Handle<String> name,
939 Register scratch,
940 Label* miss) {
941 Handle<JSGlobalPropertyCell> cell =
942 GlobalObject::EnsurePropertyCell(global, name);
943 ASSERT(cell->value()->IsTheHole());
944 __ li(scratch, Operand(cell));
945 __ lw(scratch,
946 FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset));
947 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
948 __ Branch(miss, ne, scratch, Operand(at));
949}
950
951
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000952// Calls GenerateCheckPropertyCell for each global object in the prototype chain
953// from object to (but not including) holder.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000954static void GenerateCheckPropertyCells(MacroAssembler* masm,
955 Handle<JSObject> object,
956 Handle<JSObject> holder,
957 Handle<String> name,
958 Register scratch,
959 Label* miss) {
960 Handle<JSObject> current = object;
961 while (!current.is_identical_to(holder)) {
962 if (current->IsGlobalObject()) {
963 GenerateCheckPropertyCell(masm,
964 Handle<GlobalObject>::cast(current),
965 name,
966 scratch,
967 miss);
968 }
969 current = Handle<JSObject>(JSObject::cast(current->GetPrototype()));
970 }
971}
972
973
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000974// Convert and store int passed in register ival to IEEE 754 single precision
975// floating point value at memory location (dst + 4 * wordoffset)
976// If FPU is available use it for conversion.
977static void StoreIntAsFloat(MacroAssembler* masm,
978 Register dst,
979 Register wordoffset,
980 Register ival,
981 Register fval,
982 Register scratch1,
983 Register scratch2) {
984 if (CpuFeatures::IsSupported(FPU)) {
985 CpuFeatures::Scope scope(FPU);
986 __ mtc1(ival, f0);
987 __ cvt_s_w(f0, f0);
988 __ sll(scratch1, wordoffset, 2);
989 __ addu(scratch1, dst, scratch1);
990 __ swc1(f0, MemOperand(scratch1, 0));
991 } else {
992 // FPU is not available, do manual conversions.
993
994 Label not_special, done;
995 // Move sign bit from source to destination. This works because the sign
996 // bit in the exponent word of the double has the same position and polarity
997 // as the 2's complement sign bit in a Smi.
998 ASSERT(kBinary32SignMask == 0x80000000u);
999
1000 __ And(fval, ival, Operand(kBinary32SignMask));
1001 // Negate value if it is negative.
1002 __ subu(scratch1, zero_reg, ival);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00001003 __ Movn(ival, scratch1, fval);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001004
1005 // We have -1, 0 or 1, which we treat specially. Register ival contains
1006 // absolute value: it is either equal to 1 (special case of -1 and 1),
1007 // greater than 1 (not a special case) or less than 1 (special case of 0).
1008 __ Branch(&not_special, gt, ival, Operand(1));
1009
1010 // For 1 or -1 we need to or in the 0 exponent (biased).
1011 static const uint32_t exponent_word_for_1 =
1012 kBinary32ExponentBias << kBinary32ExponentShift;
1013
1014 __ Xor(scratch1, ival, Operand(1));
1015 __ li(scratch2, exponent_word_for_1);
1016 __ or_(scratch2, fval, scratch2);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00001017 __ Movz(fval, scratch2, scratch1); // Only if ival is equal to 1.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001018 __ Branch(&done);
1019
1020 __ bind(&not_special);
1021 // Count leading zeros.
1022 // Gets the wrong answer for 0, but we already checked for that case above.
1023 Register zeros = scratch2;
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00001024 __ Clz(zeros, ival);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001025
1026 // Compute exponent and or it into the exponent register.
1027 __ li(scratch1, (kBitsPerInt - 1) + kBinary32ExponentBias);
1028 __ subu(scratch1, scratch1, zeros);
1029
1030 __ sll(scratch1, scratch1, kBinary32ExponentShift);
1031 __ or_(fval, fval, scratch1);
1032
1033 // Shift up the source chopping the top bit off.
1034 __ Addu(zeros, zeros, Operand(1));
1035 // This wouldn't work for 1 and -1 as the shift would be 32 which means 0.
1036 __ sllv(ival, ival, zeros);
1037 // And the top (top 20 bits).
1038 __ srl(scratch1, ival, kBitsPerInt - kBinary32MantissaBits);
1039 __ or_(fval, fval, scratch1);
1040
1041 __ bind(&done);
1042
1043 __ sll(scratch1, wordoffset, 2);
1044 __ addu(scratch1, dst, scratch1);
1045 __ sw(fval, MemOperand(scratch1, 0));
1046 }
1047}
1048
1049
1050// Convert unsigned integer with specified number of leading zeroes in binary
1051// representation to IEEE 754 double.
1052// Integer to convert is passed in register hiword.
1053// Resulting double is returned in registers hiword:loword.
1054// This functions does not work correctly for 0.
1055static void GenerateUInt2Double(MacroAssembler* masm,
1056 Register hiword,
1057 Register loword,
1058 Register scratch,
1059 int leading_zeroes) {
1060 const int meaningful_bits = kBitsPerInt - leading_zeroes - 1;
1061 const int biased_exponent = HeapNumber::kExponentBias + meaningful_bits;
1062
1063 const int mantissa_shift_for_hi_word =
1064 meaningful_bits - HeapNumber::kMantissaBitsInTopWord;
1065
1066 const int mantissa_shift_for_lo_word =
1067 kBitsPerInt - mantissa_shift_for_hi_word;
1068
1069 __ li(scratch, biased_exponent << HeapNumber::kExponentShift);
1070 if (mantissa_shift_for_hi_word > 0) {
1071 __ sll(loword, hiword, mantissa_shift_for_lo_word);
1072 __ srl(hiword, hiword, mantissa_shift_for_hi_word);
1073 __ or_(hiword, scratch, hiword);
1074 } else {
1075 __ mov(loword, zero_reg);
1076 __ sll(hiword, hiword, mantissa_shift_for_hi_word);
1077 __ or_(hiword, scratch, hiword);
1078 }
1079
1080 // If least significant bit of biased exponent was not 1 it was corrupted
1081 // by most significant bit of mantissa so we should fix that.
1082 if (!(biased_exponent & 1)) {
1083 __ li(scratch, 1 << HeapNumber::kExponentShift);
1084 __ nor(scratch, scratch, scratch);
1085 __ and_(hiword, hiword, scratch);
1086 }
1087}
1088
1089
ager@chromium.org5c838252010-02-19 08:53:10 +00001090#undef __
1091#define __ ACCESS_MASM(masm())
1092
1093
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001094Register StubCompiler::CheckPrototypes(Handle<JSObject> object,
1095 Register object_reg,
1096 Handle<JSObject> holder,
1097 Register holder_reg,
1098 Register scratch1,
1099 Register scratch2,
1100 Handle<String> name,
1101 int save_at_depth,
1102 Label* miss) {
1103 // Make sure there's no overlap between holder and object registers.
1104 ASSERT(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
1105 ASSERT(!scratch2.is(object_reg) && !scratch2.is(holder_reg)
1106 && !scratch2.is(scratch1));
1107
1108 // Keep track of the current object in register reg.
1109 Register reg = object_reg;
1110 int depth = 0;
1111
1112 if (save_at_depth == depth) {
1113 __ sw(reg, MemOperand(sp));
1114 }
1115
1116 // Check the maps in the prototype chain.
1117 // Traverse the prototype chain from the object and do map checks.
1118 Handle<JSObject> current = object;
1119 while (!current.is_identical_to(holder)) {
1120 ++depth;
1121
1122 // Only global objects and objects that do not require access
1123 // checks are allowed in stubs.
1124 ASSERT(current->IsJSGlobalProxy() || !current->IsAccessCheckNeeded());
1125
1126 Handle<JSObject> prototype(JSObject::cast(current->GetPrototype()));
1127 if (!current->HasFastProperties() &&
1128 !current->IsJSGlobalObject() &&
1129 !current->IsJSGlobalProxy()) {
1130 if (!name->IsSymbol()) {
1131 name = factory()->LookupSymbol(name);
1132 }
1133 ASSERT(current->property_dictionary()->FindEntry(*name) ==
1134 StringDictionary::kNotFound);
1135
1136 GenerateDictionaryNegativeLookup(masm(), miss, reg, name,
1137 scratch1, scratch2);
1138
1139 __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
1140 reg = holder_reg; // From now on the object will be in holder_reg.
1141 __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
1142 } else {
1143 Handle<Map> current_map(current->map());
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001144 __ CheckMap(reg, scratch1, current_map, miss, DONT_DO_SMI_CHECK,
1145 ALLOW_ELEMENT_TRANSITION_MAPS);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001146 // Check access rights to the global object. This has to happen after
1147 // the map check so that we know that the object is actually a global
1148 // object.
1149 if (current->IsJSGlobalProxy()) {
1150 __ CheckAccessGlobalProxy(reg, scratch2, miss);
1151 }
1152 reg = holder_reg; // From now on the object will be in holder_reg.
1153
1154 if (heap()->InNewSpace(*prototype)) {
1155 // The prototype is in new space; we cannot store a reference to it
1156 // in the code. Load it from the map.
1157 __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
1158 } else {
1159 // The prototype is in old space; load it directly.
1160 __ li(reg, Operand(prototype));
1161 }
1162 }
1163
1164 if (save_at_depth == depth) {
1165 __ sw(reg, MemOperand(sp));
1166 }
1167
1168 // Go to the next object in the prototype chain.
1169 current = prototype;
1170 }
1171
1172 // Log the check depth.
1173 LOG(masm()->isolate(), IntEvent("check-maps-depth", depth + 1));
1174
1175 // Check the holder map.
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001176 __ CheckMap(reg, scratch1, Handle<Map>(current->map()), miss,
1177 DONT_DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001178
1179 // Perform security check for access to the global object.
1180 ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded());
1181 if (holder->IsJSGlobalProxy()) {
1182 __ CheckAccessGlobalProxy(reg, scratch1, miss);
1183 }
1184
1185 // If we've skipped any global objects, it's not enough to verify that
1186 // their maps haven't changed. We also need to check that the property
1187 // cell for the property is still empty.
1188 GenerateCheckPropertyCells(masm(), object, holder, name, scratch1, miss);
1189
1190 // Return the register containing the holder.
1191 return reg;
1192}
1193
1194
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001195void StubCompiler::GenerateLoadField(Handle<JSObject> object,
1196 Handle<JSObject> holder,
ager@chromium.org5c838252010-02-19 08:53:10 +00001197 Register receiver,
1198 Register scratch1,
1199 Register scratch2,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001200 Register scratch3,
ager@chromium.org5c838252010-02-19 08:53:10 +00001201 int index,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001202 Handle<String> name,
ager@chromium.org5c838252010-02-19 08:53:10 +00001203 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001204 // Check that the receiver isn't a smi.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001205 __ JumpIfSmi(receiver, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001206
1207 // Check that the maps haven't changed.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001208 Register reg = CheckPrototypes(
1209 object, receiver, holder, scratch1, scratch2, scratch3, name, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001210 GenerateFastPropertyLoad(masm(), v0, reg, holder, index);
1211 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +00001212}
1213
1214
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001215void StubCompiler::GenerateLoadConstant(Handle<JSObject> object,
1216 Handle<JSObject> holder,
ager@chromium.org5c838252010-02-19 08:53:10 +00001217 Register receiver,
1218 Register scratch1,
1219 Register scratch2,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001220 Register scratch3,
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001221 Handle<JSFunction> value,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001222 Handle<String> name,
ager@chromium.org5c838252010-02-19 08:53:10 +00001223 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001224 // Check that the receiver isn't a smi.
1225 __ JumpIfSmi(receiver, miss, scratch1);
1226
1227 // Check that the maps haven't changed.
danno@chromium.org1044a4d2012-04-30 12:34:39 +00001228 CheckPrototypes(object, receiver, holder,
1229 scratch1, scratch2, scratch3, name, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001230
1231 // Return the constant value.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001232 __ LoadHeapObject(v0, value);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001233 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +00001234}
1235
1236
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001237void StubCompiler::GenerateLoadCallback(Handle<JSObject> object,
1238 Handle<JSObject> holder,
1239 Register receiver,
1240 Register name_reg,
1241 Register scratch1,
1242 Register scratch2,
1243 Register scratch3,
1244 Handle<AccessorInfo> callback,
1245 Handle<String> name,
1246 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001247 // Check that the receiver isn't a smi.
1248 __ JumpIfSmi(receiver, miss, scratch1);
1249
1250 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001251 Register reg = CheckPrototypes(object, receiver, holder, scratch1,
1252 scratch2, scratch3, name, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001253
1254 // Build AccessorInfo::args_ list on the stack and push property name below
1255 // the exit frame to make GC aware of them and store pointers to them.
1256 __ push(receiver);
1257 __ mov(scratch2, sp); // scratch2 = AccessorInfo::args_
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001258 if (heap()->InNewSpace(callback->data())) {
1259 __ li(scratch3, callback);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001260 __ lw(scratch3, FieldMemOperand(scratch3, AccessorInfo::kDataOffset));
1261 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001262 __ li(scratch3, Handle<Object>(callback->data()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001263 }
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001264 __ Subu(sp, sp, 4 * kPointerSize);
1265 __ sw(reg, MemOperand(sp, 3 * kPointerSize));
1266 __ sw(scratch3, MemOperand(sp, 2 * kPointerSize));
1267 __ li(scratch3, Operand(ExternalReference::isolate_address()));
1268 __ sw(scratch3, MemOperand(sp, 1 * kPointerSize));
1269 __ sw(name_reg, MemOperand(sp, 0 * kPointerSize));
1270
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001271 __ mov(a2, scratch2); // Saved in case scratch2 == a1.
1272 __ mov(a1, sp); // a1 (first argument - see note below) = Handle<String>
1273
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001274 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
1275 // struct from the function (which is currently the case). This means we pass
1276 // the arguments in a1-a2 instead of a0-a1. TryCallApiFunctionAndReturn
1277 // will handle setting up a0.
1278
1279 const int kApiStackSpace = 1;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001280 FrameScope frame_scope(masm(), StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001281 __ EnterExitFrame(false, kApiStackSpace);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001282
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001283 // Create AccessorInfo instance on the stack above the exit frame with
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001284 // scratch2 (internal::Object** args_) as the data.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001285 __ sw(a2, MemOperand(sp, kPointerSize));
1286 // a2 (second argument - see note above) = AccessorInfo&
1287 __ Addu(a2, sp, kPointerSize);
1288
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001289 const int kStackUnwindSpace = 5;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001290 Address getter_address = v8::ToCData<Address>(callback->getter());
1291 ApiFunction fun(getter_address);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001292 ExternalReference ref =
1293 ExternalReference(&fun,
1294 ExternalReference::DIRECT_GETTER_CALL,
1295 masm()->isolate());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001296 __ CallApiFunctionAndReturn(ref, kStackUnwindSpace);
ager@chromium.org5c838252010-02-19 08:53:10 +00001297}
1298
1299
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001300void StubCompiler::GenerateLoadInterceptor(Handle<JSObject> object,
1301 Handle<JSObject> interceptor_holder,
ager@chromium.org5c838252010-02-19 08:53:10 +00001302 LookupResult* lookup,
1303 Register receiver,
1304 Register name_reg,
1305 Register scratch1,
1306 Register scratch2,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001307 Register scratch3,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001308 Handle<String> name,
ager@chromium.org5c838252010-02-19 08:53:10 +00001309 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001310 ASSERT(interceptor_holder->HasNamedInterceptor());
1311 ASSERT(!interceptor_holder->GetNamedInterceptor()->getter()->IsUndefined());
1312
1313 // Check that the receiver isn't a smi.
1314 __ JumpIfSmi(receiver, miss);
1315
1316 // So far the most popular follow ups for interceptor loads are FIELD
1317 // and CALLBACKS, so inline only them, other cases may be added
1318 // later.
1319 bool compile_followup_inline = false;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001320 if (lookup->IsFound() && lookup->IsCacheable()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001321 if (lookup->type() == FIELD) {
1322 compile_followup_inline = true;
1323 } else if (lookup->type() == CALLBACKS &&
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001324 lookup->GetCallbackObject()->IsAccessorInfo()) {
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001325 AccessorInfo* callback = AccessorInfo::cast(lookup->GetCallbackObject());
1326 compile_followup_inline = callback->getter() != NULL &&
1327 callback->IsCompatibleReceiver(*object);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001328 }
1329 }
1330
1331 if (compile_followup_inline) {
1332 // Compile the interceptor call, followed by inline code to load the
1333 // property from further up the prototype chain if the call fails.
1334 // Check that the maps haven't changed.
1335 Register holder_reg = CheckPrototypes(object, receiver, interceptor_holder,
1336 scratch1, scratch2, scratch3,
1337 name, miss);
1338 ASSERT(holder_reg.is(receiver) || holder_reg.is(scratch1));
1339
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001340 // Preserve the receiver register explicitly whenever it is different from
1341 // the holder and it is needed should the interceptor return without any
1342 // result. The CALLBACKS case needs the receiver to be passed into C++ code,
1343 // the FIELD case might cause a miss during the prototype check.
1344 bool must_perfrom_prototype_check = *interceptor_holder != lookup->holder();
1345 bool must_preserve_receiver_reg = !receiver.is(holder_reg) &&
1346 (lookup->type() == CALLBACKS || must_perfrom_prototype_check);
1347
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001348 // Save necessary data before invoking an interceptor.
1349 // Requires a frame to make GC aware of pushed pointers.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001350 {
1351 FrameScope frame_scope(masm(), StackFrame::INTERNAL);
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001352 if (must_preserve_receiver_reg) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001353 __ Push(receiver, holder_reg, name_reg);
1354 } else {
1355 __ Push(holder_reg, name_reg);
1356 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001357 // Invoke an interceptor. Note: map checks from receiver to
1358 // interceptor's holder has been compiled before (see a caller
1359 // of this method).
1360 CompileCallLoadPropertyWithInterceptor(masm(),
1361 receiver,
1362 holder_reg,
1363 name_reg,
1364 interceptor_holder);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001365 // Check if interceptor provided a value for property. If it's
1366 // the case, return immediately.
1367 Label interceptor_failed;
1368 __ LoadRoot(scratch1, Heap::kNoInterceptorResultSentinelRootIndex);
1369 __ Branch(&interceptor_failed, eq, v0, Operand(scratch1));
1370 frame_scope.GenerateLeaveFrame();
1371 __ Ret();
1372
1373 __ bind(&interceptor_failed);
1374 __ pop(name_reg);
1375 __ pop(holder_reg);
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001376 if (must_preserve_receiver_reg) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001377 __ pop(receiver);
1378 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001379 // Leave the internal frame.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001380 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001381 // Check that the maps from interceptor's holder to lookup's holder
1382 // haven't changed. And load lookup's holder into |holder| register.
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001383 if (must_perfrom_prototype_check) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001384 holder_reg = CheckPrototypes(interceptor_holder,
1385 holder_reg,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001386 Handle<JSObject>(lookup->holder()),
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001387 scratch1,
1388 scratch2,
1389 scratch3,
1390 name,
1391 miss);
1392 }
1393
1394 if (lookup->type() == FIELD) {
1395 // We found FIELD property in prototype chain of interceptor's holder.
1396 // Retrieve a field from field's holder.
1397 GenerateFastPropertyLoad(masm(), v0, holder_reg,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001398 Handle<JSObject>(lookup->holder()),
1399 lookup->GetFieldIndex());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001400 __ Ret();
1401 } else {
1402 // We found CALLBACKS property in prototype chain of interceptor's
1403 // holder.
1404 ASSERT(lookup->type() == CALLBACKS);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001405 Handle<AccessorInfo> callback(
1406 AccessorInfo::cast(lookup->GetCallbackObject()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001407 ASSERT(callback->getter() != NULL);
1408
1409 // Tail call to runtime.
1410 // Important invariant in CALLBACKS case: the code above must be
1411 // structured to never clobber |receiver| register.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001412 __ li(scratch2, callback);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001413
1414 __ Push(receiver, holder_reg);
1415 __ lw(scratch3,
1416 FieldMemOperand(scratch2, AccessorInfo::kDataOffset));
1417 __ li(scratch1, Operand(ExternalReference::isolate_address()));
1418 __ Push(scratch3, scratch1, scratch2, name_reg);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001419
1420 ExternalReference ref =
1421 ExternalReference(IC_Utility(IC::kLoadCallbackProperty),
1422 masm()->isolate());
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001423 __ TailCallExternalReference(ref, 6, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001424 }
1425 } else { // !compile_followup_inline
1426 // Call the runtime system to load the interceptor.
1427 // Check that the maps haven't changed.
1428 Register holder_reg = CheckPrototypes(object, receiver, interceptor_holder,
1429 scratch1, scratch2, scratch3,
1430 name, miss);
1431 PushInterceptorArguments(masm(), receiver, holder_reg,
1432 name_reg, interceptor_holder);
1433
1434 ExternalReference ref = ExternalReference(
1435 IC_Utility(IC::kLoadPropertyWithInterceptorForLoad), masm()->isolate());
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001436 __ TailCallExternalReference(ref, 6, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001437 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001438}
1439
1440
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001441void CallStubCompiler::GenerateNameCheck(Handle<String> name, Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001442 if (kind_ == Code::KEYED_CALL_IC) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001443 __ Branch(miss, ne, a2, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001444 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001445}
1446
1447
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001448void CallStubCompiler::GenerateGlobalReceiverCheck(Handle<JSObject> object,
1449 Handle<JSObject> holder,
1450 Handle<String> name,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001451 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001452 ASSERT(holder->IsGlobalObject());
1453
1454 // Get the number of arguments.
1455 const int argc = arguments().immediate();
1456
1457 // Get the receiver from the stack.
1458 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1459
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001460 // Check that the maps haven't changed.
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00001461 __ JumpIfSmi(a0, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001462 CheckPrototypes(object, a0, holder, a3, a1, t0, name, miss);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001463}
1464
1465
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001466void CallStubCompiler::GenerateLoadFunctionFromCell(
1467 Handle<JSGlobalPropertyCell> cell,
1468 Handle<JSFunction> function,
1469 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001470 // Get the value from the cell.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001471 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001472 __ lw(a1, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
1473
1474 // Check that the cell contains the same function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001475 if (heap()->InNewSpace(*function)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001476 // We can't embed a pointer to a function in new space so we have
1477 // to verify that the shared function info is unchanged. This has
1478 // the nice side effect that multiple closures based on the same
1479 // function can all use this call IC. Before we load through the
1480 // function, we have to verify that it still is a function.
1481 __ JumpIfSmi(a1, miss);
1482 __ GetObjectType(a1, a3, a3);
1483 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
1484
1485 // Check the shared function info. Make sure it hasn't changed.
1486 __ li(a3, Handle<SharedFunctionInfo>(function->shared()));
1487 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
1488 __ Branch(miss, ne, t0, Operand(a3));
1489 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001490 __ Branch(miss, ne, a1, Operand(function));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001491 }
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001492}
1493
1494
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001495void CallStubCompiler::GenerateMissBranch() {
1496 Handle<Code> code =
danno@chromium.org40cb8782011-05-25 07:58:50 +00001497 isolate()->stub_cache()->ComputeCallMiss(arguments().immediate(),
1498 kind_,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001499 extra_state_);
1500 __ Jump(code, RelocInfo::CODE_TARGET);
1501}
1502
1503
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001504Handle<Code> CallStubCompiler::CompileCallField(Handle<JSObject> object,
1505 Handle<JSObject> holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001506 int index,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001507 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001508 // ----------- S t a t e -------------
1509 // -- a2 : name
1510 // -- ra : return address
1511 // -----------------------------------
1512 Label miss;
1513
1514 GenerateNameCheck(name, &miss);
1515
1516 const int argc = arguments().immediate();
1517
1518 // Get the receiver of the function from the stack into a0.
1519 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1520 // Check that the receiver isn't a smi.
1521 __ JumpIfSmi(a0, &miss, t0);
1522
1523 // Do the right check and compute the holder register.
1524 Register reg = CheckPrototypes(object, a0, holder, a1, a3, t0, name, &miss);
1525 GenerateFastPropertyLoad(masm(), a1, reg, holder, index);
1526
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001527 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001528
1529 // Handle call cache miss.
1530 __ bind(&miss);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001531 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001532
1533 // Return the generated code.
1534 return GetCode(FIELD, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00001535}
1536
1537
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001538Handle<Code> CallStubCompiler::CompileArrayPushCall(
1539 Handle<Object> object,
1540 Handle<JSObject> holder,
1541 Handle<JSGlobalPropertyCell> cell,
1542 Handle<JSFunction> function,
1543 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001544 // ----------- S t a t e -------------
1545 // -- a2 : name
1546 // -- ra : return address
1547 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1548 // -- ...
1549 // -- sp[argc * 4] : receiver
1550 // -----------------------------------
1551
1552 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001553 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001554
1555 Label miss;
1556
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001557 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001558
1559 Register receiver = a1;
1560
1561 // Get the receiver from the stack.
1562 const int argc = arguments().immediate();
1563 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1564
1565 // Check that the receiver isn't a smi.
1566 __ JumpIfSmi(receiver, &miss);
1567
1568 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001569 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, a3, v0, t0,
1570 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001571
1572 if (argc == 0) {
1573 // Nothing to do, just return the length.
1574 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1575 __ Drop(argc + 1);
1576 __ Ret();
1577 } else {
1578 Label call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001579 if (argc == 1) { // Otherwise fall through to call the builtin.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001580 Label attempt_to_grow_elements;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001581
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001582 Register elements = t2;
1583 Register end_elements = t1;
1584 // Get the elements array of the object.
1585 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1586
1587 // Check that the elements are in fast mode and writable.
1588 __ CheckMap(elements,
1589 v0,
1590 Heap::kFixedArrayMapRootIndex,
1591 &call_builtin,
1592 DONT_DO_SMI_CHECK);
1593
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001594 // Get the array's length into v0 and calculate new length.
1595 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1596 STATIC_ASSERT(kSmiTagSize == 1);
1597 STATIC_ASSERT(kSmiTag == 0);
1598 __ Addu(v0, v0, Operand(Smi::FromInt(argc)));
1599
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001600 // Get the elements' length.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001601 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1602
1603 // Check if we could survive without allocation.
1604 __ Branch(&attempt_to_grow_elements, gt, v0, Operand(t0));
1605
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001606 // Check if value is a smi.
1607 Label with_write_barrier;
1608 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize));
1609 __ JumpIfNotSmi(t0, &with_write_barrier);
1610
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001611 // Save new length.
1612 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1613
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001614 // Store the value.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001615 // We may need a register containing the address end_elements below,
1616 // so write back the value in end_elements.
1617 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1618 __ Addu(end_elements, elements, end_elements);
1619 const int kEndElementsOffset =
1620 FixedArray::kHeaderSize - kHeapObjectTag - argc * kPointerSize;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001621 __ Addu(end_elements, end_elements, kEndElementsOffset);
1622 __ sw(t0, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001623
1624 // Check for a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001625 __ Drop(argc + 1);
1626 __ Ret();
1627
1628 __ bind(&with_write_barrier);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001629
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001630 __ lw(a3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1631
1632 if (FLAG_smi_only_arrays && !FLAG_trace_elements_transitions) {
1633 Label fast_object, not_fast_object;
1634 __ CheckFastObjectElements(a3, t3, &not_fast_object);
1635 __ jmp(&fast_object);
1636 // In case of fast smi-only, convert to fast object, otherwise bail out.
1637 __ bind(&not_fast_object);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001638 __ CheckFastSmiElements(a3, t3, &call_builtin);
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001639 // edx: receiver
1640 // r3: map
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001641 Label try_holey_map;
1642 __ LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001643 FAST_ELEMENTS,
1644 a3,
1645 t3,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001646 &try_holey_map);
1647 __ mov(a2, receiver);
1648 ElementsTransitionGenerator::
1649 GenerateMapChangeElementsTransition(masm());
1650 __ jmp(&fast_object);
1651
1652 __ bind(&try_holey_map);
1653 __ LoadTransitionedArrayMapConditional(FAST_HOLEY_SMI_ELEMENTS,
1654 FAST_HOLEY_ELEMENTS,
1655 a3,
1656 t3,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001657 &call_builtin);
1658 __ mov(a2, receiver);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001659 ElementsTransitionGenerator::
1660 GenerateMapChangeElementsTransition(masm());
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001661 __ bind(&fast_object);
1662 } else {
1663 __ CheckFastObjectElements(a3, a3, &call_builtin);
1664 }
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001665
1666 // Save new length.
1667 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1668
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001669 // Store the value.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001670 // We may need a register containing the address end_elements below,
1671 // so write back the value in end_elements.
1672 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1673 __ Addu(end_elements, elements, end_elements);
1674 __ Addu(end_elements, end_elements, kEndElementsOffset);
1675 __ sw(t0, MemOperand(end_elements));
1676
1677 __ RecordWrite(elements,
1678 end_elements,
1679 t0,
1680 kRAHasNotBeenSaved,
1681 kDontSaveFPRegs,
1682 EMIT_REMEMBERED_SET,
1683 OMIT_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001684 __ Drop(argc + 1);
1685 __ Ret();
1686
1687 __ bind(&attempt_to_grow_elements);
1688 // v0: array's length + 1.
1689 // t0: elements' length.
1690
1691 if (!FLAG_inline_new) {
1692 __ Branch(&call_builtin);
1693 }
1694
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001695 __ lw(a2, MemOperand(sp, (argc - 1) * kPointerSize));
1696 // Growing elements that are SMI-only requires special handling in case
1697 // the new element is non-Smi. For now, delegate to the builtin.
1698 Label no_fast_elements_check;
1699 __ JumpIfSmi(a2, &no_fast_elements_check);
1700 __ lw(t3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1701 __ CheckFastObjectElements(t3, t3, &call_builtin);
1702 __ bind(&no_fast_elements_check);
1703
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001704 ExternalReference new_space_allocation_top =
1705 ExternalReference::new_space_allocation_top_address(
1706 masm()->isolate());
1707 ExternalReference new_space_allocation_limit =
1708 ExternalReference::new_space_allocation_limit_address(
1709 masm()->isolate());
1710
1711 const int kAllocationDelta = 4;
1712 // Load top and check if it is the end of elements.
1713 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1714 __ Addu(end_elements, elements, end_elements);
1715 __ Addu(end_elements, end_elements, Operand(kEndElementsOffset));
1716 __ li(t3, Operand(new_space_allocation_top));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001717 __ lw(a3, MemOperand(t3));
1718 __ Branch(&call_builtin, ne, end_elements, Operand(a3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001719
1720 __ li(t5, Operand(new_space_allocation_limit));
1721 __ lw(t5, MemOperand(t5));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001722 __ Addu(a3, a3, Operand(kAllocationDelta * kPointerSize));
1723 __ Branch(&call_builtin, hi, a3, Operand(t5));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001724
1725 // We fit and could grow elements.
1726 // Update new_space_allocation_top.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001727 __ sw(a3, MemOperand(t3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001728 // Push the argument.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001729 __ sw(a2, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001730 // Fill the rest with holes.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001731 __ LoadRoot(a3, Heap::kTheHoleValueRootIndex);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001732 for (int i = 1; i < kAllocationDelta; i++) {
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001733 __ sw(a3, MemOperand(end_elements, i * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001734 }
1735
1736 // Update elements' and array's sizes.
1737 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1738 __ Addu(t0, t0, Operand(Smi::FromInt(kAllocationDelta)));
1739 __ sw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1740
1741 // Elements are in new space, so write barrier is not required.
1742 __ Drop(argc + 1);
1743 __ Ret();
1744 }
1745 __ bind(&call_builtin);
1746 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPush,
1747 masm()->isolate()),
1748 argc + 1,
1749 1);
1750 }
1751
1752 // Handle call cache miss.
1753 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001754 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001755
1756 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001757 return GetCode(function);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001758}
1759
1760
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001761Handle<Code> CallStubCompiler::CompileArrayPopCall(
1762 Handle<Object> object,
1763 Handle<JSObject> holder,
1764 Handle<JSGlobalPropertyCell> cell,
1765 Handle<JSFunction> function,
1766 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001767 // ----------- S t a t e -------------
1768 // -- a2 : name
1769 // -- ra : return address
1770 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1771 // -- ...
1772 // -- sp[argc * 4] : receiver
1773 // -----------------------------------
1774
1775 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001776 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001777
1778 Label miss, return_undefined, call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001779 Register receiver = a1;
1780 Register elements = a3;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001781 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001782
1783 // Get the receiver from the stack.
1784 const int argc = arguments().immediate();
1785 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001786 // Check that the receiver isn't a smi.
1787 __ JumpIfSmi(receiver, &miss);
1788
1789 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001790 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, elements,
1791 t0, v0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001792
1793 // Get the elements array of the object.
1794 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1795
1796 // Check that the elements are in fast mode and writable.
danno@chromium.org40cb8782011-05-25 07:58:50 +00001797 __ CheckMap(elements,
1798 v0,
1799 Heap::kFixedArrayMapRootIndex,
1800 &call_builtin,
1801 DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001802
1803 // Get the array's length into t0 and calculate new length.
1804 __ lw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1805 __ Subu(t0, t0, Operand(Smi::FromInt(1)));
1806 __ Branch(&return_undefined, lt, t0, Operand(zero_reg));
1807
1808 // Get the last element.
1809 __ LoadRoot(t2, Heap::kTheHoleValueRootIndex);
1810 STATIC_ASSERT(kSmiTagSize == 1);
1811 STATIC_ASSERT(kSmiTag == 0);
1812 // We can't address the last element in one operation. Compute the more
1813 // expensive shift first, and use an offset later on.
1814 __ sll(t1, t0, kPointerSizeLog2 - kSmiTagSize);
1815 __ Addu(elements, elements, t1);
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00001816 __ lw(v0, FieldMemOperand(elements, FixedArray::kHeaderSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001817 __ Branch(&call_builtin, eq, v0, Operand(t2));
1818
1819 // Set the array's length.
1820 __ sw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1821
1822 // Fill with the hole.
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00001823 __ sw(t2, FieldMemOperand(elements, FixedArray::kHeaderSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001824 __ Drop(argc + 1);
1825 __ Ret();
1826
1827 __ bind(&return_undefined);
1828 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
1829 __ Drop(argc + 1);
1830 __ Ret();
1831
1832 __ bind(&call_builtin);
1833 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPop,
1834 masm()->isolate()),
1835 argc + 1,
1836 1);
1837
1838 // Handle call cache miss.
1839 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001840 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001841
1842 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001843 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00001844}
1845
1846
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001847Handle<Code> CallStubCompiler::CompileStringCharCodeAtCall(
1848 Handle<Object> object,
1849 Handle<JSObject> holder,
1850 Handle<JSGlobalPropertyCell> cell,
1851 Handle<JSFunction> function,
1852 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001853 // ----------- S t a t e -------------
1854 // -- a2 : function name
1855 // -- ra : return address
1856 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1857 // -- ...
1858 // -- sp[argc * 4] : receiver
1859 // -----------------------------------
1860
1861 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001862 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001863
1864 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001865 Label miss;
1866 Label name_miss;
1867 Label index_out_of_range;
1868
1869 Label* index_out_of_range_label = &index_out_of_range;
1870
danno@chromium.org40cb8782011-05-25 07:58:50 +00001871 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001872 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00001873 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001874 index_out_of_range_label = &miss;
1875 }
1876
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001877 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001878
1879 // Check that the maps starting from the prototype haven't changed.
1880 GenerateDirectLoadGlobalFunctionPrototype(masm(),
1881 Context::STRING_FUNCTION_INDEX,
1882 v0,
1883 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001884 ASSERT(!object.is_identical_to(holder));
1885 CheckPrototypes(Handle<JSObject>(JSObject::cast(object->GetPrototype())),
1886 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001887
1888 Register receiver = a1;
1889 Register index = t1;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001890 Register result = v0;
1891 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1892 if (argc > 0) {
1893 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
1894 } else {
1895 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
1896 }
1897
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001898 StringCharCodeAtGenerator generator(receiver,
1899 index,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001900 result,
1901 &miss, // When not a string.
1902 &miss, // When not a number.
1903 index_out_of_range_label,
1904 STRING_INDEX_IS_NUMBER);
1905 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001906 __ Drop(argc + 1);
1907 __ Ret();
1908
1909 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001910 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001911
1912 if (index_out_of_range.is_linked()) {
1913 __ bind(&index_out_of_range);
1914 __ LoadRoot(v0, Heap::kNanValueRootIndex);
1915 __ Drop(argc + 1);
1916 __ Ret();
1917 }
1918
1919 __ bind(&miss);
1920 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001921 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001922 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001923 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001924
1925 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001926 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00001927}
1928
1929
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001930Handle<Code> CallStubCompiler::CompileStringCharAtCall(
1931 Handle<Object> object,
1932 Handle<JSObject> holder,
1933 Handle<JSGlobalPropertyCell> cell,
1934 Handle<JSFunction> function,
1935 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001936 // ----------- S t a t e -------------
1937 // -- a2 : function name
1938 // -- ra : return address
1939 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1940 // -- ...
1941 // -- sp[argc * 4] : receiver
1942 // -----------------------------------
1943
1944 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001945 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001946
1947 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001948 Label miss;
1949 Label name_miss;
1950 Label index_out_of_range;
1951 Label* index_out_of_range_label = &index_out_of_range;
danno@chromium.org40cb8782011-05-25 07:58:50 +00001952 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001953 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00001954 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001955 index_out_of_range_label = &miss;
1956 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001957 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001958
1959 // Check that the maps starting from the prototype haven't changed.
1960 GenerateDirectLoadGlobalFunctionPrototype(masm(),
1961 Context::STRING_FUNCTION_INDEX,
1962 v0,
1963 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001964 ASSERT(!object.is_identical_to(holder));
1965 CheckPrototypes(Handle<JSObject>(JSObject::cast(object->GetPrototype())),
1966 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001967
1968 Register receiver = v0;
1969 Register index = t1;
danno@chromium.orgc612e022011-11-10 11:38:15 +00001970 Register scratch = a3;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001971 Register result = v0;
1972 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1973 if (argc > 0) {
1974 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
1975 } else {
1976 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
1977 }
1978
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001979 StringCharAtGenerator generator(receiver,
1980 index,
danno@chromium.orgc612e022011-11-10 11:38:15 +00001981 scratch,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001982 result,
1983 &miss, // When not a string.
1984 &miss, // When not a number.
1985 index_out_of_range_label,
1986 STRING_INDEX_IS_NUMBER);
1987 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001988 __ Drop(argc + 1);
1989 __ Ret();
1990
1991 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001992 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001993
1994 if (index_out_of_range.is_linked()) {
1995 __ bind(&index_out_of_range);
1996 __ LoadRoot(v0, Heap::kEmptyStringRootIndex);
1997 __ Drop(argc + 1);
1998 __ Ret();
1999 }
2000
2001 __ bind(&miss);
2002 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002003 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002004 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002005 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002006
2007 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002008 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002009}
2010
2011
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002012Handle<Code> CallStubCompiler::CompileStringFromCharCodeCall(
2013 Handle<Object> object,
2014 Handle<JSObject> holder,
2015 Handle<JSGlobalPropertyCell> cell,
2016 Handle<JSFunction> function,
2017 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002018 // ----------- S t a t e -------------
2019 // -- a2 : function name
2020 // -- ra : return address
2021 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2022 // -- ...
2023 // -- sp[argc * 4] : receiver
2024 // -----------------------------------
2025
2026 const int argc = arguments().immediate();
2027
2028 // If the object is not a JSObject or we got an unexpected number of
2029 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002030 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002031
2032 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002033 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002034
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002035 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002036 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
2037
2038 STATIC_ASSERT(kSmiTag == 0);
2039 __ JumpIfSmi(a1, &miss);
2040
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002041 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
2042 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002043 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002044 ASSERT(cell->value() == *function);
2045 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2046 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002047 GenerateLoadFunctionFromCell(cell, function, &miss);
2048 }
2049
2050 // Load the char code argument.
2051 Register code = a1;
2052 __ lw(code, MemOperand(sp, 0 * kPointerSize));
2053
2054 // Check the code is a smi.
2055 Label slow;
2056 STATIC_ASSERT(kSmiTag == 0);
2057 __ JumpIfNotSmi(code, &slow);
2058
2059 // Convert the smi code to uint16.
2060 __ And(code, code, Operand(Smi::FromInt(0xffff)));
2061
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002062 StringCharFromCodeGenerator generator(code, v0);
2063 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002064 __ Drop(argc + 1);
2065 __ Ret();
2066
2067 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002068 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002069
2070 // Tail call the full function. We do not have to patch the receiver
2071 // because the function makes no use of it.
2072 __ bind(&slow);
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002073 __ InvokeFunction(
2074 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002075
2076 __ bind(&miss);
2077 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002078 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002079
2080 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002081 return cell.is_null() ? GetCode(function) : GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002082}
2083
2084
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002085Handle<Code> CallStubCompiler::CompileMathFloorCall(
2086 Handle<Object> object,
2087 Handle<JSObject> holder,
2088 Handle<JSGlobalPropertyCell> cell,
2089 Handle<JSFunction> function,
2090 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002091 // ----------- S t a t e -------------
2092 // -- a2 : function name
2093 // -- ra : return address
2094 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2095 // -- ...
2096 // -- sp[argc * 4] : receiver
2097 // -----------------------------------
2098
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002099 if (!CpuFeatures::IsSupported(FPU)) {
2100 return Handle<Code>::null();
2101 }
2102
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002103 CpuFeatures::Scope scope_fpu(FPU);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002104 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002105 // If the object is not a JSObject or we got an unexpected number of
2106 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002107 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002108
2109 Label miss, slow;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002110 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002111
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002112 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002113 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002114 STATIC_ASSERT(kSmiTag == 0);
2115 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002116 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2117 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002118 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002119 ASSERT(cell->value() == *function);
2120 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2121 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002122 GenerateLoadFunctionFromCell(cell, function, &miss);
2123 }
2124
2125 // Load the (only) argument into v0.
2126 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2127
2128 // If the argument is a smi, just return.
2129 STATIC_ASSERT(kSmiTag == 0);
2130 __ And(t0, v0, Operand(kSmiTagMask));
2131 __ Drop(argc + 1, eq, t0, Operand(zero_reg));
2132 __ Ret(eq, t0, Operand(zero_reg));
2133
danno@chromium.org40cb8782011-05-25 07:58:50 +00002134 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002135
2136 Label wont_fit_smi, no_fpu_error, restore_fcsr_and_return;
2137
2138 // If fpu is enabled, we use the floor instruction.
2139
2140 // Load the HeapNumber value.
2141 __ ldc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
2142
2143 // Backup FCSR.
2144 __ cfc1(a3, FCSR);
2145 // Clearing FCSR clears the exception mask with no side-effects.
2146 __ ctc1(zero_reg, FCSR);
2147 // Convert the argument to an integer.
2148 __ floor_w_d(f0, f0);
2149
2150 // Start checking for special cases.
2151 // Get the argument exponent and clear the sign bit.
2152 __ lw(t1, FieldMemOperand(v0, HeapNumber::kValueOffset + kPointerSize));
2153 __ And(t2, t1, Operand(~HeapNumber::kSignMask));
2154 __ srl(t2, t2, HeapNumber::kMantissaBitsInTopWord);
2155
2156 // Retrieve FCSR and check for fpu errors.
2157 __ cfc1(t5, FCSR);
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002158 __ And(t5, t5, Operand(kFCSRExceptionFlagMask));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002159 __ Branch(&no_fpu_error, eq, t5, Operand(zero_reg));
2160
2161 // Check for NaN, Infinity, and -Infinity.
2162 // They are invariant through a Math.Floor call, so just
2163 // return the original argument.
2164 __ Subu(t3, t2, Operand(HeapNumber::kExponentMask
2165 >> HeapNumber::kMantissaBitsInTopWord));
2166 __ Branch(&restore_fcsr_and_return, eq, t3, Operand(zero_reg));
2167 // We had an overflow or underflow in the conversion. Check if we
2168 // have a big exponent.
2169 // If greater or equal, the argument is already round and in v0.
2170 __ Branch(&restore_fcsr_and_return, ge, t3,
2171 Operand(HeapNumber::kMantissaBits));
2172 __ Branch(&wont_fit_smi);
2173
2174 __ bind(&no_fpu_error);
2175 // Move the result back to v0.
2176 __ mfc1(v0, f0);
2177 // Check if the result fits into a smi.
2178 __ Addu(a1, v0, Operand(0x40000000));
2179 __ Branch(&wont_fit_smi, lt, a1, Operand(zero_reg));
2180 // Tag the result.
2181 STATIC_ASSERT(kSmiTag == 0);
2182 __ sll(v0, v0, kSmiTagSize);
2183
2184 // Check for -0.
2185 __ Branch(&restore_fcsr_and_return, ne, v0, Operand(zero_reg));
2186 // t1 already holds the HeapNumber exponent.
2187 __ And(t0, t1, Operand(HeapNumber::kSignMask));
2188 // If our HeapNumber is negative it was -0, so load its address and return.
2189 // Else v0 is loaded with 0, so we can also just return.
2190 __ Branch(&restore_fcsr_and_return, eq, t0, Operand(zero_reg));
2191 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2192
2193 __ bind(&restore_fcsr_and_return);
2194 // Restore FCSR and return.
2195 __ ctc1(a3, FCSR);
2196
2197 __ Drop(argc + 1);
2198 __ Ret();
2199
2200 __ bind(&wont_fit_smi);
2201 // Restore FCSR and fall to slow case.
2202 __ ctc1(a3, FCSR);
2203
2204 __ bind(&slow);
2205 // Tail call the full function. We do not have to patch the receiver
2206 // because the function makes no use of it.
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002207 __ InvokeFunction(
2208 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002209
2210 __ bind(&miss);
2211 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002212 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002213
2214 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002215 return cell.is_null() ? GetCode(function) : GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002216}
2217
2218
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002219Handle<Code> CallStubCompiler::CompileMathAbsCall(
2220 Handle<Object> object,
2221 Handle<JSObject> holder,
2222 Handle<JSGlobalPropertyCell> cell,
2223 Handle<JSFunction> function,
2224 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002225 // ----------- S t a t e -------------
2226 // -- a2 : function name
2227 // -- ra : return address
2228 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2229 // -- ...
2230 // -- sp[argc * 4] : receiver
2231 // -----------------------------------
2232
2233 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002234 // If the object is not a JSObject or we got an unexpected number of
2235 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002236 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002237
2238 Label miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002239
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002240 GenerateNameCheck(name, &miss);
2241 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002242 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002243 STATIC_ASSERT(kSmiTag == 0);
2244 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002245 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
2246 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002247 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002248 ASSERT(cell->value() == *function);
2249 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2250 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002251 GenerateLoadFunctionFromCell(cell, function, &miss);
2252 }
2253
2254 // Load the (only) argument into v0.
2255 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2256
2257 // Check if the argument is a smi.
2258 Label not_smi;
2259 STATIC_ASSERT(kSmiTag == 0);
2260 __ JumpIfNotSmi(v0, &not_smi);
2261
2262 // Do bitwise not or do nothing depending on the sign of the
2263 // argument.
2264 __ sra(t0, v0, kBitsPerInt - 1);
2265 __ Xor(a1, v0, t0);
2266
2267 // Add 1 or do nothing depending on the sign of the argument.
2268 __ Subu(v0, a1, t0);
2269
2270 // If the result is still negative, go to the slow case.
2271 // This only happens for the most negative smi.
2272 Label slow;
2273 __ Branch(&slow, lt, v0, Operand(zero_reg));
2274
2275 // Smi case done.
2276 __ Drop(argc + 1);
2277 __ Ret();
2278
2279 // Check if the argument is a heap number and load its exponent and
2280 // sign.
2281 __ bind(&not_smi);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002282 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002283 __ lw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2284
2285 // Check the sign of the argument. If the argument is positive,
2286 // just return it.
2287 Label negative_sign;
2288 __ And(t0, a1, Operand(HeapNumber::kSignMask));
2289 __ Branch(&negative_sign, ne, t0, Operand(zero_reg));
2290 __ Drop(argc + 1);
2291 __ Ret();
2292
2293 // If the argument is negative, clear the sign, and return a new
2294 // number.
2295 __ bind(&negative_sign);
2296 __ Xor(a1, a1, Operand(HeapNumber::kSignMask));
2297 __ lw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2298 __ LoadRoot(t2, Heap::kHeapNumberMapRootIndex);
2299 __ AllocateHeapNumber(v0, t0, t1, t2, &slow);
2300 __ sw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2301 __ sw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2302 __ Drop(argc + 1);
2303 __ Ret();
2304
2305 // Tail call the full function. We do not have to patch the receiver
2306 // because the function makes no use of it.
2307 __ bind(&slow);
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002308 __ InvokeFunction(
2309 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002310
2311 __ bind(&miss);
2312 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002313 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002314
2315 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002316 return cell.is_null() ? GetCode(function) : GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002317}
2318
2319
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002320Handle<Code> CallStubCompiler::CompileFastApiCall(
lrn@chromium.org7516f052011-03-30 08:52:27 +00002321 const CallOptimization& optimization,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002322 Handle<Object> object,
2323 Handle<JSObject> holder,
2324 Handle<JSGlobalPropertyCell> cell,
2325 Handle<JSFunction> function,
2326 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002327
danno@chromium.org40cb8782011-05-25 07:58:50 +00002328 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002329
2330 ASSERT(optimization.is_simple_api_call());
2331 // Bail out if object is a global object as we don't want to
2332 // repatch it to global receiver.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002333 if (object->IsGlobalObject()) return Handle<Code>::null();
2334 if (!cell.is_null()) return Handle<Code>::null();
2335 if (!object->IsJSObject()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002336 int depth = optimization.GetPrototypeDepthOfExpectedType(
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002337 Handle<JSObject>::cast(object), holder);
2338 if (depth == kInvalidProtoDepth) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002339
2340 Label miss, miss_before_stack_reserved;
2341
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002342 GenerateNameCheck(name, &miss_before_stack_reserved);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002343
2344 // Get the receiver from the stack.
2345 const int argc = arguments().immediate();
2346 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2347
2348 // Check that the receiver isn't a smi.
2349 __ JumpIfSmi(a1, &miss_before_stack_reserved);
2350
2351 __ IncrementCounter(counters->call_const(), 1, a0, a3);
2352 __ IncrementCounter(counters->call_const_fast_api(), 1, a0, a3);
2353
2354 ReserveSpaceForFastApiCall(masm(), a0);
2355
2356 // Check that the maps haven't changed and find a Holder as a side effect.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002357 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0, name,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002358 depth, &miss);
2359
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002360 GenerateFastApiDirectCall(masm(), optimization, argc);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002361
2362 __ bind(&miss);
2363 FreeSpaceForFastApiCall(masm());
2364
2365 __ bind(&miss_before_stack_reserved);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002366 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002367
2368 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002369 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002370}
2371
2372
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002373Handle<Code> CallStubCompiler::CompileCallConstant(Handle<Object> object,
2374 Handle<JSObject> holder,
2375 Handle<JSFunction> function,
2376 Handle<String> name,
lrn@chromium.org7516f052011-03-30 08:52:27 +00002377 CheckType check) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002378 // ----------- S t a t e -------------
2379 // -- a2 : name
2380 // -- ra : return address
2381 // -----------------------------------
2382 if (HasCustomCallGenerator(function)) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002383 Handle<Code> code = CompileCustomCall(object, holder,
2384 Handle<JSGlobalPropertyCell>::null(),
2385 function, name);
2386 // A null handle means bail out to the regular compiler code below.
2387 if (!code.is_null()) return code;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002388 }
2389
2390 Label miss;
2391
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002392 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002393
2394 // Get the receiver from the stack.
2395 const int argc = arguments().immediate();
2396 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2397
2398 // Check that the receiver isn't a smi.
2399 if (check != NUMBER_CHECK) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002400 __ JumpIfSmi(a1, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002401 }
2402
2403 // Make sure that it's okay not to patch the on stack receiver
2404 // unless we're doing a receiver map check.
2405 ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002406 switch (check) {
2407 case RECEIVER_MAP_CHECK:
2408 __ IncrementCounter(masm()->isolate()->counters()->call_const(),
2409 1, a0, a3);
2410
2411 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002412 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2413 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002414
2415 // Patch the receiver on the stack with the global proxy if
2416 // necessary.
2417 if (object->IsGlobalObject()) {
2418 __ lw(a3, FieldMemOperand(a1, GlobalObject::kGlobalReceiverOffset));
2419 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2420 }
2421 break;
2422
2423 case STRING_CHECK:
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00002424 if (function->IsBuiltin() || !function->shared()->is_classic_mode()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002425 // Check that the object is a two-byte string or a symbol.
2426 __ GetObjectType(a1, a3, a3);
2427 __ Branch(&miss, Ugreater_equal, a3, Operand(FIRST_NONSTRING_TYPE));
2428 // Check that the maps starting from the prototype haven't changed.
2429 GenerateDirectLoadGlobalFunctionPrototype(
2430 masm(), Context::STRING_FUNCTION_INDEX, a0, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002431 CheckPrototypes(
2432 Handle<JSObject>(JSObject::cast(object->GetPrototype())),
2433 a0, holder, a3, a1, t0, name, &miss);
2434 } else {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002435 // Calling non-strict non-builtins with a value as the receiver
2436 // requires boxing.
2437 __ jmp(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002438 }
2439 break;
2440
2441 case NUMBER_CHECK:
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00002442 if (function->IsBuiltin() || !function->shared()->is_classic_mode()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002443 Label fast;
2444 // Check that the object is a smi or a heap number.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002445 __ JumpIfSmi(a1, &fast);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002446 __ GetObjectType(a1, a0, a0);
2447 __ Branch(&miss, ne, a0, Operand(HEAP_NUMBER_TYPE));
2448 __ bind(&fast);
2449 // Check that the maps starting from the prototype haven't changed.
2450 GenerateDirectLoadGlobalFunctionPrototype(
2451 masm(), Context::NUMBER_FUNCTION_INDEX, a0, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002452 CheckPrototypes(
2453 Handle<JSObject>(JSObject::cast(object->GetPrototype())),
2454 a0, holder, a3, a1, t0, name, &miss);
2455 } else {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002456 // Calling non-strict non-builtins with a value as the receiver
2457 // requires boxing.
2458 __ jmp(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002459 }
2460 break;
2461
2462 case BOOLEAN_CHECK:
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00002463 if (function->IsBuiltin() || !function->shared()->is_classic_mode()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002464 Label fast;
2465 // Check that the object is a boolean.
2466 __ LoadRoot(t0, Heap::kTrueValueRootIndex);
2467 __ Branch(&fast, eq, a1, Operand(t0));
2468 __ LoadRoot(t0, Heap::kFalseValueRootIndex);
2469 __ Branch(&miss, ne, a1, Operand(t0));
2470 __ bind(&fast);
2471 // Check that the maps starting from the prototype haven't changed.
2472 GenerateDirectLoadGlobalFunctionPrototype(
2473 masm(), Context::BOOLEAN_FUNCTION_INDEX, a0, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002474 CheckPrototypes(
2475 Handle<JSObject>(JSObject::cast(object->GetPrototype())),
2476 a0, holder, a3, a1, t0, name, &miss);
2477 } else {
2478 // Calling non-strict non-builtins with a value as the receiver
2479 // requires boxing.
2480 __ jmp(&miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002481 }
2482 break;
2483 }
2484
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002485 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002486 ? CALL_AS_FUNCTION
2487 : CALL_AS_METHOD;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002488 __ InvokeFunction(
2489 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002490
2491 // Handle call cache miss.
2492 __ bind(&miss);
2493
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002494 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002495
2496 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002497 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002498}
2499
2500
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002501Handle<Code> CallStubCompiler::CompileCallInterceptor(Handle<JSObject> object,
2502 Handle<JSObject> holder,
2503 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002504 // ----------- S t a t e -------------
2505 // -- a2 : name
2506 // -- ra : return address
2507 // -----------------------------------
2508
2509 Label miss;
2510
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002511 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002512
2513 // Get the number of arguments.
2514 const int argc = arguments().immediate();
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002515 LookupResult lookup(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002516 LookupPostInterceptor(holder, name, &lookup);
2517
2518 // Get the receiver from the stack.
2519 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2520
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002521 CallInterceptorCompiler compiler(this, arguments(), a2, extra_state_);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002522 compiler.Compile(masm(), object, holder, name, &lookup, a1, a3, t0, a0,
2523 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002524
2525 // Move returned value, the function to call, to a1.
2526 __ mov(a1, v0);
2527 // Restore receiver.
2528 __ lw(a0, MemOperand(sp, argc * kPointerSize));
2529
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002530 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002531
2532 // Handle call cache miss.
2533 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002534 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002535
2536 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002537 return GetCode(INTERCEPTOR, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002538}
2539
2540
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002541Handle<Code> CallStubCompiler::CompileCallGlobal(
2542 Handle<JSObject> object,
2543 Handle<GlobalObject> holder,
2544 Handle<JSGlobalPropertyCell> cell,
2545 Handle<JSFunction> function,
2546 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002547 // ----------- S t a t e -------------
2548 // -- a2 : name
2549 // -- ra : return address
2550 // -----------------------------------
2551
2552 if (HasCustomCallGenerator(function)) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002553 Handle<Code> code = CompileCustomCall(object, holder, cell, function, name);
2554 // A null handle means bail out to the regular compiler code below.
2555 if (!code.is_null()) return code;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002556 }
2557
2558 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002559 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002560
2561 // Get the number of arguments.
2562 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002563 GenerateGlobalReceiverCheck(object, holder, name, &miss);
2564 GenerateLoadFunctionFromCell(cell, function, &miss);
2565
2566 // Patch the receiver on the stack with the global proxy if
2567 // necessary.
2568 if (object->IsGlobalObject()) {
2569 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
2570 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2571 }
2572
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002573 // Set up the context (function already in r1).
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002574 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
2575
2576 // Jump to the cached code (tail call).
2577 Counters* counters = masm()->isolate()->counters();
2578 __ IncrementCounter(counters->call_global_inline(), 1, a3, t0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002579 ParameterCount expected(function->shared()->formal_parameter_count());
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002580 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
danno@chromium.org40cb8782011-05-25 07:58:50 +00002581 ? CALL_AS_FUNCTION
2582 : CALL_AS_METHOD;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002583 // We call indirectly through the code field in the function to
2584 // allow recompilation to take effect without changing any of the
2585 // call sites.
2586 __ lw(a3, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
2587 __ InvokeCode(a3, expected, arguments(), JUMP_FUNCTION,
2588 NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002589
2590 // Handle call cache miss.
2591 __ bind(&miss);
2592 __ IncrementCounter(counters->call_global_inline_miss(), 1, a1, a3);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002593 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002594
2595 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002596 return GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002597}
2598
2599
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002600Handle<Code> StoreStubCompiler::CompileStoreField(Handle<JSObject> object,
ager@chromium.org5c838252010-02-19 08:53:10 +00002601 int index,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002602 Handle<Map> transition,
2603 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002604 // ----------- S t a t e -------------
2605 // -- a0 : value
2606 // -- a1 : receiver
2607 // -- a2 : name
2608 // -- ra : return address
2609 // -----------------------------------
2610 Label miss;
2611
2612 // Name register might be clobbered.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002613 GenerateStoreField(masm(),
2614 object,
2615 index,
2616 transition,
2617 name,
2618 a1, a2, a3, t0,
2619 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002620 __ bind(&miss);
2621 __ li(a2, Operand(Handle<String>(name))); // Restore name.
2622 Handle<Code> ic = masm()->isolate()->builtins()->Builtins::StoreIC_Miss();
2623 __ Jump(ic, RelocInfo::CODE_TARGET);
2624
2625 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002626 return GetCode(transition.is_null() ? FIELD : MAP_TRANSITION, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002627}
2628
2629
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002630Handle<Code> StoreStubCompiler::CompileStoreCallback(
2631 Handle<JSObject> object,
2632 Handle<AccessorInfo> callback,
2633 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002634 // ----------- S t a t e -------------
2635 // -- a0 : value
2636 // -- a1 : receiver
2637 // -- a2 : name
2638 // -- ra : return address
2639 // -----------------------------------
2640 Label miss;
2641
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002642 // Check that the map of the object hasn't changed.
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002643 __ CheckMap(a1, a3, Handle<Map>(object->map()), &miss,
2644 DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002645
2646 // Perform global security token check if needed.
2647 if (object->IsJSGlobalProxy()) {
2648 __ CheckAccessGlobalProxy(a1, a3, &miss);
2649 }
2650
2651 // Stub never generated for non-global objects that require access
2652 // checks.
2653 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
2654
2655 __ push(a1); // Receiver.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002656 __ li(a3, Operand(callback)); // Callback info.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002657 __ Push(a3, a2, a0);
2658
2659 // Do tail-call to the runtime system.
2660 ExternalReference store_callback_property =
2661 ExternalReference(IC_Utility(IC::kStoreCallbackProperty),
2662 masm()->isolate());
2663 __ TailCallExternalReference(store_callback_property, 4, 1);
2664
2665 // Handle store cache miss.
2666 __ bind(&miss);
2667 Handle<Code> ic = masm()->isolate()->builtins()->StoreIC_Miss();
2668 __ Jump(ic, RelocInfo::CODE_TARGET);
2669
2670 // Return the generated code.
2671 return GetCode(CALLBACKS, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002672}
2673
2674
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002675Handle<Code> StoreStubCompiler::CompileStoreViaSetter(
2676 Handle<JSObject> receiver,
2677 Handle<JSFunction> setter,
2678 Handle<String> name) {
2679 // ----------- S t a t e -------------
2680 // -- a0 : value
2681 // -- a1 : receiver
2682 // -- a2 : name
2683 // -- ra : return address
2684 // -----------------------------------
2685 Label miss;
2686
2687 // Check that the map of the object hasn't changed.
2688 __ CheckMap(a1, a3, Handle<Map>(receiver->map()), &miss, DO_SMI_CHECK,
2689 ALLOW_ELEMENT_TRANSITION_MAPS);
2690
2691 {
2692 FrameScope scope(masm(), StackFrame::INTERNAL);
2693
2694 // Save value register, so we can restore it later.
2695 __ push(a0);
2696
2697 // Call the JavaScript getter with the receiver and the value on the stack.
2698 __ push(a1);
2699 __ push(a0);
2700 ParameterCount actual(1);
2701 __ InvokeFunction(setter, actual, CALL_FUNCTION, NullCallWrapper(),
2702 CALL_AS_METHOD);
2703
2704 // We have to return the passed value, not the return value of the setter.
2705 __ pop(v0);
2706
2707 // Restore context register.
2708 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2709 }
2710 __ Ret();
2711
2712 __ bind(&miss);
2713 Handle<Code> ic = masm()->isolate()->builtins()->StoreIC_Miss();
2714 __ Jump(ic, RelocInfo::CODE_TARGET);
2715
2716 // Return the generated code.
2717 return GetCode(CALLBACKS, name);
2718}
2719
2720
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002721Handle<Code> StoreStubCompiler::CompileStoreInterceptor(
2722 Handle<JSObject> receiver,
2723 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002724 // ----------- S t a t e -------------
2725 // -- a0 : value
2726 // -- a1 : receiver
2727 // -- a2 : name
2728 // -- ra : return address
2729 // -----------------------------------
2730 Label miss;
2731
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002732 // Check that the map of the object hasn't changed.
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002733 __ CheckMap(a1, a3, Handle<Map>(receiver->map()), &miss,
2734 DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002735
2736 // Perform global security token check if needed.
2737 if (receiver->IsJSGlobalProxy()) {
2738 __ CheckAccessGlobalProxy(a1, a3, &miss);
2739 }
2740
2741 // Stub is never generated for non-global objects that require access
2742 // checks.
2743 ASSERT(receiver->IsJSGlobalProxy() || !receiver->IsAccessCheckNeeded());
2744
2745 __ Push(a1, a2, a0); // Receiver, name, value.
2746
2747 __ li(a0, Operand(Smi::FromInt(strict_mode_)));
2748 __ push(a0); // Strict mode.
2749
2750 // Do tail-call to the runtime system.
2751 ExternalReference store_ic_property =
2752 ExternalReference(IC_Utility(IC::kStoreInterceptorProperty),
2753 masm()->isolate());
2754 __ TailCallExternalReference(store_ic_property, 4, 1);
2755
2756 // Handle store cache miss.
2757 __ bind(&miss);
2758 Handle<Code> ic = masm()->isolate()->builtins()->Builtins::StoreIC_Miss();
2759 __ Jump(ic, RelocInfo::CODE_TARGET);
2760
2761 // Return the generated code.
2762 return GetCode(INTERCEPTOR, name);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00002763}
2764
2765
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002766Handle<Code> StoreStubCompiler::CompileStoreGlobal(
2767 Handle<GlobalObject> object,
2768 Handle<JSGlobalPropertyCell> cell,
2769 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002770 // ----------- S t a t e -------------
2771 // -- a0 : value
2772 // -- a1 : receiver
2773 // -- a2 : name
2774 // -- ra : return address
2775 // -----------------------------------
2776 Label miss;
2777
2778 // Check that the map of the global has not changed.
2779 __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
2780 __ Branch(&miss, ne, a3, Operand(Handle<Map>(object->map())));
2781
2782 // Check that the value in the cell is not the hole. If it is, this
2783 // cell could have been deleted and reintroducing the global needs
2784 // to update the property details in the property dictionary of the
2785 // global object. We bail out to the runtime system to do that.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002786 __ li(t0, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002787 __ LoadRoot(t1, Heap::kTheHoleValueRootIndex);
2788 __ lw(t2, FieldMemOperand(t0, JSGlobalPropertyCell::kValueOffset));
2789 __ Branch(&miss, eq, t1, Operand(t2));
2790
2791 // Store the value in the cell.
2792 __ sw(a0, FieldMemOperand(t0, JSGlobalPropertyCell::kValueOffset));
2793 __ mov(v0, a0); // Stored value must be returned in v0.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002794 // Cells are always rescanned, so no write barrier here.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00002795
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002796 Counters* counters = masm()->isolate()->counters();
2797 __ IncrementCounter(counters->named_store_global_inline(), 1, a1, a3);
2798 __ Ret();
2799
2800 // Handle store cache miss.
2801 __ bind(&miss);
2802 __ IncrementCounter(counters->named_store_global_inline_miss(), 1, a1, a3);
2803 Handle<Code> ic = masm()->isolate()->builtins()->StoreIC_Miss();
2804 __ Jump(ic, RelocInfo::CODE_TARGET);
2805
2806 // Return the generated code.
2807 return GetCode(NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002808}
2809
2810
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002811Handle<Code> LoadStubCompiler::CompileLoadNonexistent(Handle<String> name,
2812 Handle<JSObject> object,
2813 Handle<JSObject> last) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002814 // ----------- S t a t e -------------
2815 // -- a0 : receiver
2816 // -- ra : return address
2817 // -----------------------------------
2818 Label miss;
2819
2820 // Check that the receiver is not a smi.
2821 __ JumpIfSmi(a0, &miss);
2822
2823 // Check the maps of the full prototype chain.
2824 CheckPrototypes(object, a0, last, a3, a1, t0, name, &miss);
2825
2826 // If the last object in the prototype chain is a global object,
2827 // check that the global property cell is empty.
2828 if (last->IsGlobalObject()) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002829 GenerateCheckPropertyCell(
2830 masm(), Handle<GlobalObject>::cast(last), name, a1, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002831 }
2832
2833 // Return undefined if maps of the full prototype chain is still the same.
2834 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
2835 __ Ret();
2836
2837 __ bind(&miss);
2838 GenerateLoadMiss(masm(), Code::LOAD_IC);
2839
2840 // Return the generated code.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002841 return GetCode(NONEXISTENT, factory()->empty_string());
lrn@chromium.org7516f052011-03-30 08:52:27 +00002842}
2843
2844
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002845Handle<Code> LoadStubCompiler::CompileLoadField(Handle<JSObject> object,
2846 Handle<JSObject> holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +00002847 int index,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002848 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002849 // ----------- S t a t e -------------
2850 // -- a0 : receiver
2851 // -- a2 : name
2852 // -- ra : return address
2853 // -----------------------------------
2854 Label miss;
2855
2856 __ mov(v0, a0);
2857
2858 GenerateLoadField(object, holder, v0, a3, a1, t0, index, name, &miss);
2859 __ bind(&miss);
2860 GenerateLoadMiss(masm(), Code::LOAD_IC);
2861
2862 // Return the generated code.
2863 return GetCode(FIELD, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002864}
2865
2866
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002867Handle<Code> LoadStubCompiler::CompileLoadCallback(
2868 Handle<String> name,
2869 Handle<JSObject> object,
2870 Handle<JSObject> holder,
2871 Handle<AccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002872 // ----------- S t a t e -------------
2873 // -- a0 : receiver
2874 // -- a2 : name
2875 // -- ra : return address
2876 // -----------------------------------
2877 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002878 GenerateLoadCallback(object, holder, a0, a2, a3, a1, t0, callback, name,
2879 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002880 __ bind(&miss);
2881 GenerateLoadMiss(masm(), Code::LOAD_IC);
2882
2883 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002884 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002885}
2886
2887
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002888Handle<Code> LoadStubCompiler::CompileLoadViaGetter(
2889 Handle<String> name,
2890 Handle<JSObject> receiver,
2891 Handle<JSObject> holder,
2892 Handle<JSFunction> getter) {
2893 // ----------- S t a t e -------------
2894 // -- a0 : receiver
2895 // -- a2 : name
2896 // -- ra : return address
2897 // -----------------------------------
2898 Label miss;
2899
2900 // Check that the maps haven't changed.
2901 __ JumpIfSmi(a0, &miss);
2902 CheckPrototypes(receiver, a0, holder, a3, t0, a1, name, &miss);
2903
2904 {
2905 FrameScope scope(masm(), StackFrame::INTERNAL);
2906
2907 // Call the JavaScript getter with the receiver on the stack.
2908 __ push(a0);
2909 ParameterCount actual(0);
2910 __ InvokeFunction(getter, actual, CALL_FUNCTION, NullCallWrapper(),
2911 CALL_AS_METHOD);
2912
2913 // Restore context register.
2914 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2915 }
2916 __ Ret();
2917
2918 __ bind(&miss);
2919 GenerateLoadMiss(masm(), Code::LOAD_IC);
2920
2921 // Return the generated code.
2922 return GetCode(CALLBACKS, name);
2923}
2924
2925
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002926Handle<Code> LoadStubCompiler::CompileLoadConstant(Handle<JSObject> object,
2927 Handle<JSObject> holder,
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002928 Handle<JSFunction> value,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002929 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002930 // ----------- S t a t e -------------
2931 // -- a0 : receiver
2932 // -- a2 : name
2933 // -- ra : return address
2934 // -----------------------------------
2935 Label miss;
2936
2937 GenerateLoadConstant(object, holder, a0, a3, a1, t0, value, name, &miss);
2938 __ bind(&miss);
2939 GenerateLoadMiss(masm(), Code::LOAD_IC);
2940
2941 // Return the generated code.
2942 return GetCode(CONSTANT_FUNCTION, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002943}
2944
2945
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002946Handle<Code> LoadStubCompiler::CompileLoadInterceptor(Handle<JSObject> object,
2947 Handle<JSObject> holder,
2948 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002949 // ----------- S t a t e -------------
2950 // -- a0 : receiver
2951 // -- a2 : name
2952 // -- ra : return address
2953 // -- [sp] : receiver
2954 // -----------------------------------
2955 Label miss;
2956
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002957 LookupResult lookup(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002958 LookupPostInterceptor(holder, name, &lookup);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002959 GenerateLoadInterceptor(object, holder, &lookup, a0, a2, a3, a1, t0, name,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002960 &miss);
2961 __ bind(&miss);
2962 GenerateLoadMiss(masm(), Code::LOAD_IC);
2963
2964 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002965 return GetCode(INTERCEPTOR, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002966}
2967
2968
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002969Handle<Code> LoadStubCompiler::CompileLoadGlobal(
2970 Handle<JSObject> object,
2971 Handle<GlobalObject> holder,
2972 Handle<JSGlobalPropertyCell> cell,
2973 Handle<String> name,
2974 bool is_dont_delete) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002975 // ----------- S t a t e -------------
2976 // -- a0 : receiver
2977 // -- a2 : name
2978 // -- ra : return address
2979 // -----------------------------------
2980 Label miss;
2981
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002982 // Check that the map of the global has not changed.
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00002983 __ JumpIfSmi(a0, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002984 CheckPrototypes(object, a0, holder, a3, t0, a1, name, &miss);
2985
2986 // Get the value from the cell.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002987 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002988 __ lw(t0, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
2989
2990 // Check for deleted property if property can actually be deleted.
2991 if (!is_dont_delete) {
2992 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
2993 __ Branch(&miss, eq, t0, Operand(at));
2994 }
2995
2996 __ mov(v0, t0);
2997 Counters* counters = masm()->isolate()->counters();
2998 __ IncrementCounter(counters->named_load_global_stub(), 1, a1, a3);
2999 __ Ret();
3000
3001 __ bind(&miss);
3002 __ IncrementCounter(counters->named_load_global_stub_miss(), 1, a1, a3);
3003 GenerateLoadMiss(masm(), Code::LOAD_IC);
3004
3005 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003006 return GetCode(NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003007}
3008
3009
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003010Handle<Code> KeyedLoadStubCompiler::CompileLoadField(Handle<String> name,
3011 Handle<JSObject> receiver,
3012 Handle<JSObject> holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +00003013 int index) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003014 // ----------- S t a t e -------------
3015 // -- ra : return address
3016 // -- a0 : key
3017 // -- a1 : receiver
3018 // -----------------------------------
3019 Label miss;
3020
3021 // Check the key is the cached one.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003022 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003023
3024 GenerateLoadField(receiver, holder, a1, a2, a3, t0, index, name, &miss);
3025 __ bind(&miss);
3026 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
3027
3028 return GetCode(FIELD, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003029}
3030
3031
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003032Handle<Code> KeyedLoadStubCompiler::CompileLoadCallback(
3033 Handle<String> name,
3034 Handle<JSObject> receiver,
3035 Handle<JSObject> holder,
3036 Handle<AccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003037 // ----------- S t a t e -------------
3038 // -- ra : return address
3039 // -- a0 : key
3040 // -- a1 : receiver
3041 // -----------------------------------
3042 Label miss;
3043
3044 // Check the key is the cached one.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003045 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003046
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003047 GenerateLoadCallback(receiver, holder, a1, a0, a2, a3, t0, callback, name,
3048 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003049 __ bind(&miss);
3050 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
3051
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003052 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003053}
3054
3055
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003056Handle<Code> KeyedLoadStubCompiler::CompileLoadConstant(
3057 Handle<String> name,
3058 Handle<JSObject> receiver,
3059 Handle<JSObject> holder,
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00003060 Handle<JSFunction> value) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003061 // ----------- S t a t e -------------
3062 // -- ra : return address
3063 // -- a0 : key
3064 // -- a1 : receiver
3065 // -----------------------------------
3066 Label miss;
3067
3068 // Check the key is the cached one.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003069 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003070
3071 GenerateLoadConstant(receiver, holder, a1, a2, a3, t0, value, name, &miss);
3072 __ bind(&miss);
3073 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
3074
3075 // Return the generated code.
3076 return GetCode(CONSTANT_FUNCTION, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003077}
3078
3079
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003080Handle<Code> KeyedLoadStubCompiler::CompileLoadInterceptor(
3081 Handle<JSObject> receiver,
3082 Handle<JSObject> holder,
3083 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003084 // ----------- S t a t e -------------
3085 // -- ra : return address
3086 // -- a0 : key
3087 // -- a1 : receiver
3088 // -----------------------------------
3089 Label miss;
3090
3091 // Check the key is the cached one.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003092 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003093
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003094 LookupResult lookup(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003095 LookupPostInterceptor(holder, name, &lookup);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003096 GenerateLoadInterceptor(receiver, holder, &lookup, a1, a0, a2, a3, t0, name,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003097 &miss);
3098 __ bind(&miss);
3099 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
3100
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003101 return GetCode(INTERCEPTOR, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003102}
3103
3104
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003105Handle<Code> KeyedLoadStubCompiler::CompileLoadArrayLength(
3106 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003107 // ----------- S t a t e -------------
3108 // -- ra : return address
3109 // -- a0 : key
3110 // -- a1 : receiver
3111 // -----------------------------------
3112 Label miss;
3113
3114 // Check the key is the cached one.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003115 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003116
3117 GenerateLoadArrayLength(masm(), a1, a2, &miss);
3118 __ bind(&miss);
3119 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
3120
3121 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003122}
3123
3124
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003125Handle<Code> KeyedLoadStubCompiler::CompileLoadStringLength(
3126 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003127 // ----------- S t a t e -------------
3128 // -- ra : return address
3129 // -- a0 : key
3130 // -- a1 : receiver
3131 // -----------------------------------
3132 Label miss;
3133
3134 Counters* counters = masm()->isolate()->counters();
3135 __ IncrementCounter(counters->keyed_load_string_length(), 1, a2, a3);
3136
3137 // Check the key is the cached one.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003138 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003139
3140 GenerateLoadStringLength(masm(), a1, a2, a3, &miss, true);
3141 __ bind(&miss);
3142 __ DecrementCounter(counters->keyed_load_string_length(), 1, a2, a3);
3143
3144 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
3145
3146 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003147}
3148
3149
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003150Handle<Code> KeyedLoadStubCompiler::CompileLoadFunctionPrototype(
3151 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003152 // ----------- S t a t e -------------
3153 // -- ra : return address
3154 // -- a0 : key
3155 // -- a1 : receiver
3156 // -----------------------------------
3157 Label miss;
3158
3159 Counters* counters = masm()->isolate()->counters();
3160 __ IncrementCounter(counters->keyed_load_function_prototype(), 1, a2, a3);
3161
3162 // Check the name hasn't changed.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003163 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003164
3165 GenerateLoadFunctionPrototype(masm(), a1, a2, a3, &miss);
3166 __ bind(&miss);
3167 __ DecrementCounter(counters->keyed_load_function_prototype(), 1, a2, a3);
3168 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
3169
3170 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003171}
3172
3173
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003174Handle<Code> KeyedLoadStubCompiler::CompileLoadElement(
3175 Handle<Map> receiver_map) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003176 // ----------- S t a t e -------------
3177 // -- ra : return address
3178 // -- a0 : key
3179 // -- a1 : receiver
3180 // -----------------------------------
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003181 ElementsKind elements_kind = receiver_map->elements_kind();
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003182 Handle<Code> stub = KeyedLoadElementStub(elements_kind).GetCode();
3183
3184 __ DispatchMap(a1, a2, receiver_map, stub, DO_SMI_CHECK);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003185
3186 Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Miss();
3187 __ Jump(ic, RelocInfo::CODE_TARGET);
3188
3189 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003190 return GetCode(NORMAL, factory()->empty_string());
danno@chromium.org40cb8782011-05-25 07:58:50 +00003191}
3192
3193
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003194Handle<Code> KeyedLoadStubCompiler::CompileLoadPolymorphic(
3195 MapHandleList* receiver_maps,
3196 CodeHandleList* handler_ics) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003197 // ----------- S t a t e -------------
3198 // -- ra : return address
3199 // -- a0 : key
3200 // -- a1 : receiver
3201 // -----------------------------------
3202 Label miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003203 __ JumpIfSmi(a1, &miss);
3204
danno@chromium.org40cb8782011-05-25 07:58:50 +00003205 int receiver_count = receiver_maps->length();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003206 __ lw(a2, FieldMemOperand(a1, HeapObject::kMapOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003207 for (int current = 0; current < receiver_count; ++current) {
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003208 __ Jump(handler_ics->at(current), RelocInfo::CODE_TARGET,
3209 eq, a2, Operand(receiver_maps->at(current)));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003210 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003211
3212 __ bind(&miss);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003213 Handle<Code> miss_ic = isolate()->builtins()->KeyedLoadIC_Miss();
3214 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003215
3216 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003217 return GetCode(NORMAL, factory()->empty_string(), MEGAMORPHIC);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003218}
3219
3220
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003221Handle<Code> KeyedStoreStubCompiler::CompileStoreField(Handle<JSObject> object,
lrn@chromium.org7516f052011-03-30 08:52:27 +00003222 int index,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003223 Handle<Map> transition,
3224 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003225 // ----------- S t a t e -------------
3226 // -- a0 : value
3227 // -- a1 : key
3228 // -- a2 : receiver
3229 // -- ra : return address
3230 // -----------------------------------
3231
3232 Label miss;
3233
3234 Counters* counters = masm()->isolate()->counters();
3235 __ IncrementCounter(counters->keyed_store_field(), 1, a3, t0);
3236
3237 // Check that the name has not changed.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003238 __ Branch(&miss, ne, a1, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003239
3240 // a3 is used as scratch register. a1 and a2 keep their values if a jump to
3241 // the miss label is generated.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00003242 GenerateStoreField(masm(),
3243 object,
3244 index,
3245 transition,
3246 name,
3247 a2, a1, a3, t0,
3248 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003249 __ bind(&miss);
3250
3251 __ DecrementCounter(counters->keyed_store_field(), 1, a3, t0);
3252 Handle<Code> ic = masm()->isolate()->builtins()->KeyedStoreIC_Miss();
3253 __ Jump(ic, RelocInfo::CODE_TARGET);
3254
3255 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003256 return GetCode(transition.is_null() ? FIELD : MAP_TRANSITION, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003257}
3258
3259
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003260Handle<Code> KeyedStoreStubCompiler::CompileStoreElement(
3261 Handle<Map> receiver_map) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003262 // ----------- S t a t e -------------
3263 // -- a0 : value
3264 // -- a1 : key
3265 // -- a2 : receiver
3266 // -- ra : return address
3267 // -- a3 : scratch
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003268 // -----------------------------------
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003269 ElementsKind elements_kind = receiver_map->elements_kind();
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003270 bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE;
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003271 Handle<Code> stub =
yangguo@chromium.org56454712012-02-16 15:33:53 +00003272 KeyedStoreElementStub(is_js_array, elements_kind, grow_mode_).GetCode();
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003273
3274 __ DispatchMap(a2, a3, receiver_map, stub, DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003275
danno@chromium.org40cb8782011-05-25 07:58:50 +00003276 Handle<Code> ic = isolate()->builtins()->KeyedStoreIC_Miss();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003277 __ Jump(ic, RelocInfo::CODE_TARGET);
3278
3279 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003280 return GetCode(NORMAL, factory()->empty_string());
lrn@chromium.org7516f052011-03-30 08:52:27 +00003281}
3282
3283
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003284Handle<Code> KeyedStoreStubCompiler::CompileStorePolymorphic(
3285 MapHandleList* receiver_maps,
3286 CodeHandleList* handler_stubs,
3287 MapHandleList* transitioned_maps) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003288 // ----------- S t a t e -------------
3289 // -- a0 : value
3290 // -- a1 : key
3291 // -- a2 : receiver
3292 // -- ra : return address
3293 // -- a3 : scratch
3294 // -----------------------------------
3295 Label miss;
3296 __ JumpIfSmi(a2, &miss);
3297
3298 int receiver_count = receiver_maps->length();
3299 __ lw(a3, FieldMemOperand(a2, HeapObject::kMapOffset));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003300 for (int i = 0; i < receiver_count; ++i) {
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003301 if (transitioned_maps->at(i).is_null()) {
3302 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET, eq,
3303 a3, Operand(receiver_maps->at(i)));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003304 } else {
3305 Label next_map;
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003306 __ Branch(&next_map, ne, a3, Operand(receiver_maps->at(i)));
3307 __ li(a3, Operand(transitioned_maps->at(i)));
3308 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003309 __ bind(&next_map);
3310 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003311 }
3312
3313 __ bind(&miss);
3314 Handle<Code> miss_ic = isolate()->builtins()->KeyedStoreIC_Miss();
3315 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
3316
3317 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003318 return GetCode(NORMAL, factory()->empty_string(), MEGAMORPHIC);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003319}
3320
3321
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003322Handle<Code> ConstructStubCompiler::CompileConstructStub(
3323 Handle<JSFunction> function) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003324 // a0 : argc
3325 // a1 : constructor
3326 // ra : return address
3327 // [sp] : last argument
3328 Label generic_stub_call;
3329
3330 // Use t7 for holding undefined which is used in several places below.
3331 __ LoadRoot(t7, Heap::kUndefinedValueRootIndex);
3332
3333#ifdef ENABLE_DEBUGGER_SUPPORT
3334 // Check to see whether there are any break points in the function code. If
3335 // there are jump to the generic constructor stub which calls the actual
3336 // code for the function thereby hitting the break points.
3337 __ lw(t5, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
3338 __ lw(a2, FieldMemOperand(t5, SharedFunctionInfo::kDebugInfoOffset));
3339 __ Branch(&generic_stub_call, ne, a2, Operand(t7));
3340#endif
3341
3342 // Load the initial map and verify that it is in fact a map.
3343 // a1: constructor function
3344 // t7: undefined
3345 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003346 __ JumpIfSmi(a2, &generic_stub_call);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003347 __ GetObjectType(a2, a3, t0);
3348 __ Branch(&generic_stub_call, ne, t0, Operand(MAP_TYPE));
3349
3350#ifdef DEBUG
3351 // Cannot construct functions this way.
3352 // a0: argc
3353 // a1: constructor function
3354 // a2: initial map
3355 // t7: undefined
3356 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceTypeOffset));
3357 __ Check(ne, "Function constructed by construct stub.",
3358 a3, Operand(JS_FUNCTION_TYPE));
3359#endif
3360
3361 // Now allocate the JSObject in new space.
3362 // a0: argc
3363 // a1: constructor function
3364 // a2: initial map
3365 // t7: undefined
3366 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceSizeOffset));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003367 __ AllocateInNewSpace(a3, t4, t5, t6, &generic_stub_call, SIZE_IN_WORDS);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003368
3369 // Allocated the JSObject, now initialize the fields. Map is set to initial
3370 // map and properties and elements are set to empty fixed array.
3371 // a0: argc
3372 // a1: constructor function
3373 // a2: initial map
3374 // a3: object size (in words)
3375 // t4: JSObject (not tagged)
3376 // t7: undefined
3377 __ LoadRoot(t6, Heap::kEmptyFixedArrayRootIndex);
3378 __ mov(t5, t4);
3379 __ sw(a2, MemOperand(t5, JSObject::kMapOffset));
3380 __ sw(t6, MemOperand(t5, JSObject::kPropertiesOffset));
3381 __ sw(t6, MemOperand(t5, JSObject::kElementsOffset));
3382 __ Addu(t5, t5, Operand(3 * kPointerSize));
3383 ASSERT_EQ(0 * kPointerSize, JSObject::kMapOffset);
3384 ASSERT_EQ(1 * kPointerSize, JSObject::kPropertiesOffset);
3385 ASSERT_EQ(2 * kPointerSize, JSObject::kElementsOffset);
3386
3387
3388 // Calculate the location of the first argument. The stack contains only the
3389 // argc arguments.
3390 __ sll(a1, a0, kPointerSizeLog2);
3391 __ Addu(a1, a1, sp);
3392
3393 // Fill all the in-object properties with undefined.
3394 // a0: argc
3395 // a1: first argument
3396 // a3: object size (in words)
3397 // t4: JSObject (not tagged)
3398 // t5: First in-object property of JSObject (not tagged)
3399 // t7: undefined
3400 // Fill the initialized properties with a constant value or a passed argument
3401 // depending on the this.x = ...; assignment in the function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003402 Handle<SharedFunctionInfo> shared(function->shared());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003403 for (int i = 0; i < shared->this_property_assignments_count(); i++) {
3404 if (shared->IsThisPropertyAssignmentArgument(i)) {
3405 Label not_passed, next;
3406 // Check if the argument assigned to the property is actually passed.
3407 int arg_number = shared->GetThisPropertyAssignmentArgument(i);
3408 __ Branch(&not_passed, less_equal, a0, Operand(arg_number));
3409 // Argument passed - find it on the stack.
3410 __ lw(a2, MemOperand(a1, (arg_number + 1) * -kPointerSize));
3411 __ sw(a2, MemOperand(t5));
3412 __ Addu(t5, t5, kPointerSize);
3413 __ jmp(&next);
3414 __ bind(&not_passed);
3415 // Set the property to undefined.
3416 __ sw(t7, MemOperand(t5));
3417 __ Addu(t5, t5, Operand(kPointerSize));
3418 __ bind(&next);
3419 } else {
3420 // Set the property to the constant value.
3421 Handle<Object> constant(shared->GetThisPropertyAssignmentConstant(i));
3422 __ li(a2, Operand(constant));
3423 __ sw(a2, MemOperand(t5));
3424 __ Addu(t5, t5, kPointerSize);
3425 }
3426 }
3427
3428 // Fill the unused in-object property fields with undefined.
3429 ASSERT(function->has_initial_map());
3430 for (int i = shared->this_property_assignments_count();
3431 i < function->initial_map()->inobject_properties();
3432 i++) {
3433 __ sw(t7, MemOperand(t5));
3434 __ Addu(t5, t5, kPointerSize);
3435 }
3436
3437 // a0: argc
3438 // t4: JSObject (not tagged)
3439 // Move argc to a1 and the JSObject to return to v0 and tag it.
3440 __ mov(a1, a0);
3441 __ mov(v0, t4);
3442 __ Or(v0, v0, Operand(kHeapObjectTag));
3443
3444 // v0: JSObject
3445 // a1: argc
3446 // Remove caller arguments and receiver from the stack and return.
3447 __ sll(t0, a1, kPointerSizeLog2);
3448 __ Addu(sp, sp, t0);
3449 __ Addu(sp, sp, Operand(kPointerSize));
3450 Counters* counters = masm()->isolate()->counters();
3451 __ IncrementCounter(counters->constructed_objects(), 1, a1, a2);
3452 __ IncrementCounter(counters->constructed_objects_stub(), 1, a1, a2);
3453 __ Ret();
3454
3455 // Jump to the generic stub in case the specialized code cannot handle the
3456 // construction.
3457 __ bind(&generic_stub_call);
3458 Handle<Code> generic_construct_stub =
3459 masm()->isolate()->builtins()->JSConstructStubGeneric();
3460 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET);
3461
3462 // Return the generated code.
3463 return GetCode();
3464}
3465
3466
danno@chromium.org40cb8782011-05-25 07:58:50 +00003467#undef __
3468#define __ ACCESS_MASM(masm)
3469
3470
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003471void KeyedLoadStubCompiler::GenerateLoadDictionaryElement(
3472 MacroAssembler* masm) {
3473 // ---------- S t a t e --------------
3474 // -- ra : return address
3475 // -- a0 : key
3476 // -- a1 : receiver
3477 // -----------------------------------
3478 Label slow, miss_force_generic;
3479
3480 Register key = a0;
3481 Register receiver = a1;
3482
3483 __ JumpIfNotSmi(key, &miss_force_generic);
3484 __ lw(t0, FieldMemOperand(receiver, JSObject::kElementsOffset));
3485 __ sra(a2, a0, kSmiTagSize);
3486 __ LoadFromNumberDictionary(&slow, t0, a0, v0, a2, a3, t1);
3487 __ Ret();
3488
3489 // Slow case, key and receiver still in a0 and a1.
3490 __ bind(&slow);
3491 __ IncrementCounter(
3492 masm->isolate()->counters()->keyed_load_external_array_slow(),
3493 1, a2, a3);
3494 // Entry registers are intact.
3495 // ---------- S t a t e --------------
3496 // -- ra : return address
3497 // -- a0 : key
3498 // -- a1 : receiver
3499 // -----------------------------------
3500 Handle<Code> slow_ic =
3501 masm->isolate()->builtins()->KeyedLoadIC_Slow();
3502 __ Jump(slow_ic, RelocInfo::CODE_TARGET);
3503
3504 // Miss case, call the runtime.
3505 __ bind(&miss_force_generic);
3506
3507 // ---------- S t a t e --------------
3508 // -- ra : return address
3509 // -- a0 : key
3510 // -- a1 : receiver
3511 // -----------------------------------
3512
3513 Handle<Code> miss_ic =
3514 masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric();
3515 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
3516}
3517
3518
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003519static bool IsElementTypeSigned(ElementsKind elements_kind) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003520 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003521 case EXTERNAL_BYTE_ELEMENTS:
3522 case EXTERNAL_SHORT_ELEMENTS:
3523 case EXTERNAL_INT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003524 return true;
3525
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003526 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
3527 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
3528 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
3529 case EXTERNAL_PIXEL_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003530 return false;
3531
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003532 case EXTERNAL_FLOAT_ELEMENTS:
3533 case EXTERNAL_DOUBLE_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003534 case FAST_SMI_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003535 case FAST_ELEMENTS:
3536 case FAST_DOUBLE_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003537 case FAST_HOLEY_SMI_ELEMENTS:
3538 case FAST_HOLEY_ELEMENTS:
3539 case FAST_HOLEY_DOUBLE_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003540 case DICTIONARY_ELEMENTS:
3541 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003542 UNREACHABLE();
3543 return false;
3544 }
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003545 return false;
lrn@chromium.org7516f052011-03-30 08:52:27 +00003546}
3547
3548
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003549static void GenerateSmiKeyCheck(MacroAssembler* masm,
3550 Register key,
3551 Register scratch0,
3552 Register scratch1,
3553 FPURegister double_scratch0,
3554 Label* fail) {
3555 if (CpuFeatures::IsSupported(FPU)) {
3556 CpuFeatures::Scope scope(FPU);
3557 Label key_ok;
3558 // Check for smi or a smi inside a heap number. We convert the heap
3559 // number and check if the conversion is exact and fits into the smi
3560 // range.
3561 __ JumpIfSmi(key, &key_ok);
3562 __ CheckMap(key,
3563 scratch0,
3564 Heap::kHeapNumberMapRootIndex,
3565 fail,
3566 DONT_DO_SMI_CHECK);
3567 __ ldc1(double_scratch0, FieldMemOperand(key, HeapNumber::kValueOffset));
3568 __ EmitFPUTruncate(kRoundToZero,
3569 double_scratch0,
3570 double_scratch0,
3571 scratch0,
3572 scratch1,
3573 kCheckForInexactConversion);
3574
3575 __ Branch(fail, ne, scratch1, Operand(zero_reg));
3576
3577 __ mfc1(scratch0, double_scratch0);
3578 __ SmiTagCheckOverflow(key, scratch0, scratch1);
3579 __ BranchOnOverflow(fail, scratch1);
3580 __ bind(&key_ok);
3581 } else {
3582 // Check that the key is a smi.
3583 __ JumpIfNotSmi(key, fail);
3584 }
3585}
3586
3587
danno@chromium.org40cb8782011-05-25 07:58:50 +00003588void KeyedLoadStubCompiler::GenerateLoadExternalArray(
3589 MacroAssembler* masm,
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003590 ElementsKind elements_kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003591 // ---------- S t a t e --------------
3592 // -- ra : return address
3593 // -- a0 : key
3594 // -- a1 : receiver
3595 // -----------------------------------
danno@chromium.org40cb8782011-05-25 07:58:50 +00003596 Label miss_force_generic, slow, failed_allocation;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003597
3598 Register key = a0;
3599 Register receiver = a1;
3600
danno@chromium.org40cb8782011-05-25 07:58:50 +00003601 // This stub is meant to be tail-jumped to, the receiver must already
3602 // have been verified by the caller to not be a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003603
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003604 // Check that the key is a smi or a heap number convertible to a smi.
3605 GenerateSmiKeyCheck(masm, key, t0, t1, f2, &miss_force_generic);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003606
3607 __ lw(a3, FieldMemOperand(receiver, JSObject::kElementsOffset));
3608 // a3: elements array
3609
3610 // Check that the index is in range.
3611 __ lw(t1, FieldMemOperand(a3, ExternalArray::kLengthOffset));
3612 __ sra(t2, key, kSmiTagSize);
3613 // Unsigned comparison catches both negative and too-large values.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003614 __ Branch(&miss_force_generic, Ugreater_equal, key, Operand(t1));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003615
3616 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3617 // a3: base pointer of external storage
3618
3619 // We are not untagging smi key and instead work with it
3620 // as if it was premultiplied by 2.
fschneider@chromium.org1805e212011-09-05 10:49:12 +00003621 STATIC_ASSERT((kSmiTag == 0) && (kSmiTagSize == 1));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003622
3623 Register value = a2;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003624 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003625 case EXTERNAL_BYTE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003626 __ srl(t2, key, 1);
3627 __ addu(t3, a3, t2);
3628 __ lb(value, MemOperand(t3, 0));
3629 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003630 case EXTERNAL_PIXEL_ELEMENTS:
3631 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003632 __ srl(t2, key, 1);
3633 __ addu(t3, a3, t2);
3634 __ lbu(value, MemOperand(t3, 0));
3635 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003636 case EXTERNAL_SHORT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003637 __ addu(t3, a3, key);
3638 __ lh(value, MemOperand(t3, 0));
3639 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003640 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003641 __ addu(t3, a3, key);
3642 __ lhu(value, MemOperand(t3, 0));
3643 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003644 case EXTERNAL_INT_ELEMENTS:
3645 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003646 __ sll(t2, key, 1);
3647 __ addu(t3, a3, t2);
3648 __ lw(value, MemOperand(t3, 0));
3649 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003650 case EXTERNAL_FLOAT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003651 __ sll(t3, t2, 2);
3652 __ addu(t3, a3, t3);
3653 if (CpuFeatures::IsSupported(FPU)) {
3654 CpuFeatures::Scope scope(FPU);
3655 __ lwc1(f0, MemOperand(t3, 0));
3656 } else {
3657 __ lw(value, MemOperand(t3, 0));
3658 }
3659 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003660 case EXTERNAL_DOUBLE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003661 __ sll(t2, key, 2);
3662 __ addu(t3, a3, t2);
3663 if (CpuFeatures::IsSupported(FPU)) {
3664 CpuFeatures::Scope scope(FPU);
3665 __ ldc1(f0, MemOperand(t3, 0));
3666 } else {
3667 // t3: pointer to the beginning of the double we want to load.
3668 __ lw(a2, MemOperand(t3, 0));
3669 __ lw(a3, MemOperand(t3, Register::kSizeInBytes));
3670 }
3671 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003672 case FAST_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003673 case FAST_SMI_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003674 case FAST_DOUBLE_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003675 case FAST_HOLEY_ELEMENTS:
3676 case FAST_HOLEY_SMI_ELEMENTS:
3677 case FAST_HOLEY_DOUBLE_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003678 case DICTIONARY_ELEMENTS:
3679 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003680 UNREACHABLE();
3681 break;
3682 }
3683
3684 // For integer array types:
3685 // a2: value
3686 // For float array type:
3687 // f0: value (if FPU is supported)
3688 // a2: value (if FPU is not supported)
3689 // For double array type:
3690 // f0: value (if FPU is supported)
3691 // a2/a3: value (if FPU is not supported)
3692
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003693 if (elements_kind == EXTERNAL_INT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003694 // For the Int and UnsignedInt array types, we need to see whether
3695 // the value can be represented in a Smi. If not, we need to convert
3696 // it to a HeapNumber.
3697 Label box_int;
3698 __ Subu(t3, value, Operand(0xC0000000)); // Non-smi value gives neg result.
3699 __ Branch(&box_int, lt, t3, Operand(zero_reg));
3700 // Tag integer as smi and return it.
3701 __ sll(v0, value, kSmiTagSize);
3702 __ Ret();
3703
3704 __ bind(&box_int);
3705 // Allocate a HeapNumber for the result and perform int-to-double
3706 // conversion.
3707 // The arm version uses a temporary here to save r0, but we don't need to
3708 // (a0 is not modified).
3709 __ LoadRoot(t1, Heap::kHeapNumberMapRootIndex);
3710 __ AllocateHeapNumber(v0, a3, t0, t1, &slow);
3711
3712 if (CpuFeatures::IsSupported(FPU)) {
3713 CpuFeatures::Scope scope(FPU);
3714 __ mtc1(value, f0);
3715 __ cvt_d_w(f0, f0);
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00003716 __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003717 __ Ret();
3718 } else {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003719 Register dst1 = t2;
3720 Register dst2 = t3;
3721 FloatingPointHelper::Destination dest =
3722 FloatingPointHelper::kCoreRegisters;
3723 FloatingPointHelper::ConvertIntToDouble(masm,
3724 value,
3725 dest,
3726 f0,
3727 dst1,
3728 dst2,
3729 t1,
3730 f2);
3731 __ sw(dst1, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
3732 __ sw(dst2, FieldMemOperand(v0, HeapNumber::kExponentOffset));
3733 __ Ret();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003734 }
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003735 } else if (elements_kind == EXTERNAL_UNSIGNED_INT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003736 // The test is different for unsigned int values. Since we need
3737 // the value to be in the range of a positive smi, we can't
3738 // handle either of the top two bits being set in the value.
3739 if (CpuFeatures::IsSupported(FPU)) {
3740 CpuFeatures::Scope scope(FPU);
3741 Label pl_box_int;
3742 __ And(t2, value, Operand(0xC0000000));
3743 __ Branch(&pl_box_int, ne, t2, Operand(zero_reg));
3744
3745 // It can fit in an Smi.
3746 // Tag integer as smi and return it.
3747 __ sll(v0, value, kSmiTagSize);
3748 __ Ret();
3749
3750 __ bind(&pl_box_int);
3751 // Allocate a HeapNumber for the result and perform int-to-double
3752 // conversion. Don't use a0 and a1 as AllocateHeapNumber clobbers all
3753 // registers - also when jumping due to exhausted young space.
3754 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3755 __ AllocateHeapNumber(v0, t2, t3, t6, &slow);
3756
3757 // This is replaced by a macro:
3758 // __ mtc1(value, f0); // LS 32-bits.
3759 // __ mtc1(zero_reg, f1); // MS 32-bits are all zero.
3760 // __ cvt_d_l(f0, f0); // Use 64 bit conv to get correct unsigned 32-bit.
3761
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00003762 __ Cvt_d_uw(f0, value, f22);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003763
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00003764 __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003765
3766 __ Ret();
3767 } else {
3768 // Check whether unsigned integer fits into smi.
3769 Label box_int_0, box_int_1, done;
3770 __ And(t2, value, Operand(0x80000000));
3771 __ Branch(&box_int_0, ne, t2, Operand(zero_reg));
3772 __ And(t2, value, Operand(0x40000000));
3773 __ Branch(&box_int_1, ne, t2, Operand(zero_reg));
3774
3775 // Tag integer as smi and return it.
3776 __ sll(v0, value, kSmiTagSize);
3777 __ Ret();
3778
3779 Register hiword = value; // a2.
3780 Register loword = a3;
3781
3782 __ bind(&box_int_0);
3783 // Integer does not have leading zeros.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003784 GenerateUInt2Double(masm, hiword, loword, t0, 0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003785 __ Branch(&done);
3786
3787 __ bind(&box_int_1);
3788 // Integer has one leading zero.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003789 GenerateUInt2Double(masm, hiword, loword, t0, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003790
3791
3792 __ bind(&done);
3793 // Integer was converted to double in registers hiword:loword.
3794 // Wrap it into a HeapNumber. Don't use a0 and a1 as AllocateHeapNumber
3795 // clobbers all registers - also when jumping due to exhausted young
3796 // space.
3797 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3798 __ AllocateHeapNumber(t2, t3, t5, t6, &slow);
3799
3800 __ sw(hiword, FieldMemOperand(t2, HeapNumber::kExponentOffset));
3801 __ sw(loword, FieldMemOperand(t2, HeapNumber::kMantissaOffset));
3802
3803 __ mov(v0, t2);
3804 __ Ret();
3805 }
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003806 } else if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003807 // For the floating-point array type, we need to always allocate a
3808 // HeapNumber.
3809 if (CpuFeatures::IsSupported(FPU)) {
3810 CpuFeatures::Scope scope(FPU);
3811 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3812 // AllocateHeapNumber clobbers all registers - also when jumping due to
3813 // exhausted young space.
3814 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3815 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3816 // The float (single) value is already in fpu reg f0 (if we use float).
3817 __ cvt_d_s(f0, f0);
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00003818 __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003819 __ Ret();
3820 } else {
3821 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3822 // AllocateHeapNumber clobbers all registers - also when jumping due to
3823 // exhausted young space.
3824 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3825 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3826 // FPU is not available, do manual single to double conversion.
3827
3828 // a2: floating point value (binary32).
3829 // v0: heap number for result
3830
3831 // Extract mantissa to t4.
3832 __ And(t4, value, Operand(kBinary32MantissaMask));
3833
3834 // Extract exponent to t5.
3835 __ srl(t5, value, kBinary32MantissaBits);
3836 __ And(t5, t5, Operand(kBinary32ExponentMask >> kBinary32MantissaBits));
3837
3838 Label exponent_rebiased;
3839 __ Branch(&exponent_rebiased, eq, t5, Operand(zero_reg));
3840
3841 __ li(t0, 0x7ff);
3842 __ Xor(t1, t5, Operand(0xFF));
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00003843 __ Movz(t5, t0, t1); // Set t5 to 0x7ff only if t5 is equal to 0xff.
rossberg@chromium.org400388e2012-06-06 09:29:22 +00003844 __ Branch(&exponent_rebiased, eq, t1, Operand(zero_reg));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003845
3846 // Rebias exponent.
3847 __ Addu(t5,
3848 t5,
3849 Operand(-kBinary32ExponentBias + HeapNumber::kExponentBias));
3850
3851 __ bind(&exponent_rebiased);
3852 __ And(a2, value, Operand(kBinary32SignMask));
3853 value = no_reg;
3854 __ sll(t0, t5, HeapNumber::kMantissaBitsInTopWord);
3855 __ or_(a2, a2, t0);
3856
3857 // Shift mantissa.
3858 static const int kMantissaShiftForHiWord =
3859 kBinary32MantissaBits - HeapNumber::kMantissaBitsInTopWord;
3860
3861 static const int kMantissaShiftForLoWord =
3862 kBitsPerInt - kMantissaShiftForHiWord;
3863
3864 __ srl(t0, t4, kMantissaShiftForHiWord);
3865 __ or_(a2, a2, t0);
3866 __ sll(a0, t4, kMantissaShiftForLoWord);
3867
3868 __ sw(a2, FieldMemOperand(v0, HeapNumber::kExponentOffset));
3869 __ sw(a0, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
3870 __ Ret();
3871 }
3872
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003873 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003874 if (CpuFeatures::IsSupported(FPU)) {
3875 CpuFeatures::Scope scope(FPU);
3876 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3877 // AllocateHeapNumber clobbers all registers - also when jumping due to
3878 // exhausted young space.
3879 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3880 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3881 // The double value is already in f0
3882 __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
3883 __ Ret();
3884 } else {
3885 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3886 // AllocateHeapNumber clobbers all registers - also when jumping due to
3887 // exhausted young space.
3888 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3889 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3890
3891 __ sw(a2, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
3892 __ sw(a3, FieldMemOperand(v0, HeapNumber::kExponentOffset));
3893 __ Ret();
3894 }
3895
3896 } else {
3897 // Tag integer as smi and return it.
3898 __ sll(v0, value, kSmiTagSize);
3899 __ Ret();
3900 }
3901
3902 // Slow case, key and receiver still in a0 and a1.
3903 __ bind(&slow);
3904 __ IncrementCounter(
danno@chromium.org40cb8782011-05-25 07:58:50 +00003905 masm->isolate()->counters()->keyed_load_external_array_slow(),
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003906 1, a2, a3);
3907
3908 // ---------- S t a t e --------------
3909 // -- ra : return address
3910 // -- a0 : key
3911 // -- a1 : receiver
3912 // -----------------------------------
3913
3914 __ Push(a1, a0);
3915
3916 __ TailCallRuntime(Runtime::kKeyedGetProperty, 2, 1);
3917
danno@chromium.org40cb8782011-05-25 07:58:50 +00003918 __ bind(&miss_force_generic);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003919 Handle<Code> stub =
3920 masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric();
3921 __ Jump(stub, RelocInfo::CODE_TARGET);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003922}
3923
3924
danno@chromium.org40cb8782011-05-25 07:58:50 +00003925void KeyedStoreStubCompiler::GenerateStoreExternalArray(
3926 MacroAssembler* masm,
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003927 ElementsKind elements_kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003928 // ---------- S t a t e --------------
3929 // -- a0 : value
3930 // -- a1 : key
3931 // -- a2 : receiver
3932 // -- ra : return address
3933 // -----------------------------------
3934
danno@chromium.org40cb8782011-05-25 07:58:50 +00003935 Label slow, check_heap_number, miss_force_generic;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003936
3937 // Register usage.
3938 Register value = a0;
3939 Register key = a1;
3940 Register receiver = a2;
3941 // a3 mostly holds the elements array or the destination external array.
3942
danno@chromium.org40cb8782011-05-25 07:58:50 +00003943 // This stub is meant to be tail-jumped to, the receiver must already
3944 // have been verified by the caller to not be a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003945
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003946 // Check that the key is a smi or a heap number convertible to a smi.
3947 GenerateSmiKeyCheck(masm, key, t0, t1, f2, &miss_force_generic);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003948
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003949 __ lw(a3, FieldMemOperand(receiver, JSObject::kElementsOffset));
3950
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003951 // Check that the index is in range.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003952 __ lw(t1, FieldMemOperand(a3, ExternalArray::kLengthOffset));
3953 // Unsigned comparison catches both negative and too-large values.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003954 __ Branch(&miss_force_generic, Ugreater_equal, key, Operand(t1));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003955
3956 // Handle both smis and HeapNumbers in the fast path. Go to the
3957 // runtime for all other kinds of values.
3958 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003959
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003960 if (elements_kind == EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003961 // Double to pixel conversion is only implemented in the runtime for now.
3962 __ JumpIfNotSmi(value, &slow);
3963 } else {
3964 __ JumpIfNotSmi(value, &check_heap_number);
3965 }
3966 __ SmiUntag(t1, value);
3967 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3968
3969 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003970 // t1: value (integer).
3971
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003972 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003973 case EXTERNAL_PIXEL_ELEMENTS: {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003974 // Clamp the value to [0..255].
3975 // v0 is used as a scratch register here.
3976 Label done;
3977 __ li(v0, Operand(255));
3978 // Normal branch: nop in delay slot.
3979 __ Branch(&done, gt, t1, Operand(v0));
3980 // Use delay slot in this branch.
3981 __ Branch(USE_DELAY_SLOT, &done, lt, t1, Operand(zero_reg));
3982 __ mov(v0, zero_reg); // In delay slot.
3983 __ mov(v0, t1); // Value is in range 0..255.
3984 __ bind(&done);
3985 __ mov(t1, v0);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003986
3987 __ srl(t8, key, 1);
3988 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003989 __ sb(t1, MemOperand(t8, 0));
3990 }
3991 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003992 case EXTERNAL_BYTE_ELEMENTS:
3993 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003994 __ srl(t8, key, 1);
3995 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003996 __ sb(t1, MemOperand(t8, 0));
3997 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003998 case EXTERNAL_SHORT_ELEMENTS:
3999 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004000 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004001 __ sh(t1, MemOperand(t8, 0));
4002 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004003 case EXTERNAL_INT_ELEMENTS:
4004 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004005 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004006 __ addu(t8, a3, t8);
4007 __ sw(t1, MemOperand(t8, 0));
4008 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004009 case EXTERNAL_FLOAT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004010 // Perform int-to-float conversion and store to memory.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004011 __ SmiUntag(t0, key);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004012 StoreIntAsFloat(masm, a3, t0, t1, t2, t3, t4);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004013 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004014 case EXTERNAL_DOUBLE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004015 __ sll(t8, key, 2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004016 __ addu(a3, a3, t8);
4017 // a3: effective address of the double element
4018 FloatingPointHelper::Destination destination;
4019 if (CpuFeatures::IsSupported(FPU)) {
4020 destination = FloatingPointHelper::kFPURegisters;
4021 } else {
4022 destination = FloatingPointHelper::kCoreRegisters;
4023 }
4024 FloatingPointHelper::ConvertIntToDouble(
danno@chromium.org40cb8782011-05-25 07:58:50 +00004025 masm, t1, destination,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004026 f0, t2, t3, // These are: double_dst, dst1, dst2.
4027 t0, f2); // These are: scratch2, single_scratch.
4028 if (destination == FloatingPointHelper::kFPURegisters) {
4029 CpuFeatures::Scope scope(FPU);
4030 __ sdc1(f0, MemOperand(a3, 0));
4031 } else {
4032 __ sw(t2, MemOperand(a3, 0));
4033 __ sw(t3, MemOperand(a3, Register::kSizeInBytes));
4034 }
4035 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004036 case FAST_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00004037 case FAST_SMI_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004038 case FAST_DOUBLE_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00004039 case FAST_HOLEY_ELEMENTS:
4040 case FAST_HOLEY_SMI_ELEMENTS:
4041 case FAST_HOLEY_DOUBLE_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004042 case DICTIONARY_ELEMENTS:
4043 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004044 UNREACHABLE();
4045 break;
4046 }
4047
4048 // Entry registers are intact, a0 holds the value which is the return value.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004049 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004050 __ Ret();
4051
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004052 if (elements_kind != EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004053 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004054 __ bind(&check_heap_number);
4055 __ GetObjectType(value, t1, t2);
4056 __ Branch(&slow, ne, t2, Operand(HEAP_NUMBER_TYPE));
4057
4058 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
4059
4060 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004061
4062 // The WebGL specification leaves the behavior of storing NaN and
4063 // +/-Infinity into integer arrays basically undefined. For more
4064 // reproducible behavior, convert these to zero.
4065
4066 if (CpuFeatures::IsSupported(FPU)) {
4067 CpuFeatures::Scope scope(FPU);
4068
4069 __ ldc1(f0, FieldMemOperand(a0, HeapNumber::kValueOffset));
4070
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004071 if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004072 __ cvt_s_d(f0, f0);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004073 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004074 __ addu(t8, a3, t8);
4075 __ swc1(f0, MemOperand(t8, 0));
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004076 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004077 __ sll(t8, key, 2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004078 __ addu(t8, a3, t8);
4079 __ sdc1(f0, MemOperand(t8, 0));
4080 } else {
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00004081 __ EmitECMATruncate(t3, f0, f2, t2, t1, t5);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004082
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004083 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004084 case EXTERNAL_BYTE_ELEMENTS:
4085 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004086 __ srl(t8, key, 1);
4087 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004088 __ sb(t3, MemOperand(t8, 0));
4089 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004090 case EXTERNAL_SHORT_ELEMENTS:
4091 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004092 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004093 __ sh(t3, MemOperand(t8, 0));
4094 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004095 case EXTERNAL_INT_ELEMENTS:
4096 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004097 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004098 __ addu(t8, a3, t8);
4099 __ sw(t3, MemOperand(t8, 0));
4100 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004101 case EXTERNAL_PIXEL_ELEMENTS:
4102 case EXTERNAL_FLOAT_ELEMENTS:
4103 case EXTERNAL_DOUBLE_ELEMENTS:
4104 case FAST_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00004105 case FAST_SMI_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004106 case FAST_DOUBLE_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00004107 case FAST_HOLEY_ELEMENTS:
4108 case FAST_HOLEY_SMI_ELEMENTS:
4109 case FAST_HOLEY_DOUBLE_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004110 case DICTIONARY_ELEMENTS:
4111 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004112 UNREACHABLE();
4113 break;
4114 }
4115 }
4116
4117 // Entry registers are intact, a0 holds the value
4118 // which is the return value.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004119 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004120 __ Ret();
4121 } else {
4122 // FPU is not available, do manual conversions.
4123
4124 __ lw(t3, FieldMemOperand(value, HeapNumber::kExponentOffset));
4125 __ lw(t4, FieldMemOperand(value, HeapNumber::kMantissaOffset));
4126
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004127 if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004128 Label done, nan_or_infinity_or_zero;
4129 static const int kMantissaInHiWordShift =
4130 kBinary32MantissaBits - HeapNumber::kMantissaBitsInTopWord;
4131
4132 static const int kMantissaInLoWordShift =
4133 kBitsPerInt - kMantissaInHiWordShift;
4134
4135 // Test for all special exponent values: zeros, subnormal numbers, NaNs
4136 // and infinities. All these should be converted to 0.
4137 __ li(t5, HeapNumber::kExponentMask);
4138 __ and_(t6, t3, t5);
4139 __ Branch(&nan_or_infinity_or_zero, eq, t6, Operand(zero_reg));
4140
4141 __ xor_(t1, t6, t5);
4142 __ li(t2, kBinary32ExponentMask);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00004143 __ Movz(t6, t2, t1); // Only if t6 is equal to t5.
rossberg@chromium.org400388e2012-06-06 09:29:22 +00004144 __ Branch(&nan_or_infinity_or_zero, eq, t1, Operand(zero_reg));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004145
4146 // Rebias exponent.
4147 __ srl(t6, t6, HeapNumber::kExponentShift);
4148 __ Addu(t6,
4149 t6,
4150 Operand(kBinary32ExponentBias - HeapNumber::kExponentBias));
4151
4152 __ li(t1, Operand(kBinary32MaxExponent));
4153 __ Slt(t1, t1, t6);
4154 __ And(t2, t3, Operand(HeapNumber::kSignMask));
4155 __ Or(t2, t2, Operand(kBinary32ExponentMask));
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00004156 __ Movn(t3, t2, t1); // Only if t6 is gt kBinary32MaxExponent.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004157 __ Branch(&done, gt, t6, Operand(kBinary32MaxExponent));
4158
4159 __ Slt(t1, t6, Operand(kBinary32MinExponent));
4160 __ And(t2, t3, Operand(HeapNumber::kSignMask));
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00004161 __ Movn(t3, t2, t1); // Only if t6 is lt kBinary32MinExponent.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004162 __ Branch(&done, lt, t6, Operand(kBinary32MinExponent));
4163
4164 __ And(t7, t3, Operand(HeapNumber::kSignMask));
4165 __ And(t3, t3, Operand(HeapNumber::kMantissaMask));
4166 __ sll(t3, t3, kMantissaInHiWordShift);
4167 __ or_(t7, t7, t3);
4168 __ srl(t4, t4, kMantissaInLoWordShift);
4169 __ or_(t7, t7, t4);
4170 __ sll(t6, t6, kBinary32ExponentShift);
4171 __ or_(t3, t7, t6);
4172
4173 __ bind(&done);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004174 __ sll(t9, key, 1);
rossberg@chromium.org400388e2012-06-06 09:29:22 +00004175 __ addu(t9, a3, t9);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004176 __ sw(t3, MemOperand(t9, 0));
4177
4178 // Entry registers are intact, a0 holds the value which is the return
4179 // value.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004180 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004181 __ Ret();
4182
4183 __ bind(&nan_or_infinity_or_zero);
4184 __ And(t7, t3, Operand(HeapNumber::kSignMask));
4185 __ And(t3, t3, Operand(HeapNumber::kMantissaMask));
4186 __ or_(t6, t6, t7);
4187 __ sll(t3, t3, kMantissaInHiWordShift);
4188 __ or_(t6, t6, t3);
4189 __ srl(t4, t4, kMantissaInLoWordShift);
4190 __ or_(t3, t6, t4);
4191 __ Branch(&done);
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004192 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
rossberg@chromium.org400388e2012-06-06 09:29:22 +00004193 __ sll(t8, key, 2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004194 __ addu(t8, a3, t8);
4195 // t8: effective address of destination element.
4196 __ sw(t4, MemOperand(t8, 0));
4197 __ sw(t3, MemOperand(t8, Register::kSizeInBytes));
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004198 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004199 __ Ret();
4200 } else {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004201 bool is_signed_type = IsElementTypeSigned(elements_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004202 int meaningfull_bits = is_signed_type ? (kBitsPerInt - 1) : kBitsPerInt;
4203 int32_t min_value = is_signed_type ? 0x80000000 : 0x00000000;
4204
4205 Label done, sign;
4206
4207 // Test for all special exponent values: zeros, subnormal numbers, NaNs
4208 // and infinities. All these should be converted to 0.
4209 __ li(t5, HeapNumber::kExponentMask);
4210 __ and_(t6, t3, t5);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00004211 __ Movz(t3, zero_reg, t6); // Only if t6 is equal to zero.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004212 __ Branch(&done, eq, t6, Operand(zero_reg));
4213
4214 __ xor_(t2, t6, t5);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00004215 __ Movz(t3, zero_reg, t2); // Only if t6 is equal to t5.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004216 __ Branch(&done, eq, t6, Operand(t5));
4217
4218 // Unbias exponent.
4219 __ srl(t6, t6, HeapNumber::kExponentShift);
4220 __ Subu(t6, t6, Operand(HeapNumber::kExponentBias));
4221 // If exponent is negative then result is 0.
4222 __ slt(t2, t6, zero_reg);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00004223 __ Movn(t3, zero_reg, t2); // Only if exponent is negative.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004224 __ Branch(&done, lt, t6, Operand(zero_reg));
4225
4226 // If exponent is too big then result is minimal value.
4227 __ slti(t1, t6, meaningfull_bits - 1);
4228 __ li(t2, min_value);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00004229 __ Movz(t3, t2, t1); // Only if t6 is ge meaningfull_bits - 1.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004230 __ Branch(&done, ge, t6, Operand(meaningfull_bits - 1));
4231
4232 __ And(t5, t3, Operand(HeapNumber::kSignMask));
4233 __ And(t3, t3, Operand(HeapNumber::kMantissaMask));
4234 __ Or(t3, t3, Operand(1u << HeapNumber::kMantissaBitsInTopWord));
4235
4236 __ li(t9, HeapNumber::kMantissaBitsInTopWord);
4237 __ subu(t6, t9, t6);
4238 __ slt(t1, t6, zero_reg);
4239 __ srlv(t2, t3, t6);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00004240 __ Movz(t3, t2, t1); // Only if t6 is positive.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004241 __ Branch(&sign, ge, t6, Operand(zero_reg));
4242
4243 __ subu(t6, zero_reg, t6);
4244 __ sllv(t3, t3, t6);
4245 __ li(t9, meaningfull_bits);
4246 __ subu(t6, t9, t6);
4247 __ srlv(t4, t4, t6);
4248 __ or_(t3, t3, t4);
4249
4250 __ bind(&sign);
4251 __ subu(t2, t3, zero_reg);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00004252 __ Movz(t3, t2, t5); // Only if t5 is zero.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004253
4254 __ bind(&done);
4255
4256 // Result is in t3.
4257 // This switch block should be exactly the same as above (FPU mode).
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004258 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004259 case EXTERNAL_BYTE_ELEMENTS:
4260 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004261 __ srl(t8, key, 1);
4262 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004263 __ sb(t3, MemOperand(t8, 0));
4264 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004265 case EXTERNAL_SHORT_ELEMENTS:
4266 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004267 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004268 __ sh(t3, MemOperand(t8, 0));
4269 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004270 case EXTERNAL_INT_ELEMENTS:
4271 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004272 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004273 __ addu(t8, a3, t8);
4274 __ sw(t3, MemOperand(t8, 0));
4275 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004276 case EXTERNAL_PIXEL_ELEMENTS:
4277 case EXTERNAL_FLOAT_ELEMENTS:
4278 case EXTERNAL_DOUBLE_ELEMENTS:
4279 case FAST_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00004280 case FAST_SMI_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004281 case FAST_DOUBLE_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00004282 case FAST_HOLEY_ELEMENTS:
4283 case FAST_HOLEY_SMI_ELEMENTS:
4284 case FAST_HOLEY_DOUBLE_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004285 case DICTIONARY_ELEMENTS:
4286 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004287 UNREACHABLE();
4288 break;
4289 }
4290 }
4291 }
4292 }
4293
danno@chromium.org40cb8782011-05-25 07:58:50 +00004294 // Slow case, key and receiver still in a0 and a1.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004295 __ bind(&slow);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004296 __ IncrementCounter(
4297 masm->isolate()->counters()->keyed_load_external_array_slow(),
4298 1, a2, a3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004299 // Entry registers are intact.
4300 // ---------- S t a t e --------------
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004301 // -- ra : return address
danno@chromium.org40cb8782011-05-25 07:58:50 +00004302 // -- a0 : key
4303 // -- a1 : receiver
4304 // -----------------------------------
4305 Handle<Code> slow_ic =
4306 masm->isolate()->builtins()->KeyedStoreIC_Slow();
4307 __ Jump(slow_ic, RelocInfo::CODE_TARGET);
4308
4309 // Miss case, call the runtime.
4310 __ bind(&miss_force_generic);
4311
4312 // ---------- S t a t e --------------
4313 // -- ra : return address
4314 // -- a0 : key
4315 // -- a1 : receiver
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004316 // -----------------------------------
4317
danno@chromium.org40cb8782011-05-25 07:58:50 +00004318 Handle<Code> miss_ic =
4319 masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric();
4320 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
4321}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004322
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004323
danno@chromium.org40cb8782011-05-25 07:58:50 +00004324void KeyedLoadStubCompiler::GenerateLoadFastElement(MacroAssembler* masm) {
4325 // ----------- S t a t e -------------
4326 // -- ra : return address
4327 // -- a0 : key
4328 // -- a1 : receiver
4329 // -----------------------------------
4330 Label miss_force_generic;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004331
danno@chromium.org40cb8782011-05-25 07:58:50 +00004332 // This stub is meant to be tail-jumped to, the receiver must already
4333 // have been verified by the caller to not be a smi.
4334
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00004335 // Check that the key is a smi or a heap number convertible to a smi.
4336 GenerateSmiKeyCheck(masm, a0, t0, t1, f2, &miss_force_generic);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004337
4338 // Get the elements array.
4339 __ lw(a2, FieldMemOperand(a1, JSObject::kElementsOffset));
4340 __ AssertFastElements(a2);
4341
4342 // Check that the key is within bounds.
4343 __ lw(a3, FieldMemOperand(a2, FixedArray::kLengthOffset));
ulan@chromium.org6ff65142012-03-21 09:52:17 +00004344 __ Branch(USE_DELAY_SLOT, &miss_force_generic, hs, a0, Operand(a3));
danno@chromium.org40cb8782011-05-25 07:58:50 +00004345
4346 // Load the result and make sure it's not the hole.
4347 __ Addu(a3, a2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
fschneider@chromium.org1805e212011-09-05 10:49:12 +00004348 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004349 __ sll(t0, a0, kPointerSizeLog2 - kSmiTagSize);
4350 __ Addu(t0, t0, a3);
4351 __ lw(t0, MemOperand(t0));
4352 __ LoadRoot(t1, Heap::kTheHoleValueRootIndex);
4353 __ Branch(&miss_force_generic, eq, t0, Operand(t1));
ulan@chromium.org6ff65142012-03-21 09:52:17 +00004354 __ Ret(USE_DELAY_SLOT);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004355 __ mov(v0, t0);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004356
4357 __ bind(&miss_force_generic);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00004358 Handle<Code> stub =
4359 masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric();
4360 __ Jump(stub, RelocInfo::CODE_TARGET);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004361}
4362
4363
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00004364void KeyedLoadStubCompiler::GenerateLoadFastDoubleElement(
4365 MacroAssembler* masm) {
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004366 // ----------- S t a t e -------------
4367 // -- ra : return address
4368 // -- a0 : key
4369 // -- a1 : receiver
4370 // -----------------------------------
4371 Label miss_force_generic, slow_allocate_heapnumber;
4372
4373 Register key_reg = a0;
4374 Register receiver_reg = a1;
4375 Register elements_reg = a2;
4376 Register heap_number_reg = a2;
4377 Register indexed_double_offset = a3;
4378 Register scratch = t0;
4379 Register scratch2 = t1;
4380 Register scratch3 = t2;
4381 Register heap_number_map = t3;
4382
4383 // This stub is meant to be tail-jumped to, the receiver must already
4384 // have been verified by the caller to not be a smi.
4385
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00004386 // Check that the key is a smi or a heap number convertible to a smi.
4387 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, &miss_force_generic);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004388
4389 // Get the elements array.
4390 __ lw(elements_reg,
4391 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4392
4393 // Check that the key is within bounds.
4394 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4395 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch));
4396
4397 // Load the upper word of the double in the fixed array and test for NaN.
4398 __ sll(scratch2, key_reg, kDoubleSizeLog2 - kSmiTagSize);
4399 __ Addu(indexed_double_offset, elements_reg, Operand(scratch2));
4400 uint32_t upper_32_offset = FixedArray::kHeaderSize + sizeof(kHoleNanLower32);
4401 __ lw(scratch, FieldMemOperand(indexed_double_offset, upper_32_offset));
4402 __ Branch(&miss_force_generic, eq, scratch, Operand(kHoleNanUpper32));
4403
4404 // Non-NaN. Allocate a new heap number and copy the double value into it.
4405 __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
4406 __ AllocateHeapNumber(heap_number_reg, scratch2, scratch3,
4407 heap_number_map, &slow_allocate_heapnumber);
4408
4409 // Don't need to reload the upper 32 bits of the double, it's already in
4410 // scratch.
4411 __ sw(scratch, FieldMemOperand(heap_number_reg,
4412 HeapNumber::kExponentOffset));
4413 __ lw(scratch, FieldMemOperand(indexed_double_offset,
4414 FixedArray::kHeaderSize));
4415 __ sw(scratch, FieldMemOperand(heap_number_reg,
4416 HeapNumber::kMantissaOffset));
4417
4418 __ mov(v0, heap_number_reg);
4419 __ Ret();
4420
4421 __ bind(&slow_allocate_heapnumber);
4422 Handle<Code> slow_ic =
4423 masm->isolate()->builtins()->KeyedLoadIC_Slow();
4424 __ Jump(slow_ic, RelocInfo::CODE_TARGET);
4425
4426 __ bind(&miss_force_generic);
4427 Handle<Code> miss_ic =
4428 masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric();
4429 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00004430}
4431
4432
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004433void KeyedStoreStubCompiler::GenerateStoreFastElement(
4434 MacroAssembler* masm,
4435 bool is_js_array,
yangguo@chromium.org56454712012-02-16 15:33:53 +00004436 ElementsKind elements_kind,
4437 KeyedAccessGrowMode grow_mode) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00004438 // ----------- S t a t e -------------
4439 // -- a0 : value
4440 // -- a1 : key
4441 // -- a2 : receiver
4442 // -- ra : return address
4443 // -- a3 : scratch
4444 // -- a4 : scratch (elements)
4445 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00004446 Label miss_force_generic, transition_elements_kind, grow, slow;
4447 Label finish_store, check_capacity;
danno@chromium.org40cb8782011-05-25 07:58:50 +00004448
4449 Register value_reg = a0;
4450 Register key_reg = a1;
4451 Register receiver_reg = a2;
yangguo@chromium.org56454712012-02-16 15:33:53 +00004452 Register scratch = t0;
4453 Register elements_reg = a3;
4454 Register length_reg = t1;
4455 Register scratch2 = t2;
danno@chromium.org40cb8782011-05-25 07:58:50 +00004456
4457 // This stub is meant to be tail-jumped to, the receiver must already
4458 // have been verified by the caller to not be a smi.
4459
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00004460 // Check that the key is a smi or a heap number convertible to a smi.
4461 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, &miss_force_generic);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004462
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00004463 if (IsFastSmiElementsKind(elements_kind)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00004464 __ JumpIfNotSmi(value_reg, &transition_elements_kind);
4465 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00004466
4467 // Check that the key is within bounds.
yangguo@chromium.org56454712012-02-16 15:33:53 +00004468 __ lw(elements_reg,
4469 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00004470 if (is_js_array) {
4471 __ lw(scratch, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4472 } else {
4473 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4474 }
4475 // Compare smis.
yangguo@chromium.org56454712012-02-16 15:33:53 +00004476 if (is_js_array && grow_mode == ALLOW_JSARRAY_GROWTH) {
4477 __ Branch(&grow, hs, key_reg, Operand(scratch));
4478 } else {
4479 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch));
4480 }
4481
4482 // Make sure elements is a fast element array, not 'cow'.
4483 __ CheckMap(elements_reg,
4484 scratch,
4485 Heap::kFixedArrayMapRootIndex,
4486 &miss_force_generic,
4487 DONT_DO_SMI_CHECK);
4488
4489 __ bind(&finish_store);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004490
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00004491 if (IsFastSmiElementsKind(elements_kind)) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004492 __ Addu(scratch,
4493 elements_reg,
4494 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4495 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
4496 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
4497 __ Addu(scratch, scratch, scratch2);
4498 __ sw(value_reg, MemOperand(scratch));
4499 } else {
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00004500 ASSERT(IsFastObjectElementsKind(elements_kind));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004501 __ Addu(scratch,
4502 elements_reg,
4503 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4504 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
4505 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
4506 __ Addu(scratch, scratch, scratch2);
4507 __ sw(value_reg, MemOperand(scratch));
4508 __ mov(receiver_reg, value_reg);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004509 __ RecordWrite(elements_reg, // Object.
4510 scratch, // Address.
4511 receiver_reg, // Value.
4512 kRAHasNotBeenSaved,
4513 kDontSaveFPRegs);
4514 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00004515 // value_reg (a0) is preserved.
4516 // Done.
4517 __ Ret();
4518
4519 __ bind(&miss_force_generic);
4520 Handle<Code> ic =
4521 masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric();
4522 __ Jump(ic, RelocInfo::CODE_TARGET);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004523
4524 __ bind(&transition_elements_kind);
4525 Handle<Code> ic_miss = masm->isolate()->builtins()->KeyedStoreIC_Miss();
4526 __ Jump(ic_miss, RelocInfo::CODE_TARGET);
yangguo@chromium.org56454712012-02-16 15:33:53 +00004527
4528 if (is_js_array && grow_mode == ALLOW_JSARRAY_GROWTH) {
4529 // Grow the array by a single element if possible.
4530 __ bind(&grow);
4531
4532 // Make sure the array is only growing by a single element, anything else
4533 // must be handled by the runtime.
4534 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch));
4535
4536 // Check for the empty array, and preallocate a small backing store if
4537 // possible.
4538 __ lw(length_reg,
4539 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4540 __ lw(elements_reg,
4541 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4542 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
4543 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
4544
4545 int size = FixedArray::SizeFor(JSArray::kPreallocatedArrayElements);
4546 __ AllocateInNewSpace(size, elements_reg, scratch, scratch2, &slow,
4547 TAG_OBJECT);
4548
4549 __ LoadRoot(scratch, Heap::kFixedArrayMapRootIndex);
4550 __ sw(scratch, FieldMemOperand(elements_reg, JSObject::kMapOffset));
4551 __ li(scratch, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
4552 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4553 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
4554 for (int i = 1; i < JSArray::kPreallocatedArrayElements; ++i) {
4555 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::SizeFor(i)));
4556 }
4557
4558 // Store the element at index zero.
4559 __ sw(value_reg, FieldMemOperand(elements_reg, FixedArray::SizeFor(0)));
4560
4561 // Install the new backing store in the JSArray.
4562 __ sw(elements_reg,
4563 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4564 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
4565 scratch, kRAHasNotBeenSaved, kDontSaveFPRegs,
4566 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4567
4568 // Increment the length of the array.
4569 __ li(length_reg, Operand(Smi::FromInt(1)));
4570 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4571 __ Ret();
4572
4573 __ bind(&check_capacity);
4574 // Check for cow elements, in general they are not handled by this stub
4575 __ CheckMap(elements_reg,
4576 scratch,
4577 Heap::kFixedCOWArrayMapRootIndex,
4578 &miss_force_generic,
4579 DONT_DO_SMI_CHECK);
4580
4581 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4582 __ Branch(&slow, hs, length_reg, Operand(scratch));
4583
4584 // Grow the array and finish the store.
4585 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
4586 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4587 __ jmp(&finish_store);
4588
4589 __ bind(&slow);
4590 Handle<Code> ic_slow = masm->isolate()->builtins()->KeyedStoreIC_Slow();
4591 __ Jump(ic_slow, RelocInfo::CODE_TARGET);
4592 }
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00004593}
4594
4595
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00004596void KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(
4597 MacroAssembler* masm,
yangguo@chromium.org56454712012-02-16 15:33:53 +00004598 bool is_js_array,
4599 KeyedAccessGrowMode grow_mode) {
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004600 // ----------- S t a t e -------------
4601 // -- a0 : value
4602 // -- a1 : key
4603 // -- a2 : receiver
4604 // -- ra : return address
4605 // -- a3 : scratch
4606 // -- t0 : scratch (elements_reg)
4607 // -- t1 : scratch (mantissa_reg)
4608 // -- t2 : scratch (exponent_reg)
4609 // -- t3 : scratch4
4610 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00004611 Label miss_force_generic, transition_elements_kind, grow, slow;
4612 Label finish_store, check_capacity;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004613
4614 Register value_reg = a0;
4615 Register key_reg = a1;
4616 Register receiver_reg = a2;
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004617 Register elements_reg = a3;
4618 Register scratch1 = t0;
4619 Register scratch2 = t1;
4620 Register scratch3 = t2;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004621 Register scratch4 = t3;
yangguo@chromium.org56454712012-02-16 15:33:53 +00004622 Register length_reg = t3;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004623
4624 // This stub is meant to be tail-jumped to, the receiver must already
4625 // have been verified by the caller to not be a smi.
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00004626
4627 // Check that the key is a smi or a heap number convertible to a smi.
4628 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, &miss_force_generic);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004629
4630 __ lw(elements_reg,
4631 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4632
4633 // Check that the key is within bounds.
4634 if (is_js_array) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004635 __ lw(scratch1, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004636 } else {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004637 __ lw(scratch1,
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004638 FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4639 }
4640 // Compare smis, unsigned compare catches both negative and out-of-bound
4641 // indexes.
yangguo@chromium.org56454712012-02-16 15:33:53 +00004642 if (grow_mode == ALLOW_JSARRAY_GROWTH) {
4643 __ Branch(&grow, hs, key_reg, Operand(scratch1));
4644 } else {
4645 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch1));
4646 }
4647
4648 __ bind(&finish_store);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004649
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004650 __ StoreNumberToDoubleElements(value_reg,
4651 key_reg,
4652 receiver_reg,
4653 elements_reg,
4654 scratch1,
4655 scratch2,
4656 scratch3,
4657 scratch4,
4658 &transition_elements_kind);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004659
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00004660 __ Ret(USE_DELAY_SLOT);
4661 __ mov(v0, value_reg); // In delay slot.
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004662
4663 // Handle store cache miss, replacing the ic with the generic stub.
4664 __ bind(&miss_force_generic);
4665 Handle<Code> ic =
4666 masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric();
4667 __ Jump(ic, RelocInfo::CODE_TARGET);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004668
4669 __ bind(&transition_elements_kind);
4670 Handle<Code> ic_miss = masm->isolate()->builtins()->KeyedStoreIC_Miss();
4671 __ Jump(ic_miss, RelocInfo::CODE_TARGET);
yangguo@chromium.org56454712012-02-16 15:33:53 +00004672
4673 if (is_js_array && grow_mode == ALLOW_JSARRAY_GROWTH) {
4674 // Grow the array by a single element if possible.
4675 __ bind(&grow);
4676
4677 // Make sure the array is only growing by a single element, anything else
4678 // must be handled by the runtime.
4679 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch1));
4680
4681 // Transition on values that can't be stored in a FixedDoubleArray.
4682 Label value_is_smi;
4683 __ JumpIfSmi(value_reg, &value_is_smi);
4684 __ lw(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
4685 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex);
4686 __ Branch(&transition_elements_kind, ne, scratch1, Operand(at));
4687 __ bind(&value_is_smi);
4688
4689 // Check for the empty array, and preallocate a small backing store if
4690 // possible.
4691 __ lw(length_reg,
4692 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4693 __ lw(elements_reg,
4694 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4695 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
4696 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
4697
4698 int size = FixedDoubleArray::SizeFor(JSArray::kPreallocatedArrayElements);
4699 __ AllocateInNewSpace(size, elements_reg, scratch1, scratch2, &slow,
4700 TAG_OBJECT);
4701
4702 // Initialize the new FixedDoubleArray. Leave elements unitialized for
4703 // efficiency, they are guaranteed to be initialized before use.
4704 __ LoadRoot(scratch1, Heap::kFixedDoubleArrayMapRootIndex);
4705 __ sw(scratch1, FieldMemOperand(elements_reg, JSObject::kMapOffset));
4706 __ li(scratch1, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
4707 __ sw(scratch1,
4708 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
4709
4710 // Install the new backing store in the JSArray.
4711 __ sw(elements_reg,
4712 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4713 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
4714 scratch1, kRAHasNotBeenSaved, kDontSaveFPRegs,
4715 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4716
4717 // Increment the length of the array.
4718 __ li(length_reg, Operand(Smi::FromInt(1)));
4719 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
danno@chromium.org00379b82012-05-04 09:16:29 +00004720 __ lw(elements_reg,
4721 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
yangguo@chromium.org56454712012-02-16 15:33:53 +00004722 __ jmp(&finish_store);
4723
4724 __ bind(&check_capacity);
4725 // Make sure that the backing store can hold additional elements.
4726 __ lw(scratch1,
4727 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
4728 __ Branch(&slow, hs, length_reg, Operand(scratch1));
4729
4730 // Grow the array and finish the store.
4731 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
4732 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4733 __ jmp(&finish_store);
4734
4735 __ bind(&slow);
4736 Handle<Code> ic_slow = masm->isolate()->builtins()->KeyedStoreIC_Slow();
4737 __ Jump(ic_slow, RelocInfo::CODE_TARGET);
4738 }
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00004739}
4740
4741
ager@chromium.org5c838252010-02-19 08:53:10 +00004742#undef __
4743
4744} } // namespace v8::internal
4745
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00004746#endif // V8_TARGET_ARCH_MIPS