blob: dc2a35736c6678d227faaf838bef19bc55f3af2f [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.
jkummerow@chromium.org28faa982012-04-13 09:58:30 +0000432 CompareMapMode mode = transition.is_null() ? ALLOW_ELEMENT_TRANSITION_MAPS
433 : REQUIRE_EXACT_MAP;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +0000434 __ CheckMap(receiver_reg, scratch, Handle<Map>(object->map()), miss_label,
jkummerow@chromium.org28faa982012-04-13 09:58:30 +0000435 DO_SMI_CHECK, mode);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000436
437 // Perform global security token check if needed.
438 if (object->IsJSGlobalProxy()) {
439 __ CheckAccessGlobalProxy(receiver_reg, scratch, miss_label);
440 }
441
442 // Stub never generated for non-global objects that require access
443 // checks.
444 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
445
446 // Perform map transition for the receiver if necessary.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000447 if (!transition.is_null() && (object->map()->unused_property_fields() == 0)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000448 // The properties must be extended before we can store the value.
449 // We jump to a runtime call that extends the properties array.
450 __ push(receiver_reg);
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000451 __ li(a2, Operand(transition));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000452 __ Push(a2, a0);
453 __ TailCallExternalReference(
454 ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
455 masm->isolate()),
456 3, 1);
457 return;
458 }
459
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000460 if (!transition.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000461 // Update the map of the object; no write barrier updating is
462 // needed because the map is never in new space.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000463 __ li(t0, Operand(transition));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000464 __ sw(t0, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
465 }
466
467 // Adjust for the number of properties stored in the object. Even in the
468 // face of a transition we can use the old map here because the size of the
469 // object and the number of in-object properties is not going to change.
470 index -= object->map()->inobject_properties();
471
472 if (index < 0) {
473 // Set the property straight into the object.
474 int offset = object->map()->instance_size() + (index * kPointerSize);
475 __ sw(a0, FieldMemOperand(receiver_reg, offset));
476
477 // Skip updating write barrier if storing a smi.
478 __ JumpIfSmi(a0, &exit, scratch);
479
480 // Update the write barrier for the array address.
481 // Pass the now unused name_reg as a scratch register.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000482 __ mov(name_reg, a0);
483 __ RecordWriteField(receiver_reg,
484 offset,
485 name_reg,
486 scratch,
487 kRAHasNotBeenSaved,
488 kDontSaveFPRegs);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000489 } else {
490 // Write to the properties array.
491 int offset = index * kPointerSize + FixedArray::kHeaderSize;
492 // Get the properties array.
493 __ lw(scratch, FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
494 __ sw(a0, FieldMemOperand(scratch, offset));
495
496 // Skip updating write barrier if storing a smi.
497 __ JumpIfSmi(a0, &exit);
498
499 // Update the write barrier for the array address.
500 // Ok to clobber receiver_reg and name_reg, since we return.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000501 __ mov(name_reg, a0);
502 __ RecordWriteField(scratch,
503 offset,
504 name_reg,
505 receiver_reg,
506 kRAHasNotBeenSaved,
507 kDontSaveFPRegs);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000508 }
509
510 // Return the value (register v0).
511 __ bind(&exit);
512 __ mov(v0, a0);
513 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +0000514}
515
516
517void StubCompiler::GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000518 ASSERT(kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000519 Handle<Code> code = (kind == Code::LOAD_IC)
520 ? masm->isolate()->builtins()->LoadIC_Miss()
521 : masm->isolate()->builtins()->KeyedLoadIC_Miss();
522 __ Jump(code, RelocInfo::CODE_TARGET);
ager@chromium.org5c838252010-02-19 08:53:10 +0000523}
524
525
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000526static void GenerateCallFunction(MacroAssembler* masm,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000527 Handle<Object> object,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000528 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000529 Label* miss,
530 Code::ExtraICState extra_ic_state) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000531 // ----------- S t a t e -------------
532 // -- a0: receiver
533 // -- a1: function to call
534 // -----------------------------------
535 // Check that the function really is a function.
536 __ JumpIfSmi(a1, miss);
537 __ GetObjectType(a1, a3, a3);
538 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
539
540 // Patch the receiver on the stack with the global proxy if
541 // necessary.
542 if (object->IsGlobalObject()) {
543 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
544 __ sw(a3, MemOperand(sp, arguments.immediate() * kPointerSize));
545 }
546
547 // Invoke the function.
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000548 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state)
549 ? CALL_AS_FUNCTION
550 : CALL_AS_METHOD;
551 __ InvokeFunction(a1, arguments, JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000552}
553
554
555static void PushInterceptorArguments(MacroAssembler* masm,
556 Register receiver,
557 Register holder,
558 Register name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000559 Handle<JSObject> holder_obj) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000560 __ push(name);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000561 Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
562 ASSERT(!masm->isolate()->heap()->InNewSpace(*interceptor));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000563 Register scratch = name;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000564 __ li(scratch, Operand(interceptor));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000565 __ Push(scratch, receiver, holder);
566 __ lw(scratch, FieldMemOperand(scratch, InterceptorInfo::kDataOffset));
567 __ push(scratch);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000568 __ li(scratch, Operand(ExternalReference::isolate_address()));
569 __ push(scratch);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000570}
571
572
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000573static void CompileCallLoadPropertyWithInterceptor(
574 MacroAssembler* masm,
575 Register receiver,
576 Register holder,
577 Register name,
578 Handle<JSObject> holder_obj) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000579 PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
580
581 ExternalReference ref =
582 ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorOnly),
583 masm->isolate());
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000584 __ PrepareCEntryArgs(6);
ulan@chromium.org6ff65142012-03-21 09:52:17 +0000585 __ PrepareCEntryFunction(ref);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000586
587 CEntryStub stub(1);
588 __ CallStub(&stub);
589}
590
591
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000592static const int kFastApiCallArguments = 4;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000593
594
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000595// Reserves space for the extra arguments to API function in the
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000596// caller's frame.
597//
598// These arguments are set by CheckPrototypes and GenerateFastApiDirectCall.
599static void ReserveSpaceForFastApiCall(MacroAssembler* masm,
600 Register scratch) {
601 ASSERT(Smi::FromInt(0) == 0);
602 for (int i = 0; i < kFastApiCallArguments; i++) {
603 __ push(zero_reg);
604 }
605}
606
607
608// Undoes the effects of ReserveSpaceForFastApiCall.
609static void FreeSpaceForFastApiCall(MacroAssembler* masm) {
610 __ Drop(kFastApiCallArguments);
611}
612
613
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000614static void GenerateFastApiDirectCall(MacroAssembler* masm,
615 const CallOptimization& optimization,
616 int argc) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000617 // ----------- S t a t e -------------
618 // -- sp[0] : holder (set by CheckPrototypes)
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000619 // -- sp[4] : callee JS function
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000620 // -- sp[8] : call data
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000621 // -- sp[12] : isolate
622 // -- sp[16] : last JS argument
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000623 // -- ...
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000624 // -- sp[(argc + 3) * 4] : first JS argument
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000625 // -- sp[(argc + 4) * 4] : receiver
626 // -----------------------------------
627 // Get the function and setup the context.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000628 Handle<JSFunction> function = optimization.constant_function();
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000629 __ LoadHeapObject(t1, function);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000630 __ lw(cp, FieldMemOperand(t1, JSFunction::kContextOffset));
631
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000632 // Pass the additional arguments.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000633 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
634 Handle<Object> call_data(api_call_info->data());
635 if (masm->isolate()->heap()->InNewSpace(*call_data)) {
636 __ li(a0, api_call_info);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000637 __ lw(t2, FieldMemOperand(a0, CallHandlerInfo::kDataOffset));
638 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000639 __ li(t2, call_data);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000640 }
641
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000642 __ li(t3, Operand(ExternalReference::isolate_address()));
643 // Store JS function, call data and isolate.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000644 __ sw(t1, MemOperand(sp, 1 * kPointerSize));
645 __ sw(t2, MemOperand(sp, 2 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000646 __ sw(t3, MemOperand(sp, 3 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000647
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000648 // Prepare arguments.
649 __ Addu(a2, sp, Operand(3 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000650
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000651 // Allocate the v8::Arguments structure in the arguments' space since
652 // it's not controlled by GC.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000653 const int kApiStackSpace = 4;
654
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000655 FrameScope frame_scope(masm, StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000656 __ EnterExitFrame(false, kApiStackSpace);
657
658 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
659 // struct from the function (which is currently the case). This means we pass
660 // the first argument in a1 instead of a0. TryCallApiFunctionAndReturn
661 // will handle setting up a0.
662
663 // a1 = v8::Arguments&
664 // Arguments is built at sp + 1 (sp is a reserved spot for ra).
665 __ Addu(a1, sp, kPointerSize);
666
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000667 // v8::Arguments::implicit_args_
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000668 __ sw(a2, MemOperand(a1, 0 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000669 // v8::Arguments::values_
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000670 __ Addu(t0, a2, Operand(argc * kPointerSize));
671 __ sw(t0, MemOperand(a1, 1 * kPointerSize));
672 // v8::Arguments::length_ = argc
673 __ li(t0, Operand(argc));
674 __ sw(t0, MemOperand(a1, 2 * kPointerSize));
675 // v8::Arguments::is_construct_call = 0
676 __ sw(zero_reg, MemOperand(a1, 3 * kPointerSize));
677
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000678 const int kStackUnwindSpace = argc + kFastApiCallArguments + 1;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000679 Address function_address = v8::ToCData<Address>(api_call_info->callback());
680 ApiFunction fun(function_address);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000681 ExternalReference ref =
682 ExternalReference(&fun,
683 ExternalReference::DIRECT_API_CALL,
684 masm->isolate());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000685 AllowExternalCallThatCantCauseGC scope(masm);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000686 __ CallApiFunctionAndReturn(ref, kStackUnwindSpace);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000687}
688
lrn@chromium.org7516f052011-03-30 08:52:27 +0000689class CallInterceptorCompiler BASE_EMBEDDED {
690 public:
691 CallInterceptorCompiler(StubCompiler* stub_compiler,
692 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000693 Register name,
694 Code::ExtraICState extra_ic_state)
lrn@chromium.org7516f052011-03-30 08:52:27 +0000695 : stub_compiler_(stub_compiler),
696 arguments_(arguments),
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000697 name_(name),
698 extra_ic_state_(extra_ic_state) {}
lrn@chromium.org7516f052011-03-30 08:52:27 +0000699
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000700 void Compile(MacroAssembler* masm,
701 Handle<JSObject> object,
702 Handle<JSObject> holder,
703 Handle<String> name,
704 LookupResult* lookup,
705 Register receiver,
706 Register scratch1,
707 Register scratch2,
708 Register scratch3,
709 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000710 ASSERT(holder->HasNamedInterceptor());
711 ASSERT(!holder->GetNamedInterceptor()->getter()->IsUndefined());
712
713 // Check that the receiver isn't a smi.
714 __ JumpIfSmi(receiver, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000715 CallOptimization optimization(lookup);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000716 if (optimization.is_constant_call()) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000717 CompileCacheable(masm, object, receiver, scratch1, scratch2, scratch3,
718 holder, lookup, name, optimization, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000719 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000720 CompileRegular(masm, object, receiver, scratch1, scratch2, scratch3,
721 name, holder, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000722 }
723 }
724
725 private:
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000726 void CompileCacheable(MacroAssembler* masm,
727 Handle<JSObject> object,
728 Register receiver,
729 Register scratch1,
730 Register scratch2,
731 Register scratch3,
732 Handle<JSObject> interceptor_holder,
733 LookupResult* lookup,
734 Handle<String> name,
735 const CallOptimization& optimization,
736 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000737 ASSERT(optimization.is_constant_call());
738 ASSERT(!lookup->holder()->IsGlobalObject());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000739 Counters* counters = masm->isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000740 int depth1 = kInvalidProtoDepth;
741 int depth2 = kInvalidProtoDepth;
742 bool can_do_fast_api_call = false;
743 if (optimization.is_simple_api_call() &&
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000744 !lookup->holder()->IsGlobalObject()) {
745 depth1 = optimization.GetPrototypeDepthOfExpectedType(
746 object, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000747 if (depth1 == kInvalidProtoDepth) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000748 depth2 = optimization.GetPrototypeDepthOfExpectedType(
749 interceptor_holder, Handle<JSObject>(lookup->holder()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000750 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000751 can_do_fast_api_call =
752 depth1 != kInvalidProtoDepth || depth2 != kInvalidProtoDepth;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000753 }
754
755 __ IncrementCounter(counters->call_const_interceptor(), 1,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000756 scratch1, scratch2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000757
758 if (can_do_fast_api_call) {
759 __ IncrementCounter(counters->call_const_interceptor_fast_api(), 1,
760 scratch1, scratch2);
761 ReserveSpaceForFastApiCall(masm, scratch1);
762 }
763
764 // Check that the maps from receiver to interceptor's holder
765 // haven't changed and thus we can invoke interceptor.
766 Label miss_cleanup;
767 Label* miss = can_do_fast_api_call ? &miss_cleanup : miss_label;
768 Register holder =
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000769 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
770 scratch1, scratch2, scratch3,
771 name, depth1, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000772
773 // Invoke an interceptor and if it provides a value,
774 // branch to |regular_invoke|.
775 Label regular_invoke;
776 LoadWithInterceptor(masm, receiver, holder, interceptor_holder, scratch2,
777 &regular_invoke);
778
779 // Interceptor returned nothing for this property. Try to use cached
780 // constant function.
781
782 // Check that the maps from interceptor's holder to constant function's
783 // holder haven't changed and thus we can use cached constant function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000784 if (*interceptor_holder != lookup->holder()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000785 stub_compiler_->CheckPrototypes(interceptor_holder, receiver,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000786 Handle<JSObject>(lookup->holder()),
787 scratch1, scratch2, scratch3,
788 name, depth2, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000789 } else {
790 // CheckPrototypes has a side effect of fetching a 'holder'
791 // for API (object which is instanceof for the signature). It's
792 // safe to omit it here, as if present, it should be fetched
793 // by the previous CheckPrototypes.
794 ASSERT(depth2 == kInvalidProtoDepth);
795 }
796
797 // Invoke function.
798 if (can_do_fast_api_call) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000799 GenerateFastApiDirectCall(masm, optimization, arguments_.immediate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000800 } else {
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000801 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state_)
802 ? CALL_AS_FUNCTION
803 : CALL_AS_METHOD;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000804 __ InvokeFunction(optimization.constant_function(), arguments_,
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +0000805 JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000806 }
807
808 // Deferred code for fast API call case---clean preallocated space.
809 if (can_do_fast_api_call) {
810 __ bind(&miss_cleanup);
811 FreeSpaceForFastApiCall(masm);
812 __ Branch(miss_label);
813 }
814
815 // Invoke a regular function.
816 __ bind(&regular_invoke);
817 if (can_do_fast_api_call) {
818 FreeSpaceForFastApiCall(masm);
819 }
lrn@chromium.org7516f052011-03-30 08:52:27 +0000820 }
821
822 void CompileRegular(MacroAssembler* masm,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000823 Handle<JSObject> object,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000824 Register receiver,
825 Register scratch1,
826 Register scratch2,
827 Register scratch3,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000828 Handle<String> name,
829 Handle<JSObject> interceptor_holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000830 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000831 Register holder =
832 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000833 scratch1, scratch2, scratch3,
834 name, miss_label);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000835
836 // Call a runtime function to load the interceptor property.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000837 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000838 // Save the name_ register across the call.
839 __ push(name_);
840
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000841 PushInterceptorArguments(masm, receiver, holder, name_, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000842
843 __ CallExternalReference(
844 ExternalReference(
845 IC_Utility(IC::kLoadPropertyWithInterceptorForCall),
846 masm->isolate()),
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000847 6);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000848 // Restore the name_ register.
849 __ pop(name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000850 // Leave the internal frame.
lrn@chromium.org7516f052011-03-30 08:52:27 +0000851 }
852
853 void LoadWithInterceptor(MacroAssembler* masm,
854 Register receiver,
855 Register holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000856 Handle<JSObject> holder_obj,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000857 Register scratch,
858 Label* interceptor_succeeded) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000859 {
860 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000861
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000862 __ Push(holder, name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000863 CompileCallLoadPropertyWithInterceptor(masm,
864 receiver,
865 holder,
866 name_,
867 holder_obj);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000868 __ pop(name_); // Restore the name.
869 __ pop(receiver); // Restore the holder.
870 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000871 // If interceptor returns no-result sentinel, call the constant function.
872 __ LoadRoot(scratch, Heap::kNoInterceptorResultSentinelRootIndex);
873 __ Branch(interceptor_succeeded, ne, v0, Operand(scratch));
lrn@chromium.org7516f052011-03-30 08:52:27 +0000874 }
875
876 StubCompiler* stub_compiler_;
877 const ParameterCount& arguments_;
878 Register name_;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000879 Code::ExtraICState extra_ic_state_;
lrn@chromium.org7516f052011-03-30 08:52:27 +0000880};
881
882
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000883
884// Generate code to check that a global property cell is empty. Create
885// the property cell at compilation time if no cell exists for the
886// property.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000887static void GenerateCheckPropertyCell(MacroAssembler* masm,
888 Handle<GlobalObject> global,
889 Handle<String> name,
890 Register scratch,
891 Label* miss) {
892 Handle<JSGlobalPropertyCell> cell =
893 GlobalObject::EnsurePropertyCell(global, name);
894 ASSERT(cell->value()->IsTheHole());
895 __ li(scratch, Operand(cell));
896 __ lw(scratch,
897 FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset));
898 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
899 __ Branch(miss, ne, scratch, Operand(at));
900}
901
902
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000903// Calls GenerateCheckPropertyCell for each global object in the prototype chain
904// from object to (but not including) holder.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000905static void GenerateCheckPropertyCells(MacroAssembler* masm,
906 Handle<JSObject> object,
907 Handle<JSObject> holder,
908 Handle<String> name,
909 Register scratch,
910 Label* miss) {
911 Handle<JSObject> current = object;
912 while (!current.is_identical_to(holder)) {
913 if (current->IsGlobalObject()) {
914 GenerateCheckPropertyCell(masm,
915 Handle<GlobalObject>::cast(current),
916 name,
917 scratch,
918 miss);
919 }
920 current = Handle<JSObject>(JSObject::cast(current->GetPrototype()));
921 }
922}
923
924
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000925// Convert and store int passed in register ival to IEEE 754 single precision
926// floating point value at memory location (dst + 4 * wordoffset)
927// If FPU is available use it for conversion.
928static void StoreIntAsFloat(MacroAssembler* masm,
929 Register dst,
930 Register wordoffset,
931 Register ival,
932 Register fval,
933 Register scratch1,
934 Register scratch2) {
935 if (CpuFeatures::IsSupported(FPU)) {
936 CpuFeatures::Scope scope(FPU);
937 __ mtc1(ival, f0);
938 __ cvt_s_w(f0, f0);
939 __ sll(scratch1, wordoffset, 2);
940 __ addu(scratch1, dst, scratch1);
941 __ swc1(f0, MemOperand(scratch1, 0));
942 } else {
943 // FPU is not available, do manual conversions.
944
945 Label not_special, done;
946 // Move sign bit from source to destination. This works because the sign
947 // bit in the exponent word of the double has the same position and polarity
948 // as the 2's complement sign bit in a Smi.
949 ASSERT(kBinary32SignMask == 0x80000000u);
950
951 __ And(fval, ival, Operand(kBinary32SignMask));
952 // Negate value if it is negative.
953 __ subu(scratch1, zero_reg, ival);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +0000954 __ Movn(ival, scratch1, fval);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000955
956 // We have -1, 0 or 1, which we treat specially. Register ival contains
957 // absolute value: it is either equal to 1 (special case of -1 and 1),
958 // greater than 1 (not a special case) or less than 1 (special case of 0).
959 __ Branch(&not_special, gt, ival, Operand(1));
960
961 // For 1 or -1 we need to or in the 0 exponent (biased).
962 static const uint32_t exponent_word_for_1 =
963 kBinary32ExponentBias << kBinary32ExponentShift;
964
965 __ Xor(scratch1, ival, Operand(1));
966 __ li(scratch2, exponent_word_for_1);
967 __ or_(scratch2, fval, scratch2);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +0000968 __ Movz(fval, scratch2, scratch1); // Only if ival is equal to 1.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000969 __ Branch(&done);
970
971 __ bind(&not_special);
972 // Count leading zeros.
973 // Gets the wrong answer for 0, but we already checked for that case above.
974 Register zeros = scratch2;
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +0000975 __ Clz(zeros, ival);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000976
977 // Compute exponent and or it into the exponent register.
978 __ li(scratch1, (kBitsPerInt - 1) + kBinary32ExponentBias);
979 __ subu(scratch1, scratch1, zeros);
980
981 __ sll(scratch1, scratch1, kBinary32ExponentShift);
982 __ or_(fval, fval, scratch1);
983
984 // Shift up the source chopping the top bit off.
985 __ Addu(zeros, zeros, Operand(1));
986 // This wouldn't work for 1 and -1 as the shift would be 32 which means 0.
987 __ sllv(ival, ival, zeros);
988 // And the top (top 20 bits).
989 __ srl(scratch1, ival, kBitsPerInt - kBinary32MantissaBits);
990 __ or_(fval, fval, scratch1);
991
992 __ bind(&done);
993
994 __ sll(scratch1, wordoffset, 2);
995 __ addu(scratch1, dst, scratch1);
996 __ sw(fval, MemOperand(scratch1, 0));
997 }
998}
999
1000
1001// Convert unsigned integer with specified number of leading zeroes in binary
1002// representation to IEEE 754 double.
1003// Integer to convert is passed in register hiword.
1004// Resulting double is returned in registers hiword:loword.
1005// This functions does not work correctly for 0.
1006static void GenerateUInt2Double(MacroAssembler* masm,
1007 Register hiword,
1008 Register loword,
1009 Register scratch,
1010 int leading_zeroes) {
1011 const int meaningful_bits = kBitsPerInt - leading_zeroes - 1;
1012 const int biased_exponent = HeapNumber::kExponentBias + meaningful_bits;
1013
1014 const int mantissa_shift_for_hi_word =
1015 meaningful_bits - HeapNumber::kMantissaBitsInTopWord;
1016
1017 const int mantissa_shift_for_lo_word =
1018 kBitsPerInt - mantissa_shift_for_hi_word;
1019
1020 __ li(scratch, biased_exponent << HeapNumber::kExponentShift);
1021 if (mantissa_shift_for_hi_word > 0) {
1022 __ sll(loword, hiword, mantissa_shift_for_lo_word);
1023 __ srl(hiword, hiword, mantissa_shift_for_hi_word);
1024 __ or_(hiword, scratch, hiword);
1025 } else {
1026 __ mov(loword, zero_reg);
1027 __ sll(hiword, hiword, mantissa_shift_for_hi_word);
1028 __ or_(hiword, scratch, hiword);
1029 }
1030
1031 // If least significant bit of biased exponent was not 1 it was corrupted
1032 // by most significant bit of mantissa so we should fix that.
1033 if (!(biased_exponent & 1)) {
1034 __ li(scratch, 1 << HeapNumber::kExponentShift);
1035 __ nor(scratch, scratch, scratch);
1036 __ and_(hiword, hiword, scratch);
1037 }
1038}
1039
1040
ager@chromium.org5c838252010-02-19 08:53:10 +00001041#undef __
1042#define __ ACCESS_MASM(masm())
1043
1044
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001045Register StubCompiler::CheckPrototypes(Handle<JSObject> object,
1046 Register object_reg,
1047 Handle<JSObject> holder,
1048 Register holder_reg,
1049 Register scratch1,
1050 Register scratch2,
1051 Handle<String> name,
1052 int save_at_depth,
1053 Label* miss) {
1054 // Make sure there's no overlap between holder and object registers.
1055 ASSERT(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
1056 ASSERT(!scratch2.is(object_reg) && !scratch2.is(holder_reg)
1057 && !scratch2.is(scratch1));
1058
1059 // Keep track of the current object in register reg.
1060 Register reg = object_reg;
1061 int depth = 0;
1062
1063 if (save_at_depth == depth) {
1064 __ sw(reg, MemOperand(sp));
1065 }
1066
1067 // Check the maps in the prototype chain.
1068 // Traverse the prototype chain from the object and do map checks.
1069 Handle<JSObject> current = object;
1070 while (!current.is_identical_to(holder)) {
1071 ++depth;
1072
1073 // Only global objects and objects that do not require access
1074 // checks are allowed in stubs.
1075 ASSERT(current->IsJSGlobalProxy() || !current->IsAccessCheckNeeded());
1076
1077 Handle<JSObject> prototype(JSObject::cast(current->GetPrototype()));
1078 if (!current->HasFastProperties() &&
1079 !current->IsJSGlobalObject() &&
1080 !current->IsJSGlobalProxy()) {
1081 if (!name->IsSymbol()) {
1082 name = factory()->LookupSymbol(name);
1083 }
1084 ASSERT(current->property_dictionary()->FindEntry(*name) ==
1085 StringDictionary::kNotFound);
1086
1087 GenerateDictionaryNegativeLookup(masm(), miss, reg, name,
1088 scratch1, scratch2);
1089
1090 __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
1091 reg = holder_reg; // From now on the object will be in holder_reg.
1092 __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
1093 } else {
1094 Handle<Map> current_map(current->map());
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001095 __ CheckMap(reg, scratch1, current_map, miss, DONT_DO_SMI_CHECK,
1096 ALLOW_ELEMENT_TRANSITION_MAPS);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001097 // Check access rights to the global object. This has to happen after
1098 // the map check so that we know that the object is actually a global
1099 // object.
1100 if (current->IsJSGlobalProxy()) {
1101 __ CheckAccessGlobalProxy(reg, scratch2, miss);
1102 }
1103 reg = holder_reg; // From now on the object will be in holder_reg.
1104
1105 if (heap()->InNewSpace(*prototype)) {
1106 // The prototype is in new space; we cannot store a reference to it
1107 // in the code. Load it from the map.
1108 __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
1109 } else {
1110 // The prototype is in old space; load it directly.
1111 __ li(reg, Operand(prototype));
1112 }
1113 }
1114
1115 if (save_at_depth == depth) {
1116 __ sw(reg, MemOperand(sp));
1117 }
1118
1119 // Go to the next object in the prototype chain.
1120 current = prototype;
1121 }
1122
1123 // Log the check depth.
1124 LOG(masm()->isolate(), IntEvent("check-maps-depth", depth + 1));
1125
1126 // Check the holder map.
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001127 __ CheckMap(reg, scratch1, Handle<Map>(current->map()), miss,
1128 DONT_DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001129
1130 // Perform security check for access to the global object.
1131 ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded());
1132 if (holder->IsJSGlobalProxy()) {
1133 __ CheckAccessGlobalProxy(reg, scratch1, miss);
1134 }
1135
1136 // If we've skipped any global objects, it's not enough to verify that
1137 // their maps haven't changed. We also need to check that the property
1138 // cell for the property is still empty.
1139 GenerateCheckPropertyCells(masm(), object, holder, name, scratch1, miss);
1140
1141 // Return the register containing the holder.
1142 return reg;
1143}
1144
1145
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001146void StubCompiler::GenerateLoadField(Handle<JSObject> object,
1147 Handle<JSObject> holder,
ager@chromium.org5c838252010-02-19 08:53:10 +00001148 Register receiver,
1149 Register scratch1,
1150 Register scratch2,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001151 Register scratch3,
ager@chromium.org5c838252010-02-19 08:53:10 +00001152 int index,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001153 Handle<String> name,
ager@chromium.org5c838252010-02-19 08:53:10 +00001154 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001155 // Check that the receiver isn't a smi.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001156 __ JumpIfSmi(receiver, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001157
1158 // Check that the maps haven't changed.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001159 Register reg = CheckPrototypes(
1160 object, receiver, holder, scratch1, scratch2, scratch3, name, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001161 GenerateFastPropertyLoad(masm(), v0, reg, holder, index);
1162 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +00001163}
1164
1165
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001166void StubCompiler::GenerateLoadConstant(Handle<JSObject> object,
1167 Handle<JSObject> holder,
ager@chromium.org5c838252010-02-19 08:53:10 +00001168 Register receiver,
1169 Register scratch1,
1170 Register scratch2,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001171 Register scratch3,
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001172 Handle<JSFunction> value,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001173 Handle<String> name,
ager@chromium.org5c838252010-02-19 08:53:10 +00001174 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001175 // Check that the receiver isn't a smi.
1176 __ JumpIfSmi(receiver, miss, scratch1);
1177
1178 // Check that the maps haven't changed.
1179 Register reg =
1180 CheckPrototypes(object, receiver, holder,
1181 scratch1, scratch2, scratch3, name, miss);
1182
1183 // Return the constant value.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001184 __ LoadHeapObject(v0, value);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001185 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +00001186}
1187
1188
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001189void StubCompiler::GenerateLoadCallback(Handle<JSObject> object,
1190 Handle<JSObject> holder,
1191 Register receiver,
1192 Register name_reg,
1193 Register scratch1,
1194 Register scratch2,
1195 Register scratch3,
1196 Handle<AccessorInfo> callback,
1197 Handle<String> name,
1198 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001199 // Check that the receiver isn't a smi.
1200 __ JumpIfSmi(receiver, miss, scratch1);
1201
1202 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001203 Register reg = CheckPrototypes(object, receiver, holder, scratch1,
1204 scratch2, scratch3, name, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001205
1206 // Build AccessorInfo::args_ list on the stack and push property name below
1207 // the exit frame to make GC aware of them and store pointers to them.
1208 __ push(receiver);
1209 __ mov(scratch2, sp); // scratch2 = AccessorInfo::args_
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001210 if (heap()->InNewSpace(callback->data())) {
1211 __ li(scratch3, callback);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001212 __ lw(scratch3, FieldMemOperand(scratch3, AccessorInfo::kDataOffset));
1213 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001214 __ li(scratch3, Handle<Object>(callback->data()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001215 }
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001216 __ Subu(sp, sp, 4 * kPointerSize);
1217 __ sw(reg, MemOperand(sp, 3 * kPointerSize));
1218 __ sw(scratch3, MemOperand(sp, 2 * kPointerSize));
1219 __ li(scratch3, Operand(ExternalReference::isolate_address()));
1220 __ sw(scratch3, MemOperand(sp, 1 * kPointerSize));
1221 __ sw(name_reg, MemOperand(sp, 0 * kPointerSize));
1222
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001223 __ mov(a2, scratch2); // Saved in case scratch2 == a1.
1224 __ mov(a1, sp); // a1 (first argument - see note below) = Handle<String>
1225
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001226 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
1227 // struct from the function (which is currently the case). This means we pass
1228 // the arguments in a1-a2 instead of a0-a1. TryCallApiFunctionAndReturn
1229 // will handle setting up a0.
1230
1231 const int kApiStackSpace = 1;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001232 FrameScope frame_scope(masm(), StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001233 __ EnterExitFrame(false, kApiStackSpace);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001234
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001235 // Create AccessorInfo instance on the stack above the exit frame with
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001236 // scratch2 (internal::Object** args_) as the data.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001237 __ sw(a2, MemOperand(sp, kPointerSize));
1238 // a2 (second argument - see note above) = AccessorInfo&
1239 __ Addu(a2, sp, kPointerSize);
1240
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001241 const int kStackUnwindSpace = 5;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001242 Address getter_address = v8::ToCData<Address>(callback->getter());
1243 ApiFunction fun(getter_address);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001244 ExternalReference ref =
1245 ExternalReference(&fun,
1246 ExternalReference::DIRECT_GETTER_CALL,
1247 masm()->isolate());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001248 __ CallApiFunctionAndReturn(ref, kStackUnwindSpace);
ager@chromium.org5c838252010-02-19 08:53:10 +00001249}
1250
1251
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001252void StubCompiler::GenerateLoadInterceptor(Handle<JSObject> object,
1253 Handle<JSObject> interceptor_holder,
ager@chromium.org5c838252010-02-19 08:53:10 +00001254 LookupResult* lookup,
1255 Register receiver,
1256 Register name_reg,
1257 Register scratch1,
1258 Register scratch2,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001259 Register scratch3,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001260 Handle<String> name,
ager@chromium.org5c838252010-02-19 08:53:10 +00001261 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001262 ASSERT(interceptor_holder->HasNamedInterceptor());
1263 ASSERT(!interceptor_holder->GetNamedInterceptor()->getter()->IsUndefined());
1264
1265 // Check that the receiver isn't a smi.
1266 __ JumpIfSmi(receiver, miss);
1267
1268 // So far the most popular follow ups for interceptor loads are FIELD
1269 // and CALLBACKS, so inline only them, other cases may be added
1270 // later.
1271 bool compile_followup_inline = false;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001272 if (lookup->IsFound() && lookup->IsCacheable()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001273 if (lookup->type() == FIELD) {
1274 compile_followup_inline = true;
1275 } else if (lookup->type() == CALLBACKS &&
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001276 lookup->GetCallbackObject()->IsAccessorInfo()) {
1277 compile_followup_inline =
1278 AccessorInfo::cast(lookup->GetCallbackObject())->getter() != NULL;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001279 }
1280 }
1281
1282 if (compile_followup_inline) {
1283 // Compile the interceptor call, followed by inline code to load the
1284 // property from further up the prototype chain if the call fails.
1285 // Check that the maps haven't changed.
1286 Register holder_reg = CheckPrototypes(object, receiver, interceptor_holder,
1287 scratch1, scratch2, scratch3,
1288 name, miss);
1289 ASSERT(holder_reg.is(receiver) || holder_reg.is(scratch1));
1290
1291 // Save necessary data before invoking an interceptor.
1292 // Requires a frame to make GC aware of pushed pointers.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001293 {
1294 FrameScope frame_scope(masm(), StackFrame::INTERNAL);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001295 if (lookup->type() == CALLBACKS && !receiver.is(holder_reg)) {
1296 // CALLBACKS case needs a receiver to be passed into C++ callback.
1297 __ Push(receiver, holder_reg, name_reg);
1298 } else {
1299 __ Push(holder_reg, name_reg);
1300 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001301 // Invoke an interceptor. Note: map checks from receiver to
1302 // interceptor's holder has been compiled before (see a caller
1303 // of this method).
1304 CompileCallLoadPropertyWithInterceptor(masm(),
1305 receiver,
1306 holder_reg,
1307 name_reg,
1308 interceptor_holder);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001309 // Check if interceptor provided a value for property. If it's
1310 // the case, return immediately.
1311 Label interceptor_failed;
1312 __ LoadRoot(scratch1, Heap::kNoInterceptorResultSentinelRootIndex);
1313 __ Branch(&interceptor_failed, eq, v0, Operand(scratch1));
1314 frame_scope.GenerateLeaveFrame();
1315 __ Ret();
1316
1317 __ bind(&interceptor_failed);
1318 __ pop(name_reg);
1319 __ pop(holder_reg);
1320 if (lookup->type() == CALLBACKS && !receiver.is(holder_reg)) {
1321 __ pop(receiver);
1322 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001323 // Leave the internal frame.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001324 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001325 // Check that the maps from interceptor's holder to lookup's holder
1326 // haven't changed. And load lookup's holder into |holder| register.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001327 if (*interceptor_holder != lookup->holder()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001328 holder_reg = CheckPrototypes(interceptor_holder,
1329 holder_reg,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001330 Handle<JSObject>(lookup->holder()),
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001331 scratch1,
1332 scratch2,
1333 scratch3,
1334 name,
1335 miss);
1336 }
1337
1338 if (lookup->type() == FIELD) {
1339 // We found FIELD property in prototype chain of interceptor's holder.
1340 // Retrieve a field from field's holder.
1341 GenerateFastPropertyLoad(masm(), v0, holder_reg,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001342 Handle<JSObject>(lookup->holder()),
1343 lookup->GetFieldIndex());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001344 __ Ret();
1345 } else {
1346 // We found CALLBACKS property in prototype chain of interceptor's
1347 // holder.
1348 ASSERT(lookup->type() == CALLBACKS);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001349 Handle<AccessorInfo> callback(
1350 AccessorInfo::cast(lookup->GetCallbackObject()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001351 ASSERT(callback->getter() != NULL);
1352
1353 // Tail call to runtime.
1354 // Important invariant in CALLBACKS case: the code above must be
1355 // structured to never clobber |receiver| register.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001356 __ li(scratch2, callback);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001357
1358 __ Push(receiver, holder_reg);
1359 __ lw(scratch3,
1360 FieldMemOperand(scratch2, AccessorInfo::kDataOffset));
1361 __ li(scratch1, Operand(ExternalReference::isolate_address()));
1362 __ Push(scratch3, scratch1, scratch2, name_reg);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001363
1364 ExternalReference ref =
1365 ExternalReference(IC_Utility(IC::kLoadCallbackProperty),
1366 masm()->isolate());
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001367 __ TailCallExternalReference(ref, 6, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001368 }
1369 } else { // !compile_followup_inline
1370 // Call the runtime system to load the interceptor.
1371 // Check that the maps haven't changed.
1372 Register holder_reg = CheckPrototypes(object, receiver, interceptor_holder,
1373 scratch1, scratch2, scratch3,
1374 name, miss);
1375 PushInterceptorArguments(masm(), receiver, holder_reg,
1376 name_reg, interceptor_holder);
1377
1378 ExternalReference ref = ExternalReference(
1379 IC_Utility(IC::kLoadPropertyWithInterceptorForLoad), masm()->isolate());
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001380 __ TailCallExternalReference(ref, 6, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001381 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001382}
1383
1384
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001385void CallStubCompiler::GenerateNameCheck(Handle<String> name, Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001386 if (kind_ == Code::KEYED_CALL_IC) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001387 __ Branch(miss, ne, a2, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001388 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001389}
1390
1391
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001392void CallStubCompiler::GenerateGlobalReceiverCheck(Handle<JSObject> object,
1393 Handle<JSObject> holder,
1394 Handle<String> name,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001395 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001396 ASSERT(holder->IsGlobalObject());
1397
1398 // Get the number of arguments.
1399 const int argc = arguments().immediate();
1400
1401 // Get the receiver from the stack.
1402 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1403
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001404 // Check that the maps haven't changed.
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00001405 __ JumpIfSmi(a0, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001406 CheckPrototypes(object, a0, holder, a3, a1, t0, name, miss);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001407}
1408
1409
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001410void CallStubCompiler::GenerateLoadFunctionFromCell(
1411 Handle<JSGlobalPropertyCell> cell,
1412 Handle<JSFunction> function,
1413 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001414 // Get the value from the cell.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001415 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001416 __ lw(a1, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
1417
1418 // Check that the cell contains the same function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001419 if (heap()->InNewSpace(*function)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001420 // We can't embed a pointer to a function in new space so we have
1421 // to verify that the shared function info is unchanged. This has
1422 // the nice side effect that multiple closures based on the same
1423 // function can all use this call IC. Before we load through the
1424 // function, we have to verify that it still is a function.
1425 __ JumpIfSmi(a1, miss);
1426 __ GetObjectType(a1, a3, a3);
1427 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
1428
1429 // Check the shared function info. Make sure it hasn't changed.
1430 __ li(a3, Handle<SharedFunctionInfo>(function->shared()));
1431 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
1432 __ Branch(miss, ne, t0, Operand(a3));
1433 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001434 __ Branch(miss, ne, a1, Operand(function));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001435 }
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001436}
1437
1438
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001439void CallStubCompiler::GenerateMissBranch() {
1440 Handle<Code> code =
danno@chromium.org40cb8782011-05-25 07:58:50 +00001441 isolate()->stub_cache()->ComputeCallMiss(arguments().immediate(),
1442 kind_,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001443 extra_state_);
1444 __ Jump(code, RelocInfo::CODE_TARGET);
1445}
1446
1447
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001448Handle<Code> CallStubCompiler::CompileCallField(Handle<JSObject> object,
1449 Handle<JSObject> holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001450 int index,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001451 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001452 // ----------- S t a t e -------------
1453 // -- a2 : name
1454 // -- ra : return address
1455 // -----------------------------------
1456 Label miss;
1457
1458 GenerateNameCheck(name, &miss);
1459
1460 const int argc = arguments().immediate();
1461
1462 // Get the receiver of the function from the stack into a0.
1463 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1464 // Check that the receiver isn't a smi.
1465 __ JumpIfSmi(a0, &miss, t0);
1466
1467 // Do the right check and compute the holder register.
1468 Register reg = CheckPrototypes(object, a0, holder, a1, a3, t0, name, &miss);
1469 GenerateFastPropertyLoad(masm(), a1, reg, holder, index);
1470
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001471 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001472
1473 // Handle call cache miss.
1474 __ bind(&miss);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001475 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001476
1477 // Return the generated code.
1478 return GetCode(FIELD, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00001479}
1480
1481
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001482Handle<Code> CallStubCompiler::CompileArrayPushCall(
1483 Handle<Object> object,
1484 Handle<JSObject> holder,
1485 Handle<JSGlobalPropertyCell> cell,
1486 Handle<JSFunction> function,
1487 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001488 // ----------- S t a t e -------------
1489 // -- a2 : name
1490 // -- ra : return address
1491 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1492 // -- ...
1493 // -- sp[argc * 4] : receiver
1494 // -----------------------------------
1495
1496 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001497 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001498
1499 Label miss;
1500
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001501 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001502
1503 Register receiver = a1;
1504
1505 // Get the receiver from the stack.
1506 const int argc = arguments().immediate();
1507 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1508
1509 // Check that the receiver isn't a smi.
1510 __ JumpIfSmi(receiver, &miss);
1511
1512 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001513 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, a3, v0, t0,
1514 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001515
1516 if (argc == 0) {
1517 // Nothing to do, just return the length.
1518 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1519 __ Drop(argc + 1);
1520 __ Ret();
1521 } else {
1522 Label call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001523 if (argc == 1) { // Otherwise fall through to call the builtin.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001524 Label attempt_to_grow_elements;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001525
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001526 Register elements = t2;
1527 Register end_elements = t1;
1528 // Get the elements array of the object.
1529 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1530
1531 // Check that the elements are in fast mode and writable.
1532 __ CheckMap(elements,
1533 v0,
1534 Heap::kFixedArrayMapRootIndex,
1535 &call_builtin,
1536 DONT_DO_SMI_CHECK);
1537
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001538 // Get the array's length into v0 and calculate new length.
1539 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1540 STATIC_ASSERT(kSmiTagSize == 1);
1541 STATIC_ASSERT(kSmiTag == 0);
1542 __ Addu(v0, v0, Operand(Smi::FromInt(argc)));
1543
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001544 // Get the elements' length.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001545 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1546
1547 // Check if we could survive without allocation.
1548 __ Branch(&attempt_to_grow_elements, gt, v0, Operand(t0));
1549
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001550 // Check if value is a smi.
1551 Label with_write_barrier;
1552 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize));
1553 __ JumpIfNotSmi(t0, &with_write_barrier);
1554
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001555 // Save new length.
1556 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1557
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001558 // Store the value.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001559 // We may need a register containing the address end_elements below,
1560 // so write back the value in end_elements.
1561 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1562 __ Addu(end_elements, elements, end_elements);
1563 const int kEndElementsOffset =
1564 FixedArray::kHeaderSize - kHeapObjectTag - argc * kPointerSize;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001565 __ Addu(end_elements, end_elements, kEndElementsOffset);
1566 __ sw(t0, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001567
1568 // Check for a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001569 __ Drop(argc + 1);
1570 __ Ret();
1571
1572 __ bind(&with_write_barrier);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001573
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001574 __ lw(a3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1575
1576 if (FLAG_smi_only_arrays && !FLAG_trace_elements_transitions) {
1577 Label fast_object, not_fast_object;
1578 __ CheckFastObjectElements(a3, t3, &not_fast_object);
1579 __ jmp(&fast_object);
1580 // In case of fast smi-only, convert to fast object, otherwise bail out.
1581 __ bind(&not_fast_object);
1582 __ CheckFastSmiOnlyElements(a3, t3, &call_builtin);
1583 // edx: receiver
1584 // r3: map
1585 __ LoadTransitionedArrayMapConditional(FAST_SMI_ONLY_ELEMENTS,
1586 FAST_ELEMENTS,
1587 a3,
1588 t3,
1589 &call_builtin);
1590 __ mov(a2, receiver);
1591 ElementsTransitionGenerator::GenerateSmiOnlyToObject(masm());
1592 __ bind(&fast_object);
1593 } else {
1594 __ CheckFastObjectElements(a3, a3, &call_builtin);
1595 }
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001596
1597 // Save new length.
1598 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1599
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001600 // Store the value.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001601 // We may need a register containing the address end_elements below,
1602 // so write back the value in end_elements.
1603 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1604 __ Addu(end_elements, elements, end_elements);
1605 __ Addu(end_elements, end_elements, kEndElementsOffset);
1606 __ sw(t0, MemOperand(end_elements));
1607
1608 __ RecordWrite(elements,
1609 end_elements,
1610 t0,
1611 kRAHasNotBeenSaved,
1612 kDontSaveFPRegs,
1613 EMIT_REMEMBERED_SET,
1614 OMIT_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001615 __ Drop(argc + 1);
1616 __ Ret();
1617
1618 __ bind(&attempt_to_grow_elements);
1619 // v0: array's length + 1.
1620 // t0: elements' length.
1621
1622 if (!FLAG_inline_new) {
1623 __ Branch(&call_builtin);
1624 }
1625
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001626 __ lw(a2, MemOperand(sp, (argc - 1) * kPointerSize));
1627 // Growing elements that are SMI-only requires special handling in case
1628 // the new element is non-Smi. For now, delegate to the builtin.
1629 Label no_fast_elements_check;
1630 __ JumpIfSmi(a2, &no_fast_elements_check);
1631 __ lw(t3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1632 __ CheckFastObjectElements(t3, t3, &call_builtin);
1633 __ bind(&no_fast_elements_check);
1634
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001635 ExternalReference new_space_allocation_top =
1636 ExternalReference::new_space_allocation_top_address(
1637 masm()->isolate());
1638 ExternalReference new_space_allocation_limit =
1639 ExternalReference::new_space_allocation_limit_address(
1640 masm()->isolate());
1641
1642 const int kAllocationDelta = 4;
1643 // Load top and check if it is the end of elements.
1644 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1645 __ Addu(end_elements, elements, end_elements);
1646 __ Addu(end_elements, end_elements, Operand(kEndElementsOffset));
1647 __ li(t3, Operand(new_space_allocation_top));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001648 __ lw(a3, MemOperand(t3));
1649 __ Branch(&call_builtin, ne, end_elements, Operand(a3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001650
1651 __ li(t5, Operand(new_space_allocation_limit));
1652 __ lw(t5, MemOperand(t5));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001653 __ Addu(a3, a3, Operand(kAllocationDelta * kPointerSize));
1654 __ Branch(&call_builtin, hi, a3, Operand(t5));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001655
1656 // We fit and could grow elements.
1657 // Update new_space_allocation_top.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001658 __ sw(a3, MemOperand(t3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001659 // Push the argument.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001660 __ sw(a2, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001661 // Fill the rest with holes.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001662 __ LoadRoot(a3, Heap::kTheHoleValueRootIndex);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001663 for (int i = 1; i < kAllocationDelta; i++) {
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001664 __ sw(a3, MemOperand(end_elements, i * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001665 }
1666
1667 // Update elements' and array's sizes.
1668 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1669 __ Addu(t0, t0, Operand(Smi::FromInt(kAllocationDelta)));
1670 __ sw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1671
1672 // Elements are in new space, so write barrier is not required.
1673 __ Drop(argc + 1);
1674 __ Ret();
1675 }
1676 __ bind(&call_builtin);
1677 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPush,
1678 masm()->isolate()),
1679 argc + 1,
1680 1);
1681 }
1682
1683 // Handle call cache miss.
1684 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001685 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001686
1687 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001688 return GetCode(function);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001689}
1690
1691
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001692Handle<Code> CallStubCompiler::CompileArrayPopCall(
1693 Handle<Object> object,
1694 Handle<JSObject> holder,
1695 Handle<JSGlobalPropertyCell> cell,
1696 Handle<JSFunction> function,
1697 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001698 // ----------- S t a t e -------------
1699 // -- a2 : name
1700 // -- ra : return address
1701 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1702 // -- ...
1703 // -- sp[argc * 4] : receiver
1704 // -----------------------------------
1705
1706 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001707 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001708
1709 Label miss, return_undefined, call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001710 Register receiver = a1;
1711 Register elements = a3;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001712 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001713
1714 // Get the receiver from the stack.
1715 const int argc = arguments().immediate();
1716 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001717 // Check that the receiver isn't a smi.
1718 __ JumpIfSmi(receiver, &miss);
1719
1720 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001721 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, elements,
1722 t0, v0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001723
1724 // Get the elements array of the object.
1725 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1726
1727 // Check that the elements are in fast mode and writable.
danno@chromium.org40cb8782011-05-25 07:58:50 +00001728 __ CheckMap(elements,
1729 v0,
1730 Heap::kFixedArrayMapRootIndex,
1731 &call_builtin,
1732 DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001733
1734 // Get the array's length into t0 and calculate new length.
1735 __ lw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1736 __ Subu(t0, t0, Operand(Smi::FromInt(1)));
1737 __ Branch(&return_undefined, lt, t0, Operand(zero_reg));
1738
1739 // Get the last element.
1740 __ LoadRoot(t2, Heap::kTheHoleValueRootIndex);
1741 STATIC_ASSERT(kSmiTagSize == 1);
1742 STATIC_ASSERT(kSmiTag == 0);
1743 // We can't address the last element in one operation. Compute the more
1744 // expensive shift first, and use an offset later on.
1745 __ sll(t1, t0, kPointerSizeLog2 - kSmiTagSize);
1746 __ Addu(elements, elements, t1);
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00001747 __ lw(v0, FieldMemOperand(elements, FixedArray::kHeaderSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001748 __ Branch(&call_builtin, eq, v0, Operand(t2));
1749
1750 // Set the array's length.
1751 __ sw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1752
1753 // Fill with the hole.
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00001754 __ sw(t2, FieldMemOperand(elements, FixedArray::kHeaderSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001755 __ Drop(argc + 1);
1756 __ Ret();
1757
1758 __ bind(&return_undefined);
1759 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
1760 __ Drop(argc + 1);
1761 __ Ret();
1762
1763 __ bind(&call_builtin);
1764 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPop,
1765 masm()->isolate()),
1766 argc + 1,
1767 1);
1768
1769 // Handle call cache miss.
1770 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001771 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001772
1773 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001774 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00001775}
1776
1777
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001778Handle<Code> CallStubCompiler::CompileStringCharCodeAtCall(
1779 Handle<Object> object,
1780 Handle<JSObject> holder,
1781 Handle<JSGlobalPropertyCell> cell,
1782 Handle<JSFunction> function,
1783 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001784 // ----------- S t a t e -------------
1785 // -- a2 : function name
1786 // -- ra : return address
1787 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1788 // -- ...
1789 // -- sp[argc * 4] : receiver
1790 // -----------------------------------
1791
1792 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001793 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001794
1795 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001796 Label miss;
1797 Label name_miss;
1798 Label index_out_of_range;
1799
1800 Label* index_out_of_range_label = &index_out_of_range;
1801
danno@chromium.org40cb8782011-05-25 07:58:50 +00001802 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001803 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00001804 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001805 index_out_of_range_label = &miss;
1806 }
1807
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001808 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001809
1810 // Check that the maps starting from the prototype haven't changed.
1811 GenerateDirectLoadGlobalFunctionPrototype(masm(),
1812 Context::STRING_FUNCTION_INDEX,
1813 v0,
1814 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001815 ASSERT(!object.is_identical_to(holder));
1816 CheckPrototypes(Handle<JSObject>(JSObject::cast(object->GetPrototype())),
1817 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001818
1819 Register receiver = a1;
1820 Register index = t1;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001821 Register result = v0;
1822 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1823 if (argc > 0) {
1824 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
1825 } else {
1826 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
1827 }
1828
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001829 StringCharCodeAtGenerator generator(receiver,
1830 index,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001831 result,
1832 &miss, // When not a string.
1833 &miss, // When not a number.
1834 index_out_of_range_label,
1835 STRING_INDEX_IS_NUMBER);
1836 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001837 __ Drop(argc + 1);
1838 __ Ret();
1839
1840 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001841 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001842
1843 if (index_out_of_range.is_linked()) {
1844 __ bind(&index_out_of_range);
1845 __ LoadRoot(v0, Heap::kNanValueRootIndex);
1846 __ Drop(argc + 1);
1847 __ Ret();
1848 }
1849
1850 __ bind(&miss);
1851 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001852 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001853 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001854 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001855
1856 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001857 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00001858}
1859
1860
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001861Handle<Code> CallStubCompiler::CompileStringCharAtCall(
1862 Handle<Object> object,
1863 Handle<JSObject> holder,
1864 Handle<JSGlobalPropertyCell> cell,
1865 Handle<JSFunction> function,
1866 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001867 // ----------- S t a t e -------------
1868 // -- a2 : function name
1869 // -- ra : return address
1870 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1871 // -- ...
1872 // -- sp[argc * 4] : receiver
1873 // -----------------------------------
1874
1875 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001876 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001877
1878 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001879 Label miss;
1880 Label name_miss;
1881 Label index_out_of_range;
1882 Label* index_out_of_range_label = &index_out_of_range;
danno@chromium.org40cb8782011-05-25 07:58:50 +00001883 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001884 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00001885 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001886 index_out_of_range_label = &miss;
1887 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001888 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001889
1890 // Check that the maps starting from the prototype haven't changed.
1891 GenerateDirectLoadGlobalFunctionPrototype(masm(),
1892 Context::STRING_FUNCTION_INDEX,
1893 v0,
1894 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001895 ASSERT(!object.is_identical_to(holder));
1896 CheckPrototypes(Handle<JSObject>(JSObject::cast(object->GetPrototype())),
1897 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001898
1899 Register receiver = v0;
1900 Register index = t1;
danno@chromium.orgc612e022011-11-10 11:38:15 +00001901 Register scratch = a3;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001902 Register result = v0;
1903 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1904 if (argc > 0) {
1905 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
1906 } else {
1907 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
1908 }
1909
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001910 StringCharAtGenerator generator(receiver,
1911 index,
danno@chromium.orgc612e022011-11-10 11:38:15 +00001912 scratch,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001913 result,
1914 &miss, // When not a string.
1915 &miss, // When not a number.
1916 index_out_of_range_label,
1917 STRING_INDEX_IS_NUMBER);
1918 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001919 __ Drop(argc + 1);
1920 __ Ret();
1921
1922 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001923 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001924
1925 if (index_out_of_range.is_linked()) {
1926 __ bind(&index_out_of_range);
1927 __ LoadRoot(v0, Heap::kEmptyStringRootIndex);
1928 __ Drop(argc + 1);
1929 __ Ret();
1930 }
1931
1932 __ bind(&miss);
1933 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001934 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001935 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001936 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001937
1938 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001939 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00001940}
1941
1942
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001943Handle<Code> CallStubCompiler::CompileStringFromCharCodeCall(
1944 Handle<Object> object,
1945 Handle<JSObject> holder,
1946 Handle<JSGlobalPropertyCell> cell,
1947 Handle<JSFunction> function,
1948 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001949 // ----------- S t a t e -------------
1950 // -- a2 : function name
1951 // -- ra : return address
1952 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1953 // -- ...
1954 // -- sp[argc * 4] : receiver
1955 // -----------------------------------
1956
1957 const int argc = arguments().immediate();
1958
1959 // If the object is not a JSObject or we got an unexpected number of
1960 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001961 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001962
1963 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001964 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001965
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001966 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001967 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
1968
1969 STATIC_ASSERT(kSmiTag == 0);
1970 __ JumpIfSmi(a1, &miss);
1971
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001972 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
1973 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001974 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001975 ASSERT(cell->value() == *function);
1976 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
1977 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001978 GenerateLoadFunctionFromCell(cell, function, &miss);
1979 }
1980
1981 // Load the char code argument.
1982 Register code = a1;
1983 __ lw(code, MemOperand(sp, 0 * kPointerSize));
1984
1985 // Check the code is a smi.
1986 Label slow;
1987 STATIC_ASSERT(kSmiTag == 0);
1988 __ JumpIfNotSmi(code, &slow);
1989
1990 // Convert the smi code to uint16.
1991 __ And(code, code, Operand(Smi::FromInt(0xffff)));
1992
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001993 StringCharFromCodeGenerator generator(code, v0);
1994 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001995 __ Drop(argc + 1);
1996 __ Ret();
1997
1998 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001999 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002000
2001 // Tail call the full function. We do not have to patch the receiver
2002 // because the function makes no use of it.
2003 __ bind(&slow);
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002004 __ InvokeFunction(
2005 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002006
2007 __ bind(&miss);
2008 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002009 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002010
2011 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002012 return cell.is_null() ? GetCode(function) : GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002013}
2014
2015
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002016Handle<Code> CallStubCompiler::CompileMathFloorCall(
2017 Handle<Object> object,
2018 Handle<JSObject> holder,
2019 Handle<JSGlobalPropertyCell> cell,
2020 Handle<JSFunction> function,
2021 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002022 // ----------- S t a t e -------------
2023 // -- a2 : function name
2024 // -- ra : return address
2025 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2026 // -- ...
2027 // -- sp[argc * 4] : receiver
2028 // -----------------------------------
2029
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002030 if (!CpuFeatures::IsSupported(FPU)) {
2031 return Handle<Code>::null();
2032 }
2033
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002034 CpuFeatures::Scope scope_fpu(FPU);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002035 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002036 // If the object is not a JSObject or we got an unexpected number of
2037 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002038 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002039
2040 Label miss, slow;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002041 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002042
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002043 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002044 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002045 STATIC_ASSERT(kSmiTag == 0);
2046 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002047 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2048 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002049 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002050 ASSERT(cell->value() == *function);
2051 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2052 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002053 GenerateLoadFunctionFromCell(cell, function, &miss);
2054 }
2055
2056 // Load the (only) argument into v0.
2057 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2058
2059 // If the argument is a smi, just return.
2060 STATIC_ASSERT(kSmiTag == 0);
2061 __ And(t0, v0, Operand(kSmiTagMask));
2062 __ Drop(argc + 1, eq, t0, Operand(zero_reg));
2063 __ Ret(eq, t0, Operand(zero_reg));
2064
danno@chromium.org40cb8782011-05-25 07:58:50 +00002065 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002066
2067 Label wont_fit_smi, no_fpu_error, restore_fcsr_and_return;
2068
2069 // If fpu is enabled, we use the floor instruction.
2070
2071 // Load the HeapNumber value.
2072 __ ldc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
2073
2074 // Backup FCSR.
2075 __ cfc1(a3, FCSR);
2076 // Clearing FCSR clears the exception mask with no side-effects.
2077 __ ctc1(zero_reg, FCSR);
2078 // Convert the argument to an integer.
2079 __ floor_w_d(f0, f0);
2080
2081 // Start checking for special cases.
2082 // Get the argument exponent and clear the sign bit.
2083 __ lw(t1, FieldMemOperand(v0, HeapNumber::kValueOffset + kPointerSize));
2084 __ And(t2, t1, Operand(~HeapNumber::kSignMask));
2085 __ srl(t2, t2, HeapNumber::kMantissaBitsInTopWord);
2086
2087 // Retrieve FCSR and check for fpu errors.
2088 __ cfc1(t5, FCSR);
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002089 __ And(t5, t5, Operand(kFCSRExceptionFlagMask));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002090 __ Branch(&no_fpu_error, eq, t5, Operand(zero_reg));
2091
2092 // Check for NaN, Infinity, and -Infinity.
2093 // They are invariant through a Math.Floor call, so just
2094 // return the original argument.
2095 __ Subu(t3, t2, Operand(HeapNumber::kExponentMask
2096 >> HeapNumber::kMantissaBitsInTopWord));
2097 __ Branch(&restore_fcsr_and_return, eq, t3, Operand(zero_reg));
2098 // We had an overflow or underflow in the conversion. Check if we
2099 // have a big exponent.
2100 // If greater or equal, the argument is already round and in v0.
2101 __ Branch(&restore_fcsr_and_return, ge, t3,
2102 Operand(HeapNumber::kMantissaBits));
2103 __ Branch(&wont_fit_smi);
2104
2105 __ bind(&no_fpu_error);
2106 // Move the result back to v0.
2107 __ mfc1(v0, f0);
2108 // Check if the result fits into a smi.
2109 __ Addu(a1, v0, Operand(0x40000000));
2110 __ Branch(&wont_fit_smi, lt, a1, Operand(zero_reg));
2111 // Tag the result.
2112 STATIC_ASSERT(kSmiTag == 0);
2113 __ sll(v0, v0, kSmiTagSize);
2114
2115 // Check for -0.
2116 __ Branch(&restore_fcsr_and_return, ne, v0, Operand(zero_reg));
2117 // t1 already holds the HeapNumber exponent.
2118 __ And(t0, t1, Operand(HeapNumber::kSignMask));
2119 // If our HeapNumber is negative it was -0, so load its address and return.
2120 // Else v0 is loaded with 0, so we can also just return.
2121 __ Branch(&restore_fcsr_and_return, eq, t0, Operand(zero_reg));
2122 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2123
2124 __ bind(&restore_fcsr_and_return);
2125 // Restore FCSR and return.
2126 __ ctc1(a3, FCSR);
2127
2128 __ Drop(argc + 1);
2129 __ Ret();
2130
2131 __ bind(&wont_fit_smi);
2132 // Restore FCSR and fall to slow case.
2133 __ ctc1(a3, FCSR);
2134
2135 __ bind(&slow);
2136 // Tail call the full function. We do not have to patch the receiver
2137 // because the function makes no use of it.
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002138 __ InvokeFunction(
2139 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002140
2141 __ bind(&miss);
2142 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002143 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002144
2145 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002146 return cell.is_null() ? GetCode(function) : GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002147}
2148
2149
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002150Handle<Code> CallStubCompiler::CompileMathAbsCall(
2151 Handle<Object> object,
2152 Handle<JSObject> holder,
2153 Handle<JSGlobalPropertyCell> cell,
2154 Handle<JSFunction> function,
2155 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002156 // ----------- S t a t e -------------
2157 // -- a2 : function name
2158 // -- ra : return address
2159 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2160 // -- ...
2161 // -- sp[argc * 4] : receiver
2162 // -----------------------------------
2163
2164 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002165 // If the object is not a JSObject or we got an unexpected number of
2166 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002167 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002168
2169 Label miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002170
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002171 GenerateNameCheck(name, &miss);
2172 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002173 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002174 STATIC_ASSERT(kSmiTag == 0);
2175 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002176 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
2177 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002178 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002179 ASSERT(cell->value() == *function);
2180 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2181 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002182 GenerateLoadFunctionFromCell(cell, function, &miss);
2183 }
2184
2185 // Load the (only) argument into v0.
2186 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2187
2188 // Check if the argument is a smi.
2189 Label not_smi;
2190 STATIC_ASSERT(kSmiTag == 0);
2191 __ JumpIfNotSmi(v0, &not_smi);
2192
2193 // Do bitwise not or do nothing depending on the sign of the
2194 // argument.
2195 __ sra(t0, v0, kBitsPerInt - 1);
2196 __ Xor(a1, v0, t0);
2197
2198 // Add 1 or do nothing depending on the sign of the argument.
2199 __ Subu(v0, a1, t0);
2200
2201 // If the result is still negative, go to the slow case.
2202 // This only happens for the most negative smi.
2203 Label slow;
2204 __ Branch(&slow, lt, v0, Operand(zero_reg));
2205
2206 // Smi case done.
2207 __ Drop(argc + 1);
2208 __ Ret();
2209
2210 // Check if the argument is a heap number and load its exponent and
2211 // sign.
2212 __ bind(&not_smi);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002213 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002214 __ lw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2215
2216 // Check the sign of the argument. If the argument is positive,
2217 // just return it.
2218 Label negative_sign;
2219 __ And(t0, a1, Operand(HeapNumber::kSignMask));
2220 __ Branch(&negative_sign, ne, t0, Operand(zero_reg));
2221 __ Drop(argc + 1);
2222 __ Ret();
2223
2224 // If the argument is negative, clear the sign, and return a new
2225 // number.
2226 __ bind(&negative_sign);
2227 __ Xor(a1, a1, Operand(HeapNumber::kSignMask));
2228 __ lw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2229 __ LoadRoot(t2, Heap::kHeapNumberMapRootIndex);
2230 __ AllocateHeapNumber(v0, t0, t1, t2, &slow);
2231 __ sw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2232 __ sw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2233 __ Drop(argc + 1);
2234 __ Ret();
2235
2236 // Tail call the full function. We do not have to patch the receiver
2237 // because the function makes no use of it.
2238 __ bind(&slow);
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002239 __ InvokeFunction(
2240 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002241
2242 __ bind(&miss);
2243 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002244 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002245
2246 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002247 return cell.is_null() ? GetCode(function) : GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002248}
2249
2250
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002251Handle<Code> CallStubCompiler::CompileFastApiCall(
lrn@chromium.org7516f052011-03-30 08:52:27 +00002252 const CallOptimization& optimization,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002253 Handle<Object> object,
2254 Handle<JSObject> holder,
2255 Handle<JSGlobalPropertyCell> cell,
2256 Handle<JSFunction> function,
2257 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002258
danno@chromium.org40cb8782011-05-25 07:58:50 +00002259 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002260
2261 ASSERT(optimization.is_simple_api_call());
2262 // Bail out if object is a global object as we don't want to
2263 // repatch it to global receiver.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002264 if (object->IsGlobalObject()) return Handle<Code>::null();
2265 if (!cell.is_null()) return Handle<Code>::null();
2266 if (!object->IsJSObject()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002267 int depth = optimization.GetPrototypeDepthOfExpectedType(
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002268 Handle<JSObject>::cast(object), holder);
2269 if (depth == kInvalidProtoDepth) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002270
2271 Label miss, miss_before_stack_reserved;
2272
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002273 GenerateNameCheck(name, &miss_before_stack_reserved);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002274
2275 // Get the receiver from the stack.
2276 const int argc = arguments().immediate();
2277 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2278
2279 // Check that the receiver isn't a smi.
2280 __ JumpIfSmi(a1, &miss_before_stack_reserved);
2281
2282 __ IncrementCounter(counters->call_const(), 1, a0, a3);
2283 __ IncrementCounter(counters->call_const_fast_api(), 1, a0, a3);
2284
2285 ReserveSpaceForFastApiCall(masm(), a0);
2286
2287 // Check that the maps haven't changed and find a Holder as a side effect.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002288 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0, name,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002289 depth, &miss);
2290
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002291 GenerateFastApiDirectCall(masm(), optimization, argc);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002292
2293 __ bind(&miss);
2294 FreeSpaceForFastApiCall(masm());
2295
2296 __ bind(&miss_before_stack_reserved);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002297 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002298
2299 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002300 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002301}
2302
2303
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002304Handle<Code> CallStubCompiler::CompileCallConstant(Handle<Object> object,
2305 Handle<JSObject> holder,
2306 Handle<JSFunction> function,
2307 Handle<String> name,
lrn@chromium.org7516f052011-03-30 08:52:27 +00002308 CheckType check) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002309 // ----------- S t a t e -------------
2310 // -- a2 : name
2311 // -- ra : return address
2312 // -----------------------------------
2313 if (HasCustomCallGenerator(function)) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002314 Handle<Code> code = CompileCustomCall(object, holder,
2315 Handle<JSGlobalPropertyCell>::null(),
2316 function, name);
2317 // A null handle means bail out to the regular compiler code below.
2318 if (!code.is_null()) return code;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002319 }
2320
2321 Label miss;
2322
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002323 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002324
2325 // Get the receiver from the stack.
2326 const int argc = arguments().immediate();
2327 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2328
2329 // Check that the receiver isn't a smi.
2330 if (check != NUMBER_CHECK) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002331 __ JumpIfSmi(a1, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002332 }
2333
2334 // Make sure that it's okay not to patch the on stack receiver
2335 // unless we're doing a receiver map check.
2336 ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002337 switch (check) {
2338 case RECEIVER_MAP_CHECK:
2339 __ IncrementCounter(masm()->isolate()->counters()->call_const(),
2340 1, a0, a3);
2341
2342 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002343 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2344 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002345
2346 // Patch the receiver on the stack with the global proxy if
2347 // necessary.
2348 if (object->IsGlobalObject()) {
2349 __ lw(a3, FieldMemOperand(a1, GlobalObject::kGlobalReceiverOffset));
2350 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2351 }
2352 break;
2353
2354 case STRING_CHECK:
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00002355 if (function->IsBuiltin() || !function->shared()->is_classic_mode()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002356 // Check that the object is a two-byte string or a symbol.
2357 __ GetObjectType(a1, a3, a3);
2358 __ Branch(&miss, Ugreater_equal, a3, Operand(FIRST_NONSTRING_TYPE));
2359 // Check that the maps starting from the prototype haven't changed.
2360 GenerateDirectLoadGlobalFunctionPrototype(
2361 masm(), Context::STRING_FUNCTION_INDEX, a0, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002362 CheckPrototypes(
2363 Handle<JSObject>(JSObject::cast(object->GetPrototype())),
2364 a0, holder, a3, a1, t0, name, &miss);
2365 } else {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002366 // Calling non-strict non-builtins with a value as the receiver
2367 // requires boxing.
2368 __ jmp(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002369 }
2370 break;
2371
2372 case NUMBER_CHECK:
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00002373 if (function->IsBuiltin() || !function->shared()->is_classic_mode()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002374 Label fast;
2375 // Check that the object is a smi or a heap number.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002376 __ JumpIfSmi(a1, &fast);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002377 __ GetObjectType(a1, a0, a0);
2378 __ Branch(&miss, ne, a0, Operand(HEAP_NUMBER_TYPE));
2379 __ bind(&fast);
2380 // Check that the maps starting from the prototype haven't changed.
2381 GenerateDirectLoadGlobalFunctionPrototype(
2382 masm(), Context::NUMBER_FUNCTION_INDEX, a0, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002383 CheckPrototypes(
2384 Handle<JSObject>(JSObject::cast(object->GetPrototype())),
2385 a0, holder, a3, a1, t0, name, &miss);
2386 } else {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002387 // Calling non-strict non-builtins with a value as the receiver
2388 // requires boxing.
2389 __ jmp(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002390 }
2391 break;
2392
2393 case BOOLEAN_CHECK:
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00002394 if (function->IsBuiltin() || !function->shared()->is_classic_mode()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002395 Label fast;
2396 // Check that the object is a boolean.
2397 __ LoadRoot(t0, Heap::kTrueValueRootIndex);
2398 __ Branch(&fast, eq, a1, Operand(t0));
2399 __ LoadRoot(t0, Heap::kFalseValueRootIndex);
2400 __ Branch(&miss, ne, a1, Operand(t0));
2401 __ bind(&fast);
2402 // Check that the maps starting from the prototype haven't changed.
2403 GenerateDirectLoadGlobalFunctionPrototype(
2404 masm(), Context::BOOLEAN_FUNCTION_INDEX, a0, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002405 CheckPrototypes(
2406 Handle<JSObject>(JSObject::cast(object->GetPrototype())),
2407 a0, holder, a3, a1, t0, name, &miss);
2408 } else {
2409 // Calling non-strict non-builtins with a value as the receiver
2410 // requires boxing.
2411 __ jmp(&miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002412 }
2413 break;
2414 }
2415
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002416 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002417 ? CALL_AS_FUNCTION
2418 : CALL_AS_METHOD;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002419 __ InvokeFunction(
2420 function, arguments(), JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002421
2422 // Handle call cache miss.
2423 __ bind(&miss);
2424
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002425 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002426
2427 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002428 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002429}
2430
2431
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002432Handle<Code> CallStubCompiler::CompileCallInterceptor(Handle<JSObject> object,
2433 Handle<JSObject> holder,
2434 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002435 // ----------- S t a t e -------------
2436 // -- a2 : name
2437 // -- ra : return address
2438 // -----------------------------------
2439
2440 Label miss;
2441
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002442 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002443
2444 // Get the number of arguments.
2445 const int argc = arguments().immediate();
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002446 LookupResult lookup(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002447 LookupPostInterceptor(holder, name, &lookup);
2448
2449 // Get the receiver from the stack.
2450 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2451
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002452 CallInterceptorCompiler compiler(this, arguments(), a2, extra_state_);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002453 compiler.Compile(masm(), object, holder, name, &lookup, a1, a3, t0, a0,
2454 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002455
2456 // Move returned value, the function to call, to a1.
2457 __ mov(a1, v0);
2458 // Restore receiver.
2459 __ lw(a0, MemOperand(sp, argc * kPointerSize));
2460
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002461 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002462
2463 // Handle call cache miss.
2464 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002465 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002466
2467 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002468 return GetCode(INTERCEPTOR, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002469}
2470
2471
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002472Handle<Code> CallStubCompiler::CompileCallGlobal(
2473 Handle<JSObject> object,
2474 Handle<GlobalObject> holder,
2475 Handle<JSGlobalPropertyCell> cell,
2476 Handle<JSFunction> function,
2477 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002478 // ----------- S t a t e -------------
2479 // -- a2 : name
2480 // -- ra : return address
2481 // -----------------------------------
2482
2483 if (HasCustomCallGenerator(function)) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002484 Handle<Code> code = CompileCustomCall(object, holder, cell, function, name);
2485 // A null handle means bail out to the regular compiler code below.
2486 if (!code.is_null()) return code;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002487 }
2488
2489 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002490 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002491
2492 // Get the number of arguments.
2493 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002494 GenerateGlobalReceiverCheck(object, holder, name, &miss);
2495 GenerateLoadFunctionFromCell(cell, function, &miss);
2496
2497 // Patch the receiver on the stack with the global proxy if
2498 // necessary.
2499 if (object->IsGlobalObject()) {
2500 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
2501 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2502 }
2503
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002504 // Set up the context (function already in r1).
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002505 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
2506
2507 // Jump to the cached code (tail call).
2508 Counters* counters = masm()->isolate()->counters();
2509 __ IncrementCounter(counters->call_global_inline(), 1, a3, t0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002510 ParameterCount expected(function->shared()->formal_parameter_count());
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002511 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
danno@chromium.org40cb8782011-05-25 07:58:50 +00002512 ? CALL_AS_FUNCTION
2513 : CALL_AS_METHOD;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002514 // We call indirectly through the code field in the function to
2515 // allow recompilation to take effect without changing any of the
2516 // call sites.
2517 __ lw(a3, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
2518 __ InvokeCode(a3, expected, arguments(), JUMP_FUNCTION,
2519 NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002520
2521 // Handle call cache miss.
2522 __ bind(&miss);
2523 __ IncrementCounter(counters->call_global_inline_miss(), 1, a1, a3);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002524 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002525
2526 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002527 return GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002528}
2529
2530
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002531Handle<Code> StoreStubCompiler::CompileStoreField(Handle<JSObject> object,
ager@chromium.org5c838252010-02-19 08:53:10 +00002532 int index,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002533 Handle<Map> transition,
2534 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002535 // ----------- S t a t e -------------
2536 // -- a0 : value
2537 // -- a1 : receiver
2538 // -- a2 : name
2539 // -- ra : return address
2540 // -----------------------------------
2541 Label miss;
2542
2543 // Name register might be clobbered.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002544 GenerateStoreField(masm(), object, index, transition, a1, a2, a3, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002545 __ bind(&miss);
2546 __ li(a2, Operand(Handle<String>(name))); // Restore name.
2547 Handle<Code> ic = masm()->isolate()->builtins()->Builtins::StoreIC_Miss();
2548 __ Jump(ic, RelocInfo::CODE_TARGET);
2549
2550 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002551 return GetCode(transition.is_null() ? FIELD : MAP_TRANSITION, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002552}
2553
2554
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002555Handle<Code> StoreStubCompiler::CompileStoreCallback(
2556 Handle<JSObject> object,
2557 Handle<AccessorInfo> callback,
2558 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002559 // ----------- S t a t e -------------
2560 // -- a0 : value
2561 // -- a1 : receiver
2562 // -- a2 : name
2563 // -- ra : return address
2564 // -----------------------------------
2565 Label miss;
2566
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002567 // Check that the map of the object hasn't changed.
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002568 __ CheckMap(a1, a3, Handle<Map>(object->map()), &miss,
2569 DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002570
2571 // Perform global security token check if needed.
2572 if (object->IsJSGlobalProxy()) {
2573 __ CheckAccessGlobalProxy(a1, a3, &miss);
2574 }
2575
2576 // Stub never generated for non-global objects that require access
2577 // checks.
2578 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
2579
2580 __ push(a1); // Receiver.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002581 __ li(a3, Operand(callback)); // Callback info.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002582 __ Push(a3, a2, a0);
2583
2584 // Do tail-call to the runtime system.
2585 ExternalReference store_callback_property =
2586 ExternalReference(IC_Utility(IC::kStoreCallbackProperty),
2587 masm()->isolate());
2588 __ TailCallExternalReference(store_callback_property, 4, 1);
2589
2590 // Handle store cache miss.
2591 __ bind(&miss);
2592 Handle<Code> ic = masm()->isolate()->builtins()->StoreIC_Miss();
2593 __ Jump(ic, RelocInfo::CODE_TARGET);
2594
2595 // Return the generated code.
2596 return GetCode(CALLBACKS, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002597}
2598
2599
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002600Handle<Code> StoreStubCompiler::CompileStoreInterceptor(
2601 Handle<JSObject> receiver,
2602 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002603 // ----------- S t a t e -------------
2604 // -- a0 : value
2605 // -- a1 : receiver
2606 // -- a2 : name
2607 // -- ra : return address
2608 // -----------------------------------
2609 Label miss;
2610
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002611 // Check that the map of the object hasn't changed.
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00002612 __ CheckMap(a1, a3, Handle<Map>(receiver->map()), &miss,
2613 DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002614
2615 // Perform global security token check if needed.
2616 if (receiver->IsJSGlobalProxy()) {
2617 __ CheckAccessGlobalProxy(a1, a3, &miss);
2618 }
2619
2620 // Stub is never generated for non-global objects that require access
2621 // checks.
2622 ASSERT(receiver->IsJSGlobalProxy() || !receiver->IsAccessCheckNeeded());
2623
2624 __ Push(a1, a2, a0); // Receiver, name, value.
2625
2626 __ li(a0, Operand(Smi::FromInt(strict_mode_)));
2627 __ push(a0); // Strict mode.
2628
2629 // Do tail-call to the runtime system.
2630 ExternalReference store_ic_property =
2631 ExternalReference(IC_Utility(IC::kStoreInterceptorProperty),
2632 masm()->isolate());
2633 __ TailCallExternalReference(store_ic_property, 4, 1);
2634
2635 // Handle store cache miss.
2636 __ bind(&miss);
2637 Handle<Code> ic = masm()->isolate()->builtins()->Builtins::StoreIC_Miss();
2638 __ Jump(ic, RelocInfo::CODE_TARGET);
2639
2640 // Return the generated code.
2641 return GetCode(INTERCEPTOR, name);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00002642}
2643
2644
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002645Handle<Code> StoreStubCompiler::CompileStoreGlobal(
2646 Handle<GlobalObject> object,
2647 Handle<JSGlobalPropertyCell> cell,
2648 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002649 // ----------- S t a t e -------------
2650 // -- a0 : value
2651 // -- a1 : receiver
2652 // -- a2 : name
2653 // -- ra : return address
2654 // -----------------------------------
2655 Label miss;
2656
2657 // Check that the map of the global has not changed.
2658 __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
2659 __ Branch(&miss, ne, a3, Operand(Handle<Map>(object->map())));
2660
2661 // Check that the value in the cell is not the hole. If it is, this
2662 // cell could have been deleted and reintroducing the global needs
2663 // to update the property details in the property dictionary of the
2664 // global object. We bail out to the runtime system to do that.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002665 __ li(t0, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002666 __ LoadRoot(t1, Heap::kTheHoleValueRootIndex);
2667 __ lw(t2, FieldMemOperand(t0, JSGlobalPropertyCell::kValueOffset));
2668 __ Branch(&miss, eq, t1, Operand(t2));
2669
2670 // Store the value in the cell.
2671 __ sw(a0, FieldMemOperand(t0, JSGlobalPropertyCell::kValueOffset));
2672 __ mov(v0, a0); // Stored value must be returned in v0.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002673 // Cells are always rescanned, so no write barrier here.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00002674
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002675 Counters* counters = masm()->isolate()->counters();
2676 __ IncrementCounter(counters->named_store_global_inline(), 1, a1, a3);
2677 __ Ret();
2678
2679 // Handle store cache miss.
2680 __ bind(&miss);
2681 __ IncrementCounter(counters->named_store_global_inline_miss(), 1, a1, a3);
2682 Handle<Code> ic = masm()->isolate()->builtins()->StoreIC_Miss();
2683 __ Jump(ic, RelocInfo::CODE_TARGET);
2684
2685 // Return the generated code.
2686 return GetCode(NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002687}
2688
2689
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002690Handle<Code> LoadStubCompiler::CompileLoadNonexistent(Handle<String> name,
2691 Handle<JSObject> object,
2692 Handle<JSObject> last) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002693 // ----------- S t a t e -------------
2694 // -- a0 : receiver
2695 // -- ra : return address
2696 // -----------------------------------
2697 Label miss;
2698
2699 // Check that the receiver is not a smi.
2700 __ JumpIfSmi(a0, &miss);
2701
2702 // Check the maps of the full prototype chain.
2703 CheckPrototypes(object, a0, last, a3, a1, t0, name, &miss);
2704
2705 // If the last object in the prototype chain is a global object,
2706 // check that the global property cell is empty.
2707 if (last->IsGlobalObject()) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002708 GenerateCheckPropertyCell(
2709 masm(), Handle<GlobalObject>::cast(last), name, a1, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002710 }
2711
2712 // Return undefined if maps of the full prototype chain is still the same.
2713 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
2714 __ Ret();
2715
2716 __ bind(&miss);
2717 GenerateLoadMiss(masm(), Code::LOAD_IC);
2718
2719 // Return the generated code.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002720 return GetCode(NONEXISTENT, factory()->empty_string());
lrn@chromium.org7516f052011-03-30 08:52:27 +00002721}
2722
2723
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002724Handle<Code> LoadStubCompiler::CompileLoadField(Handle<JSObject> object,
2725 Handle<JSObject> holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +00002726 int index,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002727 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002728 // ----------- S t a t e -------------
2729 // -- a0 : receiver
2730 // -- a2 : name
2731 // -- ra : return address
2732 // -----------------------------------
2733 Label miss;
2734
2735 __ mov(v0, a0);
2736
2737 GenerateLoadField(object, holder, v0, a3, a1, t0, index, name, &miss);
2738 __ bind(&miss);
2739 GenerateLoadMiss(masm(), Code::LOAD_IC);
2740
2741 // Return the generated code.
2742 return GetCode(FIELD, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002743}
2744
2745
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002746Handle<Code> LoadStubCompiler::CompileLoadCallback(
2747 Handle<String> name,
2748 Handle<JSObject> object,
2749 Handle<JSObject> holder,
2750 Handle<AccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002751 // ----------- S t a t e -------------
2752 // -- a0 : receiver
2753 // -- a2 : name
2754 // -- ra : return address
2755 // -----------------------------------
2756 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002757 GenerateLoadCallback(object, holder, a0, a2, a3, a1, t0, callback, name,
2758 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002759 __ bind(&miss);
2760 GenerateLoadMiss(masm(), Code::LOAD_IC);
2761
2762 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002763 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002764}
2765
2766
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002767Handle<Code> LoadStubCompiler::CompileLoadConstant(Handle<JSObject> object,
2768 Handle<JSObject> holder,
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002769 Handle<JSFunction> value,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002770 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002771 // ----------- S t a t e -------------
2772 // -- a0 : receiver
2773 // -- a2 : name
2774 // -- ra : return address
2775 // -----------------------------------
2776 Label miss;
2777
2778 GenerateLoadConstant(object, holder, a0, a3, a1, t0, value, name, &miss);
2779 __ bind(&miss);
2780 GenerateLoadMiss(masm(), Code::LOAD_IC);
2781
2782 // Return the generated code.
2783 return GetCode(CONSTANT_FUNCTION, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002784}
2785
2786
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002787Handle<Code> LoadStubCompiler::CompileLoadInterceptor(Handle<JSObject> object,
2788 Handle<JSObject> holder,
2789 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002790 // ----------- S t a t e -------------
2791 // -- a0 : receiver
2792 // -- a2 : name
2793 // -- ra : return address
2794 // -- [sp] : receiver
2795 // -----------------------------------
2796 Label miss;
2797
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002798 LookupResult lookup(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002799 LookupPostInterceptor(holder, name, &lookup);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002800 GenerateLoadInterceptor(object, holder, &lookup, a0, a2, a3, a1, t0, name,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002801 &miss);
2802 __ bind(&miss);
2803 GenerateLoadMiss(masm(), Code::LOAD_IC);
2804
2805 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002806 return GetCode(INTERCEPTOR, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002807}
2808
2809
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002810Handle<Code> LoadStubCompiler::CompileLoadGlobal(
2811 Handle<JSObject> object,
2812 Handle<GlobalObject> holder,
2813 Handle<JSGlobalPropertyCell> cell,
2814 Handle<String> name,
2815 bool is_dont_delete) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002816 // ----------- S t a t e -------------
2817 // -- a0 : receiver
2818 // -- a2 : name
2819 // -- ra : return address
2820 // -----------------------------------
2821 Label miss;
2822
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002823 // Check that the map of the global has not changed.
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00002824 __ JumpIfSmi(a0, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002825 CheckPrototypes(object, a0, holder, a3, t0, a1, name, &miss);
2826
2827 // Get the value from the cell.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002828 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002829 __ lw(t0, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
2830
2831 // Check for deleted property if property can actually be deleted.
2832 if (!is_dont_delete) {
2833 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
2834 __ Branch(&miss, eq, t0, Operand(at));
2835 }
2836
2837 __ mov(v0, t0);
2838 Counters* counters = masm()->isolate()->counters();
2839 __ IncrementCounter(counters->named_load_global_stub(), 1, a1, a3);
2840 __ Ret();
2841
2842 __ bind(&miss);
2843 __ IncrementCounter(counters->named_load_global_stub_miss(), 1, a1, a3);
2844 GenerateLoadMiss(masm(), Code::LOAD_IC);
2845
2846 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002847 return GetCode(NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002848}
2849
2850
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002851Handle<Code> KeyedLoadStubCompiler::CompileLoadField(Handle<String> name,
2852 Handle<JSObject> receiver,
2853 Handle<JSObject> holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +00002854 int index) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002855 // ----------- S t a t e -------------
2856 // -- ra : return address
2857 // -- a0 : key
2858 // -- a1 : receiver
2859 // -----------------------------------
2860 Label miss;
2861
2862 // Check the key is the cached one.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002863 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002864
2865 GenerateLoadField(receiver, holder, a1, a2, a3, t0, index, name, &miss);
2866 __ bind(&miss);
2867 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
2868
2869 return GetCode(FIELD, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002870}
2871
2872
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002873Handle<Code> KeyedLoadStubCompiler::CompileLoadCallback(
2874 Handle<String> name,
2875 Handle<JSObject> receiver,
2876 Handle<JSObject> holder,
2877 Handle<AccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002878 // ----------- S t a t e -------------
2879 // -- ra : return address
2880 // -- a0 : key
2881 // -- a1 : receiver
2882 // -----------------------------------
2883 Label miss;
2884
2885 // Check the key is the cached one.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002886 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002887
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002888 GenerateLoadCallback(receiver, holder, a1, a0, a2, a3, t0, callback, name,
2889 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002890 __ bind(&miss);
2891 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
2892
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002893 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002894}
2895
2896
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002897Handle<Code> KeyedLoadStubCompiler::CompileLoadConstant(
2898 Handle<String> name,
2899 Handle<JSObject> receiver,
2900 Handle<JSObject> holder,
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002901 Handle<JSFunction> value) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002902 // ----------- S t a t e -------------
2903 // -- ra : return address
2904 // -- a0 : key
2905 // -- a1 : receiver
2906 // -----------------------------------
2907 Label miss;
2908
2909 // Check the key is the cached one.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002910 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002911
2912 GenerateLoadConstant(receiver, holder, a1, a2, a3, t0, value, name, &miss);
2913 __ bind(&miss);
2914 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
2915
2916 // Return the generated code.
2917 return GetCode(CONSTANT_FUNCTION, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002918}
2919
2920
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002921Handle<Code> KeyedLoadStubCompiler::CompileLoadInterceptor(
2922 Handle<JSObject> receiver,
2923 Handle<JSObject> holder,
2924 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002925 // ----------- S t a t e -------------
2926 // -- ra : return address
2927 // -- a0 : key
2928 // -- a1 : receiver
2929 // -----------------------------------
2930 Label miss;
2931
2932 // Check the key is the cached one.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002933 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002934
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002935 LookupResult lookup(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002936 LookupPostInterceptor(holder, name, &lookup);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002937 GenerateLoadInterceptor(receiver, holder, &lookup, a1, a0, a2, a3, t0, name,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002938 &miss);
2939 __ bind(&miss);
2940 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
2941
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002942 return GetCode(INTERCEPTOR, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002943}
2944
2945
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002946Handle<Code> KeyedLoadStubCompiler::CompileLoadArrayLength(
2947 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002948 // ----------- S t a t e -------------
2949 // -- ra : return address
2950 // -- a0 : key
2951 // -- a1 : receiver
2952 // -----------------------------------
2953 Label miss;
2954
2955 // Check the key is the cached one.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002956 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002957
2958 GenerateLoadArrayLength(masm(), a1, a2, &miss);
2959 __ bind(&miss);
2960 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
2961
2962 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002963}
2964
2965
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002966Handle<Code> KeyedLoadStubCompiler::CompileLoadStringLength(
2967 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002968 // ----------- S t a t e -------------
2969 // -- ra : return address
2970 // -- a0 : key
2971 // -- a1 : receiver
2972 // -----------------------------------
2973 Label miss;
2974
2975 Counters* counters = masm()->isolate()->counters();
2976 __ IncrementCounter(counters->keyed_load_string_length(), 1, a2, a3);
2977
2978 // Check the key is the cached one.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002979 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002980
2981 GenerateLoadStringLength(masm(), a1, a2, a3, &miss, true);
2982 __ bind(&miss);
2983 __ DecrementCounter(counters->keyed_load_string_length(), 1, a2, a3);
2984
2985 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
2986
2987 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002988}
2989
2990
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002991Handle<Code> KeyedLoadStubCompiler::CompileLoadFunctionPrototype(
2992 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002993 // ----------- S t a t e -------------
2994 // -- ra : return address
2995 // -- a0 : key
2996 // -- a1 : receiver
2997 // -----------------------------------
2998 Label miss;
2999
3000 Counters* counters = masm()->isolate()->counters();
3001 __ IncrementCounter(counters->keyed_load_function_prototype(), 1, a2, a3);
3002
3003 // Check the name hasn't changed.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003004 __ Branch(&miss, ne, a0, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003005
3006 GenerateLoadFunctionPrototype(masm(), a1, a2, a3, &miss);
3007 __ bind(&miss);
3008 __ DecrementCounter(counters->keyed_load_function_prototype(), 1, a2, a3);
3009 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
3010
3011 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003012}
3013
3014
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003015Handle<Code> KeyedLoadStubCompiler::CompileLoadElement(
3016 Handle<Map> receiver_map) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003017 // ----------- S t a t e -------------
3018 // -- ra : return address
3019 // -- a0 : key
3020 // -- a1 : receiver
3021 // -----------------------------------
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003022 ElementsKind elements_kind = receiver_map->elements_kind();
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003023 Handle<Code> stub = KeyedLoadElementStub(elements_kind).GetCode();
3024
3025 __ DispatchMap(a1, a2, receiver_map, stub, DO_SMI_CHECK);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003026
3027 Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Miss();
3028 __ Jump(ic, RelocInfo::CODE_TARGET);
3029
3030 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003031 return GetCode(NORMAL, factory()->empty_string());
danno@chromium.org40cb8782011-05-25 07:58:50 +00003032}
3033
3034
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003035Handle<Code> KeyedLoadStubCompiler::CompileLoadPolymorphic(
3036 MapHandleList* receiver_maps,
3037 CodeHandleList* handler_ics) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003038 // ----------- S t a t e -------------
3039 // -- ra : return address
3040 // -- a0 : key
3041 // -- a1 : receiver
3042 // -----------------------------------
3043 Label miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003044 __ JumpIfSmi(a1, &miss);
3045
danno@chromium.org40cb8782011-05-25 07:58:50 +00003046 int receiver_count = receiver_maps->length();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003047 __ lw(a2, FieldMemOperand(a1, HeapObject::kMapOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003048 for (int current = 0; current < receiver_count; ++current) {
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003049 __ Jump(handler_ics->at(current), RelocInfo::CODE_TARGET,
3050 eq, a2, Operand(receiver_maps->at(current)));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003051 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003052
3053 __ bind(&miss);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003054 Handle<Code> miss_ic = isolate()->builtins()->KeyedLoadIC_Miss();
3055 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003056
3057 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003058 return GetCode(NORMAL, factory()->empty_string(), MEGAMORPHIC);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003059}
3060
3061
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003062Handle<Code> KeyedStoreStubCompiler::CompileStoreField(Handle<JSObject> object,
lrn@chromium.org7516f052011-03-30 08:52:27 +00003063 int index,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003064 Handle<Map> transition,
3065 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003066 // ----------- S t a t e -------------
3067 // -- a0 : value
3068 // -- a1 : key
3069 // -- a2 : receiver
3070 // -- ra : return address
3071 // -----------------------------------
3072
3073 Label miss;
3074
3075 Counters* counters = masm()->isolate()->counters();
3076 __ IncrementCounter(counters->keyed_store_field(), 1, a3, t0);
3077
3078 // Check that the name has not changed.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003079 __ Branch(&miss, ne, a1, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003080
3081 // a3 is used as scratch register. a1 and a2 keep their values if a jump to
3082 // the miss label is generated.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003083 GenerateStoreField(masm(), object, index, transition, a2, a1, a3, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003084 __ bind(&miss);
3085
3086 __ DecrementCounter(counters->keyed_store_field(), 1, a3, t0);
3087 Handle<Code> ic = masm()->isolate()->builtins()->KeyedStoreIC_Miss();
3088 __ Jump(ic, RelocInfo::CODE_TARGET);
3089
3090 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003091 return GetCode(transition.is_null() ? FIELD : MAP_TRANSITION, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003092}
3093
3094
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003095Handle<Code> KeyedStoreStubCompiler::CompileStoreElement(
3096 Handle<Map> receiver_map) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003097 // ----------- S t a t e -------------
3098 // -- a0 : value
3099 // -- a1 : key
3100 // -- a2 : receiver
3101 // -- ra : return address
3102 // -- a3 : scratch
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003103 // -----------------------------------
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003104 ElementsKind elements_kind = receiver_map->elements_kind();
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003105 bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE;
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003106 Handle<Code> stub =
yangguo@chromium.org56454712012-02-16 15:33:53 +00003107 KeyedStoreElementStub(is_js_array, elements_kind, grow_mode_).GetCode();
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003108
3109 __ DispatchMap(a2, a3, receiver_map, stub, DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003110
danno@chromium.org40cb8782011-05-25 07:58:50 +00003111 Handle<Code> ic = isolate()->builtins()->KeyedStoreIC_Miss();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003112 __ Jump(ic, RelocInfo::CODE_TARGET);
3113
3114 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003115 return GetCode(NORMAL, factory()->empty_string());
lrn@chromium.org7516f052011-03-30 08:52:27 +00003116}
3117
3118
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003119Handle<Code> KeyedStoreStubCompiler::CompileStorePolymorphic(
3120 MapHandleList* receiver_maps,
3121 CodeHandleList* handler_stubs,
3122 MapHandleList* transitioned_maps) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003123 // ----------- S t a t e -------------
3124 // -- a0 : value
3125 // -- a1 : key
3126 // -- a2 : receiver
3127 // -- ra : return address
3128 // -- a3 : scratch
3129 // -----------------------------------
3130 Label miss;
3131 __ JumpIfSmi(a2, &miss);
3132
3133 int receiver_count = receiver_maps->length();
3134 __ lw(a3, FieldMemOperand(a2, HeapObject::kMapOffset));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003135 for (int i = 0; i < receiver_count; ++i) {
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003136 if (transitioned_maps->at(i).is_null()) {
3137 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET, eq,
3138 a3, Operand(receiver_maps->at(i)));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003139 } else {
3140 Label next_map;
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003141 __ Branch(&next_map, ne, a3, Operand(receiver_maps->at(i)));
3142 __ li(a3, Operand(transitioned_maps->at(i)));
3143 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003144 __ bind(&next_map);
3145 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003146 }
3147
3148 __ bind(&miss);
3149 Handle<Code> miss_ic = isolate()->builtins()->KeyedStoreIC_Miss();
3150 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
3151
3152 // Return the generated code.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003153 return GetCode(NORMAL, factory()->empty_string(), MEGAMORPHIC);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003154}
3155
3156
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003157Handle<Code> ConstructStubCompiler::CompileConstructStub(
3158 Handle<JSFunction> function) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003159 // a0 : argc
3160 // a1 : constructor
3161 // ra : return address
3162 // [sp] : last argument
3163 Label generic_stub_call;
3164
3165 // Use t7 for holding undefined which is used in several places below.
3166 __ LoadRoot(t7, Heap::kUndefinedValueRootIndex);
3167
3168#ifdef ENABLE_DEBUGGER_SUPPORT
3169 // Check to see whether there are any break points in the function code. If
3170 // there are jump to the generic constructor stub which calls the actual
3171 // code for the function thereby hitting the break points.
3172 __ lw(t5, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
3173 __ lw(a2, FieldMemOperand(t5, SharedFunctionInfo::kDebugInfoOffset));
3174 __ Branch(&generic_stub_call, ne, a2, Operand(t7));
3175#endif
3176
3177 // Load the initial map and verify that it is in fact a map.
3178 // a1: constructor function
3179 // t7: undefined
3180 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003181 __ JumpIfSmi(a2, &generic_stub_call);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003182 __ GetObjectType(a2, a3, t0);
3183 __ Branch(&generic_stub_call, ne, t0, Operand(MAP_TYPE));
3184
3185#ifdef DEBUG
3186 // Cannot construct functions this way.
3187 // a0: argc
3188 // a1: constructor function
3189 // a2: initial map
3190 // t7: undefined
3191 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceTypeOffset));
3192 __ Check(ne, "Function constructed by construct stub.",
3193 a3, Operand(JS_FUNCTION_TYPE));
3194#endif
3195
3196 // Now allocate the JSObject in new space.
3197 // a0: argc
3198 // a1: constructor function
3199 // a2: initial map
3200 // t7: undefined
3201 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceSizeOffset));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003202 __ AllocateInNewSpace(a3, t4, t5, t6, &generic_stub_call, SIZE_IN_WORDS);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003203
3204 // Allocated the JSObject, now initialize the fields. Map is set to initial
3205 // map and properties and elements are set to empty fixed array.
3206 // a0: argc
3207 // a1: constructor function
3208 // a2: initial map
3209 // a3: object size (in words)
3210 // t4: JSObject (not tagged)
3211 // t7: undefined
3212 __ LoadRoot(t6, Heap::kEmptyFixedArrayRootIndex);
3213 __ mov(t5, t4);
3214 __ sw(a2, MemOperand(t5, JSObject::kMapOffset));
3215 __ sw(t6, MemOperand(t5, JSObject::kPropertiesOffset));
3216 __ sw(t6, MemOperand(t5, JSObject::kElementsOffset));
3217 __ Addu(t5, t5, Operand(3 * kPointerSize));
3218 ASSERT_EQ(0 * kPointerSize, JSObject::kMapOffset);
3219 ASSERT_EQ(1 * kPointerSize, JSObject::kPropertiesOffset);
3220 ASSERT_EQ(2 * kPointerSize, JSObject::kElementsOffset);
3221
3222
3223 // Calculate the location of the first argument. The stack contains only the
3224 // argc arguments.
3225 __ sll(a1, a0, kPointerSizeLog2);
3226 __ Addu(a1, a1, sp);
3227
3228 // Fill all the in-object properties with undefined.
3229 // a0: argc
3230 // a1: first argument
3231 // a3: object size (in words)
3232 // t4: JSObject (not tagged)
3233 // t5: First in-object property of JSObject (not tagged)
3234 // t7: undefined
3235 // Fill the initialized properties with a constant value or a passed argument
3236 // depending on the this.x = ...; assignment in the function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003237 Handle<SharedFunctionInfo> shared(function->shared());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003238 for (int i = 0; i < shared->this_property_assignments_count(); i++) {
3239 if (shared->IsThisPropertyAssignmentArgument(i)) {
3240 Label not_passed, next;
3241 // Check if the argument assigned to the property is actually passed.
3242 int arg_number = shared->GetThisPropertyAssignmentArgument(i);
3243 __ Branch(&not_passed, less_equal, a0, Operand(arg_number));
3244 // Argument passed - find it on the stack.
3245 __ lw(a2, MemOperand(a1, (arg_number + 1) * -kPointerSize));
3246 __ sw(a2, MemOperand(t5));
3247 __ Addu(t5, t5, kPointerSize);
3248 __ jmp(&next);
3249 __ bind(&not_passed);
3250 // Set the property to undefined.
3251 __ sw(t7, MemOperand(t5));
3252 __ Addu(t5, t5, Operand(kPointerSize));
3253 __ bind(&next);
3254 } else {
3255 // Set the property to the constant value.
3256 Handle<Object> constant(shared->GetThisPropertyAssignmentConstant(i));
3257 __ li(a2, Operand(constant));
3258 __ sw(a2, MemOperand(t5));
3259 __ Addu(t5, t5, kPointerSize);
3260 }
3261 }
3262
3263 // Fill the unused in-object property fields with undefined.
3264 ASSERT(function->has_initial_map());
3265 for (int i = shared->this_property_assignments_count();
3266 i < function->initial_map()->inobject_properties();
3267 i++) {
3268 __ sw(t7, MemOperand(t5));
3269 __ Addu(t5, t5, kPointerSize);
3270 }
3271
3272 // a0: argc
3273 // t4: JSObject (not tagged)
3274 // Move argc to a1 and the JSObject to return to v0 and tag it.
3275 __ mov(a1, a0);
3276 __ mov(v0, t4);
3277 __ Or(v0, v0, Operand(kHeapObjectTag));
3278
3279 // v0: JSObject
3280 // a1: argc
3281 // Remove caller arguments and receiver from the stack and return.
3282 __ sll(t0, a1, kPointerSizeLog2);
3283 __ Addu(sp, sp, t0);
3284 __ Addu(sp, sp, Operand(kPointerSize));
3285 Counters* counters = masm()->isolate()->counters();
3286 __ IncrementCounter(counters->constructed_objects(), 1, a1, a2);
3287 __ IncrementCounter(counters->constructed_objects_stub(), 1, a1, a2);
3288 __ Ret();
3289
3290 // Jump to the generic stub in case the specialized code cannot handle the
3291 // construction.
3292 __ bind(&generic_stub_call);
3293 Handle<Code> generic_construct_stub =
3294 masm()->isolate()->builtins()->JSConstructStubGeneric();
3295 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET);
3296
3297 // Return the generated code.
3298 return GetCode();
3299}
3300
3301
danno@chromium.org40cb8782011-05-25 07:58:50 +00003302#undef __
3303#define __ ACCESS_MASM(masm)
3304
3305
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003306void KeyedLoadStubCompiler::GenerateLoadDictionaryElement(
3307 MacroAssembler* masm) {
3308 // ---------- S t a t e --------------
3309 // -- ra : return address
3310 // -- a0 : key
3311 // -- a1 : receiver
3312 // -----------------------------------
3313 Label slow, miss_force_generic;
3314
3315 Register key = a0;
3316 Register receiver = a1;
3317
3318 __ JumpIfNotSmi(key, &miss_force_generic);
3319 __ lw(t0, FieldMemOperand(receiver, JSObject::kElementsOffset));
3320 __ sra(a2, a0, kSmiTagSize);
3321 __ LoadFromNumberDictionary(&slow, t0, a0, v0, a2, a3, t1);
3322 __ Ret();
3323
3324 // Slow case, key and receiver still in a0 and a1.
3325 __ bind(&slow);
3326 __ IncrementCounter(
3327 masm->isolate()->counters()->keyed_load_external_array_slow(),
3328 1, a2, a3);
3329 // Entry registers are intact.
3330 // ---------- S t a t e --------------
3331 // -- ra : return address
3332 // -- a0 : key
3333 // -- a1 : receiver
3334 // -----------------------------------
3335 Handle<Code> slow_ic =
3336 masm->isolate()->builtins()->KeyedLoadIC_Slow();
3337 __ Jump(slow_ic, RelocInfo::CODE_TARGET);
3338
3339 // Miss case, call the runtime.
3340 __ bind(&miss_force_generic);
3341
3342 // ---------- S t a t e --------------
3343 // -- ra : return address
3344 // -- a0 : key
3345 // -- a1 : receiver
3346 // -----------------------------------
3347
3348 Handle<Code> miss_ic =
3349 masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric();
3350 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
3351}
3352
3353
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003354static bool IsElementTypeSigned(ElementsKind elements_kind) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003355 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003356 case EXTERNAL_BYTE_ELEMENTS:
3357 case EXTERNAL_SHORT_ELEMENTS:
3358 case EXTERNAL_INT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003359 return true;
3360
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003361 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
3362 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
3363 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
3364 case EXTERNAL_PIXEL_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003365 return false;
3366
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003367 case EXTERNAL_FLOAT_ELEMENTS:
3368 case EXTERNAL_DOUBLE_ELEMENTS:
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003369 case FAST_SMI_ONLY_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003370 case FAST_ELEMENTS:
3371 case FAST_DOUBLE_ELEMENTS:
3372 case DICTIONARY_ELEMENTS:
3373 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003374 UNREACHABLE();
3375 return false;
3376 }
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003377 return false;
lrn@chromium.org7516f052011-03-30 08:52:27 +00003378}
3379
3380
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003381static void GenerateSmiKeyCheck(MacroAssembler* masm,
3382 Register key,
3383 Register scratch0,
3384 Register scratch1,
3385 FPURegister double_scratch0,
3386 Label* fail) {
3387 if (CpuFeatures::IsSupported(FPU)) {
3388 CpuFeatures::Scope scope(FPU);
3389 Label key_ok;
3390 // Check for smi or a smi inside a heap number. We convert the heap
3391 // number and check if the conversion is exact and fits into the smi
3392 // range.
3393 __ JumpIfSmi(key, &key_ok);
3394 __ CheckMap(key,
3395 scratch0,
3396 Heap::kHeapNumberMapRootIndex,
3397 fail,
3398 DONT_DO_SMI_CHECK);
3399 __ ldc1(double_scratch0, FieldMemOperand(key, HeapNumber::kValueOffset));
3400 __ EmitFPUTruncate(kRoundToZero,
3401 double_scratch0,
3402 double_scratch0,
3403 scratch0,
3404 scratch1,
3405 kCheckForInexactConversion);
3406
3407 __ Branch(fail, ne, scratch1, Operand(zero_reg));
3408
3409 __ mfc1(scratch0, double_scratch0);
3410 __ SmiTagCheckOverflow(key, scratch0, scratch1);
3411 __ BranchOnOverflow(fail, scratch1);
3412 __ bind(&key_ok);
3413 } else {
3414 // Check that the key is a smi.
3415 __ JumpIfNotSmi(key, fail);
3416 }
3417}
3418
3419
danno@chromium.org40cb8782011-05-25 07:58:50 +00003420void KeyedLoadStubCompiler::GenerateLoadExternalArray(
3421 MacroAssembler* masm,
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003422 ElementsKind elements_kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003423 // ---------- S t a t e --------------
3424 // -- ra : return address
3425 // -- a0 : key
3426 // -- a1 : receiver
3427 // -----------------------------------
danno@chromium.org40cb8782011-05-25 07:58:50 +00003428 Label miss_force_generic, slow, failed_allocation;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003429
3430 Register key = a0;
3431 Register receiver = a1;
3432
danno@chromium.org40cb8782011-05-25 07:58:50 +00003433 // This stub is meant to be tail-jumped to, the receiver must already
3434 // have been verified by the caller to not be a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003435
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003436 // Check that the key is a smi or a heap number convertible to a smi.
3437 GenerateSmiKeyCheck(masm, key, t0, t1, f2, &miss_force_generic);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003438
3439 __ lw(a3, FieldMemOperand(receiver, JSObject::kElementsOffset));
3440 // a3: elements array
3441
3442 // Check that the index is in range.
3443 __ lw(t1, FieldMemOperand(a3, ExternalArray::kLengthOffset));
3444 __ sra(t2, key, kSmiTagSize);
3445 // Unsigned comparison catches both negative and too-large values.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003446 __ Branch(&miss_force_generic, Ugreater_equal, key, Operand(t1));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003447
3448 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3449 // a3: base pointer of external storage
3450
3451 // We are not untagging smi key and instead work with it
3452 // as if it was premultiplied by 2.
fschneider@chromium.org1805e212011-09-05 10:49:12 +00003453 STATIC_ASSERT((kSmiTag == 0) && (kSmiTagSize == 1));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003454
3455 Register value = a2;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003456 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003457 case EXTERNAL_BYTE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003458 __ srl(t2, key, 1);
3459 __ addu(t3, a3, t2);
3460 __ lb(value, MemOperand(t3, 0));
3461 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003462 case EXTERNAL_PIXEL_ELEMENTS:
3463 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003464 __ srl(t2, key, 1);
3465 __ addu(t3, a3, t2);
3466 __ lbu(value, MemOperand(t3, 0));
3467 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003468 case EXTERNAL_SHORT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003469 __ addu(t3, a3, key);
3470 __ lh(value, MemOperand(t3, 0));
3471 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003472 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003473 __ addu(t3, a3, key);
3474 __ lhu(value, MemOperand(t3, 0));
3475 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003476 case EXTERNAL_INT_ELEMENTS:
3477 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003478 __ sll(t2, key, 1);
3479 __ addu(t3, a3, t2);
3480 __ lw(value, MemOperand(t3, 0));
3481 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003482 case EXTERNAL_FLOAT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003483 __ sll(t3, t2, 2);
3484 __ addu(t3, a3, t3);
3485 if (CpuFeatures::IsSupported(FPU)) {
3486 CpuFeatures::Scope scope(FPU);
3487 __ lwc1(f0, MemOperand(t3, 0));
3488 } else {
3489 __ lw(value, MemOperand(t3, 0));
3490 }
3491 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003492 case EXTERNAL_DOUBLE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003493 __ sll(t2, key, 2);
3494 __ addu(t3, a3, t2);
3495 if (CpuFeatures::IsSupported(FPU)) {
3496 CpuFeatures::Scope scope(FPU);
3497 __ ldc1(f0, MemOperand(t3, 0));
3498 } else {
3499 // t3: pointer to the beginning of the double we want to load.
3500 __ lw(a2, MemOperand(t3, 0));
3501 __ lw(a3, MemOperand(t3, Register::kSizeInBytes));
3502 }
3503 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003504 case FAST_ELEMENTS:
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003505 case FAST_SMI_ONLY_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003506 case FAST_DOUBLE_ELEMENTS:
3507 case DICTIONARY_ELEMENTS:
3508 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003509 UNREACHABLE();
3510 break;
3511 }
3512
3513 // For integer array types:
3514 // a2: value
3515 // For float array type:
3516 // f0: value (if FPU is supported)
3517 // a2: value (if FPU is not supported)
3518 // For double array type:
3519 // f0: value (if FPU is supported)
3520 // a2/a3: value (if FPU is not supported)
3521
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003522 if (elements_kind == EXTERNAL_INT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003523 // For the Int and UnsignedInt array types, we need to see whether
3524 // the value can be represented in a Smi. If not, we need to convert
3525 // it to a HeapNumber.
3526 Label box_int;
3527 __ Subu(t3, value, Operand(0xC0000000)); // Non-smi value gives neg result.
3528 __ Branch(&box_int, lt, t3, Operand(zero_reg));
3529 // Tag integer as smi and return it.
3530 __ sll(v0, value, kSmiTagSize);
3531 __ Ret();
3532
3533 __ bind(&box_int);
3534 // Allocate a HeapNumber for the result and perform int-to-double
3535 // conversion.
3536 // The arm version uses a temporary here to save r0, but we don't need to
3537 // (a0 is not modified).
3538 __ LoadRoot(t1, Heap::kHeapNumberMapRootIndex);
3539 __ AllocateHeapNumber(v0, a3, t0, t1, &slow);
3540
3541 if (CpuFeatures::IsSupported(FPU)) {
3542 CpuFeatures::Scope scope(FPU);
3543 __ mtc1(value, f0);
3544 __ cvt_d_w(f0, f0);
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00003545 __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003546 __ Ret();
3547 } else {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003548 Register dst1 = t2;
3549 Register dst2 = t3;
3550 FloatingPointHelper::Destination dest =
3551 FloatingPointHelper::kCoreRegisters;
3552 FloatingPointHelper::ConvertIntToDouble(masm,
3553 value,
3554 dest,
3555 f0,
3556 dst1,
3557 dst2,
3558 t1,
3559 f2);
3560 __ sw(dst1, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
3561 __ sw(dst2, FieldMemOperand(v0, HeapNumber::kExponentOffset));
3562 __ Ret();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003563 }
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003564 } else if (elements_kind == EXTERNAL_UNSIGNED_INT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003565 // The test is different for unsigned int values. Since we need
3566 // the value to be in the range of a positive smi, we can't
3567 // handle either of the top two bits being set in the value.
3568 if (CpuFeatures::IsSupported(FPU)) {
3569 CpuFeatures::Scope scope(FPU);
3570 Label pl_box_int;
3571 __ And(t2, value, Operand(0xC0000000));
3572 __ Branch(&pl_box_int, ne, t2, Operand(zero_reg));
3573
3574 // It can fit in an Smi.
3575 // Tag integer as smi and return it.
3576 __ sll(v0, value, kSmiTagSize);
3577 __ Ret();
3578
3579 __ bind(&pl_box_int);
3580 // Allocate a HeapNumber for the result and perform int-to-double
3581 // conversion. Don't use a0 and a1 as AllocateHeapNumber clobbers all
3582 // registers - also when jumping due to exhausted young space.
3583 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3584 __ AllocateHeapNumber(v0, t2, t3, t6, &slow);
3585
3586 // This is replaced by a macro:
3587 // __ mtc1(value, f0); // LS 32-bits.
3588 // __ mtc1(zero_reg, f1); // MS 32-bits are all zero.
3589 // __ cvt_d_l(f0, f0); // Use 64 bit conv to get correct unsigned 32-bit.
3590
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00003591 __ Cvt_d_uw(f0, value, f22);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003592
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00003593 __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003594
3595 __ Ret();
3596 } else {
3597 // Check whether unsigned integer fits into smi.
3598 Label box_int_0, box_int_1, done;
3599 __ And(t2, value, Operand(0x80000000));
3600 __ Branch(&box_int_0, ne, t2, Operand(zero_reg));
3601 __ And(t2, value, Operand(0x40000000));
3602 __ Branch(&box_int_1, ne, t2, Operand(zero_reg));
3603
3604 // Tag integer as smi and return it.
3605 __ sll(v0, value, kSmiTagSize);
3606 __ Ret();
3607
3608 Register hiword = value; // a2.
3609 Register loword = a3;
3610
3611 __ bind(&box_int_0);
3612 // Integer does not have leading zeros.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003613 GenerateUInt2Double(masm, hiword, loword, t0, 0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003614 __ Branch(&done);
3615
3616 __ bind(&box_int_1);
3617 // Integer has one leading zero.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003618 GenerateUInt2Double(masm, hiword, loword, t0, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003619
3620
3621 __ bind(&done);
3622 // Integer was converted to double in registers hiword:loword.
3623 // Wrap it into a HeapNumber. Don't use a0 and a1 as AllocateHeapNumber
3624 // clobbers all registers - also when jumping due to exhausted young
3625 // space.
3626 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3627 __ AllocateHeapNumber(t2, t3, t5, t6, &slow);
3628
3629 __ sw(hiword, FieldMemOperand(t2, HeapNumber::kExponentOffset));
3630 __ sw(loword, FieldMemOperand(t2, HeapNumber::kMantissaOffset));
3631
3632 __ mov(v0, t2);
3633 __ Ret();
3634 }
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003635 } else if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003636 // For the floating-point array type, we need to always allocate a
3637 // HeapNumber.
3638 if (CpuFeatures::IsSupported(FPU)) {
3639 CpuFeatures::Scope scope(FPU);
3640 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3641 // AllocateHeapNumber clobbers all registers - also when jumping due to
3642 // exhausted young space.
3643 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3644 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3645 // The float (single) value is already in fpu reg f0 (if we use float).
3646 __ cvt_d_s(f0, f0);
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00003647 __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003648 __ Ret();
3649 } else {
3650 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3651 // AllocateHeapNumber clobbers all registers - also when jumping due to
3652 // exhausted young space.
3653 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3654 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3655 // FPU is not available, do manual single to double conversion.
3656
3657 // a2: floating point value (binary32).
3658 // v0: heap number for result
3659
3660 // Extract mantissa to t4.
3661 __ And(t4, value, Operand(kBinary32MantissaMask));
3662
3663 // Extract exponent to t5.
3664 __ srl(t5, value, kBinary32MantissaBits);
3665 __ And(t5, t5, Operand(kBinary32ExponentMask >> kBinary32MantissaBits));
3666
3667 Label exponent_rebiased;
3668 __ Branch(&exponent_rebiased, eq, t5, Operand(zero_reg));
3669
3670 __ li(t0, 0x7ff);
3671 __ Xor(t1, t5, Operand(0xFF));
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00003672 __ Movz(t5, t0, t1); // Set t5 to 0x7ff only if t5 is equal to 0xff.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003673 __ Branch(&exponent_rebiased, eq, t0, Operand(0xff));
3674
3675 // Rebias exponent.
3676 __ Addu(t5,
3677 t5,
3678 Operand(-kBinary32ExponentBias + HeapNumber::kExponentBias));
3679
3680 __ bind(&exponent_rebiased);
3681 __ And(a2, value, Operand(kBinary32SignMask));
3682 value = no_reg;
3683 __ sll(t0, t5, HeapNumber::kMantissaBitsInTopWord);
3684 __ or_(a2, a2, t0);
3685
3686 // Shift mantissa.
3687 static const int kMantissaShiftForHiWord =
3688 kBinary32MantissaBits - HeapNumber::kMantissaBitsInTopWord;
3689
3690 static const int kMantissaShiftForLoWord =
3691 kBitsPerInt - kMantissaShiftForHiWord;
3692
3693 __ srl(t0, t4, kMantissaShiftForHiWord);
3694 __ or_(a2, a2, t0);
3695 __ sll(a0, t4, kMantissaShiftForLoWord);
3696
3697 __ sw(a2, FieldMemOperand(v0, HeapNumber::kExponentOffset));
3698 __ sw(a0, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
3699 __ Ret();
3700 }
3701
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003702 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003703 if (CpuFeatures::IsSupported(FPU)) {
3704 CpuFeatures::Scope scope(FPU);
3705 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3706 // AllocateHeapNumber clobbers all registers - also when jumping due to
3707 // exhausted young space.
3708 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3709 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3710 // The double value is already in f0
3711 __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
3712 __ Ret();
3713 } else {
3714 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3715 // AllocateHeapNumber clobbers all registers - also when jumping due to
3716 // exhausted young space.
3717 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3718 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3719
3720 __ sw(a2, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
3721 __ sw(a3, FieldMemOperand(v0, HeapNumber::kExponentOffset));
3722 __ Ret();
3723 }
3724
3725 } else {
3726 // Tag integer as smi and return it.
3727 __ sll(v0, value, kSmiTagSize);
3728 __ Ret();
3729 }
3730
3731 // Slow case, key and receiver still in a0 and a1.
3732 __ bind(&slow);
3733 __ IncrementCounter(
danno@chromium.org40cb8782011-05-25 07:58:50 +00003734 masm->isolate()->counters()->keyed_load_external_array_slow(),
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003735 1, a2, a3);
3736
3737 // ---------- S t a t e --------------
3738 // -- ra : return address
3739 // -- a0 : key
3740 // -- a1 : receiver
3741 // -----------------------------------
3742
3743 __ Push(a1, a0);
3744
3745 __ TailCallRuntime(Runtime::kKeyedGetProperty, 2, 1);
3746
danno@chromium.org40cb8782011-05-25 07:58:50 +00003747 __ bind(&miss_force_generic);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003748 Handle<Code> stub =
3749 masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric();
3750 __ Jump(stub, RelocInfo::CODE_TARGET);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003751}
3752
3753
danno@chromium.org40cb8782011-05-25 07:58:50 +00003754void KeyedStoreStubCompiler::GenerateStoreExternalArray(
3755 MacroAssembler* masm,
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003756 ElementsKind elements_kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003757 // ---------- S t a t e --------------
3758 // -- a0 : value
3759 // -- a1 : key
3760 // -- a2 : receiver
3761 // -- ra : return address
3762 // -----------------------------------
3763
danno@chromium.org40cb8782011-05-25 07:58:50 +00003764 Label slow, check_heap_number, miss_force_generic;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003765
3766 // Register usage.
3767 Register value = a0;
3768 Register key = a1;
3769 Register receiver = a2;
3770 // a3 mostly holds the elements array or the destination external array.
3771
danno@chromium.org40cb8782011-05-25 07:58:50 +00003772 // This stub is meant to be tail-jumped to, the receiver must already
3773 // have been verified by the caller to not be a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003774
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003775 // Check that the key is a smi or a heap number convertible to a smi.
3776 GenerateSmiKeyCheck(masm, key, t0, t1, f2, &miss_force_generic);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003777
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003778 __ lw(a3, FieldMemOperand(receiver, JSObject::kElementsOffset));
3779
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003780 // Check that the index is in range.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003781 __ lw(t1, FieldMemOperand(a3, ExternalArray::kLengthOffset));
3782 // Unsigned comparison catches both negative and too-large values.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003783 __ Branch(&miss_force_generic, Ugreater_equal, key, Operand(t1));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003784
3785 // Handle both smis and HeapNumbers in the fast path. Go to the
3786 // runtime for all other kinds of values.
3787 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003788
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003789 if (elements_kind == EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003790 // Double to pixel conversion is only implemented in the runtime for now.
3791 __ JumpIfNotSmi(value, &slow);
3792 } else {
3793 __ JumpIfNotSmi(value, &check_heap_number);
3794 }
3795 __ SmiUntag(t1, value);
3796 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3797
3798 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003799 // t1: value (integer).
3800
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003801 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003802 case EXTERNAL_PIXEL_ELEMENTS: {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003803 // Clamp the value to [0..255].
3804 // v0 is used as a scratch register here.
3805 Label done;
3806 __ li(v0, Operand(255));
3807 // Normal branch: nop in delay slot.
3808 __ Branch(&done, gt, t1, Operand(v0));
3809 // Use delay slot in this branch.
3810 __ Branch(USE_DELAY_SLOT, &done, lt, t1, Operand(zero_reg));
3811 __ mov(v0, zero_reg); // In delay slot.
3812 __ mov(v0, t1); // Value is in range 0..255.
3813 __ bind(&done);
3814 __ mov(t1, v0);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003815
3816 __ srl(t8, key, 1);
3817 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003818 __ sb(t1, MemOperand(t8, 0));
3819 }
3820 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003821 case EXTERNAL_BYTE_ELEMENTS:
3822 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003823 __ srl(t8, key, 1);
3824 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003825 __ sb(t1, MemOperand(t8, 0));
3826 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003827 case EXTERNAL_SHORT_ELEMENTS:
3828 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003829 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003830 __ sh(t1, MemOperand(t8, 0));
3831 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003832 case EXTERNAL_INT_ELEMENTS:
3833 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003834 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003835 __ addu(t8, a3, t8);
3836 __ sw(t1, MemOperand(t8, 0));
3837 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003838 case EXTERNAL_FLOAT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003839 // Perform int-to-float conversion and store to memory.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003840 __ SmiUntag(t0, key);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003841 StoreIntAsFloat(masm, a3, t0, t1, t2, t3, t4);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003842 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003843 case EXTERNAL_DOUBLE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003844 __ sll(t8, key, 2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003845 __ addu(a3, a3, t8);
3846 // a3: effective address of the double element
3847 FloatingPointHelper::Destination destination;
3848 if (CpuFeatures::IsSupported(FPU)) {
3849 destination = FloatingPointHelper::kFPURegisters;
3850 } else {
3851 destination = FloatingPointHelper::kCoreRegisters;
3852 }
3853 FloatingPointHelper::ConvertIntToDouble(
danno@chromium.org40cb8782011-05-25 07:58:50 +00003854 masm, t1, destination,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003855 f0, t2, t3, // These are: double_dst, dst1, dst2.
3856 t0, f2); // These are: scratch2, single_scratch.
3857 if (destination == FloatingPointHelper::kFPURegisters) {
3858 CpuFeatures::Scope scope(FPU);
3859 __ sdc1(f0, MemOperand(a3, 0));
3860 } else {
3861 __ sw(t2, MemOperand(a3, 0));
3862 __ sw(t3, MemOperand(a3, Register::kSizeInBytes));
3863 }
3864 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003865 case FAST_ELEMENTS:
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003866 case FAST_SMI_ONLY_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003867 case FAST_DOUBLE_ELEMENTS:
3868 case DICTIONARY_ELEMENTS:
3869 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003870 UNREACHABLE();
3871 break;
3872 }
3873
3874 // Entry registers are intact, a0 holds the value which is the return value.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003875 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003876 __ Ret();
3877
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003878 if (elements_kind != EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003879 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003880 __ bind(&check_heap_number);
3881 __ GetObjectType(value, t1, t2);
3882 __ Branch(&slow, ne, t2, Operand(HEAP_NUMBER_TYPE));
3883
3884 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3885
3886 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003887
3888 // The WebGL specification leaves the behavior of storing NaN and
3889 // +/-Infinity into integer arrays basically undefined. For more
3890 // reproducible behavior, convert these to zero.
3891
3892 if (CpuFeatures::IsSupported(FPU)) {
3893 CpuFeatures::Scope scope(FPU);
3894
3895 __ ldc1(f0, FieldMemOperand(a0, HeapNumber::kValueOffset));
3896
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003897 if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003898 __ cvt_s_d(f0, f0);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003899 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003900 __ addu(t8, a3, t8);
3901 __ swc1(f0, MemOperand(t8, 0));
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003902 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003903 __ sll(t8, key, 2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003904 __ addu(t8, a3, t8);
3905 __ sdc1(f0, MemOperand(t8, 0));
3906 } else {
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00003907 __ EmitECMATruncate(t3, f0, f2, t2, t1, t5);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003908
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003909 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003910 case EXTERNAL_BYTE_ELEMENTS:
3911 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003912 __ srl(t8, key, 1);
3913 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003914 __ sb(t3, MemOperand(t8, 0));
3915 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003916 case EXTERNAL_SHORT_ELEMENTS:
3917 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003918 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003919 __ sh(t3, MemOperand(t8, 0));
3920 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003921 case EXTERNAL_INT_ELEMENTS:
3922 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003923 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003924 __ addu(t8, a3, t8);
3925 __ sw(t3, MemOperand(t8, 0));
3926 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003927 case EXTERNAL_PIXEL_ELEMENTS:
3928 case EXTERNAL_FLOAT_ELEMENTS:
3929 case EXTERNAL_DOUBLE_ELEMENTS:
3930 case FAST_ELEMENTS:
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003931 case FAST_SMI_ONLY_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003932 case FAST_DOUBLE_ELEMENTS:
3933 case DICTIONARY_ELEMENTS:
3934 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003935 UNREACHABLE();
3936 break;
3937 }
3938 }
3939
3940 // Entry registers are intact, a0 holds the value
3941 // which is the return value.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003942 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003943 __ Ret();
3944 } else {
3945 // FPU is not available, do manual conversions.
3946
3947 __ lw(t3, FieldMemOperand(value, HeapNumber::kExponentOffset));
3948 __ lw(t4, FieldMemOperand(value, HeapNumber::kMantissaOffset));
3949
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003950 if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003951 Label done, nan_or_infinity_or_zero;
3952 static const int kMantissaInHiWordShift =
3953 kBinary32MantissaBits - HeapNumber::kMantissaBitsInTopWord;
3954
3955 static const int kMantissaInLoWordShift =
3956 kBitsPerInt - kMantissaInHiWordShift;
3957
3958 // Test for all special exponent values: zeros, subnormal numbers, NaNs
3959 // and infinities. All these should be converted to 0.
3960 __ li(t5, HeapNumber::kExponentMask);
3961 __ and_(t6, t3, t5);
3962 __ Branch(&nan_or_infinity_or_zero, eq, t6, Operand(zero_reg));
3963
3964 __ xor_(t1, t6, t5);
3965 __ li(t2, kBinary32ExponentMask);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00003966 __ Movz(t6, t2, t1); // Only if t6 is equal to t5.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003967 __ Branch(&nan_or_infinity_or_zero, eq, t6, Operand(t5));
3968
3969 // Rebias exponent.
3970 __ srl(t6, t6, HeapNumber::kExponentShift);
3971 __ Addu(t6,
3972 t6,
3973 Operand(kBinary32ExponentBias - HeapNumber::kExponentBias));
3974
3975 __ li(t1, Operand(kBinary32MaxExponent));
3976 __ Slt(t1, t1, t6);
3977 __ And(t2, t3, Operand(HeapNumber::kSignMask));
3978 __ Or(t2, t2, Operand(kBinary32ExponentMask));
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00003979 __ Movn(t3, t2, t1); // Only if t6 is gt kBinary32MaxExponent.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003980 __ Branch(&done, gt, t6, Operand(kBinary32MaxExponent));
3981
3982 __ Slt(t1, t6, Operand(kBinary32MinExponent));
3983 __ And(t2, t3, Operand(HeapNumber::kSignMask));
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00003984 __ Movn(t3, t2, t1); // Only if t6 is lt kBinary32MinExponent.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003985 __ Branch(&done, lt, t6, Operand(kBinary32MinExponent));
3986
3987 __ And(t7, t3, Operand(HeapNumber::kSignMask));
3988 __ And(t3, t3, Operand(HeapNumber::kMantissaMask));
3989 __ sll(t3, t3, kMantissaInHiWordShift);
3990 __ or_(t7, t7, t3);
3991 __ srl(t4, t4, kMantissaInLoWordShift);
3992 __ or_(t7, t7, t4);
3993 __ sll(t6, t6, kBinary32ExponentShift);
3994 __ or_(t3, t7, t6);
3995
3996 __ bind(&done);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003997 __ sll(t9, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003998 __ addu(t9, a2, t9);
3999 __ sw(t3, MemOperand(t9, 0));
4000
4001 // Entry registers are intact, a0 holds the value which is the return
4002 // value.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004003 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004004 __ Ret();
4005
4006 __ bind(&nan_or_infinity_or_zero);
4007 __ And(t7, t3, Operand(HeapNumber::kSignMask));
4008 __ And(t3, t3, Operand(HeapNumber::kMantissaMask));
4009 __ or_(t6, t6, t7);
4010 __ sll(t3, t3, kMantissaInHiWordShift);
4011 __ or_(t6, t6, t3);
4012 __ srl(t4, t4, kMantissaInLoWordShift);
4013 __ or_(t3, t6, t4);
4014 __ Branch(&done);
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004015 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004016 __ sll(t8, t0, 3);
4017 __ addu(t8, a3, t8);
4018 // t8: effective address of destination element.
4019 __ sw(t4, MemOperand(t8, 0));
4020 __ sw(t3, MemOperand(t8, Register::kSizeInBytes));
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004021 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004022 __ Ret();
4023 } else {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004024 bool is_signed_type = IsElementTypeSigned(elements_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004025 int meaningfull_bits = is_signed_type ? (kBitsPerInt - 1) : kBitsPerInt;
4026 int32_t min_value = is_signed_type ? 0x80000000 : 0x00000000;
4027
4028 Label done, sign;
4029
4030 // Test for all special exponent values: zeros, subnormal numbers, NaNs
4031 // and infinities. All these should be converted to 0.
4032 __ li(t5, HeapNumber::kExponentMask);
4033 __ and_(t6, t3, t5);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00004034 __ Movz(t3, zero_reg, t6); // Only if t6 is equal to zero.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004035 __ Branch(&done, eq, t6, Operand(zero_reg));
4036
4037 __ xor_(t2, t6, t5);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00004038 __ Movz(t3, zero_reg, t2); // Only if t6 is equal to t5.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004039 __ Branch(&done, eq, t6, Operand(t5));
4040
4041 // Unbias exponent.
4042 __ srl(t6, t6, HeapNumber::kExponentShift);
4043 __ Subu(t6, t6, Operand(HeapNumber::kExponentBias));
4044 // If exponent is negative then result is 0.
4045 __ slt(t2, t6, zero_reg);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00004046 __ Movn(t3, zero_reg, t2); // Only if exponent is negative.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004047 __ Branch(&done, lt, t6, Operand(zero_reg));
4048
4049 // If exponent is too big then result is minimal value.
4050 __ slti(t1, t6, meaningfull_bits - 1);
4051 __ li(t2, min_value);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00004052 __ Movz(t3, t2, t1); // Only if t6 is ge meaningfull_bits - 1.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004053 __ Branch(&done, ge, t6, Operand(meaningfull_bits - 1));
4054
4055 __ And(t5, t3, Operand(HeapNumber::kSignMask));
4056 __ And(t3, t3, Operand(HeapNumber::kMantissaMask));
4057 __ Or(t3, t3, Operand(1u << HeapNumber::kMantissaBitsInTopWord));
4058
4059 __ li(t9, HeapNumber::kMantissaBitsInTopWord);
4060 __ subu(t6, t9, t6);
4061 __ slt(t1, t6, zero_reg);
4062 __ srlv(t2, t3, t6);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00004063 __ Movz(t3, t2, t1); // Only if t6 is positive.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004064 __ Branch(&sign, ge, t6, Operand(zero_reg));
4065
4066 __ subu(t6, zero_reg, t6);
4067 __ sllv(t3, t3, t6);
4068 __ li(t9, meaningfull_bits);
4069 __ subu(t6, t9, t6);
4070 __ srlv(t4, t4, t6);
4071 __ or_(t3, t3, t4);
4072
4073 __ bind(&sign);
4074 __ subu(t2, t3, zero_reg);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00004075 __ Movz(t3, t2, t5); // Only if t5 is zero.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004076
4077 __ bind(&done);
4078
4079 // Result is in t3.
4080 // This switch block should be exactly the same as above (FPU mode).
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004081 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004082 case EXTERNAL_BYTE_ELEMENTS:
4083 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004084 __ srl(t8, key, 1);
4085 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004086 __ sb(t3, MemOperand(t8, 0));
4087 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004088 case EXTERNAL_SHORT_ELEMENTS:
4089 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004090 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004091 __ sh(t3, MemOperand(t8, 0));
4092 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004093 case EXTERNAL_INT_ELEMENTS:
4094 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004095 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004096 __ addu(t8, a3, t8);
4097 __ sw(t3, MemOperand(t8, 0));
4098 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004099 case EXTERNAL_PIXEL_ELEMENTS:
4100 case EXTERNAL_FLOAT_ELEMENTS:
4101 case EXTERNAL_DOUBLE_ELEMENTS:
4102 case FAST_ELEMENTS:
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004103 case FAST_SMI_ONLY_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004104 case FAST_DOUBLE_ELEMENTS:
4105 case DICTIONARY_ELEMENTS:
4106 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004107 UNREACHABLE();
4108 break;
4109 }
4110 }
4111 }
4112 }
4113
danno@chromium.org40cb8782011-05-25 07:58:50 +00004114 // Slow case, key and receiver still in a0 and a1.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004115 __ bind(&slow);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004116 __ IncrementCounter(
4117 masm->isolate()->counters()->keyed_load_external_array_slow(),
4118 1, a2, a3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004119 // Entry registers are intact.
4120 // ---------- S t a t e --------------
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004121 // -- ra : return address
danno@chromium.org40cb8782011-05-25 07:58:50 +00004122 // -- a0 : key
4123 // -- a1 : receiver
4124 // -----------------------------------
4125 Handle<Code> slow_ic =
4126 masm->isolate()->builtins()->KeyedStoreIC_Slow();
4127 __ Jump(slow_ic, RelocInfo::CODE_TARGET);
4128
4129 // Miss case, call the runtime.
4130 __ bind(&miss_force_generic);
4131
4132 // ---------- S t a t e --------------
4133 // -- ra : return address
4134 // -- a0 : key
4135 // -- a1 : receiver
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004136 // -----------------------------------
4137
danno@chromium.org40cb8782011-05-25 07:58:50 +00004138 Handle<Code> miss_ic =
4139 masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric();
4140 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
4141}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004142
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004143
danno@chromium.org40cb8782011-05-25 07:58:50 +00004144void KeyedLoadStubCompiler::GenerateLoadFastElement(MacroAssembler* masm) {
4145 // ----------- S t a t e -------------
4146 // -- ra : return address
4147 // -- a0 : key
4148 // -- a1 : receiver
4149 // -----------------------------------
4150 Label miss_force_generic;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004151
danno@chromium.org40cb8782011-05-25 07:58:50 +00004152 // This stub is meant to be tail-jumped to, the receiver must already
4153 // have been verified by the caller to not be a smi.
4154
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00004155 // Check that the key is a smi or a heap number convertible to a smi.
4156 GenerateSmiKeyCheck(masm, a0, t0, t1, f2, &miss_force_generic);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004157
4158 // Get the elements array.
4159 __ lw(a2, FieldMemOperand(a1, JSObject::kElementsOffset));
4160 __ AssertFastElements(a2);
4161
4162 // Check that the key is within bounds.
4163 __ lw(a3, FieldMemOperand(a2, FixedArray::kLengthOffset));
ulan@chromium.org6ff65142012-03-21 09:52:17 +00004164 __ Branch(USE_DELAY_SLOT, &miss_force_generic, hs, a0, Operand(a3));
danno@chromium.org40cb8782011-05-25 07:58:50 +00004165
4166 // Load the result and make sure it's not the hole.
4167 __ Addu(a3, a2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
fschneider@chromium.org1805e212011-09-05 10:49:12 +00004168 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004169 __ sll(t0, a0, kPointerSizeLog2 - kSmiTagSize);
4170 __ Addu(t0, t0, a3);
4171 __ lw(t0, MemOperand(t0));
4172 __ LoadRoot(t1, Heap::kTheHoleValueRootIndex);
4173 __ Branch(&miss_force_generic, eq, t0, Operand(t1));
ulan@chromium.org6ff65142012-03-21 09:52:17 +00004174 __ Ret(USE_DELAY_SLOT);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004175 __ mov(v0, t0);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004176
4177 __ bind(&miss_force_generic);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00004178 Handle<Code> stub =
4179 masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric();
4180 __ Jump(stub, RelocInfo::CODE_TARGET);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004181}
4182
4183
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00004184void KeyedLoadStubCompiler::GenerateLoadFastDoubleElement(
4185 MacroAssembler* masm) {
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004186 // ----------- S t a t e -------------
4187 // -- ra : return address
4188 // -- a0 : key
4189 // -- a1 : receiver
4190 // -----------------------------------
4191 Label miss_force_generic, slow_allocate_heapnumber;
4192
4193 Register key_reg = a0;
4194 Register receiver_reg = a1;
4195 Register elements_reg = a2;
4196 Register heap_number_reg = a2;
4197 Register indexed_double_offset = a3;
4198 Register scratch = t0;
4199 Register scratch2 = t1;
4200 Register scratch3 = t2;
4201 Register heap_number_map = t3;
4202
4203 // This stub is meant to be tail-jumped to, the receiver must already
4204 // have been verified by the caller to not be a smi.
4205
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00004206 // Check that the key is a smi or a heap number convertible to a smi.
4207 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, &miss_force_generic);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004208
4209 // Get the elements array.
4210 __ lw(elements_reg,
4211 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4212
4213 // Check that the key is within bounds.
4214 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4215 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch));
4216
4217 // Load the upper word of the double in the fixed array and test for NaN.
4218 __ sll(scratch2, key_reg, kDoubleSizeLog2 - kSmiTagSize);
4219 __ Addu(indexed_double_offset, elements_reg, Operand(scratch2));
4220 uint32_t upper_32_offset = FixedArray::kHeaderSize + sizeof(kHoleNanLower32);
4221 __ lw(scratch, FieldMemOperand(indexed_double_offset, upper_32_offset));
4222 __ Branch(&miss_force_generic, eq, scratch, Operand(kHoleNanUpper32));
4223
4224 // Non-NaN. Allocate a new heap number and copy the double value into it.
4225 __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
4226 __ AllocateHeapNumber(heap_number_reg, scratch2, scratch3,
4227 heap_number_map, &slow_allocate_heapnumber);
4228
4229 // Don't need to reload the upper 32 bits of the double, it's already in
4230 // scratch.
4231 __ sw(scratch, FieldMemOperand(heap_number_reg,
4232 HeapNumber::kExponentOffset));
4233 __ lw(scratch, FieldMemOperand(indexed_double_offset,
4234 FixedArray::kHeaderSize));
4235 __ sw(scratch, FieldMemOperand(heap_number_reg,
4236 HeapNumber::kMantissaOffset));
4237
4238 __ mov(v0, heap_number_reg);
4239 __ Ret();
4240
4241 __ bind(&slow_allocate_heapnumber);
4242 Handle<Code> slow_ic =
4243 masm->isolate()->builtins()->KeyedLoadIC_Slow();
4244 __ Jump(slow_ic, RelocInfo::CODE_TARGET);
4245
4246 __ bind(&miss_force_generic);
4247 Handle<Code> miss_ic =
4248 masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric();
4249 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00004250}
4251
4252
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004253void KeyedStoreStubCompiler::GenerateStoreFastElement(
4254 MacroAssembler* masm,
4255 bool is_js_array,
yangguo@chromium.org56454712012-02-16 15:33:53 +00004256 ElementsKind elements_kind,
4257 KeyedAccessGrowMode grow_mode) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00004258 // ----------- S t a t e -------------
4259 // -- a0 : value
4260 // -- a1 : key
4261 // -- a2 : receiver
4262 // -- ra : return address
4263 // -- a3 : scratch
4264 // -- a4 : scratch (elements)
4265 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00004266 Label miss_force_generic, transition_elements_kind, grow, slow;
4267 Label finish_store, check_capacity;
danno@chromium.org40cb8782011-05-25 07:58:50 +00004268
4269 Register value_reg = a0;
4270 Register key_reg = a1;
4271 Register receiver_reg = a2;
yangguo@chromium.org56454712012-02-16 15:33:53 +00004272 Register scratch = t0;
4273 Register elements_reg = a3;
4274 Register length_reg = t1;
4275 Register scratch2 = t2;
4276 Register scratch3 = t3;
danno@chromium.org40cb8782011-05-25 07:58:50 +00004277
4278 // This stub is meant to be tail-jumped to, the receiver must already
4279 // have been verified by the caller to not be a smi.
4280
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00004281 // Check that the key is a smi or a heap number convertible to a smi.
4282 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, &miss_force_generic);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004283
yangguo@chromium.org56454712012-02-16 15:33:53 +00004284 if (elements_kind == FAST_SMI_ONLY_ELEMENTS) {
4285 __ JumpIfNotSmi(value_reg, &transition_elements_kind);
4286 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00004287
4288 // Check that the key is within bounds.
yangguo@chromium.org56454712012-02-16 15:33:53 +00004289 __ lw(elements_reg,
4290 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00004291 if (is_js_array) {
4292 __ lw(scratch, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4293 } else {
4294 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4295 }
4296 // Compare smis.
yangguo@chromium.org56454712012-02-16 15:33:53 +00004297 if (is_js_array && grow_mode == ALLOW_JSARRAY_GROWTH) {
4298 __ Branch(&grow, hs, key_reg, Operand(scratch));
4299 } else {
4300 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch));
4301 }
4302
4303 // Make sure elements is a fast element array, not 'cow'.
4304 __ CheckMap(elements_reg,
4305 scratch,
4306 Heap::kFixedArrayMapRootIndex,
4307 &miss_force_generic,
4308 DONT_DO_SMI_CHECK);
4309
4310 __ bind(&finish_store);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004311
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004312 if (elements_kind == FAST_SMI_ONLY_ELEMENTS) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004313 __ Addu(scratch,
4314 elements_reg,
4315 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4316 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
4317 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
4318 __ Addu(scratch, scratch, scratch2);
4319 __ sw(value_reg, MemOperand(scratch));
4320 } else {
4321 ASSERT(elements_kind == FAST_ELEMENTS);
4322 __ Addu(scratch,
4323 elements_reg,
4324 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4325 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
4326 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
4327 __ Addu(scratch, scratch, scratch2);
4328 __ sw(value_reg, MemOperand(scratch));
4329 __ mov(receiver_reg, value_reg);
4330 ASSERT(elements_kind == FAST_ELEMENTS);
4331 __ RecordWrite(elements_reg, // Object.
4332 scratch, // Address.
4333 receiver_reg, // Value.
4334 kRAHasNotBeenSaved,
4335 kDontSaveFPRegs);
4336 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00004337 // value_reg (a0) is preserved.
4338 // Done.
4339 __ Ret();
4340
4341 __ bind(&miss_force_generic);
4342 Handle<Code> ic =
4343 masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric();
4344 __ Jump(ic, RelocInfo::CODE_TARGET);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004345
4346 __ bind(&transition_elements_kind);
4347 Handle<Code> ic_miss = masm->isolate()->builtins()->KeyedStoreIC_Miss();
4348 __ Jump(ic_miss, RelocInfo::CODE_TARGET);
yangguo@chromium.org56454712012-02-16 15:33:53 +00004349
4350 if (is_js_array && grow_mode == ALLOW_JSARRAY_GROWTH) {
4351 // Grow the array by a single element if possible.
4352 __ bind(&grow);
4353
4354 // Make sure the array is only growing by a single element, anything else
4355 // must be handled by the runtime.
4356 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch));
4357
4358 // Check for the empty array, and preallocate a small backing store if
4359 // possible.
4360 __ lw(length_reg,
4361 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4362 __ lw(elements_reg,
4363 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4364 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
4365 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
4366
4367 int size = FixedArray::SizeFor(JSArray::kPreallocatedArrayElements);
4368 __ AllocateInNewSpace(size, elements_reg, scratch, scratch2, &slow,
4369 TAG_OBJECT);
4370
4371 __ LoadRoot(scratch, Heap::kFixedArrayMapRootIndex);
4372 __ sw(scratch, FieldMemOperand(elements_reg, JSObject::kMapOffset));
4373 __ li(scratch, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
4374 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4375 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
4376 for (int i = 1; i < JSArray::kPreallocatedArrayElements; ++i) {
4377 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::SizeFor(i)));
4378 }
4379
4380 // Store the element at index zero.
4381 __ sw(value_reg, FieldMemOperand(elements_reg, FixedArray::SizeFor(0)));
4382
4383 // Install the new backing store in the JSArray.
4384 __ sw(elements_reg,
4385 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4386 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
4387 scratch, kRAHasNotBeenSaved, kDontSaveFPRegs,
4388 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4389
4390 // Increment the length of the array.
4391 __ li(length_reg, Operand(Smi::FromInt(1)));
4392 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4393 __ Ret();
4394
4395 __ bind(&check_capacity);
4396 // Check for cow elements, in general they are not handled by this stub
4397 __ CheckMap(elements_reg,
4398 scratch,
4399 Heap::kFixedCOWArrayMapRootIndex,
4400 &miss_force_generic,
4401 DONT_DO_SMI_CHECK);
4402
4403 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4404 __ Branch(&slow, hs, length_reg, Operand(scratch));
4405
4406 // Grow the array and finish the store.
4407 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
4408 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4409 __ jmp(&finish_store);
4410
4411 __ bind(&slow);
4412 Handle<Code> ic_slow = masm->isolate()->builtins()->KeyedStoreIC_Slow();
4413 __ Jump(ic_slow, RelocInfo::CODE_TARGET);
4414 }
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00004415}
4416
4417
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00004418void KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(
4419 MacroAssembler* masm,
yangguo@chromium.org56454712012-02-16 15:33:53 +00004420 bool is_js_array,
4421 KeyedAccessGrowMode grow_mode) {
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004422 // ----------- S t a t e -------------
4423 // -- a0 : value
4424 // -- a1 : key
4425 // -- a2 : receiver
4426 // -- ra : return address
4427 // -- a3 : scratch
4428 // -- t0 : scratch (elements_reg)
4429 // -- t1 : scratch (mantissa_reg)
4430 // -- t2 : scratch (exponent_reg)
4431 // -- t3 : scratch4
4432 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00004433 Label miss_force_generic, transition_elements_kind, grow, slow;
4434 Label finish_store, check_capacity;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004435
4436 Register value_reg = a0;
4437 Register key_reg = a1;
4438 Register receiver_reg = a2;
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004439 Register elements_reg = a3;
4440 Register scratch1 = t0;
4441 Register scratch2 = t1;
4442 Register scratch3 = t2;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004443 Register scratch4 = t3;
yangguo@chromium.org56454712012-02-16 15:33:53 +00004444 Register length_reg = t3;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004445
4446 // This stub is meant to be tail-jumped to, the receiver must already
4447 // have been verified by the caller to not be a smi.
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00004448
4449 // Check that the key is a smi or a heap number convertible to a smi.
4450 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, &miss_force_generic);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004451
4452 __ lw(elements_reg,
4453 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4454
4455 // Check that the key is within bounds.
4456 if (is_js_array) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004457 __ lw(scratch1, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004458 } else {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004459 __ lw(scratch1,
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004460 FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4461 }
4462 // Compare smis, unsigned compare catches both negative and out-of-bound
4463 // indexes.
yangguo@chromium.org56454712012-02-16 15:33:53 +00004464 if (grow_mode == ALLOW_JSARRAY_GROWTH) {
4465 __ Branch(&grow, hs, key_reg, Operand(scratch1));
4466 } else {
4467 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch1));
4468 }
4469
4470 __ bind(&finish_store);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004471
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004472 __ StoreNumberToDoubleElements(value_reg,
4473 key_reg,
4474 receiver_reg,
4475 elements_reg,
4476 scratch1,
4477 scratch2,
4478 scratch3,
4479 scratch4,
4480 &transition_elements_kind);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004481
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00004482 __ Ret(USE_DELAY_SLOT);
4483 __ mov(v0, value_reg); // In delay slot.
rossberg@chromium.org717967f2011-07-20 13:44:42 +00004484
4485 // Handle store cache miss, replacing the ic with the generic stub.
4486 __ bind(&miss_force_generic);
4487 Handle<Code> ic =
4488 masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric();
4489 __ Jump(ic, RelocInfo::CODE_TARGET);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004490
4491 __ bind(&transition_elements_kind);
4492 Handle<Code> ic_miss = masm->isolate()->builtins()->KeyedStoreIC_Miss();
4493 __ Jump(ic_miss, RelocInfo::CODE_TARGET);
yangguo@chromium.org56454712012-02-16 15:33:53 +00004494
4495 if (is_js_array && grow_mode == ALLOW_JSARRAY_GROWTH) {
4496 // Grow the array by a single element if possible.
4497 __ bind(&grow);
4498
4499 // Make sure the array is only growing by a single element, anything else
4500 // must be handled by the runtime.
4501 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch1));
4502
4503 // Transition on values that can't be stored in a FixedDoubleArray.
4504 Label value_is_smi;
4505 __ JumpIfSmi(value_reg, &value_is_smi);
4506 __ lw(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
4507 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex);
4508 __ Branch(&transition_elements_kind, ne, scratch1, Operand(at));
4509 __ bind(&value_is_smi);
4510
4511 // Check for the empty array, and preallocate a small backing store if
4512 // possible.
4513 __ lw(length_reg,
4514 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4515 __ lw(elements_reg,
4516 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4517 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
4518 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
4519
4520 int size = FixedDoubleArray::SizeFor(JSArray::kPreallocatedArrayElements);
4521 __ AllocateInNewSpace(size, elements_reg, scratch1, scratch2, &slow,
4522 TAG_OBJECT);
4523
4524 // Initialize the new FixedDoubleArray. Leave elements unitialized for
4525 // efficiency, they are guaranteed to be initialized before use.
4526 __ LoadRoot(scratch1, Heap::kFixedDoubleArrayMapRootIndex);
4527 __ sw(scratch1, FieldMemOperand(elements_reg, JSObject::kMapOffset));
4528 __ li(scratch1, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
4529 __ sw(scratch1,
4530 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
4531
4532 // Install the new backing store in the JSArray.
4533 __ sw(elements_reg,
4534 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4535 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
4536 scratch1, kRAHasNotBeenSaved, kDontSaveFPRegs,
4537 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4538
4539 // Increment the length of the array.
4540 __ li(length_reg, Operand(Smi::FromInt(1)));
4541 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4542 __ jmp(&finish_store);
4543
4544 __ bind(&check_capacity);
4545 // Make sure that the backing store can hold additional elements.
4546 __ lw(scratch1,
4547 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
4548 __ Branch(&slow, hs, length_reg, Operand(scratch1));
4549
4550 // Grow the array and finish the store.
4551 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
4552 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4553 __ jmp(&finish_store);
4554
4555 __ bind(&slow);
4556 Handle<Code> ic_slow = masm->isolate()->builtins()->KeyedStoreIC_Slow();
4557 __ Jump(ic_slow, RelocInfo::CODE_TARGET);
4558 }
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00004559}
4560
4561
ager@chromium.org5c838252010-02-19 08:53:10 +00004562#undef __
4563
4564} } // namespace v8::internal
4565
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00004566#endif // V8_TARGET_ARCH_MIPS