OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 #if V8_TARGET_ARCH_S390 | |
6 | |
7 #include "src/ic/stub-cache.h" | |
8 #include "src/codegen.h" | |
9 #include "src/ic/ic.h" | |
10 #include "src/interface-descriptors.h" | |
11 | |
12 namespace v8 { | |
13 namespace internal { | |
14 | |
15 #define __ ACCESS_MASM(masm) | |
16 | |
17 static void ProbeTable(StubCache* stub_cache, MacroAssembler* masm, | |
18 StubCache::Table table, Register receiver, Register name, | |
19 // The offset is scaled by 4, based on | |
20 // kCacheIndexShift, which is two bits | |
21 Register offset, Register scratch, Register scratch2, | |
22 Register offset_scratch) { | |
23 ExternalReference key_offset(stub_cache->key_reference(table)); | |
24 ExternalReference value_offset(stub_cache->value_reference(table)); | |
25 ExternalReference map_offset(stub_cache->map_reference(table)); | |
26 | |
27 uintptr_t key_off_addr = reinterpret_cast<uintptr_t>(key_offset.address()); | |
28 uintptr_t value_off_addr = | |
29 reinterpret_cast<uintptr_t>(value_offset.address()); | |
30 uintptr_t map_off_addr = reinterpret_cast<uintptr_t>(map_offset.address()); | |
31 | |
32 // Check the relative positions of the address fields. | |
33 DCHECK(value_off_addr > key_off_addr); | |
34 DCHECK((value_off_addr - key_off_addr) % 4 == 0); | |
35 DCHECK((value_off_addr - key_off_addr) < (256 * 4)); | |
36 DCHECK(map_off_addr > key_off_addr); | |
37 DCHECK((map_off_addr - key_off_addr) % 4 == 0); | |
38 DCHECK((map_off_addr - key_off_addr) < (256 * 4)); | |
39 | |
40 Label miss; | |
41 Register base_addr = scratch; | |
42 scratch = no_reg; | |
43 | |
44 // Multiply by 3 because there are 3 fields per entry (name, code, map). | |
45 __ ShiftLeftP(offset_scratch, offset, Operand(1)); | |
46 __ AddP(offset_scratch, offset, offset_scratch); | |
47 | |
48 // Calculate the base address of the entry. | |
49 __ mov(base_addr, Operand(key_offset)); | |
50 #if V8_TARGET_ARCH_S390X | |
51 DCHECK(kPointerSizeLog2 > StubCache::kCacheIndexShift); | |
52 __ ShiftLeftP(offset_scratch, offset_scratch, | |
53 Operand(kPointerSizeLog2 - StubCache::kCacheIndexShift)); | |
54 #else | |
55 DCHECK(kPointerSizeLog2 == StubCache::kCacheIndexShift); | |
56 #endif | |
57 __ AddP(base_addr, base_addr, offset_scratch); | |
58 | |
59 // Check that the key in the entry matches the name. | |
60 __ CmpP(name, MemOperand(base_addr, 0)); | |
61 __ bne(&miss, Label::kNear); | |
62 | |
63 // Check the map matches. | |
64 __ LoadP(ip, MemOperand(base_addr, map_off_addr - key_off_addr)); | |
65 __ CmpP(ip, FieldMemOperand(receiver, HeapObject::kMapOffset)); | |
66 __ bne(&miss, Label::kNear); | |
67 | |
68 // Get the code entry from the cache. | |
69 Register code = scratch2; | |
70 scratch2 = no_reg; | |
71 __ LoadP(code, MemOperand(base_addr, value_off_addr - key_off_addr)); | |
72 | |
73 #ifdef DEBUG | |
74 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { | |
75 __ b(&miss, Label::kNear); | |
76 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { | |
77 __ b(&miss, Label::kNear); | |
78 } | |
79 #endif | |
80 | |
81 // Jump to the first instruction in the code stub. | |
82 // TODO(joransiu): Combine into indirect branch | |
83 __ la(code, MemOperand(code, Code::kHeaderSize - kHeapObjectTag)); | |
84 __ b(code); | |
85 | |
86 // Miss: fall through. | |
87 __ bind(&miss); | |
88 } | |
89 | |
90 void StubCache::GenerateProbe(MacroAssembler* masm, Register receiver, | |
91 Register name, Register scratch, Register extra, | |
92 Register extra2, Register extra3) { | |
93 Label miss; | |
94 | |
95 #if V8_TARGET_ARCH_S390X | |
96 // Make sure that code is valid. The multiplying code relies on the | |
97 // entry size being 24. | |
98 DCHECK(sizeof(Entry) == 24); | |
99 #else | |
100 // Make sure that code is valid. The multiplying code relies on the | |
101 // entry size being 12. | |
102 DCHECK(sizeof(Entry) == 12); | |
103 #endif | |
104 | |
105 // Make sure that there are no register conflicts. | |
106 DCHECK(!AreAliased(receiver, name, scratch, extra, extra2, extra3)); | |
107 | |
108 // Check scratch, extra and extra2 registers are valid. | |
109 DCHECK(!scratch.is(no_reg)); | |
110 DCHECK(!extra.is(no_reg)); | |
111 DCHECK(!extra2.is(no_reg)); | |
112 DCHECK(!extra3.is(no_reg)); | |
113 | |
114 #ifdef DEBUG | |
115 // If vector-based ics are in use, ensure that scratch, extra, extra2 and | |
116 // extra3 don't conflict with the vector and slot registers, which need | |
117 // to be preserved for a handler call or miss. | |
118 if (IC::ICUseVector(ic_kind_)) { | |
119 Register vector, slot; | |
120 if (ic_kind_ == Code::STORE_IC || ic_kind_ == Code::KEYED_STORE_IC) { | |
121 vector = StoreWithVectorDescriptor::VectorRegister(); | |
122 slot = StoreWithVectorDescriptor::SlotRegister(); | |
123 } else { | |
124 DCHECK(ic_kind_ == Code::LOAD_IC || ic_kind_ == Code::KEYED_LOAD_IC); | |
125 vector = LoadWithVectorDescriptor::VectorRegister(); | |
126 slot = LoadWithVectorDescriptor::SlotRegister(); | |
127 } | |
128 DCHECK(!AreAliased(vector, slot, scratch, extra, extra2, extra3)); | |
129 } | |
130 #endif | |
131 | |
132 Counters* counters = masm->isolate()->counters(); | |
133 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1, extra2, | |
134 extra3); | |
135 | |
136 // Check that the receiver isn't a smi. | |
137 __ JumpIfSmi(receiver, &miss); | |
138 | |
139 // Get the map of the receiver and compute the hash. | |
140 __ LoadlW(scratch, FieldMemOperand(name, Name::kHashFieldOffset)); | |
141 __ LoadP(ip, FieldMemOperand(receiver, HeapObject::kMapOffset)); | |
142 __ AddP(scratch, scratch, ip); | |
143 __ XorP(scratch, scratch, Operand(kPrimaryMagic)); | |
144 // The mask omits the last two bits because they are not part of the hash. | |
145 __ AndP(scratch, scratch, | |
146 Operand((kPrimaryTableSize - 1) << kCacheIndexShift)); | |
147 | |
148 // Probe the primary table. | |
149 ProbeTable(this, masm, kPrimary, receiver, name, scratch, extra, extra2, | |
150 extra3); | |
151 | |
152 // Primary miss: Compute hash for secondary probe. | |
153 __ SubP(scratch, scratch, name); | |
154 __ AddP(scratch, scratch, Operand(kSecondaryMagic)); | |
155 __ AndP(scratch, scratch, | |
156 Operand((kSecondaryTableSize - 1) << kCacheIndexShift)); | |
157 | |
158 // Probe the secondary table. | |
159 ProbeTable(this, masm, kSecondary, receiver, name, scratch, extra, extra2, | |
160 extra3); | |
161 | |
162 // Cache miss: Fall-through and let caller handle the miss by | |
163 // entering the runtime system. | |
164 __ bind(&miss); | |
165 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1, extra2, | |
166 extra3); | |
167 } | |
168 | |
169 #undef __ | |
170 } // namespace internal | |
171 } // namespace v8 | |
172 | |
173 #endif // V8_TARGET_ARCH_S390 | |
OLD | NEW |