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 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #if V8_TARGET_ARCH_ARM | 7 #if V8_TARGET_ARCH_MIPS64 |
8 | 8 |
9 #include "src/codegen.h" | 9 #include "src/codegen.h" |
10 #include "src/ic/stub-cache.h" | 10 #include "src/ic/stub-cache.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 | 17 |
18 static void ProbeTable(Isolate* isolate, MacroAssembler* masm, | 18 static void ProbeTable(Isolate* isolate, MacroAssembler* masm, |
19 Code::Flags flags, StubCache::Table table, | 19 Code::Flags flags, StubCache::Table table, |
20 Register receiver, Register name, | 20 Register receiver, Register name, |
21 // Number of the cache entry, not scaled. | 21 // Number of the cache entry, not scaled. |
22 Register offset, Register scratch, Register scratch2, | 22 Register offset, Register scratch, Register scratch2, |
23 Register offset_scratch) { | 23 Register offset_scratch) { |
24 ExternalReference key_offset(isolate->stub_cache()->key_reference(table)); | 24 ExternalReference key_offset(isolate->stub_cache()->key_reference(table)); |
25 ExternalReference value_offset(isolate->stub_cache()->value_reference(table)); | 25 ExternalReference value_offset(isolate->stub_cache()->value_reference(table)); |
26 ExternalReference map_offset(isolate->stub_cache()->map_reference(table)); | 26 ExternalReference map_offset(isolate->stub_cache()->map_reference(table)); |
27 | 27 |
28 uint32_t key_off_addr = reinterpret_cast<uint32_t>(key_offset.address()); | 28 uint64_t key_off_addr = reinterpret_cast<uint64_t>(key_offset.address()); |
29 uint32_t value_off_addr = reinterpret_cast<uint32_t>(value_offset.address()); | 29 uint64_t value_off_addr = reinterpret_cast<uint64_t>(value_offset.address()); |
30 uint32_t map_off_addr = reinterpret_cast<uint32_t>(map_offset.address()); | 30 uint64_t map_off_addr = reinterpret_cast<uint64_t>(map_offset.address()); |
31 | 31 |
32 // Check the relative positions of the address fields. | 32 // Check the relative positions of the address fields. |
33 DCHECK(value_off_addr > key_off_addr); | 33 DCHECK(value_off_addr > key_off_addr); |
34 DCHECK((value_off_addr - key_off_addr) % 4 == 0); | 34 DCHECK((value_off_addr - key_off_addr) % 4 == 0); |
35 DCHECK((value_off_addr - key_off_addr) < (256 * 4)); | 35 DCHECK((value_off_addr - key_off_addr) < (256 * 4)); |
36 DCHECK(map_off_addr > key_off_addr); | 36 DCHECK(map_off_addr > key_off_addr); |
37 DCHECK((map_off_addr - key_off_addr) % 4 == 0); | 37 DCHECK((map_off_addr - key_off_addr) % 4 == 0); |
38 DCHECK((map_off_addr - key_off_addr) < (256 * 4)); | 38 DCHECK((map_off_addr - key_off_addr) < (256 * 4)); |
39 | 39 |
40 Label miss; | 40 Label miss; |
41 Register base_addr = scratch; | 41 Register base_addr = scratch; |
42 scratch = no_reg; | 42 scratch = no_reg; |
43 | 43 |
44 // Multiply by 3 because there are 3 fields per entry (name, code, map). | 44 // Multiply by 3 because there are 3 fields per entry (name, code, map). |
45 __ add(offset_scratch, offset, Operand(offset, LSL, 1)); | 45 __ dsll(offset_scratch, offset, 1); |
| 46 __ Daddu(offset_scratch, offset_scratch, offset); |
46 | 47 |
47 // Calculate the base address of the entry. | 48 // Calculate the base address of the entry. |
48 __ mov(base_addr, Operand(key_offset)); | 49 __ li(base_addr, Operand(key_offset)); |
49 __ add(base_addr, base_addr, Operand(offset_scratch, LSL, kPointerSizeLog2)); | 50 __ dsll(at, offset_scratch, kPointerSizeLog2); |
| 51 __ Daddu(base_addr, base_addr, at); |
50 | 52 |
51 // Check that the key in the entry matches the name. | 53 // Check that the key in the entry matches the name. |
52 __ ldr(ip, MemOperand(base_addr, 0)); | 54 __ ld(at, MemOperand(base_addr, 0)); |
53 __ cmp(name, ip); | 55 __ Branch(&miss, ne, name, Operand(at)); |
54 __ b(ne, &miss); | |
55 | 56 |
56 // Check the map matches. | 57 // Check the map matches. |
57 __ ldr(ip, MemOperand(base_addr, map_off_addr - key_off_addr)); | 58 __ ld(at, MemOperand(base_addr, map_off_addr - key_off_addr)); |
58 __ ldr(scratch2, FieldMemOperand(receiver, HeapObject::kMapOffset)); | 59 __ ld(scratch2, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
59 __ cmp(ip, scratch2); | 60 __ Branch(&miss, ne, at, Operand(scratch2)); |
60 __ b(ne, &miss); | |
61 | 61 |
62 // Get the code entry from the cache. | 62 // Get the code entry from the cache. |
63 Register code = scratch2; | 63 Register code = scratch2; |
64 scratch2 = no_reg; | 64 scratch2 = no_reg; |
65 __ ldr(code, MemOperand(base_addr, value_off_addr - key_off_addr)); | 65 __ ld(code, MemOperand(base_addr, value_off_addr - key_off_addr)); |
66 | 66 |
67 // Check that the flags match what we're looking for. | 67 // Check that the flags match what we're looking for. |
68 Register flags_reg = base_addr; | 68 Register flags_reg = base_addr; |
69 base_addr = no_reg; | 69 base_addr = no_reg; |
70 __ ldr(flags_reg, FieldMemOperand(code, Code::kFlagsOffset)); | 70 __ lw(flags_reg, FieldMemOperand(code, Code::kFlagsOffset)); |
71 // It's a nice optimization if this constant is encodable in the bic insn. | 71 __ And(flags_reg, flags_reg, Operand(~Code::kFlagsNotUsedInLookup)); |
72 | 72 __ Branch(&miss, ne, flags_reg, Operand(flags)); |
73 uint32_t mask = Code::kFlagsNotUsedInLookup; | |
74 DCHECK(__ ImmediateFitsAddrMode1Instruction(mask)); | |
75 __ bic(flags_reg, flags_reg, Operand(mask)); | |
76 __ cmp(flags_reg, Operand(flags)); | |
77 __ b(ne, &miss); | |
78 | 73 |
79 #ifdef DEBUG | 74 #ifdef DEBUG |
80 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { | 75 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { |
81 __ jmp(&miss); | 76 __ jmp(&miss); |
82 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { | 77 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { |
83 __ jmp(&miss); | 78 __ jmp(&miss); |
84 } | 79 } |
85 #endif | 80 #endif |
86 | 81 |
87 // Jump to the first instruction in the code stub. | 82 // Jump to the first instruction in the code stub. |
88 __ add(pc, code, Operand(Code::kHeaderSize - kHeapObjectTag)); | 83 __ Daddu(at, code, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 84 __ Jump(at); |
89 | 85 |
90 // Miss: fall through. | 86 // Miss: fall through. |
91 __ bind(&miss); | 87 __ bind(&miss); |
92 } | 88 } |
93 | 89 |
94 | 90 |
95 void StubCache::GenerateProbe(MacroAssembler* masm, Code::Flags flags, | 91 void StubCache::GenerateProbe(MacroAssembler* masm, Code::Flags flags, |
96 Register receiver, Register name, | 92 Register receiver, Register name, |
97 Register scratch, Register extra, Register extra2, | 93 Register scratch, Register extra, Register extra2, |
98 Register extra3) { | 94 Register extra3) { |
99 Isolate* isolate = masm->isolate(); | 95 Isolate* isolate = masm->isolate(); |
100 Label miss; | 96 Label miss; |
101 | 97 |
102 // Make sure that code is valid. The multiplying code relies on the | 98 // Make sure that code is valid. The multiplying code relies on the |
103 // entry size being 12. | 99 // entry size being 12. |
104 DCHECK(sizeof(Entry) == 12); | 100 // DCHECK(sizeof(Entry) == 12); |
| 101 // DCHECK(sizeof(Entry) == 3 * kPointerSize); |
105 | 102 |
106 // Make sure the flags does not name a specific type. | 103 // Make sure the flags does not name a specific type. |
107 DCHECK(Code::ExtractTypeFromFlags(flags) == 0); | 104 DCHECK(Code::ExtractTypeFromFlags(flags) == 0); |
108 | 105 |
109 // Make sure that there are no register conflicts. | 106 // Make sure that there are no register conflicts. |
110 DCHECK(!scratch.is(receiver)); | 107 DCHECK(!scratch.is(receiver)); |
111 DCHECK(!scratch.is(name)); | 108 DCHECK(!scratch.is(name)); |
112 DCHECK(!extra.is(receiver)); | 109 DCHECK(!extra.is(receiver)); |
113 DCHECK(!extra.is(name)); | 110 DCHECK(!extra.is(name)); |
114 DCHECK(!extra.is(scratch)); | 111 DCHECK(!extra.is(scratch)); |
115 DCHECK(!extra2.is(receiver)); | 112 DCHECK(!extra2.is(receiver)); |
116 DCHECK(!extra2.is(name)); | 113 DCHECK(!extra2.is(name)); |
117 DCHECK(!extra2.is(scratch)); | 114 DCHECK(!extra2.is(scratch)); |
118 DCHECK(!extra2.is(extra)); | 115 DCHECK(!extra2.is(extra)); |
119 | 116 |
120 // Check scratch, extra and extra2 registers are valid. | 117 // Check register validity. |
121 DCHECK(!scratch.is(no_reg)); | 118 DCHECK(!scratch.is(no_reg)); |
122 DCHECK(!extra.is(no_reg)); | 119 DCHECK(!extra.is(no_reg)); |
123 DCHECK(!extra2.is(no_reg)); | 120 DCHECK(!extra2.is(no_reg)); |
124 DCHECK(!extra3.is(no_reg)); | 121 DCHECK(!extra3.is(no_reg)); |
125 | 122 |
126 Counters* counters = masm->isolate()->counters(); | 123 Counters* counters = masm->isolate()->counters(); |
127 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1, extra2, | 124 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1, extra2, |
128 extra3); | 125 extra3); |
129 | 126 |
130 // Check that the receiver isn't a smi. | 127 // Check that the receiver isn't a smi. |
131 __ JumpIfSmi(receiver, &miss); | 128 __ JumpIfSmi(receiver, &miss); |
132 | 129 |
133 // Get the map of the receiver and compute the hash. | 130 // Get the map of the receiver and compute the hash. |
134 __ ldr(scratch, FieldMemOperand(name, Name::kHashFieldOffset)); | 131 __ ld(scratch, FieldMemOperand(name, Name::kHashFieldOffset)); |
135 __ ldr(ip, FieldMemOperand(receiver, HeapObject::kMapOffset)); | 132 __ ld(at, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
136 __ add(scratch, scratch, Operand(ip)); | 133 __ Daddu(scratch, scratch, at); |
137 uint32_t mask = kPrimaryTableSize - 1; | 134 uint64_t mask = kPrimaryTableSize - 1; |
138 // We shift out the last two bits because they are not part of the hash and | 135 // We shift out the last two bits because they are not part of the hash and |
139 // they are always 01 for maps. | 136 // they are always 01 for maps. |
140 __ mov(scratch, Operand(scratch, LSR, kCacheIndexShift)); | 137 __ dsrl(scratch, scratch, kCacheIndexShift); |
141 // Mask down the eor argument to the minimum to keep the immediate | 138 __ Xor(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask)); |
142 // ARM-encodable. | 139 __ And(scratch, scratch, Operand(mask)); |
143 __ eor(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask)); | |
144 // Prefer and_ to ubfx here because ubfx takes 2 cycles. | |
145 __ and_(scratch, scratch, Operand(mask)); | |
146 | 140 |
147 // Probe the primary table. | 141 // Probe the primary table. |
148 ProbeTable(isolate, masm, flags, kPrimary, receiver, name, scratch, extra, | 142 ProbeTable(isolate, masm, flags, kPrimary, receiver, name, scratch, extra, |
149 extra2, extra3); | 143 extra2, extra3); |
150 | 144 |
151 // Primary miss: Compute hash for secondary probe. | 145 // Primary miss: Compute hash for secondary probe. |
152 __ sub(scratch, scratch, Operand(name, LSR, kCacheIndexShift)); | 146 __ dsrl(at, name, kCacheIndexShift); |
153 uint32_t mask2 = kSecondaryTableSize - 1; | 147 __ Dsubu(scratch, scratch, at); |
154 __ add(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask2)); | 148 uint64_t mask2 = kSecondaryTableSize - 1; |
155 __ and_(scratch, scratch, Operand(mask2)); | 149 __ Daddu(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask2)); |
| 150 __ And(scratch, scratch, Operand(mask2)); |
156 | 151 |
157 // Probe the secondary table. | 152 // Probe the secondary table. |
158 ProbeTable(isolate, masm, flags, kSecondary, receiver, name, scratch, extra, | 153 ProbeTable(isolate, masm, flags, kSecondary, receiver, name, scratch, extra, |
159 extra2, extra3); | 154 extra2, extra3); |
160 | 155 |
161 // Cache miss: Fall-through and let caller handle the miss by | 156 // Cache miss: Fall-through and let caller handle the miss by |
162 // entering the runtime system. | 157 // entering the runtime system. |
163 __ bind(&miss); | 158 __ bind(&miss); |
164 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1, extra2, | 159 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1, extra2, |
165 extra3); | 160 extra3); |
166 } | 161 } |
167 | 162 |
168 | 163 |
169 #undef __ | 164 #undef __ |
170 } | 165 } |
171 } // namespace v8::internal | 166 } // namespace v8::internal |
172 | 167 |
173 #endif // V8_TARGET_ARCH_ARM | 168 #endif // V8_TARGET_ARCH_MIPS64 |
OLD | NEW |