Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Side by Side Diff: src/ic/x64/stub-cache-x64.cc

Issue 483683005: Move IC code into a subdir and move ic-compilation related code from stub-cache into ic-compiler (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix BUILD.gn Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ic/x64/ic-x64.cc ('k') | src/isolate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include "src/v8.h"
6
7 #if V8_TARGET_ARCH_X64
8
9 #include "src/codegen.h"
10 #include "src/ic/stub-cache.h"
11
12 namespace v8 {
13 namespace internal {
14
15 #define __ ACCESS_MASM(masm)
16
17
18 static void ProbeTable(Isolate* isolate, MacroAssembler* masm,
19 Code::Flags flags, StubCache::Table table,
20 Register receiver, Register name,
21 // The offset is scaled by 4, based on
22 // kCacheIndexShift, which is two bits
23 Register offset) {
24 // We need to scale up the pointer by 2 when the offset is scaled by less
25 // than the pointer size.
26 DCHECK(kPointerSize == kInt64Size
27 ? kPointerSizeLog2 == StubCache::kCacheIndexShift + 1
28 : kPointerSizeLog2 == StubCache::kCacheIndexShift);
29 ScaleFactor scale_factor = kPointerSize == kInt64Size ? times_2 : times_1;
30
31 DCHECK_EQ(3 * kPointerSize, sizeof(StubCache::Entry));
32 // The offset register holds the entry offset times four (due to masking
33 // and shifting optimizations).
34 ExternalReference key_offset(isolate->stub_cache()->key_reference(table));
35 ExternalReference value_offset(isolate->stub_cache()->value_reference(table));
36 Label miss;
37
38 // Multiply by 3 because there are 3 fields per entry (name, code, map).
39 __ leap(offset, Operand(offset, offset, times_2, 0));
40
41 __ LoadAddress(kScratchRegister, key_offset);
42
43 // Check that the key in the entry matches the name.
44 // Multiply entry offset by 16 to get the entry address. Since the
45 // offset register already holds the entry offset times four, multiply
46 // by a further four.
47 __ cmpl(name, Operand(kScratchRegister, offset, scale_factor, 0));
48 __ j(not_equal, &miss);
49
50 // Get the map entry from the cache.
51 // Use key_offset + kPointerSize * 2, rather than loading map_offset.
52 __ movp(kScratchRegister,
53 Operand(kScratchRegister, offset, scale_factor, kPointerSize * 2));
54 __ cmpp(kScratchRegister, FieldOperand(receiver, HeapObject::kMapOffset));
55 __ j(not_equal, &miss);
56
57 // Get the code entry from the cache.
58 __ LoadAddress(kScratchRegister, value_offset);
59 __ movp(kScratchRegister, Operand(kScratchRegister, offset, scale_factor, 0));
60
61 // Check that the flags match what we're looking for.
62 __ movl(offset, FieldOperand(kScratchRegister, Code::kFlagsOffset));
63 __ andp(offset, Immediate(~Code::kFlagsNotUsedInLookup));
64 __ cmpl(offset, Immediate(flags));
65 __ j(not_equal, &miss);
66
67 #ifdef DEBUG
68 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) {
69 __ jmp(&miss);
70 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) {
71 __ jmp(&miss);
72 }
73 #endif
74
75 // Jump to the first instruction in the code stub.
76 __ addp(kScratchRegister, Immediate(Code::kHeaderSize - kHeapObjectTag));
77 __ jmp(kScratchRegister);
78
79 __ bind(&miss);
80 }
81
82
83 void StubCache::GenerateProbe(MacroAssembler* masm, Code::Flags flags,
84 Register receiver, Register name,
85 Register scratch, Register extra, Register extra2,
86 Register extra3) {
87 Isolate* isolate = masm->isolate();
88 Label miss;
89 USE(extra); // The register extra is not used on the X64 platform.
90 USE(extra2); // The register extra2 is not used on the X64 platform.
91 USE(extra3); // The register extra2 is not used on the X64 platform.
92 // Make sure that code is valid. The multiplying code relies on the
93 // entry size being 3 * kPointerSize.
94 DCHECK(sizeof(Entry) == 3 * kPointerSize);
95
96 // Make sure the flags do not name a specific type.
97 DCHECK(Code::ExtractTypeFromFlags(flags) == 0);
98
99 // Make sure that there are no register conflicts.
100 DCHECK(!scratch.is(receiver));
101 DCHECK(!scratch.is(name));
102
103 // Check scratch register is valid, extra and extra2 are unused.
104 DCHECK(!scratch.is(no_reg));
105 DCHECK(extra2.is(no_reg));
106 DCHECK(extra3.is(no_reg));
107
108 Counters* counters = masm->isolate()->counters();
109 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1);
110
111 // Check that the receiver isn't a smi.
112 __ JumpIfSmi(receiver, &miss);
113
114 // Get the map of the receiver and compute the hash.
115 __ movl(scratch, FieldOperand(name, Name::kHashFieldOffset));
116 // Use only the low 32 bits of the map pointer.
117 __ addl(scratch, FieldOperand(receiver, HeapObject::kMapOffset));
118 __ xorp(scratch, Immediate(flags));
119 // We mask out the last two bits because they are not part of the hash and
120 // they are always 01 for maps. Also in the two 'and' instructions below.
121 __ andp(scratch, Immediate((kPrimaryTableSize - 1) << kCacheIndexShift));
122
123 // Probe the primary table.
124 ProbeTable(isolate, masm, flags, kPrimary, receiver, name, scratch);
125
126 // Primary miss: Compute hash for secondary probe.
127 __ movl(scratch, FieldOperand(name, Name::kHashFieldOffset));
128 __ addl(scratch, FieldOperand(receiver, HeapObject::kMapOffset));
129 __ xorp(scratch, Immediate(flags));
130 __ andp(scratch, Immediate((kPrimaryTableSize - 1) << kCacheIndexShift));
131 __ subl(scratch, name);
132 __ addl(scratch, Immediate(flags));
133 __ andp(scratch, Immediate((kSecondaryTableSize - 1) << kCacheIndexShift));
134
135 // Probe the secondary table.
136 ProbeTable(isolate, masm, flags, kSecondary, receiver, name, scratch);
137
138 // Cache miss: Fall-through and let caller handle the miss by
139 // entering the runtime system.
140 __ bind(&miss);
141 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1);
142 }
143
144
145 #undef __
146 }
147 } // namespace v8::internal
148
149 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/ic/x64/ic-x64.cc ('k') | src/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698