blob: 0bd7dd0f2d42fc746b41339635e82351d9605305 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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 Murdochb8a8cc12014-11-26 15:28:44 +00005#if V8_TARGET_ARCH_MIPS64
6
7#include "src/codegen.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008#include "src/ic/ic.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/ic/stub-cache.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040010#include "src/interface-descriptors.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011
12namespace v8 {
13namespace internal {
14
15#define __ ACCESS_MASM(masm)
16
17
18static void ProbeTable(Isolate* isolate, MacroAssembler* masm,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000019 Code::Kind ic_kind, Code::Flags flags,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000020 StubCache::Table table, Register receiver, Register name,
21 // Number of the cache entry, not scaled.
22 Register offset, Register scratch, Register scratch2,
23 Register offset_scratch) {
24 ExternalReference key_offset(isolate->stub_cache()->key_reference(table));
25 ExternalReference value_offset(isolate->stub_cache()->value_reference(table));
26 ExternalReference map_offset(isolate->stub_cache()->map_reference(table));
27
28 uint64_t key_off_addr = reinterpret_cast<uint64_t>(key_offset.address());
29 uint64_t value_off_addr = reinterpret_cast<uint64_t>(value_offset.address());
30 uint64_t map_off_addr = reinterpret_cast<uint64_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).
Ben Murdoch097c5b22016-05-18 11:27:45 +010045 __ Dlsa(offset_scratch, offset, offset, 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000046
47 // Calculate the base address of the entry.
48 __ li(base_addr, Operand(key_offset));
Ben Murdoch097c5b22016-05-18 11:27:45 +010049 __ Dlsa(base_addr, base_addr, offset_scratch, kPointerSizeLog2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000050
51 // Check that the key in the entry matches the name.
52 __ ld(at, MemOperand(base_addr, 0));
53 __ Branch(&miss, ne, name, Operand(at));
54
55 // Check the map matches.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000056 __ ld(at, MemOperand(base_addr,
57 static_cast<int32_t>(map_off_addr - key_off_addr)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000058 __ ld(scratch2, FieldMemOperand(receiver, HeapObject::kMapOffset));
59 __ Branch(&miss, ne, at, Operand(scratch2));
60
61 // Get the code entry from the cache.
62 Register code = scratch2;
63 scratch2 = no_reg;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000064 __ ld(code, MemOperand(base_addr,
65 static_cast<int32_t>(value_off_addr - key_off_addr)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000066
67 // Check that the flags match what we're looking for.
68 Register flags_reg = base_addr;
69 base_addr = no_reg;
70 __ lw(flags_reg, FieldMemOperand(code, Code::kFlagsOffset));
71 __ And(flags_reg, flags_reg, Operand(~Code::kFlagsNotUsedInLookup));
72 __ Branch(&miss, ne, flags_reg, Operand(flags));
73
74#ifdef DEBUG
75 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) {
76 __ jmp(&miss);
77 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) {
78 __ jmp(&miss);
79 }
80#endif
81
Ben Murdochb8a8cc12014-11-26 15:28:44 +000082 // Jump to the first instruction in the code stub.
83 __ Daddu(at, code, Operand(Code::kHeaderSize - kHeapObjectTag));
84 __ Jump(at);
85
86 // Miss: fall through.
87 __ bind(&miss);
88}
89
90
Emily Bernierd0a1eb72015-03-24 16:35:39 -040091void StubCache::GenerateProbe(MacroAssembler* masm, Code::Kind ic_kind,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000092 Code::Flags flags, Register receiver,
93 Register name, Register scratch, Register extra,
94 Register extra2, Register extra3) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000095 Isolate* isolate = masm->isolate();
96 Label miss;
97
98 // Make sure that code is valid. The multiplying code relies on the
99 // entry size being 12.
100 // DCHECK(sizeof(Entry) == 12);
101 // DCHECK(sizeof(Entry) == 3 * kPointerSize);
102
103 // Make sure the flags does not name a specific type.
104 DCHECK(Code::ExtractTypeFromFlags(flags) == 0);
105
106 // Make sure that there are no register conflicts.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400107 DCHECK(!AreAliased(receiver, name, scratch, extra, extra2, extra3));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000108
109 // Check register validity.
110 DCHECK(!scratch.is(no_reg));
111 DCHECK(!extra.is(no_reg));
112 DCHECK(!extra2.is(no_reg));
113 DCHECK(!extra3.is(no_reg));
114
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400115#ifdef DEBUG
116 // If vector-based ics are in use, ensure that scratch, extra, extra2 and
117 // extra3 don't conflict with the vector and slot registers, which need
118 // to be preserved for a handler call or miss.
119 if (IC::ICUseVector(ic_kind)) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000120 Register vector, slot;
121 if (ic_kind == Code::STORE_IC || ic_kind == Code::KEYED_STORE_IC) {
122 vector = VectorStoreICDescriptor::VectorRegister();
123 slot = VectorStoreICDescriptor::SlotRegister();
124 } else {
125 vector = LoadWithVectorDescriptor::VectorRegister();
126 slot = LoadWithVectorDescriptor::SlotRegister();
127 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400128 DCHECK(!AreAliased(vector, slot, scratch, extra, extra2, extra3));
129 }
130#endif
131
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000132 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 __ ld(scratch, FieldMemOperand(name, Name::kHashFieldOffset));
141 __ ld(at, FieldMemOperand(receiver, HeapObject::kMapOffset));
142 __ Daddu(scratch, scratch, at);
143 uint64_t mask = kPrimaryTableSize - 1;
144 // We shift out the last two bits because they are not part of the hash and
145 // they are always 01 for maps.
146 __ dsrl(scratch, scratch, kCacheIndexShift);
147 __ Xor(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask));
148 __ And(scratch, scratch, Operand(mask));
149
150 // Probe the primary table.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000151 ProbeTable(isolate, masm, ic_kind, flags, kPrimary, receiver, name, scratch,
152 extra, extra2, extra3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000153
154 // Primary miss: Compute hash for secondary probe.
155 __ dsrl(at, name, kCacheIndexShift);
156 __ Dsubu(scratch, scratch, at);
157 uint64_t mask2 = kSecondaryTableSize - 1;
158 __ Daddu(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask2));
159 __ And(scratch, scratch, Operand(mask2));
160
161 // Probe the secondary table.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000162 ProbeTable(isolate, masm, ic_kind, flags, kSecondary, receiver, name, scratch,
163 extra, extra2, extra3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000164
165 // Cache miss: Fall-through and let caller handle the miss by
166 // entering the runtime system.
167 __ bind(&miss);
168 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1, extra2,
169 extra3);
170}
171
172
173#undef __
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000174} // namespace internal
175} // namespace v8
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000176
177#endif // V8_TARGET_ARCH_MIPS64