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.
31 #include "base/intmath.hh"
32 #include "base/misc.hh"
33 #include "base/trace.hh"
34 #include "cpu/o3/store_set.hh"
35 #include "debug/StoreSet.hh"
37 StoreSet::StoreSet(uint64_t clear_period
, int _SSIT_size
, int _LFST_size
)
38 : clearPeriod(clear_period
), SSITSize(_SSIT_size
), LFSTSize(_LFST_size
)
40 DPRINTF(StoreSet
, "StoreSet: Creating store set object.\n");
41 DPRINTF(StoreSet
, "StoreSet: SSIT size: %i, LFST size: %i.\n",
44 if (!isPowerOf2(SSITSize
)) {
45 fatal("Invalid SSIT size!\n");
48 SSIT
.resize(SSITSize
);
50 validSSIT
.resize(SSITSize
);
52 for (int i
= 0; i
< SSITSize
; ++i
)
55 if (!isPowerOf2(LFSTSize
)) {
56 fatal("Invalid LFST size!\n");
59 LFST
.resize(LFSTSize
);
61 validLFST
.resize(LFSTSize
);
63 for (int i
= 0; i
< LFSTSize
; ++i
) {
68 indexMask
= SSITSize
- 1;
80 StoreSet::init(uint64_t clear_period
, int _SSIT_size
, int _LFST_size
)
82 SSITSize
= _SSIT_size
;
83 LFSTSize
= _LFST_size
;
84 clearPeriod
= clear_period
;
86 DPRINTF(StoreSet
, "StoreSet: Creating store set object.\n");
87 DPRINTF(StoreSet
, "StoreSet: SSIT size: %i, LFST size: %i.\n",
90 SSIT
.resize(SSITSize
);
92 validSSIT
.resize(SSITSize
);
94 for (int i
= 0; i
< SSITSize
; ++i
)
97 LFST
.resize(LFSTSize
);
99 validLFST
.resize(LFSTSize
);
101 for (int i
= 0; i
< LFSTSize
; ++i
) {
102 validLFST
[i
] = false;
106 indexMask
= SSITSize
- 1;
115 StoreSet::violation(Addr store_PC
, Addr load_PC
)
117 int load_index
= calcIndex(load_PC
);
118 int store_index
= calcIndex(store_PC
);
120 assert(load_index
< SSITSize
&& store_index
< SSITSize
);
122 bool valid_load_SSID
= validSSIT
[load_index
];
123 bool valid_store_SSID
= validSSIT
[store_index
];
125 if (!valid_load_SSID
&& !valid_store_SSID
) {
126 // Calculate a new SSID here.
127 SSID new_set
= calcSSID(load_PC
);
129 validSSIT
[load_index
] = true;
131 SSIT
[load_index
] = new_set
;
133 validSSIT
[store_index
] = true;
135 SSIT
[store_index
] = new_set
;
137 assert(new_set
< LFSTSize
);
139 DPRINTF(StoreSet
, "StoreSet: Neither load nor store had a valid "
140 "storeset, creating a new one: %i for load %#x, store %#x\n",
141 new_set
, load_PC
, store_PC
);
142 } else if (valid_load_SSID
&& !valid_store_SSID
) {
143 SSID load_SSID
= SSIT
[load_index
];
145 validSSIT
[store_index
] = true;
147 SSIT
[store_index
] = load_SSID
;
149 assert(load_SSID
< LFSTSize
);
151 DPRINTF(StoreSet
, "StoreSet: Load had a valid store set. Adding "
152 "store to that set: %i for load %#x, store %#x\n",
153 load_SSID
, load_PC
, store_PC
);
154 } else if (!valid_load_SSID
&& valid_store_SSID
) {
155 SSID store_SSID
= SSIT
[store_index
];
157 validSSIT
[load_index
] = true;
159 SSIT
[load_index
] = store_SSID
;
161 DPRINTF(StoreSet
, "StoreSet: Store had a valid store set: %i for "
162 "load %#x, store %#x\n",
163 store_SSID
, load_PC
, store_PC
);
165 SSID load_SSID
= SSIT
[load_index
];
166 SSID store_SSID
= SSIT
[store_index
];
168 assert(load_SSID
< LFSTSize
&& store_SSID
< LFSTSize
);
170 // The store set with the lower number wins
171 if (store_SSID
> load_SSID
) {
172 SSIT
[store_index
] = load_SSID
;
174 DPRINTF(StoreSet
, "StoreSet: Load had smaller store set: %i; "
175 "for load %#x, store %#x\n",
176 load_SSID
, load_PC
, store_PC
);
178 SSIT
[load_index
] = store_SSID
;
180 DPRINTF(StoreSet
, "StoreSet: Store had smaller store set: %i; "
181 "for load %#x, store %#x\n",
182 store_SSID
, load_PC
, store_PC
);
188 StoreSet::checkClear()
191 if (memOpsPred
> clearPeriod
) {
192 DPRINTF(StoreSet
, "Wiping predictor state beacuse %d ld/st executed\n",
200 StoreSet::insertLoad(Addr load_PC
, InstSeqNum load_seq_num
)
208 StoreSet::insertStore(Addr store_PC
, InstSeqNum store_seq_num
, ThreadID tid
)
210 int index
= calcIndex(store_PC
);
215 assert(index
< SSITSize
);
217 if (!validSSIT
[index
]) {
218 // Do nothing if there's no valid entry.
221 store_SSID
= SSIT
[index
];
223 assert(store_SSID
< LFSTSize
);
225 // Update the last store that was fetched with the current one.
226 LFST
[store_SSID
] = store_seq_num
;
228 validLFST
[store_SSID
] = 1;
230 storeList
[store_seq_num
] = store_SSID
;
232 DPRINTF(StoreSet
, "Store %#x updated the LFST, SSID: %i\n",
233 store_PC
, store_SSID
);
238 StoreSet::checkInst(Addr PC
)
240 int index
= calcIndex(PC
);
244 assert(index
< SSITSize
);
246 if (!validSSIT
[index
]) {
247 DPRINTF(StoreSet
, "Inst %#x with index %i had no SSID\n",
250 // Return 0 if there's no valid entry.
253 inst_SSID
= SSIT
[index
];
255 assert(inst_SSID
< LFSTSize
);
257 if (!validLFST
[inst_SSID
]) {
259 DPRINTF(StoreSet
, "Inst %#x with index %i and SSID %i had no "
260 "dependency\n", PC
, index
, inst_SSID
);
264 DPRINTF(StoreSet
, "Inst %#x with index %i and SSID %i had LFST "
265 "inum of %i\n", PC
, index
, inst_SSID
, LFST
[inst_SSID
]);
267 return LFST
[inst_SSID
];
273 StoreSet::issued(Addr issued_PC
, InstSeqNum issued_seq_num
, bool is_store
)
275 // This only is updated upon a store being issued.
280 int index
= calcIndex(issued_PC
);
284 assert(index
< SSITSize
);
286 SeqNumMapIt store_list_it
= storeList
.find(issued_seq_num
);
288 if (store_list_it
!= storeList
.end()) {
289 storeList
.erase(store_list_it
);
292 // Make sure the SSIT still has a valid entry for the issued store.
293 if (!validSSIT
[index
]) {
297 store_SSID
= SSIT
[index
];
299 assert(store_SSID
< LFSTSize
);
301 // If the last fetched store in the store set refers to the store that
302 // was just issued, then invalidate the entry.
303 if (validLFST
[store_SSID
] && LFST
[store_SSID
] == issued_seq_num
) {
304 DPRINTF(StoreSet
, "StoreSet: store invalidated itself in LFST.\n");
305 validLFST
[store_SSID
] = false;
310 StoreSet::squash(InstSeqNum squashed_num
, ThreadID tid
)
312 DPRINTF(StoreSet
, "StoreSet: Squashing until inum %i\n",
316 SeqNumMapIt store_list_it
= storeList
.begin();
318 //@todo:Fix to only delete from correct thread
319 while (!storeList
.empty()) {
320 idx
= (*store_list_it
).second
;
322 if ((*store_list_it
).first
<= squashed_num
) {
326 bool younger
= LFST
[idx
] > squashed_num
;
328 if (validLFST
[idx
] && younger
) {
329 DPRINTF(StoreSet
, "Squashed [sn:%lli]\n", LFST
[idx
]);
330 validLFST
[idx
] = false;
332 storeList
.erase(store_list_it
++);
333 } else if (!validLFST
[idx
] && younger
) {
334 storeList
.erase(store_list_it
++);
342 for (int i
= 0; i
< SSITSize
; ++i
) {
343 validSSIT
[i
] = false;
346 for (int i
= 0; i
< LFSTSize
; ++i
) {
347 validLFST
[i
] = false;
356 cprintf("storeList.size(): %i\n", storeList
.size());
357 SeqNumMapIt store_list_it
= storeList
.begin();
361 while (store_list_it
!= storeList
.end()) {
362 cprintf("%i: [sn:%lli] SSID:%i\n",
363 num
, (*store_list_it
).first
, (*store_list_it
).second
);