Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #if V8_TARGET_ARCH_X87 |
| 6 | |
| 7 | #include "src/codegen.h" |
| 8 | #include "src/ic/ic.h" |
| 9 | #include "src/ic/ic-compiler.h" |
| 10 | #include "src/ic/stub-cache.h" |
| 11 | |
| 12 | namespace v8 { |
| 13 | namespace internal { |
| 14 | |
| 15 | // ---------------------------------------------------------------------------- |
| 16 | // Static IC stub generators. |
| 17 | // |
| 18 | |
| 19 | #define __ ACCESS_MASM(masm) |
| 20 | |
| 21 | |
| 22 | static void GenerateGlobalInstanceTypeCheck(MacroAssembler* masm, Register type, |
| 23 | Label* global_object) { |
| 24 | // Register usage: |
| 25 | // type: holds the receiver instance type on entry. |
| 26 | __ cmp(type, JS_GLOBAL_OBJECT_TYPE); |
| 27 | __ j(equal, global_object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 28 | __ cmp(type, JS_GLOBAL_PROXY_TYPE); |
| 29 | __ j(equal, global_object); |
| 30 | } |
| 31 | |
| 32 | |
| 33 | // Helper function used to load a property from a dictionary backing |
| 34 | // storage. This function may fail to load a property even though it is |
| 35 | // in the dictionary, so code at miss_label must always call a backup |
| 36 | // property load that is complete. This function is safe to call if |
| 37 | // name is not internalized, and will jump to the miss_label in that |
| 38 | // case. The generated code assumes that the receiver has slow |
| 39 | // properties, is not a global object and does not have interceptors. |
| 40 | static void GenerateDictionaryLoad(MacroAssembler* masm, Label* miss_label, |
| 41 | Register elements, Register name, |
| 42 | Register r0, Register r1, Register result) { |
| 43 | // Register use: |
| 44 | // |
| 45 | // elements - holds the property dictionary on entry and is unchanged. |
| 46 | // |
| 47 | // name - holds the name of the property on entry and is unchanged. |
| 48 | // |
| 49 | // Scratch registers: |
| 50 | // |
| 51 | // r0 - used for the index into the property dictionary |
| 52 | // |
| 53 | // r1 - used to hold the capacity of the property dictionary. |
| 54 | // |
| 55 | // result - holds the result on exit. |
| 56 | |
| 57 | Label done; |
| 58 | |
| 59 | // Probe the dictionary. |
| 60 | NameDictionaryLookupStub::GeneratePositiveLookup(masm, miss_label, &done, |
| 61 | elements, name, r0, r1); |
| 62 | |
| 63 | // If probing finds an entry in the dictionary, r0 contains the |
| 64 | // index into the dictionary. Check that the value is a normal |
| 65 | // property. |
| 66 | __ bind(&done); |
| 67 | const int kElementsStartOffset = |
| 68 | NameDictionary::kHeaderSize + |
| 69 | NameDictionary::kElementsStartIndex * kPointerSize; |
| 70 | const int kDetailsOffset = kElementsStartOffset + 2 * kPointerSize; |
| 71 | __ test(Operand(elements, r0, times_4, kDetailsOffset - kHeapObjectTag), |
| 72 | Immediate(PropertyDetails::TypeField::kMask << kSmiTagSize)); |
| 73 | __ j(not_zero, miss_label); |
| 74 | |
| 75 | // Get the value at the masked, scaled index. |
| 76 | const int kValueOffset = kElementsStartOffset + kPointerSize; |
| 77 | __ mov(result, Operand(elements, r0, times_4, kValueOffset - kHeapObjectTag)); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | // Helper function used to store a property to a dictionary backing |
| 82 | // storage. This function may fail to store a property eventhough it |
| 83 | // is in the dictionary, so code at miss_label must always call a |
| 84 | // backup property store that is complete. This function is safe to |
| 85 | // call if name is not internalized, and will jump to the miss_label in |
| 86 | // that case. The generated code assumes that the receiver has slow |
| 87 | // properties, is not a global object and does not have interceptors. |
| 88 | static void GenerateDictionaryStore(MacroAssembler* masm, Label* miss_label, |
| 89 | Register elements, Register name, |
| 90 | Register value, Register r0, Register r1) { |
| 91 | // Register use: |
| 92 | // |
| 93 | // elements - holds the property dictionary on entry and is clobbered. |
| 94 | // |
| 95 | // name - holds the name of the property on entry and is unchanged. |
| 96 | // |
| 97 | // value - holds the value to store and is unchanged. |
| 98 | // |
| 99 | // r0 - used for index into the property dictionary and is clobbered. |
| 100 | // |
| 101 | // r1 - used to hold the capacity of the property dictionary and is clobbered. |
| 102 | Label done; |
| 103 | |
| 104 | |
| 105 | // Probe the dictionary. |
| 106 | NameDictionaryLookupStub::GeneratePositiveLookup(masm, miss_label, &done, |
| 107 | elements, name, r0, r1); |
| 108 | |
| 109 | // If probing finds an entry in the dictionary, r0 contains the |
| 110 | // index into the dictionary. Check that the value is a normal |
| 111 | // property that is not read only. |
| 112 | __ bind(&done); |
| 113 | const int kElementsStartOffset = |
| 114 | NameDictionary::kHeaderSize + |
| 115 | NameDictionary::kElementsStartIndex * kPointerSize; |
| 116 | const int kDetailsOffset = kElementsStartOffset + 2 * kPointerSize; |
| 117 | const int kTypeAndReadOnlyMask = |
| 118 | (PropertyDetails::TypeField::kMask | |
| 119 | PropertyDetails::AttributesField::encode(READ_ONLY)) |
| 120 | << kSmiTagSize; |
| 121 | __ test(Operand(elements, r0, times_4, kDetailsOffset - kHeapObjectTag), |
| 122 | Immediate(kTypeAndReadOnlyMask)); |
| 123 | __ j(not_zero, miss_label); |
| 124 | |
| 125 | // Store the value at the masked, scaled index. |
| 126 | const int kValueOffset = kElementsStartOffset + kPointerSize; |
| 127 | __ lea(r0, Operand(elements, r0, times_4, kValueOffset - kHeapObjectTag)); |
| 128 | __ mov(Operand(r0, 0), value); |
| 129 | |
| 130 | // Update write barrier. Make sure not to clobber the value. |
| 131 | __ mov(r1, value); |
| 132 | __ RecordWrite(elements, r0, r1, kDontSaveFPRegs); |
| 133 | } |
| 134 | |
| 135 | |
| 136 | // Checks the receiver for special cases (value type, slow case bits). |
| 137 | // Falls through for regular JS object. |
| 138 | static void GenerateKeyedLoadReceiverCheck(MacroAssembler* masm, |
| 139 | Register receiver, Register map, |
| 140 | int interceptor_bit, Label* slow) { |
| 141 | // Register use: |
| 142 | // receiver - holds the receiver and is unchanged. |
| 143 | // Scratch registers: |
| 144 | // map - used to hold the map of the receiver. |
| 145 | |
| 146 | // Check that the object isn't a smi. |
| 147 | __ JumpIfSmi(receiver, slow); |
| 148 | |
| 149 | // Get the map of the receiver. |
| 150 | __ mov(map, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 151 | |
| 152 | // Check bit field. |
| 153 | __ test_b(FieldOperand(map, Map::kBitFieldOffset), |
| 154 | (1 << Map::kIsAccessCheckNeeded) | (1 << interceptor_bit)); |
| 155 | __ j(not_zero, slow); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 156 | // Check that the object is some kind of JS object EXCEPT JS Value type. In |
| 157 | // the case that the object is a value-wrapper object, we enter the runtime |
| 158 | // system to make sure that indexing into string objects works as intended. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 159 | DCHECK(JS_OBJECT_TYPE > JS_VALUE_TYPE); |
| 160 | |
| 161 | __ CmpInstanceType(map, JS_OBJECT_TYPE); |
| 162 | __ j(below, slow); |
| 163 | } |
| 164 | |
| 165 | |
| 166 | // Loads an indexed element from a fast case array. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 167 | static void GenerateFastArrayLoad(MacroAssembler* masm, Register receiver, |
| 168 | Register key, Register scratch, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 169 | Register scratch2, Register result, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 170 | Label* slow) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 171 | // Register use: |
| 172 | // receiver - holds the receiver and is unchanged. |
| 173 | // key - holds the key and is unchanged (must be a smi). |
| 174 | // Scratch registers: |
| 175 | // scratch - used to hold elements of the receiver and the loaded value. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 176 | // scratch2 - holds maps and prototypes during prototype chain check. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 177 | // result - holds the result on exit if the load succeeds and |
| 178 | // we fall through. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 179 | Label check_prototypes, check_next_prototype; |
| 180 | Label done, in_bounds, absent; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 181 | |
| 182 | __ mov(scratch, FieldOperand(receiver, JSObject::kElementsOffset)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 183 | __ AssertFastElements(scratch); |
| 184 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 185 | // Check that the key (index) is within bounds. |
| 186 | __ cmp(key, FieldOperand(scratch, FixedArray::kLengthOffset)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 187 | __ j(below, &in_bounds); |
| 188 | // Out-of-bounds. Check the prototype chain to see if we can just return |
| 189 | // 'undefined'. |
| 190 | __ cmp(key, 0); |
| 191 | __ j(less, slow); // Negative keys can't take the fast OOB path. |
| 192 | __ bind(&check_prototypes); |
| 193 | __ mov(scratch2, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 194 | __ bind(&check_next_prototype); |
| 195 | __ mov(scratch2, FieldOperand(scratch2, Map::kPrototypeOffset)); |
| 196 | // scratch2: current prototype |
| 197 | __ cmp(scratch2, masm->isolate()->factory()->null_value()); |
| 198 | __ j(equal, &absent); |
| 199 | __ mov(scratch, FieldOperand(scratch2, JSObject::kElementsOffset)); |
| 200 | __ mov(scratch2, FieldOperand(scratch2, HeapObject::kMapOffset)); |
| 201 | // scratch: elements of current prototype |
| 202 | // scratch2: map of current prototype |
| 203 | __ CmpInstanceType(scratch2, JS_OBJECT_TYPE); |
| 204 | __ j(below, slow); |
| 205 | __ test_b( |
| 206 | FieldOperand(scratch2, Map::kBitFieldOffset), |
| 207 | (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor)); |
| 208 | __ j(not_zero, slow); |
| 209 | __ cmp(scratch, masm->isolate()->factory()->empty_fixed_array()); |
| 210 | __ j(not_equal, slow); |
| 211 | __ jmp(&check_next_prototype); |
| 212 | |
| 213 | __ bind(&absent); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 214 | __ mov(result, masm->isolate()->factory()->undefined_value()); |
| 215 | __ jmp(&done); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 216 | |
| 217 | __ bind(&in_bounds); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 218 | // Fast case: Do the load. |
| 219 | STATIC_ASSERT((kPointerSize == 4) && (kSmiTagSize == 1) && (kSmiTag == 0)); |
| 220 | __ mov(scratch, FieldOperand(scratch, key, times_2, FixedArray::kHeaderSize)); |
| 221 | __ cmp(scratch, Immediate(masm->isolate()->factory()->the_hole_value())); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 222 | // In case the loaded value is the_hole we have to check the prototype chain. |
| 223 | __ j(equal, &check_prototypes); |
| 224 | __ Move(result, scratch); |
| 225 | __ bind(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | |
| 229 | // Checks whether a key is an array index string or a unique name. |
| 230 | // Falls through if the key is a unique name. |
| 231 | static void GenerateKeyNameCheck(MacroAssembler* masm, Register key, |
| 232 | Register map, Register hash, |
| 233 | Label* index_string, Label* not_unique) { |
| 234 | // Register use: |
| 235 | // key - holds the key and is unchanged. Assumed to be non-smi. |
| 236 | // Scratch registers: |
| 237 | // map - used to hold the map of the key. |
| 238 | // hash - used to hold the hash of the key. |
| 239 | Label unique; |
| 240 | __ CmpObjectType(key, LAST_UNIQUE_NAME_TYPE, map); |
| 241 | __ j(above, not_unique); |
| 242 | STATIC_ASSERT(LAST_UNIQUE_NAME_TYPE == FIRST_NONSTRING_TYPE); |
| 243 | __ j(equal, &unique); |
| 244 | |
| 245 | // Is the string an array index, with cached numeric value? |
| 246 | __ mov(hash, FieldOperand(key, Name::kHashFieldOffset)); |
| 247 | __ test(hash, Immediate(Name::kContainsCachedArrayIndexMask)); |
| 248 | __ j(zero, index_string); |
| 249 | |
| 250 | // Is the string internalized? We already know it's a string so a single |
| 251 | // bit test is enough. |
| 252 | STATIC_ASSERT(kNotInternalizedTag != 0); |
| 253 | __ test_b(FieldOperand(map, Map::kInstanceTypeOffset), |
| 254 | kIsNotInternalizedMask); |
| 255 | __ j(not_zero, not_unique); |
| 256 | |
| 257 | __ bind(&unique); |
| 258 | } |
| 259 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 260 | void KeyedLoadIC::GenerateMegamorphic(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 261 | // The return address is on the stack. |
| 262 | Label slow, check_name, index_smi, index_name, property_array_property; |
| 263 | Label probe_dictionary, check_number_dictionary; |
| 264 | |
| 265 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 266 | Register key = LoadDescriptor::NameRegister(); |
| 267 | DCHECK(receiver.is(edx)); |
| 268 | DCHECK(key.is(ecx)); |
| 269 | |
| 270 | // Check that the key is a smi. |
| 271 | __ JumpIfNotSmi(key, &check_name); |
| 272 | __ bind(&index_smi); |
| 273 | // Now the key is known to be a smi. This place is also jumped to from |
| 274 | // where a numeric string is converted to a smi. |
| 275 | |
| 276 | GenerateKeyedLoadReceiverCheck(masm, receiver, eax, |
| 277 | Map::kHasIndexedInterceptor, &slow); |
| 278 | |
| 279 | // Check the receiver's map to see if it has fast elements. |
| 280 | __ CheckFastElements(eax, &check_number_dictionary); |
| 281 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 282 | GenerateFastArrayLoad(masm, receiver, key, eax, ebx, eax, &slow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 283 | Isolate* isolate = masm->isolate(); |
| 284 | Counters* counters = isolate->counters(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 285 | __ IncrementCounter(counters->ic_keyed_load_generic_smi(), 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 286 | __ ret(0); |
| 287 | |
| 288 | __ bind(&check_number_dictionary); |
| 289 | __ mov(ebx, key); |
| 290 | __ SmiUntag(ebx); |
| 291 | __ mov(eax, FieldOperand(receiver, JSObject::kElementsOffset)); |
| 292 | |
| 293 | // Check whether the elements is a number dictionary. |
| 294 | // ebx: untagged index |
| 295 | // eax: elements |
| 296 | __ CheckMap(eax, isolate->factory()->hash_table_map(), &slow, |
| 297 | DONT_DO_SMI_CHECK); |
| 298 | Label slow_pop_receiver; |
| 299 | // Push receiver on the stack to free up a register for the dictionary |
| 300 | // probing. |
| 301 | __ push(receiver); |
| 302 | __ LoadFromNumberDictionary(&slow_pop_receiver, eax, key, ebx, edx, edi, eax); |
| 303 | // Pop receiver before returning. |
| 304 | __ pop(receiver); |
| 305 | __ ret(0); |
| 306 | |
| 307 | __ bind(&slow_pop_receiver); |
| 308 | // Pop the receiver from the stack and jump to runtime. |
| 309 | __ pop(receiver); |
| 310 | |
| 311 | __ bind(&slow); |
| 312 | // Slow case: jump to runtime. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 313 | __ IncrementCounter(counters->ic_keyed_load_generic_slow(), 1); |
| 314 | GenerateRuntimeGetProperty(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 315 | |
| 316 | __ bind(&check_name); |
| 317 | GenerateKeyNameCheck(masm, key, eax, ebx, &index_name, &slow); |
| 318 | |
| 319 | GenerateKeyedLoadReceiverCheck(masm, receiver, eax, Map::kHasNamedInterceptor, |
| 320 | &slow); |
| 321 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 322 | // If the receiver is a fast-case object, check the stub cache. Otherwise |
| 323 | // probe the dictionary. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 324 | __ mov(ebx, FieldOperand(receiver, JSObject::kPropertiesOffset)); |
| 325 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
| 326 | Immediate(isolate->factory()->hash_table_map())); |
| 327 | __ j(equal, &probe_dictionary); |
| 328 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 329 | // The handlers in the stub cache expect a vector and slot. Since we won't |
| 330 | // change the IC from any downstream misses, a dummy vector can be used. |
| 331 | Handle<TypeFeedbackVector> dummy_vector = |
| 332 | TypeFeedbackVector::DummyVector(isolate); |
| 333 | int slot = dummy_vector->GetIndex( |
| 334 | FeedbackVectorSlot(TypeFeedbackVector::kDummyKeyedLoadICSlot)); |
| 335 | __ push(Immediate(Smi::FromInt(slot))); |
| 336 | __ push(Immediate(dummy_vector)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 337 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 338 | Code::Flags flags = Code::RemoveTypeAndHolderFromFlags( |
| 339 | Code::ComputeHandlerFlags(Code::LOAD_IC)); |
| 340 | masm->isolate()->stub_cache()->GenerateProbe(masm, Code::KEYED_LOAD_IC, flags, |
| 341 | receiver, key, ebx, edi); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 342 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 343 | __ pop(LoadWithVectorDescriptor::VectorRegister()); |
| 344 | __ pop(LoadDescriptor::SlotRegister()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 345 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 346 | // Cache miss. |
| 347 | GenerateMiss(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 348 | |
| 349 | // Do a quick inline probe of the receiver's dictionary, if it |
| 350 | // exists. |
| 351 | __ bind(&probe_dictionary); |
| 352 | |
| 353 | __ mov(eax, FieldOperand(receiver, JSObject::kMapOffset)); |
| 354 | __ movzx_b(eax, FieldOperand(eax, Map::kInstanceTypeOffset)); |
| 355 | GenerateGlobalInstanceTypeCheck(masm, eax, &slow); |
| 356 | |
| 357 | GenerateDictionaryLoad(masm, &slow, ebx, key, eax, edi, eax); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 358 | __ IncrementCounter(counters->ic_keyed_load_generic_symbol(), 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 359 | __ ret(0); |
| 360 | |
| 361 | __ bind(&index_name); |
| 362 | __ IndexFromHash(ebx, key); |
| 363 | // Now jump to the place where smi keys are handled. |
| 364 | __ jmp(&index_smi); |
| 365 | } |
| 366 | |
| 367 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 368 | static void KeyedStoreGenerateMegamorphicHelper( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 369 | MacroAssembler* masm, Label* fast_object, Label* fast_double, Label* slow, |
| 370 | KeyedStoreCheckMap check_map, KeyedStoreIncrementLength increment_length) { |
| 371 | Label transition_smi_elements; |
| 372 | Label finish_object_store, non_double_value, transition_double_elements; |
| 373 | Label fast_double_without_map_check; |
| 374 | Register receiver = StoreDescriptor::ReceiverRegister(); |
| 375 | Register key = StoreDescriptor::NameRegister(); |
| 376 | Register value = StoreDescriptor::ValueRegister(); |
| 377 | DCHECK(receiver.is(edx)); |
| 378 | DCHECK(key.is(ecx)); |
| 379 | DCHECK(value.is(eax)); |
| 380 | // key is a smi. |
| 381 | // ebx: FixedArray receiver->elements |
| 382 | // edi: receiver map |
| 383 | // Fast case: Do the store, could either Object or double. |
| 384 | __ bind(fast_object); |
| 385 | if (check_map == kCheckMap) { |
| 386 | __ mov(edi, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 387 | __ cmp(edi, masm->isolate()->factory()->fixed_array_map()); |
| 388 | __ j(not_equal, fast_double); |
| 389 | } |
| 390 | |
| 391 | // HOLECHECK: guards "A[i] = V" |
| 392 | // We have to go to the runtime if the current value is the hole because |
| 393 | // there may be a callback on the element |
| 394 | Label holecheck_passed1; |
| 395 | __ cmp(FixedArrayElementOperand(ebx, key), |
| 396 | masm->isolate()->factory()->the_hole_value()); |
| 397 | __ j(not_equal, &holecheck_passed1); |
| 398 | __ JumpIfDictionaryInPrototypeChain(receiver, ebx, edi, slow); |
| 399 | __ mov(ebx, FieldOperand(receiver, JSObject::kElementsOffset)); |
| 400 | |
| 401 | __ bind(&holecheck_passed1); |
| 402 | |
| 403 | // Smi stores don't require further checks. |
| 404 | Label non_smi_value; |
| 405 | __ JumpIfNotSmi(value, &non_smi_value); |
| 406 | if (increment_length == kIncrementLength) { |
| 407 | // Add 1 to receiver->length. |
| 408 | __ add(FieldOperand(receiver, JSArray::kLengthOffset), |
| 409 | Immediate(Smi::FromInt(1))); |
| 410 | } |
| 411 | // It's irrelevant whether array is smi-only or not when writing a smi. |
| 412 | __ mov(FixedArrayElementOperand(ebx, key), value); |
| 413 | __ ret(0); |
| 414 | |
| 415 | __ bind(&non_smi_value); |
| 416 | // Escape to elements kind transition case. |
| 417 | __ mov(edi, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 418 | __ CheckFastObjectElements(edi, &transition_smi_elements); |
| 419 | |
| 420 | // Fast elements array, store the value to the elements backing store. |
| 421 | __ bind(&finish_object_store); |
| 422 | if (increment_length == kIncrementLength) { |
| 423 | // Add 1 to receiver->length. |
| 424 | __ add(FieldOperand(receiver, JSArray::kLengthOffset), |
| 425 | Immediate(Smi::FromInt(1))); |
| 426 | } |
| 427 | __ mov(FixedArrayElementOperand(ebx, key), value); |
| 428 | // Update write barrier for the elements array address. |
| 429 | __ mov(edx, value); // Preserve the value which is returned. |
| 430 | __ RecordWriteArray(ebx, edx, key, kDontSaveFPRegs, EMIT_REMEMBERED_SET, |
| 431 | OMIT_SMI_CHECK); |
| 432 | __ ret(0); |
| 433 | |
| 434 | __ bind(fast_double); |
| 435 | if (check_map == kCheckMap) { |
| 436 | // Check for fast double array case. If this fails, call through to the |
| 437 | // runtime. |
| 438 | __ cmp(edi, masm->isolate()->factory()->fixed_double_array_map()); |
| 439 | __ j(not_equal, slow); |
| 440 | // If the value is a number, store it as a double in the FastDoubleElements |
| 441 | // array. |
| 442 | } |
| 443 | |
| 444 | // HOLECHECK: guards "A[i] double hole?" |
| 445 | // We have to see if the double version of the hole is present. If so |
| 446 | // go to the runtime. |
| 447 | uint32_t offset = FixedDoubleArray::kHeaderSize + sizeof(kHoleNanLower32); |
| 448 | __ cmp(FieldOperand(ebx, key, times_4, offset), Immediate(kHoleNanUpper32)); |
| 449 | __ j(not_equal, &fast_double_without_map_check); |
| 450 | __ JumpIfDictionaryInPrototypeChain(receiver, ebx, edi, slow); |
| 451 | __ mov(ebx, FieldOperand(receiver, JSObject::kElementsOffset)); |
| 452 | |
| 453 | __ bind(&fast_double_without_map_check); |
| 454 | __ StoreNumberToDoubleElements(value, ebx, key, edi, |
| 455 | &transition_double_elements, false); |
| 456 | if (increment_length == kIncrementLength) { |
| 457 | // Add 1 to receiver->length. |
| 458 | __ add(FieldOperand(receiver, JSArray::kLengthOffset), |
| 459 | Immediate(Smi::FromInt(1))); |
| 460 | } |
| 461 | __ ret(0); |
| 462 | |
| 463 | __ bind(&transition_smi_elements); |
| 464 | __ mov(ebx, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 465 | |
| 466 | // Transition the array appropriately depending on the value type. |
| 467 | __ CheckMap(value, masm->isolate()->factory()->heap_number_map(), |
| 468 | &non_double_value, DONT_DO_SMI_CHECK); |
| 469 | |
| 470 | // Value is a double. Transition FAST_SMI_ELEMENTS -> FAST_DOUBLE_ELEMENTS |
| 471 | // and complete the store. |
| 472 | __ LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS, |
| 473 | FAST_DOUBLE_ELEMENTS, ebx, edi, slow); |
| 474 | AllocationSiteMode mode = |
| 475 | AllocationSite::GetMode(FAST_SMI_ELEMENTS, FAST_DOUBLE_ELEMENTS); |
| 476 | ElementsTransitionGenerator::GenerateSmiToDouble(masm, receiver, key, value, |
| 477 | ebx, mode, slow); |
| 478 | __ mov(ebx, FieldOperand(receiver, JSObject::kElementsOffset)); |
| 479 | __ jmp(&fast_double_without_map_check); |
| 480 | |
| 481 | __ bind(&non_double_value); |
| 482 | // Value is not a double, FAST_SMI_ELEMENTS -> FAST_ELEMENTS |
| 483 | __ LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS, FAST_ELEMENTS, ebx, |
| 484 | edi, slow); |
| 485 | mode = AllocationSite::GetMode(FAST_SMI_ELEMENTS, FAST_ELEMENTS); |
| 486 | ElementsTransitionGenerator::GenerateMapChangeElementsTransition( |
| 487 | masm, receiver, key, value, ebx, mode, slow); |
| 488 | __ mov(ebx, FieldOperand(receiver, JSObject::kElementsOffset)); |
| 489 | __ jmp(&finish_object_store); |
| 490 | |
| 491 | __ bind(&transition_double_elements); |
| 492 | // Elements are FAST_DOUBLE_ELEMENTS, but value is an Object that's not a |
| 493 | // HeapNumber. Make sure that the receiver is a Array with FAST_ELEMENTS and |
| 494 | // transition array from FAST_DOUBLE_ELEMENTS to FAST_ELEMENTS |
| 495 | __ mov(ebx, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 496 | __ LoadTransitionedArrayMapConditional(FAST_DOUBLE_ELEMENTS, FAST_ELEMENTS, |
| 497 | ebx, edi, slow); |
| 498 | mode = AllocationSite::GetMode(FAST_DOUBLE_ELEMENTS, FAST_ELEMENTS); |
| 499 | ElementsTransitionGenerator::GenerateDoubleToObject(masm, receiver, key, |
| 500 | value, ebx, mode, slow); |
| 501 | __ mov(ebx, FieldOperand(receiver, JSObject::kElementsOffset)); |
| 502 | __ jmp(&finish_object_store); |
| 503 | } |
| 504 | |
| 505 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 506 | void KeyedStoreIC::GenerateMegamorphic(MacroAssembler* masm, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 507 | LanguageMode language_mode) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 508 | // Return address is on the stack. |
| 509 | Label slow, fast_object, fast_object_grow; |
| 510 | Label fast_double, fast_double_grow; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 511 | Label array, extra, check_if_double_array, maybe_name_key, miss; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 512 | Register receiver = StoreDescriptor::ReceiverRegister(); |
| 513 | Register key = StoreDescriptor::NameRegister(); |
| 514 | DCHECK(receiver.is(edx)); |
| 515 | DCHECK(key.is(ecx)); |
| 516 | |
| 517 | // Check that the object isn't a smi. |
| 518 | __ JumpIfSmi(receiver, &slow); |
| 519 | // Get the map from the receiver. |
| 520 | __ mov(edi, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 521 | // Check that the receiver does not require access checks and is not observed. |
| 522 | // The generic stub does not perform map checks or handle observed objects. |
| 523 | __ test_b(FieldOperand(edi, Map::kBitFieldOffset), |
| 524 | 1 << Map::kIsAccessCheckNeeded | 1 << Map::kIsObserved); |
| 525 | __ j(not_zero, &slow); |
| 526 | // Check that the key is a smi. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 527 | __ JumpIfNotSmi(key, &maybe_name_key); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 528 | __ CmpInstanceType(edi, JS_ARRAY_TYPE); |
| 529 | __ j(equal, &array); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 530 | // Check that the object is some kind of JS object EXCEPT JS Value type. In |
| 531 | // the case that the object is a value-wrapper object, we enter the runtime |
| 532 | // system to make sure that indexing into string objects works as intended. |
| 533 | STATIC_ASSERT(JS_VALUE_TYPE < JS_OBJECT_TYPE); |
| 534 | __ CmpInstanceType(edi, JS_OBJECT_TYPE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 535 | __ j(below, &slow); |
| 536 | |
| 537 | // Object case: Check key against length in the elements array. |
| 538 | // Key is a smi. |
| 539 | // edi: receiver map |
| 540 | __ mov(ebx, FieldOperand(receiver, JSObject::kElementsOffset)); |
| 541 | // Check array bounds. Both the key and the length of FixedArray are smis. |
| 542 | __ cmp(key, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 543 | __ j(below, &fast_object); |
| 544 | |
| 545 | // Slow case: call runtime. |
| 546 | __ bind(&slow); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 547 | PropertyICCompiler::GenerateRuntimeSetProperty(masm, language_mode); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 548 | // Never returns to here. |
| 549 | |
| 550 | __ bind(&maybe_name_key); |
| 551 | __ mov(ebx, FieldOperand(key, HeapObject::kMapOffset)); |
| 552 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 553 | __ JumpIfNotUniqueNameInstanceType(ebx, &slow); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 554 | |
| 555 | |
| 556 | // The handlers in the stub cache expect a vector and slot. Since we won't |
| 557 | // change the IC from any downstream misses, a dummy vector can be used. |
| 558 | Handle<TypeFeedbackVector> dummy_vector = |
| 559 | TypeFeedbackVector::DummyVector(masm->isolate()); |
| 560 | int slot = dummy_vector->GetIndex( |
| 561 | FeedbackVectorSlot(TypeFeedbackVector::kDummyKeyedStoreICSlot)); |
| 562 | __ push(Immediate(Smi::FromInt(slot))); |
| 563 | __ push(Immediate(dummy_vector)); |
| 564 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 565 | Code::Flags flags = Code::RemoveTypeAndHolderFromFlags( |
| 566 | Code::ComputeHandlerFlags(Code::STORE_IC)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 567 | masm->isolate()->stub_cache()->GenerateProbe(masm, Code::STORE_IC, flags, |
| 568 | receiver, key, edi, no_reg); |
| 569 | |
| 570 | __ pop(VectorStoreICDescriptor::VectorRegister()); |
| 571 | __ pop(VectorStoreICDescriptor::SlotRegister()); |
| 572 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 573 | // Cache miss. |
| 574 | __ jmp(&miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 575 | |
| 576 | // Extra capacity case: Check if there is extra capacity to |
| 577 | // perform the store and update the length. Used for adding one |
| 578 | // element to the array by writing to array[array.length]. |
| 579 | __ bind(&extra); |
| 580 | // receiver is a JSArray. |
| 581 | // key is a smi. |
| 582 | // ebx: receiver->elements, a FixedArray |
| 583 | // edi: receiver map |
| 584 | // flags: compare (key, receiver.length()) |
| 585 | // do not leave holes in the array: |
| 586 | __ j(not_equal, &slow); |
| 587 | __ cmp(key, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 588 | __ j(above_equal, &slow); |
| 589 | __ mov(edi, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 590 | __ cmp(edi, masm->isolate()->factory()->fixed_array_map()); |
| 591 | __ j(not_equal, &check_if_double_array); |
| 592 | __ jmp(&fast_object_grow); |
| 593 | |
| 594 | __ bind(&check_if_double_array); |
| 595 | __ cmp(edi, masm->isolate()->factory()->fixed_double_array_map()); |
| 596 | __ j(not_equal, &slow); |
| 597 | __ jmp(&fast_double_grow); |
| 598 | |
| 599 | // Array case: Get the length and the elements array from the JS |
| 600 | // array. Check that the array is in fast mode (and writable); if it |
| 601 | // is the length is always a smi. |
| 602 | __ bind(&array); |
| 603 | // receiver is a JSArray. |
| 604 | // key is a smi. |
| 605 | // edi: receiver map |
| 606 | __ mov(ebx, FieldOperand(receiver, JSObject::kElementsOffset)); |
| 607 | |
| 608 | // Check the key against the length in the array and fall through to the |
| 609 | // common store code. |
| 610 | __ cmp(key, FieldOperand(receiver, JSArray::kLengthOffset)); // Compare smis. |
| 611 | __ j(above_equal, &extra); |
| 612 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 613 | KeyedStoreGenerateMegamorphicHelper(masm, &fast_object, &fast_double, &slow, |
| 614 | kCheckMap, kDontIncrementLength); |
| 615 | KeyedStoreGenerateMegamorphicHelper(masm, &fast_object_grow, |
| 616 | &fast_double_grow, &slow, kDontCheckMap, |
| 617 | kIncrementLength); |
| 618 | |
| 619 | __ bind(&miss); |
| 620 | GenerateMiss(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 623 | void LoadIC::GenerateNormal(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 624 | Register dictionary = eax; |
| 625 | DCHECK(!dictionary.is(LoadDescriptor::ReceiverRegister())); |
| 626 | DCHECK(!dictionary.is(LoadDescriptor::NameRegister())); |
| 627 | |
| 628 | Label slow; |
| 629 | |
| 630 | __ mov(dictionary, FieldOperand(LoadDescriptor::ReceiverRegister(), |
| 631 | JSObject::kPropertiesOffset)); |
| 632 | GenerateDictionaryLoad(masm, &slow, dictionary, |
| 633 | LoadDescriptor::NameRegister(), edi, ebx, eax); |
| 634 | __ ret(0); |
| 635 | |
| 636 | // Dictionary load failed, go slow (but don't miss). |
| 637 | __ bind(&slow); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 638 | GenerateRuntimeGetProperty(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | |
| 642 | static void LoadIC_PushArgs(MacroAssembler* masm) { |
| 643 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 644 | Register name = LoadDescriptor::NameRegister(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 645 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 646 | Register slot = LoadDescriptor::SlotRegister(); |
| 647 | Register vector = LoadWithVectorDescriptor::VectorRegister(); |
| 648 | DCHECK(!edi.is(receiver) && !edi.is(name) && !edi.is(slot) && |
| 649 | !edi.is(vector)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 650 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 651 | __ pop(edi); |
| 652 | __ push(receiver); |
| 653 | __ push(name); |
| 654 | __ push(slot); |
| 655 | __ push(vector); |
| 656 | __ push(edi); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | |
| 660 | void LoadIC::GenerateMiss(MacroAssembler* masm) { |
| 661 | // Return address is on the stack. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 662 | __ IncrementCounter(masm->isolate()->counters()->ic_load_miss(), 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 663 | LoadIC_PushArgs(masm); |
| 664 | |
| 665 | // Perform tail call to the entry. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 666 | __ TailCallRuntime(Runtime::kLoadIC_Miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 669 | void LoadIC::GenerateRuntimeGetProperty(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 670 | // Return address is on the stack. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 671 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 672 | Register name = LoadDescriptor::NameRegister(); |
| 673 | DCHECK(!ebx.is(receiver) && !ebx.is(name)); |
| 674 | |
| 675 | __ pop(ebx); |
| 676 | __ push(receiver); |
| 677 | __ push(name); |
| 678 | __ push(ebx); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 679 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 680 | // Do tail-call to runtime routine. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 681 | __ TailCallRuntime(Runtime::kGetProperty); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | |
| 685 | void KeyedLoadIC::GenerateMiss(MacroAssembler* masm) { |
| 686 | // Return address is on the stack. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 687 | __ IncrementCounter(masm->isolate()->counters()->ic_keyed_load_miss(), 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 688 | |
| 689 | LoadIC_PushArgs(masm); |
| 690 | |
| 691 | // Perform tail call to the entry. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 692 | __ TailCallRuntime(Runtime::kKeyedLoadIC_Miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 693 | } |
| 694 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 695 | void KeyedLoadIC::GenerateRuntimeGetProperty(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 696 | // Return address is on the stack. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 697 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 698 | Register name = LoadDescriptor::NameRegister(); |
| 699 | DCHECK(!ebx.is(receiver) && !ebx.is(name)); |
| 700 | |
| 701 | __ pop(ebx); |
| 702 | __ push(receiver); |
| 703 | __ push(name); |
| 704 | __ push(ebx); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 705 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 706 | // Do tail-call to runtime routine. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 707 | __ TailCallRuntime(Runtime::kKeyedGetProperty); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | |
| 711 | void StoreIC::GenerateMegamorphic(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 712 | // This shouldn't be called. |
| 713 | // TODO(mvstanton): remove this method. |
| 714 | __ int3(); |
| 715 | return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | |
| 719 | static void StoreIC_PushArgs(MacroAssembler* masm) { |
| 720 | Register receiver = StoreDescriptor::ReceiverRegister(); |
| 721 | Register name = StoreDescriptor::NameRegister(); |
| 722 | Register value = StoreDescriptor::ValueRegister(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 723 | Register slot = VectorStoreICDescriptor::SlotRegister(); |
| 724 | Register vector = VectorStoreICDescriptor::VectorRegister(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 725 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 726 | __ xchg(receiver, Operand(esp, 0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 727 | __ push(name); |
| 728 | __ push(value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 729 | __ push(slot); |
| 730 | __ push(vector); |
| 731 | __ push(receiver); // Contains the return address. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | |
| 735 | void StoreIC::GenerateMiss(MacroAssembler* masm) { |
| 736 | // Return address is on the stack. |
| 737 | StoreIC_PushArgs(masm); |
| 738 | |
| 739 | // Perform tail call to the entry. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 740 | __ TailCallRuntime(Runtime::kStoreIC_Miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | |
| 744 | void StoreIC::GenerateNormal(MacroAssembler* masm) { |
| 745 | Label restore_miss; |
| 746 | Register receiver = StoreDescriptor::ReceiverRegister(); |
| 747 | Register name = StoreDescriptor::NameRegister(); |
| 748 | Register value = StoreDescriptor::ValueRegister(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 749 | Register vector = VectorStoreICDescriptor::VectorRegister(); |
| 750 | Register slot = VectorStoreICDescriptor::SlotRegister(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 751 | |
| 752 | // A lot of registers are needed for storing to slow case |
| 753 | // objects. Push and restore receiver but rely on |
| 754 | // GenerateDictionaryStore preserving the value and name. |
| 755 | __ push(receiver); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 756 | __ push(vector); |
| 757 | __ push(slot); |
| 758 | |
| 759 | Register dictionary = ebx; |
| 760 | __ mov(dictionary, FieldOperand(receiver, JSObject::kPropertiesOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 761 | GenerateDictionaryStore(masm, &restore_miss, dictionary, name, value, |
| 762 | receiver, edi); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 763 | __ Drop(3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 764 | Counters* counters = masm->isolate()->counters(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 765 | __ IncrementCounter(counters->ic_store_normal_hit(), 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 766 | __ ret(0); |
| 767 | |
| 768 | __ bind(&restore_miss); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 769 | __ pop(slot); |
| 770 | __ pop(vector); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 771 | __ pop(receiver); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 772 | __ IncrementCounter(counters->ic_store_normal_miss(), 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 773 | GenerateMiss(masm); |
| 774 | } |
| 775 | |
| 776 | |
| 777 | void KeyedStoreIC::GenerateMiss(MacroAssembler* masm) { |
| 778 | // Return address is on the stack. |
| 779 | StoreIC_PushArgs(masm); |
| 780 | |
| 781 | // Do tail-call to runtime routine. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 782 | __ TailCallRuntime(Runtime::kKeyedStoreIC_Miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | |
| 786 | #undef __ |
| 787 | |
| 788 | |
| 789 | Condition CompareIC::ComputeCondition(Token::Value op) { |
| 790 | switch (op) { |
| 791 | case Token::EQ_STRICT: |
| 792 | case Token::EQ: |
| 793 | return equal; |
| 794 | case Token::LT: |
| 795 | return less; |
| 796 | case Token::GT: |
| 797 | return greater; |
| 798 | case Token::LTE: |
| 799 | return less_equal; |
| 800 | case Token::GTE: |
| 801 | return greater_equal; |
| 802 | default: |
| 803 | UNREACHABLE(); |
| 804 | return no_condition; |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | |
| 809 | bool CompareIC::HasInlinedSmiCode(Address address) { |
| 810 | // The address of the instruction following the call. |
| 811 | Address test_instruction_address = |
| 812 | address + Assembler::kCallTargetAddressOffset; |
| 813 | |
| 814 | // If the instruction following the call is not a test al, nothing |
| 815 | // was inlined. |
| 816 | return *test_instruction_address == Assembler::kTestAlByte; |
| 817 | } |
| 818 | |
| 819 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 820 | void PatchInlinedSmiCode(Isolate* isolate, Address address, |
| 821 | InlinedSmiCheck check) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 822 | // The address of the instruction following the call. |
| 823 | Address test_instruction_address = |
| 824 | address + Assembler::kCallTargetAddressOffset; |
| 825 | |
| 826 | // If the instruction following the call is not a test al, nothing |
| 827 | // was inlined. |
| 828 | if (*test_instruction_address != Assembler::kTestAlByte) { |
| 829 | DCHECK(*test_instruction_address == Assembler::kNopByte); |
| 830 | return; |
| 831 | } |
| 832 | |
| 833 | Address delta_address = test_instruction_address + 1; |
| 834 | // The delta to the start of the map check instruction and the |
| 835 | // condition code uses at the patched jump. |
| 836 | uint8_t delta = *reinterpret_cast<uint8_t*>(delta_address); |
| 837 | if (FLAG_trace_ic) { |
| 838 | PrintF("[ patching ic at %p, test=%p, delta=%d\n", address, |
| 839 | test_instruction_address, delta); |
| 840 | } |
| 841 | |
| 842 | // Patch with a short conditional jump. Enabling means switching from a short |
| 843 | // jump-if-carry/not-carry to jump-if-zero/not-zero, whereas disabling is the |
| 844 | // reverse operation of that. |
| 845 | Address jmp_address = test_instruction_address - delta; |
| 846 | DCHECK((check == ENABLE_INLINED_SMI_CHECK) |
| 847 | ? (*jmp_address == Assembler::kJncShortOpcode || |
| 848 | *jmp_address == Assembler::kJcShortOpcode) |
| 849 | : (*jmp_address == Assembler::kJnzShortOpcode || |
| 850 | *jmp_address == Assembler::kJzShortOpcode)); |
| 851 | Condition cc = |
| 852 | (check == ENABLE_INLINED_SMI_CHECK) |
| 853 | ? (*jmp_address == Assembler::kJncShortOpcode ? not_zero : zero) |
| 854 | : (*jmp_address == Assembler::kJnzShortOpcode ? not_carry : carry); |
| 855 | *jmp_address = static_cast<byte>(Assembler::kJccShortPrefix | cc); |
| 856 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 857 | } // namespace internal |
| 858 | } // namespace v8 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 859 | |
| 860 | #endif // V8_TARGET_ARCH_X87 |