blob: 2e946f98f10a955ee49cc3d3dbfe1b1b7c225263 [file] [log] [blame]
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001// Copyright 2011 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,
46 Register name,
47 Register offset,
48 Register scratch,
49 Register scratch2) {
50 ExternalReference key_offset(isolate->stub_cache()->key_reference(table));
51 ExternalReference value_offset(isolate->stub_cache()->value_reference(table));
52
53 uint32_t key_off_addr = reinterpret_cast<uint32_t>(key_offset.address());
54 uint32_t value_off_addr = reinterpret_cast<uint32_t>(value_offset.address());
55
56 // Check the relative positions of the address fields.
57 ASSERT(value_off_addr > key_off_addr);
58 ASSERT((value_off_addr - key_off_addr) % 4 == 0);
59 ASSERT((value_off_addr - key_off_addr) < (256 * 4));
60
61 Label miss;
62 Register offsets_base_addr = scratch;
63
64 // Check that the key in the entry matches the name.
65 __ li(offsets_base_addr, Operand(key_offset));
66 __ sll(scratch2, offset, 1);
67 __ addu(scratch2, offsets_base_addr, scratch2);
68 __ lw(scratch2, MemOperand(scratch2));
69 __ Branch(&miss, ne, name, Operand(scratch2));
70
71 // Get the code entry from the cache.
72 __ Addu(offsets_base_addr, offsets_base_addr,
73 Operand(value_off_addr - key_off_addr));
74 __ sll(scratch2, offset, 1);
75 __ addu(scratch2, offsets_base_addr, scratch2);
76 __ lw(scratch2, MemOperand(scratch2));
77
78 // Check that the flags match what we're looking for.
79 __ lw(scratch2, FieldMemOperand(scratch2, Code::kFlagsOffset));
80 __ And(scratch2, scratch2, Operand(~Code::kFlagsNotUsedInLookup));
81 __ Branch(&miss, ne, scratch2, Operand(flags));
82
83 // Re-load code entry from cache.
84 __ sll(offset, offset, 1);
85 __ addu(offset, offset, offsets_base_addr);
86 __ lw(offset, MemOperand(offset));
87
88 // Jump to the first instruction in the code stub.
89 __ Addu(offset, offset, Operand(Code::kHeaderSize - kHeapObjectTag));
90 __ Jump(offset);
91
92 // Miss: fall through.
93 __ bind(&miss);
94}
95
96
97// Helper function used to check that the dictionary doesn't contain
98// the property. This function may return false negatives, so miss_label
99// must always call a backup property check that is complete.
100// This function is safe to call if the receiver has fast properties.
101// Name must be a symbol and receiver must be a heap object.
102MUST_USE_RESULT static MaybeObject* GenerateDictionaryNegativeLookup(
103 MacroAssembler* masm,
104 Label* miss_label,
105 Register receiver,
106 String* name,
107 Register scratch0,
108 Register scratch1) {
109 ASSERT(name->IsSymbol());
110 Counters* counters = masm->isolate()->counters();
111 __ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1);
112 __ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
113
114 Label done;
115
116 const int kInterceptorOrAccessCheckNeededMask =
117 (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
118
119 // Bail out if the receiver has a named interceptor or requires access checks.
120 Register map = scratch1;
121 __ lw(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
122 __ lbu(scratch0, FieldMemOperand(map, Map::kBitFieldOffset));
123 __ And(at, scratch0, Operand(kInterceptorOrAccessCheckNeededMask));
124 __ Branch(miss_label, ne, at, Operand(zero_reg));
125
126
127 // Check that receiver is a JSObject.
128 __ lbu(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset));
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000129 __ Branch(miss_label, lt, scratch0, Operand(FIRST_SPEC_OBJECT_TYPE));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000130
131 // Load properties array.
132 Register properties = scratch0;
133 __ lw(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
134 // Check that the properties array is a dictionary.
135 __ lw(map, FieldMemOperand(properties, HeapObject::kMapOffset));
136 Register tmp = properties;
137 __ LoadRoot(tmp, Heap::kHashTableMapRootIndex);
138 __ Branch(miss_label, ne, map, Operand(tmp));
139
140 // Restore the temporarily used register.
141 __ lw(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
142
143 MaybeObject* result = StringDictionaryLookupStub::GenerateNegativeLookup(
144 masm,
145 miss_label,
146 &done,
147 receiver,
148 properties,
149 name,
150 scratch1);
151 if (result->IsFailure()) return result;
152
153 __ bind(&done);
154 __ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
155
156 return result;
157}
158
159
ager@chromium.org5c838252010-02-19 08:53:10 +0000160void StubCache::GenerateProbe(MacroAssembler* masm,
161 Code::Flags flags,
162 Register receiver,
163 Register name,
164 Register scratch,
fschneider@chromium.orge03fb642010-11-01 12:34:09 +0000165 Register extra,
166 Register extra2) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000167 Isolate* isolate = masm->isolate();
168 Label miss;
169
170 // Make sure that code is valid. The shifting code relies on the
171 // entry size being 8.
172 ASSERT(sizeof(Entry) == 8);
173
174 // Make sure the flags does not name a specific type.
175 ASSERT(Code::ExtractTypeFromFlags(flags) == 0);
176
177 // Make sure that there are no register conflicts.
178 ASSERT(!scratch.is(receiver));
179 ASSERT(!scratch.is(name));
180 ASSERT(!extra.is(receiver));
181 ASSERT(!extra.is(name));
182 ASSERT(!extra.is(scratch));
183 ASSERT(!extra2.is(receiver));
184 ASSERT(!extra2.is(name));
185 ASSERT(!extra2.is(scratch));
186 ASSERT(!extra2.is(extra));
187
188 // Check scratch, extra and extra2 registers are valid.
189 ASSERT(!scratch.is(no_reg));
190 ASSERT(!extra.is(no_reg));
191 ASSERT(!extra2.is(no_reg));
192
193 // Check that the receiver isn't a smi.
194 __ JumpIfSmi(receiver, &miss, t0);
195
196 // Get the map of the receiver and compute the hash.
197 __ lw(scratch, FieldMemOperand(name, String::kHashFieldOffset));
198 __ lw(t8, FieldMemOperand(receiver, HeapObject::kMapOffset));
199 __ Addu(scratch, scratch, Operand(t8));
200 __ Xor(scratch, scratch, Operand(flags));
201 __ And(scratch,
202 scratch,
203 Operand((kPrimaryTableSize - 1) << kHeapObjectTagSize));
204
205 // Probe the primary table.
206 ProbeTable(isolate, masm, flags, kPrimary, name, scratch, extra, extra2);
207
208 // Primary miss: Compute hash for secondary probe.
209 __ Subu(scratch, scratch, Operand(name));
210 __ Addu(scratch, scratch, Operand(flags));
211 __ And(scratch,
212 scratch,
213 Operand((kSecondaryTableSize - 1) << kHeapObjectTagSize));
214
215 // Probe the secondary table.
216 ProbeTable(isolate, masm, flags, kSecondary, name, scratch, extra, extra2);
217
218 // Cache miss: Fall-through and let caller handle the miss by
219 // entering the runtime system.
220 __ bind(&miss);
ager@chromium.org5c838252010-02-19 08:53:10 +0000221}
222
223
224void StubCompiler::GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm,
225 int index,
226 Register prototype) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000227 // Load the global or builtins object from the current context.
228 __ lw(prototype, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX)));
229 // Load the global context from the global or builtins object.
230 __ lw(prototype,
231 FieldMemOperand(prototype, GlobalObject::kGlobalContextOffset));
232 // Load the function from the global context.
233 __ lw(prototype, MemOperand(prototype, Context::SlotOffset(index)));
234 // Load the initial map. The global functions all have initial maps.
235 __ lw(prototype,
236 FieldMemOperand(prototype, JSFunction::kPrototypeOrInitialMapOffset));
237 // Load the prototype from the initial map.
238 __ lw(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
ager@chromium.org5c838252010-02-19 08:53:10 +0000239}
240
241
lrn@chromium.org7516f052011-03-30 08:52:27 +0000242void StubCompiler::GenerateDirectLoadGlobalFunctionPrototype(
243 MacroAssembler* masm, int index, Register prototype, Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000244 Isolate* isolate = masm->isolate();
245 // Check we're still in the same context.
246 __ lw(prototype, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX)));
247 ASSERT(!prototype.is(at));
248 __ li(at, isolate->global());
249 __ Branch(miss, ne, prototype, Operand(at));
250 // Get the global function with the given index.
251 JSFunction* function =
252 JSFunction::cast(isolate->global_context()->get(index));
253 // Load its initial map. The global functions all have initial maps.
254 __ li(prototype, Handle<Map>(function->initial_map()));
255 // Load the prototype from the initial map.
256 __ lw(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
lrn@chromium.org7516f052011-03-30 08:52:27 +0000257}
258
259
ager@chromium.org5c838252010-02-19 08:53:10 +0000260// Load a fast property out of a holder object (src). In-object properties
261// are loaded directly otherwise the property is loaded from the properties
262// fixed array.
263void StubCompiler::GenerateFastPropertyLoad(MacroAssembler* masm,
264 Register dst, Register src,
265 JSObject* holder, int index) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000266 // Adjust for the number of properties stored in the holder.
267 index -= holder->map()->inobject_properties();
268 if (index < 0) {
269 // Get the property straight out of the holder.
270 int offset = holder->map()->instance_size() + (index * kPointerSize);
271 __ lw(dst, FieldMemOperand(src, offset));
272 } else {
273 // Calculate the offset into the properties array.
274 int offset = index * kPointerSize + FixedArray::kHeaderSize;
275 __ lw(dst, FieldMemOperand(src, JSObject::kPropertiesOffset));
276 __ lw(dst, FieldMemOperand(dst, offset));
277 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000278}
279
280
281void StubCompiler::GenerateLoadArrayLength(MacroAssembler* masm,
282 Register receiver,
283 Register scratch,
284 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000285 // Check that the receiver isn't a smi.
286 __ And(scratch, receiver, Operand(kSmiTagMask));
287 __ Branch(miss_label, eq, scratch, Operand(zero_reg));
288
289 // Check that the object is a JS array.
290 __ GetObjectType(receiver, scratch, scratch);
291 __ Branch(miss_label, ne, scratch, Operand(JS_ARRAY_TYPE));
292
293 // Load length directly from the JS array.
294 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
295 __ Ret();
296}
297
298
299// Generate code to check if an object is a string. If the object is a
300// heap object, its map's instance type is left in the scratch1 register.
301// If this is not needed, scratch1 and scratch2 may be the same register.
302static void GenerateStringCheck(MacroAssembler* masm,
303 Register receiver,
304 Register scratch1,
305 Register scratch2,
306 Label* smi,
307 Label* non_string_object) {
308 // Check that the receiver isn't a smi.
309 __ JumpIfSmi(receiver, smi, t0);
310
311 // Check that the object is a string.
312 __ lw(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset));
313 __ lbu(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
314 __ And(scratch2, scratch1, Operand(kIsNotStringMask));
315 // The cast is to resolve the overload for the argument of 0x0.
316 __ Branch(non_string_object,
317 ne,
318 scratch2,
319 Operand(static_cast<int32_t>(kStringTag)));
ager@chromium.org5c838252010-02-19 08:53:10 +0000320}
321
322
lrn@chromium.org7516f052011-03-30 08:52:27 +0000323// Generate code to load the length from a string object and return the length.
324// If the receiver object is not a string or a wrapped string object the
325// execution continues at the miss label. The register containing the
326// receiver is potentially clobbered.
327void StubCompiler::GenerateLoadStringLength(MacroAssembler* masm,
328 Register receiver,
329 Register scratch1,
330 Register scratch2,
331 Label* miss,
332 bool support_wrappers) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000333 Label check_wrapper;
334
335 // Check if the object is a string leaving the instance type in the
336 // scratch1 register.
337 GenerateStringCheck(masm, receiver, scratch1, scratch2, miss,
338 support_wrappers ? &check_wrapper : miss);
339
340 // Load length directly from the string.
341 __ lw(v0, FieldMemOperand(receiver, String::kLengthOffset));
342 __ Ret();
343
344 if (support_wrappers) {
345 // Check if the object is a JSValue wrapper.
346 __ bind(&check_wrapper);
347 __ Branch(miss, ne, scratch1, Operand(JS_VALUE_TYPE));
348
349 // Unwrap the value and check if the wrapped value is a string.
350 __ lw(scratch1, FieldMemOperand(receiver, JSValue::kValueOffset));
351 GenerateStringCheck(masm, scratch1, scratch2, scratch2, miss, miss);
352 __ lw(v0, FieldMemOperand(scratch1, String::kLengthOffset));
353 __ Ret();
354 }
lrn@chromium.org7516f052011-03-30 08:52:27 +0000355}
356
357
ager@chromium.org5c838252010-02-19 08:53:10 +0000358void StubCompiler::GenerateLoadFunctionPrototype(MacroAssembler* masm,
359 Register receiver,
360 Register scratch1,
361 Register scratch2,
362 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000363 __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
364 __ mov(v0, scratch1);
365 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +0000366}
367
368
lrn@chromium.org7516f052011-03-30 08:52:27 +0000369// Generate StoreField code, value is passed in a0 register.
ager@chromium.org5c838252010-02-19 08:53:10 +0000370// After executing generated code, the receiver_reg and name_reg
371// may be clobbered.
372void StubCompiler::GenerateStoreField(MacroAssembler* masm,
ager@chromium.org5c838252010-02-19 08:53:10 +0000373 JSObject* object,
374 int index,
375 Map* transition,
376 Register receiver_reg,
377 Register name_reg,
378 Register scratch,
379 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000380 // a0 : value.
381 Label exit;
382
383 // Check that the receiver isn't a smi.
384 __ JumpIfSmi(receiver_reg, miss_label, scratch);
385
386 // Check that the map of the receiver hasn't changed.
387 __ lw(scratch, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
388 __ Branch(miss_label, ne, scratch, Operand(Handle<Map>(object->map())));
389
390 // Perform global security token check if needed.
391 if (object->IsJSGlobalProxy()) {
392 __ CheckAccessGlobalProxy(receiver_reg, scratch, miss_label);
393 }
394
395 // Stub never generated for non-global objects that require access
396 // checks.
397 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
398
399 // Perform map transition for the receiver if necessary.
400 if ((transition != NULL) && (object->map()->unused_property_fields() == 0)) {
401 // The properties must be extended before we can store the value.
402 // We jump to a runtime call that extends the properties array.
403 __ push(receiver_reg);
404 __ li(a2, Operand(Handle<Map>(transition)));
405 __ Push(a2, a0);
406 __ TailCallExternalReference(
407 ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
408 masm->isolate()),
409 3, 1);
410 return;
411 }
412
413 if (transition != NULL) {
414 // Update the map of the object; no write barrier updating is
415 // needed because the map is never in new space.
416 __ li(t0, Operand(Handle<Map>(transition)));
417 __ sw(t0, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
418 }
419
420 // Adjust for the number of properties stored in the object. Even in the
421 // face of a transition we can use the old map here because the size of the
422 // object and the number of in-object properties is not going to change.
423 index -= object->map()->inobject_properties();
424
425 if (index < 0) {
426 // Set the property straight into the object.
427 int offset = object->map()->instance_size() + (index * kPointerSize);
428 __ sw(a0, FieldMemOperand(receiver_reg, offset));
429
430 // Skip updating write barrier if storing a smi.
431 __ JumpIfSmi(a0, &exit, scratch);
432
433 // Update the write barrier for the array address.
434 // Pass the now unused name_reg as a scratch register.
435 __ RecordWrite(receiver_reg, Operand(offset), name_reg, scratch);
436 } else {
437 // Write to the properties array.
438 int offset = index * kPointerSize + FixedArray::kHeaderSize;
439 // Get the properties array.
440 __ lw(scratch, FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
441 __ sw(a0, FieldMemOperand(scratch, offset));
442
443 // Skip updating write barrier if storing a smi.
444 __ JumpIfSmi(a0, &exit);
445
446 // Update the write barrier for the array address.
447 // Ok to clobber receiver_reg and name_reg, since we return.
448 __ RecordWrite(scratch, Operand(offset), name_reg, receiver_reg);
449 }
450
451 // Return the value (register v0).
452 __ bind(&exit);
453 __ mov(v0, a0);
454 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +0000455}
456
457
458void StubCompiler::GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000459 ASSERT(kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC);
460 Code* code = NULL;
461 if (kind == Code::LOAD_IC) {
462 code = masm->isolate()->builtins()->builtin(Builtins::kLoadIC_Miss);
463 } else {
464 code = masm->isolate()->builtins()->builtin(Builtins::kKeyedLoadIC_Miss);
465 }
466
467 Handle<Code> ic(code);
468 __ Jump(ic, RelocInfo::CODE_TARGET);
ager@chromium.org5c838252010-02-19 08:53:10 +0000469}
470
471
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000472static void GenerateCallFunction(MacroAssembler* masm,
473 Object* object,
474 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000475 Label* miss,
476 Code::ExtraICState extra_ic_state) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000477 // ----------- S t a t e -------------
478 // -- a0: receiver
479 // -- a1: function to call
480 // -----------------------------------
481 // Check that the function really is a function.
482 __ JumpIfSmi(a1, miss);
483 __ GetObjectType(a1, a3, a3);
484 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
485
486 // Patch the receiver on the stack with the global proxy if
487 // necessary.
488 if (object->IsGlobalObject()) {
489 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
490 __ sw(a3, MemOperand(sp, arguments.immediate() * kPointerSize));
491 }
492
493 // Invoke the function.
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000494 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state)
495 ? CALL_AS_FUNCTION
496 : CALL_AS_METHOD;
497 __ InvokeFunction(a1, arguments, JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000498}
499
500
501static void PushInterceptorArguments(MacroAssembler* masm,
502 Register receiver,
503 Register holder,
504 Register name,
505 JSObject* holder_obj) {
506 __ push(name);
507 InterceptorInfo* interceptor = holder_obj->GetNamedInterceptor();
508 ASSERT(!masm->isolate()->heap()->InNewSpace(interceptor));
509 Register scratch = name;
510 __ li(scratch, Operand(Handle<Object>(interceptor)));
511 __ Push(scratch, receiver, holder);
512 __ lw(scratch, FieldMemOperand(scratch, InterceptorInfo::kDataOffset));
513 __ push(scratch);
514}
515
516
517static void CompileCallLoadPropertyWithInterceptor(MacroAssembler* masm,
518 Register receiver,
519 Register holder,
520 Register name,
521 JSObject* holder_obj) {
522 PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
523
524 ExternalReference ref =
525 ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorOnly),
526 masm->isolate());
527 __ li(a0, Operand(5));
528 __ li(a1, Operand(ref));
529
530 CEntryStub stub(1);
531 __ CallStub(&stub);
532}
533
534
535static const int kFastApiCallArguments = 3;
536
537
538// Reserves space for the extra arguments to FastHandleApiCall in the
539// caller's frame.
540//
541// These arguments are set by CheckPrototypes and GenerateFastApiDirectCall.
542static void ReserveSpaceForFastApiCall(MacroAssembler* masm,
543 Register scratch) {
544 ASSERT(Smi::FromInt(0) == 0);
545 for (int i = 0; i < kFastApiCallArguments; i++) {
546 __ push(zero_reg);
547 }
548}
549
550
551// Undoes the effects of ReserveSpaceForFastApiCall.
552static void FreeSpaceForFastApiCall(MacroAssembler* masm) {
553 __ Drop(kFastApiCallArguments);
554}
555
556
557static MaybeObject* GenerateFastApiDirectCall(MacroAssembler* masm,
558 const CallOptimization& optimization,
559 int argc) {
560 // ----------- S t a t e -------------
561 // -- sp[0] : holder (set by CheckPrototypes)
562 // -- sp[4] : callee js function
563 // -- sp[8] : call data
564 // -- sp[12] : last js argument
565 // -- ...
566 // -- sp[(argc + 3) * 4] : first js argument
567 // -- sp[(argc + 4) * 4] : receiver
568 // -----------------------------------
569 // Get the function and setup the context.
570 JSFunction* function = optimization.constant_function();
571 __ li(t1, Operand(Handle<JSFunction>(function)));
572 __ lw(cp, FieldMemOperand(t1, JSFunction::kContextOffset));
573
574 // Pass the additional arguments FastHandleApiCall expects.
575 Object* call_data = optimization.api_call_info()->data();
576 Handle<CallHandlerInfo> api_call_info_handle(optimization.api_call_info());
577 if (masm->isolate()->heap()->InNewSpace(call_data)) {
578 __ li(a0, api_call_info_handle);
579 __ lw(t2, FieldMemOperand(a0, CallHandlerInfo::kDataOffset));
580 } else {
581 __ li(t2, Operand(Handle<Object>(call_data)));
582 }
583
584 // Store js function and call data.
585 __ sw(t1, MemOperand(sp, 1 * kPointerSize));
586 __ sw(t2, MemOperand(sp, 2 * kPointerSize));
587
588 // a2 points to call data as expected by Arguments
589 // (refer to layout above).
590 __ Addu(a2, sp, Operand(2 * kPointerSize));
591
592 Object* callback = optimization.api_call_info()->callback();
593 Address api_function_address = v8::ToCData<Address>(callback);
594 ApiFunction fun(api_function_address);
595
596 const int kApiStackSpace = 4;
597
598 __ EnterExitFrame(false, kApiStackSpace);
599
600 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
601 // struct from the function (which is currently the case). This means we pass
602 // the first argument in a1 instead of a0. TryCallApiFunctionAndReturn
603 // will handle setting up a0.
604
605 // a1 = v8::Arguments&
606 // Arguments is built at sp + 1 (sp is a reserved spot for ra).
607 __ Addu(a1, sp, kPointerSize);
608
609 // v8::Arguments::implicit_args = data
610 __ sw(a2, MemOperand(a1, 0 * kPointerSize));
611 // v8::Arguments::values = last argument
612 __ Addu(t0, a2, Operand(argc * kPointerSize));
613 __ sw(t0, MemOperand(a1, 1 * kPointerSize));
614 // v8::Arguments::length_ = argc
615 __ li(t0, Operand(argc));
616 __ sw(t0, MemOperand(a1, 2 * kPointerSize));
617 // v8::Arguments::is_construct_call = 0
618 __ sw(zero_reg, MemOperand(a1, 3 * kPointerSize));
619
620 // Emitting a stub call may try to allocate (if the code is not
621 // already generated). Do not allow the assembler to perform a
622 // garbage collection but instead return the allocation failure
623 // object.
624 const int kStackUnwindSpace = argc + kFastApiCallArguments + 1;
625 ExternalReference ref =
626 ExternalReference(&fun,
627 ExternalReference::DIRECT_API_CALL,
628 masm->isolate());
629 return masm->TryCallApiFunctionAndReturn(ref, kStackUnwindSpace);
630}
631
lrn@chromium.org7516f052011-03-30 08:52:27 +0000632class CallInterceptorCompiler BASE_EMBEDDED {
633 public:
634 CallInterceptorCompiler(StubCompiler* stub_compiler,
635 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000636 Register name,
637 Code::ExtraICState extra_ic_state)
lrn@chromium.org7516f052011-03-30 08:52:27 +0000638 : stub_compiler_(stub_compiler),
639 arguments_(arguments),
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000640 name_(name),
641 extra_ic_state_(extra_ic_state) {}
lrn@chromium.org7516f052011-03-30 08:52:27 +0000642
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000643 MaybeObject* Compile(MacroAssembler* masm,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000644 JSObject* object,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000645 JSObject* holder,
646 String* name,
647 LookupResult* lookup,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000648 Register receiver,
649 Register scratch1,
650 Register scratch2,
651 Register scratch3,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000652 Label* miss) {
653 ASSERT(holder->HasNamedInterceptor());
654 ASSERT(!holder->GetNamedInterceptor()->getter()->IsUndefined());
655
656 // Check that the receiver isn't a smi.
657 __ JumpIfSmi(receiver, miss);
658
659 CallOptimization optimization(lookup);
660
661 if (optimization.is_constant_call()) {
662 return CompileCacheable(masm,
663 object,
664 receiver,
665 scratch1,
666 scratch2,
667 scratch3,
668 holder,
669 lookup,
670 name,
671 optimization,
672 miss);
673 } else {
674 CompileRegular(masm,
675 object,
676 receiver,
677 scratch1,
678 scratch2,
679 scratch3,
680 name,
681 holder,
682 miss);
683 return masm->isolate()->heap()->undefined_value();
684 }
685 }
686
687 private:
688 MaybeObject* CompileCacheable(MacroAssembler* masm,
689 JSObject* object,
690 Register receiver,
691 Register scratch1,
692 Register scratch2,
693 Register scratch3,
694 JSObject* interceptor_holder,
695 LookupResult* lookup,
696 String* name,
697 const CallOptimization& optimization,
698 Label* miss_label) {
699 ASSERT(optimization.is_constant_call());
700 ASSERT(!lookup->holder()->IsGlobalObject());
701
702 Counters* counters = masm->isolate()->counters();
703
704 int depth1 = kInvalidProtoDepth;
705 int depth2 = kInvalidProtoDepth;
706 bool can_do_fast_api_call = false;
707 if (optimization.is_simple_api_call() &&
708 !lookup->holder()->IsGlobalObject()) {
709 depth1 =
710 optimization.GetPrototypeDepthOfExpectedType(object,
711 interceptor_holder);
712 if (depth1 == kInvalidProtoDepth) {
713 depth2 =
714 optimization.GetPrototypeDepthOfExpectedType(interceptor_holder,
715 lookup->holder());
716 }
717 can_do_fast_api_call = (depth1 != kInvalidProtoDepth) ||
718 (depth2 != kInvalidProtoDepth);
719 }
720
721 __ IncrementCounter(counters->call_const_interceptor(), 1,
722 scratch1, scratch2);
723
724 if (can_do_fast_api_call) {
725 __ IncrementCounter(counters->call_const_interceptor_fast_api(), 1,
726 scratch1, scratch2);
727 ReserveSpaceForFastApiCall(masm, scratch1);
728 }
729
730 // Check that the maps from receiver to interceptor's holder
731 // haven't changed and thus we can invoke interceptor.
732 Label miss_cleanup;
733 Label* miss = can_do_fast_api_call ? &miss_cleanup : miss_label;
734 Register holder =
735 stub_compiler_->CheckPrototypes(object, receiver,
736 interceptor_holder, scratch1,
737 scratch2, scratch3, name, depth1, miss);
738
739 // Invoke an interceptor and if it provides a value,
740 // branch to |regular_invoke|.
741 Label regular_invoke;
742 LoadWithInterceptor(masm, receiver, holder, interceptor_holder, scratch2,
743 &regular_invoke);
744
745 // Interceptor returned nothing for this property. Try to use cached
746 // constant function.
747
748 // Check that the maps from interceptor's holder to constant function's
749 // holder haven't changed and thus we can use cached constant function.
750 if (interceptor_holder != lookup->holder()) {
751 stub_compiler_->CheckPrototypes(interceptor_holder, receiver,
752 lookup->holder(), scratch1,
753 scratch2, scratch3, name, depth2, miss);
754 } else {
755 // CheckPrototypes has a side effect of fetching a 'holder'
756 // for API (object which is instanceof for the signature). It's
757 // safe to omit it here, as if present, it should be fetched
758 // by the previous CheckPrototypes.
759 ASSERT(depth2 == kInvalidProtoDepth);
760 }
761
762 // Invoke function.
763 if (can_do_fast_api_call) {
764 MaybeObject* result = GenerateFastApiDirectCall(masm,
765 optimization,
766 arguments_.immediate());
767 if (result->IsFailure()) return result;
768 } else {
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000769 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state_)
770 ? CALL_AS_FUNCTION
771 : CALL_AS_METHOD;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000772 __ InvokeFunction(optimization.constant_function(), arguments_,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000773 JUMP_FUNCTION, call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000774 }
775
776 // Deferred code for fast API call case---clean preallocated space.
777 if (can_do_fast_api_call) {
778 __ bind(&miss_cleanup);
779 FreeSpaceForFastApiCall(masm);
780 __ Branch(miss_label);
781 }
782
783 // Invoke a regular function.
784 __ bind(&regular_invoke);
785 if (can_do_fast_api_call) {
786 FreeSpaceForFastApiCall(masm);
787 }
788
789 return masm->isolate()->heap()->undefined_value();
lrn@chromium.org7516f052011-03-30 08:52:27 +0000790 }
791
792 void CompileRegular(MacroAssembler* masm,
793 JSObject* object,
794 Register receiver,
795 Register scratch1,
796 Register scratch2,
797 Register scratch3,
798 String* name,
799 JSObject* interceptor_holder,
800 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000801 Register holder =
802 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
803 scratch1, scratch2, scratch3, name,
804 miss_label);
805
806 // Call a runtime function to load the interceptor property.
807 __ EnterInternalFrame();
808 // Save the name_ register across the call.
809 __ push(name_);
810
811 PushInterceptorArguments(masm,
812 receiver,
813 holder,
814 name_,
815 interceptor_holder);
816
817 __ CallExternalReference(
818 ExternalReference(
819 IC_Utility(IC::kLoadPropertyWithInterceptorForCall),
820 masm->isolate()),
821 5);
822
823 // Restore the name_ register.
824 __ pop(name_);
825 __ LeaveInternalFrame();
lrn@chromium.org7516f052011-03-30 08:52:27 +0000826 }
827
828 void LoadWithInterceptor(MacroAssembler* masm,
829 Register receiver,
830 Register holder,
831 JSObject* holder_obj,
832 Register scratch,
833 Label* interceptor_succeeded) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000834 __ EnterInternalFrame();
835
836 __ Push(holder, name_);
837
838 CompileCallLoadPropertyWithInterceptor(masm,
839 receiver,
840 holder,
841 name_,
842 holder_obj);
843
844 __ pop(name_); // Restore the name.
845 __ pop(receiver); // Restore the holder.
846 __ LeaveInternalFrame();
847
848 // If interceptor returns no-result sentinel, call the constant function.
849 __ LoadRoot(scratch, Heap::kNoInterceptorResultSentinelRootIndex);
850 __ Branch(interceptor_succeeded, ne, v0, Operand(scratch));
lrn@chromium.org7516f052011-03-30 08:52:27 +0000851 }
852
853 StubCompiler* stub_compiler_;
854 const ParameterCount& arguments_;
855 Register name_;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000856 Code::ExtraICState extra_ic_state_;
lrn@chromium.org7516f052011-03-30 08:52:27 +0000857};
858
859
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000860
861// Generate code to check that a global property cell is empty. Create
862// the property cell at compilation time if no cell exists for the
863// property.
864MUST_USE_RESULT static MaybeObject* GenerateCheckPropertyCell(
865 MacroAssembler* masm,
866 GlobalObject* global,
867 String* name,
868 Register scratch,
869 Label* miss) {
870 Object* probe;
871 { MaybeObject* maybe_probe = global->EnsurePropertyCell(name);
872 if (!maybe_probe->ToObject(&probe)) return maybe_probe;
873 }
874 JSGlobalPropertyCell* cell = JSGlobalPropertyCell::cast(probe);
875 ASSERT(cell->value()->IsTheHole());
876 __ li(scratch, Operand(Handle<Object>(cell)));
877 __ lw(scratch,
878 FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset));
879 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
880 __ Branch(miss, ne, scratch, Operand(at));
881 return cell;
882}
883
884
885// Calls GenerateCheckPropertyCell for each global object in the prototype chain
886// from object to (but not including) holder.
887MUST_USE_RESULT static MaybeObject* GenerateCheckPropertyCells(
888 MacroAssembler* masm,
889 JSObject* object,
890 JSObject* holder,
891 String* name,
892 Register scratch,
893 Label* miss) {
894 JSObject* current = object;
895 while (current != holder) {
896 if (current->IsGlobalObject()) {
897 // Returns a cell or a failure.
898 MaybeObject* result = GenerateCheckPropertyCell(
899 masm,
900 GlobalObject::cast(current),
901 name,
902 scratch,
903 miss);
904 if (result->IsFailure()) return result;
905 }
906 ASSERT(current->IsJSObject());
907 current = JSObject::cast(current->GetPrototype());
908 }
909 return NULL;
910}
911
912
913// Convert and store int passed in register ival to IEEE 754 single precision
914// floating point value at memory location (dst + 4 * wordoffset)
915// If FPU is available use it for conversion.
916static void StoreIntAsFloat(MacroAssembler* masm,
917 Register dst,
918 Register wordoffset,
919 Register ival,
920 Register fval,
921 Register scratch1,
922 Register scratch2) {
923 if (CpuFeatures::IsSupported(FPU)) {
924 CpuFeatures::Scope scope(FPU);
925 __ mtc1(ival, f0);
926 __ cvt_s_w(f0, f0);
927 __ sll(scratch1, wordoffset, 2);
928 __ addu(scratch1, dst, scratch1);
929 __ swc1(f0, MemOperand(scratch1, 0));
930 } else {
931 // FPU is not available, do manual conversions.
932
933 Label not_special, done;
934 // Move sign bit from source to destination. This works because the sign
935 // bit in the exponent word of the double has the same position and polarity
936 // as the 2's complement sign bit in a Smi.
937 ASSERT(kBinary32SignMask == 0x80000000u);
938
939 __ And(fval, ival, Operand(kBinary32SignMask));
940 // Negate value if it is negative.
941 __ subu(scratch1, zero_reg, ival);
942 __ movn(ival, scratch1, fval);
943
944 // We have -1, 0 or 1, which we treat specially. Register ival contains
945 // absolute value: it is either equal to 1 (special case of -1 and 1),
946 // greater than 1 (not a special case) or less than 1 (special case of 0).
947 __ Branch(&not_special, gt, ival, Operand(1));
948
949 // For 1 or -1 we need to or in the 0 exponent (biased).
950 static const uint32_t exponent_word_for_1 =
951 kBinary32ExponentBias << kBinary32ExponentShift;
952
953 __ Xor(scratch1, ival, Operand(1));
954 __ li(scratch2, exponent_word_for_1);
955 __ or_(scratch2, fval, scratch2);
956 __ movz(fval, scratch2, scratch1); // Only if ival is equal to 1.
957 __ Branch(&done);
958
959 __ bind(&not_special);
960 // Count leading zeros.
961 // Gets the wrong answer for 0, but we already checked for that case above.
962 Register zeros = scratch2;
963 __ clz(zeros, ival);
964
965 // Compute exponent and or it into the exponent register.
966 __ li(scratch1, (kBitsPerInt - 1) + kBinary32ExponentBias);
967 __ subu(scratch1, scratch1, zeros);
968
969 __ sll(scratch1, scratch1, kBinary32ExponentShift);
970 __ or_(fval, fval, scratch1);
971
972 // Shift up the source chopping the top bit off.
973 __ Addu(zeros, zeros, Operand(1));
974 // This wouldn't work for 1 and -1 as the shift would be 32 which means 0.
975 __ sllv(ival, ival, zeros);
976 // And the top (top 20 bits).
977 __ srl(scratch1, ival, kBitsPerInt - kBinary32MantissaBits);
978 __ or_(fval, fval, scratch1);
979
980 __ bind(&done);
981
982 __ sll(scratch1, wordoffset, 2);
983 __ addu(scratch1, dst, scratch1);
984 __ sw(fval, MemOperand(scratch1, 0));
985 }
986}
987
988
989// Convert unsigned integer with specified number of leading zeroes in binary
990// representation to IEEE 754 double.
991// Integer to convert is passed in register hiword.
992// Resulting double is returned in registers hiword:loword.
993// This functions does not work correctly for 0.
994static void GenerateUInt2Double(MacroAssembler* masm,
995 Register hiword,
996 Register loword,
997 Register scratch,
998 int leading_zeroes) {
999 const int meaningful_bits = kBitsPerInt - leading_zeroes - 1;
1000 const int biased_exponent = HeapNumber::kExponentBias + meaningful_bits;
1001
1002 const int mantissa_shift_for_hi_word =
1003 meaningful_bits - HeapNumber::kMantissaBitsInTopWord;
1004
1005 const int mantissa_shift_for_lo_word =
1006 kBitsPerInt - mantissa_shift_for_hi_word;
1007
1008 __ li(scratch, biased_exponent << HeapNumber::kExponentShift);
1009 if (mantissa_shift_for_hi_word > 0) {
1010 __ sll(loword, hiword, mantissa_shift_for_lo_word);
1011 __ srl(hiword, hiword, mantissa_shift_for_hi_word);
1012 __ or_(hiword, scratch, hiword);
1013 } else {
1014 __ mov(loword, zero_reg);
1015 __ sll(hiword, hiword, mantissa_shift_for_hi_word);
1016 __ or_(hiword, scratch, hiword);
1017 }
1018
1019 // If least significant bit of biased exponent was not 1 it was corrupted
1020 // by most significant bit of mantissa so we should fix that.
1021 if (!(biased_exponent & 1)) {
1022 __ li(scratch, 1 << HeapNumber::kExponentShift);
1023 __ nor(scratch, scratch, scratch);
1024 __ and_(hiword, hiword, scratch);
1025 }
1026}
1027
1028
ager@chromium.org5c838252010-02-19 08:53:10 +00001029#undef __
1030#define __ ACCESS_MASM(masm())
1031
1032
lrn@chromium.org7516f052011-03-30 08:52:27 +00001033Register StubCompiler::CheckPrototypes(JSObject* object,
1034 Register object_reg,
1035 JSObject* holder,
1036 Register holder_reg,
1037 Register scratch1,
1038 Register scratch2,
1039 String* name,
1040 int save_at_depth,
1041 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001042 // Make sure there's no overlap between holder and object registers.
1043 ASSERT(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
1044 ASSERT(!scratch2.is(object_reg) && !scratch2.is(holder_reg)
1045 && !scratch2.is(scratch1));
1046
1047 // Keep track of the current object in register reg.
1048 Register reg = object_reg;
1049 int depth = 0;
1050
1051 if (save_at_depth == depth) {
1052 __ sw(reg, MemOperand(sp));
1053 }
1054
1055 // Check the maps in the prototype chain.
1056 // Traverse the prototype chain from the object and do map checks.
1057 JSObject* current = object;
1058 while (current != holder) {
1059 depth++;
1060
1061 // Only global objects and objects that do not require access
1062 // checks are allowed in stubs.
1063 ASSERT(current->IsJSGlobalProxy() || !current->IsAccessCheckNeeded());
1064
1065 ASSERT(current->GetPrototype()->IsJSObject());
1066 JSObject* prototype = JSObject::cast(current->GetPrototype());
1067 if (!current->HasFastProperties() &&
1068 !current->IsJSGlobalObject() &&
1069 !current->IsJSGlobalProxy()) {
1070 if (!name->IsSymbol()) {
1071 MaybeObject* maybe_lookup_result = heap()->LookupSymbol(name);
1072 Object* lookup_result = NULL; // Initialization to please compiler.
1073 if (!maybe_lookup_result->ToObject(&lookup_result)) {
1074 set_failure(Failure::cast(maybe_lookup_result));
1075 return reg;
1076 }
1077 name = String::cast(lookup_result);
1078 }
1079 ASSERT(current->property_dictionary()->FindEntry(name) ==
1080 StringDictionary::kNotFound);
1081
1082 MaybeObject* negative_lookup = GenerateDictionaryNegativeLookup(masm(),
1083 miss,
1084 reg,
1085 name,
1086 scratch1,
1087 scratch2);
1088 if (negative_lookup->IsFailure()) {
1089 set_failure(Failure::cast(negative_lookup));
1090 return reg;
1091 }
1092
1093 __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
1094 reg = holder_reg; // From now the object is in holder_reg.
1095 __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
1096 } else if (heap()->InNewSpace(prototype)) {
1097 // Get the map of the current object.
1098 __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
1099
1100 // Branch on the result of the map check.
1101 __ Branch(miss, ne, scratch1, Operand(Handle<Map>(current->map())));
1102
1103 // Check access rights to the global object. This has to happen
1104 // after the map check so that we know that the object is
1105 // actually a global object.
1106 if (current->IsJSGlobalProxy()) {
1107 __ CheckAccessGlobalProxy(reg, scratch1, miss);
1108 // Restore scratch register to be the map of the object. In the
1109 // new space case below, we load the prototype from the map in
1110 // the scratch register.
1111 __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
1112 }
1113
1114 reg = holder_reg; // From now the object is in holder_reg.
1115 // The prototype is in new space; we cannot store a reference
1116 // to it in the code. Load it from the map.
1117 __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
1118 } else {
1119 // Check the map of the current object.
1120 __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
1121 // Branch on the result of the map check.
1122 __ Branch(miss, ne, scratch1, Operand(Handle<Map>(current->map())));
1123 // Check access rights to the global object. This has to happen
1124 // after the map check so that we know that the object is
1125 // actually a global object.
1126 if (current->IsJSGlobalProxy()) {
1127 __ CheckAccessGlobalProxy(reg, scratch1, miss);
1128 }
1129 // The prototype is in old space; load it directly.
1130 reg = holder_reg; // From now the object is in holder_reg.
1131 __ li(reg, Operand(Handle<JSObject>(prototype)));
1132 }
1133
1134 if (save_at_depth == depth) {
1135 __ sw(reg, MemOperand(sp));
1136 }
1137
1138 // Go to the next object in the prototype chain.
1139 current = prototype;
1140 }
1141
1142 // Check the holder map.
1143 __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
1144 __ Branch(miss, ne, scratch1, Operand(Handle<Map>(current->map())));
1145
1146 // Log the check depth.
1147 LOG(masm()->isolate(), IntEvent("check-maps-depth", depth + 1));
1148 // Perform security check for access to the global object.
1149 ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded());
1150 if (holder->IsJSGlobalProxy()) {
1151 __ CheckAccessGlobalProxy(reg, scratch1, miss);
1152 };
1153
1154 // If we've skipped any global objects, it's not enough to verify
1155 // that their maps haven't changed. We also need to check that the
1156 // property cell for the property is still empty.
1157
1158 MaybeObject* result = GenerateCheckPropertyCells(masm(),
1159 object,
1160 holder,
1161 name,
1162 scratch1,
1163 miss);
1164 if (result->IsFailure()) set_failure(Failure::cast(result));
1165
1166 // Return the register containing the holder.
1167 return reg;
lrn@chromium.org7516f052011-03-30 08:52:27 +00001168}
1169
1170
ager@chromium.org5c838252010-02-19 08:53:10 +00001171void StubCompiler::GenerateLoadField(JSObject* object,
1172 JSObject* holder,
1173 Register receiver,
1174 Register scratch1,
1175 Register scratch2,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001176 Register scratch3,
ager@chromium.org5c838252010-02-19 08:53:10 +00001177 int index,
1178 String* name,
1179 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001180 // Check that the receiver isn't a smi.
1181 __ And(scratch1, receiver, Operand(kSmiTagMask));
1182 __ Branch(miss, eq, scratch1, Operand(zero_reg));
1183
1184 // Check that the maps haven't changed.
1185 Register reg =
1186 CheckPrototypes(object, receiver, holder, scratch1, scratch2, scratch3,
1187 name, miss);
1188 GenerateFastPropertyLoad(masm(), v0, reg, holder, index);
1189 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +00001190}
1191
1192
1193void StubCompiler::GenerateLoadConstant(JSObject* object,
1194 JSObject* holder,
1195 Register receiver,
1196 Register scratch1,
1197 Register scratch2,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001198 Register scratch3,
ager@chromium.org5c838252010-02-19 08:53:10 +00001199 Object* value,
1200 String* name,
1201 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001202 // Check that the receiver isn't a smi.
1203 __ JumpIfSmi(receiver, miss, scratch1);
1204
1205 // Check that the maps haven't changed.
1206 Register reg =
1207 CheckPrototypes(object, receiver, holder,
1208 scratch1, scratch2, scratch3, name, miss);
1209
1210 // Return the constant value.
1211 __ li(v0, Operand(Handle<Object>(value)));
1212 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +00001213}
1214
1215
lrn@chromium.org7516f052011-03-30 08:52:27 +00001216MaybeObject* StubCompiler::GenerateLoadCallback(JSObject* object,
1217 JSObject* holder,
1218 Register receiver,
1219 Register name_reg,
1220 Register scratch1,
1221 Register scratch2,
1222 Register scratch3,
1223 AccessorInfo* callback,
1224 String* name,
1225 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001226 // Check that the receiver isn't a smi.
1227 __ JumpIfSmi(receiver, miss, scratch1);
1228
1229 // Check that the maps haven't changed.
1230 Register reg =
1231 CheckPrototypes(object, receiver, holder, scratch1, scratch2, scratch3,
1232 name, miss);
1233
1234 // Build AccessorInfo::args_ list on the stack and push property name below
1235 // the exit frame to make GC aware of them and store pointers to them.
1236 __ push(receiver);
1237 __ mov(scratch2, sp); // scratch2 = AccessorInfo::args_
1238 Handle<AccessorInfo> callback_handle(callback);
1239 if (heap()->InNewSpace(callback_handle->data())) {
1240 __ li(scratch3, callback_handle);
1241 __ lw(scratch3, FieldMemOperand(scratch3, AccessorInfo::kDataOffset));
1242 } else {
1243 __ li(scratch3, Handle<Object>(callback_handle->data()));
1244 }
1245 __ Push(reg, scratch3, name_reg);
1246 __ mov(a2, scratch2); // Saved in case scratch2 == a1.
1247 __ mov(a1, sp); // a1 (first argument - see note below) = Handle<String>
1248
1249 Address getter_address = v8::ToCData<Address>(callback->getter());
1250 ApiFunction fun(getter_address);
1251
1252 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
1253 // struct from the function (which is currently the case). This means we pass
1254 // the arguments in a1-a2 instead of a0-a1. TryCallApiFunctionAndReturn
1255 // will handle setting up a0.
1256
1257 const int kApiStackSpace = 1;
1258
1259 __ EnterExitFrame(false, kApiStackSpace);
1260 // Create AccessorInfo instance on the stack above the exit frame with
1261 // scratch2 (internal::Object **args_) as the data.
1262 __ sw(a2, MemOperand(sp, kPointerSize));
1263 // a2 (second argument - see note above) = AccessorInfo&
1264 __ Addu(a2, sp, kPointerSize);
1265
1266 // Emitting a stub call may try to allocate (if the code is not
1267 // already generated). Do not allow the assembler to perform a
1268 // garbage collection but instead return the allocation failure
1269 // object.
1270 ExternalReference ref =
1271 ExternalReference(&fun,
1272 ExternalReference::DIRECT_GETTER_CALL,
1273 masm()->isolate());
1274 // 4 args - will be freed later by LeaveExitFrame.
1275 return masm()->TryCallApiFunctionAndReturn(ref, 4);
ager@chromium.org5c838252010-02-19 08:53:10 +00001276}
1277
1278
1279void StubCompiler::GenerateLoadInterceptor(JSObject* object,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001280 JSObject* interceptor_holder,
ager@chromium.org5c838252010-02-19 08:53:10 +00001281 LookupResult* lookup,
1282 Register receiver,
1283 Register name_reg,
1284 Register scratch1,
1285 Register scratch2,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001286 Register scratch3,
ager@chromium.org5c838252010-02-19 08:53:10 +00001287 String* name,
1288 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001289 ASSERT(interceptor_holder->HasNamedInterceptor());
1290 ASSERT(!interceptor_holder->GetNamedInterceptor()->getter()->IsUndefined());
1291
1292 // Check that the receiver isn't a smi.
1293 __ JumpIfSmi(receiver, miss);
1294
1295 // So far the most popular follow ups for interceptor loads are FIELD
1296 // and CALLBACKS, so inline only them, other cases may be added
1297 // later.
1298 bool compile_followup_inline = false;
1299 if (lookup->IsProperty() && lookup->IsCacheable()) {
1300 if (lookup->type() == FIELD) {
1301 compile_followup_inline = true;
1302 } else if (lookup->type() == CALLBACKS &&
1303 lookup->GetCallbackObject()->IsAccessorInfo() &&
1304 AccessorInfo::cast(lookup->GetCallbackObject())->getter() != NULL) {
1305 compile_followup_inline = true;
1306 }
1307 }
1308
1309 if (compile_followup_inline) {
1310 // Compile the interceptor call, followed by inline code to load the
1311 // property from further up the prototype chain if the call fails.
1312 // Check that the maps haven't changed.
1313 Register holder_reg = CheckPrototypes(object, receiver, interceptor_holder,
1314 scratch1, scratch2, scratch3,
1315 name, miss);
1316 ASSERT(holder_reg.is(receiver) || holder_reg.is(scratch1));
1317
1318 // Save necessary data before invoking an interceptor.
1319 // Requires a frame to make GC aware of pushed pointers.
1320 __ EnterInternalFrame();
1321
1322 if (lookup->type() == CALLBACKS && !receiver.is(holder_reg)) {
1323 // CALLBACKS case needs a receiver to be passed into C++ callback.
1324 __ Push(receiver, holder_reg, name_reg);
1325 } else {
1326 __ Push(holder_reg, name_reg);
1327 }
1328
1329 // Invoke an interceptor. Note: map checks from receiver to
1330 // interceptor's holder has been compiled before (see a caller
1331 // of this method).
1332 CompileCallLoadPropertyWithInterceptor(masm(),
1333 receiver,
1334 holder_reg,
1335 name_reg,
1336 interceptor_holder);
1337
1338 // Check if interceptor provided a value for property. If it's
1339 // the case, return immediately.
1340 Label interceptor_failed;
1341 __ LoadRoot(scratch1, Heap::kNoInterceptorResultSentinelRootIndex);
1342 __ Branch(&interceptor_failed, eq, v0, Operand(scratch1));
1343 __ LeaveInternalFrame();
1344 __ Ret();
1345
1346 __ bind(&interceptor_failed);
1347 __ pop(name_reg);
1348 __ pop(holder_reg);
1349 if (lookup->type() == CALLBACKS && !receiver.is(holder_reg)) {
1350 __ pop(receiver);
1351 }
1352
1353 __ LeaveInternalFrame();
1354
1355 // Check that the maps from interceptor's holder to lookup's holder
1356 // haven't changed. And load lookup's holder into |holder| register.
1357 if (interceptor_holder != lookup->holder()) {
1358 holder_reg = CheckPrototypes(interceptor_holder,
1359 holder_reg,
1360 lookup->holder(),
1361 scratch1,
1362 scratch2,
1363 scratch3,
1364 name,
1365 miss);
1366 }
1367
1368 if (lookup->type() == FIELD) {
1369 // We found FIELD property in prototype chain of interceptor's holder.
1370 // Retrieve a field from field's holder.
1371 GenerateFastPropertyLoad(masm(), v0, holder_reg,
1372 lookup->holder(), lookup->GetFieldIndex());
1373 __ Ret();
1374 } else {
1375 // We found CALLBACKS property in prototype chain of interceptor's
1376 // holder.
1377 ASSERT(lookup->type() == CALLBACKS);
1378 ASSERT(lookup->GetCallbackObject()->IsAccessorInfo());
1379 AccessorInfo* callback = AccessorInfo::cast(lookup->GetCallbackObject());
1380 ASSERT(callback != NULL);
1381 ASSERT(callback->getter() != NULL);
1382
1383 // Tail call to runtime.
1384 // Important invariant in CALLBACKS case: the code above must be
1385 // structured to never clobber |receiver| register.
1386 __ li(scratch2, Handle<AccessorInfo>(callback));
1387 // holder_reg is either receiver or scratch1.
1388 if (!receiver.is(holder_reg)) {
1389 ASSERT(scratch1.is(holder_reg));
1390 __ Push(receiver, holder_reg);
1391 __ lw(scratch3,
1392 FieldMemOperand(scratch2, AccessorInfo::kDataOffset));
1393 __ Push(scratch3, scratch2, name_reg);
1394 } else {
1395 __ push(receiver);
1396 __ lw(scratch3,
1397 FieldMemOperand(scratch2, AccessorInfo::kDataOffset));
1398 __ Push(holder_reg, scratch3, scratch2, name_reg);
1399 }
1400
1401 ExternalReference ref =
1402 ExternalReference(IC_Utility(IC::kLoadCallbackProperty),
1403 masm()->isolate());
1404 __ TailCallExternalReference(ref, 5, 1);
1405 }
1406 } else { // !compile_followup_inline
1407 // Call the runtime system to load the interceptor.
1408 // Check that the maps haven't changed.
1409 Register holder_reg = CheckPrototypes(object, receiver, interceptor_holder,
1410 scratch1, scratch2, scratch3,
1411 name, miss);
1412 PushInterceptorArguments(masm(), receiver, holder_reg,
1413 name_reg, interceptor_holder);
1414
1415 ExternalReference ref = ExternalReference(
1416 IC_Utility(IC::kLoadPropertyWithInterceptorForLoad), masm()->isolate());
1417 __ TailCallExternalReference(ref, 5, 1);
1418 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001419}
1420
1421
lrn@chromium.org7516f052011-03-30 08:52:27 +00001422void CallStubCompiler::GenerateNameCheck(String* name, Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001423 if (kind_ == Code::KEYED_CALL_IC) {
1424 __ Branch(miss, ne, a2, Operand(Handle<String>(name)));
1425 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001426}
1427
1428
lrn@chromium.org7516f052011-03-30 08:52:27 +00001429void CallStubCompiler::GenerateGlobalReceiverCheck(JSObject* object,
1430 JSObject* holder,
1431 String* name,
1432 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001433 ASSERT(holder->IsGlobalObject());
1434
1435 // Get the number of arguments.
1436 const int argc = arguments().immediate();
1437
1438 // Get the receiver from the stack.
1439 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1440
1441 // If the object is the holder then we know that it's a global
1442 // object which can only happen for contextual calls. In this case,
1443 // the receiver cannot be a smi.
1444 if (object != holder) {
1445 __ JumpIfSmi(a0, miss);
1446 }
1447
1448 // Check that the maps haven't changed.
1449 CheckPrototypes(object, a0, holder, a3, a1, t0, name, miss);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001450}
1451
1452
lrn@chromium.org7516f052011-03-30 08:52:27 +00001453void CallStubCompiler::GenerateLoadFunctionFromCell(JSGlobalPropertyCell* cell,
1454 JSFunction* function,
1455 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001456 // Get the value from the cell.
1457 __ li(a3, Operand(Handle<JSGlobalPropertyCell>(cell)));
1458 __ lw(a1, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
1459
1460 // Check that the cell contains the same function.
1461 if (heap()->InNewSpace(function)) {
1462 // We can't embed a pointer to a function in new space so we have
1463 // to verify that the shared function info is unchanged. This has
1464 // the nice side effect that multiple closures based on the same
1465 // function can all use this call IC. Before we load through the
1466 // function, we have to verify that it still is a function.
1467 __ JumpIfSmi(a1, miss);
1468 __ GetObjectType(a1, a3, a3);
1469 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
1470
1471 // Check the shared function info. Make sure it hasn't changed.
1472 __ li(a3, Handle<SharedFunctionInfo>(function->shared()));
1473 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
1474 __ Branch(miss, ne, t0, Operand(a3));
1475 } else {
1476 __ Branch(miss, ne, a1, Operand(Handle<JSFunction>(function)));
1477 }
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001478}
1479
1480
lrn@chromium.org7516f052011-03-30 08:52:27 +00001481MaybeObject* CallStubCompiler::GenerateMissBranch() {
danno@chromium.org40cb8782011-05-25 07:58:50 +00001482 MaybeObject* maybe_obj =
1483 isolate()->stub_cache()->ComputeCallMiss(arguments().immediate(),
1484 kind_,
1485 extra_ic_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001486 Object* obj;
1487 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
1488 __ Jump(Handle<Code>(Code::cast(obj)), RelocInfo::CODE_TARGET);
1489 return obj;
ager@chromium.org5c838252010-02-19 08:53:10 +00001490}
1491
1492
lrn@chromium.org7516f052011-03-30 08:52:27 +00001493MaybeObject* CallStubCompiler::CompileCallField(JSObject* object,
1494 JSObject* holder,
1495 int index,
ager@chromium.org5c838252010-02-19 08:53:10 +00001496 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001497 // ----------- S t a t e -------------
1498 // -- a2 : name
1499 // -- ra : return address
1500 // -----------------------------------
1501 Label miss;
1502
1503 GenerateNameCheck(name, &miss);
1504
1505 const int argc = arguments().immediate();
1506
1507 // Get the receiver of the function from the stack into a0.
1508 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1509 // Check that the receiver isn't a smi.
1510 __ JumpIfSmi(a0, &miss, t0);
1511
1512 // Do the right check and compute the holder register.
1513 Register reg = CheckPrototypes(object, a0, holder, a1, a3, t0, name, &miss);
1514 GenerateFastPropertyLoad(masm(), a1, reg, holder, index);
1515
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00001516 GenerateCallFunction(masm(), object, arguments(), &miss, extra_ic_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001517
1518 // Handle call cache miss.
1519 __ bind(&miss);
1520 MaybeObject* maybe_result = GenerateMissBranch();
1521 if (maybe_result->IsFailure()) return maybe_result;
1522
1523 // Return the generated code.
1524 return GetCode(FIELD, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00001525}
1526
1527
lrn@chromium.org7516f052011-03-30 08:52:27 +00001528MaybeObject* CallStubCompiler::CompileArrayPushCall(Object* object,
1529 JSObject* holder,
1530 JSGlobalPropertyCell* cell,
1531 JSFunction* function,
1532 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001533 // ----------- S t a t e -------------
1534 // -- a2 : name
1535 // -- ra : return address
1536 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1537 // -- ...
1538 // -- sp[argc * 4] : receiver
1539 // -----------------------------------
1540
1541 // If object is not an array, bail out to regular call.
1542 if (!object->IsJSArray() || cell != NULL) return heap()->undefined_value();
1543
1544 Label miss;
1545
1546 GenerateNameCheck(name, &miss);
1547
1548 Register receiver = a1;
1549
1550 // Get the receiver from the stack.
1551 const int argc = arguments().immediate();
1552 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1553
1554 // Check that the receiver isn't a smi.
1555 __ JumpIfSmi(receiver, &miss);
1556
1557 // Check that the maps haven't changed.
1558 CheckPrototypes(JSObject::cast(object), receiver,
1559 holder, a3, v0, t0, name, &miss);
1560
1561 if (argc == 0) {
1562 // Nothing to do, just return the length.
1563 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1564 __ Drop(argc + 1);
1565 __ Ret();
1566 } else {
1567 Label call_builtin;
1568
1569 Register elements = a3;
1570 Register end_elements = t1;
1571
1572 // Get the elements array of the object.
1573 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1574
1575 // Check that the elements are in fast mode and writable.
danno@chromium.org40cb8782011-05-25 07:58:50 +00001576 __ CheckMap(elements,
1577 v0,
1578 Heap::kFixedArrayMapRootIndex,
1579 &call_builtin,
1580 DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001581
1582 if (argc == 1) { // Otherwise fall through to call the builtin.
1583 Label exit, with_write_barrier, attempt_to_grow_elements;
1584
1585 // Get the array's length into v0 and calculate new length.
1586 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1587 STATIC_ASSERT(kSmiTagSize == 1);
1588 STATIC_ASSERT(kSmiTag == 0);
1589 __ Addu(v0, v0, Operand(Smi::FromInt(argc)));
1590
1591 // Get the element's length.
1592 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1593
1594 // Check if we could survive without allocation.
1595 __ Branch(&attempt_to_grow_elements, gt, v0, Operand(t0));
1596
1597 // Save new length.
1598 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1599
1600 // Push the element.
1601 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize));
1602 // We may need a register containing the address end_elements below,
1603 // so write back the value in end_elements.
1604 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1605 __ Addu(end_elements, elements, end_elements);
1606 const int kEndElementsOffset =
1607 FixedArray::kHeaderSize - kHeapObjectTag - argc * kPointerSize;
1608 __ sw(t0, MemOperand(end_elements, kEndElementsOffset));
1609 __ Addu(end_elements, end_elements, kPointerSize);
1610
1611 // Check for a smi.
1612 __ JumpIfNotSmi(t0, &with_write_barrier);
1613 __ bind(&exit);
1614 __ Drop(argc + 1);
1615 __ Ret();
1616
1617 __ bind(&with_write_barrier);
1618 __ InNewSpace(elements, t0, eq, &exit);
1619 __ RecordWriteHelper(elements, end_elements, t0);
1620 __ Drop(argc + 1);
1621 __ Ret();
1622
1623 __ bind(&attempt_to_grow_elements);
1624 // v0: array's length + 1.
1625 // t0: elements' length.
1626
1627 if (!FLAG_inline_new) {
1628 __ Branch(&call_builtin);
1629 }
1630
1631 ExternalReference new_space_allocation_top =
1632 ExternalReference::new_space_allocation_top_address(
1633 masm()->isolate());
1634 ExternalReference new_space_allocation_limit =
1635 ExternalReference::new_space_allocation_limit_address(
1636 masm()->isolate());
1637
1638 const int kAllocationDelta = 4;
1639 // Load top and check if it is the end of elements.
1640 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1641 __ Addu(end_elements, elements, end_elements);
1642 __ Addu(end_elements, end_elements, Operand(kEndElementsOffset));
1643 __ li(t3, Operand(new_space_allocation_top));
1644 __ lw(t2, MemOperand(t3));
1645 __ Branch(&call_builtin, ne, end_elements, Operand(t2));
1646
1647 __ li(t5, Operand(new_space_allocation_limit));
1648 __ lw(t5, MemOperand(t5));
1649 __ Addu(t2, t2, Operand(kAllocationDelta * kPointerSize));
1650 __ Branch(&call_builtin, hi, t2, Operand(t5));
1651
1652 // We fit and could grow elements.
1653 // Update new_space_allocation_top.
1654 __ sw(t2, MemOperand(t3));
1655 // Push the argument.
1656 __ lw(t2, MemOperand(sp, (argc - 1) * kPointerSize));
1657 __ sw(t2, MemOperand(end_elements));
1658 // Fill the rest with holes.
1659 __ LoadRoot(t2, Heap::kTheHoleValueRootIndex);
1660 for (int i = 1; i < kAllocationDelta; i++) {
1661 __ sw(t2, MemOperand(end_elements, i * kPointerSize));
1662 }
1663
1664 // Update elements' and array's sizes.
1665 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1666 __ Addu(t0, t0, Operand(Smi::FromInt(kAllocationDelta)));
1667 __ sw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1668
1669 // Elements are in new space, so write barrier is not required.
1670 __ Drop(argc + 1);
1671 __ Ret();
1672 }
1673 __ bind(&call_builtin);
1674 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPush,
1675 masm()->isolate()),
1676 argc + 1,
1677 1);
1678 }
1679
1680 // Handle call cache miss.
1681 __ bind(&miss);
1682 MaybeObject* maybe_result = GenerateMissBranch();
1683 if (maybe_result->IsFailure()) return maybe_result;
1684
1685 // Return the generated code.
1686 return GetCode(function);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001687}
1688
1689
1690MaybeObject* CallStubCompiler::CompileArrayPopCall(Object* object,
1691 JSObject* holder,
1692 JSGlobalPropertyCell* cell,
1693 JSFunction* function,
ager@chromium.org5c838252010-02-19 08:53:10 +00001694 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001695 // ----------- S t a t e -------------
1696 // -- a2 : name
1697 // -- ra : return address
1698 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1699 // -- ...
1700 // -- sp[argc * 4] : receiver
1701 // -----------------------------------
1702
1703 // If object is not an array, bail out to regular call.
1704 if (!object->IsJSArray() || cell != NULL) return heap()->undefined_value();
1705
1706 Label miss, return_undefined, call_builtin;
1707
1708 Register receiver = a1;
1709 Register elements = a3;
1710
1711 GenerateNameCheck(name, &miss);
1712
1713 // Get the receiver from the stack.
1714 const int argc = arguments().immediate();
1715 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1716
1717 // Check that the receiver isn't a smi.
1718 __ JumpIfSmi(receiver, &miss);
1719
1720 // Check that the maps haven't changed.
1721 CheckPrototypes(JSObject::cast(object),
1722 receiver, holder, elements, t0, v0, name, &miss);
1723
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);
1747 __ lw(v0, MemOperand(elements, FixedArray::kHeaderSize - kHeapObjectTag));
1748 __ 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.
1754 __ sw(t2, MemOperand(elements, FixedArray::kHeaderSize - kHeapObjectTag));
1755 __ 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);
1771 MaybeObject* maybe_result = GenerateMissBranch();
1772 if (maybe_result->IsFailure()) return maybe_result;
1773
1774 // Return the generated code.
1775 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00001776}
1777
1778
lrn@chromium.org7516f052011-03-30 08:52:27 +00001779MaybeObject* CallStubCompiler::CompileStringCharCodeAtCall(
1780 Object* object,
1781 JSObject* holder,
1782 JSGlobalPropertyCell* cell,
1783 JSFunction* function,
1784 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001785 // ----------- S t a t e -------------
1786 // -- a2 : function name
1787 // -- ra : return address
1788 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1789 // -- ...
1790 // -- sp[argc * 4] : receiver
1791 // -----------------------------------
1792
1793 // If object is not a string, bail out to regular call.
1794 if (!object->IsString() || cell != NULL) return heap()->undefined_value();
1795
1796 const int argc = arguments().immediate();
1797
1798 Label miss;
1799 Label name_miss;
1800 Label index_out_of_range;
1801
1802 Label* index_out_of_range_label = &index_out_of_range;
1803
danno@chromium.org40cb8782011-05-25 07:58:50 +00001804 if (kind_ == Code::CALL_IC &&
1805 (CallICBase::StringStubState::decode(extra_ic_state_) ==
1806 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001807 index_out_of_range_label = &miss;
1808 }
1809
1810 GenerateNameCheck(name, &name_miss);
1811
1812 // Check that the maps starting from the prototype haven't changed.
1813 GenerateDirectLoadGlobalFunctionPrototype(masm(),
1814 Context::STRING_FUNCTION_INDEX,
1815 v0,
1816 &miss);
1817 ASSERT(object != holder);
1818 CheckPrototypes(JSObject::cast(object->GetPrototype()), v0, holder,
1819 a1, a3, t0, name, &miss);
1820
1821 Register receiver = a1;
1822 Register index = t1;
1823 Register scratch = a3;
1824 Register result = v0;
1825 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1826 if (argc > 0) {
1827 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
1828 } else {
1829 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
1830 }
1831
1832 StringCharCodeAtGenerator char_code_at_generator(receiver,
1833 index,
1834 scratch,
1835 result,
1836 &miss, // When not a string.
1837 &miss, // When not a number.
1838 index_out_of_range_label,
1839 STRING_INDEX_IS_NUMBER);
1840 char_code_at_generator.GenerateFast(masm());
1841 __ Drop(argc + 1);
1842 __ Ret();
1843
1844 StubRuntimeCallHelper call_helper;
1845 char_code_at_generator.GenerateSlow(masm(), call_helper);
1846
1847 if (index_out_of_range.is_linked()) {
1848 __ bind(&index_out_of_range);
1849 __ LoadRoot(v0, Heap::kNanValueRootIndex);
1850 __ Drop(argc + 1);
1851 __ Ret();
1852 }
1853
1854 __ bind(&miss);
1855 // Restore function name in a2.
1856 __ li(a2, Handle<String>(name));
1857 __ bind(&name_miss);
1858 MaybeObject* maybe_result = GenerateMissBranch();
1859 if (maybe_result->IsFailure()) return maybe_result;
1860
1861 // Return the generated code.
1862 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00001863}
1864
1865
lrn@chromium.org7516f052011-03-30 08:52:27 +00001866MaybeObject* CallStubCompiler::CompileStringCharAtCall(
1867 Object* object,
1868 JSObject* holder,
1869 JSGlobalPropertyCell* cell,
1870 JSFunction* function,
1871 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001872 // ----------- S t a t e -------------
1873 // -- a2 : function name
1874 // -- ra : return address
1875 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1876 // -- ...
1877 // -- sp[argc * 4] : receiver
1878 // -----------------------------------
1879
1880 // If object is not a string, bail out to regular call.
1881 if (!object->IsString() || cell != NULL) return heap()->undefined_value();
1882
1883 const int argc = arguments().immediate();
1884
1885 Label miss;
1886 Label name_miss;
1887 Label index_out_of_range;
1888 Label* index_out_of_range_label = &index_out_of_range;
1889
danno@chromium.org40cb8782011-05-25 07:58:50 +00001890 if (kind_ == Code::CALL_IC &&
1891 (CallICBase::StringStubState::decode(extra_ic_state_) ==
1892 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001893 index_out_of_range_label = &miss;
1894 }
1895
1896 GenerateNameCheck(name, &name_miss);
1897
1898 // Check that the maps starting from the prototype haven't changed.
1899 GenerateDirectLoadGlobalFunctionPrototype(masm(),
1900 Context::STRING_FUNCTION_INDEX,
1901 v0,
1902 &miss);
1903 ASSERT(object != holder);
1904 CheckPrototypes(JSObject::cast(object->GetPrototype()), v0, holder,
1905 a1, a3, t0, name, &miss);
1906
1907 Register receiver = v0;
1908 Register index = t1;
1909 Register scratch1 = a1;
1910 Register scratch2 = a3;
1911 Register result = v0;
1912 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1913 if (argc > 0) {
1914 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
1915 } else {
1916 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
1917 }
1918
1919 StringCharAtGenerator char_at_generator(receiver,
1920 index,
1921 scratch1,
1922 scratch2,
1923 result,
1924 &miss, // When not a string.
1925 &miss, // When not a number.
1926 index_out_of_range_label,
1927 STRING_INDEX_IS_NUMBER);
1928 char_at_generator.GenerateFast(masm());
1929 __ Drop(argc + 1);
1930 __ Ret();
1931
1932 StubRuntimeCallHelper call_helper;
1933 char_at_generator.GenerateSlow(masm(), call_helper);
1934
1935 if (index_out_of_range.is_linked()) {
1936 __ bind(&index_out_of_range);
1937 __ LoadRoot(v0, Heap::kEmptyStringRootIndex);
1938 __ Drop(argc + 1);
1939 __ Ret();
1940 }
1941
1942 __ bind(&miss);
1943 // Restore function name in a2.
1944 __ li(a2, Handle<String>(name));
1945 __ bind(&name_miss);
1946 MaybeObject* maybe_result = GenerateMissBranch();
1947 if (maybe_result->IsFailure()) return maybe_result;
1948
1949 // Return the generated code.
1950 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00001951}
1952
1953
lrn@chromium.org7516f052011-03-30 08:52:27 +00001954MaybeObject* CallStubCompiler::CompileStringFromCharCodeCall(
1955 Object* object,
1956 JSObject* holder,
1957 JSGlobalPropertyCell* cell,
1958 JSFunction* function,
1959 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001960 // ----------- S t a t e -------------
1961 // -- a2 : function name
1962 // -- ra : return address
1963 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1964 // -- ...
1965 // -- sp[argc * 4] : receiver
1966 // -----------------------------------
1967
1968 const int argc = arguments().immediate();
1969
1970 // If the object is not a JSObject or we got an unexpected number of
1971 // arguments, bail out to the regular call.
1972 if (!object->IsJSObject() || argc != 1) return heap()->undefined_value();
1973
1974 Label miss;
1975 GenerateNameCheck(name, &miss);
1976
1977 if (cell == NULL) {
1978 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
1979
1980 STATIC_ASSERT(kSmiTag == 0);
1981 __ JumpIfSmi(a1, &miss);
1982
1983 CheckPrototypes(JSObject::cast(object), a1, holder, v0, a3, t0, name,
1984 &miss);
1985 } else {
1986 ASSERT(cell->value() == function);
1987 GenerateGlobalReceiverCheck(JSObject::cast(object), holder, name, &miss);
1988 GenerateLoadFunctionFromCell(cell, function, &miss);
1989 }
1990
1991 // Load the char code argument.
1992 Register code = a1;
1993 __ lw(code, MemOperand(sp, 0 * kPointerSize));
1994
1995 // Check the code is a smi.
1996 Label slow;
1997 STATIC_ASSERT(kSmiTag == 0);
1998 __ JumpIfNotSmi(code, &slow);
1999
2000 // Convert the smi code to uint16.
2001 __ And(code, code, Operand(Smi::FromInt(0xffff)));
2002
2003 StringCharFromCodeGenerator char_from_code_generator(code, v0);
2004 char_from_code_generator.GenerateFast(masm());
2005 __ Drop(argc + 1);
2006 __ Ret();
2007
2008 StubRuntimeCallHelper call_helper;
2009 char_from_code_generator.GenerateSlow(masm(), call_helper);
2010
2011 // Tail call the full function. We do not have to patch the receiver
2012 // because the function makes no use of it.
2013 __ bind(&slow);
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002014 __ InvokeFunction(function, arguments(), JUMP_FUNCTION, CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002015
2016 __ bind(&miss);
2017 // a2: function name.
2018 MaybeObject* maybe_result = GenerateMissBranch();
2019 if (maybe_result->IsFailure()) return maybe_result;
2020
2021 // Return the generated code.
2022 return (cell == NULL) ? GetCode(function) : GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002023}
2024
2025
lrn@chromium.org7516f052011-03-30 08:52:27 +00002026MaybeObject* CallStubCompiler::CompileMathFloorCall(Object* object,
2027 JSObject* holder,
2028 JSGlobalPropertyCell* cell,
2029 JSFunction* function,
2030 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002031 // ----------- S t a t e -------------
2032 // -- a2 : function name
2033 // -- ra : return address
2034 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2035 // -- ...
2036 // -- sp[argc * 4] : receiver
2037 // -----------------------------------
2038
2039 if (!CpuFeatures::IsSupported(FPU))
2040 return heap()->undefined_value();
2041 CpuFeatures::Scope scope_fpu(FPU);
2042
2043 const int argc = arguments().immediate();
2044
2045 // If the object is not a JSObject or we got an unexpected number of
2046 // arguments, bail out to the regular call.
2047 if (!object->IsJSObject() || argc != 1) return heap()->undefined_value();
2048
2049 Label miss, slow;
2050 GenerateNameCheck(name, &miss);
2051
2052 if (cell == NULL) {
2053 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
2054
2055 STATIC_ASSERT(kSmiTag == 0);
2056 __ JumpIfSmi(a1, &miss);
2057
2058 CheckPrototypes(JSObject::cast(object), a1, holder, a0, a3, t0, name,
2059 &miss);
2060 } else {
2061 ASSERT(cell->value() == function);
2062 GenerateGlobalReceiverCheck(JSObject::cast(object), holder, name, &miss);
2063 GenerateLoadFunctionFromCell(cell, function, &miss);
2064 }
2065
2066 // Load the (only) argument into v0.
2067 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2068
2069 // If the argument is a smi, just return.
2070 STATIC_ASSERT(kSmiTag == 0);
2071 __ And(t0, v0, Operand(kSmiTagMask));
2072 __ Drop(argc + 1, eq, t0, Operand(zero_reg));
2073 __ Ret(eq, t0, Operand(zero_reg));
2074
danno@chromium.org40cb8782011-05-25 07:58:50 +00002075 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002076
2077 Label wont_fit_smi, no_fpu_error, restore_fcsr_and_return;
2078
2079 // If fpu is enabled, we use the floor instruction.
2080
2081 // Load the HeapNumber value.
2082 __ ldc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
2083
2084 // Backup FCSR.
2085 __ cfc1(a3, FCSR);
2086 // Clearing FCSR clears the exception mask with no side-effects.
2087 __ ctc1(zero_reg, FCSR);
2088 // Convert the argument to an integer.
2089 __ floor_w_d(f0, f0);
2090
2091 // Start checking for special cases.
2092 // Get the argument exponent and clear the sign bit.
2093 __ lw(t1, FieldMemOperand(v0, HeapNumber::kValueOffset + kPointerSize));
2094 __ And(t2, t1, Operand(~HeapNumber::kSignMask));
2095 __ srl(t2, t2, HeapNumber::kMantissaBitsInTopWord);
2096
2097 // Retrieve FCSR and check for fpu errors.
2098 __ cfc1(t5, FCSR);
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002099 __ And(t5, t5, Operand(kFCSRExceptionFlagMask));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002100 __ Branch(&no_fpu_error, eq, t5, Operand(zero_reg));
2101
2102 // Check for NaN, Infinity, and -Infinity.
2103 // They are invariant through a Math.Floor call, so just
2104 // return the original argument.
2105 __ Subu(t3, t2, Operand(HeapNumber::kExponentMask
2106 >> HeapNumber::kMantissaBitsInTopWord));
2107 __ Branch(&restore_fcsr_and_return, eq, t3, Operand(zero_reg));
2108 // We had an overflow or underflow in the conversion. Check if we
2109 // have a big exponent.
2110 // If greater or equal, the argument is already round and in v0.
2111 __ Branch(&restore_fcsr_and_return, ge, t3,
2112 Operand(HeapNumber::kMantissaBits));
2113 __ Branch(&wont_fit_smi);
2114
2115 __ bind(&no_fpu_error);
2116 // Move the result back to v0.
2117 __ mfc1(v0, f0);
2118 // Check if the result fits into a smi.
2119 __ Addu(a1, v0, Operand(0x40000000));
2120 __ Branch(&wont_fit_smi, lt, a1, Operand(zero_reg));
2121 // Tag the result.
2122 STATIC_ASSERT(kSmiTag == 0);
2123 __ sll(v0, v0, kSmiTagSize);
2124
2125 // Check for -0.
2126 __ Branch(&restore_fcsr_and_return, ne, v0, Operand(zero_reg));
2127 // t1 already holds the HeapNumber exponent.
2128 __ And(t0, t1, Operand(HeapNumber::kSignMask));
2129 // If our HeapNumber is negative it was -0, so load its address and return.
2130 // Else v0 is loaded with 0, so we can also just return.
2131 __ Branch(&restore_fcsr_and_return, eq, t0, Operand(zero_reg));
2132 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2133
2134 __ bind(&restore_fcsr_and_return);
2135 // Restore FCSR and return.
2136 __ ctc1(a3, FCSR);
2137
2138 __ Drop(argc + 1);
2139 __ Ret();
2140
2141 __ bind(&wont_fit_smi);
2142 // Restore FCSR and fall to slow case.
2143 __ ctc1(a3, FCSR);
2144
2145 __ bind(&slow);
2146 // Tail call the full function. We do not have to patch the receiver
2147 // because the function makes no use of it.
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002148 __ InvokeFunction(function, arguments(), JUMP_FUNCTION, CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002149
2150 __ bind(&miss);
2151 // a2: function name.
2152 MaybeObject* obj = GenerateMissBranch();
2153 if (obj->IsFailure()) return obj;
2154
2155 // Return the generated code.
2156 return (cell == NULL) ? GetCode(function) : GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002157}
2158
2159
lrn@chromium.org7516f052011-03-30 08:52:27 +00002160MaybeObject* CallStubCompiler::CompileMathAbsCall(Object* object,
2161 JSObject* holder,
2162 JSGlobalPropertyCell* cell,
2163 JSFunction* function,
2164 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002165 // ----------- S t a t e -------------
2166 // -- a2 : function name
2167 // -- ra : return address
2168 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2169 // -- ...
2170 // -- sp[argc * 4] : receiver
2171 // -----------------------------------
2172
2173 const int argc = arguments().immediate();
2174
2175 // If the object is not a JSObject or we got an unexpected number of
2176 // arguments, bail out to the regular call.
2177 if (!object->IsJSObject() || argc != 1) return heap()->undefined_value();
2178
2179 Label miss;
2180 GenerateNameCheck(name, &miss);
2181
2182 if (cell == NULL) {
2183 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
2184
2185 STATIC_ASSERT(kSmiTag == 0);
2186 __ JumpIfSmi(a1, &miss);
2187
2188 CheckPrototypes(JSObject::cast(object), a1, holder, v0, a3, t0, name,
2189 &miss);
2190 } else {
2191 ASSERT(cell->value() == function);
2192 GenerateGlobalReceiverCheck(JSObject::cast(object), holder, name, &miss);
2193 GenerateLoadFunctionFromCell(cell, function, &miss);
2194 }
2195
2196 // Load the (only) argument into v0.
2197 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2198
2199 // Check if the argument is a smi.
2200 Label not_smi;
2201 STATIC_ASSERT(kSmiTag == 0);
2202 __ JumpIfNotSmi(v0, &not_smi);
2203
2204 // Do bitwise not or do nothing depending on the sign of the
2205 // argument.
2206 __ sra(t0, v0, kBitsPerInt - 1);
2207 __ Xor(a1, v0, t0);
2208
2209 // Add 1 or do nothing depending on the sign of the argument.
2210 __ Subu(v0, a1, t0);
2211
2212 // If the result is still negative, go to the slow case.
2213 // This only happens for the most negative smi.
2214 Label slow;
2215 __ Branch(&slow, lt, v0, Operand(zero_reg));
2216
2217 // Smi case done.
2218 __ Drop(argc + 1);
2219 __ Ret();
2220
2221 // Check if the argument is a heap number and load its exponent and
2222 // sign.
2223 __ bind(&not_smi);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002224 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002225 __ lw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2226
2227 // Check the sign of the argument. If the argument is positive,
2228 // just return it.
2229 Label negative_sign;
2230 __ And(t0, a1, Operand(HeapNumber::kSignMask));
2231 __ Branch(&negative_sign, ne, t0, Operand(zero_reg));
2232 __ Drop(argc + 1);
2233 __ Ret();
2234
2235 // If the argument is negative, clear the sign, and return a new
2236 // number.
2237 __ bind(&negative_sign);
2238 __ Xor(a1, a1, Operand(HeapNumber::kSignMask));
2239 __ lw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2240 __ LoadRoot(t2, Heap::kHeapNumberMapRootIndex);
2241 __ AllocateHeapNumber(v0, t0, t1, t2, &slow);
2242 __ sw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2243 __ sw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2244 __ Drop(argc + 1);
2245 __ Ret();
2246
2247 // Tail call the full function. We do not have to patch the receiver
2248 // because the function makes no use of it.
2249 __ bind(&slow);
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002250 __ InvokeFunction(function, arguments(), JUMP_FUNCTION, CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002251
2252 __ bind(&miss);
2253 // a2: function name.
2254 MaybeObject* maybe_result = GenerateMissBranch();
2255 if (maybe_result->IsFailure()) return maybe_result;
2256
2257 // Return the generated code.
2258 return (cell == NULL) ? GetCode(function) : GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002259}
2260
2261
lrn@chromium.org7516f052011-03-30 08:52:27 +00002262MaybeObject* CallStubCompiler::CompileFastApiCall(
2263 const CallOptimization& optimization,
2264 Object* object,
2265 JSObject* holder,
2266 JSGlobalPropertyCell* cell,
2267 JSFunction* function,
2268 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002269
danno@chromium.org40cb8782011-05-25 07:58:50 +00002270 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002271
2272 ASSERT(optimization.is_simple_api_call());
2273 // Bail out if object is a global object as we don't want to
2274 // repatch it to global receiver.
danno@chromium.org40cb8782011-05-25 07:58:50 +00002275 if (object->IsGlobalObject()) return heap()->undefined_value();
2276 if (cell != NULL) return heap()->undefined_value();
ager@chromium.orgea91cc52011-05-23 06:06:11 +00002277 if (!object->IsJSObject()) return heap()->undefined_value();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002278 int depth = optimization.GetPrototypeDepthOfExpectedType(
2279 JSObject::cast(object), holder);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002280 if (depth == kInvalidProtoDepth) return heap()->undefined_value();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002281
2282 Label miss, miss_before_stack_reserved;
2283
2284 GenerateNameCheck(name, &miss_before_stack_reserved);
2285
2286 // Get the receiver from the stack.
2287 const int argc = arguments().immediate();
2288 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2289
2290 // Check that the receiver isn't a smi.
2291 __ JumpIfSmi(a1, &miss_before_stack_reserved);
2292
2293 __ IncrementCounter(counters->call_const(), 1, a0, a3);
2294 __ IncrementCounter(counters->call_const_fast_api(), 1, a0, a3);
2295
2296 ReserveSpaceForFastApiCall(masm(), a0);
2297
2298 // Check that the maps haven't changed and find a Holder as a side effect.
2299 CheckPrototypes(JSObject::cast(object), a1, holder, a0, a3, t0, name,
2300 depth, &miss);
2301
2302 MaybeObject* result = GenerateFastApiDirectCall(masm(), optimization, argc);
2303 if (result->IsFailure()) return result;
2304
2305 __ bind(&miss);
2306 FreeSpaceForFastApiCall(masm());
2307
2308 __ bind(&miss_before_stack_reserved);
2309 MaybeObject* maybe_result = GenerateMissBranch();
2310 if (maybe_result->IsFailure()) return maybe_result;
2311
2312 // Return the generated code.
2313 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002314}
2315
2316
lrn@chromium.org7516f052011-03-30 08:52:27 +00002317MaybeObject* CallStubCompiler::CompileCallConstant(Object* object,
ager@chromium.org5c838252010-02-19 08:53:10 +00002318 JSObject* holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +00002319 JSFunction* function,
2320 String* name,
2321 CheckType check) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002322 // ----------- S t a t e -------------
2323 // -- a2 : name
2324 // -- ra : return address
2325 // -----------------------------------
2326 if (HasCustomCallGenerator(function)) {
2327 MaybeObject* maybe_result = CompileCustomCall(
2328 object, holder, NULL, function, name);
2329 Object* result;
2330 if (!maybe_result->ToObject(&result)) return maybe_result;
2331 // Undefined means bail out to regular compiler.
2332 if (!result->IsUndefined()) return result;
2333 }
2334
2335 Label miss;
2336
2337 GenerateNameCheck(name, &miss);
2338
2339 // Get the receiver from the stack.
2340 const int argc = arguments().immediate();
2341 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2342
2343 // Check that the receiver isn't a smi.
2344 if (check != NUMBER_CHECK) {
2345 __ And(t1, a1, Operand(kSmiTagMask));
2346 __ Branch(&miss, eq, t1, Operand(zero_reg));
2347 }
2348
2349 // Make sure that it's okay not to patch the on stack receiver
2350 // unless we're doing a receiver map check.
2351 ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK);
2352
2353 SharedFunctionInfo* function_info = function->shared();
2354 switch (check) {
2355 case RECEIVER_MAP_CHECK:
2356 __ IncrementCounter(masm()->isolate()->counters()->call_const(),
2357 1, a0, a3);
2358
2359 // Check that the maps haven't changed.
2360 CheckPrototypes(JSObject::cast(object), a1, holder, a0, a3, t0, name,
2361 &miss);
2362
2363 // Patch the receiver on the stack with the global proxy if
2364 // necessary.
2365 if (object->IsGlobalObject()) {
2366 __ lw(a3, FieldMemOperand(a1, GlobalObject::kGlobalReceiverOffset));
2367 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2368 }
2369 break;
2370
2371 case STRING_CHECK:
2372 if (!function->IsBuiltin() && !function_info->strict_mode()) {
2373 // Calling non-strict non-builtins with a value as the receiver
2374 // requires boxing.
2375 __ jmp(&miss);
2376 } else {
2377 // Check that the object is a two-byte string or a symbol.
2378 __ GetObjectType(a1, a3, a3);
2379 __ Branch(&miss, Ugreater_equal, a3, Operand(FIRST_NONSTRING_TYPE));
2380 // Check that the maps starting from the prototype haven't changed.
2381 GenerateDirectLoadGlobalFunctionPrototype(
2382 masm(), Context::STRING_FUNCTION_INDEX, a0, &miss);
2383 CheckPrototypes(JSObject::cast(object->GetPrototype()), a0, holder, a3,
2384 a1, t0, name, &miss);
2385 }
2386 break;
2387
2388 case NUMBER_CHECK: {
2389 if (!function->IsBuiltin() && !function_info->strict_mode()) {
2390 // Calling non-strict non-builtins with a value as the receiver
2391 // requires boxing.
2392 __ jmp(&miss);
2393 } else {
2394 Label fast;
2395 // Check that the object is a smi or a heap number.
2396 __ And(t1, a1, Operand(kSmiTagMask));
2397 __ Branch(&fast, eq, t1, Operand(zero_reg));
2398 __ GetObjectType(a1, a0, a0);
2399 __ Branch(&miss, ne, a0, Operand(HEAP_NUMBER_TYPE));
2400 __ bind(&fast);
2401 // Check that the maps starting from the prototype haven't changed.
2402 GenerateDirectLoadGlobalFunctionPrototype(
2403 masm(), Context::NUMBER_FUNCTION_INDEX, a0, &miss);
2404 CheckPrototypes(JSObject::cast(object->GetPrototype()), a0, holder, a3,
2405 a1, t0, name, &miss);
2406 }
2407 break;
2408 }
2409
2410 case BOOLEAN_CHECK: {
2411 if (!function->IsBuiltin() && !function_info->strict_mode()) {
2412 // Calling non-strict non-builtins with a value as the receiver
2413 // requires boxing.
2414 __ jmp(&miss);
2415 } else {
2416 Label fast;
2417 // Check that the object is a boolean.
2418 __ LoadRoot(t0, Heap::kTrueValueRootIndex);
2419 __ Branch(&fast, eq, a1, Operand(t0));
2420 __ LoadRoot(t0, Heap::kFalseValueRootIndex);
2421 __ Branch(&miss, ne, a1, Operand(t0));
2422 __ bind(&fast);
2423 // Check that the maps starting from the prototype haven't changed.
2424 GenerateDirectLoadGlobalFunctionPrototype(
2425 masm(), Context::BOOLEAN_FUNCTION_INDEX, a0, &miss);
2426 CheckPrototypes(JSObject::cast(object->GetPrototype()), a0, holder, a3,
2427 a1, t0, name, &miss);
2428 }
2429 break;
2430 }
2431
2432 default:
2433 UNREACHABLE();
2434 }
2435
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002436 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state_)
2437 ? CALL_AS_FUNCTION
2438 : CALL_AS_METHOD;
2439 __ InvokeFunction(function, arguments(), JUMP_FUNCTION, call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002440
2441 // Handle call cache miss.
2442 __ bind(&miss);
2443
2444 MaybeObject* maybe_result = GenerateMissBranch();
2445 if (maybe_result->IsFailure()) return maybe_result;
2446
2447 // Return the generated code.
2448 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002449}
2450
2451
lrn@chromium.org7516f052011-03-30 08:52:27 +00002452MaybeObject* CallStubCompiler::CompileCallInterceptor(JSObject* object,
ager@chromium.org5c838252010-02-19 08:53:10 +00002453 JSObject* holder,
2454 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002455 // ----------- S t a t e -------------
2456 // -- a2 : name
2457 // -- ra : return address
2458 // -----------------------------------
2459
2460 Label miss;
2461
2462 GenerateNameCheck(name, &miss);
2463
2464 // Get the number of arguments.
2465 const int argc = arguments().immediate();
2466
2467 LookupResult lookup;
2468 LookupPostInterceptor(holder, name, &lookup);
2469
2470 // Get the receiver from the stack.
2471 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2472
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002473 CallInterceptorCompiler compiler(this, arguments(), a2, extra_ic_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002474 MaybeObject* result = compiler.Compile(masm(),
2475 object,
2476 holder,
2477 name,
2478 &lookup,
2479 a1,
2480 a3,
2481 t0,
2482 a0,
2483 &miss);
2484 if (result->IsFailure()) {
2485 return result;
2486 }
2487
2488 // Move returned value, the function to call, to a1.
2489 __ mov(a1, v0);
2490 // Restore receiver.
2491 __ lw(a0, MemOperand(sp, argc * kPointerSize));
2492
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002493 GenerateCallFunction(masm(), object, arguments(), &miss, extra_ic_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002494
2495 // Handle call cache miss.
2496 __ bind(&miss);
2497 MaybeObject* maybe_result = GenerateMissBranch();
2498 if (maybe_result->IsFailure()) return maybe_result;
2499
2500 // Return the generated code.
2501 return GetCode(INTERCEPTOR, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002502}
2503
2504
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002505MaybeObject* CallStubCompiler::CompileCallGlobal(JSObject* object,
2506 GlobalObject* holder,
2507 JSGlobalPropertyCell* cell,
2508 JSFunction* function,
2509 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002510 // ----------- S t a t e -------------
2511 // -- a2 : name
2512 // -- ra : return address
2513 // -----------------------------------
2514
2515 if (HasCustomCallGenerator(function)) {
2516 MaybeObject* maybe_result = CompileCustomCall(
2517 object, holder, cell, function, name);
2518 Object* result;
2519 if (!maybe_result->ToObject(&result)) return maybe_result;
2520 // Undefined means bail out to regular compiler.
2521 if (!result->IsUndefined()) return result;
2522 }
2523
2524 Label miss;
2525
2526 GenerateNameCheck(name, &miss);
2527
2528 // Get the number of arguments.
2529 const int argc = arguments().immediate();
2530
2531 GenerateGlobalReceiverCheck(object, holder, name, &miss);
2532 GenerateLoadFunctionFromCell(cell, function, &miss);
2533
2534 // Patch the receiver on the stack with the global proxy if
2535 // necessary.
2536 if (object->IsGlobalObject()) {
2537 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
2538 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2539 }
2540
2541 // Setup the context (function already in r1).
2542 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
2543
2544 // Jump to the cached code (tail call).
2545 Counters* counters = masm()->isolate()->counters();
2546 __ IncrementCounter(counters->call_global_inline(), 1, a3, t0);
2547 ASSERT(function->is_compiled());
2548 Handle<Code> code(function->code());
2549 ParameterCount expected(function->shared()->formal_parameter_count());
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002550 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state_)
danno@chromium.org40cb8782011-05-25 07:58:50 +00002551 ? CALL_AS_FUNCTION
2552 : CALL_AS_METHOD;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002553 if (V8::UseCrankshaft()) {
2554 UNIMPLEMENTED_MIPS();
2555 } else {
danno@chromium.org40cb8782011-05-25 07:58:50 +00002556 __ InvokeCode(code, expected, arguments(), RelocInfo::CODE_TARGET,
2557 JUMP_FUNCTION, call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002558 }
2559
2560 // Handle call cache miss.
2561 __ bind(&miss);
2562 __ IncrementCounter(counters->call_global_inline_miss(), 1, a1, a3);
2563 MaybeObject* maybe_result = GenerateMissBranch();
2564 if (maybe_result->IsFailure()) return maybe_result;
2565
2566 // Return the generated code.
2567 return GetCode(NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002568}
2569
2570
lrn@chromium.org7516f052011-03-30 08:52:27 +00002571MaybeObject* StoreStubCompiler::CompileStoreField(JSObject* object,
ager@chromium.org5c838252010-02-19 08:53:10 +00002572 int index,
2573 Map* transition,
2574 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002575 // ----------- S t a t e -------------
2576 // -- a0 : value
2577 // -- a1 : receiver
2578 // -- a2 : name
2579 // -- ra : return address
2580 // -----------------------------------
2581 Label miss;
2582
2583 // Name register might be clobbered.
2584 GenerateStoreField(masm(),
2585 object,
2586 index,
2587 transition,
2588 a1, a2, a3,
2589 &miss);
2590 __ bind(&miss);
2591 __ li(a2, Operand(Handle<String>(name))); // Restore name.
2592 Handle<Code> ic = masm()->isolate()->builtins()->Builtins::StoreIC_Miss();
2593 __ Jump(ic, RelocInfo::CODE_TARGET);
2594
2595 // Return the generated code.
2596 return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002597}
2598
2599
lrn@chromium.org7516f052011-03-30 08:52:27 +00002600MaybeObject* StoreStubCompiler::CompileStoreCallback(JSObject* object,
2601 AccessorInfo* callback,
2602 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
2611 // Check that the object isn't a smi.
2612 __ JumpIfSmi(a1, &miss);
2613
2614 // Check that the map of the object hasn't changed.
2615 __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
2616 __ Branch(&miss, ne, a3, Operand(Handle<Map>(object->map())));
2617
2618 // Perform global security token check if needed.
2619 if (object->IsJSGlobalProxy()) {
2620 __ CheckAccessGlobalProxy(a1, a3, &miss);
2621 }
2622
2623 // Stub never generated for non-global objects that require access
2624 // checks.
2625 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
2626
2627 __ push(a1); // Receiver.
2628 __ li(a3, Operand(Handle<AccessorInfo>(callback))); // Callback info.
2629 __ Push(a3, a2, a0);
2630
2631 // Do tail-call to the runtime system.
2632 ExternalReference store_callback_property =
2633 ExternalReference(IC_Utility(IC::kStoreCallbackProperty),
2634 masm()->isolate());
2635 __ TailCallExternalReference(store_callback_property, 4, 1);
2636
2637 // Handle store cache miss.
2638 __ bind(&miss);
2639 Handle<Code> ic = masm()->isolate()->builtins()->StoreIC_Miss();
2640 __ Jump(ic, RelocInfo::CODE_TARGET);
2641
2642 // Return the generated code.
2643 return GetCode(CALLBACKS, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002644}
2645
2646
lrn@chromium.org7516f052011-03-30 08:52:27 +00002647MaybeObject* StoreStubCompiler::CompileStoreInterceptor(JSObject* receiver,
2648 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 object isn't a smi.
2658 __ JumpIfSmi(a1, &miss);
2659
2660 // Check that the map of the object hasn't changed.
2661 __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
2662 __ Branch(&miss, ne, a3, Operand(Handle<Map>(receiver->map())));
2663
2664 // Perform global security token check if needed.
2665 if (receiver->IsJSGlobalProxy()) {
2666 __ CheckAccessGlobalProxy(a1, a3, &miss);
2667 }
2668
2669 // Stub is never generated for non-global objects that require access
2670 // checks.
2671 ASSERT(receiver->IsJSGlobalProxy() || !receiver->IsAccessCheckNeeded());
2672
2673 __ Push(a1, a2, a0); // Receiver, name, value.
2674
2675 __ li(a0, Operand(Smi::FromInt(strict_mode_)));
2676 __ push(a0); // Strict mode.
2677
2678 // Do tail-call to the runtime system.
2679 ExternalReference store_ic_property =
2680 ExternalReference(IC_Utility(IC::kStoreInterceptorProperty),
2681 masm()->isolate());
2682 __ TailCallExternalReference(store_ic_property, 4, 1);
2683
2684 // Handle store cache miss.
2685 __ bind(&miss);
2686 Handle<Code> ic = masm()->isolate()->builtins()->Builtins::StoreIC_Miss();
2687 __ Jump(ic, RelocInfo::CODE_TARGET);
2688
2689 // Return the generated code.
2690 return GetCode(INTERCEPTOR, name);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00002691}
2692
2693
lrn@chromium.org7516f052011-03-30 08:52:27 +00002694MaybeObject* StoreStubCompiler::CompileStoreGlobal(GlobalObject* object,
2695 JSGlobalPropertyCell* cell,
2696 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002697 // ----------- S t a t e -------------
2698 // -- a0 : value
2699 // -- a1 : receiver
2700 // -- a2 : name
2701 // -- ra : return address
2702 // -----------------------------------
2703 Label miss;
2704
2705 // Check that the map of the global has not changed.
2706 __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
2707 __ Branch(&miss, ne, a3, Operand(Handle<Map>(object->map())));
2708
2709 // Check that the value in the cell is not the hole. If it is, this
2710 // cell could have been deleted and reintroducing the global needs
2711 // to update the property details in the property dictionary of the
2712 // global object. We bail out to the runtime system to do that.
2713 __ li(t0, Operand(Handle<JSGlobalPropertyCell>(cell)));
2714 __ LoadRoot(t1, Heap::kTheHoleValueRootIndex);
2715 __ lw(t2, FieldMemOperand(t0, JSGlobalPropertyCell::kValueOffset));
2716 __ Branch(&miss, eq, t1, Operand(t2));
2717
2718 // Store the value in the cell.
2719 __ sw(a0, FieldMemOperand(t0, JSGlobalPropertyCell::kValueOffset));
2720 __ mov(v0, a0); // Stored value must be returned in v0.
2721 Counters* counters = masm()->isolate()->counters();
2722 __ IncrementCounter(counters->named_store_global_inline(), 1, a1, a3);
2723 __ Ret();
2724
2725 // Handle store cache miss.
2726 __ bind(&miss);
2727 __ IncrementCounter(counters->named_store_global_inline_miss(), 1, a1, a3);
2728 Handle<Code> ic = masm()->isolate()->builtins()->StoreIC_Miss();
2729 __ Jump(ic, RelocInfo::CODE_TARGET);
2730
2731 // Return the generated code.
2732 return GetCode(NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002733}
2734
2735
2736MaybeObject* LoadStubCompiler::CompileLoadNonexistent(String* name,
2737 JSObject* object,
2738 JSObject* last) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002739 // ----------- S t a t e -------------
2740 // -- a0 : receiver
2741 // -- ra : return address
2742 // -----------------------------------
2743 Label miss;
2744
2745 // Check that the receiver is not a smi.
2746 __ JumpIfSmi(a0, &miss);
2747
2748 // Check the maps of the full prototype chain.
2749 CheckPrototypes(object, a0, last, a3, a1, t0, name, &miss);
2750
2751 // If the last object in the prototype chain is a global object,
2752 // check that the global property cell is empty.
2753 if (last->IsGlobalObject()) {
2754 MaybeObject* cell = GenerateCheckPropertyCell(masm(),
2755 GlobalObject::cast(last),
2756 name,
2757 a1,
2758 &miss);
2759 if (cell->IsFailure()) {
2760 miss.Unuse();
2761 return cell;
2762 }
2763 }
2764
2765 // Return undefined if maps of the full prototype chain is still the same.
2766 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
2767 __ Ret();
2768
2769 __ bind(&miss);
2770 GenerateLoadMiss(masm(), Code::LOAD_IC);
2771
2772 // Return the generated code.
2773 return GetCode(NONEXISTENT, heap()->empty_string());
lrn@chromium.org7516f052011-03-30 08:52:27 +00002774}
2775
2776
2777MaybeObject* LoadStubCompiler::CompileLoadField(JSObject* object,
2778 JSObject* holder,
2779 int index,
2780 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002781 // ----------- S t a t e -------------
2782 // -- a0 : receiver
2783 // -- a2 : name
2784 // -- ra : return address
2785 // -----------------------------------
2786 Label miss;
2787
2788 __ mov(v0, a0);
2789
2790 GenerateLoadField(object, holder, v0, a3, a1, t0, index, name, &miss);
2791 __ bind(&miss);
2792 GenerateLoadMiss(masm(), Code::LOAD_IC);
2793
2794 // Return the generated code.
2795 return GetCode(FIELD, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002796}
2797
2798
2799MaybeObject* LoadStubCompiler::CompileLoadCallback(String* name,
2800 JSObject* object,
2801 JSObject* holder,
2802 AccessorInfo* callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002803 // ----------- S t a t e -------------
2804 // -- a0 : receiver
2805 // -- a2 : name
2806 // -- ra : return address
2807 // -----------------------------------
2808 Label miss;
2809
2810 MaybeObject* result = GenerateLoadCallback(object, holder, a0, a2, a3, a1, t0,
2811 callback, name, &miss);
2812 if (result->IsFailure()) {
2813 miss.Unuse();
2814 return result;
2815 }
2816
2817 __ bind(&miss);
2818 GenerateLoadMiss(masm(), Code::LOAD_IC);
2819
2820 // Return the generated code.
2821 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002822}
2823
2824
2825MaybeObject* LoadStubCompiler::CompileLoadConstant(JSObject* object,
2826 JSObject* holder,
2827 Object* value,
2828 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002829 // ----------- S t a t e -------------
2830 // -- a0 : receiver
2831 // -- a2 : name
2832 // -- ra : return address
2833 // -----------------------------------
2834 Label miss;
2835
2836 GenerateLoadConstant(object, holder, a0, a3, a1, t0, value, name, &miss);
2837 __ bind(&miss);
2838 GenerateLoadMiss(masm(), Code::LOAD_IC);
2839
2840 // Return the generated code.
2841 return GetCode(CONSTANT_FUNCTION, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002842}
2843
2844
2845MaybeObject* LoadStubCompiler::CompileLoadInterceptor(JSObject* object,
2846 JSObject* holder,
2847 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002848 // ----------- S t a t e -------------
2849 // -- a0 : receiver
2850 // -- a2 : name
2851 // -- ra : return address
2852 // -- [sp] : receiver
2853 // -----------------------------------
2854 Label miss;
2855
2856 LookupResult lookup;
2857 LookupPostInterceptor(holder, name, &lookup);
2858 GenerateLoadInterceptor(object,
2859 holder,
2860 &lookup,
2861 a0,
2862 a2,
2863 a3,
2864 a1,
2865 t0,
2866 name,
2867 &miss);
2868 __ bind(&miss);
2869 GenerateLoadMiss(masm(), Code::LOAD_IC);
2870
2871 // Return the generated code.
2872 return GetCode(INTERCEPTOR, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002873}
2874
2875
2876MaybeObject* LoadStubCompiler::CompileLoadGlobal(JSObject* object,
2877 GlobalObject* holder,
2878 JSGlobalPropertyCell* cell,
2879 String* name,
2880 bool is_dont_delete) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002881 // ----------- S t a t e -------------
2882 // -- a0 : receiver
2883 // -- a2 : name
2884 // -- ra : return address
2885 // -----------------------------------
2886 Label miss;
2887
2888 // If the object is the holder then we know that it's a global
2889 // object which can only happen for contextual calls. In this case,
2890 // the receiver cannot be a smi.
2891 if (object != holder) {
2892 __ And(t0, a0, Operand(kSmiTagMask));
2893 __ Branch(&miss, eq, t0, Operand(zero_reg));
2894 }
2895
2896 // Check that the map of the global has not changed.
2897 CheckPrototypes(object, a0, holder, a3, t0, a1, name, &miss);
2898
2899 // Get the value from the cell.
2900 __ li(a3, Operand(Handle<JSGlobalPropertyCell>(cell)));
2901 __ lw(t0, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
2902
2903 // Check for deleted property if property can actually be deleted.
2904 if (!is_dont_delete) {
2905 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
2906 __ Branch(&miss, eq, t0, Operand(at));
2907 }
2908
2909 __ mov(v0, t0);
2910 Counters* counters = masm()->isolate()->counters();
2911 __ IncrementCounter(counters->named_load_global_stub(), 1, a1, a3);
2912 __ Ret();
2913
2914 __ bind(&miss);
2915 __ IncrementCounter(counters->named_load_global_stub_miss(), 1, a1, a3);
2916 GenerateLoadMiss(masm(), Code::LOAD_IC);
2917
2918 // Return the generated code.
2919 return GetCode(NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002920}
2921
2922
2923MaybeObject* KeyedLoadStubCompiler::CompileLoadField(String* name,
2924 JSObject* receiver,
2925 JSObject* holder,
2926 int index) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002927 // ----------- S t a t e -------------
2928 // -- ra : return address
2929 // -- a0 : key
2930 // -- a1 : receiver
2931 // -----------------------------------
2932 Label miss;
2933
2934 // Check the key is the cached one.
2935 __ Branch(&miss, ne, a0, Operand(Handle<String>(name)));
2936
2937 GenerateLoadField(receiver, holder, a1, a2, a3, t0, index, name, &miss);
2938 __ bind(&miss);
2939 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
2940
2941 return GetCode(FIELD, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002942}
2943
2944
2945MaybeObject* KeyedLoadStubCompiler::CompileLoadCallback(
2946 String* name,
2947 JSObject* receiver,
2948 JSObject* holder,
2949 AccessorInfo* callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002950 // ----------- S t a t e -------------
2951 // -- ra : return address
2952 // -- a0 : key
2953 // -- a1 : receiver
2954 // -----------------------------------
2955 Label miss;
2956
2957 // Check the key is the cached one.
2958 __ Branch(&miss, ne, a0, Operand(Handle<String>(name)));
2959
2960 MaybeObject* result = GenerateLoadCallback(receiver, holder, a1, a0, a2, a3,
2961 t0, callback, name, &miss);
2962 if (result->IsFailure()) {
2963 miss.Unuse();
2964 return result;
2965 }
2966
2967 __ bind(&miss);
2968 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
2969
2970 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002971}
2972
2973
2974MaybeObject* KeyedLoadStubCompiler::CompileLoadConstant(String* name,
2975 JSObject* receiver,
2976 JSObject* holder,
2977 Object* value) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002978 // ----------- S t a t e -------------
2979 // -- ra : return address
2980 // -- a0 : key
2981 // -- a1 : receiver
2982 // -----------------------------------
2983 Label miss;
2984
2985 // Check the key is the cached one.
2986 __ Branch(&miss, ne, a0, Operand(Handle<String>(name)));
2987
2988 GenerateLoadConstant(receiver, holder, a1, a2, a3, t0, value, name, &miss);
2989 __ bind(&miss);
2990 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
2991
2992 // Return the generated code.
2993 return GetCode(CONSTANT_FUNCTION, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002994}
2995
2996
2997MaybeObject* KeyedLoadStubCompiler::CompileLoadInterceptor(JSObject* receiver,
2998 JSObject* holder,
2999 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003000 // ----------- S t a t e -------------
3001 // -- ra : return address
3002 // -- a0 : key
3003 // -- a1 : receiver
3004 // -----------------------------------
3005 Label miss;
3006
3007 // Check the key is the cached one.
3008 __ Branch(&miss, ne, a0, Operand(Handle<String>(name)));
3009
3010 LookupResult lookup;
3011 LookupPostInterceptor(holder, name, &lookup);
3012 GenerateLoadInterceptor(receiver,
3013 holder,
3014 &lookup,
3015 a1,
3016 a0,
3017 a2,
3018 a3,
3019 t0,
3020 name,
3021 &miss);
3022 __ bind(&miss);
3023 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
3024
3025 return GetCode(INTERCEPTOR, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003026}
3027
3028
3029MaybeObject* KeyedLoadStubCompiler::CompileLoadArrayLength(String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003030 // ----------- S t a t e -------------
3031 // -- ra : return address
3032 // -- a0 : key
3033 // -- a1 : receiver
3034 // -----------------------------------
3035 Label miss;
3036
3037 // Check the key is the cached one.
3038 __ Branch(&miss, ne, a0, Operand(Handle<String>(name)));
3039
3040 GenerateLoadArrayLength(masm(), a1, a2, &miss);
3041 __ bind(&miss);
3042 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
3043
3044 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003045}
3046
3047
3048MaybeObject* KeyedLoadStubCompiler::CompileLoadStringLength(String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003049 // ----------- S t a t e -------------
3050 // -- ra : return address
3051 // -- a0 : key
3052 // -- a1 : receiver
3053 // -----------------------------------
3054 Label miss;
3055
3056 Counters* counters = masm()->isolate()->counters();
3057 __ IncrementCounter(counters->keyed_load_string_length(), 1, a2, a3);
3058
3059 // Check the key is the cached one.
3060 __ Branch(&miss, ne, a0, Operand(Handle<String>(name)));
3061
3062 GenerateLoadStringLength(masm(), a1, a2, a3, &miss, true);
3063 __ bind(&miss);
3064 __ DecrementCounter(counters->keyed_load_string_length(), 1, a2, a3);
3065
3066 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
3067
3068 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003069}
3070
3071
3072MaybeObject* KeyedLoadStubCompiler::CompileLoadFunctionPrototype(String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003073 // ----------- S t a t e -------------
3074 // -- ra : return address
3075 // -- a0 : key
3076 // -- a1 : receiver
3077 // -----------------------------------
3078 Label miss;
3079
3080 Counters* counters = masm()->isolate()->counters();
3081 __ IncrementCounter(counters->keyed_load_function_prototype(), 1, a2, a3);
3082
3083 // Check the name hasn't changed.
3084 __ Branch(&miss, ne, a0, Operand(Handle<String>(name)));
3085
3086 GenerateLoadFunctionPrototype(masm(), a1, a2, a3, &miss);
3087 __ bind(&miss);
3088 __ DecrementCounter(counters->keyed_load_function_prototype(), 1, a2, a3);
3089 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
3090
3091 return GetCode(CALLBACKS, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003092}
3093
3094
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003095MaybeObject* KeyedLoadStubCompiler::CompileLoadElement(Map* receiver_map) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003096 // ----------- S t a t e -------------
3097 // -- ra : return address
3098 // -- a0 : key
3099 // -- a1 : receiver
3100 // -----------------------------------
danno@chromium.org40cb8782011-05-25 07:58:50 +00003101 Code* stub;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003102 MaybeObject* maybe_stub = ComputeSharedKeyedLoadElementStub(receiver_map);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003103 if (!maybe_stub->To(&stub)) return maybe_stub;
3104 __ DispatchMap(a1,
3105 a2,
3106 Handle<Map>(receiver_map),
3107 Handle<Code>(stub),
3108 DO_SMI_CHECK);
3109
3110 Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Miss();
3111 __ Jump(ic, RelocInfo::CODE_TARGET);
3112
3113 // Return the generated code.
3114 return GetCode(NORMAL, NULL);
3115}
3116
3117
3118MaybeObject* KeyedLoadStubCompiler::CompileLoadMegamorphic(
3119 MapList* receiver_maps,
3120 CodeList* handler_ics) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003121 // ----------- S t a t e -------------
3122 // -- ra : return address
3123 // -- a0 : key
3124 // -- a1 : receiver
3125 // -----------------------------------
3126 Label miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003127 __ JumpIfSmi(a1, &miss);
3128
danno@chromium.org40cb8782011-05-25 07:58:50 +00003129 int receiver_count = receiver_maps->length();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003130 __ lw(a2, FieldMemOperand(a1, HeapObject::kMapOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003131 for (int current = 0; current < receiver_count; ++current) {
3132 Handle<Map> map(receiver_maps->at(current));
3133 Handle<Code> code(handler_ics->at(current));
3134 __ Jump(code, RelocInfo::CODE_TARGET, eq, a2, Operand(map));
3135 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003136
3137 __ bind(&miss);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003138 Handle<Code> miss_ic = isolate()->builtins()->KeyedLoadIC_Miss();
3139 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003140
3141 // Return the generated code.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003142 return GetCode(NORMAL, NULL, MEGAMORPHIC);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003143}
3144
3145
3146MaybeObject* KeyedStoreStubCompiler::CompileStoreField(JSObject* object,
3147 int index,
3148 Map* transition,
3149 String* name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003150 // ----------- S t a t e -------------
3151 // -- a0 : value
3152 // -- a1 : key
3153 // -- a2 : receiver
3154 // -- ra : return address
3155 // -----------------------------------
3156
3157 Label miss;
3158
3159 Counters* counters = masm()->isolate()->counters();
3160 __ IncrementCounter(counters->keyed_store_field(), 1, a3, t0);
3161
3162 // Check that the name has not changed.
3163 __ Branch(&miss, ne, a1, Operand(Handle<String>(name)));
3164
3165 // a3 is used as scratch register. a1 and a2 keep their values if a jump to
3166 // the miss label is generated.
3167 GenerateStoreField(masm(),
3168 object,
3169 index,
3170 transition,
3171 a2, a1, a3,
3172 &miss);
3173 __ bind(&miss);
3174
3175 __ DecrementCounter(counters->keyed_store_field(), 1, a3, t0);
3176 Handle<Code> ic = masm()->isolate()->builtins()->KeyedStoreIC_Miss();
3177 __ Jump(ic, RelocInfo::CODE_TARGET);
3178
3179 // Return the generated code.
3180 return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003181}
3182
3183
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003184MaybeObject* KeyedStoreStubCompiler::CompileStoreElement(Map* receiver_map) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003185 // ----------- S t a t e -------------
3186 // -- a0 : value
3187 // -- a1 : key
3188 // -- a2 : receiver
3189 // -- ra : return address
3190 // -- a3 : scratch
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003191 // -----------------------------------
danno@chromium.org40cb8782011-05-25 07:58:50 +00003192 Code* stub;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003193 MaybeObject* maybe_stub = ComputeSharedKeyedStoreElementStub(receiver_map);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003194 if (!maybe_stub->To(&stub)) return maybe_stub;
3195 __ DispatchMap(a2,
3196 a3,
3197 Handle<Map>(receiver_map),
3198 Handle<Code>(stub),
3199 DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003200
danno@chromium.org40cb8782011-05-25 07:58:50 +00003201 Handle<Code> ic = isolate()->builtins()->KeyedStoreIC_Miss();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003202 __ Jump(ic, RelocInfo::CODE_TARGET);
3203
3204 // Return the generated code.
3205 return GetCode(NORMAL, NULL);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003206}
3207
3208
danno@chromium.org40cb8782011-05-25 07:58:50 +00003209MaybeObject* KeyedStoreStubCompiler::CompileStoreMegamorphic(
3210 MapList* receiver_maps,
3211 CodeList* handler_ics) {
3212 // ----------- S t a t e -------------
3213 // -- a0 : value
3214 // -- a1 : key
3215 // -- a2 : receiver
3216 // -- ra : return address
3217 // -- a3 : scratch
3218 // -----------------------------------
3219 Label miss;
3220 __ JumpIfSmi(a2, &miss);
3221
3222 int receiver_count = receiver_maps->length();
3223 __ lw(a3, FieldMemOperand(a2, HeapObject::kMapOffset));
3224 for (int current = 0; current < receiver_count; ++current) {
3225 Handle<Map> map(receiver_maps->at(current));
3226 Handle<Code> code(handler_ics->at(current));
3227 __ Jump(code, RelocInfo::CODE_TARGET, eq, a3, Operand(map));
3228 }
3229
3230 __ bind(&miss);
3231 Handle<Code> miss_ic = isolate()->builtins()->KeyedStoreIC_Miss();
3232 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
3233
3234 // Return the generated code.
3235 return GetCode(NORMAL, NULL, MEGAMORPHIC);
3236}
3237
3238
lrn@chromium.org7516f052011-03-30 08:52:27 +00003239MaybeObject* ConstructStubCompiler::CompileConstructStub(JSFunction* function) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003240 // a0 : argc
3241 // a1 : constructor
3242 // ra : return address
3243 // [sp] : last argument
3244 Label generic_stub_call;
3245
3246 // Use t7 for holding undefined which is used in several places below.
3247 __ LoadRoot(t7, Heap::kUndefinedValueRootIndex);
3248
3249#ifdef ENABLE_DEBUGGER_SUPPORT
3250 // Check to see whether there are any break points in the function code. If
3251 // there are jump to the generic constructor stub which calls the actual
3252 // code for the function thereby hitting the break points.
3253 __ lw(t5, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
3254 __ lw(a2, FieldMemOperand(t5, SharedFunctionInfo::kDebugInfoOffset));
3255 __ Branch(&generic_stub_call, ne, a2, Operand(t7));
3256#endif
3257
3258 // Load the initial map and verify that it is in fact a map.
3259 // a1: constructor function
3260 // t7: undefined
3261 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
3262 __ And(t0, a2, Operand(kSmiTagMask));
3263 __ Branch(&generic_stub_call, eq, t0, Operand(zero_reg));
3264 __ GetObjectType(a2, a3, t0);
3265 __ Branch(&generic_stub_call, ne, t0, Operand(MAP_TYPE));
3266
3267#ifdef DEBUG
3268 // Cannot construct functions this way.
3269 // a0: argc
3270 // a1: constructor function
3271 // a2: initial map
3272 // t7: undefined
3273 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceTypeOffset));
3274 __ Check(ne, "Function constructed by construct stub.",
3275 a3, Operand(JS_FUNCTION_TYPE));
3276#endif
3277
3278 // Now allocate the JSObject in new space.
3279 // a0: argc
3280 // a1: constructor function
3281 // a2: initial map
3282 // t7: undefined
3283 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceSizeOffset));
3284 __ AllocateInNewSpace(a3,
3285 t4,
3286 t5,
3287 t6,
3288 &generic_stub_call,
3289 SIZE_IN_WORDS);
3290
3291 // Allocated the JSObject, now initialize the fields. Map is set to initial
3292 // map and properties and elements are set to empty fixed array.
3293 // a0: argc
3294 // a1: constructor function
3295 // a2: initial map
3296 // a3: object size (in words)
3297 // t4: JSObject (not tagged)
3298 // t7: undefined
3299 __ LoadRoot(t6, Heap::kEmptyFixedArrayRootIndex);
3300 __ mov(t5, t4);
3301 __ sw(a2, MemOperand(t5, JSObject::kMapOffset));
3302 __ sw(t6, MemOperand(t5, JSObject::kPropertiesOffset));
3303 __ sw(t6, MemOperand(t5, JSObject::kElementsOffset));
3304 __ Addu(t5, t5, Operand(3 * kPointerSize));
3305 ASSERT_EQ(0 * kPointerSize, JSObject::kMapOffset);
3306 ASSERT_EQ(1 * kPointerSize, JSObject::kPropertiesOffset);
3307 ASSERT_EQ(2 * kPointerSize, JSObject::kElementsOffset);
3308
3309
3310 // Calculate the location of the first argument. The stack contains only the
3311 // argc arguments.
3312 __ sll(a1, a0, kPointerSizeLog2);
3313 __ Addu(a1, a1, sp);
3314
3315 // Fill all the in-object properties with undefined.
3316 // a0: argc
3317 // a1: first argument
3318 // a3: object size (in words)
3319 // t4: JSObject (not tagged)
3320 // t5: First in-object property of JSObject (not tagged)
3321 // t7: undefined
3322 // Fill the initialized properties with a constant value or a passed argument
3323 // depending on the this.x = ...; assignment in the function.
3324 SharedFunctionInfo* shared = function->shared();
3325 for (int i = 0; i < shared->this_property_assignments_count(); i++) {
3326 if (shared->IsThisPropertyAssignmentArgument(i)) {
3327 Label not_passed, next;
3328 // Check if the argument assigned to the property is actually passed.
3329 int arg_number = shared->GetThisPropertyAssignmentArgument(i);
3330 __ Branch(&not_passed, less_equal, a0, Operand(arg_number));
3331 // Argument passed - find it on the stack.
3332 __ lw(a2, MemOperand(a1, (arg_number + 1) * -kPointerSize));
3333 __ sw(a2, MemOperand(t5));
3334 __ Addu(t5, t5, kPointerSize);
3335 __ jmp(&next);
3336 __ bind(&not_passed);
3337 // Set the property to undefined.
3338 __ sw(t7, MemOperand(t5));
3339 __ Addu(t5, t5, Operand(kPointerSize));
3340 __ bind(&next);
3341 } else {
3342 // Set the property to the constant value.
3343 Handle<Object> constant(shared->GetThisPropertyAssignmentConstant(i));
3344 __ li(a2, Operand(constant));
3345 __ sw(a2, MemOperand(t5));
3346 __ Addu(t5, t5, kPointerSize);
3347 }
3348 }
3349
3350 // Fill the unused in-object property fields with undefined.
3351 ASSERT(function->has_initial_map());
3352 for (int i = shared->this_property_assignments_count();
3353 i < function->initial_map()->inobject_properties();
3354 i++) {
3355 __ sw(t7, MemOperand(t5));
3356 __ Addu(t5, t5, kPointerSize);
3357 }
3358
3359 // a0: argc
3360 // t4: JSObject (not tagged)
3361 // Move argc to a1 and the JSObject to return to v0 and tag it.
3362 __ mov(a1, a0);
3363 __ mov(v0, t4);
3364 __ Or(v0, v0, Operand(kHeapObjectTag));
3365
3366 // v0: JSObject
3367 // a1: argc
3368 // Remove caller arguments and receiver from the stack and return.
3369 __ sll(t0, a1, kPointerSizeLog2);
3370 __ Addu(sp, sp, t0);
3371 __ Addu(sp, sp, Operand(kPointerSize));
3372 Counters* counters = masm()->isolate()->counters();
3373 __ IncrementCounter(counters->constructed_objects(), 1, a1, a2);
3374 __ IncrementCounter(counters->constructed_objects_stub(), 1, a1, a2);
3375 __ Ret();
3376
3377 // Jump to the generic stub in case the specialized code cannot handle the
3378 // construction.
3379 __ bind(&generic_stub_call);
3380 Handle<Code> generic_construct_stub =
3381 masm()->isolate()->builtins()->JSConstructStubGeneric();
3382 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET);
3383
3384 // Return the generated code.
3385 return GetCode();
3386}
3387
3388
danno@chromium.org40cb8782011-05-25 07:58:50 +00003389#undef __
3390#define __ ACCESS_MASM(masm)
3391
3392
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003393static bool IsElementTypeSigned(JSObject::ElementsKind elements_kind) {
3394 switch (elements_kind) {
3395 case JSObject::EXTERNAL_BYTE_ELEMENTS:
3396 case JSObject::EXTERNAL_SHORT_ELEMENTS:
3397 case JSObject::EXTERNAL_INT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003398 return true;
3399
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003400 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
3401 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
3402 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS:
3403 case JSObject::EXTERNAL_PIXEL_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003404 return false;
3405
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003406 case JSObject::EXTERNAL_FLOAT_ELEMENTS:
3407 case JSObject::EXTERNAL_DOUBLE_ELEMENTS:
3408 case JSObject::FAST_ELEMENTS:
3409 case JSObject::FAST_DOUBLE_ELEMENTS:
3410 case JSObject::DICTIONARY_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003411 UNREACHABLE();
3412 return false;
3413 }
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003414 return false;
lrn@chromium.org7516f052011-03-30 08:52:27 +00003415}
3416
3417
danno@chromium.org40cb8782011-05-25 07:58:50 +00003418void KeyedLoadStubCompiler::GenerateLoadExternalArray(
3419 MacroAssembler* masm,
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003420 JSObject::ElementsKind elements_kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003421 // ---------- S t a t e --------------
3422 // -- ra : return address
3423 // -- a0 : key
3424 // -- a1 : receiver
3425 // -----------------------------------
danno@chromium.org40cb8782011-05-25 07:58:50 +00003426 Label miss_force_generic, slow, failed_allocation;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003427
3428 Register key = a0;
3429 Register receiver = a1;
3430
danno@chromium.org40cb8782011-05-25 07:58:50 +00003431 // This stub is meant to be tail-jumped to, the receiver must already
3432 // have been verified by the caller to not be a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003433
3434 // Check that the key is a smi.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003435 __ JumpIfNotSmi(key, &miss_force_generic);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003436
3437 __ lw(a3, FieldMemOperand(receiver, JSObject::kElementsOffset));
3438 // a3: elements array
3439
3440 // Check that the index is in range.
3441 __ lw(t1, FieldMemOperand(a3, ExternalArray::kLengthOffset));
3442 __ sra(t2, key, kSmiTagSize);
3443 // Unsigned comparison catches both negative and too-large values.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003444 __ Branch(&miss_force_generic, Uless, t1, Operand(t2));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003445
3446 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3447 // a3: base pointer of external storage
3448
3449 // We are not untagging smi key and instead work with it
3450 // as if it was premultiplied by 2.
3451 ASSERT((kSmiTag == 0) && (kSmiTagSize == 1));
3452
3453 Register value = a2;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003454 switch (elements_kind) {
3455 case JSObject::EXTERNAL_BYTE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003456 __ srl(t2, key, 1);
3457 __ addu(t3, a3, t2);
3458 __ lb(value, MemOperand(t3, 0));
3459 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003460 case JSObject::EXTERNAL_PIXEL_ELEMENTS:
3461 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003462 __ srl(t2, key, 1);
3463 __ addu(t3, a3, t2);
3464 __ lbu(value, MemOperand(t3, 0));
3465 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003466 case JSObject::EXTERNAL_SHORT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003467 __ addu(t3, a3, key);
3468 __ lh(value, MemOperand(t3, 0));
3469 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003470 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003471 __ addu(t3, a3, key);
3472 __ lhu(value, MemOperand(t3, 0));
3473 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003474 case JSObject::EXTERNAL_INT_ELEMENTS:
3475 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003476 __ sll(t2, key, 1);
3477 __ addu(t3, a3, t2);
3478 __ lw(value, MemOperand(t3, 0));
3479 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003480 case JSObject::EXTERNAL_FLOAT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003481 __ sll(t3, t2, 2);
3482 __ addu(t3, a3, t3);
3483 if (CpuFeatures::IsSupported(FPU)) {
3484 CpuFeatures::Scope scope(FPU);
3485 __ lwc1(f0, MemOperand(t3, 0));
3486 } else {
3487 __ lw(value, MemOperand(t3, 0));
3488 }
3489 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003490 case JSObject::EXTERNAL_DOUBLE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003491 __ sll(t2, key, 2);
3492 __ addu(t3, a3, t2);
3493 if (CpuFeatures::IsSupported(FPU)) {
3494 CpuFeatures::Scope scope(FPU);
3495 __ ldc1(f0, MemOperand(t3, 0));
3496 } else {
3497 // t3: pointer to the beginning of the double we want to load.
3498 __ lw(a2, MemOperand(t3, 0));
3499 __ lw(a3, MemOperand(t3, Register::kSizeInBytes));
3500 }
3501 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003502 case JSObject::FAST_ELEMENTS:
3503 case JSObject::FAST_DOUBLE_ELEMENTS:
3504 case JSObject::DICTIONARY_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003505 UNREACHABLE();
3506 break;
3507 }
3508
3509 // For integer array types:
3510 // a2: value
3511 // For float array type:
3512 // f0: value (if FPU is supported)
3513 // a2: value (if FPU is not supported)
3514 // For double array type:
3515 // f0: value (if FPU is supported)
3516 // a2/a3: value (if FPU is not supported)
3517
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003518 if (elements_kind == JSObject::EXTERNAL_INT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003519 // For the Int and UnsignedInt array types, we need to see whether
3520 // the value can be represented in a Smi. If not, we need to convert
3521 // it to a HeapNumber.
3522 Label box_int;
3523 __ Subu(t3, value, Operand(0xC0000000)); // Non-smi value gives neg result.
3524 __ Branch(&box_int, lt, t3, Operand(zero_reg));
3525 // Tag integer as smi and return it.
3526 __ sll(v0, value, kSmiTagSize);
3527 __ Ret();
3528
3529 __ bind(&box_int);
3530 // Allocate a HeapNumber for the result and perform int-to-double
3531 // conversion.
3532 // The arm version uses a temporary here to save r0, but we don't need to
3533 // (a0 is not modified).
3534 __ LoadRoot(t1, Heap::kHeapNumberMapRootIndex);
3535 __ AllocateHeapNumber(v0, a3, t0, t1, &slow);
3536
3537 if (CpuFeatures::IsSupported(FPU)) {
3538 CpuFeatures::Scope scope(FPU);
3539 __ mtc1(value, f0);
3540 __ cvt_d_w(f0, f0);
3541 __ sdc1(f0, MemOperand(v0, HeapNumber::kValueOffset - kHeapObjectTag));
3542 __ Ret();
3543 } else {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003544 Register dst1 = t2;
3545 Register dst2 = t3;
3546 FloatingPointHelper::Destination dest =
3547 FloatingPointHelper::kCoreRegisters;
3548 FloatingPointHelper::ConvertIntToDouble(masm,
3549 value,
3550 dest,
3551 f0,
3552 dst1,
3553 dst2,
3554 t1,
3555 f2);
3556 __ sw(dst1, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
3557 __ sw(dst2, FieldMemOperand(v0, HeapNumber::kExponentOffset));
3558 __ Ret();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003559 }
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003560 } else if (elements_kind == JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003561 // The test is different for unsigned int values. Since we need
3562 // the value to be in the range of a positive smi, we can't
3563 // handle either of the top two bits being set in the value.
3564 if (CpuFeatures::IsSupported(FPU)) {
3565 CpuFeatures::Scope scope(FPU);
3566 Label pl_box_int;
3567 __ And(t2, value, Operand(0xC0000000));
3568 __ Branch(&pl_box_int, ne, t2, Operand(zero_reg));
3569
3570 // It can fit in an Smi.
3571 // Tag integer as smi and return it.
3572 __ sll(v0, value, kSmiTagSize);
3573 __ Ret();
3574
3575 __ bind(&pl_box_int);
3576 // Allocate a HeapNumber for the result and perform int-to-double
3577 // conversion. Don't use a0 and a1 as AllocateHeapNumber clobbers all
3578 // registers - also when jumping due to exhausted young space.
3579 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3580 __ AllocateHeapNumber(v0, t2, t3, t6, &slow);
3581
3582 // This is replaced by a macro:
3583 // __ mtc1(value, f0); // LS 32-bits.
3584 // __ mtc1(zero_reg, f1); // MS 32-bits are all zero.
3585 // __ cvt_d_l(f0, f0); // Use 64 bit conv to get correct unsigned 32-bit.
3586
3587 __ Cvt_d_uw(f0, value);
3588
3589 __ sdc1(f0, MemOperand(v0, HeapNumber::kValueOffset - kHeapObjectTag));
3590
3591 __ Ret();
3592 } else {
3593 // Check whether unsigned integer fits into smi.
3594 Label box_int_0, box_int_1, done;
3595 __ And(t2, value, Operand(0x80000000));
3596 __ Branch(&box_int_0, ne, t2, Operand(zero_reg));
3597 __ And(t2, value, Operand(0x40000000));
3598 __ Branch(&box_int_1, ne, t2, Operand(zero_reg));
3599
3600 // Tag integer as smi and return it.
3601 __ sll(v0, value, kSmiTagSize);
3602 __ Ret();
3603
3604 Register hiword = value; // a2.
3605 Register loword = a3;
3606
3607 __ bind(&box_int_0);
3608 // Integer does not have leading zeros.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003609 GenerateUInt2Double(masm, hiword, loword, t0, 0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003610 __ Branch(&done);
3611
3612 __ bind(&box_int_1);
3613 // Integer has one leading zero.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003614 GenerateUInt2Double(masm, hiword, loword, t0, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003615
3616
3617 __ bind(&done);
3618 // Integer was converted to double in registers hiword:loword.
3619 // Wrap it into a HeapNumber. Don't use a0 and a1 as AllocateHeapNumber
3620 // clobbers all registers - also when jumping due to exhausted young
3621 // space.
3622 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3623 __ AllocateHeapNumber(t2, t3, t5, t6, &slow);
3624
3625 __ sw(hiword, FieldMemOperand(t2, HeapNumber::kExponentOffset));
3626 __ sw(loword, FieldMemOperand(t2, HeapNumber::kMantissaOffset));
3627
3628 __ mov(v0, t2);
3629 __ Ret();
3630 }
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003631 } else if (elements_kind == JSObject::EXTERNAL_FLOAT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003632 // For the floating-point array type, we need to always allocate a
3633 // HeapNumber.
3634 if (CpuFeatures::IsSupported(FPU)) {
3635 CpuFeatures::Scope scope(FPU);
3636 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3637 // AllocateHeapNumber clobbers all registers - also when jumping due to
3638 // exhausted young space.
3639 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3640 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3641 // The float (single) value is already in fpu reg f0 (if we use float).
3642 __ cvt_d_s(f0, f0);
3643 __ sdc1(f0, MemOperand(v0, HeapNumber::kValueOffset - kHeapObjectTag));
3644 __ Ret();
3645 } else {
3646 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3647 // AllocateHeapNumber clobbers all registers - also when jumping due to
3648 // exhausted young space.
3649 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3650 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3651 // FPU is not available, do manual single to double conversion.
3652
3653 // a2: floating point value (binary32).
3654 // v0: heap number for result
3655
3656 // Extract mantissa to t4.
3657 __ And(t4, value, Operand(kBinary32MantissaMask));
3658
3659 // Extract exponent to t5.
3660 __ srl(t5, value, kBinary32MantissaBits);
3661 __ And(t5, t5, Operand(kBinary32ExponentMask >> kBinary32MantissaBits));
3662
3663 Label exponent_rebiased;
3664 __ Branch(&exponent_rebiased, eq, t5, Operand(zero_reg));
3665
3666 __ li(t0, 0x7ff);
3667 __ Xor(t1, t5, Operand(0xFF));
3668 __ movz(t5, t0, t1); // Set t5 to 0x7ff only if t5 is equal to 0xff.
3669 __ Branch(&exponent_rebiased, eq, t0, Operand(0xff));
3670
3671 // Rebias exponent.
3672 __ Addu(t5,
3673 t5,
3674 Operand(-kBinary32ExponentBias + HeapNumber::kExponentBias));
3675
3676 __ bind(&exponent_rebiased);
3677 __ And(a2, value, Operand(kBinary32SignMask));
3678 value = no_reg;
3679 __ sll(t0, t5, HeapNumber::kMantissaBitsInTopWord);
3680 __ or_(a2, a2, t0);
3681
3682 // Shift mantissa.
3683 static const int kMantissaShiftForHiWord =
3684 kBinary32MantissaBits - HeapNumber::kMantissaBitsInTopWord;
3685
3686 static const int kMantissaShiftForLoWord =
3687 kBitsPerInt - kMantissaShiftForHiWord;
3688
3689 __ srl(t0, t4, kMantissaShiftForHiWord);
3690 __ or_(a2, a2, t0);
3691 __ sll(a0, t4, kMantissaShiftForLoWord);
3692
3693 __ sw(a2, FieldMemOperand(v0, HeapNumber::kExponentOffset));
3694 __ sw(a0, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
3695 __ Ret();
3696 }
3697
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003698 } else if (elements_kind == JSObject::EXTERNAL_DOUBLE_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003699 if (CpuFeatures::IsSupported(FPU)) {
3700 CpuFeatures::Scope scope(FPU);
3701 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3702 // AllocateHeapNumber clobbers all registers - also when jumping due to
3703 // exhausted young space.
3704 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3705 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3706 // The double value is already in f0
3707 __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
3708 __ Ret();
3709 } else {
3710 // Allocate a HeapNumber for the result. Don't use a0 and a1 as
3711 // AllocateHeapNumber clobbers all registers - also when jumping due to
3712 // exhausted young space.
3713 __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
3714 __ AllocateHeapNumber(v0, t3, t5, t6, &slow);
3715
3716 __ sw(a2, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
3717 __ sw(a3, FieldMemOperand(v0, HeapNumber::kExponentOffset));
3718 __ Ret();
3719 }
3720
3721 } else {
3722 // Tag integer as smi and return it.
3723 __ sll(v0, value, kSmiTagSize);
3724 __ Ret();
3725 }
3726
3727 // Slow case, key and receiver still in a0 and a1.
3728 __ bind(&slow);
3729 __ IncrementCounter(
danno@chromium.org40cb8782011-05-25 07:58:50 +00003730 masm->isolate()->counters()->keyed_load_external_array_slow(),
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003731 1, a2, a3);
3732
3733 // ---------- S t a t e --------------
3734 // -- ra : return address
3735 // -- a0 : key
3736 // -- a1 : receiver
3737 // -----------------------------------
3738
3739 __ Push(a1, a0);
3740
3741 __ TailCallRuntime(Runtime::kKeyedGetProperty, 2, 1);
3742
danno@chromium.org40cb8782011-05-25 07:58:50 +00003743 __ bind(&miss_force_generic);
3744 Code* stub = masm->isolate()->builtins()->builtin(
3745 Builtins::kKeyedLoadIC_MissForceGeneric);
3746 __ Jump(Handle<Code>(stub), RelocInfo::CODE_TARGET);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003747}
3748
3749
danno@chromium.org40cb8782011-05-25 07:58:50 +00003750void KeyedStoreStubCompiler::GenerateStoreExternalArray(
3751 MacroAssembler* masm,
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003752 JSObject::ElementsKind elements_kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003753 // ---------- S t a t e --------------
3754 // -- a0 : value
3755 // -- a1 : key
3756 // -- a2 : receiver
3757 // -- ra : return address
3758 // -----------------------------------
3759
danno@chromium.org40cb8782011-05-25 07:58:50 +00003760 Label slow, check_heap_number, miss_force_generic;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003761
3762 // Register usage.
3763 Register value = a0;
3764 Register key = a1;
3765 Register receiver = a2;
3766 // a3 mostly holds the elements array or the destination external array.
3767
danno@chromium.org40cb8782011-05-25 07:58:50 +00003768 // This stub is meant to be tail-jumped to, the receiver must already
3769 // have been verified by the caller to not be a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003770
3771 __ lw(a3, FieldMemOperand(receiver, JSObject::kElementsOffset));
3772
3773 // Check that the key is a smi.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003774 __ JumpIfNotSmi(key, &miss_force_generic);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003775
3776 // Check that the index is in range.
3777 __ SmiUntag(t0, key);
3778 __ lw(t1, FieldMemOperand(a3, ExternalArray::kLengthOffset));
3779 // Unsigned comparison catches both negative and too-large values.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003780 __ Branch(&miss_force_generic, Ugreater_equal, t0, Operand(t1));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003781
3782 // Handle both smis and HeapNumbers in the fast path. Go to the
3783 // runtime for all other kinds of values.
3784 // a3: external array.
3785 // t0: key (integer).
3786
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003787 if (elements_kind == JSObject::EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003788 // Double to pixel conversion is only implemented in the runtime for now.
3789 __ JumpIfNotSmi(value, &slow);
3790 } else {
3791 __ JumpIfNotSmi(value, &check_heap_number);
3792 }
3793 __ SmiUntag(t1, value);
3794 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3795
3796 // a3: base pointer of external storage.
3797 // t0: key (integer).
3798 // t1: value (integer).
3799
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003800 switch (elements_kind) {
3801 case JSObject::EXTERNAL_PIXEL_ELEMENTS: {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003802 // Clamp the value to [0..255].
3803 // v0 is used as a scratch register here.
3804 Label done;
3805 __ li(v0, Operand(255));
3806 // Normal branch: nop in delay slot.
3807 __ Branch(&done, gt, t1, Operand(v0));
3808 // Use delay slot in this branch.
3809 __ Branch(USE_DELAY_SLOT, &done, lt, t1, Operand(zero_reg));
3810 __ mov(v0, zero_reg); // In delay slot.
3811 __ mov(v0, t1); // Value is in range 0..255.
3812 __ bind(&done);
3813 __ mov(t1, v0);
3814 __ addu(t8, a3, t0);
3815 __ sb(t1, MemOperand(t8, 0));
3816 }
3817 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003818 case JSObject::EXTERNAL_BYTE_ELEMENTS:
3819 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003820 __ addu(t8, a3, t0);
3821 __ sb(t1, MemOperand(t8, 0));
3822 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003823 case JSObject::EXTERNAL_SHORT_ELEMENTS:
3824 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003825 __ sll(t8, t0, 1);
3826 __ addu(t8, a3, t8);
3827 __ sh(t1, MemOperand(t8, 0));
3828 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003829 case JSObject::EXTERNAL_INT_ELEMENTS:
3830 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003831 __ sll(t8, t0, 2);
3832 __ addu(t8, a3, t8);
3833 __ sw(t1, MemOperand(t8, 0));
3834 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003835 case JSObject::EXTERNAL_FLOAT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003836 // Perform int-to-float conversion and store to memory.
danno@chromium.org40cb8782011-05-25 07:58:50 +00003837 StoreIntAsFloat(masm, a3, t0, t1, t2, t3, t4);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003838 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003839 case JSObject::EXTERNAL_DOUBLE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003840 __ sll(t8, t0, 3);
3841 __ addu(a3, a3, t8);
3842 // a3: effective address of the double element
3843 FloatingPointHelper::Destination destination;
3844 if (CpuFeatures::IsSupported(FPU)) {
3845 destination = FloatingPointHelper::kFPURegisters;
3846 } else {
3847 destination = FloatingPointHelper::kCoreRegisters;
3848 }
3849 FloatingPointHelper::ConvertIntToDouble(
danno@chromium.org40cb8782011-05-25 07:58:50 +00003850 masm, t1, destination,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003851 f0, t2, t3, // These are: double_dst, dst1, dst2.
3852 t0, f2); // These are: scratch2, single_scratch.
3853 if (destination == FloatingPointHelper::kFPURegisters) {
3854 CpuFeatures::Scope scope(FPU);
3855 __ sdc1(f0, MemOperand(a3, 0));
3856 } else {
3857 __ sw(t2, MemOperand(a3, 0));
3858 __ sw(t3, MemOperand(a3, Register::kSizeInBytes));
3859 }
3860 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003861 case JSObject::FAST_ELEMENTS:
3862 case JSObject::FAST_DOUBLE_ELEMENTS:
3863 case JSObject::DICTIONARY_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003864 UNREACHABLE();
3865 break;
3866 }
3867
3868 // Entry registers are intact, a0 holds the value which is the return value.
3869 __ mov(v0, value);
3870 __ Ret();
3871
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003872 if (elements_kind != JSObject::EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003873 // a3: external array.
3874 // t0: index (integer).
3875 __ bind(&check_heap_number);
3876 __ GetObjectType(value, t1, t2);
3877 __ Branch(&slow, ne, t2, Operand(HEAP_NUMBER_TYPE));
3878
3879 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3880
3881 // a3: base pointer of external storage.
3882 // t0: key (integer).
3883
3884 // The WebGL specification leaves the behavior of storing NaN and
3885 // +/-Infinity into integer arrays basically undefined. For more
3886 // reproducible behavior, convert these to zero.
3887
3888 if (CpuFeatures::IsSupported(FPU)) {
3889 CpuFeatures::Scope scope(FPU);
3890
3891 __ ldc1(f0, FieldMemOperand(a0, HeapNumber::kValueOffset));
3892
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003893 if (elements_kind == JSObject::EXTERNAL_FLOAT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003894 __ cvt_s_d(f0, f0);
3895 __ sll(t8, t0, 2);
3896 __ addu(t8, a3, t8);
3897 __ swc1(f0, MemOperand(t8, 0));
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003898 } else if (elements_kind == JSObject::EXTERNAL_DOUBLE_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003899 __ sll(t8, t0, 3);
3900 __ addu(t8, a3, t8);
3901 __ sdc1(f0, MemOperand(t8, 0));
3902 } else {
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00003903 __ EmitECMATruncate(t3, f0, f2, t2, t1, t5);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003904
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003905 switch (elements_kind) {
3906 case JSObject::EXTERNAL_BYTE_ELEMENTS:
3907 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003908 __ addu(t8, a3, t0);
3909 __ sb(t3, MemOperand(t8, 0));
3910 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003911 case JSObject::EXTERNAL_SHORT_ELEMENTS:
3912 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003913 __ sll(t8, t0, 1);
3914 __ addu(t8, a3, t8);
3915 __ sh(t3, MemOperand(t8, 0));
3916 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003917 case JSObject::EXTERNAL_INT_ELEMENTS:
3918 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003919 __ sll(t8, t0, 2);
3920 __ addu(t8, a3, t8);
3921 __ sw(t3, MemOperand(t8, 0));
3922 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003923 case JSObject::EXTERNAL_PIXEL_ELEMENTS:
3924 case JSObject::EXTERNAL_FLOAT_ELEMENTS:
3925 case JSObject::EXTERNAL_DOUBLE_ELEMENTS:
3926 case JSObject::FAST_ELEMENTS:
3927 case JSObject::FAST_DOUBLE_ELEMENTS:
3928 case JSObject::DICTIONARY_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003929 UNREACHABLE();
3930 break;
3931 }
3932 }
3933
3934 // Entry registers are intact, a0 holds the value
3935 // which is the return value.
3936 __ mov(v0, value);
3937 __ Ret();
3938 } else {
3939 // FPU is not available, do manual conversions.
3940
3941 __ lw(t3, FieldMemOperand(value, HeapNumber::kExponentOffset));
3942 __ lw(t4, FieldMemOperand(value, HeapNumber::kMantissaOffset));
3943
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003944 if (elements_kind == JSObject::EXTERNAL_FLOAT_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003945 Label done, nan_or_infinity_or_zero;
3946 static const int kMantissaInHiWordShift =
3947 kBinary32MantissaBits - HeapNumber::kMantissaBitsInTopWord;
3948
3949 static const int kMantissaInLoWordShift =
3950 kBitsPerInt - kMantissaInHiWordShift;
3951
3952 // Test for all special exponent values: zeros, subnormal numbers, NaNs
3953 // and infinities. All these should be converted to 0.
3954 __ li(t5, HeapNumber::kExponentMask);
3955 __ and_(t6, t3, t5);
3956 __ Branch(&nan_or_infinity_or_zero, eq, t6, Operand(zero_reg));
3957
3958 __ xor_(t1, t6, t5);
3959 __ li(t2, kBinary32ExponentMask);
3960 __ movz(t6, t2, t1); // Only if t6 is equal to t5.
3961 __ Branch(&nan_or_infinity_or_zero, eq, t6, Operand(t5));
3962
3963 // Rebias exponent.
3964 __ srl(t6, t6, HeapNumber::kExponentShift);
3965 __ Addu(t6,
3966 t6,
3967 Operand(kBinary32ExponentBias - HeapNumber::kExponentBias));
3968
3969 __ li(t1, Operand(kBinary32MaxExponent));
3970 __ Slt(t1, t1, t6);
3971 __ And(t2, t3, Operand(HeapNumber::kSignMask));
3972 __ Or(t2, t2, Operand(kBinary32ExponentMask));
3973 __ movn(t3, t2, t1); // Only if t6 is gt kBinary32MaxExponent.
3974 __ Branch(&done, gt, t6, Operand(kBinary32MaxExponent));
3975
3976 __ Slt(t1, t6, Operand(kBinary32MinExponent));
3977 __ And(t2, t3, Operand(HeapNumber::kSignMask));
3978 __ movn(t3, t2, t1); // Only if t6 is lt kBinary32MinExponent.
3979 __ Branch(&done, lt, t6, Operand(kBinary32MinExponent));
3980
3981 __ And(t7, t3, Operand(HeapNumber::kSignMask));
3982 __ And(t3, t3, Operand(HeapNumber::kMantissaMask));
3983 __ sll(t3, t3, kMantissaInHiWordShift);
3984 __ or_(t7, t7, t3);
3985 __ srl(t4, t4, kMantissaInLoWordShift);
3986 __ or_(t7, t7, t4);
3987 __ sll(t6, t6, kBinary32ExponentShift);
3988 __ or_(t3, t7, t6);
3989
3990 __ bind(&done);
3991 __ sll(t9, a1, 2);
3992 __ addu(t9, a2, t9);
3993 __ sw(t3, MemOperand(t9, 0));
3994
3995 // Entry registers are intact, a0 holds the value which is the return
3996 // value.
3997 __ mov(v0, value);
3998 __ Ret();
3999
4000 __ bind(&nan_or_infinity_or_zero);
4001 __ And(t7, t3, Operand(HeapNumber::kSignMask));
4002 __ And(t3, t3, Operand(HeapNumber::kMantissaMask));
4003 __ or_(t6, t6, t7);
4004 __ sll(t3, t3, kMantissaInHiWordShift);
4005 __ or_(t6, t6, t3);
4006 __ srl(t4, t4, kMantissaInLoWordShift);
4007 __ or_(t3, t6, t4);
4008 __ Branch(&done);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004009 } else if (elements_kind == JSObject::EXTERNAL_DOUBLE_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004010 __ sll(t8, t0, 3);
4011 __ addu(t8, a3, t8);
4012 // t8: effective address of destination element.
4013 __ sw(t4, MemOperand(t8, 0));
4014 __ sw(t3, MemOperand(t8, Register::kSizeInBytes));
4015 __ Ret();
4016 } else {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004017 bool is_signed_type = IsElementTypeSigned(elements_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004018 int meaningfull_bits = is_signed_type ? (kBitsPerInt - 1) : kBitsPerInt;
4019 int32_t min_value = is_signed_type ? 0x80000000 : 0x00000000;
4020
4021 Label done, sign;
4022
4023 // Test for all special exponent values: zeros, subnormal numbers, NaNs
4024 // and infinities. All these should be converted to 0.
4025 __ li(t5, HeapNumber::kExponentMask);
4026 __ and_(t6, t3, t5);
4027 __ movz(t3, zero_reg, t6); // Only if t6 is equal to zero.
4028 __ Branch(&done, eq, t6, Operand(zero_reg));
4029
4030 __ xor_(t2, t6, t5);
4031 __ movz(t3, zero_reg, t2); // Only if t6 is equal to t5.
4032 __ Branch(&done, eq, t6, Operand(t5));
4033
4034 // Unbias exponent.
4035 __ srl(t6, t6, HeapNumber::kExponentShift);
4036 __ Subu(t6, t6, Operand(HeapNumber::kExponentBias));
4037 // If exponent is negative then result is 0.
4038 __ slt(t2, t6, zero_reg);
4039 __ movn(t3, zero_reg, t2); // Only if exponent is negative.
4040 __ Branch(&done, lt, t6, Operand(zero_reg));
4041
4042 // If exponent is too big then result is minimal value.
4043 __ slti(t1, t6, meaningfull_bits - 1);
4044 __ li(t2, min_value);
4045 __ movz(t3, t2, t1); // Only if t6 is ge meaningfull_bits - 1.
4046 __ Branch(&done, ge, t6, Operand(meaningfull_bits - 1));
4047
4048 __ And(t5, t3, Operand(HeapNumber::kSignMask));
4049 __ And(t3, t3, Operand(HeapNumber::kMantissaMask));
4050 __ Or(t3, t3, Operand(1u << HeapNumber::kMantissaBitsInTopWord));
4051
4052 __ li(t9, HeapNumber::kMantissaBitsInTopWord);
4053 __ subu(t6, t9, t6);
4054 __ slt(t1, t6, zero_reg);
4055 __ srlv(t2, t3, t6);
4056 __ movz(t3, t2, t1); // Only if t6 is positive.
4057 __ Branch(&sign, ge, t6, Operand(zero_reg));
4058
4059 __ subu(t6, zero_reg, t6);
4060 __ sllv(t3, t3, t6);
4061 __ li(t9, meaningfull_bits);
4062 __ subu(t6, t9, t6);
4063 __ srlv(t4, t4, t6);
4064 __ or_(t3, t3, t4);
4065
4066 __ bind(&sign);
4067 __ subu(t2, t3, zero_reg);
4068 __ movz(t3, t2, t5); // Only if t5 is zero.
4069
4070 __ bind(&done);
4071
4072 // Result is in t3.
4073 // This switch block should be exactly the same as above (FPU mode).
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004074 switch (elements_kind) {
4075 case JSObject::EXTERNAL_BYTE_ELEMENTS:
4076 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004077 __ addu(t8, a3, t0);
4078 __ sb(t3, MemOperand(t8, 0));
4079 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004080 case JSObject::EXTERNAL_SHORT_ELEMENTS:
4081 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004082 __ sll(t8, t0, 1);
4083 __ addu(t8, a3, t8);
4084 __ sh(t3, MemOperand(t8, 0));
4085 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004086 case JSObject::EXTERNAL_INT_ELEMENTS:
4087 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004088 __ sll(t8, t0, 2);
4089 __ addu(t8, a3, t8);
4090 __ sw(t3, MemOperand(t8, 0));
4091 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004092 case JSObject::EXTERNAL_PIXEL_ELEMENTS:
4093 case JSObject::EXTERNAL_FLOAT_ELEMENTS:
4094 case JSObject::EXTERNAL_DOUBLE_ELEMENTS:
4095 case JSObject::FAST_ELEMENTS:
4096 case JSObject::FAST_DOUBLE_ELEMENTS:
4097 case JSObject::DICTIONARY_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004098 UNREACHABLE();
4099 break;
4100 }
4101 }
4102 }
4103 }
4104
danno@chromium.org40cb8782011-05-25 07:58:50 +00004105 // Slow case, key and receiver still in a0 and a1.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004106 __ bind(&slow);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004107 __ IncrementCounter(
4108 masm->isolate()->counters()->keyed_load_external_array_slow(),
4109 1, a2, a3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004110 // Entry registers are intact.
4111 // ---------- S t a t e --------------
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004112 // -- ra : return address
danno@chromium.org40cb8782011-05-25 07:58:50 +00004113 // -- a0 : key
4114 // -- a1 : receiver
4115 // -----------------------------------
4116 Handle<Code> slow_ic =
4117 masm->isolate()->builtins()->KeyedStoreIC_Slow();
4118 __ Jump(slow_ic, RelocInfo::CODE_TARGET);
4119
4120 // Miss case, call the runtime.
4121 __ bind(&miss_force_generic);
4122
4123 // ---------- S t a t e --------------
4124 // -- ra : return address
4125 // -- a0 : key
4126 // -- a1 : receiver
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004127 // -----------------------------------
4128
danno@chromium.org40cb8782011-05-25 07:58:50 +00004129 Handle<Code> miss_ic =
4130 masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric();
4131 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
4132}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004133
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004134
danno@chromium.org40cb8782011-05-25 07:58:50 +00004135void KeyedLoadStubCompiler::GenerateLoadFastElement(MacroAssembler* masm) {
4136 // ----------- S t a t e -------------
4137 // -- ra : return address
4138 // -- a0 : key
4139 // -- a1 : receiver
4140 // -----------------------------------
4141 Label miss_force_generic;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004142
danno@chromium.org40cb8782011-05-25 07:58:50 +00004143 // This stub is meant to be tail-jumped to, the receiver must already
4144 // have been verified by the caller to not be a smi.
4145
4146 // Check that the key is a smi.
4147 __ JumpIfNotSmi(a0, &miss_force_generic);
4148
4149 // Get the elements array.
4150 __ lw(a2, FieldMemOperand(a1, JSObject::kElementsOffset));
4151 __ AssertFastElements(a2);
4152
4153 // Check that the key is within bounds.
4154 __ lw(a3, FieldMemOperand(a2, FixedArray::kLengthOffset));
4155 __ Branch(&miss_force_generic, hs, a0, Operand(a3));
4156
4157 // Load the result and make sure it's not the hole.
4158 __ Addu(a3, a2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4159 ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
4160 __ sll(t0, a0, kPointerSizeLog2 - kSmiTagSize);
4161 __ Addu(t0, t0, a3);
4162 __ lw(t0, MemOperand(t0));
4163 __ LoadRoot(t1, Heap::kTheHoleValueRootIndex);
4164 __ Branch(&miss_force_generic, eq, t0, Operand(t1));
4165 __ mov(v0, t0);
4166 __ Ret();
4167
4168 __ bind(&miss_force_generic);
4169 Code* stub = masm->isolate()->builtins()->builtin(
4170 Builtins::kKeyedLoadIC_MissForceGeneric);
4171 __ Jump(Handle<Code>(stub), RelocInfo::CODE_TARGET);
4172}
4173
4174
4175void KeyedStoreStubCompiler::GenerateStoreFastElement(MacroAssembler* masm,
4176 bool is_js_array) {
4177 // ----------- S t a t e -------------
4178 // -- a0 : value
4179 // -- a1 : key
4180 // -- a2 : receiver
4181 // -- ra : return address
4182 // -- a3 : scratch
4183 // -- a4 : scratch (elements)
4184 // -----------------------------------
4185 Label miss_force_generic;
4186
4187 Register value_reg = a0;
4188 Register key_reg = a1;
4189 Register receiver_reg = a2;
4190 Register scratch = a3;
4191 Register elements_reg = t0;
4192 Register scratch2 = t1;
4193 Register scratch3 = t2;
4194
4195 // This stub is meant to be tail-jumped to, the receiver must already
4196 // have been verified by the caller to not be a smi.
4197
4198 // Check that the key is a smi.
4199 __ JumpIfNotSmi(a0, &miss_force_generic);
4200
4201 // Get the elements array and make sure it is a fast element array, not 'cow'.
4202 __ lw(elements_reg,
4203 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4204 __ CheckMap(elements_reg,
4205 scratch,
4206 Heap::kFixedArrayMapRootIndex,
4207 &miss_force_generic,
4208 DONT_DO_SMI_CHECK);
4209
4210 // Check that the key is within bounds.
4211 if (is_js_array) {
4212 __ lw(scratch, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4213 } else {
4214 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4215 }
4216 // Compare smis.
4217 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch));
4218
4219 __ Addu(scratch,
4220 elements_reg, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4221 ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
4222 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
4223 __ Addu(scratch3, scratch2, scratch);
4224 __ sw(value_reg, MemOperand(scratch3));
4225 __ RecordWrite(scratch, Operand(scratch2), receiver_reg , elements_reg);
4226
4227 // value_reg (a0) is preserved.
4228 // Done.
4229 __ Ret();
4230
4231 __ bind(&miss_force_generic);
4232 Handle<Code> ic =
4233 masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric();
4234 __ Jump(ic, RelocInfo::CODE_TARGET);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00004235}
4236
4237
ager@chromium.org5c838252010-02-19 08:53:10 +00004238#undef __
4239
4240} } // namespace v8::internal
4241
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00004242#endif // V8_TARGET_ARCH_MIPS