blob: fde5ba994c1cf04b7583173da8d38ac1d40adbd5 [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,
ager@chromium.org5c838252010-02-19 08:53:10 +0000425 Register receiver_reg,
426 Register name_reg,
427 Register scratch,
428 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000429 // a0 : value.
430 Label exit;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +0000431 // Check that the map of the object hasn't changed.
432 __ CheckMap(receiver_reg, scratch, Handle<Map>(object->map()), miss_label,
433 DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000434
435 // Perform global security token check if needed.
436 if (object->IsJSGlobalProxy()) {
437 __ CheckAccessGlobalProxy(receiver_reg, scratch, miss_label);
438 }
439
440 // Stub never generated for non-global objects that require access
441 // checks.
442 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
443
444 // Perform map transition for the receiver if necessary.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000445 if (!transition.is_null() && (object->map()->unused_property_fields() == 0)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000446 // The properties must be extended before we can store the value.
447 // We jump to a runtime call that extends the properties array.
448 __ push(receiver_reg);
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000449 __ li(a2, Operand(transition));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000450 __ Push(a2, a0);
451 __ TailCallExternalReference(
452 ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
453 masm->isolate()),
454 3, 1);
455 return;
456 }
457
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000458 if (!transition.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000459 // Update the map of the object; no write barrier updating is
460 // needed because the map is never in new space.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000461 __ li(t0, Operand(transition));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000462 __ sw(t0, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
463 }
464
465 // Adjust for the number of properties stored in the object. Even in the
466 // face of a transition we can use the old map here because the size of the
467 // object and the number of in-object properties is not going to change.
468 index -= object->map()->inobject_properties();
469
470 if (index < 0) {
471 // Set the property straight into the object.
472 int offset = object->map()->instance_size() + (index * kPointerSize);
473 __ sw(a0, FieldMemOperand(receiver_reg, offset));
474
475 // Skip updating write barrier if storing a smi.
476 __ JumpIfSmi(a0, &exit, scratch);
477
478 // Update the write barrier for the array address.
479 // Pass the now unused name_reg as a scratch register.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000480 __ mov(name_reg, a0);
481 __ RecordWriteField(receiver_reg,
482 offset,
483 name_reg,
484 scratch,
485 kRAHasNotBeenSaved,
486 kDontSaveFPRegs);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000487 } else {
488 // Write to the properties array.
489 int offset = index * kPointerSize + FixedArray::kHeaderSize;
490 // Get the properties array.
491 __ lw(scratch, FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
492 __ sw(a0, FieldMemOperand(scratch, offset));
493
494 // Skip updating write barrier if storing a smi.
495 __ JumpIfSmi(a0, &exit);
496
497 // Update the write barrier for the array address.
498 // Ok to clobber receiver_reg and name_reg, since we return.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000499 __ mov(name_reg, a0);
500 __ RecordWriteField(scratch,
501 offset,
502 name_reg,
503 receiver_reg,
504 kRAHasNotBeenSaved,
505 kDontSaveFPRegs);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000506 }
507
508 // Return the value (register v0).
509 __ bind(&exit);
510 __ mov(v0, a0);
511 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +0000512}
513
514
515void StubCompiler::GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000516 ASSERT(kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000517 Handle<Code> code = (kind == Code::LOAD_IC)
518 ? masm->isolate()->builtins()->LoadIC_Miss()
519 : masm->isolate()->builtins()->KeyedLoadIC_Miss();
520 __ Jump(code, RelocInfo::CODE_TARGET);
ager@chromium.org5c838252010-02-19 08:53:10 +0000521}
522
523
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000524static void GenerateCallFunction(MacroAssembler* masm,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000525 Handle<Object> object,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000526 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000527 Label* miss,
528 Code::ExtraICState extra_ic_state) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000529 // ----------- S t a t e -------------
530 // -- a0: receiver
531 // -- a1: function to call
532 // -----------------------------------
533 // Check that the function really is a function.
534 __ JumpIfSmi(a1, miss);
535 __ GetObjectType(a1, a3, a3);
536 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
537
538 // Patch the receiver on the stack with the global proxy if
539 // necessary.
540 if (object->IsGlobalObject()) {
541 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
542 __ sw(a3, MemOperand(sp, arguments.immediate() * kPointerSize));
543 }
544
545 // Invoke the function.
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000546 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state)
547 ? CALL_AS_FUNCTION
548 : CALL_AS_METHOD;
549 __ InvokeFunction(a1, arguments, JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000550}
551
552
553static void PushInterceptorArguments(MacroAssembler* masm,
554 Register receiver,
555 Register holder,
556 Register name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000557 Handle<JSObject> holder_obj) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000558 __ push(name);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000559 Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
560 ASSERT(!masm->isolate()->heap()->InNewSpace(*interceptor));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000561 Register scratch = name;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000562 __ li(scratch, Operand(interceptor));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000563 __ Push(scratch, receiver, holder);
564 __ lw(scratch, FieldMemOperand(scratch, InterceptorInfo::kDataOffset));
565 __ push(scratch);
566}
567
568
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000569static void CompileCallLoadPropertyWithInterceptor(
570 MacroAssembler* masm,
571 Register receiver,
572 Register holder,
573 Register name,
574 Handle<JSObject> holder_obj) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000575 PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
576
577 ExternalReference ref =
578 ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorOnly),
579 masm->isolate());
580 __ li(a0, Operand(5));
581 __ li(a1, Operand(ref));
582
583 CEntryStub stub(1);
584 __ CallStub(&stub);
585}
586
587
588static const int kFastApiCallArguments = 3;
589
590
591// Reserves space for the extra arguments to FastHandleApiCall in the
592// caller's frame.
593//
594// These arguments are set by CheckPrototypes and GenerateFastApiDirectCall.
595static void ReserveSpaceForFastApiCall(MacroAssembler* masm,
596 Register scratch) {
597 ASSERT(Smi::FromInt(0) == 0);
598 for (int i = 0; i < kFastApiCallArguments; i++) {
599 __ push(zero_reg);
600 }
601}
602
603
604// Undoes the effects of ReserveSpaceForFastApiCall.
605static void FreeSpaceForFastApiCall(MacroAssembler* masm) {
606 __ Drop(kFastApiCallArguments);
607}
608
609
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000610static void GenerateFastApiDirectCall(MacroAssembler* masm,
611 const CallOptimization& optimization,
612 int argc) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000613 // ----------- S t a t e -------------
614 // -- sp[0] : holder (set by CheckPrototypes)
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000615 // -- sp[4] : callee JS function
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000616 // -- sp[8] : call data
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000617 // -- sp[12] : last JS argument
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000618 // -- ...
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000619 // -- sp[(argc + 3) * 4] : first JS argument
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000620 // -- sp[(argc + 4) * 4] : receiver
621 // -----------------------------------
622 // Get the function and setup the context.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000623 Handle<JSFunction> function = optimization.constant_function();
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000624 __ LoadHeapObject(t1, function);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000625 __ lw(cp, FieldMemOperand(t1, JSFunction::kContextOffset));
626
627 // Pass the additional arguments FastHandleApiCall expects.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000628 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
629 Handle<Object> call_data(api_call_info->data());
630 if (masm->isolate()->heap()->InNewSpace(*call_data)) {
631 __ li(a0, api_call_info);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000632 __ lw(t2, FieldMemOperand(a0, CallHandlerInfo::kDataOffset));
633 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000634 __ li(t2, call_data);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000635 }
636
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000637 // Store JS function and call data.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000638 __ sw(t1, MemOperand(sp, 1 * kPointerSize));
639 __ sw(t2, MemOperand(sp, 2 * kPointerSize));
640
641 // a2 points to call data as expected by Arguments
642 // (refer to layout above).
643 __ Addu(a2, sp, Operand(2 * kPointerSize));
644
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000645 const int kApiStackSpace = 4;
646
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000647 FrameScope frame_scope(masm, StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000648 __ EnterExitFrame(false, kApiStackSpace);
649
650 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
651 // struct from the function (which is currently the case). This means we pass
652 // the first argument in a1 instead of a0. TryCallApiFunctionAndReturn
653 // will handle setting up a0.
654
655 // a1 = v8::Arguments&
656 // Arguments is built at sp + 1 (sp is a reserved spot for ra).
657 __ Addu(a1, sp, kPointerSize);
658
659 // v8::Arguments::implicit_args = data
660 __ sw(a2, MemOperand(a1, 0 * kPointerSize));
661 // v8::Arguments::values = last argument
662 __ Addu(t0, a2, Operand(argc * kPointerSize));
663 __ sw(t0, MemOperand(a1, 1 * kPointerSize));
664 // v8::Arguments::length_ = argc
665 __ li(t0, Operand(argc));
666 __ sw(t0, MemOperand(a1, 2 * kPointerSize));
667 // v8::Arguments::is_construct_call = 0
668 __ sw(zero_reg, MemOperand(a1, 3 * kPointerSize));
669
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000670 const int kStackUnwindSpace = argc + kFastApiCallArguments + 1;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000671 Address function_address = v8::ToCData<Address>(api_call_info->callback());
672 ApiFunction fun(function_address);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000673 ExternalReference ref =
674 ExternalReference(&fun,
675 ExternalReference::DIRECT_API_CALL,
676 masm->isolate());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000677 AllowExternalCallThatCantCauseGC scope(masm);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000678 __ CallApiFunctionAndReturn(ref, kStackUnwindSpace);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000679}
680
lrn@chromium.org7516f052011-03-30 08:52:27 +0000681class CallInterceptorCompiler BASE_EMBEDDED {
682 public:
683 CallInterceptorCompiler(StubCompiler* stub_compiler,
684 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000685 Register name,
686 Code::ExtraICState extra_ic_state)
lrn@chromium.org7516f052011-03-30 08:52:27 +0000687 : stub_compiler_(stub_compiler),
688 arguments_(arguments),
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000689 name_(name),
690 extra_ic_state_(extra_ic_state) {}
lrn@chromium.org7516f052011-03-30 08:52:27 +0000691
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000692 void Compile(MacroAssembler* masm,
693 Handle<JSObject> object,
694 Handle<JSObject> holder,
695 Handle<String> name,
696 LookupResult* lookup,
697 Register receiver,
698 Register scratch1,
699 Register scratch2,
700 Register scratch3,
701 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000702 ASSERT(holder->HasNamedInterceptor());
703 ASSERT(!holder->GetNamedInterceptor()->getter()->IsUndefined());
704
705 // Check that the receiver isn't a smi.
706 __ JumpIfSmi(receiver, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000707 CallOptimization optimization(lookup);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000708 if (optimization.is_constant_call()) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000709 CompileCacheable(masm, object, receiver, scratch1, scratch2, scratch3,
710 holder, lookup, name, optimization, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000711 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000712 CompileRegular(masm, object, receiver, scratch1, scratch2, scratch3,
713 name, holder, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000714 }
715 }
716
717 private:
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000718 void CompileCacheable(MacroAssembler* masm,
719 Handle<JSObject> object,
720 Register receiver,
721 Register scratch1,
722 Register scratch2,
723 Register scratch3,
724 Handle<JSObject> interceptor_holder,
725 LookupResult* lookup,
726 Handle<String> name,
727 const CallOptimization& optimization,
728 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000729 ASSERT(optimization.is_constant_call());
730 ASSERT(!lookup->holder()->IsGlobalObject());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000731 Counters* counters = masm->isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000732 int depth1 = kInvalidProtoDepth;
733 int depth2 = kInvalidProtoDepth;
734 bool can_do_fast_api_call = false;
735 if (optimization.is_simple_api_call() &&
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000736 !lookup->holder()->IsGlobalObject()) {
737 depth1 = optimization.GetPrototypeDepthOfExpectedType(
738 object, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000739 if (depth1 == kInvalidProtoDepth) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000740 depth2 = optimization.GetPrototypeDepthOfExpectedType(
741 interceptor_holder, Handle<JSObject>(lookup->holder()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000742 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000743 can_do_fast_api_call =
744 depth1 != kInvalidProtoDepth || depth2 != kInvalidProtoDepth;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000745 }
746
747 __ IncrementCounter(counters->call_const_interceptor(), 1,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000748 scratch1, scratch2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000749
750 if (can_do_fast_api_call) {
751 __ IncrementCounter(counters->call_const_interceptor_fast_api(), 1,
752 scratch1, scratch2);
753 ReserveSpaceForFastApiCall(masm, scratch1);
754 }
755
756 // Check that the maps from receiver to interceptor's holder
757 // haven't changed and thus we can invoke interceptor.
758 Label miss_cleanup;
759 Label* miss = can_do_fast_api_call ? &miss_cleanup : miss_label;
760 Register holder =
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000761 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
762 scratch1, scratch2, scratch3,
763 name, depth1, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000764
765 // Invoke an interceptor and if it provides a value,
766 // branch to |regular_invoke|.
767 Label regular_invoke;
768 LoadWithInterceptor(masm, receiver, holder, interceptor_holder, scratch2,
769 &regular_invoke);
770
771 // Interceptor returned nothing for this property. Try to use cached
772 // constant function.
773
774 // Check that the maps from interceptor's holder to constant function's
775 // holder haven't changed and thus we can use cached constant function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000776 if (*interceptor_holder != lookup->holder()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000777 stub_compiler_->CheckPrototypes(interceptor_holder, receiver,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000778 Handle<JSObject>(lookup->holder()),
779 scratch1, scratch2, scratch3,
780 name, depth2, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000781 } else {
782 // CheckPrototypes has a side effect of fetching a 'holder'
783 // for API (object which is instanceof for the signature). It's
784 // safe to omit it here, as if present, it should be fetched
785 // by the previous CheckPrototypes.
786 ASSERT(depth2 == kInvalidProtoDepth);
787 }
788
789 // Invoke function.
790 if (can_do_fast_api_call) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000791 GenerateFastApiDirectCall(masm, optimization, arguments_.immediate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000792 } else {
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000793 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state_)
794 ? CALL_AS_FUNCTION
795 : CALL_AS_METHOD;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000796 __ InvokeFunction(optimization.constant_function(), arguments_,
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +0000797 JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000798 }
799
800 // Deferred code for fast API call case---clean preallocated space.
801 if (can_do_fast_api_call) {
802 __ bind(&miss_cleanup);
803 FreeSpaceForFastApiCall(masm);
804 __ Branch(miss_label);
805 }
806
807 // Invoke a regular function.
808 __ bind(&regular_invoke);
809 if (can_do_fast_api_call) {
810 FreeSpaceForFastApiCall(masm);
811 }
lrn@chromium.org7516f052011-03-30 08:52:27 +0000812 }
813
814 void CompileRegular(MacroAssembler* masm,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000815 Handle<JSObject> object,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000816 Register receiver,
817 Register scratch1,
818 Register scratch2,
819 Register scratch3,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000820 Handle<String> name,
821 Handle<JSObject> interceptor_holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000822 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000823 Register holder =
824 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000825 scratch1, scratch2, scratch3,
826 name, miss_label);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000827
828 // Call a runtime function to load the interceptor property.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000829 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000830 // Save the name_ register across the call.
831 __ push(name_);
832
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000833 PushInterceptorArguments(masm, receiver, holder, name_, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000834
835 __ CallExternalReference(
836 ExternalReference(
837 IC_Utility(IC::kLoadPropertyWithInterceptorForCall),
838 masm->isolate()),
839 5);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000840 // Restore the name_ register.
841 __ pop(name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000842 // Leave the internal frame.
lrn@chromium.org7516f052011-03-30 08:52:27 +0000843 }
844
845 void LoadWithInterceptor(MacroAssembler* masm,
846 Register receiver,
847 Register holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000848 Handle<JSObject> holder_obj,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000849 Register scratch,
850 Label* interceptor_succeeded) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000851 {
852 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000853
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000854 __ Push(holder, name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000855 CompileCallLoadPropertyWithInterceptor(masm,
856 receiver,
857 holder,
858 name_,
859 holder_obj);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000860 __ pop(name_); // Restore the name.
861 __ pop(receiver); // Restore the holder.
862 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000863 // If interceptor returns no-result sentinel, call the constant function.
864 __ LoadRoot(scratch, Heap::kNoInterceptorResultSentinelRootIndex);
865 __ Branch(interceptor_succeeded, ne, v0, Operand(scratch));
lrn@chromium.org7516f052011-03-30 08:52:27 +0000866 }
867
868 StubCompiler* stub_compiler_;
869 const ParameterCount& arguments_;
870 Register name_;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000871 Code::ExtraICState extra_ic_state_;
lrn@chromium.org7516f052011-03-30 08:52:27 +0000872};
873
874
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000875
876// Generate code to check that a global property cell is empty. Create
877// the property cell at compilation time if no cell exists for the
878// property.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000879static void GenerateCheckPropertyCell(MacroAssembler* masm,
880 Handle<GlobalObject> global,
881 Handle<String> name,
882 Register scratch,
883 Label* miss) {
884 Handle<JSGlobalPropertyCell> cell =
885 GlobalObject::EnsurePropertyCell(global, name);
886 ASSERT(cell->value()->IsTheHole());
887 __ li(scratch, Operand(cell));
888 __ lw(scratch,
889 FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset));
890 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
891 __ Branch(miss, ne, scratch, Operand(at));
892}
893
894
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000895// Calls GenerateCheckPropertyCell for each global object in the prototype chain
896// from object to (but not including) holder.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000897static void GenerateCheckPropertyCells(MacroAssembler* masm,
898 Handle<JSObject> object,
899 Handle<JSObject> holder,
900 Handle<String> name,
901 Register scratch,
902 Label* miss) {
903 Handle<JSObject> current = object;
904 while (!current.is_identical_to(holder)) {
905 if (current->IsGlobalObject()) {
906 GenerateCheckPropertyCell(masm,
907 Handle<GlobalObject>::cast(current),
908 name,
909 scratch,
910 miss);
911 }
912 current = Handle<JSObject>(JSObject::cast(current->GetPrototype()));
913 }
914}
915
916
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000917// Convert and store int passed in register ival to IEEE 754 single precision
918// floating point value at memory location (dst + 4 * wordoffset)
919// If FPU is available use it for conversion.
920static void StoreIntAsFloat(MacroAssembler* masm,
921 Register dst,
922 Register wordoffset,
923 Register ival,
924 Register fval,
925 Register scratch1,
926 Register scratch2) {
927 if (CpuFeatures::IsSupported(FPU)) {
928 CpuFeatures::Scope scope(FPU);
929 __ mtc1(ival, f0);
930 __ cvt_s_w(f0, f0);
931 __ sll(scratch1, wordoffset, 2);
932 __ addu(scratch1, dst, scratch1);
933 __ swc1(f0, MemOperand(scratch1, 0));
934 } else {
935 // FPU is not available, do manual conversions.
936
937 Label not_special, done;
938 // Move sign bit from source to destination. This works because the sign
939 // bit in the exponent word of the double has the same position and polarity
940 // as the 2's complement sign bit in a Smi.
941 ASSERT(kBinary32SignMask == 0x80000000u);
942
943 __ And(fval, ival, Operand(kBinary32SignMask));
944 // Negate value if it is negative.
945 __ subu(scratch1, zero_reg, ival);
946 __ movn(ival, scratch1, fval);
947
948 // We have -1, 0 or 1, which we treat specially. Register ival contains
949 // absolute value: it is either equal to 1 (special case of -1 and 1),
950 // greater than 1 (not a special case) or less than 1 (special case of 0).
951 __ Branch(&not_special, gt, ival, Operand(1));
952
953 // For 1 or -1 we need to or in the 0 exponent (biased).
954 static const uint32_t exponent_word_for_1 =
955 kBinary32ExponentBias << kBinary32ExponentShift;
956
957 __ Xor(scratch1, ival, Operand(1));
958 __ li(scratch2, exponent_word_for_1);
959 __ or_(scratch2, fval, scratch2);
960 __ movz(fval, scratch2, scratch1); // Only if ival is equal to 1.
961 __ Branch(&done);
962
963 __ bind(&not_special);
964 // Count leading zeros.
965 // Gets the wrong answer for 0, but we already checked for that case above.
966 Register zeros = scratch2;
967 __ clz(zeros, ival);
968
969 // Compute exponent and or it into the exponent register.
970 __ li(scratch1, (kBitsPerInt - 1) + kBinary32ExponentBias);
971 __ subu(scratch1, scratch1, zeros);
972
973 __ sll(scratch1, scratch1, kBinary32ExponentShift);
974 __ or_(fval, fval, scratch1);
975
976 // Shift up the source chopping the top bit off.
977 __ Addu(zeros, zeros, Operand(1));
978 // This wouldn't work for 1 and -1 as the shift would be 32 which means 0.
979 __ sllv(ival, ival, zeros);
980 // And the top (top 20 bits).
981 __ srl(scratch1, ival, kBitsPerInt - kBinary32MantissaBits);
982 __ or_(fval, fval, scratch1);
983
984 __ bind(&done);
985
986 __ sll(scratch1, wordoffset, 2);
987 __ addu(scratch1, dst, scratch1);
988 __ sw(fval, MemOperand(scratch1, 0));
989 }
990}
991
992
993// Convert unsigned integer with specified number of leading zeroes in binary
994// representation to IEEE 754 double.
995// Integer to convert is passed in register hiword.
996// Resulting double is returned in registers hiword:loword.
997// This functions does not work correctly for 0.
998static void GenerateUInt2Double(MacroAssembler* masm,
999 Register hiword,
1000 Register loword,
1001 Register scratch,
1002 int leading_zeroes) {
1003 const int meaningful_bits = kBitsPerInt - leading_zeroes - 1;
1004 const int biased_exponent = HeapNumber::kExponentBias + meaningful_bits;
1005
1006 const int mantissa_shift_for_hi_word =
1007 meaningful_bits - HeapNumber::kMantissaBitsInTopWord;
1008
1009 const int mantissa_shift_for_lo_word =
1010 kBitsPerInt - mantissa_shift_for_hi_word;
1011
1012 __ li(scratch, biased_exponent << HeapNumber::kExponentShift);
1013 if (mantissa_shift_for_hi_word > 0) {
1014 __ sll(loword, hiword, mantissa_shift_for_lo_word);
1015 __ srl(hiword, hiword, mantissa_shift_for_hi_word);
1016 __ or_(hiword, scratch, hiword);
1017 } else {
1018 __ mov(loword, zero_reg);
1019 __ sll(hiword, hiword, mantissa_shift_for_hi_word);
1020 __ or_(hiword, scratch, hiword);
1021 }
1022
1023 // If least significant bit of biased exponent was not 1 it was corrupted
1024 // by most significant bit of mantissa so we should fix that.
1025 if (!(biased_exponent & 1)) {
1026 __ li(scratch, 1 << HeapNumber::kExponentShift);
1027 __ nor(scratch, scratch, scratch);
1028 __ and_(hiword, hiword, scratch);
1029 }
1030}
1031
1032
ager@chromium.org5c838252010-02-19 08:53:10 +00001033#undef __
1034#define __ ACCESS_MASM(masm())
1035
1036
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001037Register StubCompiler::CheckPrototypes(Handle<JSObject> object,
1038 Register object_reg,
1039 Handle<JSObject> holder,
1040 Register holder_reg,
1041 Register scratch1,
1042 Register scratch2,
1043 Handle<String> name,
1044 int save_at_depth,
1045 Label* miss) {
1046 // Make sure there's no overlap between holder and object registers.
1047 ASSERT(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
1048 ASSERT(!scratch2.is(object_reg) && !scratch2.is(holder_reg)
1049 && !scratch2.is(scratch1));
1050
1051 // Keep track of the current object in register reg.
1052 Register reg = object_reg;
1053 int depth = 0;
1054
1055 if (save_at_depth == depth) {
1056 __ sw(reg, MemOperand(sp));
1057 }
1058
1059 // Check the maps in the prototype chain.
1060 // Traverse the prototype chain from the object and do map checks.
1061 Handle<JSObject> current = object;
1062 while (!current.is_identical_to(holder)) {
1063 ++depth;
1064
1065 // Only global objects and objects that do not require access
1066 // checks are allowed in stubs.
1067 ASSERT(current->IsJSGlobalProxy() || !current->IsAccessCheckNeeded());
1068
1069 Handle<JSObject> prototype(JSObject::cast(current->GetPrototype()));
1070 if (!current->HasFastProperties() &&
1071 !current->IsJSGlobalObject() &&
1072 !current->IsJSGlobalProxy()) {
1073 if (!name->IsSymbol()) {
1074 name = factory()->LookupSymbol(name);
1075 }
1076 ASSERT(current->property_dictionary()->FindEntry(*name) ==
1077 StringDictionary::kNotFound);
1078
1079 GenerateDictionaryNegativeLookup(masm(), miss, reg, name,
1080 scratch1, scratch2);
1081
1082 __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
1083 reg = holder_reg; // From now on the object will be in holder_reg.
1084 __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
1085 } else {
1086 Handle<Map> current_map(current->map());
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001087 __ CheckMap(reg, scratch1, current_map, miss, DONT_DO_SMI_CHECK,
1088 ALLOW_ELEMENT_TRANSITION_MAPS);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001089 // Check access rights to the global object. This has to happen after
1090 // the map check so that we know that the object is actually a global
1091 // object.
1092 if (current->IsJSGlobalProxy()) {
1093 __ CheckAccessGlobalProxy(reg, scratch2, miss);
1094 }
1095 reg = holder_reg; // From now on the object will be in holder_reg.
1096
1097 if (heap()->InNewSpace(*prototype)) {
1098 // The prototype is in new space; we cannot store a reference to it
1099 // in the code. Load it from the map.
1100 __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
1101 } else {
1102 // The prototype is in old space; load it directly.
1103 __ li(reg, Operand(prototype));
1104 }
1105 }
1106
1107 if (save_at_depth == depth) {
1108 __ sw(reg, MemOperand(sp));
1109 }
1110
1111 // Go to the next object in the prototype chain.
1112 current = prototype;
1113 }
1114
1115 // Log the check depth.
1116 LOG(masm()->isolate(), IntEvent("check-maps-depth", depth + 1));
1117
1118 // Check the holder map.
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001119 __ CheckMap(reg, scratch1, Handle<Map>(current->map()), miss,
1120 DONT_DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001121
1122 // Perform security check for access to the global object.
1123 ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded());
1124 if (holder->IsJSGlobalProxy()) {
1125 __ CheckAccessGlobalProxy(reg, scratch1, miss);
1126 }
1127
1128 // If we've skipped any global objects, it's not enough to verify that
1129 // their maps haven't changed. We also need to check that the property
1130 // cell for the property is still empty.
1131 GenerateCheckPropertyCells(masm(), object, holder, name, scratch1, miss);
1132
1133 // Return the register containing the holder.
1134 return reg;
1135}
1136
1137
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001138void StubCompiler::GenerateLoadField(Handle<JSObject> object,
1139 Handle<JSObject> holder,
ager@chromium.org5c838252010-02-19 08:53:10 +00001140 Register receiver,
1141 Register scratch1,
1142 Register scratch2,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001143 Register scratch3,
ager@chromium.org5c838252010-02-19 08:53:10 +00001144 int index,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001145 Handle<String> name,
ager@chromium.org5c838252010-02-19 08:53:10 +00001146 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001147 // Check that the receiver isn't a smi.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001148 __ JumpIfSmi(receiver, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001149
1150 // Check that the maps haven't changed.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001151 Register reg = CheckPrototypes(
1152 object, receiver, holder, scratch1, scratch2, scratch3, name, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001153 GenerateFastPropertyLoad(masm(), v0, reg, holder, index);
1154 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +00001155}
1156
1157
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001158void StubCompiler::GenerateLoadConstant(Handle<JSObject> object,
1159 Handle<JSObject> holder,
ager@chromium.org5c838252010-02-19 08:53:10 +00001160 Register receiver,
1161 Register scratch1,
1162 Register scratch2,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001163 Register scratch3,
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001164 Handle<JSFunction> value,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001165 Handle<String> name,
ager@chromium.org5c838252010-02-19 08:53:10 +00001166 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001167 // Check that the receiver isn't a smi.
1168 __ JumpIfSmi(receiver, miss, scratch1);
1169
1170 // Check that the maps haven't changed.
1171 Register reg =
1172 CheckPrototypes(object, receiver, holder,
1173 scratch1, scratch2, scratch3, name, miss);
1174
1175 // Return the constant value.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001176 __ LoadHeapObject(v0, value);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001177 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +00001178}
1179
1180
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001181void StubCompiler::GenerateLoadCallback(Handle<JSObject> object,
1182 Handle<JSObject> holder,
1183 Register receiver,
1184 Register name_reg,
1185 Register scratch1,
1186 Register scratch2,
1187 Register scratch3,
1188 Handle<AccessorInfo> callback,
1189 Handle<String> name,
1190 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001191 // Check that the receiver isn't a smi.
1192 __ JumpIfSmi(receiver, miss, scratch1);
1193
1194 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001195 Register reg = CheckPrototypes(object, receiver, holder, scratch1,
1196 scratch2, scratch3, name, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001197
1198 // Build AccessorInfo::args_ list on the stack and push property name below
1199 // the exit frame to make GC aware of them and store pointers to them.
1200 __ push(receiver);
1201 __ mov(scratch2, sp); // scratch2 = AccessorInfo::args_
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001202 if (heap()->InNewSpace(callback->data())) {
1203 __ li(scratch3, callback);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001204 __ lw(scratch3, FieldMemOperand(scratch3, AccessorInfo::kDataOffset));
1205 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001206 __ li(scratch3, Handle<Object>(callback->data()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001207 }
1208 __ Push(reg, scratch3, name_reg);
1209 __ mov(a2, scratch2); // Saved in case scratch2 == a1.
1210 __ mov(a1, sp); // a1 (first argument - see note below) = Handle<String>
1211
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001212 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
1213 // struct from the function (which is currently the case). This means we pass
1214 // the arguments in a1-a2 instead of a0-a1. TryCallApiFunctionAndReturn
1215 // will handle setting up a0.
1216
1217 const int kApiStackSpace = 1;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001218 FrameScope frame_scope(masm(), StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001219 __ EnterExitFrame(false, kApiStackSpace);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001220
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001221 // Create AccessorInfo instance on the stack above the exit frame with
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001222 // scratch2 (internal::Object** args_) as the data.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001223 __ sw(a2, MemOperand(sp, kPointerSize));
1224 // a2 (second argument - see note above) = AccessorInfo&
1225 __ Addu(a2, sp, kPointerSize);
1226
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001227 const int kStackUnwindSpace = 4;
1228 Address getter_address = v8::ToCData<Address>(callback->getter());
1229 ApiFunction fun(getter_address);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001230 ExternalReference ref =
1231 ExternalReference(&fun,
1232 ExternalReference::DIRECT_GETTER_CALL,
1233 masm()->isolate());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001234 __ CallApiFunctionAndReturn(ref, kStackUnwindSpace);
ager@chromium.org5c838252010-02-19 08:53:10 +00001235}
1236
1237
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001238void StubCompiler::GenerateLoadInterceptor(Handle<JSObject> object,
1239 Handle<JSObject> interceptor_holder,
ager@chromium.org5c838252010-02-19 08:53:10 +00001240 LookupResult* lookup,
1241 Register receiver,
1242 Register name_reg,
1243 Register scratch1,
1244 Register scratch2,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001245 Register scratch3,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001246 Handle<String> name,
ager@chromium.org5c838252010-02-19 08:53:10 +00001247 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001248 ASSERT(interceptor_holder->HasNamedInterceptor());
1249 ASSERT(!interceptor_holder->GetNamedInterceptor()->getter()->IsUndefined());
1250
1251 // Check that the receiver isn't a smi.
1252 __ JumpIfSmi(receiver, miss);
1253
1254 // So far the most popular follow ups for interceptor loads are FIELD
1255 // and CALLBACKS, so inline only them, other cases may be added
1256 // later.
1257 bool compile_followup_inline = false;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001258 if (lookup->IsFound() && lookup->IsCacheable()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001259 if (lookup->type() == FIELD) {
1260 compile_followup_inline = true;
1261 } else if (lookup->type() == CALLBACKS &&
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001262 lookup->GetCallbackObject()->IsAccessorInfo()) {
1263 compile_followup_inline =
1264 AccessorInfo::cast(lookup->GetCallbackObject())->getter() != NULL;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001265 }
1266 }
1267
1268 if (compile_followup_inline) {
1269 // Compile the interceptor call, followed by inline code to load the
1270 // property from further up the prototype chain if the call fails.
1271 // Check that the maps haven't changed.
1272 Register holder_reg = CheckPrototypes(object, receiver, interceptor_holder,
1273 scratch1, scratch2, scratch3,
1274 name, miss);
1275 ASSERT(holder_reg.is(receiver) || holder_reg.is(scratch1));
1276
1277 // Save necessary data before invoking an interceptor.
1278 // Requires a frame to make GC aware of pushed pointers.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001279 {
1280 FrameScope frame_scope(masm(), StackFrame::INTERNAL);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001281 if (lookup->type() == CALLBACKS && !receiver.is(holder_reg)) {
1282 // CALLBACKS case needs a receiver to be passed into C++ callback.
1283 __ Push(receiver, holder_reg, name_reg);
1284 } else {
1285 __ Push(holder_reg, name_reg);
1286 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001287 // Invoke an interceptor. Note: map checks from receiver to
1288 // interceptor's holder has been compiled before (see a caller
1289 // of this method).
1290 CompileCallLoadPropertyWithInterceptor(masm(),
1291 receiver,
1292 holder_reg,
1293 name_reg,
1294 interceptor_holder);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001295 // Check if interceptor provided a value for property. If it's
1296 // the case, return immediately.
1297 Label interceptor_failed;
1298 __ LoadRoot(scratch1, Heap::kNoInterceptorResultSentinelRootIndex);
1299 __ Branch(&interceptor_failed, eq, v0, Operand(scratch1));
1300 frame_scope.GenerateLeaveFrame();
1301 __ Ret();
1302
1303 __ bind(&interceptor_failed);
1304 __ pop(name_reg);
1305 __ pop(holder_reg);
1306 if (lookup->type() == CALLBACKS && !receiver.is(holder_reg)) {
1307 __ pop(receiver);
1308 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001309 // Leave the internal frame.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001310 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001311 // Check that the maps from interceptor's holder to lookup's holder
1312 // haven't changed. And load lookup's holder into |holder| register.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001313 if (*interceptor_holder != lookup->holder()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001314 holder_reg = CheckPrototypes(interceptor_holder,
1315 holder_reg,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001316 Handle<JSObject>(lookup->holder()),
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001317 scratch1,
1318 scratch2,
1319 scratch3,
1320 name,
1321 miss);
1322 }
1323
1324 if (lookup->type() == FIELD) {
1325 // We found FIELD property in prototype chain of interceptor's holder.
1326 // Retrieve a field from field's holder.
1327 GenerateFastPropertyLoad(masm(), v0, holder_reg,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001328 Handle<JSObject>(lookup->holder()),
1329 lookup->GetFieldIndex());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001330 __ Ret();
1331 } else {
1332 // We found CALLBACKS property in prototype chain of interceptor's
1333 // holder.
1334 ASSERT(lookup->type() == CALLBACKS);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001335 Handle<AccessorInfo> callback(
1336 AccessorInfo::cast(lookup->GetCallbackObject()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001337 ASSERT(callback->getter() != NULL);
1338
1339 // Tail call to runtime.
1340 // Important invariant in CALLBACKS case: the code above must be
1341 // structured to never clobber |receiver| register.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001342 __ li(scratch2, callback);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001343 // holder_reg is either receiver or scratch1.
1344 if (!receiver.is(holder_reg)) {
1345 ASSERT(scratch1.is(holder_reg));
1346 __ Push(receiver, holder_reg);
1347 __ lw(scratch3,
1348 FieldMemOperand(scratch2, AccessorInfo::kDataOffset));
1349 __ Push(scratch3, scratch2, name_reg);
1350 } else {
1351 __ push(receiver);
1352 __ lw(scratch3,
1353 FieldMemOperand(scratch2, AccessorInfo::kDataOffset));
1354 __ Push(holder_reg, scratch3, scratch2, name_reg);
1355 }
1356
1357 ExternalReference ref =
1358 ExternalReference(IC_Utility(IC::kLoadCallbackProperty),
1359 masm()->isolate());
1360 __ TailCallExternalReference(ref, 5, 1);
1361 }
1362 } else { // !compile_followup_inline
1363 // Call the runtime system to load the interceptor.
1364 // Check that the maps haven't changed.
1365 Register holder_reg = CheckPrototypes(object, receiver, interceptor_holder,
1366 scratch1, scratch2, scratch3,
1367 name, miss);
1368 PushInterceptorArguments(masm(), receiver, holder_reg,
1369 name_reg, interceptor_holder);
1370
1371 ExternalReference ref = ExternalReference(
1372 IC_Utility(IC::kLoadPropertyWithInterceptorForLoad), masm()->isolate());
1373 __ TailCallExternalReference(ref, 5, 1);
1374 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001375}
1376
1377
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001378void CallStubCompiler::GenerateNameCheck(Handle<String> name, Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001379 if (kind_ == Code::KEYED_CALL_IC) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001380 __ Branch(miss, ne, a2, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001381 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001382}
1383
1384
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001385void CallStubCompiler::GenerateGlobalReceiverCheck(Handle<JSObject> object,
1386 Handle<JSObject> holder,
1387 Handle<String> name,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001388 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001389 ASSERT(holder->IsGlobalObject());
1390
1391 // Get the number of arguments.
1392 const int argc = arguments().immediate();
1393
1394 // Get the receiver from the stack.
1395 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1396
1397 // If the object is the holder then we know that it's a global
1398 // object which can only happen for contextual calls. In this case,
1399 // the receiver cannot be a smi.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001400 if (!object.is_identical_to(holder)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001401 __ JumpIfSmi(a0, miss);
1402 }
1403
1404 // Check that the maps haven't changed.
1405 CheckPrototypes(object, a0, holder, a3, a1, t0, name, miss);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001406}
1407
1408
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001409void CallStubCompiler::GenerateLoadFunctionFromCell(
1410 Handle<JSGlobalPropertyCell> cell,
1411 Handle<JSFunction> function,
1412 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001413 // Get the value from the cell.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001414 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001415 __ lw(a1, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
1416
1417 // Check that the cell contains the same function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001418 if (heap()->InNewSpace(*function)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001419 // We can't embed a pointer to a function in new space so we have
1420 // to verify that the shared function info is unchanged. This has
1421 // the nice side effect that multiple closures based on the same
1422 // function can all use this call IC. Before we load through the
1423 // function, we have to verify that it still is a function.
1424 __ JumpIfSmi(a1, miss);
1425 __ GetObjectType(a1, a3, a3);
1426 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
1427
1428 // Check the shared function info. Make sure it hasn't changed.
1429 __ li(a3, Handle<SharedFunctionInfo>(function->shared()));
1430 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
1431 __ Branch(miss, ne, t0, Operand(a3));
1432 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001433 __ Branch(miss, ne, a1, Operand(function));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001434 }
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001435}
1436
1437
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001438void CallStubCompiler::GenerateMissBranch() {
1439 Handle<Code> code =
danno@chromium.org40cb8782011-05-25 07:58:50 +00001440 isolate()->stub_cache()->ComputeCallMiss(arguments().immediate(),
1441 kind_,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001442 extra_state_);
1443 __ Jump(code, RelocInfo::CODE_TARGET);
1444}
1445
1446
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001447Handle<Code> CallStubCompiler::CompileCallField(Handle<JSObject> object,
1448 Handle<JSObject> holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001449 int index,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001450 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001451 // ----------- S t a t e -------------
1452 // -- a2 : name
1453 // -- ra : return address
1454 // -----------------------------------
1455 Label miss;
1456
1457 GenerateNameCheck(name, &miss);
1458
1459 const int argc = arguments().immediate();
1460
1461 // Get the receiver of the function from the stack into a0.
1462 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1463 // Check that the receiver isn't a smi.
1464 __ JumpIfSmi(a0, &miss, t0);
1465
1466 // Do the right check and compute the holder register.
1467 Register reg = CheckPrototypes(object, a0, holder, a1, a3, t0, name, &miss);
1468 GenerateFastPropertyLoad(masm(), a1, reg, holder, index);
1469
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001470 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001471
1472 // Handle call cache miss.
1473 __ bind(&miss);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001474 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001475
1476 // Return the generated code.
1477 return GetCode(FIELD, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00001478}
1479
1480
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001481Handle<Code> CallStubCompiler::CompileArrayPushCall(
1482 Handle<Object> object,
1483 Handle<JSObject> holder,
1484 Handle<JSGlobalPropertyCell> cell,
1485 Handle<JSFunction> function,
1486 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001487 // ----------- S t a t e -------------
1488 // -- a2 : name
1489 // -- ra : return address
1490 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1491 // -- ...
1492 // -- sp[argc * 4] : receiver
1493 // -----------------------------------
1494
1495 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001496 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001497
1498 Label miss;
1499
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001500 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001501
1502 Register receiver = a1;
1503
1504 // Get the receiver from the stack.
1505 const int argc = arguments().immediate();
1506 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1507
1508 // Check that the receiver isn't a smi.
1509 __ JumpIfSmi(receiver, &miss);
1510
1511 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001512 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, a3, v0, t0,
1513 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001514
1515 if (argc == 0) {
1516 // Nothing to do, just return the length.
1517 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1518 __ Drop(argc + 1);
1519 __ Ret();
1520 } else {
1521 Label call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001522 if (argc == 1) { // Otherwise fall through to call the builtin.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001523 Label attempt_to_grow_elements;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001524
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001525 Register elements = t2;
1526 Register end_elements = t1;
1527 // Get the elements array of the object.
1528 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1529
1530 // Check that the elements are in fast mode and writable.
1531 __ CheckMap(elements,
1532 v0,
1533 Heap::kFixedArrayMapRootIndex,
1534 &call_builtin,
1535 DONT_DO_SMI_CHECK);
1536
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001537 // Get the array's length into v0 and calculate new length.
1538 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1539 STATIC_ASSERT(kSmiTagSize == 1);
1540 STATIC_ASSERT(kSmiTag == 0);
1541 __ Addu(v0, v0, Operand(Smi::FromInt(argc)));
1542
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001543 // Get the elements' length.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001544 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1545
1546 // Check if we could survive without allocation.
1547 __ Branch(&attempt_to_grow_elements, gt, v0, Operand(t0));
1548
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001549 // Check if value is a smi.
1550 Label with_write_barrier;
1551 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize));
1552 __ JumpIfNotSmi(t0, &with_write_barrier);
1553
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001554 // Save new length.
1555 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1556
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001557 // Store the value.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001558 // We may need a register containing the address end_elements below,
1559 // so write back the value in end_elements.
1560 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1561 __ Addu(end_elements, elements, end_elements);
1562 const int kEndElementsOffset =
1563 FixedArray::kHeaderSize - kHeapObjectTag - argc * kPointerSize;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001564 __ Addu(end_elements, end_elements, kEndElementsOffset);
1565 __ sw(t0, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001566
1567 // Check for a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001568 __ Drop(argc + 1);
1569 __ Ret();
1570
1571 __ bind(&with_write_barrier);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001572
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001573 __ lw(a3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1574
1575 if (FLAG_smi_only_arrays && !FLAG_trace_elements_transitions) {
1576 Label fast_object, not_fast_object;
1577 __ CheckFastObjectElements(a3, t3, &not_fast_object);
1578 __ jmp(&fast_object);
1579 // In case of fast smi-only, convert to fast object, otherwise bail out.
1580 __ bind(&not_fast_object);
1581 __ CheckFastSmiOnlyElements(a3, t3, &call_builtin);
1582 // edx: receiver
1583 // r3: map
1584 __ LoadTransitionedArrayMapConditional(FAST_SMI_ONLY_ELEMENTS,
1585 FAST_ELEMENTS,
1586 a3,
1587 t3,
1588 &call_builtin);
1589 __ mov(a2, receiver);
1590 ElementsTransitionGenerator::GenerateSmiOnlyToObject(masm());
1591 __ bind(&fast_object);
1592 } else {
1593 __ CheckFastObjectElements(a3, a3, &call_builtin);
1594 }
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001595
1596 // Save new length.
1597 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1598
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001599 // Store the value.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001600 // We may need a register containing the address end_elements below,
1601 // so write back the value in end_elements.
1602 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1603 __ Addu(end_elements, elements, end_elements);
1604 __ Addu(end_elements, end_elements, kEndElementsOffset);
1605 __ sw(t0, MemOperand(end_elements));
1606
1607 __ RecordWrite(elements,
1608 end_elements,
1609 t0,
1610 kRAHasNotBeenSaved,
1611 kDontSaveFPRegs,
1612 EMIT_REMEMBERED_SET,
1613 OMIT_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001614 __ Drop(argc + 1);
1615 __ Ret();
1616
1617 __ bind(&attempt_to_grow_elements);
1618 // v0: array's length + 1.
1619 // t0: elements' length.
1620
1621 if (!FLAG_inline_new) {
1622 __ Branch(&call_builtin);
1623 }
1624
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001625 __ lw(a2, MemOperand(sp, (argc - 1) * kPointerSize));
1626 // Growing elements that are SMI-only requires special handling in case
1627 // the new element is non-Smi. For now, delegate to the builtin.
1628 Label no_fast_elements_check;
1629 __ JumpIfSmi(a2, &no_fast_elements_check);
1630 __ lw(t3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1631 __ CheckFastObjectElements(t3, t3, &call_builtin);
1632 __ bind(&no_fast_elements_check);
1633
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001634 ExternalReference new_space_allocation_top =
1635 ExternalReference::new_space_allocation_top_address(
1636 masm()->isolate());
1637 ExternalReference new_space_allocation_limit =
1638 ExternalReference::new_space_allocation_limit_address(
1639 masm()->isolate());
1640
1641 const int kAllocationDelta = 4;
1642 // Load top and check if it is the end of elements.
1643 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1644 __ Addu(end_elements, elements, end_elements);
1645 __ Addu(end_elements, end_elements, Operand(kEndElementsOffset));
1646 __ li(t3, Operand(new_space_allocation_top));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001647 __ lw(a3, MemOperand(t3));
1648 __ Branch(&call_builtin, ne, end_elements, Operand(a3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001649
1650 __ li(t5, Operand(new_space_allocation_limit));
1651 __ lw(t5, MemOperand(t5));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001652 __ Addu(a3, a3, Operand(kAllocationDelta * kPointerSize));
1653 __ Branch(&call_builtin, hi, a3, Operand(t5));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001654
1655 // We fit and could grow elements.
1656 // Update new_space_allocation_top.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001657 __ sw(a3, MemOperand(t3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001658 // Push the argument.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001659 __ sw(a2, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001660 // Fill the rest with holes.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001661 __ LoadRoot(a3, Heap::kTheHoleValueRootIndex);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001662 for (int i = 1; i < kAllocationDelta; i++) {
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001663 __ sw(a3, MemOperand(end_elements, i * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001664 }
1665
1666 // Update elements' and array's sizes.
1667 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1668 __ Addu(t0, t0, Operand(Smi::FromInt(kAllocationDelta)));
1669 __ sw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1670
1671 // Elements are in new space, so write barrier is not required.
1672 __ Drop(argc + 1);
1673 __ Ret();
1674 }
1675 __ bind(&call_builtin);
1676 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPush,
1677 masm()->isolate()),
1678 argc + 1,
1679 1);
1680 }
1681
1682 // Handle call cache miss.
1683 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001684 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001685
1686 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001687 return GetCode(function);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001688}
1689
1690
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001691Handle<Code> CallStubCompiler::CompileArrayPopCall(
1692 Handle<Object> object,
1693 Handle<JSObject> holder,
1694 Handle<JSGlobalPropertyCell> cell,
1695 Handle<JSFunction> function,
1696 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001697 // ----------- S t a t e -------------
1698 // -- a2 : name
1699 // -- ra : return address
1700 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1701 // -- ...
1702 // -- sp[argc * 4] : receiver
1703 // -----------------------------------
1704
1705 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001706 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001707
1708 Label miss, return_undefined, call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001709 Register receiver = a1;
1710 Register elements = a3;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001711 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001712
1713 // Get the receiver from the stack.
1714 const int argc = arguments().immediate();
1715 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001716 // Check that the receiver isn't a smi.
1717 __ JumpIfSmi(receiver, &miss);
1718
1719 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001720 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, elements,
1721 t0, v0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001722
1723 // Get the elements array of the object.
1724 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1725
1726 // Check that the elements are in fast mode and writable.
danno@chromium.org40cb8782011-05-25 07:58:50 +00001727 __ CheckMap(elements,
1728 v0,
1729 Heap::kFixedArrayMapRootIndex,
1730 &call_builtin,
1731 DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001732
1733 // Get the array's length into t0 and calculate new length.
1734 __ lw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1735 __ Subu(t0, t0, Operand(Smi::FromInt(1)));
1736 __ Branch(&return_undefined, lt, t0, Operand(zero_reg));
1737
1738 // Get the last element.
1739 __ LoadRoot(t2, Heap::kTheHoleValueRootIndex);
1740 STATIC_ASSERT(kSmiTagSize == 1);
1741 STATIC_ASSERT(kSmiTag == 0);
1742 // We can't address the last element in one operation. Compute the more
1743 // expensive shift first, and use an offset later on.
1744 __ sll(t1, t0, kPointerSizeLog2 - kSmiTagSize);
1745 __ Addu(elements, elements, t1);
1746 __ lw(v0, MemOperand(elements, FixedArray::kHeaderSize - kHeapObjectTag));
1747 __ Branch(&call_builtin, eq, v0, Operand(t2));
1748
1749 // Set the array's length.
1750 __ sw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1751
1752 // Fill with the hole.
1753 __ sw(t2, MemOperand(elements, FixedArray::kHeaderSize - kHeapObjectTag));
1754 __ Drop(argc + 1);
1755 __ Ret();
1756
1757 __ bind(&return_undefined);
1758 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
1759 __ Drop(argc + 1);
1760 __ Ret();
1761
1762 __ bind(&call_builtin);
1763 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPop,
1764 masm()->isolate()),
1765 argc + 1,
1766 1);
1767
1768 // Handle call cache miss.
1769 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001770 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001771
1772 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001773 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00001774}
1775
1776
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001777Handle<Code> CallStubCompiler::CompileStringCharCodeAtCall(
1778 Handle<Object> object,
1779 Handle<JSObject> holder,
1780 Handle<JSGlobalPropertyCell> cell,
1781 Handle<JSFunction> function,
1782 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001783 // ----------- S t a t e -------------
1784 // -- a2 : function name
1785 // -- ra : return address
1786 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1787 // -- ...
1788 // -- sp[argc * 4] : receiver
1789 // -----------------------------------
1790
1791 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001792 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001793
1794 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001795 Label miss;
1796 Label name_miss;
1797 Label index_out_of_range;
1798
1799 Label* index_out_of_range_label = &index_out_of_range;
1800
danno@chromium.org40cb8782011-05-25 07:58:50 +00001801 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001802 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00001803 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001804 index_out_of_range_label = &miss;
1805 }
1806
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001807 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001808
1809 // Check that the maps starting from the prototype haven't changed.
1810 GenerateDirectLoadGlobalFunctionPrototype(masm(),
1811 Context::STRING_FUNCTION_INDEX,
1812 v0,
1813 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001814 ASSERT(!object.is_identical_to(holder));
1815 CheckPrototypes(Handle<JSObject>(JSObject::cast(object->GetPrototype())),
1816 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001817
1818 Register receiver = a1;
1819 Register index = t1;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001820 Register result = v0;
1821 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1822 if (argc > 0) {
1823 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
1824 } else {
1825 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
1826 }
1827
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001828 StringCharCodeAtGenerator generator(receiver,
1829 index,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001830 result,
1831 &miss, // When not a string.
1832 &miss, // When not a number.
1833 index_out_of_range_label,
1834 STRING_INDEX_IS_NUMBER);
1835 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001836 __ Drop(argc + 1);
1837 __ Ret();
1838
1839 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001840 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001841
1842 if (index_out_of_range.is_linked()) {
1843 __ bind(&index_out_of_range);
1844 __ LoadRoot(v0, Heap::kNanValueRootIndex);
1845 __ Drop(argc + 1);
1846 __ Ret();
1847 }
1848
1849 __ bind(&miss);
1850 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001851 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001852 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001853 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001854
1855 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001856 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00001857}
1858
1859
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001860Handle<Code> CallStubCompiler::CompileStringCharAtCall(
1861 Handle<Object> object,
1862 Handle<JSObject> holder,
1863 Handle<JSGlobalPropertyCell> cell,
1864 Handle<JSFunction> function,
1865 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001866 // ----------- S t a t e -------------
1867 // -- a2 : function name
1868 // -- ra : return address
1869 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1870 // -- ...
1871 // -- sp[argc * 4] : receiver
1872 // -----------------------------------
1873
1874 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001875 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001876
1877 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001878 Label miss;
1879 Label name_miss;
1880 Label index_out_of_range;
1881 Label* index_out_of_range_label = &index_out_of_range;
danno@chromium.org40cb8782011-05-25 07:58:50 +00001882 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001883 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00001884 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001885 index_out_of_range_label = &miss;
1886 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001887 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001888
1889 // Check that the maps starting from the prototype haven't changed.
1890 GenerateDirectLoadGlobalFunctionPrototype(masm(),
1891 Context::STRING_FUNCTION_INDEX,
1892 v0,
1893 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001894 ASSERT(!object.is_identical_to(holder));
1895 CheckPrototypes(Handle<JSObject>(JSObject::cast(object->GetPrototype())),
1896 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001897
1898 Register receiver = v0;
1899 Register index = t1;
danno@chromium.orgc612e022011-11-10 11:38:15 +00001900 Register scratch = a3;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001901 Register result = v0;
1902 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1903 if (argc > 0) {
1904 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
1905 } else {
1906 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
1907 }
1908
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001909 StringCharAtGenerator generator(receiver,
1910 index,
danno@chromium.orgc612e022011-11-10 11:38:15 +00001911 scratch,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001912 result,
1913 &miss, // When not a string.
1914 &miss, // When not a number.
1915 index_out_of_range_label,
1916 STRING_INDEX_IS_NUMBER);
1917 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001918 __ Drop(argc + 1);
1919 __ Ret();
1920
1921 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001922 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001923
1924 if (index_out_of_range.is_linked()) {
1925 __ bind(&index_out_of_range);
1926 __ LoadRoot(v0, Heap::kEmptyStringRootIndex);
1927 __ Drop(argc + 1);
1928 __ Ret();
1929 }
1930
1931 __ bind(&miss);
1932 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001933 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001934 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001935 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001936
1937 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001938 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00001939}
1940
1941
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001942Handle<Code> CallStubCompiler::CompileStringFromCharCodeCall(
1943 Handle<Object> object,
1944 Handle<JSObject> holder,
1945 Handle<JSGlobalPropertyCell> cell,
1946 Handle<JSFunction> function,
1947 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001948 // ----------- S t a t e -------------
1949 // -- a2 : function name
1950 // -- ra : return address
1951 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1952 // -- ...
1953 // -- sp[argc * 4] : receiver
1954 // -----------------------------------
1955
1956 const int argc = arguments().immediate();
1957
1958 // If the object is not a JSObject or we got an unexpected number of
1959 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001960 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001961
1962 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001963 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001964
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001965 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001966 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
1967
1968 STATIC_ASSERT(kSmiTag == 0);
1969 __ JumpIfSmi(a1, &miss);
1970
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001971 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
1972 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001973 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001974 ASSERT(cell->value() == *function);
1975 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
1976 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001977 GenerateLoadFunctionFromCell(cell, function, &miss);
1978 }
1979
1980 // Load the char code argument.
1981 Register code = a1;
1982 __ lw(code, MemOperand(sp, 0 * kPointerSize));
1983
1984 // Check the code is a smi.
1985 Label slow;
1986 STATIC_ASSERT(kSmiTag == 0);
1987 __ JumpIfNotSmi(code, &slow);
1988
1989 // Convert the smi code to uint16.
1990 __ And(code, code, Operand(Smi::FromInt(0xffff)));
1991
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001992 StringCharFromCodeGenerator generator(code, v0);
1993 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001994 __ Drop(argc + 1);
1995 __ Ret();
1996
1997 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001998 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001999
2000 // Tail call the full function. We do not have to patch the receiver
2001 // because the function makes no use of it.
2002 __ bind(&slow);
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002003 __ InvokeFunction(
2004 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002005
2006 __ bind(&miss);
2007 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002008 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002009
2010 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002011 return cell.is_null() ? GetCode(function) : GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002012}
2013
2014
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002015Handle<Code> CallStubCompiler::CompileMathFloorCall(
2016 Handle<Object> object,
2017 Handle<JSObject> holder,
2018 Handle<JSGlobalPropertyCell> cell,
2019 Handle<JSFunction> function,
2020 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002021 // ----------- S t a t e -------------
2022 // -- a2 : function name
2023 // -- ra : return address
2024 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2025 // -- ...
2026 // -- sp[argc * 4] : receiver
2027 // -----------------------------------
2028
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002029 if (!CpuFeatures::IsSupported(FPU)) {
2030 return Handle<Code>::null();
2031 }
2032
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002033 CpuFeatures::Scope scope_fpu(FPU);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002034 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002035 // If the object is not a JSObject or we got an unexpected number of
2036 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002037 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002038
2039 Label miss, slow;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002040 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002041
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002042 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002043 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002044 STATIC_ASSERT(kSmiTag == 0);
2045 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002046 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2047 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002048 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002049 ASSERT(cell->value() == *function);
2050 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2051 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002052 GenerateLoadFunctionFromCell(cell, function, &miss);
2053 }
2054
2055 // Load the (only) argument into v0.
2056 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2057
2058 // If the argument is a smi, just return.
2059 STATIC_ASSERT(kSmiTag == 0);
2060 __ And(t0, v0, Operand(kSmiTagMask));
2061 __ Drop(argc + 1, eq, t0, Operand(zero_reg));
2062 __ Ret(eq, t0, Operand(zero_reg));
2063
danno@chromium.org40cb8782011-05-25 07:58:50 +00002064 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002065
2066 Label wont_fit_smi, no_fpu_error, restore_fcsr_and_return;
2067
2068 // If fpu is enabled, we use the floor instruction.
2069
2070 // Load the HeapNumber value.
2071 __ ldc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
2072
2073 // Backup FCSR.
2074 __ cfc1(a3, FCSR);
2075 // Clearing FCSR clears the exception mask with no side-effects.
2076 __ ctc1(zero_reg, FCSR);
2077 // Convert the argument to an integer.
2078 __ floor_w_d(f0, f0);
2079
2080 // Start checking for special cases.
2081 // Get the argument exponent and clear the sign bit.
2082 __ lw(t1, FieldMemOperand(v0, HeapNumber::kValueOffset + kPointerSize));
2083 __ And(t2, t1, Operand(~HeapNumber::kSignMask));
2084 __ srl(t2, t2, HeapNumber::kMantissaBitsInTopWord);
2085
2086 // Retrieve FCSR and check for fpu errors.
2087 __ cfc1(t5, FCSR);
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002088 __ And(t5, t5, Operand(kFCSRExceptionFlagMask));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002089 __ Branch(&no_fpu_error, eq, t5, Operand(zero_reg));
2090
2091 // Check for NaN, Infinity, and -Infinity.
2092 // They are invariant through a Math.Floor call, so just
2093 // return the original argument.
2094 __ Subu(t3, t2, Operand(HeapNumber::kExponentMask
2095 >> HeapNumber::kMantissaBitsInTopWord));
2096 __ Branch(&restore_fcsr_and_return, eq, t3, Operand(zero_reg));
2097 // We had an overflow or underflow in the conversion. Check if we
2098 // have a big exponent.
2099 // If greater or equal, the argument is already round and in v0.
2100 __ Branch(&restore_fcsr_and_return, ge, t3,
2101 Operand(HeapNumber::kMantissaBits));
2102 __ Branch(&wont_fit_smi);
2103
2104 __ bind(&no_fpu_error);
2105 // Move the result back to v0.
2106 __ mfc1(v0, f0);
2107 // Check if the result fits into a smi.
2108 __ Addu(a1, v0, Operand(0x40000000));
2109 __ Branch(&wont_fit_smi, lt, a1, Operand(zero_reg));
2110 // Tag the result.
2111 STATIC_ASSERT(kSmiTag == 0);
2112 __ sll(v0, v0, kSmiTagSize);
2113
2114 // Check for -0.
2115 __ Branch(&restore_fcsr_and_return, ne, v0, Operand(zero_reg));
2116 // t1 already holds the HeapNumber exponent.
2117 __ And(t0, t1, Operand(HeapNumber::kSignMask));
2118 // If our HeapNumber is negative it was -0, so load its address and return.
2119 // Else v0 is loaded with 0, so we can also just return.
2120 __ Branch(&restore_fcsr_and_return, eq, t0, Operand(zero_reg));
2121 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2122
2123 __ bind(&restore_fcsr_and_return);
2124 // Restore FCSR and return.
2125 __ ctc1(a3, FCSR);
2126
2127 __ Drop(argc + 1);
2128 __ Ret();
2129
2130 __ bind(&wont_fit_smi);
2131 // Restore FCSR and fall to slow case.
2132 __ ctc1(a3, FCSR);
2133
2134 __ bind(&slow);
2135 // Tail call the full function. We do not have to patch the receiver
2136 // because the function makes no use of it.
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002137 __ InvokeFunction(
2138 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002139
2140 __ bind(&miss);
2141 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002142 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002143
2144 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002145 return cell.is_null() ? GetCode(function) : GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002146}
2147
2148
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002149Handle<Code> CallStubCompiler::CompileMathAbsCall(
2150 Handle<Object> object,
2151 Handle<JSObject> holder,
2152 Handle<JSGlobalPropertyCell> cell,
2153 Handle<JSFunction> function,
2154 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002155 // ----------- S t a t e -------------
2156 // -- a2 : function name
2157 // -- ra : return address
2158 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2159 // -- ...
2160 // -- sp[argc * 4] : receiver
2161 // -----------------------------------
2162
2163 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002164 // If the object is not a JSObject or we got an unexpected number of
2165 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002166 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002167
2168 Label miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002169
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002170 GenerateNameCheck(name, &miss);
2171 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002172 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002173 STATIC_ASSERT(kSmiTag == 0);
2174 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002175 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
2176 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002177 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002178 ASSERT(cell->value() == *function);
2179 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2180 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002181 GenerateLoadFunctionFromCell(cell, function, &miss);
2182 }
2183
2184 // Load the (only) argument into v0.
2185 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2186
2187 // Check if the argument is a smi.
2188 Label not_smi;
2189 STATIC_ASSERT(kSmiTag == 0);
2190 __ JumpIfNotSmi(v0, &not_smi);
2191
2192 // Do bitwise not or do nothing depending on the sign of the
2193 // argument.
2194 __ sra(t0, v0, kBitsPerInt - 1);
2195 __ Xor(a1, v0, t0);
2196
2197 // Add 1 or do nothing depending on the sign of the argument.
2198 __ Subu(v0, a1, t0);
2199
2200 // If the result is still negative, go to the slow case.
2201 // This only happens for the most negative smi.
2202 Label slow;
2203 __ Branch(&slow, lt, v0, Operand(zero_reg));
2204
2205 // Smi case done.
2206 __ Drop(argc + 1);
2207 __ Ret();
2208
2209 // Check if the argument is a heap number and load its exponent and
2210 // sign.
2211 __ bind(&not_smi);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002212 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002213 __ lw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2214
2215 // Check the sign of the argument. If the argument is positive,
2216 // just return it.
2217 Label negative_sign;
2218 __ And(t0, a1, Operand(HeapNumber::kSignMask));
2219 __ Branch(&negative_sign, ne, t0, Operand(zero_reg));
2220 __ Drop(argc + 1);
2221 __ Ret();
2222
2223 // If the argument is negative, clear the sign, and return a new
2224 // number.
2225 __ bind(&negative_sign);
2226 __ Xor(a1, a1, Operand(HeapNumber::kSignMask));
2227 __ lw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2228 __ LoadRoot(t2, Heap::kHeapNumberMapRootIndex);
2229 __ AllocateHeapNumber(v0, t0, t1, t2, &slow);
2230 __ sw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2231 __ sw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2232 __ Drop(argc + 1);
2233 __ Ret();
2234
2235 // Tail call the full function. We do not have to patch the receiver
2236 // because the function makes no use of it.
2237 __ bind(&slow);
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002238 __ InvokeFunction(
2239 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002240
2241 __ bind(&miss);
2242 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002243 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002244
2245 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002246 return cell.is_null() ? GetCode(function) : GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002247}
2248
2249
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002250Handle<Code> CallStubCompiler::CompileFastApiCall(
lrn@chromium.org7516f052011-03-30 08:52:27 +00002251 const CallOptimization& optimization,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002252 Handle<Object> object,
2253 Handle<JSObject> holder,
2254 Handle<JSGlobalPropertyCell> cell,
2255 Handle<JSFunction> function,
2256 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002257
danno@chromium.org40cb8782011-05-25 07:58:50 +00002258 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002259
2260 ASSERT(optimization.is_simple_api_call());
2261 // Bail out if object is a global object as we don't want to
2262 // repatch it to global receiver.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002263 if (object->IsGlobalObject()) return Handle<Code>::null();
2264 if (!cell.is_null()) return Handle<Code>::null();
2265 if (!object->IsJSObject()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002266 int depth = optimization.GetPrototypeDepthOfExpectedType(
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002267 Handle<JSObject>::cast(object), holder);
2268 if (depth == kInvalidProtoDepth) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002269
2270 Label miss, miss_before_stack_reserved;
2271
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002272 GenerateNameCheck(name, &miss_before_stack_reserved);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002273
2274 // Get the receiver from the stack.
2275 const int argc = arguments().immediate();
2276 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2277
2278 // Check that the receiver isn't a smi.
2279 __ JumpIfSmi(a1, &miss_before_stack_reserved);
2280
2281 __ IncrementCounter(counters->call_const(), 1, a0, a3);
2282 __ IncrementCounter(counters->call_const_fast_api(), 1, a0, a3);
2283
2284 ReserveSpaceForFastApiCall(masm(), a0);
2285
2286 // Check that the maps haven't changed and find a Holder as a side effect.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002287 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0, name,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002288 depth, &miss);
2289
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002290 GenerateFastApiDirectCall(masm(), optimization, argc);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002291
2292 __ bind(&miss);
2293 FreeSpaceForFastApiCall(masm());
2294
2295 __ bind(&miss_before_stack_reserved);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002296 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002297
2298 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002299 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002300}
2301
2302
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002303Handle<Code> CallStubCompiler::CompileCallConstant(Handle<Object> object,
2304 Handle<JSObject> holder,
2305 Handle<JSFunction> function,
2306 Handle<String> name,
lrn@chromium.org7516f052011-03-30 08:52:27 +00002307 CheckType check) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002308 // ----------- S t a t e -------------
2309 // -- a2 : name
2310 // -- ra : return address
2311 // -----------------------------------
2312 if (HasCustomCallGenerator(function)) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002313 Handle<Code> code = CompileCustomCall(object, holder,
2314 Handle<JSGlobalPropertyCell>::null(),
2315 function, name);
2316 // A null handle means bail out to the regular compiler code below.
2317 if (!code.is_null()) return code;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002318 }
2319
2320 Label miss;
2321
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002322 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002323
2324 // Get the receiver from the stack.
2325 const int argc = arguments().immediate();
2326 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2327
2328 // Check that the receiver isn't a smi.
2329 if (check != NUMBER_CHECK) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002330 __ JumpIfSmi(a1, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002331 }
2332
2333 // Make sure that it's okay not to patch the on stack receiver
2334 // unless we're doing a receiver map check.
2335 ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002336 switch (check) {
2337 case RECEIVER_MAP_CHECK:
2338 __ IncrementCounter(masm()->isolate()->counters()->call_const(),
2339 1, a0, a3);
2340
2341 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002342 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2343 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002344
2345 // Patch the receiver on the stack with the global proxy if
2346 // necessary.
2347 if (object->IsGlobalObject()) {
2348 __ lw(a3, FieldMemOperand(a1, GlobalObject::kGlobalReceiverOffset));
2349 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2350 }
2351 break;
2352
2353 case STRING_CHECK:
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00002354 if (function->IsBuiltin() || !function->shared()->is_classic_mode()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002355 // Check that the object is a two-byte string or a symbol.
2356 __ GetObjectType(a1, a3, a3);
2357 __ Branch(&miss, Ugreater_equal, a3, Operand(FIRST_NONSTRING_TYPE));
2358 // Check that the maps starting from the prototype haven't changed.
2359 GenerateDirectLoadGlobalFunctionPrototype(
2360 masm(), Context::STRING_FUNCTION_INDEX, a0, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002361 CheckPrototypes(
2362 Handle<JSObject>(JSObject::cast(object->GetPrototype())),
2363 a0, holder, a3, a1, t0, name, &miss);
2364 } else {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002365 // Calling non-strict non-builtins with a value as the receiver
2366 // requires boxing.
2367 __ jmp(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002368 }
2369 break;
2370
2371 case NUMBER_CHECK:
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00002372 if (function->IsBuiltin() || !function->shared()->is_classic_mode()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002373 Label fast;
2374 // Check that the object is a smi or a heap number.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002375 __ JumpIfSmi(a1, &fast);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002376 __ GetObjectType(a1, a0, a0);
2377 __ Branch(&miss, ne, a0, Operand(HEAP_NUMBER_TYPE));
2378 __ bind(&fast);
2379 // Check that the maps starting from the prototype haven't changed.
2380 GenerateDirectLoadGlobalFunctionPrototype(
2381 masm(), Context::NUMBER_FUNCTION_INDEX, a0, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002382 CheckPrototypes(
2383 Handle<JSObject>(JSObject::cast(object->GetPrototype())),
2384 a0, holder, a3, a1, t0, name, &miss);
2385 } else {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002386 // Calling non-strict non-builtins with a value as the receiver
2387 // requires boxing.
2388 __ jmp(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002389 }
2390 break;
2391
2392 case BOOLEAN_CHECK:
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00002393 if (function->IsBuiltin() || !function->shared()->is_classic_mode()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002394 Label fast;
2395 // Check that the object is a boolean.
2396 __ LoadRoot(t0, Heap::kTrueValueRootIndex);
2397 __ Branch(&fast, eq, a1, Operand(t0));
2398 __ LoadRoot(t0, Heap::kFalseValueRootIndex);
2399 __ Branch(&miss, ne, a1, Operand(t0));
2400 __ bind(&fast);
2401 // Check that the maps starting from the prototype haven't changed.
2402 GenerateDirectLoadGlobalFunctionPrototype(
2403 masm(), Context::BOOLEAN_FUNCTION_INDEX, a0, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002404 CheckPrototypes(
2405 Handle<JSObject>(JSObject::cast(object->GetPrototype())),
2406 a0, holder, a3, a1, t0, name, &miss);
2407 } else {
2408 // Calling non-strict non-builtins with a value as the receiver
2409 // requires boxing.
2410 __ jmp(&miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002411 }
2412 break;
2413 }
2414
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002415 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002416 ? CALL_AS_FUNCTION
2417 : CALL_AS_METHOD;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002418 __ InvokeFunction(
2419 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002420
2421 // Handle call cache miss.
2422 __ bind(&miss);
2423
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002424 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002425
2426 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002427 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002428}
2429
2430
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002431Handle<Code> CallStubCompiler::CompileCallInterceptor(Handle<JSObject> object,
2432 Handle<JSObject> holder,
2433 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002434 // ----------- S t a t e -------------
2435 // -- a2 : name
2436 // -- ra : return address
2437 // -----------------------------------
2438
2439 Label miss;
2440
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002441 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002442
2443 // Get the number of arguments.
2444 const int argc = arguments().immediate();
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002445 LookupResult lookup(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002446 LookupPostInterceptor(holder, name, &lookup);
2447
2448 // Get the receiver from the stack.
2449 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2450
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002451 CallInterceptorCompiler compiler(this, arguments(), a2, extra_state_);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002452 compiler.Compile(masm(), object, holder, name, &lookup, a1, a3, t0, a0,
2453 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002454
2455 // Move returned value, the function to call, to a1.
2456 __ mov(a1, v0);
2457 // Restore receiver.
2458 __ lw(a0, MemOperand(sp, argc * kPointerSize));
2459
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002460 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002461
2462 // Handle call cache miss.
2463 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002464 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002465
2466 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002467 return GetCode(INTERCEPTOR, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002468}
2469
2470
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002471Handle<Code> CallStubCompiler::CompileCallGlobal(
2472 Handle<JSObject> object,
2473 Handle<GlobalObject> holder,
2474 Handle<JSGlobalPropertyCell> cell,
2475 Handle<JSFunction> function,
2476 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002477 // ----------- S t a t e -------------
2478 // -- a2 : name
2479 // -- ra : return address
2480 // -----------------------------------
2481
2482 if (HasCustomCallGenerator(function)) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002483 Handle<Code> code = CompileCustomCall(object, holder, cell, function, name);
2484 // A null handle means bail out to the regular compiler code below.
2485 if (!code.is_null()) return code;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002486 }
2487
2488 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002489 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002490
2491 // Get the number of arguments.
2492 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002493 GenerateGlobalReceiverCheck(object, holder, name, &miss);
2494 GenerateLoadFunctionFromCell(cell, function, &miss);
2495
2496 // Patch the receiver on the stack with the global proxy if
2497 // necessary.
2498 if (object->IsGlobalObject()) {
2499 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
2500 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2501 }
2502
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002503 // Set up the context (function already in r1).
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002504 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
2505
2506 // Jump to the cached code (tail call).
2507 Counters* counters = masm()->isolate()->counters();
2508 __ IncrementCounter(counters->call_global_inline(), 1, a3, t0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002509 ParameterCount expected(function->shared()->formal_parameter_count());
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002510 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
danno@chromium.org40cb8782011-05-25 07:58:50 +00002511 ? CALL_AS_FUNCTION
2512 : CALL_AS_METHOD;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002513 // We call indirectly through the code field in the function to
2514 // allow recompilation to take effect without changing any of the
2515 // call sites.
2516 __ lw(a3, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
2517 __ InvokeCode(a3, expected, arguments(), JUMP_FUNCTION,
2518 NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002519
2520 // Handle call cache miss.
2521 __ bind(&miss);
2522 __ IncrementCounter(counters->call_global_inline_miss(), 1, a1, a3);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002523 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002524
2525 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002526 return GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002527}
2528
2529
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002530Handle<Code> StoreStubCompiler::CompileStoreField(Handle<JSObject> object,
ager@chromium.org5c838252010-02-19 08:53:10 +00002531 int index,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002532 Handle<Map> transition,
2533 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002534 // ----------- S t a t e -------------
2535 // -- a0 : value
2536 // -- a1 : receiver
2537 // -- a2 : name
2538 // -- ra : return address
2539 // -----------------------------------
2540 Label miss;
2541
2542 // Name register might be clobbered.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002543 GenerateStoreField(masm(), object, index, transition, a1, a2, a3, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002544 __ bind(&miss);
2545 __ li(a2, Operand(Handle<String>(name))); // Restore name.
2546 Handle<Code> ic = masm()->isolate()->builtins()->Builtins::StoreIC_Miss();
2547 __ Jump(ic, RelocInfo::CODE_TARGET);
2548
2549 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002550 return GetCode(transition.is_null() ? FIELD : MAP_TRANSITION, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002551}
2552
2553
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002554Handle<Code> StoreStubCompiler::CompileStoreCallback(
2555 Handle<JSObject> object,
2556 Handle<AccessorInfo> callback,
2557 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002558 // ----------- S t a t e -------------
2559 // -- a0 : value
2560 // -- a1 : receiver
2561 // -- a2 : name
2562 // -- ra : return address
2563 // -----------------------------------
2564 Label miss;
2565
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002566 // Check that the map of the object hasn't changed.
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002567 __ CheckMap(a1, a3, Handle<Map>(object->map()), &miss,
2568 DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002569
2570 // Perform global security token check if needed.
2571 if (object->IsJSGlobalProxy()) {
2572 __ CheckAccessGlobalProxy(a1, a3, &miss);
2573 }
2574
2575 // Stub never generated for non-global objects that require access
2576 // checks.
2577 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
2578
2579 __ push(a1); // Receiver.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002580 __ li(a3, Operand(callback)); // Callback info.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002581 __ Push(a3, a2, a0);
2582
2583 // Do tail-call to the runtime system.
2584 ExternalReference store_callback_property =
2585 ExternalReference(IC_Utility(IC::kStoreCallbackProperty),
2586 masm()->isolate());
2587 __ TailCallExternalReference(store_callback_property, 4, 1);
2588
2589 // Handle store cache miss.
2590 __ bind(&miss);
2591 Handle<Code> ic = masm()->isolate()->builtins()->StoreIC_Miss();
2592 __ Jump(ic, RelocInfo::CODE_TARGET);
2593
2594 // Return the generated code.
2595 return GetCode(CALLBACKS, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002596}
2597
2598
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002599Handle<Code> StoreStubCompiler::CompileStoreInterceptor(
2600 Handle<JSObject> receiver,
2601 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002602 // ----------- S t a t e -------------
2603 // -- a0 : value
2604 // -- a1 : receiver
2605 // -- a2 : name
2606 // -- ra : return address
2607 // -----------------------------------
2608 Label miss;
2609
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002610 // Check that the map of the object hasn't changed.
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002611 __ CheckMap(a1, a3, Handle<Map>(receiver->map()), &miss,
2612 DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002613
2614 // Perform global security token check if needed.
2615 if (receiver->IsJSGlobalProxy()) {
2616 __ CheckAccessGlobalProxy(a1, a3, &miss);
2617 }
2618
2619 // Stub is never generated for non-global objects that require access
2620 // checks.
2621 ASSERT(receiver->IsJSGlobalProxy() || !receiver->IsAccessCheckNeeded());
2622
2623 __ Push(a1, a2, a0); // Receiver, name, value.
2624
2625 __ li(a0, Operand(Smi::FromInt(strict_mode_)));
2626 __ push(a0); // Strict mode.
2627
2628 // Do tail-call to the runtime system.
2629 ExternalReference store_ic_property =
2630 ExternalReference(IC_Utility(IC::kStoreInterceptorProperty),
2631 masm()->isolate());
2632 __ TailCallExternalReference(store_ic_property, 4, 1);
2633
2634 // Handle store cache miss.
2635 __ bind(&miss);
2636 Handle<Code> ic = masm()->isolate()->builtins()->Builtins::StoreIC_Miss();
2637 __ Jump(ic, RelocInfo::CODE_TARGET);
2638
2639 // Return the generated code.
2640 return GetCode(INTERCEPTOR, name);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00002641}
2642
2643
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002644Handle<Code> StoreStubCompiler::CompileStoreGlobal(
2645 Handle<GlobalObject> object,
2646 Handle<JSGlobalPropertyCell> cell,
2647 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002648 // ----------- S t a t e -------------
2649 // -- a0 : value
2650 // -- a1 : receiver
2651 // -- a2 : name
2652 // -- ra : return address
2653 // -----------------------------------
2654 Label miss;
2655
2656 // Check that the map of the global has not changed.
2657 __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
2658 __ Branch(&miss, ne, a3, Operand(Handle<Map>(object->map())));
2659
2660 // Check that the value in the cell is not the hole. If it is, this
2661 // cell could have been deleted and reintroducing the global needs
2662 // to update the property details in the property dictionary of the
2663 // global object. We bail out to the runtime system to do that.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002664 __ li(t0, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002665 __ LoadRoot(t1, Heap::kTheHoleValueRootIndex);
2666 __ lw(t2, FieldMemOperand(t0, JSGlobalPropertyCell::kValueOffset));
2667 __ Branch(&miss, eq, t1, Operand(t2));
2668
2669 // Store the value in the cell.
2670 __ sw(a0, FieldMemOperand(t0, JSGlobalPropertyCell::kValueOffset));
2671 __ mov(v0, a0); // Stored value must be returned in v0.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002672 // Cells are always rescanned, so no write barrier here.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00002673
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002674 Counters* counters = masm()->isolate()->counters();
2675 __ IncrementCounter(counters->named_store_global_inline(), 1, a1, a3);
2676 __ Ret();
2677
2678 // Handle store cache miss.
2679 __ bind(&miss);
2680 __ IncrementCounter(counters->named_store_global_inline_miss(), 1, a1, a3);
2681 Handle<Code> ic = masm()->isolate()->builtins()->StoreIC_Miss();
2682 __ Jump(ic, RelocInfo::CODE_TARGET);
2683
2684 // Return the generated code.
2685 return GetCode(NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002686}
2687
2688
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002689Handle<Code> LoadStubCompiler::CompileLoadNonexistent(Handle<String> name,
2690 Handle<JSObject> object,
2691 Handle<JSObject> last) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002692 // ----------- S t a t e -------------
2693 // -- a0 : receiver
2694 // -- ra : return address
2695 // -----------------------------------
2696 Label miss;
2697
2698 // Check that the receiver is not a smi.
2699 __ JumpIfSmi(a0, &miss);
2700
2701 // Check the maps of the full prototype chain.
2702 CheckPrototypes(object, a0, last, a3, a1, t0, name, &miss);
2703
2704 // If the last object in the prototype chain is a global object,
2705 // check that the global property cell is empty.
2706 if (last->IsGlobalObject()) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002707 GenerateCheckPropertyCell(
2708 masm(), Handle<GlobalObject>::cast(last), name, a1, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002709 }
2710
2711 // Return undefined if maps of the full prototype chain is still the same.
2712 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
2713 __ Ret();
2714
2715 __ bind(&miss);
2716 GenerateLoadMiss(masm(), Code::LOAD_IC);
2717
2718 // Return the generated code.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002719 return GetCode(NONEXISTENT, factory()->empty_string());
lrn@chromium.org7516f052011-03-30 08:52:27 +00002720}
2721
2722
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002723Handle<Code> LoadStubCompiler::CompileLoadField(Handle<JSObject> object,
2724 Handle<JSObject> holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +00002725 int index,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002726 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002727 // ----------- S t a t e -------------
2728 // -- a0 : receiver
2729 // -- a2 : name
2730 // -- ra : return address
2731 // -----------------------------------
2732 Label miss;
2733
2734 __ mov(v0, a0);
2735
2736 GenerateLoadField(object, holder, v0, a3, a1, t0, index, name, &miss);
2737 __ bind(&miss);
2738 GenerateLoadMiss(masm(), Code::LOAD_IC);
2739
2740 // Return the generated code.
2741 return GetCode(FIELD, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002742}
2743
2744
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002745Handle<Code> LoadStubCompiler::CompileLoadCallback(
2746 Handle<String> name,
2747 Handle<JSObject> object,
2748 Handle<JSObject> holder,
2749 Handle<AccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002750 // ----------- S t a t e -------------
2751 // -- a0 : receiver
2752 // -- a2 : name
2753 // -- ra : return address
2754 // -----------------------------------
2755 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002756 GenerateLoadCallback(object, holder, a0, a2, a3, a1, t0, callback, name,
2757 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002758 __ bind(&miss);
2759 GenerateLoadMiss(masm(), Code::LOAD_IC);
2760
2761 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002762 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002763}
2764
2765
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002766Handle<Code> LoadStubCompiler::CompileLoadConstant(Handle<JSObject> object,
2767 Handle<JSObject> holder,
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002768 Handle<JSFunction> value,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002769 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002770 // ----------- S t a t e -------------
2771 // -- a0 : receiver
2772 // -- a2 : name
2773 // -- ra : return address
2774 // -----------------------------------
2775 Label miss;
2776
2777 GenerateLoadConstant(object, holder, a0, a3, a1, t0, value, name, &miss);
2778 __ bind(&miss);
2779 GenerateLoadMiss(masm(), Code::LOAD_IC);
2780
2781 // Return the generated code.
2782 return GetCode(CONSTANT_FUNCTION, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002783}
2784
2785
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002786Handle<Code> LoadStubCompiler::CompileLoadInterceptor(Handle<JSObject> object,
2787 Handle<JSObject> holder,
2788 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002789 // ----------- S t a t e -------------
2790 // -- a0 : receiver
2791 // -- a2 : name
2792 // -- ra : return address
2793 // -- [sp] : receiver
2794 // -----------------------------------
2795 Label miss;
2796
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002797 LookupResult lookup(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002798 LookupPostInterceptor(holder, name, &lookup);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002799 GenerateLoadInterceptor(object, holder, &lookup, a0, a2, a3, a1, t0, name,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002800 &miss);
2801 __ bind(&miss);
2802 GenerateLoadMiss(masm(), Code::LOAD_IC);
2803
2804 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002805 return GetCode(INTERCEPTOR, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002806}
2807
2808
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002809Handle<Code> LoadStubCompiler::CompileLoadGlobal(
2810 Handle<JSObject> object,
2811 Handle<GlobalObject> holder,
2812 Handle<JSGlobalPropertyCell> cell,
2813 Handle<String> name,
2814 bool is_dont_delete) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002815 // ----------- S t a t e -------------
2816 // -- a0 : receiver
2817 // -- a2 : name
2818 // -- ra : return address
2819 // -----------------------------------
2820 Label miss;
2821
2822 // If the object is the holder then we know that it's a global
2823 // object which can only happen for contextual calls. In this case,
2824 // the receiver cannot be a smi.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002825 if (!object.is_identical_to(holder)) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002826 __ JumpIfSmi(a0, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002827 }
2828
2829 // Check that the map of the global has not changed.
2830 CheckPrototypes(object, a0, holder, a3, t0, a1, name, &miss);
2831
2832 // Get the value from the cell.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002833 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002834 __ lw(t0, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
2835
2836 // Check for deleted property if property can actually be deleted.
2837 if (!is_dont_delete) {
2838 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
2839 __ Branch(&miss, eq, t0, Operand(at));
2840 }
2841
2842 __ mov(v0, t0);
2843 Counters* counters = masm()->isolate()->counters();
2844 __ IncrementCounter(counters->named_load_global_stub(), 1, a1, a3);
2845 __ Ret();
2846
2847 __ bind(&miss);
2848 __ IncrementCounter(counters->named_load_global_stub_miss(), 1, a1, a3);
2849 GenerateLoadMiss(masm(), Code::LOAD_IC);
2850
2851 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002852 return GetCode(NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002853}
2854
2855
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002856Handle<Code> KeyedLoadStubCompiler::CompileLoadField(Handle<String> name,
2857 Handle<JSObject> receiver,
2858 Handle<JSObject> holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +00002859 int index) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002860 // ----------- S t a t e -------------
2861 // -- ra : return address
2862 // -- a0 : key
2863 // -- a1 : receiver
2864 // -----------------------------------
2865 Label miss;
2866
2867 // Check the key is the cached one.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002868 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002869
2870 GenerateLoadField(receiver, holder, a1, a2, a3, t0, index, name, &miss);
2871 __ bind(&miss);
2872 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
2873
2874 return GetCode(FIELD, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002875}
2876
2877
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002878Handle<Code> KeyedLoadStubCompiler::CompileLoadCallback(
2879 Handle<String> name,
2880 Handle<JSObject> receiver,
2881 Handle<JSObject> holder,
2882 Handle<AccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002883 // ----------- S t a t e -------------
2884 // -- ra : return address
2885 // -- a0 : key
2886 // -- a1 : receiver
2887 // -----------------------------------
2888 Label miss;
2889
2890 // Check the key is the cached one.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002891 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002892
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002893 GenerateLoadCallback(receiver, holder, a1, a0, a2, a3, t0, callback, name,
2894 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002895 __ bind(&miss);
2896 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
2897
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002898 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002899}
2900
2901
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002902Handle<Code> KeyedLoadStubCompiler::CompileLoadConstant(
2903 Handle<String> name,
2904 Handle<JSObject> receiver,
2905 Handle<JSObject> holder,
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002906 Handle<JSFunction> value) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002907 // ----------- S t a t e -------------
2908 // -- ra : return address
2909 // -- a0 : key
2910 // -- a1 : receiver
2911 // -----------------------------------
2912 Label miss;
2913
2914 // Check the key is the cached one.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002915 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002916
2917 GenerateLoadConstant(receiver, holder, a1, a2, a3, t0, value, name, &miss);
2918 __ bind(&miss);
2919 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
2920
2921 // Return the generated code.
2922 return GetCode(CONSTANT_FUNCTION, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002923}
2924
2925
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002926Handle<Code> KeyedLoadStubCompiler::CompileLoadInterceptor(
2927 Handle<JSObject> receiver,
2928 Handle<JSObject> holder,
2929 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002930 // ----------- S t a t e -------------
2931 // -- ra : return address
2932 // -- a0 : key
2933 // -- a1 : receiver
2934 // -----------------------------------
2935 Label miss;
2936
2937 // Check the key is the cached one.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002938 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002939
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002940 LookupResult lookup(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002941 LookupPostInterceptor(holder, name, &lookup);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002942 GenerateLoadInterceptor(receiver, holder, &lookup, a1, a0, a2, a3, t0, name,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002943 &miss);
2944 __ bind(&miss);
2945 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
2946
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002947 return GetCode(INTERCEPTOR, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002948}
2949
2950
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002951Handle<Code> KeyedLoadStubCompiler::CompileLoadArrayLength(
2952 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002953 // ----------- S t a t e -------------
2954 // -- ra : return address
2955 // -- a0 : key
2956 // -- a1 : receiver
2957 // -----------------------------------
2958 Label miss;
2959
2960 // Check the key is the cached one.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002961 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002962
2963 GenerateLoadArrayLength(masm(), a1, a2, &miss);
2964 __ bind(&miss);
2965 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
2966
2967 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002968}
2969
2970
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002971Handle<Code> KeyedLoadStubCompiler::CompileLoadStringLength(
2972 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002973 // ----------- S t a t e -------------
2974 // -- ra : return address
2975 // -- a0 : key
2976 // -- a1 : receiver
2977 // -----------------------------------
2978 Label miss;
2979
2980 Counters* counters = masm()->isolate()->counters();
2981 __ IncrementCounter(counters->keyed_load_string_length(), 1, a2, a3);
2982
2983 // Check the key is the cached one.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002984 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002985
2986 GenerateLoadStringLength(masm(), a1, a2, a3, &miss, true);
2987 __ bind(&miss);
2988 __ DecrementCounter(counters->keyed_load_string_length(), 1, a2, a3);
2989
2990 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
2991
2992 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002993}
2994
2995
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002996Handle<Code> KeyedLoadStubCompiler::CompileLoadFunctionPrototype(
2997 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002998 // ----------- S t a t e -------------
2999 // -- ra : return address
3000 // -- a0 : key
3001 // -- a1 : receiver
3002 // -----------------------------------
3003 Label miss;
3004
3005 Counters* counters = masm()->isolate()->counters();
3006 __ IncrementCounter(counters->keyed_load_function_prototype(), 1, a2, a3);
3007
3008 // Check the name hasn't changed.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003009 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003010
3011 GenerateLoadFunctionPrototype(masm(), a1, a2, a3, &miss);
3012 __ bind(&miss);
3013 __ DecrementCounter(counters->keyed_load_function_prototype(), 1, a2, a3);
3014 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
3015
3016 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003017}
3018
3019
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003020Handle<Code> KeyedLoadStubCompiler::CompileLoadElement(
3021 Handle<Map> receiver_map) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003022 // ----------- S t a t e -------------
3023 // -- ra : return address
3024 // -- a0 : key
3025 // -- a1 : receiver
3026 // -----------------------------------
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003027 ElementsKind elements_kind = receiver_map->elements_kind();
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003028 Handle<Code> stub = KeyedLoadElementStub(elements_kind).GetCode();
3029
3030 __ DispatchMap(a1, a2, receiver_map, stub, DO_SMI_CHECK);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003031
3032 Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Miss();
3033 __ Jump(ic, RelocInfo::CODE_TARGET);
3034
3035 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003036 return GetCode(NORMAL, factory()->empty_string());
danno@chromium.org40cb8782011-05-25 07:58:50 +00003037}
3038
3039
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003040Handle<Code> KeyedLoadStubCompiler::CompileLoadPolymorphic(
3041 MapHandleList* receiver_maps,
3042 CodeHandleList* handler_ics) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003043 // ----------- S t a t e -------------
3044 // -- ra : return address
3045 // -- a0 : key
3046 // -- a1 : receiver
3047 // -----------------------------------
3048 Label miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003049 __ JumpIfSmi(a1, &miss);
3050
danno@chromium.org40cb8782011-05-25 07:58:50 +00003051 int receiver_count = receiver_maps->length();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003052 __ lw(a2, FieldMemOperand(a1, HeapObject::kMapOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003053 for (int current = 0; current < receiver_count; ++current) {
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003054 __ Jump(handler_ics->at(current), RelocInfo::CODE_TARGET,
3055 eq, a2, Operand(receiver_maps->at(current)));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003056 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003057
3058 __ bind(&miss);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003059 Handle<Code> miss_ic = isolate()->builtins()->KeyedLoadIC_Miss();
3060 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003061
3062 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003063 return GetCode(NORMAL, factory()->empty_string(), MEGAMORPHIC);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003064}
3065
3066
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003067Handle<Code> KeyedStoreStubCompiler::CompileStoreField(Handle<JSObject> object,
lrn@chromium.org7516f052011-03-30 08:52:27 +00003068 int index,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003069 Handle<Map> transition,
3070 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003071 // ----------- S t a t e -------------
3072 // -- a0 : value
3073 // -- a1 : key
3074 // -- a2 : receiver
3075 // -- ra : return address
3076 // -----------------------------------
3077
3078 Label miss;
3079
3080 Counters* counters = masm()->isolate()->counters();
3081 __ IncrementCounter(counters->keyed_store_field(), 1, a3, t0);
3082
3083 // Check that the name has not changed.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003084 __ Branch(&miss, ne, a1, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003085
3086 // a3 is used as scratch register. a1 and a2 keep their values if a jump to
3087 // the miss label is generated.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003088 GenerateStoreField(masm(), object, index, transition, a2, a1, a3, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003089 __ bind(&miss);
3090
3091 __ DecrementCounter(counters->keyed_store_field(), 1, a3, t0);
3092 Handle<Code> ic = masm()->isolate()->builtins()->KeyedStoreIC_Miss();
3093 __ Jump(ic, RelocInfo::CODE_TARGET);
3094
3095 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003096 return GetCode(transition.is_null() ? FIELD : MAP_TRANSITION, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003097}
3098
3099
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003100Handle<Code> KeyedStoreStubCompiler::CompileStoreElement(
3101 Handle<Map> receiver_map) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003102 // ----------- S t a t e -------------
3103 // -- a0 : value
3104 // -- a1 : key
3105 // -- a2 : receiver
3106 // -- ra : return address
3107 // -- a3 : scratch
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003108 // -----------------------------------
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003109 ElementsKind elements_kind = receiver_map->elements_kind();
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003110 bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE;
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003111 Handle<Code> stub =
yangguo@chromium.org56454712012-02-16 15:33:53 +00003112 KeyedStoreElementStub(is_js_array, elements_kind, grow_mode_).GetCode();
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003113
3114 __ DispatchMap(a2, a3, receiver_map, stub, DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003115
danno@chromium.org40cb8782011-05-25 07:58:50 +00003116 Handle<Code> ic = isolate()->builtins()->KeyedStoreIC_Miss();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003117 __ Jump(ic, RelocInfo::CODE_TARGET);
3118
3119 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003120 return GetCode(NORMAL, factory()->empty_string());
lrn@chromium.org7516f052011-03-30 08:52:27 +00003121}
3122
3123
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003124Handle<Code> KeyedStoreStubCompiler::CompileStorePolymorphic(
3125 MapHandleList* receiver_maps,
3126 CodeHandleList* handler_stubs,
3127 MapHandleList* transitioned_maps) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003128 // ----------- S t a t e -------------
3129 // -- a0 : value
3130 // -- a1 : key
3131 // -- a2 : receiver
3132 // -- ra : return address
3133 // -- a3 : scratch
3134 // -----------------------------------
3135 Label miss;
3136 __ JumpIfSmi(a2, &miss);
3137
3138 int receiver_count = receiver_maps->length();
3139 __ lw(a3, FieldMemOperand(a2, HeapObject::kMapOffset));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003140 for (int i = 0; i < receiver_count; ++i) {
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003141 if (transitioned_maps->at(i).is_null()) {
3142 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET, eq,
3143 a3, Operand(receiver_maps->at(i)));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003144 } else {
3145 Label next_map;
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003146 __ Branch(&next_map, ne, a3, Operand(receiver_maps->at(i)));
3147 __ li(a3, Operand(transitioned_maps->at(i)));
3148 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003149 __ bind(&next_map);
3150 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003151 }
3152
3153 __ bind(&miss);
3154 Handle<Code> miss_ic = isolate()->builtins()->KeyedStoreIC_Miss();
3155 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
3156
3157 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003158 return GetCode(NORMAL, factory()->empty_string(), MEGAMORPHIC);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003159}
3160
3161
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003162Handle<Code> ConstructStubCompiler::CompileConstructStub(
3163 Handle<JSFunction> function) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003164 // a0 : argc
3165 // a1 : constructor
3166 // ra : return address
3167 // [sp] : last argument
3168 Label generic_stub_call;
3169
3170 // Use t7 for holding undefined which is used in several places below.
3171 __ LoadRoot(t7, Heap::kUndefinedValueRootIndex);
3172
3173#ifdef ENABLE_DEBUGGER_SUPPORT
3174 // Check to see whether there are any break points in the function code. If
3175 // there are jump to the generic constructor stub which calls the actual
3176 // code for the function thereby hitting the break points.
3177 __ lw(t5, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
3178 __ lw(a2, FieldMemOperand(t5, SharedFunctionInfo::kDebugInfoOffset));
3179 __ Branch(&generic_stub_call, ne, a2, Operand(t7));
3180#endif
3181
3182 // Load the initial map and verify that it is in fact a map.
3183 // a1: constructor function
3184 // t7: undefined
3185 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003186 __ JumpIfSmi(a2, &generic_stub_call);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003187 __ GetObjectType(a2, a3, t0);
3188 __ Branch(&generic_stub_call, ne, t0, Operand(MAP_TYPE));
3189
3190#ifdef DEBUG
3191 // Cannot construct functions this way.
3192 // a0: argc
3193 // a1: constructor function
3194 // a2: initial map
3195 // t7: undefined
3196 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceTypeOffset));
3197 __ Check(ne, "Function constructed by construct stub.",
3198 a3, Operand(JS_FUNCTION_TYPE));
3199#endif
3200
3201 // Now allocate the JSObject in new space.
3202 // a0: argc
3203 // a1: constructor function
3204 // a2: initial map
3205 // t7: undefined
3206 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceSizeOffset));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003207 __ AllocateInNewSpace(a3, t4, t5, t6, &generic_stub_call, SIZE_IN_WORDS);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003208
3209 // Allocated the JSObject, now initialize the fields. Map is set to initial
3210 // map and properties and elements are set to empty fixed array.
3211 // a0: argc
3212 // a1: constructor function
3213 // a2: initial map
3214 // a3: object size (in words)
3215 // t4: JSObject (not tagged)
3216 // t7: undefined
3217 __ LoadRoot(t6, Heap::kEmptyFixedArrayRootIndex);
3218 __ mov(t5, t4);
3219 __ sw(a2, MemOperand(t5, JSObject::kMapOffset));
3220 __ sw(t6, MemOperand(t5, JSObject::kPropertiesOffset));
3221 __ sw(t6, MemOperand(t5, JSObject::kElementsOffset));
3222 __ Addu(t5, t5, Operand(3 * kPointerSize));
3223 ASSERT_EQ(0 * kPointerSize, JSObject::kMapOffset);
3224 ASSERT_EQ(1 * kPointerSize, JSObject::kPropertiesOffset);
3225 ASSERT_EQ(2 * kPointerSize, JSObject::kElementsOffset);
3226
3227
3228 // Calculate the location of the first argument. The stack contains only the
3229 // argc arguments.
3230 __ sll(a1, a0, kPointerSizeLog2);
3231 __ Addu(a1, a1, sp);
3232
3233 // Fill all the in-object properties with undefined.
3234 // a0: argc
3235 // a1: first argument
3236 // a3: object size (in words)
3237 // t4: JSObject (not tagged)
3238 // t5: First in-object property of JSObject (not tagged)
3239 // t7: undefined
3240 // Fill the initialized properties with a constant value or a passed argument
3241 // depending on the this.x = ...; assignment in the function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003242 Handle<SharedFunctionInfo> shared(function->shared());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003243 for (int i = 0; i < shared->this_property_assignments_count(); i++) {
3244 if (shared->IsThisPropertyAssignmentArgument(i)) {
3245 Label not_passed, next;
3246 // Check if the argument assigned to the property is actually passed.
3247 int arg_number = shared->GetThisPropertyAssignmentArgument(i);
3248 __ Branch(&not_passed, less_equal, a0, Operand(arg_number));
3249 // Argument passed - find it on the stack.
3250 __ lw(a2, MemOperand(a1, (arg_number + 1) * -kPointerSize));
3251 __ sw(a2, MemOperand(t5));
3252 __ Addu(t5, t5, kPointerSize);
3253 __ jmp(&next);
3254 __ bind(&not_passed);
3255 // Set the property to undefined.
3256 __ sw(t7, MemOperand(t5));
3257 __ Addu(t5, t5, Operand(kPointerSize));
3258 __ bind(&next);
3259 } else {
3260 // Set the property to the constant value.
3261 Handle<Object> constant(shared->GetThisPropertyAssignmentConstant(i));
3262 __ li(a2, Operand(constant));
3263 __ sw(a2, MemOperand(t5));
3264 __ Addu(t5, t5, kPointerSize);
3265 }
3266 }
3267
3268 // Fill the unused in-object property fields with undefined.
3269 ASSERT(function->has_initial_map());
3270 for (int i = shared->this_property_assignments_count();
3271 i < function->initial_map()->inobject_properties();
3272 i++) {
3273 __ sw(t7, MemOperand(t5));
3274 __ Addu(t5, t5, kPointerSize);
3275 }
3276
3277 // a0: argc
3278 // t4: JSObject (not tagged)
3279 // Move argc to a1 and the JSObject to return to v0 and tag it.
3280 __ mov(a1, a0);
3281 __ mov(v0, t4);
3282 __ Or(v0, v0, Operand(kHeapObjectTag));
3283
3284 // v0: JSObject
3285 // a1: argc
3286 // Remove caller arguments and receiver from the stack and return.
3287 __ sll(t0, a1, kPointerSizeLog2);
3288 __ Addu(sp, sp, t0);
3289 __ Addu(sp, sp, Operand(kPointerSize));
3290 Counters* counters = masm()->isolate()->counters();
3291 __ IncrementCounter(counters->constructed_objects(), 1, a1, a2);
3292 __ IncrementCounter(counters->constructed_objects_stub(), 1, a1, a2);
3293 __ Ret();
3294
3295 // Jump to the generic stub in case the specialized code cannot handle the
3296 // construction.
3297 __ bind(&generic_stub_call);
3298 Handle<Code> generic_construct_stub =
3299 masm()->isolate()->builtins()->JSConstructStubGeneric();
3300 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET);
3301
3302 // Return the generated code.
3303 return GetCode();
3304}
3305
3306
danno@chromium.org40cb8782011-05-25 07:58:50 +00003307#undef __
3308#define __ ACCESS_MASM(masm)
3309
3310
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003311void KeyedLoadStubCompiler::GenerateLoadDictionaryElement(
3312 MacroAssembler* masm) {
3313 // ---------- S t a t e --------------
3314 // -- ra : return address
3315 // -- a0 : key
3316 // -- a1 : receiver
3317 // -----------------------------------
3318 Label slow, miss_force_generic;
3319
3320 Register key = a0;
3321 Register receiver = a1;
3322
3323 __ JumpIfNotSmi(key, &miss_force_generic);
3324 __ lw(t0, FieldMemOperand(receiver, JSObject::kElementsOffset));
3325 __ sra(a2, a0, kSmiTagSize);
3326 __ LoadFromNumberDictionary(&slow, t0, a0, v0, a2, a3, t1);
3327 __ Ret();
3328
3329 // Slow case, key and receiver still in a0 and a1.
3330 __ bind(&slow);
3331 __ IncrementCounter(
3332 masm->isolate()->counters()->keyed_load_external_array_slow(),
3333 1, a2, a3);
3334 // Entry registers are intact.
3335 // ---------- S t a t e --------------
3336 // -- ra : return address
3337 // -- a0 : key
3338 // -- a1 : receiver
3339 // -----------------------------------
3340 Handle<Code> slow_ic =
3341 masm->isolate()->builtins()->KeyedLoadIC_Slow();
3342 __ Jump(slow_ic, RelocInfo::CODE_TARGET);
3343
3344 // Miss case, call the runtime.
3345 __ bind(&miss_force_generic);
3346
3347 // ---------- S t a t e --------------
3348 // -- ra : return address
3349 // -- a0 : key
3350 // -- a1 : receiver
3351 // -----------------------------------
3352
3353 Handle<Code> miss_ic =
3354 masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric();
3355 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
3356}
3357
3358
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003359static bool IsElementTypeSigned(ElementsKind elements_kind) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003360 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003361 case EXTERNAL_BYTE_ELEMENTS:
3362 case EXTERNAL_SHORT_ELEMENTS:
3363 case EXTERNAL_INT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003364 return true;
3365
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003366 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
3367 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
3368 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
3369 case EXTERNAL_PIXEL_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003370 return false;
3371
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003372 case EXTERNAL_FLOAT_ELEMENTS:
3373 case EXTERNAL_DOUBLE_ELEMENTS:
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003374 case FAST_SMI_ONLY_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003375 case FAST_ELEMENTS:
3376 case FAST_DOUBLE_ELEMENTS:
3377 case DICTIONARY_ELEMENTS:
3378 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003379 UNREACHABLE();
3380 return false;
3381 }
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003382 return false;
lrn@chromium.org7516f052011-03-30 08:52:27 +00003383}
3384
3385
danno@chromium.org40cb8782011-05-25 07:58:50 +00003386void KeyedLoadStubCompiler::GenerateLoadExternalArray(
3387 MacroAssembler* masm,
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003388 ElementsKind elements_kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003389 // ---------- S t a t e --------------
3390 // -- ra : return address
3391 // -- a0 : key
3392 // -- a1 : receiver
3393 // -----------------------------------
danno@chromium.org40cb8782011-05-25 07:58:50 +00003394 Label miss_force_generic, slow, failed_allocation;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003395
3396 Register key = a0;
3397 Register receiver = a1;
3398
danno@chromium.org40cb8782011-05-25 07:58:50 +00003399 // This stub is meant to be tail-jumped to, the receiver must already
3400 // have been verified by the caller to not be a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003401
3402 // Check that the key is a smi.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003403 __ JumpIfNotSmi(key, &miss_force_generic);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003404
3405 __ lw(a3, FieldMemOperand(receiver, JSObject::kElementsOffset));
3406 // a3: elements array
3407
3408 // Check that the index is in range.
3409 __ lw(t1, FieldMemOperand(a3, ExternalArray::kLengthOffset));
3410 __ sra(t2, key, kSmiTagSize);
3411 // Unsigned comparison catches both negative and too-large values.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003412 __ Branch(&miss_force_generic, Ugreater_equal, key, Operand(t1));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003413
3414 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3415 // a3: base pointer of external storage
3416
3417 // We are not untagging smi key and instead work with it
3418 // as if it was premultiplied by 2.
fschneider@chromium.org1805e212011-09-05 10:49:12 +00003419 STATIC_ASSERT((kSmiTag == 0) && (kSmiTagSize == 1));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003420
3421 Register value = a2;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003422 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003423 case EXTERNAL_BYTE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003424 __ srl(t2, key, 1);
3425 __ addu(t3, a3, t2);
3426 __ lb(value, MemOperand(t3, 0));
3427 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003428 case EXTERNAL_PIXEL_ELEMENTS:
3429 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003430 __ srl(t2, key, 1);
3431 __ addu(t3, a3, t2);
3432 __ lbu(value, MemOperand(t3, 0));
3433 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003434 case EXTERNAL_SHORT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003435 __ addu(t3, a3, key);
3436 __ lh(value, MemOperand(t3, 0));
3437 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003438 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003439 __ addu(t3, a3, key);
3440 __ lhu(value, MemOperand(t3, 0));
3441 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003442 case EXTERNAL_INT_ELEMENTS:
3443 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003444 __ sll(t2, key, 1);
3445 __ addu(t3, a3, t2);
3446 __ lw(value, MemOperand(t3, 0));
3447 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003448 case EXTERNAL_FLOAT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003449 __ sll(t3, t2, 2);
3450 __ addu(t3, a3, t3);
3451 if (CpuFeatures::IsSupported(FPU)) {
3452 CpuFeatures::Scope scope(FPU);
3453 __ lwc1(f0, MemOperand(t3, 0));
3454 } else {
3455 __ lw(value, MemOperand(t3, 0));
3456 }
3457 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003458 case EXTERNAL_DOUBLE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003459 __ sll(t2, key, 2);
3460 __ addu(t3, a3, t2);
3461 if (CpuFeatures::IsSupported(FPU)) {
3462 CpuFeatures::Scope scope(FPU);
3463 __ ldc1(f0, MemOperand(t3, 0));
3464 } else {
3465 // t3: pointer to the beginning of the double we want to load.
3466 __ lw(a2, MemOperand(t3, 0));
3467 __ lw(a3, MemOperand(t3, Register::kSizeInBytes));
3468 }
3469 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003470 case FAST_ELEMENTS:
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003471 case FAST_SMI_ONLY_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003472 case FAST_DOUBLE_ELEMENTS:
3473 case DICTIONARY_ELEMENTS:
3474 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003475 UNREACHABLE();
3476 break;
3477 }
3478
3479 // For integer array types:
3480 // a2: value
3481 // For float array type:
3482 // f0: value (if FPU is supported)
3483 // a2: value (if FPU is not supported)
3484 // For double array type:
3485 // f0: value (if FPU is supported)
3486 // a2/a3: value (if FPU is not supported)
3487
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003488 if (elements_kind == EXTERNAL_INT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003489 // For the Int and UnsignedInt array types, we need to see whether
3490 // the value can be represented in a Smi. If not, we need to convert
3491 // it to a HeapNumber.
3492 Label box_int;
3493 __ Subu(t3, value, Operand(0xC0000000)); // Non-smi value gives neg result.
3494 __ Branch(&box_int, lt, t3, Operand(zero_reg));
3495 // Tag integer as smi and return it.
3496 __ sll(v0, value, kSmiTagSize);
3497 __ Ret();
3498
3499 __ bind(&box_int);
3500 // Allocate a HeapNumber for the result and perform int-to-double
3501 // conversion.
3502 // The arm version uses a temporary here to save r0, but we don't need to
3503 // (a0 is not modified).
3504 __ LoadRoot(t1, Heap::kHeapNumberMapRootIndex);
3505 __ AllocateHeapNumber(v0, a3, t0, t1, &slow);
3506
3507 if (CpuFeatures::IsSupported(FPU)) {
3508 CpuFeatures::Scope scope(FPU);
3509 __ mtc1(value, f0);
3510 __ cvt_d_w(f0, f0);
3511 __ sdc1(f0, MemOperand(v0, HeapNumber::kValueOffset - kHeapObjectTag));
3512 __ Ret();
3513 } else {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003514 Register dst1 = t2;
3515 Register dst2 = t3;
3516 FloatingPointHelper::Destination dest =
3517 FloatingPointHelper::kCoreRegisters;
3518 FloatingPointHelper::ConvertIntToDouble(masm,
3519 value,
3520 dest,
3521 f0,
3522 dst1,
3523 dst2,
3524 t1,
3525 f2);
3526 __ sw(dst1, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
3527 __ sw(dst2, FieldMemOperand(v0, HeapNumber::kExponentOffset));
3528 __ Ret();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003529 }
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003530 } else if (elements_kind == EXTERNAL_UNSIGNED_INT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003531 // The test is different for unsigned int values. Since we need
3532 // the value to be in the range of a positive smi, we can't
3533 // handle either of the top two bits being set in the value.
3534 if (CpuFeatures::IsSupported(FPU)) {
3535 CpuFeatures::Scope scope(FPU);
3536 Label pl_box_int;
3537 __ And(t2, value, Operand(0xC0000000));
3538 __ Branch(&pl_box_int, ne, t2, Operand(zero_reg));
3539
3540 // It can fit in an Smi.
3541 // Tag integer as smi and return it.
3542 __ sll(v0, value, kSmiTagSize);
3543 __ Ret();
3544
3545 __ bind(&pl_box_int);
3546 // Allocate a HeapNumber for the result and perform int-to-double
3547 // conversion. Don't use a0 and a1 as AllocateHeapNumber clobbers all
3548 // registers - also when jumping due to exhausted young space.
3549 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3550 __ AllocateHeapNumber(v0, t2, t3, t6, &slow);
3551
3552 // This is replaced by a macro:
3553 // __ mtc1(value, f0); // LS 32-bits.
3554 // __ mtc1(zero_reg, f1); // MS 32-bits are all zero.
3555 // __ cvt_d_l(f0, f0); // Use 64 bit conv to get correct unsigned 32-bit.
3556
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00003557 __ Cvt_d_uw(f0, value, f22);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003558
3559 __ sdc1(f0, MemOperand(v0, HeapNumber::kValueOffset - kHeapObjectTag));
3560
3561 __ Ret();
3562 } else {
3563 // Check whether unsigned integer fits into smi.
3564 Label box_int_0, box_int_1, done;
3565 __ And(t2, value, Operand(0x80000000));
3566 __ Branch(&box_int_0, ne, t2, Operand(zero_reg));
3567 __ And(t2, value, Operand(0x40000000));
3568 __ Branch(&box_int_1, ne, t2, Operand(zero_reg));
3569
3570 // Tag integer as smi and return it.
3571 __ sll(v0, value, kSmiTagSize);
3572 __ Ret();
3573
3574 Register hiword = value; // a2.
3575 Register loword = a3;
3576
3577 __ bind(&box_int_0);
3578 // Integer does not have leading zeros.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003579 GenerateUInt2Double(masm, hiword, loword, t0, 0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003580 __ Branch(&done);
3581
3582 __ bind(&box_int_1);
3583 // Integer has one leading zero.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003584 GenerateUInt2Double(masm, hiword, loword, t0, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003585
3586
3587 __ bind(&done);
3588 // Integer was converted to double in registers hiword:loword.
3589 // Wrap it into a HeapNumber. Don't use a0 and a1 as AllocateHeapNumber
3590 // clobbers all registers - also when jumping due to exhausted young
3591 // space.
3592 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3593 __ AllocateHeapNumber(t2, t3, t5, t6, &slow);
3594
3595 __ sw(hiword, FieldMemOperand(t2, HeapNumber::kExponentOffset));
3596 __ sw(loword, FieldMemOperand(t2, HeapNumber::kMantissaOffset));
3597
3598 __ mov(v0, t2);
3599 __ Ret();
3600 }
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003601 } else if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003602 // For the floating-point array type, we need to always allocate a
3603 // HeapNumber.
3604 if (CpuFeatures::IsSupported(FPU)) {
3605 CpuFeatures::Scope scope(FPU);
3606 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3607 // AllocateHeapNumber clobbers all registers - also when jumping due to
3608 // exhausted young space.
3609 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3610 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3611 // The float (single) value is already in fpu reg f0 (if we use float).
3612 __ cvt_d_s(f0, f0);
3613 __ sdc1(f0, MemOperand(v0, HeapNumber::kValueOffset - kHeapObjectTag));
3614 __ Ret();
3615 } else {
3616 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3617 // AllocateHeapNumber clobbers all registers - also when jumping due to
3618 // exhausted young space.
3619 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3620 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3621 // FPU is not available, do manual single to double conversion.
3622
3623 // a2: floating point value (binary32).
3624 // v0: heap number for result
3625
3626 // Extract mantissa to t4.
3627 __ And(t4, value, Operand(kBinary32MantissaMask));
3628
3629 // Extract exponent to t5.
3630 __ srl(t5, value, kBinary32MantissaBits);
3631 __ And(t5, t5, Operand(kBinary32ExponentMask >> kBinary32MantissaBits));
3632
3633 Label exponent_rebiased;
3634 __ Branch(&exponent_rebiased, eq, t5, Operand(zero_reg));
3635
3636 __ li(t0, 0x7ff);
3637 __ Xor(t1, t5, Operand(0xFF));
3638 __ movz(t5, t0, t1); // Set t5 to 0x7ff only if t5 is equal to 0xff.
3639 __ Branch(&exponent_rebiased, eq, t0, Operand(0xff));
3640
3641 // Rebias exponent.
3642 __ Addu(t5,
3643 t5,
3644 Operand(-kBinary32ExponentBias + HeapNumber::kExponentBias));
3645
3646 __ bind(&exponent_rebiased);
3647 __ And(a2, value, Operand(kBinary32SignMask));
3648 value = no_reg;
3649 __ sll(t0, t5, HeapNumber::kMantissaBitsInTopWord);
3650 __ or_(a2, a2, t0);
3651
3652 // Shift mantissa.
3653 static const int kMantissaShiftForHiWord =
3654 kBinary32MantissaBits - HeapNumber::kMantissaBitsInTopWord;
3655
3656 static const int kMantissaShiftForLoWord =
3657 kBitsPerInt - kMantissaShiftForHiWord;
3658
3659 __ srl(t0, t4, kMantissaShiftForHiWord);
3660 __ or_(a2, a2, t0);
3661 __ sll(a0, t4, kMantissaShiftForLoWord);
3662
3663 __ sw(a2, FieldMemOperand(v0, HeapNumber::kExponentOffset));
3664 __ sw(a0, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
3665 __ Ret();
3666 }
3667
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003668 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003669 if (CpuFeatures::IsSupported(FPU)) {
3670 CpuFeatures::Scope scope(FPU);
3671 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3672 // AllocateHeapNumber clobbers all registers - also when jumping due to
3673 // exhausted young space.
3674 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3675 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3676 // The double value is already in f0
3677 __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
3678 __ Ret();
3679 } else {
3680 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3681 // AllocateHeapNumber clobbers all registers - also when jumping due to
3682 // exhausted young space.
3683 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3684 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3685
3686 __ sw(a2, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
3687 __ sw(a3, FieldMemOperand(v0, HeapNumber::kExponentOffset));
3688 __ Ret();
3689 }
3690
3691 } else {
3692 // Tag integer as smi and return it.
3693 __ sll(v0, value, kSmiTagSize);
3694 __ Ret();
3695 }
3696
3697 // Slow case, key and receiver still in a0 and a1.
3698 __ bind(&slow);
3699 __ IncrementCounter(
danno@chromium.org40cb8782011-05-25 07:58:50 +00003700 masm->isolate()->counters()->keyed_load_external_array_slow(),
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003701 1, a2, a3);
3702
3703 // ---------- S t a t e --------------
3704 // -- ra : return address
3705 // -- a0 : key
3706 // -- a1 : receiver
3707 // -----------------------------------
3708
3709 __ Push(a1, a0);
3710
3711 __ TailCallRuntime(Runtime::kKeyedGetProperty, 2, 1);
3712
danno@chromium.org40cb8782011-05-25 07:58:50 +00003713 __ bind(&miss_force_generic);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003714 Handle<Code> stub =
3715 masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric();
3716 __ Jump(stub, RelocInfo::CODE_TARGET);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003717}
3718
3719
danno@chromium.org40cb8782011-05-25 07:58:50 +00003720void KeyedStoreStubCompiler::GenerateStoreExternalArray(
3721 MacroAssembler* masm,
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003722 ElementsKind elements_kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003723 // ---------- S t a t e --------------
3724 // -- a0 : value
3725 // -- a1 : key
3726 // -- a2 : receiver
3727 // -- ra : return address
3728 // -----------------------------------
3729
danno@chromium.org40cb8782011-05-25 07:58:50 +00003730 Label slow, check_heap_number, miss_force_generic;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003731
3732 // Register usage.
3733 Register value = a0;
3734 Register key = a1;
3735 Register receiver = a2;
3736 // a3 mostly holds the elements array or the destination external array.
3737
danno@chromium.org40cb8782011-05-25 07:58:50 +00003738 // This stub is meant to be tail-jumped to, the receiver must already
3739 // have been verified by the caller to not be a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003740
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003741 // Check that the key is a smi.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003742 __ JumpIfNotSmi(key, &miss_force_generic);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003743
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003744 __ lw(a3, FieldMemOperand(receiver, JSObject::kElementsOffset));
3745
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003746 // Check that the index is in range.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003747 __ lw(t1, FieldMemOperand(a3, ExternalArray::kLengthOffset));
3748 // Unsigned comparison catches both negative and too-large values.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003749 __ Branch(&miss_force_generic, Ugreater_equal, key, Operand(t1));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003750
3751 // Handle both smis and HeapNumbers in the fast path. Go to the
3752 // runtime for all other kinds of values.
3753 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003754
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003755 if (elements_kind == EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003756 // Double to pixel conversion is only implemented in the runtime for now.
3757 __ JumpIfNotSmi(value, &slow);
3758 } else {
3759 __ JumpIfNotSmi(value, &check_heap_number);
3760 }
3761 __ SmiUntag(t1, value);
3762 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3763
3764 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003765 // t1: value (integer).
3766
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003767 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003768 case EXTERNAL_PIXEL_ELEMENTS: {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003769 // Clamp the value to [0..255].
3770 // v0 is used as a scratch register here.
3771 Label done;
3772 __ li(v0, Operand(255));
3773 // Normal branch: nop in delay slot.
3774 __ Branch(&done, gt, t1, Operand(v0));
3775 // Use delay slot in this branch.
3776 __ Branch(USE_DELAY_SLOT, &done, lt, t1, Operand(zero_reg));
3777 __ mov(v0, zero_reg); // In delay slot.
3778 __ mov(v0, t1); // Value is in range 0..255.
3779 __ bind(&done);
3780 __ mov(t1, v0);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003781
3782 __ srl(t8, key, 1);
3783 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003784 __ sb(t1, MemOperand(t8, 0));
3785 }
3786 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003787 case EXTERNAL_BYTE_ELEMENTS:
3788 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003789 __ srl(t8, key, 1);
3790 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003791 __ sb(t1, MemOperand(t8, 0));
3792 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003793 case EXTERNAL_SHORT_ELEMENTS:
3794 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003795 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003796 __ sh(t1, MemOperand(t8, 0));
3797 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003798 case EXTERNAL_INT_ELEMENTS:
3799 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003800 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003801 __ addu(t8, a3, t8);
3802 __ sw(t1, MemOperand(t8, 0));
3803 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003804 case EXTERNAL_FLOAT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003805 // Perform int-to-float conversion and store to memory.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003806 __ SmiUntag(t0, key);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003807 StoreIntAsFloat(masm, a3, t0, t1, t2, t3, t4);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003808 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003809 case EXTERNAL_DOUBLE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003810 __ sll(t8, key, 2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003811 __ addu(a3, a3, t8);
3812 // a3: effective address of the double element
3813 FloatingPointHelper::Destination destination;
3814 if (CpuFeatures::IsSupported(FPU)) {
3815 destination = FloatingPointHelper::kFPURegisters;
3816 } else {
3817 destination = FloatingPointHelper::kCoreRegisters;
3818 }
3819 FloatingPointHelper::ConvertIntToDouble(
danno@chromium.org40cb8782011-05-25 07:58:50 +00003820 masm, t1, destination,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003821 f0, t2, t3, // These are: double_dst, dst1, dst2.
3822 t0, f2); // These are: scratch2, single_scratch.
3823 if (destination == FloatingPointHelper::kFPURegisters) {
3824 CpuFeatures::Scope scope(FPU);
3825 __ sdc1(f0, MemOperand(a3, 0));
3826 } else {
3827 __ sw(t2, MemOperand(a3, 0));
3828 __ sw(t3, MemOperand(a3, Register::kSizeInBytes));
3829 }
3830 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003831 case FAST_ELEMENTS:
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003832 case FAST_SMI_ONLY_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003833 case FAST_DOUBLE_ELEMENTS:
3834 case DICTIONARY_ELEMENTS:
3835 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003836 UNREACHABLE();
3837 break;
3838 }
3839
3840 // Entry registers are intact, a0 holds the value which is the return value.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003841 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003842 __ Ret();
3843
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003844 if (elements_kind != EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003845 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003846 __ bind(&check_heap_number);
3847 __ GetObjectType(value, t1, t2);
3848 __ Branch(&slow, ne, t2, Operand(HEAP_NUMBER_TYPE));
3849
3850 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3851
3852 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003853
3854 // The WebGL specification leaves the behavior of storing NaN and
3855 // +/-Infinity into integer arrays basically undefined. For more
3856 // reproducible behavior, convert these to zero.
3857
3858 if (CpuFeatures::IsSupported(FPU)) {
3859 CpuFeatures::Scope scope(FPU);
3860
3861 __ ldc1(f0, FieldMemOperand(a0, HeapNumber::kValueOffset));
3862
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003863 if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003864 __ cvt_s_d(f0, f0);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003865 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003866 __ addu(t8, a3, t8);
3867 __ swc1(f0, MemOperand(t8, 0));
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003868 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003869 __ sll(t8, key, 2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003870 __ addu(t8, a3, t8);
3871 __ sdc1(f0, MemOperand(t8, 0));
3872 } else {
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00003873 __ EmitECMATruncate(t3, f0, f2, t2, t1, t5);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003874
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003875 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003876 case EXTERNAL_BYTE_ELEMENTS:
3877 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003878 __ srl(t8, key, 1);
3879 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003880 __ sb(t3, MemOperand(t8, 0));
3881 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003882 case EXTERNAL_SHORT_ELEMENTS:
3883 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003884 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003885 __ sh(t3, MemOperand(t8, 0));
3886 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003887 case EXTERNAL_INT_ELEMENTS:
3888 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003889 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003890 __ addu(t8, a3, t8);
3891 __ sw(t3, MemOperand(t8, 0));
3892 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003893 case EXTERNAL_PIXEL_ELEMENTS:
3894 case EXTERNAL_FLOAT_ELEMENTS:
3895 case EXTERNAL_DOUBLE_ELEMENTS:
3896 case FAST_ELEMENTS:
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003897 case FAST_SMI_ONLY_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003898 case FAST_DOUBLE_ELEMENTS:
3899 case DICTIONARY_ELEMENTS:
3900 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003901 UNREACHABLE();
3902 break;
3903 }
3904 }
3905
3906 // Entry registers are intact, a0 holds the value
3907 // which is the return value.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003908 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003909 __ Ret();
3910 } else {
3911 // FPU is not available, do manual conversions.
3912
3913 __ lw(t3, FieldMemOperand(value, HeapNumber::kExponentOffset));
3914 __ lw(t4, FieldMemOperand(value, HeapNumber::kMantissaOffset));
3915
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003916 if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003917 Label done, nan_or_infinity_or_zero;
3918 static const int kMantissaInHiWordShift =
3919 kBinary32MantissaBits - HeapNumber::kMantissaBitsInTopWord;
3920
3921 static const int kMantissaInLoWordShift =
3922 kBitsPerInt - kMantissaInHiWordShift;
3923
3924 // Test for all special exponent values: zeros, subnormal numbers, NaNs
3925 // and infinities. All these should be converted to 0.
3926 __ li(t5, HeapNumber::kExponentMask);
3927 __ and_(t6, t3, t5);
3928 __ Branch(&nan_or_infinity_or_zero, eq, t6, Operand(zero_reg));
3929
3930 __ xor_(t1, t6, t5);
3931 __ li(t2, kBinary32ExponentMask);
3932 __ movz(t6, t2, t1); // Only if t6 is equal to t5.
3933 __ Branch(&nan_or_infinity_or_zero, eq, t6, Operand(t5));
3934
3935 // Rebias exponent.
3936 __ srl(t6, t6, HeapNumber::kExponentShift);
3937 __ Addu(t6,
3938 t6,
3939 Operand(kBinary32ExponentBias - HeapNumber::kExponentBias));
3940
3941 __ li(t1, Operand(kBinary32MaxExponent));
3942 __ Slt(t1, t1, t6);
3943 __ And(t2, t3, Operand(HeapNumber::kSignMask));
3944 __ Or(t2, t2, Operand(kBinary32ExponentMask));
3945 __ movn(t3, t2, t1); // Only if t6 is gt kBinary32MaxExponent.
3946 __ Branch(&done, gt, t6, Operand(kBinary32MaxExponent));
3947
3948 __ Slt(t1, t6, Operand(kBinary32MinExponent));
3949 __ And(t2, t3, Operand(HeapNumber::kSignMask));
3950 __ movn(t3, t2, t1); // Only if t6 is lt kBinary32MinExponent.
3951 __ Branch(&done, lt, t6, Operand(kBinary32MinExponent));
3952
3953 __ And(t7, t3, Operand(HeapNumber::kSignMask));
3954 __ And(t3, t3, Operand(HeapNumber::kMantissaMask));
3955 __ sll(t3, t3, kMantissaInHiWordShift);
3956 __ or_(t7, t7, t3);
3957 __ srl(t4, t4, kMantissaInLoWordShift);
3958 __ or_(t7, t7, t4);
3959 __ sll(t6, t6, kBinary32ExponentShift);
3960 __ or_(t3, t7, t6);
3961
3962 __ bind(&done);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003963 __ sll(t9, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003964 __ addu(t9, a2, t9);
3965 __ sw(t3, MemOperand(t9, 0));
3966
3967 // Entry registers are intact, a0 holds the value which is the return
3968 // value.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003969 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003970 __ Ret();
3971
3972 __ bind(&nan_or_infinity_or_zero);
3973 __ And(t7, t3, Operand(HeapNumber::kSignMask));
3974 __ And(t3, t3, Operand(HeapNumber::kMantissaMask));
3975 __ or_(t6, t6, t7);
3976 __ sll(t3, t3, kMantissaInHiWordShift);
3977 __ or_(t6, t6, t3);
3978 __ srl(t4, t4, kMantissaInLoWordShift);
3979 __ or_(t3, t6, t4);
3980 __ Branch(&done);
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003981 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003982 __ sll(t8, t0, 3);
3983 __ addu(t8, a3, t8);
3984 // t8: effective address of destination element.
3985 __ sw(t4, MemOperand(t8, 0));
3986 __ sw(t3, MemOperand(t8, Register::kSizeInBytes));
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003987 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003988 __ Ret();
3989 } else {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003990 bool is_signed_type = IsElementTypeSigned(elements_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003991 int meaningfull_bits = is_signed_type ? (kBitsPerInt - 1) : kBitsPerInt;
3992 int32_t min_value = is_signed_type ? 0x80000000 : 0x00000000;
3993
3994 Label done, sign;
3995
3996 // Test for all special exponent values: zeros, subnormal numbers, NaNs
3997 // and infinities. All these should be converted to 0.
3998 __ li(t5, HeapNumber::kExponentMask);
3999 __ and_(t6, t3, t5);
4000 __ movz(t3, zero_reg, t6); // Only if t6 is equal to zero.
4001 __ Branch(&done, eq, t6, Operand(zero_reg));
4002
4003 __ xor_(t2, t6, t5);
4004 __ movz(t3, zero_reg, t2); // Only if t6 is equal to t5.
4005 __ Branch(&done, eq, t6, Operand(t5));
4006
4007 // Unbias exponent.
4008 __ srl(t6, t6, HeapNumber::kExponentShift);
4009 __ Subu(t6, t6, Operand(HeapNumber::kExponentBias));
4010 // If exponent is negative then result is 0.
4011 __ slt(t2, t6, zero_reg);
4012 __ movn(t3, zero_reg, t2); // Only if exponent is negative.
4013 __ Branch(&done, lt, t6, Operand(zero_reg));
4014
4015 // If exponent is too big then result is minimal value.
4016 __ slti(t1, t6, meaningfull_bits - 1);
4017 __ li(t2, min_value);
4018 __ movz(t3, t2, t1); // Only if t6 is ge meaningfull_bits - 1.
4019 __ Branch(&done, ge, t6, Operand(meaningfull_bits - 1));
4020
4021 __ And(t5, t3, Operand(HeapNumber::kSignMask));
4022 __ And(t3, t3, Operand(HeapNumber::kMantissaMask));
4023 __ Or(t3, t3, Operand(1u << HeapNumber::kMantissaBitsInTopWord));
4024
4025 __ li(t9, HeapNumber::kMantissaBitsInTopWord);
4026 __ subu(t6, t9, t6);
4027 __ slt(t1, t6, zero_reg);
4028 __ srlv(t2, t3, t6);
4029 __ movz(t3, t2, t1); // Only if t6 is positive.
4030 __ Branch(&sign, ge, t6, Operand(zero_reg));
4031
4032 __ subu(t6, zero_reg, t6);
4033 __ sllv(t3, t3, t6);
4034 __ li(t9, meaningfull_bits);
4035 __ subu(t6, t9, t6);
4036 __ srlv(t4, t4, t6);
4037 __ or_(t3, t3, t4);
4038
4039 __ bind(&sign);
4040 __ subu(t2, t3, zero_reg);
4041 __ movz(t3, t2, t5); // Only if t5 is zero.
4042
4043 __ bind(&done);
4044
4045 // Result is in t3.
4046 // This switch block should be exactly the same as above (FPU mode).
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004047 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004048 case EXTERNAL_BYTE_ELEMENTS:
4049 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004050 __ srl(t8, key, 1);
4051 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004052 __ sb(t3, MemOperand(t8, 0));
4053 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004054 case EXTERNAL_SHORT_ELEMENTS:
4055 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004056 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004057 __ sh(t3, MemOperand(t8, 0));
4058 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004059 case EXTERNAL_INT_ELEMENTS:
4060 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004061 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004062 __ addu(t8, a3, t8);
4063 __ sw(t3, MemOperand(t8, 0));
4064 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004065 case EXTERNAL_PIXEL_ELEMENTS:
4066 case EXTERNAL_FLOAT_ELEMENTS:
4067 case EXTERNAL_DOUBLE_ELEMENTS:
4068 case FAST_ELEMENTS:
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004069 case FAST_SMI_ONLY_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004070 case FAST_DOUBLE_ELEMENTS:
4071 case DICTIONARY_ELEMENTS:
4072 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004073 UNREACHABLE();
4074 break;
4075 }
4076 }
4077 }
4078 }
4079
danno@chromium.org40cb8782011-05-25 07:58:50 +00004080 // Slow case, key and receiver still in a0 and a1.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004081 __ bind(&slow);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004082 __ IncrementCounter(
4083 masm->isolate()->counters()->keyed_load_external_array_slow(),
4084 1, a2, a3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004085 // Entry registers are intact.
4086 // ---------- S t a t e --------------
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004087 // -- ra : return address
danno@chromium.org40cb8782011-05-25 07:58:50 +00004088 // -- a0 : key
4089 // -- a1 : receiver
4090 // -----------------------------------
4091 Handle<Code> slow_ic =
4092 masm->isolate()->builtins()->KeyedStoreIC_Slow();
4093 __ Jump(slow_ic, RelocInfo::CODE_TARGET);
4094
4095 // Miss case, call the runtime.
4096 __ bind(&miss_force_generic);
4097
4098 // ---------- S t a t e --------------
4099 // -- ra : return address
4100 // -- a0 : key
4101 // -- a1 : receiver
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004102 // -----------------------------------
4103
danno@chromium.org40cb8782011-05-25 07:58:50 +00004104 Handle<Code> miss_ic =
4105 masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric();
4106 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
4107}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004108
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004109
danno@chromium.org40cb8782011-05-25 07:58:50 +00004110void KeyedLoadStubCompiler::GenerateLoadFastElement(MacroAssembler* masm) {
4111 // ----------- S t a t e -------------
4112 // -- ra : return address
4113 // -- a0 : key
4114 // -- a1 : receiver
4115 // -----------------------------------
4116 Label miss_force_generic;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004117
danno@chromium.org40cb8782011-05-25 07:58:50 +00004118 // This stub is meant to be tail-jumped to, the receiver must already
4119 // have been verified by the caller to not be a smi.
4120
4121 // Check that the key is a smi.
4122 __ JumpIfNotSmi(a0, &miss_force_generic);
4123
4124 // Get the elements array.
4125 __ lw(a2, FieldMemOperand(a1, JSObject::kElementsOffset));
4126 __ AssertFastElements(a2);
4127
4128 // Check that the key is within bounds.
4129 __ lw(a3, FieldMemOperand(a2, FixedArray::kLengthOffset));
4130 __ Branch(&miss_force_generic, hs, a0, Operand(a3));
4131
4132 // Load the result and make sure it's not the hole.
4133 __ Addu(a3, a2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
fschneider@chromium.org1805e212011-09-05 10:49:12 +00004134 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004135 __ sll(t0, a0, kPointerSizeLog2 - kSmiTagSize);
4136 __ Addu(t0, t0, a3);
4137 __ lw(t0, MemOperand(t0));
4138 __ LoadRoot(t1, Heap::kTheHoleValueRootIndex);
4139 __ Branch(&miss_force_generic, eq, t0, Operand(t1));
4140 __ mov(v0, t0);
4141 __ Ret();
4142
4143 __ bind(&miss_force_generic);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00004144 Handle<Code> stub =
4145 masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric();
4146 __ Jump(stub, RelocInfo::CODE_TARGET);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004147}
4148
4149
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00004150void KeyedLoadStubCompiler::GenerateLoadFastDoubleElement(
4151 MacroAssembler* masm) {
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004152 // ----------- S t a t e -------------
4153 // -- ra : return address
4154 // -- a0 : key
4155 // -- a1 : receiver
4156 // -----------------------------------
4157 Label miss_force_generic, slow_allocate_heapnumber;
4158
4159 Register key_reg = a0;
4160 Register receiver_reg = a1;
4161 Register elements_reg = a2;
4162 Register heap_number_reg = a2;
4163 Register indexed_double_offset = a3;
4164 Register scratch = t0;
4165 Register scratch2 = t1;
4166 Register scratch3 = t2;
4167 Register heap_number_map = t3;
4168
4169 // This stub is meant to be tail-jumped to, the receiver must already
4170 // have been verified by the caller to not be a smi.
4171
4172 // Check that the key is a smi.
4173 __ JumpIfNotSmi(key_reg, &miss_force_generic);
4174
4175 // Get the elements array.
4176 __ lw(elements_reg,
4177 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4178
4179 // Check that the key is within bounds.
4180 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4181 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch));
4182
4183 // Load the upper word of the double in the fixed array and test for NaN.
4184 __ sll(scratch2, key_reg, kDoubleSizeLog2 - kSmiTagSize);
4185 __ Addu(indexed_double_offset, elements_reg, Operand(scratch2));
4186 uint32_t upper_32_offset = FixedArray::kHeaderSize + sizeof(kHoleNanLower32);
4187 __ lw(scratch, FieldMemOperand(indexed_double_offset, upper_32_offset));
4188 __ Branch(&miss_force_generic, eq, scratch, Operand(kHoleNanUpper32));
4189
4190 // Non-NaN. Allocate a new heap number and copy the double value into it.
4191 __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
4192 __ AllocateHeapNumber(heap_number_reg, scratch2, scratch3,
4193 heap_number_map, &slow_allocate_heapnumber);
4194
4195 // Don't need to reload the upper 32 bits of the double, it's already in
4196 // scratch.
4197 __ sw(scratch, FieldMemOperand(heap_number_reg,
4198 HeapNumber::kExponentOffset));
4199 __ lw(scratch, FieldMemOperand(indexed_double_offset,
4200 FixedArray::kHeaderSize));
4201 __ sw(scratch, FieldMemOperand(heap_number_reg,
4202 HeapNumber::kMantissaOffset));
4203
4204 __ mov(v0, heap_number_reg);
4205 __ Ret();
4206
4207 __ bind(&slow_allocate_heapnumber);
4208 Handle<Code> slow_ic =
4209 masm->isolate()->builtins()->KeyedLoadIC_Slow();
4210 __ Jump(slow_ic, RelocInfo::CODE_TARGET);
4211
4212 __ bind(&miss_force_generic);
4213 Handle<Code> miss_ic =
4214 masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric();
4215 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00004216}
4217
4218
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004219void KeyedStoreStubCompiler::GenerateStoreFastElement(
4220 MacroAssembler* masm,
4221 bool is_js_array,
yangguo@chromium.org56454712012-02-16 15:33:53 +00004222 ElementsKind elements_kind,
4223 KeyedAccessGrowMode grow_mode) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00004224 // ----------- S t a t e -------------
4225 // -- a0 : value
4226 // -- a1 : key
4227 // -- a2 : receiver
4228 // -- ra : return address
4229 // -- a3 : scratch
4230 // -- a4 : scratch (elements)
4231 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00004232 Label miss_force_generic, transition_elements_kind, grow, slow;
4233 Label finish_store, check_capacity;
danno@chromium.org40cb8782011-05-25 07:58:50 +00004234
4235 Register value_reg = a0;
4236 Register key_reg = a1;
4237 Register receiver_reg = a2;
yangguo@chromium.org56454712012-02-16 15:33:53 +00004238 Register scratch = t0;
4239 Register elements_reg = a3;
4240 Register length_reg = t1;
4241 Register scratch2 = t2;
4242 Register scratch3 = t3;
danno@chromium.org40cb8782011-05-25 07:58:50 +00004243
4244 // This stub is meant to be tail-jumped to, the receiver must already
4245 // have been verified by the caller to not be a smi.
4246
4247 // Check that the key is a smi.
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00004248 __ JumpIfNotSmi(key_reg, &miss_force_generic);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004249
yangguo@chromium.org56454712012-02-16 15:33:53 +00004250 if (elements_kind == FAST_SMI_ONLY_ELEMENTS) {
4251 __ JumpIfNotSmi(value_reg, &transition_elements_kind);
4252 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00004253
4254 // Check that the key is within bounds.
yangguo@chromium.org56454712012-02-16 15:33:53 +00004255 __ lw(elements_reg,
4256 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00004257 if (is_js_array) {
4258 __ lw(scratch, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4259 } else {
4260 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4261 }
4262 // Compare smis.
yangguo@chromium.org56454712012-02-16 15:33:53 +00004263 if (is_js_array && grow_mode == ALLOW_JSARRAY_GROWTH) {
4264 __ Branch(&grow, hs, key_reg, Operand(scratch));
4265 } else {
4266 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch));
4267 }
4268
4269 // Make sure elements is a fast element array, not 'cow'.
4270 __ CheckMap(elements_reg,
4271 scratch,
4272 Heap::kFixedArrayMapRootIndex,
4273 &miss_force_generic,
4274 DONT_DO_SMI_CHECK);
4275
4276 __ bind(&finish_store);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004277
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004278 if (elements_kind == FAST_SMI_ONLY_ELEMENTS) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004279 __ Addu(scratch,
4280 elements_reg,
4281 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4282 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
4283 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
4284 __ Addu(scratch, scratch, scratch2);
4285 __ sw(value_reg, MemOperand(scratch));
4286 } else {
4287 ASSERT(elements_kind == FAST_ELEMENTS);
4288 __ Addu(scratch,
4289 elements_reg,
4290 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4291 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
4292 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
4293 __ Addu(scratch, scratch, scratch2);
4294 __ sw(value_reg, MemOperand(scratch));
4295 __ mov(receiver_reg, value_reg);
4296 ASSERT(elements_kind == FAST_ELEMENTS);
4297 __ RecordWrite(elements_reg, // Object.
4298 scratch, // Address.
4299 receiver_reg, // Value.
4300 kRAHasNotBeenSaved,
4301 kDontSaveFPRegs);
4302 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00004303 // value_reg (a0) is preserved.
4304 // Done.
4305 __ Ret();
4306
4307 __ bind(&miss_force_generic);
4308 Handle<Code> ic =
4309 masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric();
4310 __ Jump(ic, RelocInfo::CODE_TARGET);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004311
4312 __ bind(&transition_elements_kind);
4313 Handle<Code> ic_miss = masm->isolate()->builtins()->KeyedStoreIC_Miss();
4314 __ Jump(ic_miss, RelocInfo::CODE_TARGET);
yangguo@chromium.org56454712012-02-16 15:33:53 +00004315
4316 if (is_js_array && grow_mode == ALLOW_JSARRAY_GROWTH) {
4317 // Grow the array by a single element if possible.
4318 __ bind(&grow);
4319
4320 // Make sure the array is only growing by a single element, anything else
4321 // must be handled by the runtime.
4322 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch));
4323
4324 // Check for the empty array, and preallocate a small backing store if
4325 // possible.
4326 __ lw(length_reg,
4327 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4328 __ lw(elements_reg,
4329 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4330 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
4331 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
4332
4333 int size = FixedArray::SizeFor(JSArray::kPreallocatedArrayElements);
4334 __ AllocateInNewSpace(size, elements_reg, scratch, scratch2, &slow,
4335 TAG_OBJECT);
4336
4337 __ LoadRoot(scratch, Heap::kFixedArrayMapRootIndex);
4338 __ sw(scratch, FieldMemOperand(elements_reg, JSObject::kMapOffset));
4339 __ li(scratch, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
4340 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4341 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
4342 for (int i = 1; i < JSArray::kPreallocatedArrayElements; ++i) {
4343 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::SizeFor(i)));
4344 }
4345
4346 // Store the element at index zero.
4347 __ sw(value_reg, FieldMemOperand(elements_reg, FixedArray::SizeFor(0)));
4348
4349 // Install the new backing store in the JSArray.
4350 __ sw(elements_reg,
4351 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4352 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
4353 scratch, kRAHasNotBeenSaved, kDontSaveFPRegs,
4354 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4355
4356 // Increment the length of the array.
4357 __ li(length_reg, Operand(Smi::FromInt(1)));
4358 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4359 __ Ret();
4360
4361 __ bind(&check_capacity);
4362 // Check for cow elements, in general they are not handled by this stub
4363 __ CheckMap(elements_reg,
4364 scratch,
4365 Heap::kFixedCOWArrayMapRootIndex,
4366 &miss_force_generic,
4367 DONT_DO_SMI_CHECK);
4368
4369 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4370 __ Branch(&slow, hs, length_reg, Operand(scratch));
4371
4372 // Grow the array and finish the store.
4373 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
4374 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4375 __ jmp(&finish_store);
4376
4377 __ bind(&slow);
4378 Handle<Code> ic_slow = masm->isolate()->builtins()->KeyedStoreIC_Slow();
4379 __ Jump(ic_slow, RelocInfo::CODE_TARGET);
4380 }
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00004381}
4382
4383
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00004384void KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(
4385 MacroAssembler* masm,
yangguo@chromium.org56454712012-02-16 15:33:53 +00004386 bool is_js_array,
4387 KeyedAccessGrowMode grow_mode) {
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004388 // ----------- S t a t e -------------
4389 // -- a0 : value
4390 // -- a1 : key
4391 // -- a2 : receiver
4392 // -- ra : return address
4393 // -- a3 : scratch
4394 // -- t0 : scratch (elements_reg)
4395 // -- t1 : scratch (mantissa_reg)
4396 // -- t2 : scratch (exponent_reg)
4397 // -- t3 : scratch4
4398 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00004399 Label miss_force_generic, transition_elements_kind, grow, slow;
4400 Label finish_store, check_capacity;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004401
4402 Register value_reg = a0;
4403 Register key_reg = a1;
4404 Register receiver_reg = a2;
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004405 Register elements_reg = a3;
4406 Register scratch1 = t0;
4407 Register scratch2 = t1;
4408 Register scratch3 = t2;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004409 Register scratch4 = t3;
yangguo@chromium.org56454712012-02-16 15:33:53 +00004410 Register length_reg = t3;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004411
4412 // This stub is meant to be tail-jumped to, the receiver must already
4413 // have been verified by the caller to not be a smi.
4414 __ JumpIfNotSmi(key_reg, &miss_force_generic);
4415
4416 __ lw(elements_reg,
4417 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4418
4419 // Check that the key is within bounds.
4420 if (is_js_array) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004421 __ lw(scratch1, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004422 } else {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004423 __ lw(scratch1,
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004424 FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4425 }
4426 // Compare smis, unsigned compare catches both negative and out-of-bound
4427 // indexes.
yangguo@chromium.org56454712012-02-16 15:33:53 +00004428 if (grow_mode == ALLOW_JSARRAY_GROWTH) {
4429 __ Branch(&grow, hs, key_reg, Operand(scratch1));
4430 } else {
4431 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch1));
4432 }
4433
4434 __ bind(&finish_store);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004435
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004436 __ StoreNumberToDoubleElements(value_reg,
4437 key_reg,
4438 receiver_reg,
4439 elements_reg,
4440 scratch1,
4441 scratch2,
4442 scratch3,
4443 scratch4,
4444 &transition_elements_kind);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004445
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00004446 __ Ret(USE_DELAY_SLOT);
4447 __ mov(v0, value_reg); // In delay slot.
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004448
4449 // Handle store cache miss, replacing the ic with the generic stub.
4450 __ bind(&miss_force_generic);
4451 Handle<Code> ic =
4452 masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric();
4453 __ Jump(ic, RelocInfo::CODE_TARGET);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004454
4455 __ bind(&transition_elements_kind);
4456 Handle<Code> ic_miss = masm->isolate()->builtins()->KeyedStoreIC_Miss();
4457 __ Jump(ic_miss, RelocInfo::CODE_TARGET);
yangguo@chromium.org56454712012-02-16 15:33:53 +00004458
4459 if (is_js_array && grow_mode == ALLOW_JSARRAY_GROWTH) {
4460 // Grow the array by a single element if possible.
4461 __ bind(&grow);
4462
4463 // Make sure the array is only growing by a single element, anything else
4464 // must be handled by the runtime.
4465 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch1));
4466
4467 // Transition on values that can't be stored in a FixedDoubleArray.
4468 Label value_is_smi;
4469 __ JumpIfSmi(value_reg, &value_is_smi);
4470 __ lw(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
4471 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex);
4472 __ Branch(&transition_elements_kind, ne, scratch1, Operand(at));
4473 __ bind(&value_is_smi);
4474
4475 // Check for the empty array, and preallocate a small backing store if
4476 // possible.
4477 __ lw(length_reg,
4478 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4479 __ lw(elements_reg,
4480 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4481 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
4482 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
4483
4484 int size = FixedDoubleArray::SizeFor(JSArray::kPreallocatedArrayElements);
4485 __ AllocateInNewSpace(size, elements_reg, scratch1, scratch2, &slow,
4486 TAG_OBJECT);
4487
4488 // Initialize the new FixedDoubleArray. Leave elements unitialized for
4489 // efficiency, they are guaranteed to be initialized before use.
4490 __ LoadRoot(scratch1, Heap::kFixedDoubleArrayMapRootIndex);
4491 __ sw(scratch1, FieldMemOperand(elements_reg, JSObject::kMapOffset));
4492 __ li(scratch1, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
4493 __ sw(scratch1,
4494 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
4495
4496 // Install the new backing store in the JSArray.
4497 __ sw(elements_reg,
4498 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4499 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
4500 scratch1, kRAHasNotBeenSaved, kDontSaveFPRegs,
4501 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4502
4503 // Increment the length of the array.
4504 __ li(length_reg, Operand(Smi::FromInt(1)));
4505 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4506 __ jmp(&finish_store);
4507
4508 __ bind(&check_capacity);
4509 // Make sure that the backing store can hold additional elements.
4510 __ lw(scratch1,
4511 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
4512 __ Branch(&slow, hs, length_reg, Operand(scratch1));
4513
4514 // Grow the array and finish the store.
4515 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
4516 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4517 __ jmp(&finish_store);
4518
4519 __ bind(&slow);
4520 Handle<Code> ic_slow = masm->isolate()->builtins()->KeyedStoreIC_Slow();
4521 __ Jump(ic_slow, RelocInfo::CODE_TARGET);
4522 }
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00004523}
4524
4525
ager@chromium.org5c838252010-02-19 08:53:10 +00004526#undef __
4527
4528} } // namespace v8::internal
4529
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00004530#endif // V8_TARGET_ARCH_MIPS