jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2 | // 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.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 30 | #if defined(V8_TARGET_ARCH_MIPS) |
| 31 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 32 | #include "ic-inl.h" |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 33 | #include "codegen.h" |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 34 | #include "stub-cache.h" |
| 35 | |
| 36 | namespace v8 { |
| 37 | namespace internal { |
| 38 | |
| 39 | #define __ ACCESS_MASM(masm) |
| 40 | |
| 41 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 42 | static void ProbeTable(Isolate* isolate, |
| 43 | MacroAssembler* masm, |
| 44 | Code::Flags flags, |
| 45 | StubCache::Table table, |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 46 | Register receiver, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 47 | Register name, |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 48 | // Number of the cache entry, not scaled. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 49 | Register offset, |
| 50 | Register scratch, |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 51 | Register scratch2, |
| 52 | Register offset_scratch) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 53 | ExternalReference key_offset(isolate->stub_cache()->key_reference(table)); |
| 54 | ExternalReference value_offset(isolate->stub_cache()->value_reference(table)); |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 55 | ExternalReference map_offset(isolate->stub_cache()->map_reference(table)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 56 | |
| 57 | uint32_t key_off_addr = reinterpret_cast<uint32_t>(key_offset.address()); |
| 58 | uint32_t value_off_addr = reinterpret_cast<uint32_t>(value_offset.address()); |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 59 | uint32_t map_off_addr = reinterpret_cast<uint32_t>(map_offset.address()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 60 | |
| 61 | // Check the relative positions of the address fields. |
| 62 | ASSERT(value_off_addr > key_off_addr); |
| 63 | ASSERT((value_off_addr - key_off_addr) % 4 == 0); |
| 64 | ASSERT((value_off_addr - key_off_addr) < (256 * 4)); |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 65 | ASSERT(map_off_addr > key_off_addr); |
| 66 | ASSERT((map_off_addr - key_off_addr) % 4 == 0); |
| 67 | ASSERT((map_off_addr - key_off_addr) < (256 * 4)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 68 | |
| 69 | Label miss; |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 70 | Register base_addr = scratch; |
| 71 | scratch = no_reg; |
| 72 | |
| 73 | // Multiply by 3 because there are 3 fields per entry (name, code, map). |
| 74 | __ sll(offset_scratch, offset, 1); |
| 75 | __ Addu(offset_scratch, offset_scratch, offset); |
| 76 | |
| 77 | // Calculate the base address of the entry. |
| 78 | __ li(base_addr, Operand(key_offset)); |
| 79 | __ sll(at, offset_scratch, kPointerSizeLog2); |
| 80 | __ Addu(base_addr, base_addr, at); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 81 | |
| 82 | // Check that the key in the entry matches the name. |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 83 | __ lw(at, MemOperand(base_addr, 0)); |
| 84 | __ Branch(&miss, ne, name, Operand(at)); |
| 85 | |
| 86 | // Check the map matches. |
| 87 | __ lw(at, MemOperand(base_addr, map_off_addr - key_off_addr)); |
| 88 | __ lw(scratch2, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 89 | __ Branch(&miss, ne, at, Operand(scratch2)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 90 | |
| 91 | // Get the code entry from the cache. |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 92 | Register code = scratch2; |
| 93 | scratch2 = no_reg; |
| 94 | __ lw(code, MemOperand(base_addr, value_off_addr - key_off_addr)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 95 | |
| 96 | // Check that the flags match what we're looking for. |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 97 | Register flags_reg = base_addr; |
| 98 | base_addr = no_reg; |
| 99 | __ lw(flags_reg, FieldMemOperand(code, Code::kFlagsOffset)); |
| 100 | __ And(flags_reg, flags_reg, Operand(~Code::kFlagsNotUsedInLookup)); |
| 101 | __ Branch(&miss, ne, flags_reg, Operand(flags)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 102 | |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 103 | #ifdef DEBUG |
| 104 | if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { |
| 105 | __ jmp(&miss); |
| 106 | } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { |
| 107 | __ jmp(&miss); |
| 108 | } |
| 109 | #endif |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 110 | |
| 111 | // Jump to the first instruction in the code stub. |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 112 | __ Addu(at, code, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 113 | __ Jump(at); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 114 | |
| 115 | // Miss: fall through. |
| 116 | __ bind(&miss); |
| 117 | } |
| 118 | |
| 119 | |
| 120 | // Helper function used to check that the dictionary doesn't contain |
| 121 | // the property. This function may return false negatives, so miss_label |
| 122 | // must always call a backup property check that is complete. |
| 123 | // This function is safe to call if the receiver has fast properties. |
| 124 | // Name must be a symbol and receiver must be a heap object. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 125 | static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, |
| 126 | Label* miss_label, |
| 127 | Register receiver, |
| 128 | Handle<String> name, |
| 129 | Register scratch0, |
| 130 | Register scratch1) { |
| 131 | ASSERT(name->IsSymbol()); |
| 132 | Counters* counters = masm->isolate()->counters(); |
| 133 | __ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1); |
| 134 | __ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1); |
| 135 | |
| 136 | Label done; |
| 137 | |
| 138 | const int kInterceptorOrAccessCheckNeededMask = |
| 139 | (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded); |
| 140 | |
| 141 | // Bail out if the receiver has a named interceptor or requires access checks. |
| 142 | Register map = scratch1; |
| 143 | __ lw(map, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 144 | __ lbu(scratch0, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 145 | __ And(scratch0, scratch0, Operand(kInterceptorOrAccessCheckNeededMask)); |
| 146 | __ Branch(miss_label, ne, scratch0, Operand(zero_reg)); |
| 147 | |
| 148 | // Check that receiver is a JSObject. |
| 149 | __ lbu(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 150 | __ Branch(miss_label, lt, scratch0, Operand(FIRST_SPEC_OBJECT_TYPE)); |
| 151 | |
| 152 | // Load properties array. |
| 153 | Register properties = scratch0; |
| 154 | __ lw(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 155 | // Check that the properties array is a dictionary. |
| 156 | __ lw(map, FieldMemOperand(properties, HeapObject::kMapOffset)); |
| 157 | Register tmp = properties; |
| 158 | __ LoadRoot(tmp, Heap::kHashTableMapRootIndex); |
| 159 | __ Branch(miss_label, ne, map, Operand(tmp)); |
| 160 | |
| 161 | // Restore the temporarily used register. |
| 162 | __ lw(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 163 | |
| 164 | |
| 165 | StringDictionaryLookupStub::GenerateNegativeLookup(masm, |
| 166 | miss_label, |
| 167 | &done, |
| 168 | receiver, |
| 169 | properties, |
| 170 | name, |
| 171 | scratch1); |
| 172 | __ bind(&done); |
| 173 | __ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1); |
| 174 | } |
| 175 | |
| 176 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 177 | void StubCache::GenerateProbe(MacroAssembler* masm, |
| 178 | Code::Flags flags, |
| 179 | Register receiver, |
| 180 | Register name, |
| 181 | Register scratch, |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 182 | Register extra, |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 183 | Register extra2, |
| 184 | Register extra3) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 185 | Isolate* isolate = masm->isolate(); |
| 186 | Label miss; |
| 187 | |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 188 | // Make sure that code is valid. The multiplying code relies on the |
| 189 | // entry size being 12. |
| 190 | ASSERT(sizeof(Entry) == 12); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 191 | |
| 192 | // Make sure the flags does not name a specific type. |
| 193 | ASSERT(Code::ExtractTypeFromFlags(flags) == 0); |
| 194 | |
| 195 | // Make sure that there are no register conflicts. |
| 196 | ASSERT(!scratch.is(receiver)); |
| 197 | ASSERT(!scratch.is(name)); |
| 198 | ASSERT(!extra.is(receiver)); |
| 199 | ASSERT(!extra.is(name)); |
| 200 | ASSERT(!extra.is(scratch)); |
| 201 | ASSERT(!extra2.is(receiver)); |
| 202 | ASSERT(!extra2.is(name)); |
| 203 | ASSERT(!extra2.is(scratch)); |
| 204 | ASSERT(!extra2.is(extra)); |
| 205 | |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 206 | // Check register validity. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 207 | ASSERT(!scratch.is(no_reg)); |
| 208 | ASSERT(!extra.is(no_reg)); |
| 209 | ASSERT(!extra2.is(no_reg)); |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 210 | ASSERT(!extra3.is(no_reg)); |
| 211 | |
| 212 | Counters* counters = masm->isolate()->counters(); |
| 213 | __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1, |
| 214 | extra2, extra3); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 215 | |
| 216 | // Check that the receiver isn't a smi. |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 217 | __ JumpIfSmi(receiver, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 218 | |
| 219 | // Get the map of the receiver and compute the hash. |
| 220 | __ lw(scratch, FieldMemOperand(name, String::kHashFieldOffset)); |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 221 | __ lw(at, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 222 | __ Addu(scratch, scratch, at); |
| 223 | uint32_t mask = kPrimaryTableSize - 1; |
| 224 | // We shift out the last two bits because they are not part of the hash and |
| 225 | // they are always 01 for maps. |
| 226 | __ srl(scratch, scratch, kHeapObjectTagSize); |
| 227 | __ Xor(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask)); |
| 228 | __ And(scratch, scratch, Operand(mask)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 229 | |
| 230 | // Probe the primary table. |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 231 | ProbeTable(isolate, |
| 232 | masm, |
| 233 | flags, |
| 234 | kPrimary, |
| 235 | receiver, |
| 236 | name, |
| 237 | scratch, |
| 238 | extra, |
| 239 | extra2, |
| 240 | extra3); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 241 | |
| 242 | // Primary miss: Compute hash for secondary probe. |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 243 | __ srl(at, name, kHeapObjectTagSize); |
| 244 | __ Subu(scratch, scratch, at); |
| 245 | uint32_t mask2 = kSecondaryTableSize - 1; |
| 246 | __ Addu(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask2)); |
| 247 | __ And(scratch, scratch, Operand(mask2)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 248 | |
| 249 | // Probe the secondary table. |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 250 | ProbeTable(isolate, |
| 251 | masm, |
| 252 | flags, |
| 253 | kSecondary, |
| 254 | receiver, |
| 255 | name, |
| 256 | scratch, |
| 257 | extra, |
| 258 | extra2, |
| 259 | extra3); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 260 | |
| 261 | // Cache miss: Fall-through and let caller handle the miss by |
| 262 | // entering the runtime system. |
| 263 | __ bind(&miss); |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 264 | __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1, |
| 265 | extra2, extra3); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | |
| 269 | void StubCompiler::GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, |
| 270 | int index, |
| 271 | Register prototype) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 272 | // Load the global or builtins object from the current context. |
| 273 | __ lw(prototype, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 274 | // Load the global context from the global or builtins object. |
| 275 | __ lw(prototype, |
| 276 | FieldMemOperand(prototype, GlobalObject::kGlobalContextOffset)); |
| 277 | // Load the function from the global context. |
| 278 | __ lw(prototype, MemOperand(prototype, Context::SlotOffset(index))); |
| 279 | // Load the initial map. The global functions all have initial maps. |
| 280 | __ lw(prototype, |
| 281 | FieldMemOperand(prototype, JSFunction::kPrototypeOrInitialMapOffset)); |
| 282 | // Load the prototype from the initial map. |
| 283 | __ lw(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 287 | void StubCompiler::GenerateDirectLoadGlobalFunctionPrototype( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 288 | MacroAssembler* masm, |
| 289 | int index, |
| 290 | Register prototype, |
| 291 | Label* miss) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 292 | Isolate* isolate = masm->isolate(); |
| 293 | // Check we're still in the same context. |
| 294 | __ lw(prototype, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 295 | ASSERT(!prototype.is(at)); |
| 296 | __ li(at, isolate->global()); |
| 297 | __ Branch(miss, ne, prototype, Operand(at)); |
| 298 | // Get the global function with the given index. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 299 | Handle<JSFunction> function( |
| 300 | JSFunction::cast(isolate->global_context()->get(index))); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 301 | // Load its initial map. The global functions all have initial maps. |
| 302 | __ li(prototype, Handle<Map>(function->initial_map())); |
| 303 | // Load the prototype from the initial map. |
| 304 | __ lw(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 308 | // Load a fast property out of a holder object (src). In-object properties |
| 309 | // are loaded directly otherwise the property is loaded from the properties |
| 310 | // fixed array. |
| 311 | void StubCompiler::GenerateFastPropertyLoad(MacroAssembler* masm, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 312 | Register dst, |
| 313 | Register src, |
| 314 | Handle<JSObject> holder, |
| 315 | int index) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 316 | // Adjust for the number of properties stored in the holder. |
| 317 | index -= holder->map()->inobject_properties(); |
| 318 | if (index < 0) { |
| 319 | // Get the property straight out of the holder. |
| 320 | int offset = holder->map()->instance_size() + (index * kPointerSize); |
| 321 | __ lw(dst, FieldMemOperand(src, offset)); |
| 322 | } else { |
| 323 | // Calculate the offset into the properties array. |
| 324 | int offset = index * kPointerSize + FixedArray::kHeaderSize; |
| 325 | __ lw(dst, FieldMemOperand(src, JSObject::kPropertiesOffset)); |
| 326 | __ lw(dst, FieldMemOperand(dst, offset)); |
| 327 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | |
| 331 | void StubCompiler::GenerateLoadArrayLength(MacroAssembler* masm, |
| 332 | Register receiver, |
| 333 | Register scratch, |
| 334 | Label* miss_label) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 335 | // Check that the receiver isn't a smi. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 336 | __ JumpIfSmi(receiver, miss_label); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 337 | |
| 338 | // Check that the object is a JS array. |
| 339 | __ GetObjectType(receiver, scratch, scratch); |
| 340 | __ Branch(miss_label, ne, scratch, Operand(JS_ARRAY_TYPE)); |
| 341 | |
| 342 | // Load length directly from the JS array. |
| 343 | __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
| 344 | __ Ret(); |
| 345 | } |
| 346 | |
| 347 | |
| 348 | // Generate code to check if an object is a string. If the object is a |
| 349 | // heap object, its map's instance type is left in the scratch1 register. |
| 350 | // If this is not needed, scratch1 and scratch2 may be the same register. |
| 351 | static void GenerateStringCheck(MacroAssembler* masm, |
| 352 | Register receiver, |
| 353 | Register scratch1, |
| 354 | Register scratch2, |
| 355 | Label* smi, |
| 356 | Label* non_string_object) { |
| 357 | // Check that the receiver isn't a smi. |
| 358 | __ JumpIfSmi(receiver, smi, t0); |
| 359 | |
| 360 | // Check that the object is a string. |
| 361 | __ lw(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 362 | __ lbu(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset)); |
| 363 | __ And(scratch2, scratch1, Operand(kIsNotStringMask)); |
| 364 | // The cast is to resolve the overload for the argument of 0x0. |
| 365 | __ Branch(non_string_object, |
| 366 | ne, |
| 367 | scratch2, |
| 368 | Operand(static_cast<int32_t>(kStringTag))); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 372 | // Generate code to load the length from a string object and return the length. |
| 373 | // If the receiver object is not a string or a wrapped string object the |
| 374 | // execution continues at the miss label. The register containing the |
| 375 | // receiver is potentially clobbered. |
| 376 | void StubCompiler::GenerateLoadStringLength(MacroAssembler* masm, |
| 377 | Register receiver, |
| 378 | Register scratch1, |
| 379 | Register scratch2, |
| 380 | Label* miss, |
| 381 | bool support_wrappers) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 382 | Label check_wrapper; |
| 383 | |
| 384 | // Check if the object is a string leaving the instance type in the |
| 385 | // scratch1 register. |
| 386 | GenerateStringCheck(masm, receiver, scratch1, scratch2, miss, |
| 387 | support_wrappers ? &check_wrapper : miss); |
| 388 | |
| 389 | // Load length directly from the string. |
| 390 | __ lw(v0, FieldMemOperand(receiver, String::kLengthOffset)); |
| 391 | __ Ret(); |
| 392 | |
| 393 | if (support_wrappers) { |
| 394 | // Check if the object is a JSValue wrapper. |
| 395 | __ bind(&check_wrapper); |
| 396 | __ Branch(miss, ne, scratch1, Operand(JS_VALUE_TYPE)); |
| 397 | |
| 398 | // Unwrap the value and check if the wrapped value is a string. |
| 399 | __ lw(scratch1, FieldMemOperand(receiver, JSValue::kValueOffset)); |
| 400 | GenerateStringCheck(masm, scratch1, scratch2, scratch2, miss, miss); |
| 401 | __ lw(v0, FieldMemOperand(scratch1, String::kLengthOffset)); |
| 402 | __ Ret(); |
| 403 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 407 | void StubCompiler::GenerateLoadFunctionPrototype(MacroAssembler* masm, |
| 408 | Register receiver, |
| 409 | Register scratch1, |
| 410 | Register scratch2, |
| 411 | Label* miss_label) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 412 | __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label); |
| 413 | __ mov(v0, scratch1); |
| 414 | __ Ret(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 418 | // Generate StoreField code, value is passed in a0 register. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 419 | // After executing generated code, the receiver_reg and name_reg |
| 420 | // may be clobbered. |
| 421 | void StubCompiler::GenerateStoreField(MacroAssembler* masm, |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 422 | Handle<JSObject> object, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 423 | int index, |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 424 | Handle<Map> transition, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 425 | Handle<String> name, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 426 | Register receiver_reg, |
| 427 | Register name_reg, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 428 | Register scratch1, |
| 429 | Register scratch2, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 430 | Label* miss_label) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 431 | // a0 : value. |
| 432 | Label exit; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 433 | |
| 434 | LookupResult lookup(masm->isolate()); |
| 435 | object->Lookup(*name, &lookup); |
| 436 | if (lookup.IsFound() && (lookup.IsReadOnly() || !lookup.IsCacheable())) { |
| 437 | // In sloppy mode, we could just return the value and be done. However, we |
| 438 | // might be in strict mode, where we have to throw. Since we cannot tell, |
| 439 | // go into slow case unconditionally. |
| 440 | __ jmp(miss_label); |
| 441 | return; |
| 442 | } |
| 443 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 444 | // Check that the map of the object hasn't changed. |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 445 | CompareMapMode mode = transition.is_null() ? ALLOW_ELEMENT_TRANSITION_MAPS |
| 446 | : REQUIRE_EXACT_MAP; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 447 | __ CheckMap(receiver_reg, scratch1, Handle<Map>(object->map()), miss_label, |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 448 | DO_SMI_CHECK, mode); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 449 | |
| 450 | // Perform global security token check if needed. |
| 451 | if (object->IsJSGlobalProxy()) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 452 | __ CheckAccessGlobalProxy(receiver_reg, scratch1, miss_label); |
| 453 | } |
| 454 | |
| 455 | // Check that we are allowed to write this. |
| 456 | if (!transition.is_null() && object->GetPrototype()->IsJSObject()) { |
| 457 | JSObject* holder; |
| 458 | if (lookup.IsFound()) { |
| 459 | holder = lookup.holder(); |
| 460 | } else { |
| 461 | // Find the top object. |
| 462 | holder = *object; |
| 463 | do { |
| 464 | holder = JSObject::cast(holder->GetPrototype()); |
| 465 | } while (holder->GetPrototype()->IsJSObject()); |
| 466 | } |
| 467 | // We need an extra register, push |
| 468 | __ push(name_reg); |
| 469 | Label miss_pop, done_check; |
| 470 | CheckPrototypes(object, receiver_reg, Handle<JSObject>(holder), name_reg, |
| 471 | scratch1, scratch2, name, &miss_pop); |
| 472 | __ jmp(&done_check); |
| 473 | __ bind(&miss_pop); |
| 474 | __ pop(name_reg); |
| 475 | __ jmp(miss_label); |
| 476 | __ bind(&done_check); |
| 477 | __ pop(name_reg); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | // Stub never generated for non-global objects that require access |
| 481 | // checks. |
| 482 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
| 483 | |
| 484 | // Perform map transition for the receiver if necessary. |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 485 | if (!transition.is_null() && (object->map()->unused_property_fields() == 0)) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 486 | // The properties must be extended before we can store the value. |
| 487 | // We jump to a runtime call that extends the properties array. |
| 488 | __ push(receiver_reg); |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 489 | __ li(a2, Operand(transition)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 490 | __ Push(a2, a0); |
| 491 | __ TailCallExternalReference( |
| 492 | ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage), |
| 493 | masm->isolate()), |
| 494 | 3, 1); |
| 495 | return; |
| 496 | } |
| 497 | |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 498 | if (!transition.is_null()) { |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 499 | // Update the map of the object. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 500 | __ li(scratch1, Operand(transition)); |
| 501 | __ sw(scratch1, FieldMemOperand(receiver_reg, HeapObject::kMapOffset)); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 502 | |
| 503 | // Update the write barrier for the map field and pass the now unused |
| 504 | // name_reg as scratch register. |
| 505 | __ RecordWriteField(receiver_reg, |
| 506 | HeapObject::kMapOffset, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 507 | scratch1, |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 508 | name_reg, |
| 509 | kRAHasNotBeenSaved, |
| 510 | kDontSaveFPRegs, |
| 511 | OMIT_REMEMBERED_SET, |
| 512 | OMIT_SMI_CHECK); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | // Adjust for the number of properties stored in the object. Even in the |
| 516 | // face of a transition we can use the old map here because the size of the |
| 517 | // object and the number of in-object properties is not going to change. |
| 518 | index -= object->map()->inobject_properties(); |
| 519 | |
| 520 | if (index < 0) { |
| 521 | // Set the property straight into the object. |
| 522 | int offset = object->map()->instance_size() + (index * kPointerSize); |
| 523 | __ sw(a0, FieldMemOperand(receiver_reg, offset)); |
| 524 | |
| 525 | // Skip updating write barrier if storing a smi. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 526 | __ JumpIfSmi(a0, &exit, scratch1); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 527 | |
| 528 | // Update the write barrier for the array address. |
| 529 | // Pass the now unused name_reg as a scratch register. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 530 | __ mov(name_reg, a0); |
| 531 | __ RecordWriteField(receiver_reg, |
| 532 | offset, |
| 533 | name_reg, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 534 | scratch1, |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 535 | kRAHasNotBeenSaved, |
| 536 | kDontSaveFPRegs); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 537 | } else { |
| 538 | // Write to the properties array. |
| 539 | int offset = index * kPointerSize + FixedArray::kHeaderSize; |
| 540 | // Get the properties array. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 541 | __ lw(scratch1, |
| 542 | FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset)); |
| 543 | __ sw(a0, FieldMemOperand(scratch1, offset)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 544 | |
| 545 | // Skip updating write barrier if storing a smi. |
| 546 | __ JumpIfSmi(a0, &exit); |
| 547 | |
| 548 | // Update the write barrier for the array address. |
| 549 | // Ok to clobber receiver_reg and name_reg, since we return. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 550 | __ mov(name_reg, a0); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 551 | __ RecordWriteField(scratch1, |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 552 | offset, |
| 553 | name_reg, |
| 554 | receiver_reg, |
| 555 | kRAHasNotBeenSaved, |
| 556 | kDontSaveFPRegs); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | // Return the value (register v0). |
| 560 | __ bind(&exit); |
| 561 | __ mov(v0, a0); |
| 562 | __ Ret(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | |
| 566 | void StubCompiler::GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 567 | ASSERT(kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 568 | Handle<Code> code = (kind == Code::LOAD_IC) |
| 569 | ? masm->isolate()->builtins()->LoadIC_Miss() |
| 570 | : masm->isolate()->builtins()->KeyedLoadIC_Miss(); |
| 571 | __ Jump(code, RelocInfo::CODE_TARGET); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 575 | static void GenerateCallFunction(MacroAssembler* masm, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 576 | Handle<Object> object, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 577 | const ParameterCount& arguments, |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 578 | Label* miss, |
| 579 | Code::ExtraICState extra_ic_state) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 580 | // ----------- S t a t e ------------- |
| 581 | // -- a0: receiver |
| 582 | // -- a1: function to call |
| 583 | // ----------------------------------- |
| 584 | // Check that the function really is a function. |
| 585 | __ JumpIfSmi(a1, miss); |
| 586 | __ GetObjectType(a1, a3, a3); |
| 587 | __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE)); |
| 588 | |
| 589 | // Patch the receiver on the stack with the global proxy if |
| 590 | // necessary. |
| 591 | if (object->IsGlobalObject()) { |
| 592 | __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset)); |
| 593 | __ sw(a3, MemOperand(sp, arguments.immediate() * kPointerSize)); |
| 594 | } |
| 595 | |
| 596 | // Invoke the function. |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 597 | CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state) |
| 598 | ? CALL_AS_FUNCTION |
| 599 | : CALL_AS_METHOD; |
| 600 | __ InvokeFunction(a1, arguments, JUMP_FUNCTION, NullCallWrapper(), call_kind); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | |
| 604 | static void PushInterceptorArguments(MacroAssembler* masm, |
| 605 | Register receiver, |
| 606 | Register holder, |
| 607 | Register name, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 608 | Handle<JSObject> holder_obj) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 609 | __ push(name); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 610 | Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor()); |
| 611 | ASSERT(!masm->isolate()->heap()->InNewSpace(*interceptor)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 612 | Register scratch = name; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 613 | __ li(scratch, Operand(interceptor)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 614 | __ Push(scratch, receiver, holder); |
| 615 | __ lw(scratch, FieldMemOperand(scratch, InterceptorInfo::kDataOffset)); |
| 616 | __ push(scratch); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 617 | __ li(scratch, Operand(ExternalReference::isolate_address())); |
| 618 | __ push(scratch); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 622 | static void CompileCallLoadPropertyWithInterceptor( |
| 623 | MacroAssembler* masm, |
| 624 | Register receiver, |
| 625 | Register holder, |
| 626 | Register name, |
| 627 | Handle<JSObject> holder_obj) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 628 | PushInterceptorArguments(masm, receiver, holder, name, holder_obj); |
| 629 | |
| 630 | ExternalReference ref = |
| 631 | ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorOnly), |
| 632 | masm->isolate()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 633 | __ PrepareCEntryArgs(6); |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 634 | __ PrepareCEntryFunction(ref); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 635 | |
| 636 | CEntryStub stub(1); |
| 637 | __ CallStub(&stub); |
| 638 | } |
| 639 | |
| 640 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 641 | static const int kFastApiCallArguments = 4; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 642 | |
| 643 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 644 | // Reserves space for the extra arguments to API function in the |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 645 | // caller's frame. |
| 646 | // |
| 647 | // These arguments are set by CheckPrototypes and GenerateFastApiDirectCall. |
| 648 | static void ReserveSpaceForFastApiCall(MacroAssembler* masm, |
| 649 | Register scratch) { |
| 650 | ASSERT(Smi::FromInt(0) == 0); |
| 651 | for (int i = 0; i < kFastApiCallArguments; i++) { |
| 652 | __ push(zero_reg); |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | |
| 657 | // Undoes the effects of ReserveSpaceForFastApiCall. |
| 658 | static void FreeSpaceForFastApiCall(MacroAssembler* masm) { |
| 659 | __ Drop(kFastApiCallArguments); |
| 660 | } |
| 661 | |
| 662 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 663 | static void GenerateFastApiDirectCall(MacroAssembler* masm, |
| 664 | const CallOptimization& optimization, |
| 665 | int argc) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 666 | // ----------- S t a t e ------------- |
| 667 | // -- sp[0] : holder (set by CheckPrototypes) |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 668 | // -- sp[4] : callee JS function |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 669 | // -- sp[8] : call data |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 670 | // -- sp[12] : isolate |
| 671 | // -- sp[16] : last JS argument |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 672 | // -- ... |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 673 | // -- sp[(argc + 3) * 4] : first JS argument |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 674 | // -- sp[(argc + 4) * 4] : receiver |
| 675 | // ----------------------------------- |
| 676 | // Get the function and setup the context. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 677 | Handle<JSFunction> function = optimization.constant_function(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 678 | __ LoadHeapObject(t1, function); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 679 | __ lw(cp, FieldMemOperand(t1, JSFunction::kContextOffset)); |
| 680 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 681 | // Pass the additional arguments. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 682 | Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); |
| 683 | Handle<Object> call_data(api_call_info->data()); |
| 684 | if (masm->isolate()->heap()->InNewSpace(*call_data)) { |
| 685 | __ li(a0, api_call_info); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 686 | __ lw(t2, FieldMemOperand(a0, CallHandlerInfo::kDataOffset)); |
| 687 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 688 | __ li(t2, call_data); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 689 | } |
| 690 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 691 | __ li(t3, Operand(ExternalReference::isolate_address())); |
| 692 | // Store JS function, call data and isolate. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 693 | __ sw(t1, MemOperand(sp, 1 * kPointerSize)); |
| 694 | __ sw(t2, MemOperand(sp, 2 * kPointerSize)); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 695 | __ sw(t3, MemOperand(sp, 3 * kPointerSize)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 696 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 697 | // Prepare arguments. |
| 698 | __ Addu(a2, sp, Operand(3 * kPointerSize)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 699 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 700 | // Allocate the v8::Arguments structure in the arguments' space since |
| 701 | // it's not controlled by GC. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 702 | const int kApiStackSpace = 4; |
| 703 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 704 | FrameScope frame_scope(masm, StackFrame::MANUAL); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 705 | __ EnterExitFrame(false, kApiStackSpace); |
| 706 | |
| 707 | // NOTE: the O32 abi requires a0 to hold a special pointer when returning a |
| 708 | // struct from the function (which is currently the case). This means we pass |
| 709 | // the first argument in a1 instead of a0. TryCallApiFunctionAndReturn |
| 710 | // will handle setting up a0. |
| 711 | |
| 712 | // a1 = v8::Arguments& |
| 713 | // Arguments is built at sp + 1 (sp is a reserved spot for ra). |
| 714 | __ Addu(a1, sp, kPointerSize); |
| 715 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 716 | // v8::Arguments::implicit_args_ |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 717 | __ sw(a2, MemOperand(a1, 0 * kPointerSize)); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 718 | // v8::Arguments::values_ |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 719 | __ Addu(t0, a2, Operand(argc * kPointerSize)); |
| 720 | __ sw(t0, MemOperand(a1, 1 * kPointerSize)); |
| 721 | // v8::Arguments::length_ = argc |
| 722 | __ li(t0, Operand(argc)); |
| 723 | __ sw(t0, MemOperand(a1, 2 * kPointerSize)); |
| 724 | // v8::Arguments::is_construct_call = 0 |
| 725 | __ sw(zero_reg, MemOperand(a1, 3 * kPointerSize)); |
| 726 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 727 | const int kStackUnwindSpace = argc + kFastApiCallArguments + 1; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 728 | Address function_address = v8::ToCData<Address>(api_call_info->callback()); |
| 729 | ApiFunction fun(function_address); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 730 | ExternalReference ref = |
| 731 | ExternalReference(&fun, |
| 732 | ExternalReference::DIRECT_API_CALL, |
| 733 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 734 | AllowExternalCallThatCantCauseGC scope(masm); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 735 | __ CallApiFunctionAndReturn(ref, kStackUnwindSpace); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 736 | } |
| 737 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 738 | class CallInterceptorCompiler BASE_EMBEDDED { |
| 739 | public: |
| 740 | CallInterceptorCompiler(StubCompiler* stub_compiler, |
| 741 | const ParameterCount& arguments, |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 742 | Register name, |
| 743 | Code::ExtraICState extra_ic_state) |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 744 | : stub_compiler_(stub_compiler), |
| 745 | arguments_(arguments), |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 746 | name_(name), |
| 747 | extra_ic_state_(extra_ic_state) {} |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 748 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 749 | void Compile(MacroAssembler* masm, |
| 750 | Handle<JSObject> object, |
| 751 | Handle<JSObject> holder, |
| 752 | Handle<String> name, |
| 753 | LookupResult* lookup, |
| 754 | Register receiver, |
| 755 | Register scratch1, |
| 756 | Register scratch2, |
| 757 | Register scratch3, |
| 758 | Label* miss) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 759 | ASSERT(holder->HasNamedInterceptor()); |
| 760 | ASSERT(!holder->GetNamedInterceptor()->getter()->IsUndefined()); |
| 761 | |
| 762 | // Check that the receiver isn't a smi. |
| 763 | __ JumpIfSmi(receiver, miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 764 | CallOptimization optimization(lookup); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 765 | if (optimization.is_constant_call()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 766 | CompileCacheable(masm, object, receiver, scratch1, scratch2, scratch3, |
| 767 | holder, lookup, name, optimization, miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 768 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 769 | CompileRegular(masm, object, receiver, scratch1, scratch2, scratch3, |
| 770 | name, holder, miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | |
| 774 | private: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 775 | void CompileCacheable(MacroAssembler* masm, |
| 776 | Handle<JSObject> object, |
| 777 | Register receiver, |
| 778 | Register scratch1, |
| 779 | Register scratch2, |
| 780 | Register scratch3, |
| 781 | Handle<JSObject> interceptor_holder, |
| 782 | LookupResult* lookup, |
| 783 | Handle<String> name, |
| 784 | const CallOptimization& optimization, |
| 785 | Label* miss_label) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 786 | ASSERT(optimization.is_constant_call()); |
| 787 | ASSERT(!lookup->holder()->IsGlobalObject()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 788 | Counters* counters = masm->isolate()->counters(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 789 | int depth1 = kInvalidProtoDepth; |
| 790 | int depth2 = kInvalidProtoDepth; |
| 791 | bool can_do_fast_api_call = false; |
| 792 | if (optimization.is_simple_api_call() && |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 793 | !lookup->holder()->IsGlobalObject()) { |
| 794 | depth1 = optimization.GetPrototypeDepthOfExpectedType( |
| 795 | object, interceptor_holder); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 796 | if (depth1 == kInvalidProtoDepth) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 797 | depth2 = optimization.GetPrototypeDepthOfExpectedType( |
| 798 | interceptor_holder, Handle<JSObject>(lookup->holder())); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 799 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 800 | can_do_fast_api_call = |
| 801 | depth1 != kInvalidProtoDepth || depth2 != kInvalidProtoDepth; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | __ IncrementCounter(counters->call_const_interceptor(), 1, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 805 | scratch1, scratch2); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 806 | |
| 807 | if (can_do_fast_api_call) { |
| 808 | __ IncrementCounter(counters->call_const_interceptor_fast_api(), 1, |
| 809 | scratch1, scratch2); |
| 810 | ReserveSpaceForFastApiCall(masm, scratch1); |
| 811 | } |
| 812 | |
| 813 | // Check that the maps from receiver to interceptor's holder |
| 814 | // haven't changed and thus we can invoke interceptor. |
| 815 | Label miss_cleanup; |
| 816 | Label* miss = can_do_fast_api_call ? &miss_cleanup : miss_label; |
| 817 | Register holder = |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 818 | stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder, |
| 819 | scratch1, scratch2, scratch3, |
| 820 | name, depth1, miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 821 | |
| 822 | // Invoke an interceptor and if it provides a value, |
| 823 | // branch to |regular_invoke|. |
| 824 | Label regular_invoke; |
| 825 | LoadWithInterceptor(masm, receiver, holder, interceptor_holder, scratch2, |
| 826 | ®ular_invoke); |
| 827 | |
| 828 | // Interceptor returned nothing for this property. Try to use cached |
| 829 | // constant function. |
| 830 | |
| 831 | // Check that the maps from interceptor's holder to constant function's |
| 832 | // holder haven't changed and thus we can use cached constant function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 833 | if (*interceptor_holder != lookup->holder()) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 834 | stub_compiler_->CheckPrototypes(interceptor_holder, receiver, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 835 | Handle<JSObject>(lookup->holder()), |
| 836 | scratch1, scratch2, scratch3, |
| 837 | name, depth2, miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 838 | } else { |
| 839 | // CheckPrototypes has a side effect of fetching a 'holder' |
| 840 | // for API (object which is instanceof for the signature). It's |
| 841 | // safe to omit it here, as if present, it should be fetched |
| 842 | // by the previous CheckPrototypes. |
| 843 | ASSERT(depth2 == kInvalidProtoDepth); |
| 844 | } |
| 845 | |
| 846 | // Invoke function. |
| 847 | if (can_do_fast_api_call) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 848 | GenerateFastApiDirectCall(masm, optimization, arguments_.immediate()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 849 | } else { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 850 | CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state_) |
| 851 | ? CALL_AS_FUNCTION |
| 852 | : CALL_AS_METHOD; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 853 | __ InvokeFunction(optimization.constant_function(), arguments_, |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 854 | JUMP_FUNCTION, NullCallWrapper(), call_kind); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | // Deferred code for fast API call case---clean preallocated space. |
| 858 | if (can_do_fast_api_call) { |
| 859 | __ bind(&miss_cleanup); |
| 860 | FreeSpaceForFastApiCall(masm); |
| 861 | __ Branch(miss_label); |
| 862 | } |
| 863 | |
| 864 | // Invoke a regular function. |
| 865 | __ bind(®ular_invoke); |
| 866 | if (can_do_fast_api_call) { |
| 867 | FreeSpaceForFastApiCall(masm); |
| 868 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | void CompileRegular(MacroAssembler* masm, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 872 | Handle<JSObject> object, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 873 | Register receiver, |
| 874 | Register scratch1, |
| 875 | Register scratch2, |
| 876 | Register scratch3, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 877 | Handle<String> name, |
| 878 | Handle<JSObject> interceptor_holder, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 879 | Label* miss_label) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 880 | Register holder = |
| 881 | stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 882 | scratch1, scratch2, scratch3, |
| 883 | name, miss_label); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 884 | |
| 885 | // Call a runtime function to load the interceptor property. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 886 | FrameScope scope(masm, StackFrame::INTERNAL); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 887 | // Save the name_ register across the call. |
| 888 | __ push(name_); |
| 889 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 890 | PushInterceptorArguments(masm, receiver, holder, name_, interceptor_holder); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 891 | |
| 892 | __ CallExternalReference( |
| 893 | ExternalReference( |
| 894 | IC_Utility(IC::kLoadPropertyWithInterceptorForCall), |
| 895 | masm->isolate()), |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 896 | 6); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 897 | // Restore the name_ register. |
| 898 | __ pop(name_); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 899 | // Leave the internal frame. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | void LoadWithInterceptor(MacroAssembler* masm, |
| 903 | Register receiver, |
| 904 | Register holder, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 905 | Handle<JSObject> holder_obj, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 906 | Register scratch, |
| 907 | Label* interceptor_succeeded) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 908 | { |
| 909 | FrameScope scope(masm, StackFrame::INTERNAL); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 910 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 911 | __ Push(holder, name_); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 912 | CompileCallLoadPropertyWithInterceptor(masm, |
| 913 | receiver, |
| 914 | holder, |
| 915 | name_, |
| 916 | holder_obj); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 917 | __ pop(name_); // Restore the name. |
| 918 | __ pop(receiver); // Restore the holder. |
| 919 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 920 | // If interceptor returns no-result sentinel, call the constant function. |
| 921 | __ LoadRoot(scratch, Heap::kNoInterceptorResultSentinelRootIndex); |
| 922 | __ Branch(interceptor_succeeded, ne, v0, Operand(scratch)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | StubCompiler* stub_compiler_; |
| 926 | const ParameterCount& arguments_; |
| 927 | Register name_; |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 928 | Code::ExtraICState extra_ic_state_; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 929 | }; |
| 930 | |
| 931 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 932 | |
| 933 | // Generate code to check that a global property cell is empty. Create |
| 934 | // the property cell at compilation time if no cell exists for the |
| 935 | // property. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 936 | static void GenerateCheckPropertyCell(MacroAssembler* masm, |
| 937 | Handle<GlobalObject> global, |
| 938 | Handle<String> name, |
| 939 | Register scratch, |
| 940 | Label* miss) { |
| 941 | Handle<JSGlobalPropertyCell> cell = |
| 942 | GlobalObject::EnsurePropertyCell(global, name); |
| 943 | ASSERT(cell->value()->IsTheHole()); |
| 944 | __ li(scratch, Operand(cell)); |
| 945 | __ lw(scratch, |
| 946 | FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset)); |
| 947 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 948 | __ Branch(miss, ne, scratch, Operand(at)); |
| 949 | } |
| 950 | |
| 951 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 952 | // Calls GenerateCheckPropertyCell for each global object in the prototype chain |
| 953 | // from object to (but not including) holder. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 954 | static void GenerateCheckPropertyCells(MacroAssembler* masm, |
| 955 | Handle<JSObject> object, |
| 956 | Handle<JSObject> holder, |
| 957 | Handle<String> name, |
| 958 | Register scratch, |
| 959 | Label* miss) { |
| 960 | Handle<JSObject> current = object; |
| 961 | while (!current.is_identical_to(holder)) { |
| 962 | if (current->IsGlobalObject()) { |
| 963 | GenerateCheckPropertyCell(masm, |
| 964 | Handle<GlobalObject>::cast(current), |
| 965 | name, |
| 966 | scratch, |
| 967 | miss); |
| 968 | } |
| 969 | current = Handle<JSObject>(JSObject::cast(current->GetPrototype())); |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 974 | // Convert and store int passed in register ival to IEEE 754 single precision |
| 975 | // floating point value at memory location (dst + 4 * wordoffset) |
| 976 | // If FPU is available use it for conversion. |
| 977 | static void StoreIntAsFloat(MacroAssembler* masm, |
| 978 | Register dst, |
| 979 | Register wordoffset, |
| 980 | Register ival, |
| 981 | Register fval, |
| 982 | Register scratch1, |
| 983 | Register scratch2) { |
| 984 | if (CpuFeatures::IsSupported(FPU)) { |
| 985 | CpuFeatures::Scope scope(FPU); |
| 986 | __ mtc1(ival, f0); |
| 987 | __ cvt_s_w(f0, f0); |
| 988 | __ sll(scratch1, wordoffset, 2); |
| 989 | __ addu(scratch1, dst, scratch1); |
| 990 | __ swc1(f0, MemOperand(scratch1, 0)); |
| 991 | } else { |
| 992 | // FPU is not available, do manual conversions. |
| 993 | |
| 994 | Label not_special, done; |
| 995 | // Move sign bit from source to destination. This works because the sign |
| 996 | // bit in the exponent word of the double has the same position and polarity |
| 997 | // as the 2's complement sign bit in a Smi. |
| 998 | ASSERT(kBinary32SignMask == 0x80000000u); |
| 999 | |
| 1000 | __ And(fval, ival, Operand(kBinary32SignMask)); |
| 1001 | // Negate value if it is negative. |
| 1002 | __ subu(scratch1, zero_reg, ival); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 1003 | __ Movn(ival, scratch1, fval); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1004 | |
| 1005 | // We have -1, 0 or 1, which we treat specially. Register ival contains |
| 1006 | // absolute value: it is either equal to 1 (special case of -1 and 1), |
| 1007 | // greater than 1 (not a special case) or less than 1 (special case of 0). |
| 1008 | __ Branch(¬_special, gt, ival, Operand(1)); |
| 1009 | |
| 1010 | // For 1 or -1 we need to or in the 0 exponent (biased). |
| 1011 | static const uint32_t exponent_word_for_1 = |
| 1012 | kBinary32ExponentBias << kBinary32ExponentShift; |
| 1013 | |
| 1014 | __ Xor(scratch1, ival, Operand(1)); |
| 1015 | __ li(scratch2, exponent_word_for_1); |
| 1016 | __ or_(scratch2, fval, scratch2); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 1017 | __ Movz(fval, scratch2, scratch1); // Only if ival is equal to 1. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1018 | __ Branch(&done); |
| 1019 | |
| 1020 | __ bind(¬_special); |
| 1021 | // Count leading zeros. |
| 1022 | // Gets the wrong answer for 0, but we already checked for that case above. |
| 1023 | Register zeros = scratch2; |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 1024 | __ Clz(zeros, ival); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1025 | |
| 1026 | // Compute exponent and or it into the exponent register. |
| 1027 | __ li(scratch1, (kBitsPerInt - 1) + kBinary32ExponentBias); |
| 1028 | __ subu(scratch1, scratch1, zeros); |
| 1029 | |
| 1030 | __ sll(scratch1, scratch1, kBinary32ExponentShift); |
| 1031 | __ or_(fval, fval, scratch1); |
| 1032 | |
| 1033 | // Shift up the source chopping the top bit off. |
| 1034 | __ Addu(zeros, zeros, Operand(1)); |
| 1035 | // This wouldn't work for 1 and -1 as the shift would be 32 which means 0. |
| 1036 | __ sllv(ival, ival, zeros); |
| 1037 | // And the top (top 20 bits). |
| 1038 | __ srl(scratch1, ival, kBitsPerInt - kBinary32MantissaBits); |
| 1039 | __ or_(fval, fval, scratch1); |
| 1040 | |
| 1041 | __ bind(&done); |
| 1042 | |
| 1043 | __ sll(scratch1, wordoffset, 2); |
| 1044 | __ addu(scratch1, dst, scratch1); |
| 1045 | __ sw(fval, MemOperand(scratch1, 0)); |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | |
| 1050 | // Convert unsigned integer with specified number of leading zeroes in binary |
| 1051 | // representation to IEEE 754 double. |
| 1052 | // Integer to convert is passed in register hiword. |
| 1053 | // Resulting double is returned in registers hiword:loword. |
| 1054 | // This functions does not work correctly for 0. |
| 1055 | static void GenerateUInt2Double(MacroAssembler* masm, |
| 1056 | Register hiword, |
| 1057 | Register loword, |
| 1058 | Register scratch, |
| 1059 | int leading_zeroes) { |
| 1060 | const int meaningful_bits = kBitsPerInt - leading_zeroes - 1; |
| 1061 | const int biased_exponent = HeapNumber::kExponentBias + meaningful_bits; |
| 1062 | |
| 1063 | const int mantissa_shift_for_hi_word = |
| 1064 | meaningful_bits - HeapNumber::kMantissaBitsInTopWord; |
| 1065 | |
| 1066 | const int mantissa_shift_for_lo_word = |
| 1067 | kBitsPerInt - mantissa_shift_for_hi_word; |
| 1068 | |
| 1069 | __ li(scratch, biased_exponent << HeapNumber::kExponentShift); |
| 1070 | if (mantissa_shift_for_hi_word > 0) { |
| 1071 | __ sll(loword, hiword, mantissa_shift_for_lo_word); |
| 1072 | __ srl(hiword, hiword, mantissa_shift_for_hi_word); |
| 1073 | __ or_(hiword, scratch, hiword); |
| 1074 | } else { |
| 1075 | __ mov(loword, zero_reg); |
| 1076 | __ sll(hiword, hiword, mantissa_shift_for_hi_word); |
| 1077 | __ or_(hiword, scratch, hiword); |
| 1078 | } |
| 1079 | |
| 1080 | // If least significant bit of biased exponent was not 1 it was corrupted |
| 1081 | // by most significant bit of mantissa so we should fix that. |
| 1082 | if (!(biased_exponent & 1)) { |
| 1083 | __ li(scratch, 1 << HeapNumber::kExponentShift); |
| 1084 | __ nor(scratch, scratch, scratch); |
| 1085 | __ and_(hiword, hiword, scratch); |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1090 | #undef __ |
| 1091 | #define __ ACCESS_MASM(masm()) |
| 1092 | |
| 1093 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1094 | Register StubCompiler::CheckPrototypes(Handle<JSObject> object, |
| 1095 | Register object_reg, |
| 1096 | Handle<JSObject> holder, |
| 1097 | Register holder_reg, |
| 1098 | Register scratch1, |
| 1099 | Register scratch2, |
| 1100 | Handle<String> name, |
| 1101 | int save_at_depth, |
| 1102 | Label* miss) { |
| 1103 | // Make sure there's no overlap between holder and object registers. |
| 1104 | ASSERT(!scratch1.is(object_reg) && !scratch1.is(holder_reg)); |
| 1105 | ASSERT(!scratch2.is(object_reg) && !scratch2.is(holder_reg) |
| 1106 | && !scratch2.is(scratch1)); |
| 1107 | |
| 1108 | // Keep track of the current object in register reg. |
| 1109 | Register reg = object_reg; |
| 1110 | int depth = 0; |
| 1111 | |
| 1112 | if (save_at_depth == depth) { |
| 1113 | __ sw(reg, MemOperand(sp)); |
| 1114 | } |
| 1115 | |
| 1116 | // Check the maps in the prototype chain. |
| 1117 | // Traverse the prototype chain from the object and do map checks. |
| 1118 | Handle<JSObject> current = object; |
| 1119 | while (!current.is_identical_to(holder)) { |
| 1120 | ++depth; |
| 1121 | |
| 1122 | // Only global objects and objects that do not require access |
| 1123 | // checks are allowed in stubs. |
| 1124 | ASSERT(current->IsJSGlobalProxy() || !current->IsAccessCheckNeeded()); |
| 1125 | |
| 1126 | Handle<JSObject> prototype(JSObject::cast(current->GetPrototype())); |
| 1127 | if (!current->HasFastProperties() && |
| 1128 | !current->IsJSGlobalObject() && |
| 1129 | !current->IsJSGlobalProxy()) { |
| 1130 | if (!name->IsSymbol()) { |
| 1131 | name = factory()->LookupSymbol(name); |
| 1132 | } |
| 1133 | ASSERT(current->property_dictionary()->FindEntry(*name) == |
| 1134 | StringDictionary::kNotFound); |
| 1135 | |
| 1136 | GenerateDictionaryNegativeLookup(masm(), miss, reg, name, |
| 1137 | scratch1, scratch2); |
| 1138 | |
| 1139 | __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 1140 | reg = holder_reg; // From now on the object will be in holder_reg. |
| 1141 | __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset)); |
| 1142 | } else { |
| 1143 | Handle<Map> current_map(current->map()); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1144 | __ CheckMap(reg, scratch1, current_map, miss, DONT_DO_SMI_CHECK, |
| 1145 | ALLOW_ELEMENT_TRANSITION_MAPS); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1146 | // Check access rights to the global object. This has to happen after |
| 1147 | // the map check so that we know that the object is actually a global |
| 1148 | // object. |
| 1149 | if (current->IsJSGlobalProxy()) { |
| 1150 | __ CheckAccessGlobalProxy(reg, scratch2, miss); |
| 1151 | } |
| 1152 | reg = holder_reg; // From now on the object will be in holder_reg. |
| 1153 | |
| 1154 | if (heap()->InNewSpace(*prototype)) { |
| 1155 | // The prototype is in new space; we cannot store a reference to it |
| 1156 | // in the code. Load it from the map. |
| 1157 | __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset)); |
| 1158 | } else { |
| 1159 | // The prototype is in old space; load it directly. |
| 1160 | __ li(reg, Operand(prototype)); |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | if (save_at_depth == depth) { |
| 1165 | __ sw(reg, MemOperand(sp)); |
| 1166 | } |
| 1167 | |
| 1168 | // Go to the next object in the prototype chain. |
| 1169 | current = prototype; |
| 1170 | } |
| 1171 | |
| 1172 | // Log the check depth. |
| 1173 | LOG(masm()->isolate(), IntEvent("check-maps-depth", depth + 1)); |
| 1174 | |
| 1175 | // Check the holder map. |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1176 | __ CheckMap(reg, scratch1, Handle<Map>(current->map()), miss, |
| 1177 | DONT_DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1178 | |
| 1179 | // Perform security check for access to the global object. |
| 1180 | ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded()); |
| 1181 | if (holder->IsJSGlobalProxy()) { |
| 1182 | __ CheckAccessGlobalProxy(reg, scratch1, miss); |
| 1183 | } |
| 1184 | |
| 1185 | // If we've skipped any global objects, it's not enough to verify that |
| 1186 | // their maps haven't changed. We also need to check that the property |
| 1187 | // cell for the property is still empty. |
| 1188 | GenerateCheckPropertyCells(masm(), object, holder, name, scratch1, miss); |
| 1189 | |
| 1190 | // Return the register containing the holder. |
| 1191 | return reg; |
| 1192 | } |
| 1193 | |
| 1194 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1195 | void StubCompiler::GenerateLoadField(Handle<JSObject> object, |
| 1196 | Handle<JSObject> holder, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1197 | Register receiver, |
| 1198 | Register scratch1, |
| 1199 | Register scratch2, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1200 | Register scratch3, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1201 | int index, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1202 | Handle<String> name, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1203 | Label* miss) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1204 | // Check that the receiver isn't a smi. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1205 | __ JumpIfSmi(receiver, miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1206 | |
| 1207 | // Check that the maps haven't changed. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1208 | Register reg = CheckPrototypes( |
| 1209 | object, receiver, holder, scratch1, scratch2, scratch3, name, miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1210 | GenerateFastPropertyLoad(masm(), v0, reg, holder, index); |
| 1211 | __ Ret(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1215 | void StubCompiler::GenerateLoadConstant(Handle<JSObject> object, |
| 1216 | Handle<JSObject> holder, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1217 | Register receiver, |
| 1218 | Register scratch1, |
| 1219 | Register scratch2, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1220 | Register scratch3, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1221 | Handle<JSFunction> value, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1222 | Handle<String> name, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1223 | Label* miss) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1224 | // Check that the receiver isn't a smi. |
| 1225 | __ JumpIfSmi(receiver, miss, scratch1); |
| 1226 | |
| 1227 | // Check that the maps haven't changed. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1228 | CheckPrototypes(object, receiver, holder, |
| 1229 | scratch1, scratch2, scratch3, name, miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1230 | |
| 1231 | // Return the constant value. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1232 | __ LoadHeapObject(v0, value); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1233 | __ Ret(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1237 | void StubCompiler::GenerateLoadCallback(Handle<JSObject> object, |
| 1238 | Handle<JSObject> holder, |
| 1239 | Register receiver, |
| 1240 | Register name_reg, |
| 1241 | Register scratch1, |
| 1242 | Register scratch2, |
| 1243 | Register scratch3, |
| 1244 | Handle<AccessorInfo> callback, |
| 1245 | Handle<String> name, |
| 1246 | Label* miss) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1247 | // Check that the receiver isn't a smi. |
| 1248 | __ JumpIfSmi(receiver, miss, scratch1); |
| 1249 | |
| 1250 | // Check that the maps haven't changed. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1251 | Register reg = CheckPrototypes(object, receiver, holder, scratch1, |
| 1252 | scratch2, scratch3, name, miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1253 | |
| 1254 | // Build AccessorInfo::args_ list on the stack and push property name below |
| 1255 | // the exit frame to make GC aware of them and store pointers to them. |
| 1256 | __ push(receiver); |
| 1257 | __ mov(scratch2, sp); // scratch2 = AccessorInfo::args_ |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1258 | if (heap()->InNewSpace(callback->data())) { |
| 1259 | __ li(scratch3, callback); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1260 | __ lw(scratch3, FieldMemOperand(scratch3, AccessorInfo::kDataOffset)); |
| 1261 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1262 | __ li(scratch3, Handle<Object>(callback->data())); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1263 | } |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1264 | __ Subu(sp, sp, 4 * kPointerSize); |
| 1265 | __ sw(reg, MemOperand(sp, 3 * kPointerSize)); |
| 1266 | __ sw(scratch3, MemOperand(sp, 2 * kPointerSize)); |
| 1267 | __ li(scratch3, Operand(ExternalReference::isolate_address())); |
| 1268 | __ sw(scratch3, MemOperand(sp, 1 * kPointerSize)); |
| 1269 | __ sw(name_reg, MemOperand(sp, 0 * kPointerSize)); |
| 1270 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1271 | __ mov(a2, scratch2); // Saved in case scratch2 == a1. |
| 1272 | __ mov(a1, sp); // a1 (first argument - see note below) = Handle<String> |
| 1273 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1274 | // NOTE: the O32 abi requires a0 to hold a special pointer when returning a |
| 1275 | // struct from the function (which is currently the case). This means we pass |
| 1276 | // the arguments in a1-a2 instead of a0-a1. TryCallApiFunctionAndReturn |
| 1277 | // will handle setting up a0. |
| 1278 | |
| 1279 | const int kApiStackSpace = 1; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1280 | FrameScope frame_scope(masm(), StackFrame::MANUAL); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1281 | __ EnterExitFrame(false, kApiStackSpace); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1282 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1283 | // Create AccessorInfo instance on the stack above the exit frame with |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1284 | // scratch2 (internal::Object** args_) as the data. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1285 | __ sw(a2, MemOperand(sp, kPointerSize)); |
| 1286 | // a2 (second argument - see note above) = AccessorInfo& |
| 1287 | __ Addu(a2, sp, kPointerSize); |
| 1288 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1289 | const int kStackUnwindSpace = 5; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1290 | Address getter_address = v8::ToCData<Address>(callback->getter()); |
| 1291 | ApiFunction fun(getter_address); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1292 | ExternalReference ref = |
| 1293 | ExternalReference(&fun, |
| 1294 | ExternalReference::DIRECT_GETTER_CALL, |
| 1295 | masm()->isolate()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1296 | __ CallApiFunctionAndReturn(ref, kStackUnwindSpace); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1300 | void StubCompiler::GenerateLoadInterceptor(Handle<JSObject> object, |
| 1301 | Handle<JSObject> interceptor_holder, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1302 | LookupResult* lookup, |
| 1303 | Register receiver, |
| 1304 | Register name_reg, |
| 1305 | Register scratch1, |
| 1306 | Register scratch2, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1307 | Register scratch3, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1308 | Handle<String> name, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1309 | Label* miss) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1310 | ASSERT(interceptor_holder->HasNamedInterceptor()); |
| 1311 | ASSERT(!interceptor_holder->GetNamedInterceptor()->getter()->IsUndefined()); |
| 1312 | |
| 1313 | // Check that the receiver isn't a smi. |
| 1314 | __ JumpIfSmi(receiver, miss); |
| 1315 | |
| 1316 | // So far the most popular follow ups for interceptor loads are FIELD |
| 1317 | // and CALLBACKS, so inline only them, other cases may be added |
| 1318 | // later. |
| 1319 | bool compile_followup_inline = false; |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1320 | if (lookup->IsFound() && lookup->IsCacheable()) { |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 1321 | if (lookup->IsField()) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1322 | compile_followup_inline = true; |
| 1323 | } else if (lookup->type() == CALLBACKS && |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1324 | lookup->GetCallbackObject()->IsAccessorInfo()) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1325 | AccessorInfo* callback = AccessorInfo::cast(lookup->GetCallbackObject()); |
| 1326 | compile_followup_inline = callback->getter() != NULL && |
| 1327 | callback->IsCompatibleReceiver(*object); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | if (compile_followup_inline) { |
| 1332 | // Compile the interceptor call, followed by inline code to load the |
| 1333 | // property from further up the prototype chain if the call fails. |
| 1334 | // Check that the maps haven't changed. |
| 1335 | Register holder_reg = CheckPrototypes(object, receiver, interceptor_holder, |
| 1336 | scratch1, scratch2, scratch3, |
| 1337 | name, miss); |
| 1338 | ASSERT(holder_reg.is(receiver) || holder_reg.is(scratch1)); |
| 1339 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1340 | // Preserve the receiver register explicitly whenever it is different from |
| 1341 | // the holder and it is needed should the interceptor return without any |
| 1342 | // result. The CALLBACKS case needs the receiver to be passed into C++ code, |
| 1343 | // the FIELD case might cause a miss during the prototype check. |
| 1344 | bool must_perfrom_prototype_check = *interceptor_holder != lookup->holder(); |
| 1345 | bool must_preserve_receiver_reg = !receiver.is(holder_reg) && |
| 1346 | (lookup->type() == CALLBACKS || must_perfrom_prototype_check); |
| 1347 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1348 | // Save necessary data before invoking an interceptor. |
| 1349 | // Requires a frame to make GC aware of pushed pointers. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1350 | { |
| 1351 | FrameScope frame_scope(masm(), StackFrame::INTERNAL); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1352 | if (must_preserve_receiver_reg) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1353 | __ Push(receiver, holder_reg, name_reg); |
| 1354 | } else { |
| 1355 | __ Push(holder_reg, name_reg); |
| 1356 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1357 | // Invoke an interceptor. Note: map checks from receiver to |
| 1358 | // interceptor's holder has been compiled before (see a caller |
| 1359 | // of this method). |
| 1360 | CompileCallLoadPropertyWithInterceptor(masm(), |
| 1361 | receiver, |
| 1362 | holder_reg, |
| 1363 | name_reg, |
| 1364 | interceptor_holder); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1365 | // Check if interceptor provided a value for property. If it's |
| 1366 | // the case, return immediately. |
| 1367 | Label interceptor_failed; |
| 1368 | __ LoadRoot(scratch1, Heap::kNoInterceptorResultSentinelRootIndex); |
| 1369 | __ Branch(&interceptor_failed, eq, v0, Operand(scratch1)); |
| 1370 | frame_scope.GenerateLeaveFrame(); |
| 1371 | __ Ret(); |
| 1372 | |
| 1373 | __ bind(&interceptor_failed); |
| 1374 | __ pop(name_reg); |
| 1375 | __ pop(holder_reg); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1376 | if (must_preserve_receiver_reg) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1377 | __ pop(receiver); |
| 1378 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1379 | // Leave the internal frame. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1380 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1381 | // Check that the maps from interceptor's holder to lookup's holder |
| 1382 | // haven't changed. And load lookup's holder into |holder| register. |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1383 | if (must_perfrom_prototype_check) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1384 | holder_reg = CheckPrototypes(interceptor_holder, |
| 1385 | holder_reg, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1386 | Handle<JSObject>(lookup->holder()), |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1387 | scratch1, |
| 1388 | scratch2, |
| 1389 | scratch3, |
| 1390 | name, |
| 1391 | miss); |
| 1392 | } |
| 1393 | |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 1394 | if (lookup->IsField()) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1395 | // We found FIELD property in prototype chain of interceptor's holder. |
| 1396 | // Retrieve a field from field's holder. |
| 1397 | GenerateFastPropertyLoad(masm(), v0, holder_reg, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1398 | Handle<JSObject>(lookup->holder()), |
| 1399 | lookup->GetFieldIndex()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1400 | __ Ret(); |
| 1401 | } else { |
| 1402 | // We found CALLBACKS property in prototype chain of interceptor's |
| 1403 | // holder. |
| 1404 | ASSERT(lookup->type() == CALLBACKS); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1405 | Handle<AccessorInfo> callback( |
| 1406 | AccessorInfo::cast(lookup->GetCallbackObject())); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1407 | ASSERT(callback->getter() != NULL); |
| 1408 | |
| 1409 | // Tail call to runtime. |
| 1410 | // Important invariant in CALLBACKS case: the code above must be |
| 1411 | // structured to never clobber |receiver| register. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1412 | __ li(scratch2, callback); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1413 | |
| 1414 | __ Push(receiver, holder_reg); |
| 1415 | __ lw(scratch3, |
| 1416 | FieldMemOperand(scratch2, AccessorInfo::kDataOffset)); |
| 1417 | __ li(scratch1, Operand(ExternalReference::isolate_address())); |
| 1418 | __ Push(scratch3, scratch1, scratch2, name_reg); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1419 | |
| 1420 | ExternalReference ref = |
| 1421 | ExternalReference(IC_Utility(IC::kLoadCallbackProperty), |
| 1422 | masm()->isolate()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1423 | __ TailCallExternalReference(ref, 6, 1); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1424 | } |
| 1425 | } else { // !compile_followup_inline |
| 1426 | // Call the runtime system to load the interceptor. |
| 1427 | // Check that the maps haven't changed. |
| 1428 | Register holder_reg = CheckPrototypes(object, receiver, interceptor_holder, |
| 1429 | scratch1, scratch2, scratch3, |
| 1430 | name, miss); |
| 1431 | PushInterceptorArguments(masm(), receiver, holder_reg, |
| 1432 | name_reg, interceptor_holder); |
| 1433 | |
| 1434 | ExternalReference ref = ExternalReference( |
| 1435 | IC_Utility(IC::kLoadPropertyWithInterceptorForLoad), masm()->isolate()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1436 | __ TailCallExternalReference(ref, 6, 1); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1437 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1441 | void CallStubCompiler::GenerateNameCheck(Handle<String> name, Label* miss) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1442 | if (kind_ == Code::KEYED_CALL_IC) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1443 | __ Branch(miss, ne, a2, Operand(name)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1444 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1448 | void CallStubCompiler::GenerateGlobalReceiverCheck(Handle<JSObject> object, |
| 1449 | Handle<JSObject> holder, |
| 1450 | Handle<String> name, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1451 | Label* miss) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1452 | ASSERT(holder->IsGlobalObject()); |
| 1453 | |
| 1454 | // Get the number of arguments. |
| 1455 | const int argc = arguments().immediate(); |
| 1456 | |
| 1457 | // Get the receiver from the stack. |
| 1458 | __ lw(a0, MemOperand(sp, argc * kPointerSize)); |
| 1459 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1460 | // Check that the maps haven't changed. |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 1461 | __ JumpIfSmi(a0, miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1462 | CheckPrototypes(object, a0, holder, a3, a1, t0, name, miss); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1466 | void CallStubCompiler::GenerateLoadFunctionFromCell( |
| 1467 | Handle<JSGlobalPropertyCell> cell, |
| 1468 | Handle<JSFunction> function, |
| 1469 | Label* miss) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1470 | // Get the value from the cell. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1471 | __ li(a3, Operand(cell)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1472 | __ lw(a1, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset)); |
| 1473 | |
| 1474 | // Check that the cell contains the same function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1475 | if (heap()->InNewSpace(*function)) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1476 | // We can't embed a pointer to a function in new space so we have |
| 1477 | // to verify that the shared function info is unchanged. This has |
| 1478 | // the nice side effect that multiple closures based on the same |
| 1479 | // function can all use this call IC. Before we load through the |
| 1480 | // function, we have to verify that it still is a function. |
| 1481 | __ JumpIfSmi(a1, miss); |
| 1482 | __ GetObjectType(a1, a3, a3); |
| 1483 | __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE)); |
| 1484 | |
| 1485 | // Check the shared function info. Make sure it hasn't changed. |
| 1486 | __ li(a3, Handle<SharedFunctionInfo>(function->shared())); |
| 1487 | __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 1488 | __ Branch(miss, ne, t0, Operand(a3)); |
| 1489 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1490 | __ Branch(miss, ne, a1, Operand(function)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1491 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1495 | void CallStubCompiler::GenerateMissBranch() { |
| 1496 | Handle<Code> code = |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1497 | isolate()->stub_cache()->ComputeCallMiss(arguments().immediate(), |
| 1498 | kind_, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1499 | extra_state_); |
| 1500 | __ Jump(code, RelocInfo::CODE_TARGET); |
| 1501 | } |
| 1502 | |
| 1503 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1504 | Handle<Code> CallStubCompiler::CompileCallField(Handle<JSObject> object, |
| 1505 | Handle<JSObject> holder, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1506 | int index, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1507 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1508 | // ----------- S t a t e ------------- |
| 1509 | // -- a2 : name |
| 1510 | // -- ra : return address |
| 1511 | // ----------------------------------- |
| 1512 | Label miss; |
| 1513 | |
| 1514 | GenerateNameCheck(name, &miss); |
| 1515 | |
| 1516 | const int argc = arguments().immediate(); |
| 1517 | |
| 1518 | // Get the receiver of the function from the stack into a0. |
| 1519 | __ lw(a0, MemOperand(sp, argc * kPointerSize)); |
| 1520 | // Check that the receiver isn't a smi. |
| 1521 | __ JumpIfSmi(a0, &miss, t0); |
| 1522 | |
| 1523 | // Do the right check and compute the holder register. |
| 1524 | Register reg = CheckPrototypes(object, a0, holder, a1, a3, t0, name, &miss); |
| 1525 | GenerateFastPropertyLoad(masm(), a1, reg, holder, index); |
| 1526 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1527 | GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1528 | |
| 1529 | // Handle call cache miss. |
| 1530 | __ bind(&miss); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1531 | GenerateMissBranch(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1532 | |
| 1533 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 1534 | return GetCode(Code::FIELD, name); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1538 | Handle<Code> CallStubCompiler::CompileArrayPushCall( |
| 1539 | Handle<Object> object, |
| 1540 | Handle<JSObject> holder, |
| 1541 | Handle<JSGlobalPropertyCell> cell, |
| 1542 | Handle<JSFunction> function, |
| 1543 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1544 | // ----------- S t a t e ------------- |
| 1545 | // -- a2 : name |
| 1546 | // -- ra : return address |
| 1547 | // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based) |
| 1548 | // -- ... |
| 1549 | // -- sp[argc * 4] : receiver |
| 1550 | // ----------------------------------- |
| 1551 | |
| 1552 | // If object is not an array, bail out to regular call. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1553 | if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1554 | |
| 1555 | Label miss; |
| 1556 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1557 | GenerateNameCheck(name, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1558 | |
| 1559 | Register receiver = a1; |
| 1560 | |
| 1561 | // Get the receiver from the stack. |
| 1562 | const int argc = arguments().immediate(); |
| 1563 | __ lw(receiver, MemOperand(sp, argc * kPointerSize)); |
| 1564 | |
| 1565 | // Check that the receiver isn't a smi. |
| 1566 | __ JumpIfSmi(receiver, &miss); |
| 1567 | |
| 1568 | // Check that the maps haven't changed. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1569 | CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, a3, v0, t0, |
| 1570 | name, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1571 | |
| 1572 | if (argc == 0) { |
| 1573 | // Nothing to do, just return the length. |
| 1574 | __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
| 1575 | __ Drop(argc + 1); |
| 1576 | __ Ret(); |
| 1577 | } else { |
| 1578 | Label call_builtin; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1579 | if (argc == 1) { // Otherwise fall through to call the builtin. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1580 | Label attempt_to_grow_elements; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1581 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1582 | Register elements = t2; |
| 1583 | Register end_elements = t1; |
| 1584 | // Get the elements array of the object. |
| 1585 | __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset)); |
| 1586 | |
| 1587 | // Check that the elements are in fast mode and writable. |
| 1588 | __ CheckMap(elements, |
| 1589 | v0, |
| 1590 | Heap::kFixedArrayMapRootIndex, |
| 1591 | &call_builtin, |
| 1592 | DONT_DO_SMI_CHECK); |
| 1593 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1594 | // Get the array's length into v0 and calculate new length. |
| 1595 | __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
| 1596 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1597 | STATIC_ASSERT(kSmiTag == 0); |
| 1598 | __ Addu(v0, v0, Operand(Smi::FromInt(argc))); |
| 1599 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1600 | // Get the elements' length. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1601 | __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset)); |
| 1602 | |
| 1603 | // Check if we could survive without allocation. |
| 1604 | __ Branch(&attempt_to_grow_elements, gt, v0, Operand(t0)); |
| 1605 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1606 | // Check if value is a smi. |
| 1607 | Label with_write_barrier; |
| 1608 | __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize)); |
| 1609 | __ JumpIfNotSmi(t0, &with_write_barrier); |
| 1610 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1611 | // Save new length. |
| 1612 | __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
| 1613 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1614 | // Store the value. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1615 | // We may need a register containing the address end_elements below, |
| 1616 | // so write back the value in end_elements. |
| 1617 | __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize); |
| 1618 | __ Addu(end_elements, elements, end_elements); |
| 1619 | const int kEndElementsOffset = |
| 1620 | FixedArray::kHeaderSize - kHeapObjectTag - argc * kPointerSize; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1621 | __ Addu(end_elements, end_elements, kEndElementsOffset); |
| 1622 | __ sw(t0, MemOperand(end_elements)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1623 | |
| 1624 | // Check for a smi. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1625 | __ Drop(argc + 1); |
| 1626 | __ Ret(); |
| 1627 | |
| 1628 | __ bind(&with_write_barrier); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1629 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1630 | __ lw(a3, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 1631 | |
| 1632 | if (FLAG_smi_only_arrays && !FLAG_trace_elements_transitions) { |
| 1633 | Label fast_object, not_fast_object; |
| 1634 | __ CheckFastObjectElements(a3, t3, ¬_fast_object); |
| 1635 | __ jmp(&fast_object); |
| 1636 | // In case of fast smi-only, convert to fast object, otherwise bail out. |
| 1637 | __ bind(¬_fast_object); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1638 | __ CheckFastSmiElements(a3, t3, &call_builtin); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1639 | // edx: receiver |
| 1640 | // r3: map |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1641 | Label try_holey_map; |
| 1642 | __ LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS, |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1643 | FAST_ELEMENTS, |
| 1644 | a3, |
| 1645 | t3, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1646 | &try_holey_map); |
| 1647 | __ mov(a2, receiver); |
| 1648 | ElementsTransitionGenerator:: |
| 1649 | GenerateMapChangeElementsTransition(masm()); |
| 1650 | __ jmp(&fast_object); |
| 1651 | |
| 1652 | __ bind(&try_holey_map); |
| 1653 | __ LoadTransitionedArrayMapConditional(FAST_HOLEY_SMI_ELEMENTS, |
| 1654 | FAST_HOLEY_ELEMENTS, |
| 1655 | a3, |
| 1656 | t3, |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1657 | &call_builtin); |
| 1658 | __ mov(a2, receiver); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1659 | ElementsTransitionGenerator:: |
| 1660 | GenerateMapChangeElementsTransition(masm()); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1661 | __ bind(&fast_object); |
| 1662 | } else { |
| 1663 | __ CheckFastObjectElements(a3, a3, &call_builtin); |
| 1664 | } |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1665 | |
| 1666 | // Save new length. |
| 1667 | __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
| 1668 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1669 | // Store the value. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1670 | // We may need a register containing the address end_elements below, |
| 1671 | // so write back the value in end_elements. |
| 1672 | __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize); |
| 1673 | __ Addu(end_elements, elements, end_elements); |
| 1674 | __ Addu(end_elements, end_elements, kEndElementsOffset); |
| 1675 | __ sw(t0, MemOperand(end_elements)); |
| 1676 | |
| 1677 | __ RecordWrite(elements, |
| 1678 | end_elements, |
| 1679 | t0, |
| 1680 | kRAHasNotBeenSaved, |
| 1681 | kDontSaveFPRegs, |
| 1682 | EMIT_REMEMBERED_SET, |
| 1683 | OMIT_SMI_CHECK); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1684 | __ Drop(argc + 1); |
| 1685 | __ Ret(); |
| 1686 | |
| 1687 | __ bind(&attempt_to_grow_elements); |
| 1688 | // v0: array's length + 1. |
| 1689 | // t0: elements' length. |
| 1690 | |
| 1691 | if (!FLAG_inline_new) { |
| 1692 | __ Branch(&call_builtin); |
| 1693 | } |
| 1694 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1695 | __ lw(a2, MemOperand(sp, (argc - 1) * kPointerSize)); |
| 1696 | // Growing elements that are SMI-only requires special handling in case |
| 1697 | // the new element is non-Smi. For now, delegate to the builtin. |
| 1698 | Label no_fast_elements_check; |
| 1699 | __ JumpIfSmi(a2, &no_fast_elements_check); |
| 1700 | __ lw(t3, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 1701 | __ CheckFastObjectElements(t3, t3, &call_builtin); |
| 1702 | __ bind(&no_fast_elements_check); |
| 1703 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1704 | ExternalReference new_space_allocation_top = |
| 1705 | ExternalReference::new_space_allocation_top_address( |
| 1706 | masm()->isolate()); |
| 1707 | ExternalReference new_space_allocation_limit = |
| 1708 | ExternalReference::new_space_allocation_limit_address( |
| 1709 | masm()->isolate()); |
| 1710 | |
| 1711 | const int kAllocationDelta = 4; |
| 1712 | // Load top and check if it is the end of elements. |
| 1713 | __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize); |
| 1714 | __ Addu(end_elements, elements, end_elements); |
| 1715 | __ Addu(end_elements, end_elements, Operand(kEndElementsOffset)); |
| 1716 | __ li(t3, Operand(new_space_allocation_top)); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1717 | __ lw(a3, MemOperand(t3)); |
| 1718 | __ Branch(&call_builtin, ne, end_elements, Operand(a3)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1719 | |
| 1720 | __ li(t5, Operand(new_space_allocation_limit)); |
| 1721 | __ lw(t5, MemOperand(t5)); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1722 | __ Addu(a3, a3, Operand(kAllocationDelta * kPointerSize)); |
| 1723 | __ Branch(&call_builtin, hi, a3, Operand(t5)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1724 | |
| 1725 | // We fit and could grow elements. |
| 1726 | // Update new_space_allocation_top. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1727 | __ sw(a3, MemOperand(t3)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1728 | // Push the argument. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1729 | __ sw(a2, MemOperand(end_elements)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1730 | // Fill the rest with holes. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1731 | __ LoadRoot(a3, Heap::kTheHoleValueRootIndex); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1732 | for (int i = 1; i < kAllocationDelta; i++) { |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1733 | __ sw(a3, MemOperand(end_elements, i * kPointerSize)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | // Update elements' and array's sizes. |
| 1737 | __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
| 1738 | __ Addu(t0, t0, Operand(Smi::FromInt(kAllocationDelta))); |
| 1739 | __ sw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset)); |
| 1740 | |
| 1741 | // Elements are in new space, so write barrier is not required. |
| 1742 | __ Drop(argc + 1); |
| 1743 | __ Ret(); |
| 1744 | } |
| 1745 | __ bind(&call_builtin); |
| 1746 | __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPush, |
| 1747 | masm()->isolate()), |
| 1748 | argc + 1, |
| 1749 | 1); |
| 1750 | } |
| 1751 | |
| 1752 | // Handle call cache miss. |
| 1753 | __ bind(&miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1754 | GenerateMissBranch(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1755 | |
| 1756 | // Return the generated code. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1757 | return GetCode(function); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1761 | Handle<Code> CallStubCompiler::CompileArrayPopCall( |
| 1762 | Handle<Object> object, |
| 1763 | Handle<JSObject> holder, |
| 1764 | Handle<JSGlobalPropertyCell> cell, |
| 1765 | Handle<JSFunction> function, |
| 1766 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1767 | // ----------- S t a t e ------------- |
| 1768 | // -- a2 : name |
| 1769 | // -- ra : return address |
| 1770 | // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based) |
| 1771 | // -- ... |
| 1772 | // -- sp[argc * 4] : receiver |
| 1773 | // ----------------------------------- |
| 1774 | |
| 1775 | // If object is not an array, bail out to regular call. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1776 | if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1777 | |
| 1778 | Label miss, return_undefined, call_builtin; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1779 | Register receiver = a1; |
| 1780 | Register elements = a3; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1781 | GenerateNameCheck(name, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1782 | |
| 1783 | // Get the receiver from the stack. |
| 1784 | const int argc = arguments().immediate(); |
| 1785 | __ lw(receiver, MemOperand(sp, argc * kPointerSize)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1786 | // Check that the receiver isn't a smi. |
| 1787 | __ JumpIfSmi(receiver, &miss); |
| 1788 | |
| 1789 | // Check that the maps haven't changed. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1790 | CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, elements, |
| 1791 | t0, v0, name, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1792 | |
| 1793 | // Get the elements array of the object. |
| 1794 | __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset)); |
| 1795 | |
| 1796 | // Check that the elements are in fast mode and writable. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1797 | __ CheckMap(elements, |
| 1798 | v0, |
| 1799 | Heap::kFixedArrayMapRootIndex, |
| 1800 | &call_builtin, |
| 1801 | DONT_DO_SMI_CHECK); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1802 | |
| 1803 | // Get the array's length into t0 and calculate new length. |
| 1804 | __ lw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
| 1805 | __ Subu(t0, t0, Operand(Smi::FromInt(1))); |
| 1806 | __ Branch(&return_undefined, lt, t0, Operand(zero_reg)); |
| 1807 | |
| 1808 | // Get the last element. |
| 1809 | __ LoadRoot(t2, Heap::kTheHoleValueRootIndex); |
| 1810 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1811 | STATIC_ASSERT(kSmiTag == 0); |
| 1812 | // We can't address the last element in one operation. Compute the more |
| 1813 | // expensive shift first, and use an offset later on. |
| 1814 | __ sll(t1, t0, kPointerSizeLog2 - kSmiTagSize); |
| 1815 | __ Addu(elements, elements, t1); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 1816 | __ lw(v0, FieldMemOperand(elements, FixedArray::kHeaderSize)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1817 | __ Branch(&call_builtin, eq, v0, Operand(t2)); |
| 1818 | |
| 1819 | // Set the array's length. |
| 1820 | __ sw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
| 1821 | |
| 1822 | // Fill with the hole. |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 1823 | __ sw(t2, FieldMemOperand(elements, FixedArray::kHeaderSize)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1824 | __ Drop(argc + 1); |
| 1825 | __ Ret(); |
| 1826 | |
| 1827 | __ bind(&return_undefined); |
| 1828 | __ LoadRoot(v0, Heap::kUndefinedValueRootIndex); |
| 1829 | __ Drop(argc + 1); |
| 1830 | __ Ret(); |
| 1831 | |
| 1832 | __ bind(&call_builtin); |
| 1833 | __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPop, |
| 1834 | masm()->isolate()), |
| 1835 | argc + 1, |
| 1836 | 1); |
| 1837 | |
| 1838 | // Handle call cache miss. |
| 1839 | __ bind(&miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1840 | GenerateMissBranch(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1841 | |
| 1842 | // Return the generated code. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1843 | return GetCode(function); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1847 | Handle<Code> CallStubCompiler::CompileStringCharCodeAtCall( |
| 1848 | Handle<Object> object, |
| 1849 | Handle<JSObject> holder, |
| 1850 | Handle<JSGlobalPropertyCell> cell, |
| 1851 | Handle<JSFunction> function, |
| 1852 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1853 | // ----------- S t a t e ------------- |
| 1854 | // -- a2 : function name |
| 1855 | // -- ra : return address |
| 1856 | // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based) |
| 1857 | // -- ... |
| 1858 | // -- sp[argc * 4] : receiver |
| 1859 | // ----------------------------------- |
| 1860 | |
| 1861 | // If object is not a string, bail out to regular call. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1862 | if (!object->IsString() || !cell.is_null()) return Handle<Code>::null(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1863 | |
| 1864 | const int argc = arguments().immediate(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1865 | Label miss; |
| 1866 | Label name_miss; |
| 1867 | Label index_out_of_range; |
| 1868 | |
| 1869 | Label* index_out_of_range_label = &index_out_of_range; |
| 1870 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1871 | if (kind_ == Code::CALL_IC && |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1872 | (CallICBase::StringStubState::decode(extra_state_) == |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1873 | DEFAULT_STRING_STUB)) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1874 | index_out_of_range_label = &miss; |
| 1875 | } |
| 1876 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1877 | GenerateNameCheck(name, &name_miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1878 | |
| 1879 | // Check that the maps starting from the prototype haven't changed. |
| 1880 | GenerateDirectLoadGlobalFunctionPrototype(masm(), |
| 1881 | Context::STRING_FUNCTION_INDEX, |
| 1882 | v0, |
| 1883 | &miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1884 | ASSERT(!object.is_identical_to(holder)); |
| 1885 | CheckPrototypes(Handle<JSObject>(JSObject::cast(object->GetPrototype())), |
| 1886 | v0, holder, a1, a3, t0, name, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1887 | |
| 1888 | Register receiver = a1; |
| 1889 | Register index = t1; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1890 | Register result = v0; |
| 1891 | __ lw(receiver, MemOperand(sp, argc * kPointerSize)); |
| 1892 | if (argc > 0) { |
| 1893 | __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize)); |
| 1894 | } else { |
| 1895 | __ LoadRoot(index, Heap::kUndefinedValueRootIndex); |
| 1896 | } |
| 1897 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1898 | StringCharCodeAtGenerator generator(receiver, |
| 1899 | index, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1900 | result, |
| 1901 | &miss, // When not a string. |
| 1902 | &miss, // When not a number. |
| 1903 | index_out_of_range_label, |
| 1904 | STRING_INDEX_IS_NUMBER); |
| 1905 | generator.GenerateFast(masm()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1906 | __ Drop(argc + 1); |
| 1907 | __ Ret(); |
| 1908 | |
| 1909 | StubRuntimeCallHelper call_helper; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1910 | generator.GenerateSlow(masm(), call_helper); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1911 | |
| 1912 | if (index_out_of_range.is_linked()) { |
| 1913 | __ bind(&index_out_of_range); |
| 1914 | __ LoadRoot(v0, Heap::kNanValueRootIndex); |
| 1915 | __ Drop(argc + 1); |
| 1916 | __ Ret(); |
| 1917 | } |
| 1918 | |
| 1919 | __ bind(&miss); |
| 1920 | // Restore function name in a2. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1921 | __ li(a2, name); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1922 | __ bind(&name_miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1923 | GenerateMissBranch(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1924 | |
| 1925 | // Return the generated code. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1926 | return GetCode(function); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1930 | Handle<Code> CallStubCompiler::CompileStringCharAtCall( |
| 1931 | Handle<Object> object, |
| 1932 | Handle<JSObject> holder, |
| 1933 | Handle<JSGlobalPropertyCell> cell, |
| 1934 | Handle<JSFunction> function, |
| 1935 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1936 | // ----------- S t a t e ------------- |
| 1937 | // -- a2 : function name |
| 1938 | // -- ra : return address |
| 1939 | // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based) |
| 1940 | // -- ... |
| 1941 | // -- sp[argc * 4] : receiver |
| 1942 | // ----------------------------------- |
| 1943 | |
| 1944 | // If object is not a string, bail out to regular call. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1945 | if (!object->IsString() || !cell.is_null()) return Handle<Code>::null(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1946 | |
| 1947 | const int argc = arguments().immediate(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1948 | Label miss; |
| 1949 | Label name_miss; |
| 1950 | Label index_out_of_range; |
| 1951 | Label* index_out_of_range_label = &index_out_of_range; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1952 | if (kind_ == Code::CALL_IC && |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1953 | (CallICBase::StringStubState::decode(extra_state_) == |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1954 | DEFAULT_STRING_STUB)) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1955 | index_out_of_range_label = &miss; |
| 1956 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1957 | GenerateNameCheck(name, &name_miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1958 | |
| 1959 | // Check that the maps starting from the prototype haven't changed. |
| 1960 | GenerateDirectLoadGlobalFunctionPrototype(masm(), |
| 1961 | Context::STRING_FUNCTION_INDEX, |
| 1962 | v0, |
| 1963 | &miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1964 | ASSERT(!object.is_identical_to(holder)); |
| 1965 | CheckPrototypes(Handle<JSObject>(JSObject::cast(object->GetPrototype())), |
| 1966 | v0, holder, a1, a3, t0, name, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1967 | |
| 1968 | Register receiver = v0; |
| 1969 | Register index = t1; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1970 | Register scratch = a3; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1971 | Register result = v0; |
| 1972 | __ lw(receiver, MemOperand(sp, argc * kPointerSize)); |
| 1973 | if (argc > 0) { |
| 1974 | __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize)); |
| 1975 | } else { |
| 1976 | __ LoadRoot(index, Heap::kUndefinedValueRootIndex); |
| 1977 | } |
| 1978 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1979 | StringCharAtGenerator generator(receiver, |
| 1980 | index, |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1981 | scratch, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1982 | result, |
| 1983 | &miss, // When not a string. |
| 1984 | &miss, // When not a number. |
| 1985 | index_out_of_range_label, |
| 1986 | STRING_INDEX_IS_NUMBER); |
| 1987 | generator.GenerateFast(masm()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1988 | __ Drop(argc + 1); |
| 1989 | __ Ret(); |
| 1990 | |
| 1991 | StubRuntimeCallHelper call_helper; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1992 | generator.GenerateSlow(masm(), call_helper); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1993 | |
| 1994 | if (index_out_of_range.is_linked()) { |
| 1995 | __ bind(&index_out_of_range); |
| 1996 | __ LoadRoot(v0, Heap::kEmptyStringRootIndex); |
| 1997 | __ Drop(argc + 1); |
| 1998 | __ Ret(); |
| 1999 | } |
| 2000 | |
| 2001 | __ bind(&miss); |
| 2002 | // Restore function name in a2. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2003 | __ li(a2, name); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2004 | __ bind(&name_miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2005 | GenerateMissBranch(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2006 | |
| 2007 | // Return the generated code. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2008 | return GetCode(function); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2012 | Handle<Code> CallStubCompiler::CompileStringFromCharCodeCall( |
| 2013 | Handle<Object> object, |
| 2014 | Handle<JSObject> holder, |
| 2015 | Handle<JSGlobalPropertyCell> cell, |
| 2016 | Handle<JSFunction> function, |
| 2017 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2018 | // ----------- S t a t e ------------- |
| 2019 | // -- a2 : function name |
| 2020 | // -- ra : return address |
| 2021 | // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based) |
| 2022 | // -- ... |
| 2023 | // -- sp[argc * 4] : receiver |
| 2024 | // ----------------------------------- |
| 2025 | |
| 2026 | const int argc = arguments().immediate(); |
| 2027 | |
| 2028 | // If the object is not a JSObject or we got an unexpected number of |
| 2029 | // arguments, bail out to the regular call. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2030 | if (!object->IsJSObject() || argc != 1) return Handle<Code>::null(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2031 | |
| 2032 | Label miss; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2033 | GenerateNameCheck(name, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2034 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2035 | if (cell.is_null()) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2036 | __ lw(a1, MemOperand(sp, 1 * kPointerSize)); |
| 2037 | |
| 2038 | STATIC_ASSERT(kSmiTag == 0); |
| 2039 | __ JumpIfSmi(a1, &miss); |
| 2040 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2041 | CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0, |
| 2042 | name, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2043 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2044 | ASSERT(cell->value() == *function); |
| 2045 | GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name, |
| 2046 | &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2047 | GenerateLoadFunctionFromCell(cell, function, &miss); |
| 2048 | } |
| 2049 | |
| 2050 | // Load the char code argument. |
| 2051 | Register code = a1; |
| 2052 | __ lw(code, MemOperand(sp, 0 * kPointerSize)); |
| 2053 | |
| 2054 | // Check the code is a smi. |
| 2055 | Label slow; |
| 2056 | STATIC_ASSERT(kSmiTag == 0); |
| 2057 | __ JumpIfNotSmi(code, &slow); |
| 2058 | |
| 2059 | // Convert the smi code to uint16. |
| 2060 | __ And(code, code, Operand(Smi::FromInt(0xffff))); |
| 2061 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2062 | StringCharFromCodeGenerator generator(code, v0); |
| 2063 | generator.GenerateFast(masm()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2064 | __ Drop(argc + 1); |
| 2065 | __ Ret(); |
| 2066 | |
| 2067 | StubRuntimeCallHelper call_helper; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2068 | generator.GenerateSlow(masm(), call_helper); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2069 | |
| 2070 | // Tail call the full function. We do not have to patch the receiver |
| 2071 | // because the function makes no use of it. |
| 2072 | __ bind(&slow); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 2073 | __ InvokeFunction( |
| 2074 | function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2075 | |
| 2076 | __ bind(&miss); |
| 2077 | // a2: function name. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2078 | GenerateMissBranch(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2079 | |
| 2080 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2081 | return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2085 | Handle<Code> CallStubCompiler::CompileMathFloorCall( |
| 2086 | Handle<Object> object, |
| 2087 | Handle<JSObject> holder, |
| 2088 | Handle<JSGlobalPropertyCell> cell, |
| 2089 | Handle<JSFunction> function, |
| 2090 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2091 | // ----------- S t a t e ------------- |
| 2092 | // -- a2 : function name |
| 2093 | // -- ra : return address |
| 2094 | // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based) |
| 2095 | // -- ... |
| 2096 | // -- sp[argc * 4] : receiver |
| 2097 | // ----------------------------------- |
| 2098 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2099 | if (!CpuFeatures::IsSupported(FPU)) { |
| 2100 | return Handle<Code>::null(); |
| 2101 | } |
| 2102 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2103 | CpuFeatures::Scope scope_fpu(FPU); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2104 | const int argc = arguments().immediate(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2105 | // If the object is not a JSObject or we got an unexpected number of |
| 2106 | // arguments, bail out to the regular call. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2107 | if (!object->IsJSObject() || argc != 1) return Handle<Code>::null(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2108 | |
| 2109 | Label miss, slow; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2110 | GenerateNameCheck(name, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2111 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2112 | if (cell.is_null()) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2113 | __ lw(a1, MemOperand(sp, 1 * kPointerSize)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2114 | STATIC_ASSERT(kSmiTag == 0); |
| 2115 | __ JumpIfSmi(a1, &miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2116 | CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0, |
| 2117 | name, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2118 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2119 | ASSERT(cell->value() == *function); |
| 2120 | GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name, |
| 2121 | &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2122 | GenerateLoadFunctionFromCell(cell, function, &miss); |
| 2123 | } |
| 2124 | |
| 2125 | // Load the (only) argument into v0. |
| 2126 | __ lw(v0, MemOperand(sp, 0 * kPointerSize)); |
| 2127 | |
| 2128 | // If the argument is a smi, just return. |
| 2129 | STATIC_ASSERT(kSmiTag == 0); |
| 2130 | __ And(t0, v0, Operand(kSmiTagMask)); |
| 2131 | __ Drop(argc + 1, eq, t0, Operand(zero_reg)); |
| 2132 | __ Ret(eq, t0, Operand(zero_reg)); |
| 2133 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2134 | __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2135 | |
| 2136 | Label wont_fit_smi, no_fpu_error, restore_fcsr_and_return; |
| 2137 | |
| 2138 | // If fpu is enabled, we use the floor instruction. |
| 2139 | |
| 2140 | // Load the HeapNumber value. |
| 2141 | __ ldc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset)); |
| 2142 | |
| 2143 | // Backup FCSR. |
| 2144 | __ cfc1(a3, FCSR); |
| 2145 | // Clearing FCSR clears the exception mask with no side-effects. |
| 2146 | __ ctc1(zero_reg, FCSR); |
| 2147 | // Convert the argument to an integer. |
| 2148 | __ floor_w_d(f0, f0); |
| 2149 | |
| 2150 | // Start checking for special cases. |
| 2151 | // Get the argument exponent and clear the sign bit. |
| 2152 | __ lw(t1, FieldMemOperand(v0, HeapNumber::kValueOffset + kPointerSize)); |
| 2153 | __ And(t2, t1, Operand(~HeapNumber::kSignMask)); |
| 2154 | __ srl(t2, t2, HeapNumber::kMantissaBitsInTopWord); |
| 2155 | |
| 2156 | // Retrieve FCSR and check for fpu errors. |
| 2157 | __ cfc1(t5, FCSR); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 2158 | __ And(t5, t5, Operand(kFCSRExceptionFlagMask)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2159 | __ Branch(&no_fpu_error, eq, t5, Operand(zero_reg)); |
| 2160 | |
| 2161 | // Check for NaN, Infinity, and -Infinity. |
| 2162 | // They are invariant through a Math.Floor call, so just |
| 2163 | // return the original argument. |
| 2164 | __ Subu(t3, t2, Operand(HeapNumber::kExponentMask |
| 2165 | >> HeapNumber::kMantissaBitsInTopWord)); |
| 2166 | __ Branch(&restore_fcsr_and_return, eq, t3, Operand(zero_reg)); |
| 2167 | // We had an overflow or underflow in the conversion. Check if we |
| 2168 | // have a big exponent. |
| 2169 | // If greater or equal, the argument is already round and in v0. |
| 2170 | __ Branch(&restore_fcsr_and_return, ge, t3, |
| 2171 | Operand(HeapNumber::kMantissaBits)); |
| 2172 | __ Branch(&wont_fit_smi); |
| 2173 | |
| 2174 | __ bind(&no_fpu_error); |
| 2175 | // Move the result back to v0. |
| 2176 | __ mfc1(v0, f0); |
| 2177 | // Check if the result fits into a smi. |
| 2178 | __ Addu(a1, v0, Operand(0x40000000)); |
| 2179 | __ Branch(&wont_fit_smi, lt, a1, Operand(zero_reg)); |
| 2180 | // Tag the result. |
| 2181 | STATIC_ASSERT(kSmiTag == 0); |
| 2182 | __ sll(v0, v0, kSmiTagSize); |
| 2183 | |
| 2184 | // Check for -0. |
| 2185 | __ Branch(&restore_fcsr_and_return, ne, v0, Operand(zero_reg)); |
| 2186 | // t1 already holds the HeapNumber exponent. |
| 2187 | __ And(t0, t1, Operand(HeapNumber::kSignMask)); |
| 2188 | // If our HeapNumber is negative it was -0, so load its address and return. |
| 2189 | // Else v0 is loaded with 0, so we can also just return. |
| 2190 | __ Branch(&restore_fcsr_and_return, eq, t0, Operand(zero_reg)); |
| 2191 | __ lw(v0, MemOperand(sp, 0 * kPointerSize)); |
| 2192 | |
| 2193 | __ bind(&restore_fcsr_and_return); |
| 2194 | // Restore FCSR and return. |
| 2195 | __ ctc1(a3, FCSR); |
| 2196 | |
| 2197 | __ Drop(argc + 1); |
| 2198 | __ Ret(); |
| 2199 | |
| 2200 | __ bind(&wont_fit_smi); |
| 2201 | // Restore FCSR and fall to slow case. |
| 2202 | __ ctc1(a3, FCSR); |
| 2203 | |
| 2204 | __ bind(&slow); |
| 2205 | // Tail call the full function. We do not have to patch the receiver |
| 2206 | // because the function makes no use of it. |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 2207 | __ InvokeFunction( |
| 2208 | function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2209 | |
| 2210 | __ bind(&miss); |
| 2211 | // a2: function name. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2212 | GenerateMissBranch(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2213 | |
| 2214 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2215 | return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2219 | Handle<Code> CallStubCompiler::CompileMathAbsCall( |
| 2220 | Handle<Object> object, |
| 2221 | Handle<JSObject> holder, |
| 2222 | Handle<JSGlobalPropertyCell> cell, |
| 2223 | Handle<JSFunction> function, |
| 2224 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2225 | // ----------- S t a t e ------------- |
| 2226 | // -- a2 : function name |
| 2227 | // -- ra : return address |
| 2228 | // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based) |
| 2229 | // -- ... |
| 2230 | // -- sp[argc * 4] : receiver |
| 2231 | // ----------------------------------- |
| 2232 | |
| 2233 | const int argc = arguments().immediate(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2234 | // If the object is not a JSObject or we got an unexpected number of |
| 2235 | // arguments, bail out to the regular call. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2236 | if (!object->IsJSObject() || argc != 1) return Handle<Code>::null(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2237 | |
| 2238 | Label miss; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2239 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2240 | GenerateNameCheck(name, &miss); |
| 2241 | if (cell.is_null()) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2242 | __ lw(a1, MemOperand(sp, 1 * kPointerSize)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2243 | STATIC_ASSERT(kSmiTag == 0); |
| 2244 | __ JumpIfSmi(a1, &miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2245 | CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0, |
| 2246 | name, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2247 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2248 | ASSERT(cell->value() == *function); |
| 2249 | GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name, |
| 2250 | &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2251 | GenerateLoadFunctionFromCell(cell, function, &miss); |
| 2252 | } |
| 2253 | |
| 2254 | // Load the (only) argument into v0. |
| 2255 | __ lw(v0, MemOperand(sp, 0 * kPointerSize)); |
| 2256 | |
| 2257 | // Check if the argument is a smi. |
| 2258 | Label not_smi; |
| 2259 | STATIC_ASSERT(kSmiTag == 0); |
| 2260 | __ JumpIfNotSmi(v0, ¬_smi); |
| 2261 | |
| 2262 | // Do bitwise not or do nothing depending on the sign of the |
| 2263 | // argument. |
| 2264 | __ sra(t0, v0, kBitsPerInt - 1); |
| 2265 | __ Xor(a1, v0, t0); |
| 2266 | |
| 2267 | // Add 1 or do nothing depending on the sign of the argument. |
| 2268 | __ Subu(v0, a1, t0); |
| 2269 | |
| 2270 | // If the result is still negative, go to the slow case. |
| 2271 | // This only happens for the most negative smi. |
| 2272 | Label slow; |
| 2273 | __ Branch(&slow, lt, v0, Operand(zero_reg)); |
| 2274 | |
| 2275 | // Smi case done. |
| 2276 | __ Drop(argc + 1); |
| 2277 | __ Ret(); |
| 2278 | |
| 2279 | // Check if the argument is a heap number and load its exponent and |
| 2280 | // sign. |
| 2281 | __ bind(¬_smi); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2282 | __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2283 | __ lw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset)); |
| 2284 | |
| 2285 | // Check the sign of the argument. If the argument is positive, |
| 2286 | // just return it. |
| 2287 | Label negative_sign; |
| 2288 | __ And(t0, a1, Operand(HeapNumber::kSignMask)); |
| 2289 | __ Branch(&negative_sign, ne, t0, Operand(zero_reg)); |
| 2290 | __ Drop(argc + 1); |
| 2291 | __ Ret(); |
| 2292 | |
| 2293 | // If the argument is negative, clear the sign, and return a new |
| 2294 | // number. |
| 2295 | __ bind(&negative_sign); |
| 2296 | __ Xor(a1, a1, Operand(HeapNumber::kSignMask)); |
| 2297 | __ lw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset)); |
| 2298 | __ LoadRoot(t2, Heap::kHeapNumberMapRootIndex); |
| 2299 | __ AllocateHeapNumber(v0, t0, t1, t2, &slow); |
| 2300 | __ sw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset)); |
| 2301 | __ sw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset)); |
| 2302 | __ Drop(argc + 1); |
| 2303 | __ Ret(); |
| 2304 | |
| 2305 | // Tail call the full function. We do not have to patch the receiver |
| 2306 | // because the function makes no use of it. |
| 2307 | __ bind(&slow); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 2308 | __ InvokeFunction( |
| 2309 | function, arguments(), JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2310 | |
| 2311 | __ bind(&miss); |
| 2312 | // a2: function name. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2313 | GenerateMissBranch(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2314 | |
| 2315 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2316 | return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2320 | Handle<Code> CallStubCompiler::CompileFastApiCall( |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2321 | const CallOptimization& optimization, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2322 | Handle<Object> object, |
| 2323 | Handle<JSObject> holder, |
| 2324 | Handle<JSGlobalPropertyCell> cell, |
| 2325 | Handle<JSFunction> function, |
| 2326 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2327 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2328 | Counters* counters = isolate()->counters(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2329 | |
| 2330 | ASSERT(optimization.is_simple_api_call()); |
| 2331 | // Bail out if object is a global object as we don't want to |
| 2332 | // repatch it to global receiver. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2333 | if (object->IsGlobalObject()) return Handle<Code>::null(); |
| 2334 | if (!cell.is_null()) return Handle<Code>::null(); |
| 2335 | if (!object->IsJSObject()) return Handle<Code>::null(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2336 | int depth = optimization.GetPrototypeDepthOfExpectedType( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2337 | Handle<JSObject>::cast(object), holder); |
| 2338 | if (depth == kInvalidProtoDepth) return Handle<Code>::null(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2339 | |
| 2340 | Label miss, miss_before_stack_reserved; |
| 2341 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2342 | GenerateNameCheck(name, &miss_before_stack_reserved); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2343 | |
| 2344 | // Get the receiver from the stack. |
| 2345 | const int argc = arguments().immediate(); |
| 2346 | __ lw(a1, MemOperand(sp, argc * kPointerSize)); |
| 2347 | |
| 2348 | // Check that the receiver isn't a smi. |
| 2349 | __ JumpIfSmi(a1, &miss_before_stack_reserved); |
| 2350 | |
| 2351 | __ IncrementCounter(counters->call_const(), 1, a0, a3); |
| 2352 | __ IncrementCounter(counters->call_const_fast_api(), 1, a0, a3); |
| 2353 | |
| 2354 | ReserveSpaceForFastApiCall(masm(), a0); |
| 2355 | |
| 2356 | // Check that the maps haven't changed and find a Holder as a side effect. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2357 | CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0, name, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2358 | depth, &miss); |
| 2359 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2360 | GenerateFastApiDirectCall(masm(), optimization, argc); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2361 | |
| 2362 | __ bind(&miss); |
| 2363 | FreeSpaceForFastApiCall(masm()); |
| 2364 | |
| 2365 | __ bind(&miss_before_stack_reserved); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2366 | GenerateMissBranch(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2367 | |
| 2368 | // Return the generated code. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2369 | return GetCode(function); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2370 | } |
| 2371 | |
| 2372 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2373 | Handle<Code> CallStubCompiler::CompileCallConstant(Handle<Object> object, |
| 2374 | Handle<JSObject> holder, |
| 2375 | Handle<JSFunction> function, |
| 2376 | Handle<String> name, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2377 | CheckType check) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2378 | // ----------- S t a t e ------------- |
| 2379 | // -- a2 : name |
| 2380 | // -- ra : return address |
| 2381 | // ----------------------------------- |
| 2382 | if (HasCustomCallGenerator(function)) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2383 | Handle<Code> code = CompileCustomCall(object, holder, |
| 2384 | Handle<JSGlobalPropertyCell>::null(), |
| 2385 | function, name); |
| 2386 | // A null handle means bail out to the regular compiler code below. |
| 2387 | if (!code.is_null()) return code; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | Label miss; |
| 2391 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2392 | GenerateNameCheck(name, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2393 | |
| 2394 | // Get the receiver from the stack. |
| 2395 | const int argc = arguments().immediate(); |
| 2396 | __ lw(a1, MemOperand(sp, argc * kPointerSize)); |
| 2397 | |
| 2398 | // Check that the receiver isn't a smi. |
| 2399 | if (check != NUMBER_CHECK) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2400 | __ JumpIfSmi(a1, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | // Make sure that it's okay not to patch the on stack receiver |
| 2404 | // unless we're doing a receiver map check. |
| 2405 | ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2406 | switch (check) { |
| 2407 | case RECEIVER_MAP_CHECK: |
| 2408 | __ IncrementCounter(masm()->isolate()->counters()->call_const(), |
| 2409 | 1, a0, a3); |
| 2410 | |
| 2411 | // Check that the maps haven't changed. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2412 | CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0, |
| 2413 | name, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2414 | |
| 2415 | // Patch the receiver on the stack with the global proxy if |
| 2416 | // necessary. |
| 2417 | if (object->IsGlobalObject()) { |
| 2418 | __ lw(a3, FieldMemOperand(a1, GlobalObject::kGlobalReceiverOffset)); |
| 2419 | __ sw(a3, MemOperand(sp, argc * kPointerSize)); |
| 2420 | } |
| 2421 | break; |
| 2422 | |
| 2423 | case STRING_CHECK: |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2424 | if (function->IsBuiltin() || !function->shared()->is_classic_mode()) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2425 | // Check that the object is a two-byte string or a symbol. |
| 2426 | __ GetObjectType(a1, a3, a3); |
| 2427 | __ Branch(&miss, Ugreater_equal, a3, Operand(FIRST_NONSTRING_TYPE)); |
| 2428 | // Check that the maps starting from the prototype haven't changed. |
| 2429 | GenerateDirectLoadGlobalFunctionPrototype( |
| 2430 | masm(), Context::STRING_FUNCTION_INDEX, a0, &miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2431 | CheckPrototypes( |
| 2432 | Handle<JSObject>(JSObject::cast(object->GetPrototype())), |
| 2433 | a0, holder, a3, a1, t0, name, &miss); |
| 2434 | } else { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2435 | // Calling non-strict non-builtins with a value as the receiver |
| 2436 | // requires boxing. |
| 2437 | __ jmp(&miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2438 | } |
| 2439 | break; |
| 2440 | |
| 2441 | case NUMBER_CHECK: |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2442 | if (function->IsBuiltin() || !function->shared()->is_classic_mode()) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2443 | Label fast; |
| 2444 | // Check that the object is a smi or a heap number. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2445 | __ JumpIfSmi(a1, &fast); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2446 | __ GetObjectType(a1, a0, a0); |
| 2447 | __ Branch(&miss, ne, a0, Operand(HEAP_NUMBER_TYPE)); |
| 2448 | __ bind(&fast); |
| 2449 | // Check that the maps starting from the prototype haven't changed. |
| 2450 | GenerateDirectLoadGlobalFunctionPrototype( |
| 2451 | masm(), Context::NUMBER_FUNCTION_INDEX, a0, &miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2452 | CheckPrototypes( |
| 2453 | Handle<JSObject>(JSObject::cast(object->GetPrototype())), |
| 2454 | a0, holder, a3, a1, t0, name, &miss); |
| 2455 | } else { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2456 | // Calling non-strict non-builtins with a value as the receiver |
| 2457 | // requires boxing. |
| 2458 | __ jmp(&miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2459 | } |
| 2460 | break; |
| 2461 | |
| 2462 | case BOOLEAN_CHECK: |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2463 | if (function->IsBuiltin() || !function->shared()->is_classic_mode()) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2464 | Label fast; |
| 2465 | // Check that the object is a boolean. |
| 2466 | __ LoadRoot(t0, Heap::kTrueValueRootIndex); |
| 2467 | __ Branch(&fast, eq, a1, Operand(t0)); |
| 2468 | __ LoadRoot(t0, Heap::kFalseValueRootIndex); |
| 2469 | __ Branch(&miss, ne, a1, Operand(t0)); |
| 2470 | __ bind(&fast); |
| 2471 | // Check that the maps starting from the prototype haven't changed. |
| 2472 | GenerateDirectLoadGlobalFunctionPrototype( |
| 2473 | masm(), Context::BOOLEAN_FUNCTION_INDEX, a0, &miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2474 | CheckPrototypes( |
| 2475 | Handle<JSObject>(JSObject::cast(object->GetPrototype())), |
| 2476 | a0, holder, a3, a1, t0, name, &miss); |
| 2477 | } else { |
| 2478 | // Calling non-strict non-builtins with a value as the receiver |
| 2479 | // requires boxing. |
| 2480 | __ jmp(&miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2481 | } |
| 2482 | break; |
| 2483 | } |
| 2484 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2485 | CallKind call_kind = CallICBase::Contextual::decode(extra_state_) |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 2486 | ? CALL_AS_FUNCTION |
| 2487 | : CALL_AS_METHOD; |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 2488 | __ InvokeFunction( |
| 2489 | function, arguments(), JUMP_FUNCTION, NullCallWrapper(), call_kind); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2490 | |
| 2491 | // Handle call cache miss. |
| 2492 | __ bind(&miss); |
| 2493 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2494 | GenerateMissBranch(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2495 | |
| 2496 | // Return the generated code. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2497 | return GetCode(function); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2501 | Handle<Code> CallStubCompiler::CompileCallInterceptor(Handle<JSObject> object, |
| 2502 | Handle<JSObject> holder, |
| 2503 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2504 | // ----------- S t a t e ------------- |
| 2505 | // -- a2 : name |
| 2506 | // -- ra : return address |
| 2507 | // ----------------------------------- |
| 2508 | |
| 2509 | Label miss; |
| 2510 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2511 | GenerateNameCheck(name, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2512 | |
| 2513 | // Get the number of arguments. |
| 2514 | const int argc = arguments().immediate(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2515 | LookupResult lookup(isolate()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2516 | LookupPostInterceptor(holder, name, &lookup); |
| 2517 | |
| 2518 | // Get the receiver from the stack. |
| 2519 | __ lw(a1, MemOperand(sp, argc * kPointerSize)); |
| 2520 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2521 | CallInterceptorCompiler compiler(this, arguments(), a2, extra_state_); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2522 | compiler.Compile(masm(), object, holder, name, &lookup, a1, a3, t0, a0, |
| 2523 | &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2524 | |
| 2525 | // Move returned value, the function to call, to a1. |
| 2526 | __ mov(a1, v0); |
| 2527 | // Restore receiver. |
| 2528 | __ lw(a0, MemOperand(sp, argc * kPointerSize)); |
| 2529 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2530 | GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2531 | |
| 2532 | // Handle call cache miss. |
| 2533 | __ bind(&miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2534 | GenerateMissBranch(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2535 | |
| 2536 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2537 | return GetCode(Code::INTERCEPTOR, name); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2541 | Handle<Code> CallStubCompiler::CompileCallGlobal( |
| 2542 | Handle<JSObject> object, |
| 2543 | Handle<GlobalObject> holder, |
| 2544 | Handle<JSGlobalPropertyCell> cell, |
| 2545 | Handle<JSFunction> function, |
| 2546 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2547 | // ----------- S t a t e ------------- |
| 2548 | // -- a2 : name |
| 2549 | // -- ra : return address |
| 2550 | // ----------------------------------- |
| 2551 | |
| 2552 | if (HasCustomCallGenerator(function)) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2553 | Handle<Code> code = CompileCustomCall(object, holder, cell, function, name); |
| 2554 | // A null handle means bail out to the regular compiler code below. |
| 2555 | if (!code.is_null()) return code; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | Label miss; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2559 | GenerateNameCheck(name, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2560 | |
| 2561 | // Get the number of arguments. |
| 2562 | const int argc = arguments().immediate(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2563 | GenerateGlobalReceiverCheck(object, holder, name, &miss); |
| 2564 | GenerateLoadFunctionFromCell(cell, function, &miss); |
| 2565 | |
| 2566 | // Patch the receiver on the stack with the global proxy if |
| 2567 | // necessary. |
| 2568 | if (object->IsGlobalObject()) { |
| 2569 | __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset)); |
| 2570 | __ sw(a3, MemOperand(sp, argc * kPointerSize)); |
| 2571 | } |
| 2572 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2573 | // Set up the context (function already in r1). |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2574 | __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 2575 | |
| 2576 | // Jump to the cached code (tail call). |
| 2577 | Counters* counters = masm()->isolate()->counters(); |
| 2578 | __ IncrementCounter(counters->call_global_inline(), 1, a3, t0); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2579 | ParameterCount expected(function->shared()->formal_parameter_count()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2580 | CallKind call_kind = CallICBase::Contextual::decode(extra_state_) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2581 | ? CALL_AS_FUNCTION |
| 2582 | : CALL_AS_METHOD; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2583 | // We call indirectly through the code field in the function to |
| 2584 | // allow recompilation to take effect without changing any of the |
| 2585 | // call sites. |
| 2586 | __ lw(a3, FieldMemOperand(a1, JSFunction::kCodeEntryOffset)); |
| 2587 | __ InvokeCode(a3, expected, arguments(), JUMP_FUNCTION, |
| 2588 | NullCallWrapper(), call_kind); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2589 | |
| 2590 | // Handle call cache miss. |
| 2591 | __ bind(&miss); |
| 2592 | __ IncrementCounter(counters->call_global_inline_miss(), 1, a1, a3); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2593 | GenerateMissBranch(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2594 | |
| 2595 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2596 | return GetCode(Code::NORMAL, name); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2597 | } |
| 2598 | |
| 2599 | |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 2600 | Handle<Code> StoreStubCompiler::CompileStoreField(Handle<JSObject> object, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2601 | int index, |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 2602 | Handle<Map> transition, |
| 2603 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2604 | // ----------- S t a t e ------------- |
| 2605 | // -- a0 : value |
| 2606 | // -- a1 : receiver |
| 2607 | // -- a2 : name |
| 2608 | // -- ra : return address |
| 2609 | // ----------------------------------- |
| 2610 | Label miss; |
| 2611 | |
| 2612 | // Name register might be clobbered. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2613 | GenerateStoreField(masm(), |
| 2614 | object, |
| 2615 | index, |
| 2616 | transition, |
| 2617 | name, |
| 2618 | a1, a2, a3, t0, |
| 2619 | &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2620 | __ bind(&miss); |
| 2621 | __ li(a2, Operand(Handle<String>(name))); // Restore name. |
| 2622 | Handle<Code> ic = masm()->isolate()->builtins()->Builtins::StoreIC_Miss(); |
| 2623 | __ Jump(ic, RelocInfo::CODE_TARGET); |
| 2624 | |
| 2625 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2626 | return GetCode(transition.is_null() |
| 2627 | ? Code::FIELD |
| 2628 | : Code::MAP_TRANSITION, name); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2629 | } |
| 2630 | |
| 2631 | |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 2632 | Handle<Code> StoreStubCompiler::CompileStoreCallback( |
| 2633 | Handle<JSObject> object, |
| 2634 | Handle<AccessorInfo> callback, |
| 2635 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2636 | // ----------- S t a t e ------------- |
| 2637 | // -- a0 : value |
| 2638 | // -- a1 : receiver |
| 2639 | // -- a2 : name |
| 2640 | // -- ra : return address |
| 2641 | // ----------------------------------- |
| 2642 | Label miss; |
| 2643 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2644 | // Check that the map of the object hasn't changed. |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 2645 | __ CheckMap(a1, a3, Handle<Map>(object->map()), &miss, |
| 2646 | DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2647 | |
| 2648 | // Perform global security token check if needed. |
| 2649 | if (object->IsJSGlobalProxy()) { |
| 2650 | __ CheckAccessGlobalProxy(a1, a3, &miss); |
| 2651 | } |
| 2652 | |
| 2653 | // Stub never generated for non-global objects that require access |
| 2654 | // checks. |
| 2655 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
| 2656 | |
| 2657 | __ push(a1); // Receiver. |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 2658 | __ li(a3, Operand(callback)); // Callback info. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2659 | __ Push(a3, a2, a0); |
| 2660 | |
| 2661 | // Do tail-call to the runtime system. |
| 2662 | ExternalReference store_callback_property = |
| 2663 | ExternalReference(IC_Utility(IC::kStoreCallbackProperty), |
| 2664 | masm()->isolate()); |
| 2665 | __ TailCallExternalReference(store_callback_property, 4, 1); |
| 2666 | |
| 2667 | // Handle store cache miss. |
| 2668 | __ bind(&miss); |
| 2669 | Handle<Code> ic = masm()->isolate()->builtins()->StoreIC_Miss(); |
| 2670 | __ Jump(ic, RelocInfo::CODE_TARGET); |
| 2671 | |
| 2672 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2673 | return GetCode(Code::CALLBACKS, name); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2674 | } |
| 2675 | |
| 2676 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2677 | Handle<Code> StoreStubCompiler::CompileStoreViaSetter( |
svenpanne@chromium.org | 619781a | 2012-07-05 08:22:44 +0000 | [diff] [blame^] | 2678 | Handle<String> name, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2679 | Handle<JSObject> receiver, |
svenpanne@chromium.org | 619781a | 2012-07-05 08:22:44 +0000 | [diff] [blame^] | 2680 | Handle<JSObject> holder, |
| 2681 | Handle<JSFunction> setter) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2682 | // ----------- S t a t e ------------- |
| 2683 | // -- a0 : value |
| 2684 | // -- a1 : receiver |
| 2685 | // -- a2 : name |
| 2686 | // -- ra : return address |
| 2687 | // ----------------------------------- |
| 2688 | Label miss; |
| 2689 | |
svenpanne@chromium.org | 619781a | 2012-07-05 08:22:44 +0000 | [diff] [blame^] | 2690 | // Check that the maps haven't changed. |
| 2691 | __ JumpIfSmi(a1, &miss); |
| 2692 | CheckPrototypes(receiver, a1, holder, a3, t0, t1, name, &miss); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2693 | |
| 2694 | { |
| 2695 | FrameScope scope(masm(), StackFrame::INTERNAL); |
| 2696 | |
| 2697 | // Save value register, so we can restore it later. |
| 2698 | __ push(a0); |
| 2699 | |
svenpanne@chromium.org | 619781a | 2012-07-05 08:22:44 +0000 | [diff] [blame^] | 2700 | // Call the JavaScript setter with the receiver and the value on the stack. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2701 | __ push(a1); |
| 2702 | __ push(a0); |
| 2703 | ParameterCount actual(1); |
| 2704 | __ InvokeFunction(setter, actual, CALL_FUNCTION, NullCallWrapper(), |
| 2705 | CALL_AS_METHOD); |
| 2706 | |
| 2707 | // We have to return the passed value, not the return value of the setter. |
| 2708 | __ pop(v0); |
| 2709 | |
| 2710 | // Restore context register. |
| 2711 | __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 2712 | } |
| 2713 | __ Ret(); |
| 2714 | |
| 2715 | __ bind(&miss); |
| 2716 | Handle<Code> ic = masm()->isolate()->builtins()->StoreIC_Miss(); |
| 2717 | __ Jump(ic, RelocInfo::CODE_TARGET); |
| 2718 | |
| 2719 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2720 | return GetCode(Code::CALLBACKS, name); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 2724 | Handle<Code> StoreStubCompiler::CompileStoreInterceptor( |
| 2725 | Handle<JSObject> receiver, |
| 2726 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2727 | // ----------- S t a t e ------------- |
| 2728 | // -- a0 : value |
| 2729 | // -- a1 : receiver |
| 2730 | // -- a2 : name |
| 2731 | // -- ra : return address |
| 2732 | // ----------------------------------- |
| 2733 | Label miss; |
| 2734 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2735 | // Check that the map of the object hasn't changed. |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 2736 | __ CheckMap(a1, a3, Handle<Map>(receiver->map()), &miss, |
| 2737 | DO_SMI_CHECK, ALLOW_ELEMENT_TRANSITION_MAPS); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2738 | |
| 2739 | // Perform global security token check if needed. |
| 2740 | if (receiver->IsJSGlobalProxy()) { |
| 2741 | __ CheckAccessGlobalProxy(a1, a3, &miss); |
| 2742 | } |
| 2743 | |
| 2744 | // Stub is never generated for non-global objects that require access |
| 2745 | // checks. |
| 2746 | ASSERT(receiver->IsJSGlobalProxy() || !receiver->IsAccessCheckNeeded()); |
| 2747 | |
| 2748 | __ Push(a1, a2, a0); // Receiver, name, value. |
| 2749 | |
| 2750 | __ li(a0, Operand(Smi::FromInt(strict_mode_))); |
| 2751 | __ push(a0); // Strict mode. |
| 2752 | |
| 2753 | // Do tail-call to the runtime system. |
| 2754 | ExternalReference store_ic_property = |
| 2755 | ExternalReference(IC_Utility(IC::kStoreInterceptorProperty), |
| 2756 | masm()->isolate()); |
| 2757 | __ TailCallExternalReference(store_ic_property, 4, 1); |
| 2758 | |
| 2759 | // Handle store cache miss. |
| 2760 | __ bind(&miss); |
| 2761 | Handle<Code> ic = masm()->isolate()->builtins()->Builtins::StoreIC_Miss(); |
| 2762 | __ Jump(ic, RelocInfo::CODE_TARGET); |
| 2763 | |
| 2764 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2765 | return GetCode(Code::INTERCEPTOR, name); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 2769 | Handle<Code> StoreStubCompiler::CompileStoreGlobal( |
| 2770 | Handle<GlobalObject> object, |
| 2771 | Handle<JSGlobalPropertyCell> cell, |
| 2772 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2773 | // ----------- S t a t e ------------- |
| 2774 | // -- a0 : value |
| 2775 | // -- a1 : receiver |
| 2776 | // -- a2 : name |
| 2777 | // -- ra : return address |
| 2778 | // ----------------------------------- |
| 2779 | Label miss; |
| 2780 | |
| 2781 | // Check that the map of the global has not changed. |
| 2782 | __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset)); |
| 2783 | __ Branch(&miss, ne, a3, Operand(Handle<Map>(object->map()))); |
| 2784 | |
| 2785 | // Check that the value in the cell is not the hole. If it is, this |
| 2786 | // cell could have been deleted and reintroducing the global needs |
| 2787 | // to update the property details in the property dictionary of the |
| 2788 | // global object. We bail out to the runtime system to do that. |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 2789 | __ li(t0, Operand(cell)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2790 | __ LoadRoot(t1, Heap::kTheHoleValueRootIndex); |
| 2791 | __ lw(t2, FieldMemOperand(t0, JSGlobalPropertyCell::kValueOffset)); |
| 2792 | __ Branch(&miss, eq, t1, Operand(t2)); |
| 2793 | |
| 2794 | // Store the value in the cell. |
| 2795 | __ sw(a0, FieldMemOperand(t0, JSGlobalPropertyCell::kValueOffset)); |
| 2796 | __ mov(v0, a0); // Stored value must be returned in v0. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2797 | // Cells are always rescanned, so no write barrier here. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 2798 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2799 | Counters* counters = masm()->isolate()->counters(); |
| 2800 | __ IncrementCounter(counters->named_store_global_inline(), 1, a1, a3); |
| 2801 | __ Ret(); |
| 2802 | |
| 2803 | // Handle store cache miss. |
| 2804 | __ bind(&miss); |
| 2805 | __ IncrementCounter(counters->named_store_global_inline_miss(), 1, a1, a3); |
| 2806 | Handle<Code> ic = masm()->isolate()->builtins()->StoreIC_Miss(); |
| 2807 | __ Jump(ic, RelocInfo::CODE_TARGET); |
| 2808 | |
| 2809 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2810 | return GetCode(Code::NORMAL, name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2814 | Handle<Code> LoadStubCompiler::CompileLoadNonexistent(Handle<String> name, |
| 2815 | Handle<JSObject> object, |
| 2816 | Handle<JSObject> last) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2817 | // ----------- S t a t e ------------- |
| 2818 | // -- a0 : receiver |
| 2819 | // -- ra : return address |
| 2820 | // ----------------------------------- |
| 2821 | Label miss; |
| 2822 | |
| 2823 | // Check that the receiver is not a smi. |
| 2824 | __ JumpIfSmi(a0, &miss); |
| 2825 | |
| 2826 | // Check the maps of the full prototype chain. |
| 2827 | CheckPrototypes(object, a0, last, a3, a1, t0, name, &miss); |
| 2828 | |
| 2829 | // If the last object in the prototype chain is a global object, |
| 2830 | // check that the global property cell is empty. |
| 2831 | if (last->IsGlobalObject()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2832 | GenerateCheckPropertyCell( |
| 2833 | masm(), Handle<GlobalObject>::cast(last), name, a1, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | // Return undefined if maps of the full prototype chain is still the same. |
| 2837 | __ LoadRoot(v0, Heap::kUndefinedValueRootIndex); |
| 2838 | __ Ret(); |
| 2839 | |
| 2840 | __ bind(&miss); |
| 2841 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2842 | |
| 2843 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2844 | return GetCode(Code::NONEXISTENT, factory()->empty_string()); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2848 | Handle<Code> LoadStubCompiler::CompileLoadField(Handle<JSObject> object, |
| 2849 | Handle<JSObject> holder, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2850 | int index, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2851 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2852 | // ----------- S t a t e ------------- |
| 2853 | // -- a0 : receiver |
| 2854 | // -- a2 : name |
| 2855 | // -- ra : return address |
| 2856 | // ----------------------------------- |
| 2857 | Label miss; |
| 2858 | |
| 2859 | __ mov(v0, a0); |
| 2860 | |
| 2861 | GenerateLoadField(object, holder, v0, a3, a1, t0, index, name, &miss); |
| 2862 | __ bind(&miss); |
| 2863 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2864 | |
| 2865 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2866 | return GetCode(Code::FIELD, name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2870 | Handle<Code> LoadStubCompiler::CompileLoadCallback( |
| 2871 | Handle<String> name, |
| 2872 | Handle<JSObject> object, |
| 2873 | Handle<JSObject> holder, |
| 2874 | Handle<AccessorInfo> callback) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2875 | // ----------- S t a t e ------------- |
| 2876 | // -- a0 : receiver |
| 2877 | // -- a2 : name |
| 2878 | // -- ra : return address |
| 2879 | // ----------------------------------- |
| 2880 | Label miss; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2881 | GenerateLoadCallback(object, holder, a0, a2, a3, a1, t0, callback, name, |
| 2882 | &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2883 | __ bind(&miss); |
| 2884 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2885 | |
| 2886 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2887 | return GetCode(Code::CALLBACKS, name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2891 | Handle<Code> LoadStubCompiler::CompileLoadViaGetter( |
| 2892 | Handle<String> name, |
| 2893 | Handle<JSObject> receiver, |
| 2894 | Handle<JSObject> holder, |
| 2895 | Handle<JSFunction> getter) { |
| 2896 | // ----------- S t a t e ------------- |
| 2897 | // -- a0 : receiver |
| 2898 | // -- a2 : name |
| 2899 | // -- ra : return address |
| 2900 | // ----------------------------------- |
| 2901 | Label miss; |
| 2902 | |
| 2903 | // Check that the maps haven't changed. |
| 2904 | __ JumpIfSmi(a0, &miss); |
| 2905 | CheckPrototypes(receiver, a0, holder, a3, t0, a1, name, &miss); |
| 2906 | |
| 2907 | { |
| 2908 | FrameScope scope(masm(), StackFrame::INTERNAL); |
| 2909 | |
| 2910 | // Call the JavaScript getter with the receiver on the stack. |
| 2911 | __ push(a0); |
| 2912 | ParameterCount actual(0); |
| 2913 | __ InvokeFunction(getter, actual, CALL_FUNCTION, NullCallWrapper(), |
| 2914 | CALL_AS_METHOD); |
| 2915 | |
| 2916 | // Restore context register. |
| 2917 | __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 2918 | } |
| 2919 | __ Ret(); |
| 2920 | |
| 2921 | __ bind(&miss); |
| 2922 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2923 | |
| 2924 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2925 | return GetCode(Code::CALLBACKS, name); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2926 | } |
| 2927 | |
| 2928 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2929 | Handle<Code> LoadStubCompiler::CompileLoadConstant(Handle<JSObject> object, |
| 2930 | Handle<JSObject> holder, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2931 | Handle<JSFunction> value, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2932 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2933 | // ----------- S t a t e ------------- |
| 2934 | // -- a0 : receiver |
| 2935 | // -- a2 : name |
| 2936 | // -- ra : return address |
| 2937 | // ----------------------------------- |
| 2938 | Label miss; |
| 2939 | |
| 2940 | GenerateLoadConstant(object, holder, a0, a3, a1, t0, value, name, &miss); |
| 2941 | __ bind(&miss); |
| 2942 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2943 | |
| 2944 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2945 | return GetCode(Code::CONSTANT_FUNCTION, name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2949 | Handle<Code> LoadStubCompiler::CompileLoadInterceptor(Handle<JSObject> object, |
| 2950 | Handle<JSObject> holder, |
| 2951 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2952 | // ----------- S t a t e ------------- |
| 2953 | // -- a0 : receiver |
| 2954 | // -- a2 : name |
| 2955 | // -- ra : return address |
| 2956 | // -- [sp] : receiver |
| 2957 | // ----------------------------------- |
| 2958 | Label miss; |
| 2959 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2960 | LookupResult lookup(isolate()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2961 | LookupPostInterceptor(holder, name, &lookup); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2962 | GenerateLoadInterceptor(object, holder, &lookup, a0, a2, a3, a1, t0, name, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2963 | &miss); |
| 2964 | __ bind(&miss); |
| 2965 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2966 | |
| 2967 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2968 | return GetCode(Code::INTERCEPTOR, name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 2972 | Handle<Code> LoadStubCompiler::CompileLoadGlobal( |
| 2973 | Handle<JSObject> object, |
| 2974 | Handle<GlobalObject> holder, |
| 2975 | Handle<JSGlobalPropertyCell> cell, |
| 2976 | Handle<String> name, |
| 2977 | bool is_dont_delete) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2978 | // ----------- S t a t e ------------- |
| 2979 | // -- a0 : receiver |
| 2980 | // -- a2 : name |
| 2981 | // -- ra : return address |
| 2982 | // ----------------------------------- |
| 2983 | Label miss; |
| 2984 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2985 | // Check that the map of the global has not changed. |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 2986 | __ JumpIfSmi(a0, &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2987 | CheckPrototypes(object, a0, holder, a3, t0, a1, name, &miss); |
| 2988 | |
| 2989 | // Get the value from the cell. |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 2990 | __ li(a3, Operand(cell)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2991 | __ lw(t0, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset)); |
| 2992 | |
| 2993 | // Check for deleted property if property can actually be deleted. |
| 2994 | if (!is_dont_delete) { |
| 2995 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 2996 | __ Branch(&miss, eq, t0, Operand(at)); |
| 2997 | } |
| 2998 | |
| 2999 | __ mov(v0, t0); |
| 3000 | Counters* counters = masm()->isolate()->counters(); |
| 3001 | __ IncrementCounter(counters->named_load_global_stub(), 1, a1, a3); |
| 3002 | __ Ret(); |
| 3003 | |
| 3004 | __ bind(&miss); |
| 3005 | __ IncrementCounter(counters->named_load_global_stub_miss(), 1, a1, a3); |
| 3006 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 3007 | |
| 3008 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3009 | return GetCode(Code::NORMAL, name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3010 | } |
| 3011 | |
| 3012 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3013 | Handle<Code> KeyedLoadStubCompiler::CompileLoadField(Handle<String> name, |
| 3014 | Handle<JSObject> receiver, |
| 3015 | Handle<JSObject> holder, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3016 | int index) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3017 | // ----------- S t a t e ------------- |
| 3018 | // -- ra : return address |
| 3019 | // -- a0 : key |
| 3020 | // -- a1 : receiver |
| 3021 | // ----------------------------------- |
| 3022 | Label miss; |
| 3023 | |
| 3024 | // Check the key is the cached one. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3025 | __ Branch(&miss, ne, a0, Operand(name)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3026 | |
| 3027 | GenerateLoadField(receiver, holder, a1, a2, a3, t0, index, name, &miss); |
| 3028 | __ bind(&miss); |
| 3029 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 3030 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3031 | return GetCode(Code::FIELD, name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3035 | Handle<Code> KeyedLoadStubCompiler::CompileLoadCallback( |
| 3036 | Handle<String> name, |
| 3037 | Handle<JSObject> receiver, |
| 3038 | Handle<JSObject> holder, |
| 3039 | Handle<AccessorInfo> callback) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3040 | // ----------- S t a t e ------------- |
| 3041 | // -- ra : return address |
| 3042 | // -- a0 : key |
| 3043 | // -- a1 : receiver |
| 3044 | // ----------------------------------- |
| 3045 | Label miss; |
| 3046 | |
| 3047 | // Check the key is the cached one. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3048 | __ Branch(&miss, ne, a0, Operand(name)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3049 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3050 | GenerateLoadCallback(receiver, holder, a1, a0, a2, a3, t0, callback, name, |
| 3051 | &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3052 | __ bind(&miss); |
| 3053 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 3054 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3055 | return GetCode(Code::CALLBACKS, name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3059 | Handle<Code> KeyedLoadStubCompiler::CompileLoadConstant( |
| 3060 | Handle<String> name, |
| 3061 | Handle<JSObject> receiver, |
| 3062 | Handle<JSObject> holder, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3063 | Handle<JSFunction> value) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3064 | // ----------- S t a t e ------------- |
| 3065 | // -- ra : return address |
| 3066 | // -- a0 : key |
| 3067 | // -- a1 : receiver |
| 3068 | // ----------------------------------- |
| 3069 | Label miss; |
| 3070 | |
| 3071 | // Check the key is the cached one. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3072 | __ Branch(&miss, ne, a0, Operand(name)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3073 | |
| 3074 | GenerateLoadConstant(receiver, holder, a1, a2, a3, t0, value, name, &miss); |
| 3075 | __ bind(&miss); |
| 3076 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 3077 | |
| 3078 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3079 | return GetCode(Code::CONSTANT_FUNCTION, name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3083 | Handle<Code> KeyedLoadStubCompiler::CompileLoadInterceptor( |
| 3084 | Handle<JSObject> receiver, |
| 3085 | Handle<JSObject> holder, |
| 3086 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3087 | // ----------- S t a t e ------------- |
| 3088 | // -- ra : return address |
| 3089 | // -- a0 : key |
| 3090 | // -- a1 : receiver |
| 3091 | // ----------------------------------- |
| 3092 | Label miss; |
| 3093 | |
| 3094 | // Check the key is the cached one. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3095 | __ Branch(&miss, ne, a0, Operand(name)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3096 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3097 | LookupResult lookup(isolate()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3098 | LookupPostInterceptor(holder, name, &lookup); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3099 | GenerateLoadInterceptor(receiver, holder, &lookup, a1, a0, a2, a3, t0, name, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3100 | &miss); |
| 3101 | __ bind(&miss); |
| 3102 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 3103 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3104 | return GetCode(Code::INTERCEPTOR, name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3108 | Handle<Code> KeyedLoadStubCompiler::CompileLoadArrayLength( |
| 3109 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3110 | // ----------- S t a t e ------------- |
| 3111 | // -- ra : return address |
| 3112 | // -- a0 : key |
| 3113 | // -- a1 : receiver |
| 3114 | // ----------------------------------- |
| 3115 | Label miss; |
| 3116 | |
| 3117 | // Check the key is the cached one. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3118 | __ Branch(&miss, ne, a0, Operand(name)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3119 | |
| 3120 | GenerateLoadArrayLength(masm(), a1, a2, &miss); |
| 3121 | __ bind(&miss); |
| 3122 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 3123 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3124 | return GetCode(Code::CALLBACKS, name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3125 | } |
| 3126 | |
| 3127 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3128 | Handle<Code> KeyedLoadStubCompiler::CompileLoadStringLength( |
| 3129 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3130 | // ----------- S t a t e ------------- |
| 3131 | // -- ra : return address |
| 3132 | // -- a0 : key |
| 3133 | // -- a1 : receiver |
| 3134 | // ----------------------------------- |
| 3135 | Label miss; |
| 3136 | |
| 3137 | Counters* counters = masm()->isolate()->counters(); |
| 3138 | __ IncrementCounter(counters->keyed_load_string_length(), 1, a2, a3); |
| 3139 | |
| 3140 | // Check the key is the cached one. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3141 | __ Branch(&miss, ne, a0, Operand(name)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3142 | |
| 3143 | GenerateLoadStringLength(masm(), a1, a2, a3, &miss, true); |
| 3144 | __ bind(&miss); |
| 3145 | __ DecrementCounter(counters->keyed_load_string_length(), 1, a2, a3); |
| 3146 | |
| 3147 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 3148 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3149 | return GetCode(Code::CALLBACKS, name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3153 | Handle<Code> KeyedLoadStubCompiler::CompileLoadFunctionPrototype( |
| 3154 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3155 | // ----------- S t a t e ------------- |
| 3156 | // -- ra : return address |
| 3157 | // -- a0 : key |
| 3158 | // -- a1 : receiver |
| 3159 | // ----------------------------------- |
| 3160 | Label miss; |
| 3161 | |
| 3162 | Counters* counters = masm()->isolate()->counters(); |
| 3163 | __ IncrementCounter(counters->keyed_load_function_prototype(), 1, a2, a3); |
| 3164 | |
| 3165 | // Check the name hasn't changed. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3166 | __ Branch(&miss, ne, a0, Operand(name)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3167 | |
| 3168 | GenerateLoadFunctionPrototype(masm(), a1, a2, a3, &miss); |
| 3169 | __ bind(&miss); |
| 3170 | __ DecrementCounter(counters->keyed_load_function_prototype(), 1, a2, a3); |
| 3171 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 3172 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3173 | return GetCode(Code::CALLBACKS, name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 3177 | Handle<Code> KeyedLoadStubCompiler::CompileLoadElement( |
| 3178 | Handle<Map> receiver_map) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3179 | // ----------- S t a t e ------------- |
| 3180 | // -- ra : return address |
| 3181 | // -- a0 : key |
| 3182 | // -- a1 : receiver |
| 3183 | // ----------------------------------- |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3184 | ElementsKind elements_kind = receiver_map->elements_kind(); |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 3185 | Handle<Code> stub = KeyedLoadElementStub(elements_kind).GetCode(); |
| 3186 | |
| 3187 | __ DispatchMap(a1, a2, receiver_map, stub, DO_SMI_CHECK); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3188 | |
| 3189 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Miss(); |
| 3190 | __ Jump(ic, RelocInfo::CODE_TARGET); |
| 3191 | |
| 3192 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3193 | return GetCode(Code::NORMAL, factory()->empty_string()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 3197 | Handle<Code> KeyedLoadStubCompiler::CompileLoadPolymorphic( |
| 3198 | MapHandleList* receiver_maps, |
| 3199 | CodeHandleList* handler_ics) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3200 | // ----------- S t a t e ------------- |
| 3201 | // -- ra : return address |
| 3202 | // -- a0 : key |
| 3203 | // -- a1 : receiver |
| 3204 | // ----------------------------------- |
| 3205 | Label miss; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3206 | __ JumpIfSmi(a1, &miss); |
| 3207 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3208 | int receiver_count = receiver_maps->length(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3209 | __ lw(a2, FieldMemOperand(a1, HeapObject::kMapOffset)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3210 | for (int current = 0; current < receiver_count; ++current) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 3211 | __ Jump(handler_ics->at(current), RelocInfo::CODE_TARGET, |
| 3212 | eq, a2, Operand(receiver_maps->at(current))); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3213 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3214 | |
| 3215 | __ bind(&miss); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3216 | Handle<Code> miss_ic = isolate()->builtins()->KeyedLoadIC_Miss(); |
| 3217 | __ Jump(miss_ic, RelocInfo::CODE_TARGET); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3218 | |
| 3219 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3220 | return GetCode(Code::NORMAL, factory()->empty_string(), MEGAMORPHIC); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3221 | } |
| 3222 | |
| 3223 | |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 3224 | Handle<Code> KeyedStoreStubCompiler::CompileStoreField(Handle<JSObject> object, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3225 | int index, |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 3226 | Handle<Map> transition, |
| 3227 | Handle<String> name) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3228 | // ----------- S t a t e ------------- |
| 3229 | // -- a0 : value |
| 3230 | // -- a1 : key |
| 3231 | // -- a2 : receiver |
| 3232 | // -- ra : return address |
| 3233 | // ----------------------------------- |
| 3234 | |
| 3235 | Label miss; |
| 3236 | |
| 3237 | Counters* counters = masm()->isolate()->counters(); |
| 3238 | __ IncrementCounter(counters->keyed_store_field(), 1, a3, t0); |
| 3239 | |
| 3240 | // Check that the name has not changed. |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 3241 | __ Branch(&miss, ne, a1, Operand(name)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3242 | |
| 3243 | // a3 is used as scratch register. a1 and a2 keep their values if a jump to |
| 3244 | // the miss label is generated. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3245 | GenerateStoreField(masm(), |
| 3246 | object, |
| 3247 | index, |
| 3248 | transition, |
| 3249 | name, |
| 3250 | a2, a1, a3, t0, |
| 3251 | &miss); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3252 | __ bind(&miss); |
| 3253 | |
| 3254 | __ DecrementCounter(counters->keyed_store_field(), 1, a3, t0); |
| 3255 | Handle<Code> ic = masm()->isolate()->builtins()->KeyedStoreIC_Miss(); |
| 3256 | __ Jump(ic, RelocInfo::CODE_TARGET); |
| 3257 | |
| 3258 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3259 | return GetCode(transition.is_null() |
| 3260 | ? Code::FIELD |
| 3261 | : Code::MAP_TRANSITION, name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3262 | } |
| 3263 | |
| 3264 | |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 3265 | Handle<Code> KeyedStoreStubCompiler::CompileStoreElement( |
| 3266 | Handle<Map> receiver_map) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3267 | // ----------- S t a t e ------------- |
| 3268 | // -- a0 : value |
| 3269 | // -- a1 : key |
| 3270 | // -- a2 : receiver |
| 3271 | // -- ra : return address |
| 3272 | // -- a3 : scratch |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3273 | // ----------------------------------- |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3274 | ElementsKind elements_kind = receiver_map->elements_kind(); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3275 | bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE; |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 3276 | Handle<Code> stub = |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3277 | KeyedStoreElementStub(is_js_array, elements_kind, grow_mode_).GetCode(); |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 3278 | |
| 3279 | __ DispatchMap(a2, a3, receiver_map, stub, DO_SMI_CHECK); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3280 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3281 | Handle<Code> ic = isolate()->builtins()->KeyedStoreIC_Miss(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3282 | __ Jump(ic, RelocInfo::CODE_TARGET); |
| 3283 | |
| 3284 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3285 | return GetCode(Code::NORMAL, factory()->empty_string()); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3286 | } |
| 3287 | |
| 3288 | |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 3289 | Handle<Code> KeyedStoreStubCompiler::CompileStorePolymorphic( |
| 3290 | MapHandleList* receiver_maps, |
| 3291 | CodeHandleList* handler_stubs, |
| 3292 | MapHandleList* transitioned_maps) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3293 | // ----------- S t a t e ------------- |
| 3294 | // -- a0 : value |
| 3295 | // -- a1 : key |
| 3296 | // -- a2 : receiver |
| 3297 | // -- ra : return address |
| 3298 | // -- a3 : scratch |
| 3299 | // ----------------------------------- |
| 3300 | Label miss; |
| 3301 | __ JumpIfSmi(a2, &miss); |
| 3302 | |
| 3303 | int receiver_count = receiver_maps->length(); |
| 3304 | __ lw(a3, FieldMemOperand(a2, HeapObject::kMapOffset)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3305 | for (int i = 0; i < receiver_count; ++i) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 3306 | if (transitioned_maps->at(i).is_null()) { |
| 3307 | __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET, eq, |
| 3308 | a3, Operand(receiver_maps->at(i))); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3309 | } else { |
| 3310 | Label next_map; |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 3311 | __ Branch(&next_map, ne, a3, Operand(receiver_maps->at(i))); |
| 3312 | __ li(a3, Operand(transitioned_maps->at(i))); |
| 3313 | __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3314 | __ bind(&next_map); |
| 3315 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3316 | } |
| 3317 | |
| 3318 | __ bind(&miss); |
| 3319 | Handle<Code> miss_ic = isolate()->builtins()->KeyedStoreIC_Miss(); |
| 3320 | __ Jump(miss_ic, RelocInfo::CODE_TARGET); |
| 3321 | |
| 3322 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3323 | return GetCode(Code::NORMAL, factory()->empty_string(), MEGAMORPHIC); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3324 | } |
| 3325 | |
| 3326 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3327 | Handle<Code> ConstructStubCompiler::CompileConstructStub( |
| 3328 | Handle<JSFunction> function) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3329 | // a0 : argc |
| 3330 | // a1 : constructor |
| 3331 | // ra : return address |
| 3332 | // [sp] : last argument |
| 3333 | Label generic_stub_call; |
| 3334 | |
| 3335 | // Use t7 for holding undefined which is used in several places below. |
| 3336 | __ LoadRoot(t7, Heap::kUndefinedValueRootIndex); |
| 3337 | |
| 3338 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 3339 | // Check to see whether there are any break points in the function code. If |
| 3340 | // there are jump to the generic constructor stub which calls the actual |
| 3341 | // code for the function thereby hitting the break points. |
| 3342 | __ lw(t5, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 3343 | __ lw(a2, FieldMemOperand(t5, SharedFunctionInfo::kDebugInfoOffset)); |
| 3344 | __ Branch(&generic_stub_call, ne, a2, Operand(t7)); |
| 3345 | #endif |
| 3346 | |
| 3347 | // Load the initial map and verify that it is in fact a map. |
| 3348 | // a1: constructor function |
| 3349 | // t7: undefined |
| 3350 | __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3351 | __ JumpIfSmi(a2, &generic_stub_call); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3352 | __ GetObjectType(a2, a3, t0); |
| 3353 | __ Branch(&generic_stub_call, ne, t0, Operand(MAP_TYPE)); |
| 3354 | |
| 3355 | #ifdef DEBUG |
| 3356 | // Cannot construct functions this way. |
| 3357 | // a0: argc |
| 3358 | // a1: constructor function |
| 3359 | // a2: initial map |
| 3360 | // t7: undefined |
| 3361 | __ lbu(a3, FieldMemOperand(a2, Map::kInstanceTypeOffset)); |
| 3362 | __ Check(ne, "Function constructed by construct stub.", |
| 3363 | a3, Operand(JS_FUNCTION_TYPE)); |
| 3364 | #endif |
| 3365 | |
| 3366 | // Now allocate the JSObject in new space. |
| 3367 | // a0: argc |
| 3368 | // a1: constructor function |
| 3369 | // a2: initial map |
| 3370 | // t7: undefined |
| 3371 | __ lbu(a3, FieldMemOperand(a2, Map::kInstanceSizeOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3372 | __ AllocateInNewSpace(a3, t4, t5, t6, &generic_stub_call, SIZE_IN_WORDS); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3373 | |
| 3374 | // Allocated the JSObject, now initialize the fields. Map is set to initial |
| 3375 | // map and properties and elements are set to empty fixed array. |
| 3376 | // a0: argc |
| 3377 | // a1: constructor function |
| 3378 | // a2: initial map |
| 3379 | // a3: object size (in words) |
| 3380 | // t4: JSObject (not tagged) |
| 3381 | // t7: undefined |
| 3382 | __ LoadRoot(t6, Heap::kEmptyFixedArrayRootIndex); |
| 3383 | __ mov(t5, t4); |
| 3384 | __ sw(a2, MemOperand(t5, JSObject::kMapOffset)); |
| 3385 | __ sw(t6, MemOperand(t5, JSObject::kPropertiesOffset)); |
| 3386 | __ sw(t6, MemOperand(t5, JSObject::kElementsOffset)); |
| 3387 | __ Addu(t5, t5, Operand(3 * kPointerSize)); |
| 3388 | ASSERT_EQ(0 * kPointerSize, JSObject::kMapOffset); |
| 3389 | ASSERT_EQ(1 * kPointerSize, JSObject::kPropertiesOffset); |
| 3390 | ASSERT_EQ(2 * kPointerSize, JSObject::kElementsOffset); |
| 3391 | |
| 3392 | |
| 3393 | // Calculate the location of the first argument. The stack contains only the |
| 3394 | // argc arguments. |
| 3395 | __ sll(a1, a0, kPointerSizeLog2); |
| 3396 | __ Addu(a1, a1, sp); |
| 3397 | |
| 3398 | // Fill all the in-object properties with undefined. |
| 3399 | // a0: argc |
| 3400 | // a1: first argument |
| 3401 | // a3: object size (in words) |
| 3402 | // t4: JSObject (not tagged) |
| 3403 | // t5: First in-object property of JSObject (not tagged) |
| 3404 | // t7: undefined |
| 3405 | // Fill the initialized properties with a constant value or a passed argument |
| 3406 | // depending on the this.x = ...; assignment in the function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3407 | Handle<SharedFunctionInfo> shared(function->shared()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3408 | for (int i = 0; i < shared->this_property_assignments_count(); i++) { |
| 3409 | if (shared->IsThisPropertyAssignmentArgument(i)) { |
| 3410 | Label not_passed, next; |
| 3411 | // Check if the argument assigned to the property is actually passed. |
| 3412 | int arg_number = shared->GetThisPropertyAssignmentArgument(i); |
| 3413 | __ Branch(¬_passed, less_equal, a0, Operand(arg_number)); |
| 3414 | // Argument passed - find it on the stack. |
| 3415 | __ lw(a2, MemOperand(a1, (arg_number + 1) * -kPointerSize)); |
| 3416 | __ sw(a2, MemOperand(t5)); |
| 3417 | __ Addu(t5, t5, kPointerSize); |
| 3418 | __ jmp(&next); |
| 3419 | __ bind(¬_passed); |
| 3420 | // Set the property to undefined. |
| 3421 | __ sw(t7, MemOperand(t5)); |
| 3422 | __ Addu(t5, t5, Operand(kPointerSize)); |
| 3423 | __ bind(&next); |
| 3424 | } else { |
| 3425 | // Set the property to the constant value. |
| 3426 | Handle<Object> constant(shared->GetThisPropertyAssignmentConstant(i)); |
| 3427 | __ li(a2, Operand(constant)); |
| 3428 | __ sw(a2, MemOperand(t5)); |
| 3429 | __ Addu(t5, t5, kPointerSize); |
| 3430 | } |
| 3431 | } |
| 3432 | |
| 3433 | // Fill the unused in-object property fields with undefined. |
| 3434 | ASSERT(function->has_initial_map()); |
| 3435 | for (int i = shared->this_property_assignments_count(); |
| 3436 | i < function->initial_map()->inobject_properties(); |
| 3437 | i++) { |
| 3438 | __ sw(t7, MemOperand(t5)); |
| 3439 | __ Addu(t5, t5, kPointerSize); |
| 3440 | } |
| 3441 | |
| 3442 | // a0: argc |
| 3443 | // t4: JSObject (not tagged) |
| 3444 | // Move argc to a1 and the JSObject to return to v0 and tag it. |
| 3445 | __ mov(a1, a0); |
| 3446 | __ mov(v0, t4); |
| 3447 | __ Or(v0, v0, Operand(kHeapObjectTag)); |
| 3448 | |
| 3449 | // v0: JSObject |
| 3450 | // a1: argc |
| 3451 | // Remove caller arguments and receiver from the stack and return. |
| 3452 | __ sll(t0, a1, kPointerSizeLog2); |
| 3453 | __ Addu(sp, sp, t0); |
| 3454 | __ Addu(sp, sp, Operand(kPointerSize)); |
| 3455 | Counters* counters = masm()->isolate()->counters(); |
| 3456 | __ IncrementCounter(counters->constructed_objects(), 1, a1, a2); |
| 3457 | __ IncrementCounter(counters->constructed_objects_stub(), 1, a1, a2); |
| 3458 | __ Ret(); |
| 3459 | |
| 3460 | // Jump to the generic stub in case the specialized code cannot handle the |
| 3461 | // construction. |
| 3462 | __ bind(&generic_stub_call); |
| 3463 | Handle<Code> generic_construct_stub = |
| 3464 | masm()->isolate()->builtins()->JSConstructStubGeneric(); |
| 3465 | __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET); |
| 3466 | |
| 3467 | // Return the generated code. |
| 3468 | return GetCode(); |
| 3469 | } |
| 3470 | |
| 3471 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3472 | #undef __ |
| 3473 | #define __ ACCESS_MASM(masm) |
| 3474 | |
| 3475 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3476 | void KeyedLoadStubCompiler::GenerateLoadDictionaryElement( |
| 3477 | MacroAssembler* masm) { |
| 3478 | // ---------- S t a t e -------------- |
| 3479 | // -- ra : return address |
| 3480 | // -- a0 : key |
| 3481 | // -- a1 : receiver |
| 3482 | // ----------------------------------- |
| 3483 | Label slow, miss_force_generic; |
| 3484 | |
| 3485 | Register key = a0; |
| 3486 | Register receiver = a1; |
| 3487 | |
| 3488 | __ JumpIfNotSmi(key, &miss_force_generic); |
| 3489 | __ lw(t0, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
| 3490 | __ sra(a2, a0, kSmiTagSize); |
| 3491 | __ LoadFromNumberDictionary(&slow, t0, a0, v0, a2, a3, t1); |
| 3492 | __ Ret(); |
| 3493 | |
| 3494 | // Slow case, key and receiver still in a0 and a1. |
| 3495 | __ bind(&slow); |
| 3496 | __ IncrementCounter( |
| 3497 | masm->isolate()->counters()->keyed_load_external_array_slow(), |
| 3498 | 1, a2, a3); |
| 3499 | // Entry registers are intact. |
| 3500 | // ---------- S t a t e -------------- |
| 3501 | // -- ra : return address |
| 3502 | // -- a0 : key |
| 3503 | // -- a1 : receiver |
| 3504 | // ----------------------------------- |
| 3505 | Handle<Code> slow_ic = |
| 3506 | masm->isolate()->builtins()->KeyedLoadIC_Slow(); |
| 3507 | __ Jump(slow_ic, RelocInfo::CODE_TARGET); |
| 3508 | |
| 3509 | // Miss case, call the runtime. |
| 3510 | __ bind(&miss_force_generic); |
| 3511 | |
| 3512 | // ---------- S t a t e -------------- |
| 3513 | // -- ra : return address |
| 3514 | // -- a0 : key |
| 3515 | // -- a1 : receiver |
| 3516 | // ----------------------------------- |
| 3517 | |
| 3518 | Handle<Code> miss_ic = |
| 3519 | masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric(); |
| 3520 | __ Jump(miss_ic, RelocInfo::CODE_TARGET); |
| 3521 | } |
| 3522 | |
| 3523 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3524 | static bool IsElementTypeSigned(ElementsKind elements_kind) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3525 | switch (elements_kind) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3526 | case EXTERNAL_BYTE_ELEMENTS: |
| 3527 | case EXTERNAL_SHORT_ELEMENTS: |
| 3528 | case EXTERNAL_INT_ELEMENTS: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3529 | return true; |
| 3530 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3531 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
| 3532 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
| 3533 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
| 3534 | case EXTERNAL_PIXEL_ELEMENTS: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3535 | return false; |
| 3536 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3537 | case EXTERNAL_FLOAT_ELEMENTS: |
| 3538 | case EXTERNAL_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3539 | case FAST_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3540 | case FAST_ELEMENTS: |
| 3541 | case FAST_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3542 | case FAST_HOLEY_SMI_ELEMENTS: |
| 3543 | case FAST_HOLEY_ELEMENTS: |
| 3544 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3545 | case DICTIONARY_ELEMENTS: |
| 3546 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3547 | UNREACHABLE(); |
| 3548 | return false; |
| 3549 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3550 | return false; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3551 | } |
| 3552 | |
| 3553 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 3554 | static void GenerateSmiKeyCheck(MacroAssembler* masm, |
| 3555 | Register key, |
| 3556 | Register scratch0, |
| 3557 | Register scratch1, |
| 3558 | FPURegister double_scratch0, |
| 3559 | Label* fail) { |
| 3560 | if (CpuFeatures::IsSupported(FPU)) { |
| 3561 | CpuFeatures::Scope scope(FPU); |
| 3562 | Label key_ok; |
| 3563 | // Check for smi or a smi inside a heap number. We convert the heap |
| 3564 | // number and check if the conversion is exact and fits into the smi |
| 3565 | // range. |
| 3566 | __ JumpIfSmi(key, &key_ok); |
| 3567 | __ CheckMap(key, |
| 3568 | scratch0, |
| 3569 | Heap::kHeapNumberMapRootIndex, |
| 3570 | fail, |
| 3571 | DONT_DO_SMI_CHECK); |
| 3572 | __ ldc1(double_scratch0, FieldMemOperand(key, HeapNumber::kValueOffset)); |
| 3573 | __ EmitFPUTruncate(kRoundToZero, |
| 3574 | double_scratch0, |
| 3575 | double_scratch0, |
| 3576 | scratch0, |
| 3577 | scratch1, |
| 3578 | kCheckForInexactConversion); |
| 3579 | |
| 3580 | __ Branch(fail, ne, scratch1, Operand(zero_reg)); |
| 3581 | |
| 3582 | __ mfc1(scratch0, double_scratch0); |
| 3583 | __ SmiTagCheckOverflow(key, scratch0, scratch1); |
| 3584 | __ BranchOnOverflow(fail, scratch1); |
| 3585 | __ bind(&key_ok); |
| 3586 | } else { |
| 3587 | // Check that the key is a smi. |
| 3588 | __ JumpIfNotSmi(key, fail); |
| 3589 | } |
| 3590 | } |
| 3591 | |
| 3592 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3593 | void KeyedLoadStubCompiler::GenerateLoadExternalArray( |
| 3594 | MacroAssembler* masm, |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3595 | ElementsKind elements_kind) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3596 | // ---------- S t a t e -------------- |
| 3597 | // -- ra : return address |
| 3598 | // -- a0 : key |
| 3599 | // -- a1 : receiver |
| 3600 | // ----------------------------------- |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3601 | Label miss_force_generic, slow, failed_allocation; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3602 | |
| 3603 | Register key = a0; |
| 3604 | Register receiver = a1; |
| 3605 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3606 | // This stub is meant to be tail-jumped to, the receiver must already |
| 3607 | // have been verified by the caller to not be a smi. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3608 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 3609 | // Check that the key is a smi or a heap number convertible to a smi. |
| 3610 | GenerateSmiKeyCheck(masm, key, t0, t1, f2, &miss_force_generic); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3611 | |
| 3612 | __ lw(a3, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
| 3613 | // a3: elements array |
| 3614 | |
| 3615 | // Check that the index is in range. |
| 3616 | __ lw(t1, FieldMemOperand(a3, ExternalArray::kLengthOffset)); |
| 3617 | __ sra(t2, key, kSmiTagSize); |
| 3618 | // Unsigned comparison catches both negative and too-large values. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3619 | __ Branch(&miss_force_generic, Ugreater_equal, key, Operand(t1)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3620 | |
| 3621 | __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset)); |
| 3622 | // a3: base pointer of external storage |
| 3623 | |
| 3624 | // We are not untagging smi key and instead work with it |
| 3625 | // as if it was premultiplied by 2. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 3626 | STATIC_ASSERT((kSmiTag == 0) && (kSmiTagSize == 1)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3627 | |
| 3628 | Register value = a2; |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3629 | switch (elements_kind) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3630 | case EXTERNAL_BYTE_ELEMENTS: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3631 | __ srl(t2, key, 1); |
| 3632 | __ addu(t3, a3, t2); |
| 3633 | __ lb(value, MemOperand(t3, 0)); |
| 3634 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3635 | case EXTERNAL_PIXEL_ELEMENTS: |
| 3636 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3637 | __ srl(t2, key, 1); |
| 3638 | __ addu(t3, a3, t2); |
| 3639 | __ lbu(value, MemOperand(t3, 0)); |
| 3640 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3641 | case EXTERNAL_SHORT_ELEMENTS: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3642 | __ addu(t3, a3, key); |
| 3643 | __ lh(value, MemOperand(t3, 0)); |
| 3644 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3645 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3646 | __ addu(t3, a3, key); |
| 3647 | __ lhu(value, MemOperand(t3, 0)); |
| 3648 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3649 | case EXTERNAL_INT_ELEMENTS: |
| 3650 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3651 | __ sll(t2, key, 1); |
| 3652 | __ addu(t3, a3, t2); |
| 3653 | __ lw(value, MemOperand(t3, 0)); |
| 3654 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3655 | case EXTERNAL_FLOAT_ELEMENTS: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3656 | __ sll(t3, t2, 2); |
| 3657 | __ addu(t3, a3, t3); |
| 3658 | if (CpuFeatures::IsSupported(FPU)) { |
| 3659 | CpuFeatures::Scope scope(FPU); |
| 3660 | __ lwc1(f0, MemOperand(t3, 0)); |
| 3661 | } else { |
| 3662 | __ lw(value, MemOperand(t3, 0)); |
| 3663 | } |
| 3664 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3665 | case EXTERNAL_DOUBLE_ELEMENTS: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3666 | __ sll(t2, key, 2); |
| 3667 | __ addu(t3, a3, t2); |
| 3668 | if (CpuFeatures::IsSupported(FPU)) { |
| 3669 | CpuFeatures::Scope scope(FPU); |
| 3670 | __ ldc1(f0, MemOperand(t3, 0)); |
| 3671 | } else { |
| 3672 | // t3: pointer to the beginning of the double we want to load. |
| 3673 | __ lw(a2, MemOperand(t3, 0)); |
| 3674 | __ lw(a3, MemOperand(t3, Register::kSizeInBytes)); |
| 3675 | } |
| 3676 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3677 | case FAST_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3678 | case FAST_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3679 | case FAST_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3680 | case FAST_HOLEY_ELEMENTS: |
| 3681 | case FAST_HOLEY_SMI_ELEMENTS: |
| 3682 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3683 | case DICTIONARY_ELEMENTS: |
| 3684 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3685 | UNREACHABLE(); |
| 3686 | break; |
| 3687 | } |
| 3688 | |
| 3689 | // For integer array types: |
| 3690 | // a2: value |
| 3691 | // For float array type: |
| 3692 | // f0: value (if FPU is supported) |
| 3693 | // a2: value (if FPU is not supported) |
| 3694 | // For double array type: |
| 3695 | // f0: value (if FPU is supported) |
| 3696 | // a2/a3: value (if FPU is not supported) |
| 3697 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3698 | if (elements_kind == EXTERNAL_INT_ELEMENTS) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3699 | // For the Int and UnsignedInt array types, we need to see whether |
| 3700 | // the value can be represented in a Smi. If not, we need to convert |
| 3701 | // it to a HeapNumber. |
| 3702 | Label box_int; |
| 3703 | __ Subu(t3, value, Operand(0xC0000000)); // Non-smi value gives neg result. |
| 3704 | __ Branch(&box_int, lt, t3, Operand(zero_reg)); |
| 3705 | // Tag integer as smi and return it. |
| 3706 | __ sll(v0, value, kSmiTagSize); |
| 3707 | __ Ret(); |
| 3708 | |
| 3709 | __ bind(&box_int); |
| 3710 | // Allocate a HeapNumber for the result and perform int-to-double |
| 3711 | // conversion. |
| 3712 | // The arm version uses a temporary here to save r0, but we don't need to |
| 3713 | // (a0 is not modified). |
| 3714 | __ LoadRoot(t1, Heap::kHeapNumberMapRootIndex); |
| 3715 | __ AllocateHeapNumber(v0, a3, t0, t1, &slow); |
| 3716 | |
| 3717 | if (CpuFeatures::IsSupported(FPU)) { |
| 3718 | CpuFeatures::Scope scope(FPU); |
| 3719 | __ mtc1(value, f0); |
| 3720 | __ cvt_d_w(f0, f0); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3721 | __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3722 | __ Ret(); |
| 3723 | } else { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3724 | Register dst1 = t2; |
| 3725 | Register dst2 = t3; |
| 3726 | FloatingPointHelper::Destination dest = |
| 3727 | FloatingPointHelper::kCoreRegisters; |
| 3728 | FloatingPointHelper::ConvertIntToDouble(masm, |
| 3729 | value, |
| 3730 | dest, |
| 3731 | f0, |
| 3732 | dst1, |
| 3733 | dst2, |
| 3734 | t1, |
| 3735 | f2); |
| 3736 | __ sw(dst1, FieldMemOperand(v0, HeapNumber::kMantissaOffset)); |
| 3737 | __ sw(dst2, FieldMemOperand(v0, HeapNumber::kExponentOffset)); |
| 3738 | __ Ret(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3739 | } |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3740 | } else if (elements_kind == EXTERNAL_UNSIGNED_INT_ELEMENTS) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3741 | // The test is different for unsigned int values. Since we need |
| 3742 | // the value to be in the range of a positive smi, we can't |
| 3743 | // handle either of the top two bits being set in the value. |
| 3744 | if (CpuFeatures::IsSupported(FPU)) { |
| 3745 | CpuFeatures::Scope scope(FPU); |
| 3746 | Label pl_box_int; |
| 3747 | __ And(t2, value, Operand(0xC0000000)); |
| 3748 | __ Branch(&pl_box_int, ne, t2, Operand(zero_reg)); |
| 3749 | |
| 3750 | // It can fit in an Smi. |
| 3751 | // Tag integer as smi and return it. |
| 3752 | __ sll(v0, value, kSmiTagSize); |
| 3753 | __ Ret(); |
| 3754 | |
| 3755 | __ bind(&pl_box_int); |
| 3756 | // Allocate a HeapNumber for the result and perform int-to-double |
| 3757 | // conversion. Don't use a0 and a1 as AllocateHeapNumber clobbers all |
| 3758 | // registers - also when jumping due to exhausted young space. |
| 3759 | __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex); |
| 3760 | __ AllocateHeapNumber(v0, t2, t3, t6, &slow); |
| 3761 | |
| 3762 | // This is replaced by a macro: |
| 3763 | // __ mtc1(value, f0); // LS 32-bits. |
| 3764 | // __ mtc1(zero_reg, f1); // MS 32-bits are all zero. |
| 3765 | // __ cvt_d_l(f0, f0); // Use 64 bit conv to get correct unsigned 32-bit. |
| 3766 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3767 | __ Cvt_d_uw(f0, value, f22); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3768 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3769 | __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3770 | |
| 3771 | __ Ret(); |
| 3772 | } else { |
| 3773 | // Check whether unsigned integer fits into smi. |
| 3774 | Label box_int_0, box_int_1, done; |
| 3775 | __ And(t2, value, Operand(0x80000000)); |
| 3776 | __ Branch(&box_int_0, ne, t2, Operand(zero_reg)); |
| 3777 | __ And(t2, value, Operand(0x40000000)); |
| 3778 | __ Branch(&box_int_1, ne, t2, Operand(zero_reg)); |
| 3779 | |
| 3780 | // Tag integer as smi and return it. |
| 3781 | __ sll(v0, value, kSmiTagSize); |
| 3782 | __ Ret(); |
| 3783 | |
| 3784 | Register hiword = value; // a2. |
| 3785 | Register loword = a3; |
| 3786 | |
| 3787 | __ bind(&box_int_0); |
| 3788 | // Integer does not have leading zeros. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3789 | GenerateUInt2Double(masm, hiword, loword, t0, 0); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3790 | __ Branch(&done); |
| 3791 | |
| 3792 | __ bind(&box_int_1); |
| 3793 | // Integer has one leading zero. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3794 | GenerateUInt2Double(masm, hiword, loword, t0, 1); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3795 | |
| 3796 | |
| 3797 | __ bind(&done); |
| 3798 | // Integer was converted to double in registers hiword:loword. |
| 3799 | // Wrap it into a HeapNumber. Don't use a0 and a1 as AllocateHeapNumber |
| 3800 | // clobbers all registers - also when jumping due to exhausted young |
| 3801 | // space. |
| 3802 | __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex); |
| 3803 | __ AllocateHeapNumber(t2, t3, t5, t6, &slow); |
| 3804 | |
| 3805 | __ sw(hiword, FieldMemOperand(t2, HeapNumber::kExponentOffset)); |
| 3806 | __ sw(loword, FieldMemOperand(t2, HeapNumber::kMantissaOffset)); |
| 3807 | |
| 3808 | __ mov(v0, t2); |
| 3809 | __ Ret(); |
| 3810 | } |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3811 | } else if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3812 | // For the floating-point array type, we need to always allocate a |
| 3813 | // HeapNumber. |
| 3814 | if (CpuFeatures::IsSupported(FPU)) { |
| 3815 | CpuFeatures::Scope scope(FPU); |
| 3816 | // Allocate a HeapNumber for the result. Don't use a0 and a1 as |
| 3817 | // AllocateHeapNumber clobbers all registers - also when jumping due to |
| 3818 | // exhausted young space. |
| 3819 | __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex); |
| 3820 | __ AllocateHeapNumber(v0, t3, t5, t6, &slow); |
| 3821 | // The float (single) value is already in fpu reg f0 (if we use float). |
| 3822 | __ cvt_d_s(f0, f0); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3823 | __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3824 | __ Ret(); |
| 3825 | } else { |
| 3826 | // Allocate a HeapNumber for the result. Don't use a0 and a1 as |
| 3827 | // AllocateHeapNumber clobbers all registers - also when jumping due to |
| 3828 | // exhausted young space. |
| 3829 | __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex); |
| 3830 | __ AllocateHeapNumber(v0, t3, t5, t6, &slow); |
| 3831 | // FPU is not available, do manual single to double conversion. |
| 3832 | |
| 3833 | // a2: floating point value (binary32). |
| 3834 | // v0: heap number for result |
| 3835 | |
| 3836 | // Extract mantissa to t4. |
| 3837 | __ And(t4, value, Operand(kBinary32MantissaMask)); |
| 3838 | |
| 3839 | // Extract exponent to t5. |
| 3840 | __ srl(t5, value, kBinary32MantissaBits); |
| 3841 | __ And(t5, t5, Operand(kBinary32ExponentMask >> kBinary32MantissaBits)); |
| 3842 | |
| 3843 | Label exponent_rebiased; |
| 3844 | __ Branch(&exponent_rebiased, eq, t5, Operand(zero_reg)); |
| 3845 | |
| 3846 | __ li(t0, 0x7ff); |
| 3847 | __ Xor(t1, t5, Operand(0xFF)); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 3848 | __ Movz(t5, t0, t1); // Set t5 to 0x7ff only if t5 is equal to 0xff. |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 3849 | __ Branch(&exponent_rebiased, eq, t1, Operand(zero_reg)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3850 | |
| 3851 | // Rebias exponent. |
| 3852 | __ Addu(t5, |
| 3853 | t5, |
| 3854 | Operand(-kBinary32ExponentBias + HeapNumber::kExponentBias)); |
| 3855 | |
| 3856 | __ bind(&exponent_rebiased); |
| 3857 | __ And(a2, value, Operand(kBinary32SignMask)); |
| 3858 | value = no_reg; |
| 3859 | __ sll(t0, t5, HeapNumber::kMantissaBitsInTopWord); |
| 3860 | __ or_(a2, a2, t0); |
| 3861 | |
| 3862 | // Shift mantissa. |
| 3863 | static const int kMantissaShiftForHiWord = |
| 3864 | kBinary32MantissaBits - HeapNumber::kMantissaBitsInTopWord; |
| 3865 | |
| 3866 | static const int kMantissaShiftForLoWord = |
| 3867 | kBitsPerInt - kMantissaShiftForHiWord; |
| 3868 | |
| 3869 | __ srl(t0, t4, kMantissaShiftForHiWord); |
| 3870 | __ or_(a2, a2, t0); |
| 3871 | __ sll(a0, t4, kMantissaShiftForLoWord); |
| 3872 | |
| 3873 | __ sw(a2, FieldMemOperand(v0, HeapNumber::kExponentOffset)); |
| 3874 | __ sw(a0, FieldMemOperand(v0, HeapNumber::kMantissaOffset)); |
| 3875 | __ Ret(); |
| 3876 | } |
| 3877 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3878 | } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3879 | if (CpuFeatures::IsSupported(FPU)) { |
| 3880 | CpuFeatures::Scope scope(FPU); |
| 3881 | // Allocate a HeapNumber for the result. Don't use a0 and a1 as |
| 3882 | // AllocateHeapNumber clobbers all registers - also when jumping due to |
| 3883 | // exhausted young space. |
| 3884 | __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex); |
| 3885 | __ AllocateHeapNumber(v0, t3, t5, t6, &slow); |
| 3886 | // The double value is already in f0 |
| 3887 | __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset)); |
| 3888 | __ Ret(); |
| 3889 | } else { |
| 3890 | // Allocate a HeapNumber for the result. Don't use a0 and a1 as |
| 3891 | // AllocateHeapNumber clobbers all registers - also when jumping due to |
| 3892 | // exhausted young space. |
| 3893 | __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex); |
| 3894 | __ AllocateHeapNumber(v0, t3, t5, t6, &slow); |
| 3895 | |
| 3896 | __ sw(a2, FieldMemOperand(v0, HeapNumber::kMantissaOffset)); |
| 3897 | __ sw(a3, FieldMemOperand(v0, HeapNumber::kExponentOffset)); |
| 3898 | __ Ret(); |
| 3899 | } |
| 3900 | |
| 3901 | } else { |
| 3902 | // Tag integer as smi and return it. |
| 3903 | __ sll(v0, value, kSmiTagSize); |
| 3904 | __ Ret(); |
| 3905 | } |
| 3906 | |
| 3907 | // Slow case, key and receiver still in a0 and a1. |
| 3908 | __ bind(&slow); |
| 3909 | __ IncrementCounter( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3910 | masm->isolate()->counters()->keyed_load_external_array_slow(), |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3911 | 1, a2, a3); |
| 3912 | |
| 3913 | // ---------- S t a t e -------------- |
| 3914 | // -- ra : return address |
| 3915 | // -- a0 : key |
| 3916 | // -- a1 : receiver |
| 3917 | // ----------------------------------- |
| 3918 | |
| 3919 | __ Push(a1, a0); |
| 3920 | |
| 3921 | __ TailCallRuntime(Runtime::kKeyedGetProperty, 2, 1); |
| 3922 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3923 | __ bind(&miss_force_generic); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3924 | Handle<Code> stub = |
| 3925 | masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric(); |
| 3926 | __ Jump(stub, RelocInfo::CODE_TARGET); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3927 | } |
| 3928 | |
| 3929 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3930 | void KeyedStoreStubCompiler::GenerateStoreExternalArray( |
| 3931 | MacroAssembler* masm, |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3932 | ElementsKind elements_kind) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3933 | // ---------- S t a t e -------------- |
| 3934 | // -- a0 : value |
| 3935 | // -- a1 : key |
| 3936 | // -- a2 : receiver |
| 3937 | // -- ra : return address |
| 3938 | // ----------------------------------- |
| 3939 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3940 | Label slow, check_heap_number, miss_force_generic; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3941 | |
| 3942 | // Register usage. |
| 3943 | Register value = a0; |
| 3944 | Register key = a1; |
| 3945 | Register receiver = a2; |
| 3946 | // a3 mostly holds the elements array or the destination external array. |
| 3947 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3948 | // This stub is meant to be tail-jumped to, the receiver must already |
| 3949 | // have been verified by the caller to not be a smi. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3950 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 3951 | // Check that the key is a smi or a heap number convertible to a smi. |
| 3952 | GenerateSmiKeyCheck(masm, key, t0, t1, f2, &miss_force_generic); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3953 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3954 | __ lw(a3, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
| 3955 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3956 | // Check that the index is in range. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3957 | __ lw(t1, FieldMemOperand(a3, ExternalArray::kLengthOffset)); |
| 3958 | // Unsigned comparison catches both negative and too-large values. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3959 | __ Branch(&miss_force_generic, Ugreater_equal, key, Operand(t1)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3960 | |
| 3961 | // Handle both smis and HeapNumbers in the fast path. Go to the |
| 3962 | // runtime for all other kinds of values. |
| 3963 | // a3: external array. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3964 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3965 | if (elements_kind == EXTERNAL_PIXEL_ELEMENTS) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3966 | // Double to pixel conversion is only implemented in the runtime for now. |
| 3967 | __ JumpIfNotSmi(value, &slow); |
| 3968 | } else { |
| 3969 | __ JumpIfNotSmi(value, &check_heap_number); |
| 3970 | } |
| 3971 | __ SmiUntag(t1, value); |
| 3972 | __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset)); |
| 3973 | |
| 3974 | // a3: base pointer of external storage. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3975 | // t1: value (integer). |
| 3976 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3977 | switch (elements_kind) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3978 | case EXTERNAL_PIXEL_ELEMENTS: { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3979 | // Clamp the value to [0..255]. |
| 3980 | // v0 is used as a scratch register here. |
| 3981 | Label done; |
| 3982 | __ li(v0, Operand(255)); |
| 3983 | // Normal branch: nop in delay slot. |
| 3984 | __ Branch(&done, gt, t1, Operand(v0)); |
| 3985 | // Use delay slot in this branch. |
| 3986 | __ Branch(USE_DELAY_SLOT, &done, lt, t1, Operand(zero_reg)); |
| 3987 | __ mov(v0, zero_reg); // In delay slot. |
| 3988 | __ mov(v0, t1); // Value is in range 0..255. |
| 3989 | __ bind(&done); |
| 3990 | __ mov(t1, v0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3991 | |
| 3992 | __ srl(t8, key, 1); |
| 3993 | __ addu(t8, a3, t8); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3994 | __ sb(t1, MemOperand(t8, 0)); |
| 3995 | } |
| 3996 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3997 | case EXTERNAL_BYTE_ELEMENTS: |
| 3998 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3999 | __ srl(t8, key, 1); |
| 4000 | __ addu(t8, a3, t8); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4001 | __ sb(t1, MemOperand(t8, 0)); |
| 4002 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4003 | case EXTERNAL_SHORT_ELEMENTS: |
| 4004 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4005 | __ addu(t8, a3, key); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4006 | __ sh(t1, MemOperand(t8, 0)); |
| 4007 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4008 | case EXTERNAL_INT_ELEMENTS: |
| 4009 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4010 | __ sll(t8, key, 1); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4011 | __ addu(t8, a3, t8); |
| 4012 | __ sw(t1, MemOperand(t8, 0)); |
| 4013 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4014 | case EXTERNAL_FLOAT_ELEMENTS: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4015 | // Perform int-to-float conversion and store to memory. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4016 | __ SmiUntag(t0, key); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4017 | StoreIntAsFloat(masm, a3, t0, t1, t2, t3, t4); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4018 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4019 | case EXTERNAL_DOUBLE_ELEMENTS: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4020 | __ sll(t8, key, 2); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4021 | __ addu(a3, a3, t8); |
| 4022 | // a3: effective address of the double element |
| 4023 | FloatingPointHelper::Destination destination; |
| 4024 | if (CpuFeatures::IsSupported(FPU)) { |
| 4025 | destination = FloatingPointHelper::kFPURegisters; |
| 4026 | } else { |
| 4027 | destination = FloatingPointHelper::kCoreRegisters; |
| 4028 | } |
| 4029 | FloatingPointHelper::ConvertIntToDouble( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4030 | masm, t1, destination, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4031 | f0, t2, t3, // These are: double_dst, dst1, dst2. |
| 4032 | t0, f2); // These are: scratch2, single_scratch. |
| 4033 | if (destination == FloatingPointHelper::kFPURegisters) { |
| 4034 | CpuFeatures::Scope scope(FPU); |
| 4035 | __ sdc1(f0, MemOperand(a3, 0)); |
| 4036 | } else { |
| 4037 | __ sw(t2, MemOperand(a3, 0)); |
| 4038 | __ sw(t3, MemOperand(a3, Register::kSizeInBytes)); |
| 4039 | } |
| 4040 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4041 | case FAST_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4042 | case FAST_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4043 | case FAST_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4044 | case FAST_HOLEY_ELEMENTS: |
| 4045 | case FAST_HOLEY_SMI_ELEMENTS: |
| 4046 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4047 | case DICTIONARY_ELEMENTS: |
| 4048 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4049 | UNREACHABLE(); |
| 4050 | break; |
| 4051 | } |
| 4052 | |
| 4053 | // Entry registers are intact, a0 holds the value which is the return value. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4054 | __ mov(v0, a0); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4055 | __ Ret(); |
| 4056 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4057 | if (elements_kind != EXTERNAL_PIXEL_ELEMENTS) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4058 | // a3: external array. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4059 | __ bind(&check_heap_number); |
| 4060 | __ GetObjectType(value, t1, t2); |
| 4061 | __ Branch(&slow, ne, t2, Operand(HEAP_NUMBER_TYPE)); |
| 4062 | |
| 4063 | __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset)); |
| 4064 | |
| 4065 | // a3: base pointer of external storage. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4066 | |
| 4067 | // The WebGL specification leaves the behavior of storing NaN and |
| 4068 | // +/-Infinity into integer arrays basically undefined. For more |
| 4069 | // reproducible behavior, convert these to zero. |
| 4070 | |
| 4071 | if (CpuFeatures::IsSupported(FPU)) { |
| 4072 | CpuFeatures::Scope scope(FPU); |
| 4073 | |
| 4074 | __ ldc1(f0, FieldMemOperand(a0, HeapNumber::kValueOffset)); |
| 4075 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4076 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4077 | __ cvt_s_d(f0, f0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4078 | __ sll(t8, key, 1); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4079 | __ addu(t8, a3, t8); |
| 4080 | __ swc1(f0, MemOperand(t8, 0)); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4081 | } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4082 | __ sll(t8, key, 2); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4083 | __ addu(t8, a3, t8); |
| 4084 | __ sdc1(f0, MemOperand(t8, 0)); |
| 4085 | } else { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4086 | __ EmitECMATruncate(t3, f0, f2, t2, t1, t5); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4087 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4088 | switch (elements_kind) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4089 | case EXTERNAL_BYTE_ELEMENTS: |
| 4090 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4091 | __ srl(t8, key, 1); |
| 4092 | __ addu(t8, a3, t8); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4093 | __ sb(t3, MemOperand(t8, 0)); |
| 4094 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4095 | case EXTERNAL_SHORT_ELEMENTS: |
| 4096 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4097 | __ addu(t8, a3, key); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4098 | __ sh(t3, MemOperand(t8, 0)); |
| 4099 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4100 | case EXTERNAL_INT_ELEMENTS: |
| 4101 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4102 | __ sll(t8, key, 1); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4103 | __ addu(t8, a3, t8); |
| 4104 | __ sw(t3, MemOperand(t8, 0)); |
| 4105 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4106 | case EXTERNAL_PIXEL_ELEMENTS: |
| 4107 | case EXTERNAL_FLOAT_ELEMENTS: |
| 4108 | case EXTERNAL_DOUBLE_ELEMENTS: |
| 4109 | case FAST_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4110 | case FAST_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4111 | case FAST_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4112 | case FAST_HOLEY_ELEMENTS: |
| 4113 | case FAST_HOLEY_SMI_ELEMENTS: |
| 4114 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4115 | case DICTIONARY_ELEMENTS: |
| 4116 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4117 | UNREACHABLE(); |
| 4118 | break; |
| 4119 | } |
| 4120 | } |
| 4121 | |
| 4122 | // Entry registers are intact, a0 holds the value |
| 4123 | // which is the return value. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4124 | __ mov(v0, a0); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4125 | __ Ret(); |
| 4126 | } else { |
| 4127 | // FPU is not available, do manual conversions. |
| 4128 | |
| 4129 | __ lw(t3, FieldMemOperand(value, HeapNumber::kExponentOffset)); |
| 4130 | __ lw(t4, FieldMemOperand(value, HeapNumber::kMantissaOffset)); |
| 4131 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4132 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4133 | Label done, nan_or_infinity_or_zero; |
| 4134 | static const int kMantissaInHiWordShift = |
| 4135 | kBinary32MantissaBits - HeapNumber::kMantissaBitsInTopWord; |
| 4136 | |
| 4137 | static const int kMantissaInLoWordShift = |
| 4138 | kBitsPerInt - kMantissaInHiWordShift; |
| 4139 | |
| 4140 | // Test for all special exponent values: zeros, subnormal numbers, NaNs |
| 4141 | // and infinities. All these should be converted to 0. |
| 4142 | __ li(t5, HeapNumber::kExponentMask); |
| 4143 | __ and_(t6, t3, t5); |
| 4144 | __ Branch(&nan_or_infinity_or_zero, eq, t6, Operand(zero_reg)); |
| 4145 | |
| 4146 | __ xor_(t1, t6, t5); |
| 4147 | __ li(t2, kBinary32ExponentMask); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 4148 | __ Movz(t6, t2, t1); // Only if t6 is equal to t5. |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 4149 | __ Branch(&nan_or_infinity_or_zero, eq, t1, Operand(zero_reg)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4150 | |
| 4151 | // Rebias exponent. |
| 4152 | __ srl(t6, t6, HeapNumber::kExponentShift); |
| 4153 | __ Addu(t6, |
| 4154 | t6, |
| 4155 | Operand(kBinary32ExponentBias - HeapNumber::kExponentBias)); |
| 4156 | |
| 4157 | __ li(t1, Operand(kBinary32MaxExponent)); |
| 4158 | __ Slt(t1, t1, t6); |
| 4159 | __ And(t2, t3, Operand(HeapNumber::kSignMask)); |
| 4160 | __ Or(t2, t2, Operand(kBinary32ExponentMask)); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 4161 | __ Movn(t3, t2, t1); // Only if t6 is gt kBinary32MaxExponent. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4162 | __ Branch(&done, gt, t6, Operand(kBinary32MaxExponent)); |
| 4163 | |
| 4164 | __ Slt(t1, t6, Operand(kBinary32MinExponent)); |
| 4165 | __ And(t2, t3, Operand(HeapNumber::kSignMask)); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 4166 | __ Movn(t3, t2, t1); // Only if t6 is lt kBinary32MinExponent. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4167 | __ Branch(&done, lt, t6, Operand(kBinary32MinExponent)); |
| 4168 | |
| 4169 | __ And(t7, t3, Operand(HeapNumber::kSignMask)); |
| 4170 | __ And(t3, t3, Operand(HeapNumber::kMantissaMask)); |
| 4171 | __ sll(t3, t3, kMantissaInHiWordShift); |
| 4172 | __ or_(t7, t7, t3); |
| 4173 | __ srl(t4, t4, kMantissaInLoWordShift); |
| 4174 | __ or_(t7, t7, t4); |
| 4175 | __ sll(t6, t6, kBinary32ExponentShift); |
| 4176 | __ or_(t3, t7, t6); |
| 4177 | |
| 4178 | __ bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4179 | __ sll(t9, key, 1); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 4180 | __ addu(t9, a3, t9); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4181 | __ sw(t3, MemOperand(t9, 0)); |
| 4182 | |
| 4183 | // Entry registers are intact, a0 holds the value which is the return |
| 4184 | // value. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4185 | __ mov(v0, a0); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4186 | __ Ret(); |
| 4187 | |
| 4188 | __ bind(&nan_or_infinity_or_zero); |
| 4189 | __ And(t7, t3, Operand(HeapNumber::kSignMask)); |
| 4190 | __ And(t3, t3, Operand(HeapNumber::kMantissaMask)); |
| 4191 | __ or_(t6, t6, t7); |
| 4192 | __ sll(t3, t3, kMantissaInHiWordShift); |
| 4193 | __ or_(t6, t6, t3); |
| 4194 | __ srl(t4, t4, kMantissaInLoWordShift); |
| 4195 | __ or_(t3, t6, t4); |
| 4196 | __ Branch(&done); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4197 | } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 4198 | __ sll(t8, key, 2); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4199 | __ addu(t8, a3, t8); |
| 4200 | // t8: effective address of destination element. |
| 4201 | __ sw(t4, MemOperand(t8, 0)); |
| 4202 | __ sw(t3, MemOperand(t8, Register::kSizeInBytes)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4203 | __ mov(v0, a0); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4204 | __ Ret(); |
| 4205 | } else { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4206 | bool is_signed_type = IsElementTypeSigned(elements_kind); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4207 | int meaningfull_bits = is_signed_type ? (kBitsPerInt - 1) : kBitsPerInt; |
| 4208 | int32_t min_value = is_signed_type ? 0x80000000 : 0x00000000; |
| 4209 | |
| 4210 | Label done, sign; |
| 4211 | |
| 4212 | // Test for all special exponent values: zeros, subnormal numbers, NaNs |
| 4213 | // and infinities. All these should be converted to 0. |
| 4214 | __ li(t5, HeapNumber::kExponentMask); |
| 4215 | __ and_(t6, t3, t5); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 4216 | __ Movz(t3, zero_reg, t6); // Only if t6 is equal to zero. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4217 | __ Branch(&done, eq, t6, Operand(zero_reg)); |
| 4218 | |
| 4219 | __ xor_(t2, t6, t5); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 4220 | __ Movz(t3, zero_reg, t2); // Only if t6 is equal to t5. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4221 | __ Branch(&done, eq, t6, Operand(t5)); |
| 4222 | |
| 4223 | // Unbias exponent. |
| 4224 | __ srl(t6, t6, HeapNumber::kExponentShift); |
| 4225 | __ Subu(t6, t6, Operand(HeapNumber::kExponentBias)); |
| 4226 | // If exponent is negative then result is 0. |
| 4227 | __ slt(t2, t6, zero_reg); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 4228 | __ Movn(t3, zero_reg, t2); // Only if exponent is negative. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4229 | __ Branch(&done, lt, t6, Operand(zero_reg)); |
| 4230 | |
| 4231 | // If exponent is too big then result is minimal value. |
| 4232 | __ slti(t1, t6, meaningfull_bits - 1); |
| 4233 | __ li(t2, min_value); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 4234 | __ Movz(t3, t2, t1); // Only if t6 is ge meaningfull_bits - 1. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4235 | __ Branch(&done, ge, t6, Operand(meaningfull_bits - 1)); |
| 4236 | |
| 4237 | __ And(t5, t3, Operand(HeapNumber::kSignMask)); |
| 4238 | __ And(t3, t3, Operand(HeapNumber::kMantissaMask)); |
| 4239 | __ Or(t3, t3, Operand(1u << HeapNumber::kMantissaBitsInTopWord)); |
| 4240 | |
| 4241 | __ li(t9, HeapNumber::kMantissaBitsInTopWord); |
| 4242 | __ subu(t6, t9, t6); |
| 4243 | __ slt(t1, t6, zero_reg); |
| 4244 | __ srlv(t2, t3, t6); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 4245 | __ Movz(t3, t2, t1); // Only if t6 is positive. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4246 | __ Branch(&sign, ge, t6, Operand(zero_reg)); |
| 4247 | |
| 4248 | __ subu(t6, zero_reg, t6); |
| 4249 | __ sllv(t3, t3, t6); |
| 4250 | __ li(t9, meaningfull_bits); |
| 4251 | __ subu(t6, t9, t6); |
| 4252 | __ srlv(t4, t4, t6); |
| 4253 | __ or_(t3, t3, t4); |
| 4254 | |
| 4255 | __ bind(&sign); |
| 4256 | __ subu(t2, t3, zero_reg); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 4257 | __ Movz(t3, t2, t5); // Only if t5 is zero. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4258 | |
| 4259 | __ bind(&done); |
| 4260 | |
| 4261 | // Result is in t3. |
| 4262 | // This switch block should be exactly the same as above (FPU mode). |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4263 | switch (elements_kind) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4264 | case EXTERNAL_BYTE_ELEMENTS: |
| 4265 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4266 | __ srl(t8, key, 1); |
| 4267 | __ addu(t8, a3, t8); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4268 | __ sb(t3, MemOperand(t8, 0)); |
| 4269 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4270 | case EXTERNAL_SHORT_ELEMENTS: |
| 4271 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4272 | __ addu(t8, a3, key); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4273 | __ sh(t3, MemOperand(t8, 0)); |
| 4274 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4275 | case EXTERNAL_INT_ELEMENTS: |
| 4276 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4277 | __ sll(t8, key, 1); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4278 | __ addu(t8, a3, t8); |
| 4279 | __ sw(t3, MemOperand(t8, 0)); |
| 4280 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4281 | case EXTERNAL_PIXEL_ELEMENTS: |
| 4282 | case EXTERNAL_FLOAT_ELEMENTS: |
| 4283 | case EXTERNAL_DOUBLE_ELEMENTS: |
| 4284 | case FAST_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4285 | case FAST_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4286 | case FAST_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4287 | case FAST_HOLEY_ELEMENTS: |
| 4288 | case FAST_HOLEY_SMI_ELEMENTS: |
| 4289 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4290 | case DICTIONARY_ELEMENTS: |
| 4291 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4292 | UNREACHABLE(); |
| 4293 | break; |
| 4294 | } |
| 4295 | } |
| 4296 | } |
| 4297 | } |
| 4298 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4299 | // Slow case, key and receiver still in a0 and a1. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4300 | __ bind(&slow); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4301 | __ IncrementCounter( |
| 4302 | masm->isolate()->counters()->keyed_load_external_array_slow(), |
| 4303 | 1, a2, a3); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4304 | // Entry registers are intact. |
| 4305 | // ---------- S t a t e -------------- |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4306 | // -- ra : return address |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4307 | // -- a0 : key |
| 4308 | // -- a1 : receiver |
| 4309 | // ----------------------------------- |
| 4310 | Handle<Code> slow_ic = |
| 4311 | masm->isolate()->builtins()->KeyedStoreIC_Slow(); |
| 4312 | __ Jump(slow_ic, RelocInfo::CODE_TARGET); |
| 4313 | |
| 4314 | // Miss case, call the runtime. |
| 4315 | __ bind(&miss_force_generic); |
| 4316 | |
| 4317 | // ---------- S t a t e -------------- |
| 4318 | // -- ra : return address |
| 4319 | // -- a0 : key |
| 4320 | // -- a1 : receiver |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4321 | // ----------------------------------- |
| 4322 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4323 | Handle<Code> miss_ic = |
| 4324 | masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric(); |
| 4325 | __ Jump(miss_ic, RelocInfo::CODE_TARGET); |
| 4326 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4327 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4328 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4329 | void KeyedLoadStubCompiler::GenerateLoadFastElement(MacroAssembler* masm) { |
| 4330 | // ----------- S t a t e ------------- |
| 4331 | // -- ra : return address |
| 4332 | // -- a0 : key |
| 4333 | // -- a1 : receiver |
| 4334 | // ----------------------------------- |
| 4335 | Label miss_force_generic; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4336 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4337 | // This stub is meant to be tail-jumped to, the receiver must already |
| 4338 | // have been verified by the caller to not be a smi. |
| 4339 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4340 | // Check that the key is a smi or a heap number convertible to a smi. |
| 4341 | GenerateSmiKeyCheck(masm, a0, t0, t1, f2, &miss_force_generic); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4342 | |
| 4343 | // Get the elements array. |
| 4344 | __ lw(a2, FieldMemOperand(a1, JSObject::kElementsOffset)); |
| 4345 | __ AssertFastElements(a2); |
| 4346 | |
| 4347 | // Check that the key is within bounds. |
| 4348 | __ lw(a3, FieldMemOperand(a2, FixedArray::kLengthOffset)); |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 4349 | __ Branch(USE_DELAY_SLOT, &miss_force_generic, hs, a0, Operand(a3)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4350 | |
| 4351 | // Load the result and make sure it's not the hole. |
| 4352 | __ Addu(a3, a2, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 4353 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4354 | __ sll(t0, a0, kPointerSizeLog2 - kSmiTagSize); |
| 4355 | __ Addu(t0, t0, a3); |
| 4356 | __ lw(t0, MemOperand(t0)); |
| 4357 | __ LoadRoot(t1, Heap::kTheHoleValueRootIndex); |
| 4358 | __ Branch(&miss_force_generic, eq, t0, Operand(t1)); |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 4359 | __ Ret(USE_DELAY_SLOT); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4360 | __ mov(v0, t0); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4361 | |
| 4362 | __ bind(&miss_force_generic); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4363 | Handle<Code> stub = |
| 4364 | masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric(); |
| 4365 | __ Jump(stub, RelocInfo::CODE_TARGET); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4366 | } |
| 4367 | |
| 4368 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4369 | void KeyedLoadStubCompiler::GenerateLoadFastDoubleElement( |
| 4370 | MacroAssembler* masm) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4371 | // ----------- S t a t e ------------- |
| 4372 | // -- ra : return address |
| 4373 | // -- a0 : key |
| 4374 | // -- a1 : receiver |
| 4375 | // ----------------------------------- |
| 4376 | Label miss_force_generic, slow_allocate_heapnumber; |
| 4377 | |
| 4378 | Register key_reg = a0; |
| 4379 | Register receiver_reg = a1; |
| 4380 | Register elements_reg = a2; |
| 4381 | Register heap_number_reg = a2; |
| 4382 | Register indexed_double_offset = a3; |
| 4383 | Register scratch = t0; |
| 4384 | Register scratch2 = t1; |
| 4385 | Register scratch3 = t2; |
| 4386 | Register heap_number_map = t3; |
| 4387 | |
| 4388 | // This stub is meant to be tail-jumped to, the receiver must already |
| 4389 | // have been verified by the caller to not be a smi. |
| 4390 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4391 | // Check that the key is a smi or a heap number convertible to a smi. |
| 4392 | GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, &miss_force_generic); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4393 | |
| 4394 | // Get the elements array. |
| 4395 | __ lw(elements_reg, |
| 4396 | FieldMemOperand(receiver_reg, JSObject::kElementsOffset)); |
| 4397 | |
| 4398 | // Check that the key is within bounds. |
| 4399 | __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset)); |
| 4400 | __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch)); |
| 4401 | |
| 4402 | // Load the upper word of the double in the fixed array and test for NaN. |
| 4403 | __ sll(scratch2, key_reg, kDoubleSizeLog2 - kSmiTagSize); |
| 4404 | __ Addu(indexed_double_offset, elements_reg, Operand(scratch2)); |
| 4405 | uint32_t upper_32_offset = FixedArray::kHeaderSize + sizeof(kHoleNanLower32); |
| 4406 | __ lw(scratch, FieldMemOperand(indexed_double_offset, upper_32_offset)); |
| 4407 | __ Branch(&miss_force_generic, eq, scratch, Operand(kHoleNanUpper32)); |
| 4408 | |
| 4409 | // Non-NaN. Allocate a new heap number and copy the double value into it. |
| 4410 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 4411 | __ AllocateHeapNumber(heap_number_reg, scratch2, scratch3, |
| 4412 | heap_number_map, &slow_allocate_heapnumber); |
| 4413 | |
| 4414 | // Don't need to reload the upper 32 bits of the double, it's already in |
| 4415 | // scratch. |
| 4416 | __ sw(scratch, FieldMemOperand(heap_number_reg, |
| 4417 | HeapNumber::kExponentOffset)); |
| 4418 | __ lw(scratch, FieldMemOperand(indexed_double_offset, |
| 4419 | FixedArray::kHeaderSize)); |
| 4420 | __ sw(scratch, FieldMemOperand(heap_number_reg, |
| 4421 | HeapNumber::kMantissaOffset)); |
| 4422 | |
| 4423 | __ mov(v0, heap_number_reg); |
| 4424 | __ Ret(); |
| 4425 | |
| 4426 | __ bind(&slow_allocate_heapnumber); |
| 4427 | Handle<Code> slow_ic = |
| 4428 | masm->isolate()->builtins()->KeyedLoadIC_Slow(); |
| 4429 | __ Jump(slow_ic, RelocInfo::CODE_TARGET); |
| 4430 | |
| 4431 | __ bind(&miss_force_generic); |
| 4432 | Handle<Code> miss_ic = |
| 4433 | masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric(); |
| 4434 | __ Jump(miss_ic, RelocInfo::CODE_TARGET); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4435 | } |
| 4436 | |
| 4437 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4438 | void KeyedStoreStubCompiler::GenerateStoreFastElement( |
| 4439 | MacroAssembler* masm, |
| 4440 | bool is_js_array, |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4441 | ElementsKind elements_kind, |
| 4442 | KeyedAccessGrowMode grow_mode) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4443 | // ----------- S t a t e ------------- |
| 4444 | // -- a0 : value |
| 4445 | // -- a1 : key |
| 4446 | // -- a2 : receiver |
| 4447 | // -- ra : return address |
| 4448 | // -- a3 : scratch |
| 4449 | // -- a4 : scratch (elements) |
| 4450 | // ----------------------------------- |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4451 | Label miss_force_generic, transition_elements_kind, grow, slow; |
| 4452 | Label finish_store, check_capacity; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4453 | |
| 4454 | Register value_reg = a0; |
| 4455 | Register key_reg = a1; |
| 4456 | Register receiver_reg = a2; |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4457 | Register scratch = t0; |
| 4458 | Register elements_reg = a3; |
| 4459 | Register length_reg = t1; |
| 4460 | Register scratch2 = t2; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4461 | |
| 4462 | // This stub is meant to be tail-jumped to, the receiver must already |
| 4463 | // have been verified by the caller to not be a smi. |
| 4464 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4465 | // Check that the key is a smi or a heap number convertible to a smi. |
| 4466 | GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, &miss_force_generic); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4467 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4468 | if (IsFastSmiElementsKind(elements_kind)) { |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4469 | __ JumpIfNotSmi(value_reg, &transition_elements_kind); |
| 4470 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4471 | |
| 4472 | // Check that the key is within bounds. |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4473 | __ lw(elements_reg, |
| 4474 | FieldMemOperand(receiver_reg, JSObject::kElementsOffset)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4475 | if (is_js_array) { |
| 4476 | __ lw(scratch, FieldMemOperand(receiver_reg, JSArray::kLengthOffset)); |
| 4477 | } else { |
| 4478 | __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset)); |
| 4479 | } |
| 4480 | // Compare smis. |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4481 | if (is_js_array && grow_mode == ALLOW_JSARRAY_GROWTH) { |
| 4482 | __ Branch(&grow, hs, key_reg, Operand(scratch)); |
| 4483 | } else { |
| 4484 | __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch)); |
| 4485 | } |
| 4486 | |
| 4487 | // Make sure elements is a fast element array, not 'cow'. |
| 4488 | __ CheckMap(elements_reg, |
| 4489 | scratch, |
| 4490 | Heap::kFixedArrayMapRootIndex, |
| 4491 | &miss_force_generic, |
| 4492 | DONT_DO_SMI_CHECK); |
| 4493 | |
| 4494 | __ bind(&finish_store); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4495 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4496 | if (IsFastSmiElementsKind(elements_kind)) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4497 | __ Addu(scratch, |
| 4498 | elements_reg, |
| 4499 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 4500 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2); |
| 4501 | __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize); |
| 4502 | __ Addu(scratch, scratch, scratch2); |
| 4503 | __ sw(value_reg, MemOperand(scratch)); |
| 4504 | } else { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4505 | ASSERT(IsFastObjectElementsKind(elements_kind)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4506 | __ Addu(scratch, |
| 4507 | elements_reg, |
| 4508 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 4509 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2); |
| 4510 | __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize); |
| 4511 | __ Addu(scratch, scratch, scratch2); |
| 4512 | __ sw(value_reg, MemOperand(scratch)); |
| 4513 | __ mov(receiver_reg, value_reg); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4514 | __ RecordWrite(elements_reg, // Object. |
| 4515 | scratch, // Address. |
| 4516 | receiver_reg, // Value. |
| 4517 | kRAHasNotBeenSaved, |
| 4518 | kDontSaveFPRegs); |
| 4519 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4520 | // value_reg (a0) is preserved. |
| 4521 | // Done. |
| 4522 | __ Ret(); |
| 4523 | |
| 4524 | __ bind(&miss_force_generic); |
| 4525 | Handle<Code> ic = |
| 4526 | masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric(); |
| 4527 | __ Jump(ic, RelocInfo::CODE_TARGET); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4528 | |
| 4529 | __ bind(&transition_elements_kind); |
| 4530 | Handle<Code> ic_miss = masm->isolate()->builtins()->KeyedStoreIC_Miss(); |
| 4531 | __ Jump(ic_miss, RelocInfo::CODE_TARGET); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4532 | |
| 4533 | if (is_js_array && grow_mode == ALLOW_JSARRAY_GROWTH) { |
| 4534 | // Grow the array by a single element if possible. |
| 4535 | __ bind(&grow); |
| 4536 | |
| 4537 | // Make sure the array is only growing by a single element, anything else |
| 4538 | // must be handled by the runtime. |
| 4539 | __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch)); |
| 4540 | |
| 4541 | // Check for the empty array, and preallocate a small backing store if |
| 4542 | // possible. |
| 4543 | __ lw(length_reg, |
| 4544 | FieldMemOperand(receiver_reg, JSArray::kLengthOffset)); |
| 4545 | __ lw(elements_reg, |
| 4546 | FieldMemOperand(receiver_reg, JSObject::kElementsOffset)); |
| 4547 | __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex); |
| 4548 | __ Branch(&check_capacity, ne, elements_reg, Operand(at)); |
| 4549 | |
| 4550 | int size = FixedArray::SizeFor(JSArray::kPreallocatedArrayElements); |
| 4551 | __ AllocateInNewSpace(size, elements_reg, scratch, scratch2, &slow, |
| 4552 | TAG_OBJECT); |
| 4553 | |
| 4554 | __ LoadRoot(scratch, Heap::kFixedArrayMapRootIndex); |
| 4555 | __ sw(scratch, FieldMemOperand(elements_reg, JSObject::kMapOffset)); |
| 4556 | __ li(scratch, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements))); |
| 4557 | __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset)); |
| 4558 | __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); |
| 4559 | for (int i = 1; i < JSArray::kPreallocatedArrayElements; ++i) { |
| 4560 | __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::SizeFor(i))); |
| 4561 | } |
| 4562 | |
| 4563 | // Store the element at index zero. |
| 4564 | __ sw(value_reg, FieldMemOperand(elements_reg, FixedArray::SizeFor(0))); |
| 4565 | |
| 4566 | // Install the new backing store in the JSArray. |
| 4567 | __ sw(elements_reg, |
| 4568 | FieldMemOperand(receiver_reg, JSObject::kElementsOffset)); |
| 4569 | __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg, |
| 4570 | scratch, kRAHasNotBeenSaved, kDontSaveFPRegs, |
| 4571 | EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); |
| 4572 | |
| 4573 | // Increment the length of the array. |
| 4574 | __ li(length_reg, Operand(Smi::FromInt(1))); |
| 4575 | __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset)); |
| 4576 | __ Ret(); |
| 4577 | |
| 4578 | __ bind(&check_capacity); |
| 4579 | // Check for cow elements, in general they are not handled by this stub |
| 4580 | __ CheckMap(elements_reg, |
| 4581 | scratch, |
| 4582 | Heap::kFixedCOWArrayMapRootIndex, |
| 4583 | &miss_force_generic, |
| 4584 | DONT_DO_SMI_CHECK); |
| 4585 | |
| 4586 | __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset)); |
| 4587 | __ Branch(&slow, hs, length_reg, Operand(scratch)); |
| 4588 | |
| 4589 | // Grow the array and finish the store. |
| 4590 | __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1))); |
| 4591 | __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset)); |
| 4592 | __ jmp(&finish_store); |
| 4593 | |
| 4594 | __ bind(&slow); |
| 4595 | Handle<Code> ic_slow = masm->isolate()->builtins()->KeyedStoreIC_Slow(); |
| 4596 | __ Jump(ic_slow, RelocInfo::CODE_TARGET); |
| 4597 | } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4598 | } |
| 4599 | |
| 4600 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4601 | void KeyedStoreStubCompiler::GenerateStoreFastDoubleElement( |
| 4602 | MacroAssembler* masm, |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4603 | bool is_js_array, |
| 4604 | KeyedAccessGrowMode grow_mode) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4605 | // ----------- S t a t e ------------- |
| 4606 | // -- a0 : value |
| 4607 | // -- a1 : key |
| 4608 | // -- a2 : receiver |
| 4609 | // -- ra : return address |
| 4610 | // -- a3 : scratch |
| 4611 | // -- t0 : scratch (elements_reg) |
| 4612 | // -- t1 : scratch (mantissa_reg) |
| 4613 | // -- t2 : scratch (exponent_reg) |
| 4614 | // -- t3 : scratch4 |
| 4615 | // ----------------------------------- |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4616 | Label miss_force_generic, transition_elements_kind, grow, slow; |
| 4617 | Label finish_store, check_capacity; |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4618 | |
| 4619 | Register value_reg = a0; |
| 4620 | Register key_reg = a1; |
| 4621 | Register receiver_reg = a2; |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4622 | Register elements_reg = a3; |
| 4623 | Register scratch1 = t0; |
| 4624 | Register scratch2 = t1; |
| 4625 | Register scratch3 = t2; |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4626 | Register scratch4 = t3; |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4627 | Register length_reg = t3; |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4628 | |
| 4629 | // This stub is meant to be tail-jumped to, the receiver must already |
| 4630 | // have been verified by the caller to not be a smi. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4631 | |
| 4632 | // Check that the key is a smi or a heap number convertible to a smi. |
| 4633 | GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, &miss_force_generic); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4634 | |
| 4635 | __ lw(elements_reg, |
| 4636 | FieldMemOperand(receiver_reg, JSObject::kElementsOffset)); |
| 4637 | |
| 4638 | // Check that the key is within bounds. |
| 4639 | if (is_js_array) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4640 | __ lw(scratch1, FieldMemOperand(receiver_reg, JSArray::kLengthOffset)); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4641 | } else { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4642 | __ lw(scratch1, |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4643 | FieldMemOperand(elements_reg, FixedArray::kLengthOffset)); |
| 4644 | } |
| 4645 | // Compare smis, unsigned compare catches both negative and out-of-bound |
| 4646 | // indexes. |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4647 | if (grow_mode == ALLOW_JSARRAY_GROWTH) { |
| 4648 | __ Branch(&grow, hs, key_reg, Operand(scratch1)); |
| 4649 | } else { |
| 4650 | __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch1)); |
| 4651 | } |
| 4652 | |
| 4653 | __ bind(&finish_store); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4654 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4655 | __ StoreNumberToDoubleElements(value_reg, |
| 4656 | key_reg, |
| 4657 | receiver_reg, |
| 4658 | elements_reg, |
| 4659 | scratch1, |
| 4660 | scratch2, |
| 4661 | scratch3, |
| 4662 | scratch4, |
| 4663 | &transition_elements_kind); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4664 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4665 | __ Ret(USE_DELAY_SLOT); |
| 4666 | __ mov(v0, value_reg); // In delay slot. |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4667 | |
| 4668 | // Handle store cache miss, replacing the ic with the generic stub. |
| 4669 | __ bind(&miss_force_generic); |
| 4670 | Handle<Code> ic = |
| 4671 | masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric(); |
| 4672 | __ Jump(ic, RelocInfo::CODE_TARGET); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4673 | |
| 4674 | __ bind(&transition_elements_kind); |
| 4675 | Handle<Code> ic_miss = masm->isolate()->builtins()->KeyedStoreIC_Miss(); |
| 4676 | __ Jump(ic_miss, RelocInfo::CODE_TARGET); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4677 | |
| 4678 | if (is_js_array && grow_mode == ALLOW_JSARRAY_GROWTH) { |
| 4679 | // Grow the array by a single element if possible. |
| 4680 | __ bind(&grow); |
| 4681 | |
| 4682 | // Make sure the array is only growing by a single element, anything else |
| 4683 | // must be handled by the runtime. |
| 4684 | __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch1)); |
| 4685 | |
| 4686 | // Transition on values that can't be stored in a FixedDoubleArray. |
| 4687 | Label value_is_smi; |
| 4688 | __ JumpIfSmi(value_reg, &value_is_smi); |
| 4689 | __ lw(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset)); |
| 4690 | __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); |
| 4691 | __ Branch(&transition_elements_kind, ne, scratch1, Operand(at)); |
| 4692 | __ bind(&value_is_smi); |
| 4693 | |
| 4694 | // Check for the empty array, and preallocate a small backing store if |
| 4695 | // possible. |
| 4696 | __ lw(length_reg, |
| 4697 | FieldMemOperand(receiver_reg, JSArray::kLengthOffset)); |
| 4698 | __ lw(elements_reg, |
| 4699 | FieldMemOperand(receiver_reg, JSObject::kElementsOffset)); |
| 4700 | __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex); |
| 4701 | __ Branch(&check_capacity, ne, elements_reg, Operand(at)); |
| 4702 | |
| 4703 | int size = FixedDoubleArray::SizeFor(JSArray::kPreallocatedArrayElements); |
| 4704 | __ AllocateInNewSpace(size, elements_reg, scratch1, scratch2, &slow, |
| 4705 | TAG_OBJECT); |
| 4706 | |
| 4707 | // Initialize the new FixedDoubleArray. Leave elements unitialized for |
| 4708 | // efficiency, they are guaranteed to be initialized before use. |
| 4709 | __ LoadRoot(scratch1, Heap::kFixedDoubleArrayMapRootIndex); |
| 4710 | __ sw(scratch1, FieldMemOperand(elements_reg, JSObject::kMapOffset)); |
| 4711 | __ li(scratch1, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements))); |
| 4712 | __ sw(scratch1, |
| 4713 | FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset)); |
| 4714 | |
| 4715 | // Install the new backing store in the JSArray. |
| 4716 | __ sw(elements_reg, |
| 4717 | FieldMemOperand(receiver_reg, JSObject::kElementsOffset)); |
| 4718 | __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg, |
| 4719 | scratch1, kRAHasNotBeenSaved, kDontSaveFPRegs, |
| 4720 | EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); |
| 4721 | |
| 4722 | // Increment the length of the array. |
| 4723 | __ li(length_reg, Operand(Smi::FromInt(1))); |
| 4724 | __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset)); |
danno@chromium.org | 00379b8 | 2012-05-04 09:16:29 +0000 | [diff] [blame] | 4725 | __ lw(elements_reg, |
| 4726 | FieldMemOperand(receiver_reg, JSObject::kElementsOffset)); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4727 | __ jmp(&finish_store); |
| 4728 | |
| 4729 | __ bind(&check_capacity); |
| 4730 | // Make sure that the backing store can hold additional elements. |
| 4731 | __ lw(scratch1, |
| 4732 | FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset)); |
| 4733 | __ Branch(&slow, hs, length_reg, Operand(scratch1)); |
| 4734 | |
| 4735 | // Grow the array and finish the store. |
| 4736 | __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1))); |
| 4737 | __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset)); |
| 4738 | __ jmp(&finish_store); |
| 4739 | |
| 4740 | __ bind(&slow); |
| 4741 | Handle<Code> ic_slow = masm->isolate()->builtins()->KeyedStoreIC_Slow(); |
| 4742 | __ Jump(ic_slow, RelocInfo::CODE_TARGET); |
| 4743 | } |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4744 | } |
| 4745 | |
| 4746 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4747 | #undef __ |
| 4748 | |
| 4749 | } } // namespace v8::internal |
| 4750 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4751 | #endif // V8_TARGET_ARCH_MIPS |