• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #if V8_TARGET_ARCH_MIPS64
6 
7 #include "src/codegen.h"
8 #include "src/ic/ic.h"
9 #include "src/ic/stub-cache.h"
10 #include "src/interface-descriptors.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 #define __ ACCESS_MASM(masm)
16 
17 
ProbeTable(Isolate * isolate,MacroAssembler * masm,Code::Kind ic_kind,Code::Flags flags,StubCache::Table table,Register receiver,Register name,Register offset,Register scratch,Register scratch2,Register offset_scratch)18 static void ProbeTable(Isolate* isolate, MacroAssembler* masm,
19                        Code::Kind ic_kind, Code::Flags flags,
20                        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).
45   __ dsll(offset_scratch, offset, 1);
46   __ Daddu(offset_scratch, offset_scratch, offset);
47 
48   // Calculate the base address of the entry.
49   __ li(base_addr, Operand(key_offset));
50   __ dsll(at, offset_scratch, kPointerSizeLog2);
51   __ Daddu(base_addr, base_addr, at);
52 
53   // Check that the key in the entry matches the name.
54   __ ld(at, MemOperand(base_addr, 0));
55   __ Branch(&miss, ne, name, Operand(at));
56 
57   // Check the map matches.
58   __ ld(at, MemOperand(base_addr,
59                        static_cast<int32_t>(map_off_addr - key_off_addr)));
60   __ ld(scratch2, FieldMemOperand(receiver, HeapObject::kMapOffset));
61   __ Branch(&miss, ne, at, Operand(scratch2));
62 
63   // Get the code entry from the cache.
64   Register code = scratch2;
65   scratch2 = no_reg;
66   __ ld(code, MemOperand(base_addr,
67                          static_cast<int32_t>(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   // Jump to the first instruction in the code stub.
85   __ Daddu(at, code, Operand(Code::kHeaderSize - kHeapObjectTag));
86   __ Jump(at);
87 
88   // Miss: fall through.
89   __ bind(&miss);
90 }
91 
92 
GenerateProbe(MacroAssembler * masm,Code::Kind ic_kind,Code::Flags flags,Register receiver,Register name,Register scratch,Register extra,Register extra2,Register extra3)93 void StubCache::GenerateProbe(MacroAssembler* masm, Code::Kind ic_kind,
94                               Code::Flags flags, Register receiver,
95                               Register name, Register scratch, Register extra,
96                               Register extra2, Register extra3) {
97   Isolate* isolate = masm->isolate();
98   Label miss;
99 
100   // Make sure that code is valid. The multiplying code relies on the
101   // entry size being 12.
102   // DCHECK(sizeof(Entry) == 12);
103   // DCHECK(sizeof(Entry) == 3 * kPointerSize);
104 
105   // Make sure the flags does not name a specific type.
106   DCHECK(Code::ExtractTypeFromFlags(flags) == 0);
107 
108   // Make sure that there are no register conflicts.
109   DCHECK(!AreAliased(receiver, name, scratch, extra, extra2, extra3));
110 
111   // Check register validity.
112   DCHECK(!scratch.is(no_reg));
113   DCHECK(!extra.is(no_reg));
114   DCHECK(!extra2.is(no_reg));
115   DCHECK(!extra3.is(no_reg));
116 
117 #ifdef DEBUG
118   // If vector-based ics are in use, ensure that scratch, extra, extra2 and
119   // extra3 don't conflict with the vector and slot registers, which need
120   // to be preserved for a handler call or miss.
121   if (IC::ICUseVector(ic_kind)) {
122     Register vector, slot;
123     if (ic_kind == Code::STORE_IC || ic_kind == Code::KEYED_STORE_IC) {
124       vector = VectorStoreICDescriptor::VectorRegister();
125       slot = VectorStoreICDescriptor::SlotRegister();
126     } else {
127       vector = LoadWithVectorDescriptor::VectorRegister();
128       slot = LoadWithVectorDescriptor::SlotRegister();
129     }
130     DCHECK(!AreAliased(vector, slot, scratch, extra, extra2, extra3));
131   }
132 #endif
133 
134   Counters* counters = masm->isolate()->counters();
135   __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1, extra2,
136                       extra3);
137 
138   // Check that the receiver isn't a smi.
139   __ JumpIfSmi(receiver, &miss);
140 
141   // Get the map of the receiver and compute the hash.
142   __ ld(scratch, FieldMemOperand(name, Name::kHashFieldOffset));
143   __ ld(at, FieldMemOperand(receiver, HeapObject::kMapOffset));
144   __ Daddu(scratch, scratch, at);
145   uint64_t mask = kPrimaryTableSize - 1;
146   // We shift out the last two bits because they are not part of the hash and
147   // they are always 01 for maps.
148   __ dsrl(scratch, scratch, kCacheIndexShift);
149   __ Xor(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask));
150   __ And(scratch, scratch, Operand(mask));
151 
152   // Probe the primary table.
153   ProbeTable(isolate, masm, ic_kind, flags, kPrimary, receiver, name, scratch,
154              extra, extra2, extra3);
155 
156   // Primary miss: Compute hash for secondary probe.
157   __ dsrl(at, name, kCacheIndexShift);
158   __ Dsubu(scratch, scratch, at);
159   uint64_t mask2 = kSecondaryTableSize - 1;
160   __ Daddu(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask2));
161   __ And(scratch, scratch, Operand(mask2));
162 
163   // Probe the secondary table.
164   ProbeTable(isolate, masm, ic_kind, flags, kSecondary, receiver, name, scratch,
165              extra, extra2, extra3);
166 
167   // Cache miss: Fall-through and let caller handle the miss by
168   // entering the runtime system.
169   __ bind(&miss);
170   __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1, extra2,
171                       extra3);
172 }
173 
174 
175 #undef __
176 }  // namespace internal
177 }  // namespace v8
178 
179 #endif  // V8_TARGET_ARCH_MIPS64
180