2 * Copyright (c) 2004-2006 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "cpu/o3/store_set.hh"
31 #include "base/intmath.hh"
32 #include "base/logging.hh"
33 #include "base/trace.hh"
34 #include "debug/StoreSet.hh"
36 StoreSet::StoreSet(uint64_t clear_period
, int _SSIT_size
, int _LFST_size
)
37 : clearPeriod(clear_period
), SSITSize(_SSIT_size
), LFSTSize(_LFST_size
)
39 DPRINTF(StoreSet
, "StoreSet: Creating store set object.\n");
40 DPRINTF(StoreSet
, "StoreSet: SSIT size: %i, LFST size: %i.\n",
43 if (!isPowerOf2(SSITSize
)) {
44 fatal("Invalid SSIT size!\n");
47 SSIT
.resize(SSITSize
);
49 validSSIT
.resize(SSITSize
);
51 for (int i
= 0; i
< SSITSize
; ++i
)
54 if (!isPowerOf2(LFSTSize
)) {
55 fatal("Invalid LFST size!\n");
58 LFST
.resize(LFSTSize
);
60 validLFST
.resize(LFSTSize
);
62 for (int i
= 0; i
< LFSTSize
; ++i
) {
67 indexMask
= SSITSize
- 1;
79 StoreSet::init(uint64_t clear_period
, int _SSIT_size
, int _LFST_size
)
81 SSITSize
= _SSIT_size
;
82 LFSTSize
= _LFST_size
;
83 clearPeriod
= clear_period
;
85 DPRINTF(StoreSet
, "StoreSet: Creating store set object.\n");
86 DPRINTF(StoreSet
, "StoreSet: SSIT size: %i, LFST size: %i.\n",
89 SSIT
.resize(SSITSize
);
91 validSSIT
.resize(SSITSize
);
93 for (int i
= 0; i
< SSITSize
; ++i
)
96 LFST
.resize(LFSTSize
);
98 validLFST
.resize(LFSTSize
);
100 for (int i
= 0; i
< LFSTSize
; ++i
) {
101 validLFST
[i
] = false;
105 indexMask
= SSITSize
- 1;
114 StoreSet::violation(Addr store_PC
, Addr load_PC
)
116 int load_index
= calcIndex(load_PC
);
117 int store_index
= calcIndex(store_PC
);
119 assert(load_index
< SSITSize
&& store_index
< SSITSize
);
121 bool valid_load_SSID
= validSSIT
[load_index
];
122 bool valid_store_SSID
= validSSIT
[store_index
];
124 if (!valid_load_SSID
&& !valid_store_SSID
) {
125 // Calculate a new SSID here.
126 SSID new_set
= calcSSID(load_PC
);
128 validSSIT
[load_index
] = true;
130 SSIT
[load_index
] = new_set
;
132 validSSIT
[store_index
] = true;
134 SSIT
[store_index
] = new_set
;
136 assert(new_set
< LFSTSize
);
138 DPRINTF(StoreSet
, "StoreSet: Neither load nor store had a valid "
139 "storeset, creating a new one: %i for load %#x, store %#x\n",
140 new_set
, load_PC
, store_PC
);
141 } else if (valid_load_SSID
&& !valid_store_SSID
) {
142 SSID load_SSID
= SSIT
[load_index
];
144 validSSIT
[store_index
] = true;
146 SSIT
[store_index
] = load_SSID
;
148 assert(load_SSID
< LFSTSize
);
150 DPRINTF(StoreSet
, "StoreSet: Load had a valid store set. Adding "
151 "store to that set: %i for load %#x, store %#x\n",
152 load_SSID
, load_PC
, store_PC
);
153 } else if (!valid_load_SSID
&& valid_store_SSID
) {
154 SSID store_SSID
= SSIT
[store_index
];
156 validSSIT
[load_index
] = true;
158 SSIT
[load_index
] = store_SSID
;
160 DPRINTF(StoreSet
, "StoreSet: Store had a valid store set: %i for "
161 "load %#x, store %#x\n",
162 store_SSID
, load_PC
, store_PC
);
164 SSID load_SSID
= SSIT
[load_index
];
165 SSID store_SSID
= SSIT
[store_index
];
167 assert(load_SSID
< LFSTSize
&& store_SSID
< LFSTSize
);
169 // The store set with the lower number wins
170 if (store_SSID
> load_SSID
) {
171 SSIT
[store_index
] = load_SSID
;
173 DPRINTF(StoreSet
, "StoreSet: Load had smaller store set: %i; "
174 "for load %#x, store %#x\n",
175 load_SSID
, load_PC
, store_PC
);
177 SSIT
[load_index
] = store_SSID
;
179 DPRINTF(StoreSet
, "StoreSet: Store had smaller store set: %i; "
180 "for load %#x, store %#x\n",
181 store_SSID
, load_PC
, store_PC
);
187 StoreSet::checkClear()
190 if (memOpsPred
> clearPeriod
) {
191 DPRINTF(StoreSet
, "Wiping predictor state beacuse %d ld/st executed\n",
199 StoreSet::insertLoad(Addr load_PC
, InstSeqNum load_seq_num
)
207 StoreSet::insertStore(Addr store_PC
, InstSeqNum store_seq_num
, ThreadID tid
)
209 int index
= calcIndex(store_PC
);
214 assert(index
< SSITSize
);
216 if (!validSSIT
[index
]) {
217 // Do nothing if there's no valid entry.
220 store_SSID
= SSIT
[index
];
222 assert(store_SSID
< LFSTSize
);
224 // Update the last store that was fetched with the current one.
225 LFST
[store_SSID
] = store_seq_num
;
227 validLFST
[store_SSID
] = 1;
229 storeList
[store_seq_num
] = store_SSID
;
231 DPRINTF(StoreSet
, "Store %#x updated the LFST, SSID: %i\n",
232 store_PC
, store_SSID
);
237 StoreSet::checkInst(Addr PC
)
239 int index
= calcIndex(PC
);
243 assert(index
< SSITSize
);
245 if (!validSSIT
[index
]) {
246 DPRINTF(StoreSet
, "Inst %#x with index %i had no SSID\n",
249 // Return 0 if there's no valid entry.
252 inst_SSID
= SSIT
[index
];
254 assert(inst_SSID
< LFSTSize
);
256 if (!validLFST
[inst_SSID
]) {
258 DPRINTF(StoreSet
, "Inst %#x with index %i and SSID %i had no "
259 "dependency\n", PC
, index
, inst_SSID
);
263 DPRINTF(StoreSet
, "Inst %#x with index %i and SSID %i had LFST "
264 "inum of %i\n", PC
, index
, inst_SSID
, LFST
[inst_SSID
]);
266 return LFST
[inst_SSID
];
272 StoreSet::issued(Addr issued_PC
, InstSeqNum issued_seq_num
, bool is_store
)
274 // This only is updated upon a store being issued.
279 int index
= calcIndex(issued_PC
);
283 assert(index
< SSITSize
);
285 SeqNumMapIt store_list_it
= storeList
.find(issued_seq_num
);
287 if (store_list_it
!= storeList
.end()) {
288 storeList
.erase(store_list_it
);
291 // Make sure the SSIT still has a valid entry for the issued store.
292 if (!validSSIT
[index
]) {
296 store_SSID
= SSIT
[index
];
298 assert(store_SSID
< LFSTSize
);
300 // If the last fetched store in the store set refers to the store that
301 // was just issued, then invalidate the entry.
302 if (validLFST
[store_SSID
] && LFST
[store_SSID
] == issued_seq_num
) {
303 DPRINTF(StoreSet
, "StoreSet: store invalidated itself in LFST.\n");
304 validLFST
[store_SSID
] = false;
309 StoreSet::squash(InstSeqNum squashed_num
, ThreadID tid
)
311 DPRINTF(StoreSet
, "StoreSet: Squashing until inum %i\n",
315 SeqNumMapIt store_list_it
= storeList
.begin();
317 //@todo:Fix to only delete from correct thread
318 while (!storeList
.empty()) {
319 idx
= (*store_list_it
).second
;
321 if ((*store_list_it
).first
<= squashed_num
) {
325 bool younger
= LFST
[idx
] > squashed_num
;
327 if (validLFST
[idx
] && younger
) {
328 DPRINTF(StoreSet
, "Squashed [sn:%lli]\n", LFST
[idx
]);
329 validLFST
[idx
] = false;
331 storeList
.erase(store_list_it
++);
332 } else if (!validLFST
[idx
] && younger
) {
333 storeList
.erase(store_list_it
++);
341 for (int i
= 0; i
< SSITSize
; ++i
) {
342 validSSIT
[i
] = false;
345 for (int i
= 0; i
< LFSTSize
; ++i
) {
346 validLFST
[i
] = false;
355 cprintf("storeList.size(): %i\n", storeList
.size());
356 SeqNumMapIt store_list_it
= storeList
.begin();
360 while (store_list_it
!= storeList
.end()) {
361 cprintf("%i: [sn:%lli] SSID:%i\n",
362 num
, (*store_list_it
).first
, (*store_list_it
).second
);