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/trace.hh"
33 #include "cpu/o3/store_set.hh"
35 StoreSet::StoreSet(int _SSIT_size
, int _LFST_size
)
36 : SSITSize(_SSIT_size
), LFSTSize(_LFST_size
)
38 DPRINTF(StoreSet
, "StoreSet: Creating store set object.\n");
39 DPRINTF(StoreSet
, "StoreSet: SSIT size: %i, LFST size: %i.\n",
42 if (!isPowerOf2(SSITSize
)) {
43 fatal("Invalid SSIT size!\n");
46 SSIT
.resize(SSITSize
);
48 validSSIT
.resize(SSITSize
);
50 for (int i
= 0; i
< SSITSize
; ++i
)
53 if (!isPowerOf2(LFSTSize
)) {
54 fatal("Invalid LFST size!\n");
57 LFST
.resize(LFSTSize
);
59 validLFST
.resize(LFSTSize
);
61 for (int i
= 0; i
< LFSTSize
; ++i
) {
66 indexMask
= SSITSize
- 1;
76 StoreSet::init(int _SSIT_size
, int _LFST_size
)
78 SSITSize
= _SSIT_size
;
79 LFSTSize
= _LFST_size
;
81 DPRINTF(StoreSet
, "StoreSet: Creating store set object.\n");
82 DPRINTF(StoreSet
, "StoreSet: SSIT size: %i, LFST size: %i.\n",
85 SSIT
.resize(SSITSize
);
87 validSSIT
.resize(SSITSize
);
89 for (int i
= 0; i
< SSITSize
; ++i
)
92 LFST
.resize(LFSTSize
);
94 validLFST
.resize(LFSTSize
);
96 for (int i
= 0; i
< LFSTSize
; ++i
) {
101 indexMask
= SSITSize
- 1;
108 StoreSet::violation(Addr store_PC
, Addr load_PC
)
110 int load_index
= calcIndex(load_PC
);
111 int store_index
= calcIndex(store_PC
);
113 assert(load_index
< SSITSize
&& store_index
< SSITSize
);
115 bool valid_load_SSID
= validSSIT
[load_index
];
116 bool valid_store_SSID
= validSSIT
[store_index
];
118 if (!valid_load_SSID
&& !valid_store_SSID
) {
119 // Calculate a new SSID here.
120 SSID new_set
= calcSSID(load_PC
);
122 validSSIT
[load_index
] = true;
124 SSIT
[load_index
] = new_set
;
126 validSSIT
[store_index
] = true;
128 SSIT
[store_index
] = new_set
;
130 assert(new_set
< LFSTSize
);
132 DPRINTF(StoreSet
, "StoreSet: Neither load nor store had a valid "
133 "storeset, creating a new one: %i for load %#x, store %#x\n",
134 new_set
, load_PC
, store_PC
);
135 } else if (valid_load_SSID
&& !valid_store_SSID
) {
136 SSID load_SSID
= SSIT
[load_index
];
138 validSSIT
[store_index
] = true;
140 SSIT
[store_index
] = load_SSID
;
142 assert(load_SSID
< LFSTSize
);
144 DPRINTF(StoreSet
, "StoreSet: Load had a valid store set. Adding "
145 "store to that set: %i for load %#x, store %#x\n",
146 load_SSID
, load_PC
, store_PC
);
147 } else if (!valid_load_SSID
&& valid_store_SSID
) {
148 SSID store_SSID
= SSIT
[store_index
];
150 validSSIT
[load_index
] = true;
152 SSIT
[load_index
] = store_SSID
;
154 DPRINTF(StoreSet
, "StoreSet: Store had a valid store set: %i for "
155 "load %#x, store %#x\n",
156 store_SSID
, load_PC
, store_PC
);
158 SSID load_SSID
= SSIT
[load_index
];
159 SSID store_SSID
= SSIT
[store_index
];
161 assert(load_SSID
< LFSTSize
&& store_SSID
< LFSTSize
);
163 // The store set with the lower number wins
164 if (store_SSID
> load_SSID
) {
165 SSIT
[store_index
] = load_SSID
;
167 DPRINTF(StoreSet
, "StoreSet: Load had smaller store set: %i; "
168 "for load %#x, store %#x\n",
169 load_SSID
, load_PC
, store_PC
);
171 SSIT
[load_index
] = store_SSID
;
173 DPRINTF(StoreSet
, "StoreSet: Store had smaller store set: %i; "
174 "for load %#x, store %#x\n",
175 store_SSID
, load_PC
, store_PC
);
181 StoreSet::insertLoad(Addr load_PC
, InstSeqNum load_seq_num
)
188 StoreSet::insertStore(Addr store_PC
, InstSeqNum store_seq_num
,
191 int index
= calcIndex(store_PC
);
195 assert(index
< SSITSize
);
197 if (!validSSIT
[index
]) {
198 // Do nothing if there's no valid entry.
201 store_SSID
= SSIT
[index
];
203 assert(store_SSID
< LFSTSize
);
205 // Update the last store that was fetched with the current one.
206 LFST
[store_SSID
] = store_seq_num
;
208 validLFST
[store_SSID
] = 1;
210 storeList
[store_seq_num
] = store_SSID
;
212 DPRINTF(StoreSet
, "Store %#x updated the LFST, SSID: %i\n",
213 store_PC
, store_SSID
);
218 StoreSet::checkInst(Addr PC
)
220 int index
= calcIndex(PC
);
224 assert(index
< SSITSize
);
226 if (!validSSIT
[index
]) {
227 DPRINTF(StoreSet
, "Inst %#x with index %i had no SSID\n",
230 // Return 0 if there's no valid entry.
233 inst_SSID
= SSIT
[index
];
235 assert(inst_SSID
< LFSTSize
);
237 if (!validLFST
[inst_SSID
]) {
239 DPRINTF(StoreSet
, "Inst %#x with index %i and SSID %i had no "
240 "dependency\n", PC
, index
, inst_SSID
);
244 DPRINTF(StoreSet
, "Inst %#x with index %i and SSID %i had LFST "
245 "inum of %i\n", PC
, index
, inst_SSID
, LFST
[inst_SSID
]);
247 return LFST
[inst_SSID
];
253 StoreSet::issued(Addr issued_PC
, InstSeqNum issued_seq_num
, bool is_store
)
255 // This only is updated upon a store being issued.
260 int index
= calcIndex(issued_PC
);
264 assert(index
< SSITSize
);
266 SeqNumMapIt store_list_it
= storeList
.find(issued_seq_num
);
268 if (store_list_it
!= storeList
.end()) {
269 storeList
.erase(store_list_it
);
272 // Make sure the SSIT still has a valid entry for the issued store.
273 if (!validSSIT
[index
]) {
277 store_SSID
= SSIT
[index
];
279 assert(store_SSID
< LFSTSize
);
281 // If the last fetched store in the store set refers to the store that
282 // was just issued, then invalidate the entry.
283 if (validLFST
[store_SSID
] && LFST
[store_SSID
] == issued_seq_num
) {
284 DPRINTF(StoreSet
, "StoreSet: store invalidated itself in LFST.\n");
285 validLFST
[store_SSID
] = false;
290 StoreSet::squash(InstSeqNum squashed_num
, unsigned tid
)
292 DPRINTF(StoreSet
, "StoreSet: Squashing until inum %i\n",
296 SeqNumMapIt store_list_it
= storeList
.begin();
298 //@todo:Fix to only delete from correct thread
299 while (!storeList
.empty()) {
300 idx
= (*store_list_it
).second
;
302 if ((*store_list_it
).first
<= squashed_num
) {
306 bool younger
= LFST
[idx
] > squashed_num
;
308 if (validLFST
[idx
] && younger
) {
309 DPRINTF(StoreSet
, "Squashed [sn:%lli]\n", LFST
[idx
]);
310 validLFST
[idx
] = false;
312 storeList
.erase(store_list_it
++);
313 } else if (!validLFST
[idx
] && younger
) {
314 storeList
.erase(store_list_it
++);
322 for (int i
= 0; i
< SSITSize
; ++i
) {
323 validSSIT
[i
] = false;
326 for (int i
= 0; i
< LFSTSize
; ++i
) {
327 validLFST
[i
] = false;
336 cprintf("storeList.size(): %i\n", storeList
.size());
337 SeqNumMapIt store_list_it
= storeList
.begin();
341 while (store_list_it
!= storeList
.end()) {
342 cprintf("%i: [sn:%lli] SSID:%i\n",
343 num
, (*store_list_it
).first
, (*store_list_it
).second
);