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 | |
| 5 | #include "src/v8.h" |
| 6 | |
| 7 | #if V8_TARGET_ARCH_MIPS |
| 8 | |
| 9 | #include "src/codegen.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 10 | #include "src/ic/ic.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #include "src/ic/stub-cache.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 12 | #include "src/interface-descriptors.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 13 | |
| 14 | namespace v8 { |
| 15 | namespace internal { |
| 16 | |
| 17 | #define __ ACCESS_MASM(masm) |
| 18 | |
| 19 | |
| 20 | static void ProbeTable(Isolate* isolate, MacroAssembler* masm, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 21 | Code::Kind ic_kind, Code::Flags flags, bool leave_frame, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 22 | StubCache::Table table, Register receiver, Register name, |
| 23 | // Number of the cache entry, not scaled. |
| 24 | Register offset, Register scratch, Register scratch2, |
| 25 | Register offset_scratch) { |
| 26 | ExternalReference key_offset(isolate->stub_cache()->key_reference(table)); |
| 27 | ExternalReference value_offset(isolate->stub_cache()->value_reference(table)); |
| 28 | ExternalReference map_offset(isolate->stub_cache()->map_reference(table)); |
| 29 | |
| 30 | uint32_t key_off_addr = reinterpret_cast<uint32_t>(key_offset.address()); |
| 31 | uint32_t value_off_addr = reinterpret_cast<uint32_t>(value_offset.address()); |
| 32 | uint32_t map_off_addr = reinterpret_cast<uint32_t>(map_offset.address()); |
| 33 | |
| 34 | // Check the relative positions of the address fields. |
| 35 | DCHECK(value_off_addr > key_off_addr); |
| 36 | DCHECK((value_off_addr - key_off_addr) % 4 == 0); |
| 37 | DCHECK((value_off_addr - key_off_addr) < (256 * 4)); |
| 38 | DCHECK(map_off_addr > key_off_addr); |
| 39 | DCHECK((map_off_addr - key_off_addr) % 4 == 0); |
| 40 | DCHECK((map_off_addr - key_off_addr) < (256 * 4)); |
| 41 | |
| 42 | Label miss; |
| 43 | Register base_addr = scratch; |
| 44 | scratch = no_reg; |
| 45 | |
| 46 | // Multiply by 3 because there are 3 fields per entry (name, code, map). |
| 47 | __ sll(offset_scratch, offset, 1); |
| 48 | __ Addu(offset_scratch, offset_scratch, offset); |
| 49 | |
| 50 | // Calculate the base address of the entry. |
| 51 | __ li(base_addr, Operand(key_offset)); |
| 52 | __ sll(at, offset_scratch, kPointerSizeLog2); |
| 53 | __ Addu(base_addr, base_addr, at); |
| 54 | |
| 55 | // Check that the key in the entry matches the name. |
| 56 | __ lw(at, MemOperand(base_addr, 0)); |
| 57 | __ Branch(&miss, ne, name, Operand(at)); |
| 58 | |
| 59 | // Check the map matches. |
| 60 | __ lw(at, MemOperand(base_addr, map_off_addr - key_off_addr)); |
| 61 | __ lw(scratch2, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 62 | __ Branch(&miss, ne, at, Operand(scratch2)); |
| 63 | |
| 64 | // Get the code entry from the cache. |
| 65 | Register code = scratch2; |
| 66 | scratch2 = no_reg; |
| 67 | __ lw(code, MemOperand(base_addr, value_off_addr - key_off_addr)); |
| 68 | |
| 69 | // Check that the flags match what we're looking for. |
| 70 | Register flags_reg = base_addr; |
| 71 | base_addr = no_reg; |
| 72 | __ lw(flags_reg, FieldMemOperand(code, Code::kFlagsOffset)); |
| 73 | __ And(flags_reg, flags_reg, Operand(~Code::kFlagsNotUsedInLookup)); |
| 74 | __ Branch(&miss, ne, flags_reg, Operand(flags)); |
| 75 | |
| 76 | #ifdef DEBUG |
| 77 | if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { |
| 78 | __ jmp(&miss); |
| 79 | } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { |
| 80 | __ jmp(&miss); |
| 81 | } |
| 82 | #endif |
| 83 | |
| 84 | if (leave_frame) __ LeaveFrame(StackFrame::INTERNAL); |
| 85 | |
| 86 | // Jump to the first instruction in the code stub. |
| 87 | __ Addu(at, code, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 88 | __ Jump(at); |
| 89 | |
| 90 | // Miss: fall through. |
| 91 | __ bind(&miss); |
| 92 | } |
| 93 | |
| 94 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 95 | void StubCache::GenerateProbe(MacroAssembler* masm, Code::Kind ic_kind, |
| 96 | Code::Flags flags, bool leave_frame, |
| 97 | Register receiver, Register name, |
| 98 | Register scratch, Register extra, Register extra2, |
| 99 | Register extra3) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 100 | Isolate* isolate = masm->isolate(); |
| 101 | Label miss; |
| 102 | |
| 103 | // Make sure that code is valid. The multiplying code relies on the |
| 104 | // entry size being 12. |
| 105 | DCHECK(sizeof(Entry) == 12); |
| 106 | |
| 107 | // Make sure the flags does not name a specific type. |
| 108 | DCHECK(Code::ExtractTypeFromFlags(flags) == 0); |
| 109 | |
| 110 | // Make sure that there are no register conflicts. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 111 | DCHECK(!AreAliased(receiver, name, scratch, extra, extra2, extra3)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 112 | |
| 113 | // Check register validity. |
| 114 | DCHECK(!scratch.is(no_reg)); |
| 115 | DCHECK(!extra.is(no_reg)); |
| 116 | DCHECK(!extra2.is(no_reg)); |
| 117 | DCHECK(!extra3.is(no_reg)); |
| 118 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 119 | #ifdef DEBUG |
| 120 | // If vector-based ics are in use, ensure that scratch, extra, extra2 and |
| 121 | // extra3 don't conflict with the vector and slot registers, which need |
| 122 | // to be preserved for a handler call or miss. |
| 123 | if (IC::ICUseVector(ic_kind)) { |
| 124 | Register vector = VectorLoadICDescriptor::VectorRegister(); |
| 125 | Register slot = VectorLoadICDescriptor::SlotRegister(); |
| 126 | DCHECK(!AreAliased(vector, slot, scratch, extra, extra2, extra3)); |
| 127 | } |
| 128 | #endif |
| 129 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 130 | Counters* counters = masm->isolate()->counters(); |
| 131 | __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1, extra2, |
| 132 | extra3); |
| 133 | |
| 134 | // Check that the receiver isn't a smi. |
| 135 | __ JumpIfSmi(receiver, &miss); |
| 136 | |
| 137 | // Get the map of the receiver and compute the hash. |
| 138 | __ lw(scratch, FieldMemOperand(name, Name::kHashFieldOffset)); |
| 139 | __ lw(at, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 140 | __ Addu(scratch, scratch, at); |
| 141 | uint32_t mask = kPrimaryTableSize - 1; |
| 142 | // We shift out the last two bits because they are not part of the hash and |
| 143 | // they are always 01 for maps. |
| 144 | __ srl(scratch, scratch, kCacheIndexShift); |
| 145 | __ Xor(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask)); |
| 146 | __ And(scratch, scratch, Operand(mask)); |
| 147 | |
| 148 | // Probe the primary table. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 149 | ProbeTable(isolate, masm, ic_kind, flags, leave_frame, kPrimary, receiver, |
| 150 | name, scratch, extra, extra2, extra3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 151 | |
| 152 | // Primary miss: Compute hash for secondary probe. |
| 153 | __ srl(at, name, kCacheIndexShift); |
| 154 | __ Subu(scratch, scratch, at); |
| 155 | uint32_t mask2 = kSecondaryTableSize - 1; |
| 156 | __ Addu(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask2)); |
| 157 | __ And(scratch, scratch, Operand(mask2)); |
| 158 | |
| 159 | // Probe the secondary table. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 160 | ProbeTable(isolate, masm, ic_kind, flags, leave_frame, kSecondary, receiver, |
| 161 | name, scratch, extra, extra2, extra3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 162 | |
| 163 | // Cache miss: Fall-through and let caller handle the miss by |
| 164 | // entering the runtime system. |
| 165 | __ bind(&miss); |
| 166 | __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1, extra2, |
| 167 | extra3); |
| 168 | } |
| 169 | |
| 170 | |
| 171 | #undef __ |
| 172 | } |
| 173 | } // namespace v8::internal |
| 174 | |
| 175 | #endif // V8_TARGET_ARCH_MIPS |