OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if V8_TARGET_ARCH_MIPS | 5 #if V8_TARGET_ARCH_MIPS |
6 | 6 |
7 #include "src/codegen.h" | 7 #include "src/codegen.h" |
8 #include "src/ic/ic.h" | 8 #include "src/ic/ic.h" |
9 #include "src/ic/stub-cache.h" | 9 #include "src/ic/stub-cache.h" |
10 #include "src/interface-descriptors.h" | 10 #include "src/interface-descriptors.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 #define __ ACCESS_MASM(masm) | 15 #define __ ACCESS_MASM(masm) |
16 | 16 |
17 static void ProbeTable(StubCache* stub_cache, MacroAssembler* masm, | 17 static void ProbeTable(StubCache* stub_cache, MacroAssembler* masm, |
18 Code::Flags flags, StubCache::Table table, | 18 StubCache::Table table, Register receiver, Register name, |
19 Register receiver, Register name, | |
20 // Number of the cache entry, not scaled. | 19 // Number of the cache entry, not scaled. |
21 Register offset, Register scratch, Register scratch2, | 20 Register offset, Register scratch, Register scratch2, |
22 Register offset_scratch) { | 21 Register offset_scratch) { |
23 ExternalReference key_offset(stub_cache->key_reference(table)); | 22 ExternalReference key_offset(stub_cache->key_reference(table)); |
24 ExternalReference value_offset(stub_cache->value_reference(table)); | 23 ExternalReference value_offset(stub_cache->value_reference(table)); |
25 ExternalReference map_offset(stub_cache->map_reference(table)); | 24 ExternalReference map_offset(stub_cache->map_reference(table)); |
26 | 25 |
27 uint32_t key_off_addr = reinterpret_cast<uint32_t>(key_offset.address()); | 26 uint32_t key_off_addr = reinterpret_cast<uint32_t>(key_offset.address()); |
28 uint32_t value_off_addr = reinterpret_cast<uint32_t>(value_offset.address()); | 27 uint32_t value_off_addr = reinterpret_cast<uint32_t>(value_offset.address()); |
29 uint32_t map_off_addr = reinterpret_cast<uint32_t>(map_offset.address()); | 28 uint32_t map_off_addr = reinterpret_cast<uint32_t>(map_offset.address()); |
30 | 29 |
31 // Check the relative positions of the address fields. | 30 // Check the relative positions of the address fields. |
32 DCHECK(value_off_addr > key_off_addr); | 31 DCHECK(value_off_addr > key_off_addr); |
33 DCHECK((value_off_addr - key_off_addr) % 4 == 0); | 32 DCHECK((value_off_addr - key_off_addr) % 4 == 0); |
34 DCHECK((value_off_addr - key_off_addr) < (256 * 4)); | 33 DCHECK((value_off_addr - key_off_addr) < (256 * 4)); |
35 DCHECK(map_off_addr > key_off_addr); | 34 DCHECK(map_off_addr > key_off_addr); |
36 DCHECK((map_off_addr - key_off_addr) % 4 == 0); | 35 DCHECK((map_off_addr - key_off_addr) % 4 == 0); |
37 DCHECK((map_off_addr - key_off_addr) < (256 * 4)); | 36 DCHECK((map_off_addr - key_off_addr) < (256 * 4)); |
38 | 37 |
39 Label miss; | 38 Label miss; |
40 Register base_addr = scratch; | 39 Register base_addr = scratch; |
41 scratch = no_reg; | 40 scratch = no_reg; |
42 | 41 |
43 // Multiply by 3 because there are 3 fields per entry (name, code, map). | 42 // Multiply by 3 because there are 3 fields per entry (name, code, map). |
44 __ Lsa(offset_scratch, offset, offset, 1); | 43 __ Lsa(offset_scratch, offset, offset, 1); |
45 | 44 |
46 // Calculate the base address of the entry. | 45 // Calculate the base address of the entry. |
47 __ li(base_addr, Operand(key_offset)); | 46 __ li(base_addr, Operand(key_offset)); |
48 __ Lsa(base_addr, base_addr, offset_scratch, kPointerSizeLog2); | 47 __ Addu(base_addr, base_addr, offset_scratch); |
49 | 48 |
50 // Check that the key in the entry matches the name. | 49 // Check that the key in the entry matches the name. |
51 __ lw(at, MemOperand(base_addr, 0)); | 50 __ lw(at, MemOperand(base_addr, 0)); |
52 __ Branch(&miss, ne, name, Operand(at)); | 51 __ Branch(&miss, ne, name, Operand(at)); |
53 | 52 |
54 // Check the map matches. | 53 // Check the map matches. |
55 __ lw(at, MemOperand(base_addr, map_off_addr - key_off_addr)); | 54 __ lw(at, MemOperand(base_addr, map_off_addr - key_off_addr)); |
56 __ lw(scratch2, FieldMemOperand(receiver, HeapObject::kMapOffset)); | 55 __ lw(scratch2, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
57 __ Branch(&miss, ne, at, Operand(scratch2)); | 56 __ Branch(&miss, ne, at, Operand(scratch2)); |
58 | 57 |
59 // Get the code entry from the cache. | 58 // Get the code entry from the cache. |
60 Register code = scratch2; | 59 Register code = scratch2; |
61 scratch2 = no_reg; | 60 scratch2 = no_reg; |
62 __ lw(code, MemOperand(base_addr, value_off_addr - key_off_addr)); | 61 __ lw(code, MemOperand(base_addr, value_off_addr - key_off_addr)); |
63 | 62 |
| 63 #ifdef DEBUG |
64 // Check that the flags match what we're looking for. | 64 // Check that the flags match what we're looking for. |
| 65 Code::Flags flags = Code::RemoveHolderFromFlags( |
| 66 Code::ComputeHandlerFlags(stub_cache->ic_kind())); |
65 Register flags_reg = base_addr; | 67 Register flags_reg = base_addr; |
66 base_addr = no_reg; | 68 base_addr = no_reg; |
67 __ lw(flags_reg, FieldMemOperand(code, Code::kFlagsOffset)); | 69 __ lw(flags_reg, FieldMemOperand(code, Code::kFlagsOffset)); |
68 __ And(flags_reg, flags_reg, Operand(~Code::kFlagsNotUsedInLookup)); | 70 __ And(flags_reg, flags_reg, Operand(~Code::kFlagsNotUsedInLookup)); |
69 __ Branch(&miss, ne, flags_reg, Operand(flags)); | 71 __ Check(eq, kUnexpectedValue, flags_reg, Operand(flags)); |
70 | 72 |
71 #ifdef DEBUG | |
72 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { | 73 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { |
73 __ jmp(&miss); | 74 __ jmp(&miss); |
74 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { | 75 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { |
75 __ jmp(&miss); | 76 __ jmp(&miss); |
76 } | 77 } |
77 #endif | 78 #endif |
78 | 79 |
79 // Jump to the first instruction in the code stub. | 80 // Jump to the first instruction in the code stub. |
80 __ Addu(at, code, Operand(Code::kHeaderSize - kHeapObjectTag)); | 81 __ Addu(at, code, Operand(Code::kHeaderSize - kHeapObjectTag)); |
81 __ Jump(at); | 82 __ Jump(at); |
82 | 83 |
83 // Miss: fall through. | 84 // Miss: fall through. |
84 __ bind(&miss); | 85 __ bind(&miss); |
85 } | 86 } |
86 | 87 |
87 void StubCache::GenerateProbe(MacroAssembler* masm, Register receiver, | 88 void StubCache::GenerateProbe(MacroAssembler* masm, Register receiver, |
88 Register name, Register scratch, Register extra, | 89 Register name, Register scratch, Register extra, |
89 Register extra2, Register extra3) { | 90 Register extra2, Register extra3) { |
90 Code::Flags flags = | |
91 Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(ic_kind_)); | |
92 | |
93 Label miss; | 91 Label miss; |
94 | 92 |
95 // Make sure that code is valid. The multiplying code relies on the | 93 // Make sure that code is valid. The multiplying code relies on the |
96 // entry size being 12. | 94 // entry size being 12. |
97 DCHECK(sizeof(Entry) == 12); | 95 DCHECK(sizeof(Entry) == 12); |
98 | 96 |
99 // Make sure that there are no register conflicts. | 97 // Make sure that there are no register conflicts. |
100 DCHECK(!AreAliased(receiver, name, scratch, extra, extra2, extra3)); | 98 DCHECK(!AreAliased(receiver, name, scratch, extra, extra2, extra3)); |
101 | 99 |
102 // Check register validity. | 100 // Check register validity. |
(...skipping 21 matching lines...) Expand all Loading... |
124 #endif | 122 #endif |
125 | 123 |
126 Counters* counters = masm->isolate()->counters(); | 124 Counters* counters = masm->isolate()->counters(); |
127 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1, extra2, | 125 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1, extra2, |
128 extra3); | 126 extra3); |
129 | 127 |
130 // Check that the receiver isn't a smi. | 128 // Check that the receiver isn't a smi. |
131 __ JumpIfSmi(receiver, &miss); | 129 __ JumpIfSmi(receiver, &miss); |
132 | 130 |
133 // Get the map of the receiver and compute the hash. | 131 // Get the map of the receiver and compute the hash. |
134 __ lw(scratch, FieldMemOperand(name, Name::kHashFieldOffset)); | 132 __ lwu(scratch, FieldMemOperand(name, Name::kHashFieldOffset)); |
135 __ lw(at, FieldMemOperand(receiver, HeapObject::kMapOffset)); | 133 __ lw(at, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
136 __ Addu(scratch, scratch, at); | 134 __ Addu(scratch, scratch, at); |
137 uint32_t mask = kPrimaryTableSize - 1; | 135 __ li(at, Operand(kPrimaryTableSize - 1)); |
138 // We shift out the last two bits because they are not part of the hash and | 136 __ sll(at, at, kCacheIndexShift); |
139 // they are always 01 for maps. | 137 __ And(scratch, scratch, at); |
140 __ srl(scratch, scratch, kCacheIndexShift); | |
141 __ Xor(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask)); | |
142 __ And(scratch, scratch, Operand(mask)); | |
143 | 138 |
144 // Probe the primary table. | 139 // Probe the primary table. |
145 ProbeTable(this, masm, flags, kPrimary, receiver, name, scratch, extra, | 140 ProbeTable(this, masm, kPrimary, receiver, name, scratch, extra, extra2, |
146 extra2, extra3); | 141 extra3); |
147 | 142 |
148 // Primary miss: Compute hash for secondary probe. | 143 // Primary miss: Compute hash for secondary probe. |
149 __ srl(at, name, kCacheIndexShift); | 144 __ Subu(scratch, scratch, name); |
150 __ Subu(scratch, scratch, at); | 145 __ Addu(scratch, scratch, Operand(kSecondaryMagic)); |
151 uint32_t mask2 = kSecondaryTableSize - 1; | 146 __ li(at, Operand(kSecondaryTableSize - 1)); |
152 __ Addu(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask2)); | 147 __ sll(at, at, kCacheIndexShift); |
153 __ And(scratch, scratch, Operand(mask2)); | 148 __ And(scratch, scratch, at); |
154 | 149 |
155 // Probe the secondary table. | 150 // Probe the secondary table. |
156 ProbeTable(this, masm, flags, kSecondary, receiver, name, scratch, extra, | 151 ProbeTable(this, masm, kSecondary, receiver, name, scratch, extra, extra2, |
157 extra2, extra3); | 152 extra3); |
158 | 153 |
159 // Cache miss: Fall-through and let caller handle the miss by | 154 // Cache miss: Fall-through and let caller handle the miss by |
160 // entering the runtime system. | 155 // entering the runtime system. |
161 __ bind(&miss); | 156 __ bind(&miss); |
162 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1, extra2, | 157 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1, extra2, |
163 extra3); | 158 extra3); |
164 } | 159 } |
165 | 160 |
166 | 161 |
167 #undef __ | 162 #undef __ |
168 } // namespace internal | 163 } // namespace internal |
169 } // namespace v8 | 164 } // namespace v8 |
170 | 165 |
171 #endif // V8_TARGET_ARCH_MIPS | 166 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |