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/trace.hh"
32 #include "cpu/o3/store_set.hh"
34 StoreSet::StoreSet(int _SSIT_size
, int _LFST_size
)
35 : SSITSize(_SSIT_size
), LFSTSize(_LFST_size
)
37 DPRINTF(StoreSet
, "StoreSet: Creating store set object.\n");
38 DPRINTF(StoreSet
, "StoreSet: SSIT size: %i, LFST size: %i.\n",
41 SSIT
.resize(SSITSize
);
43 validSSIT
.resize(SSITSize
);
45 for (int i
= 0; i
< SSITSize
; ++i
)
48 LFST
.resize(LFSTSize
);
50 validLFST
.resize(LFSTSize
);
52 for (int i
= 0; i
< LFSTSize
; ++i
) {
57 indexMask
= SSITSize
- 1;
67 StoreSet::init(int _SSIT_size
, int _LFST_size
)
69 SSITSize
= _SSIT_size
;
70 LFSTSize
= _LFST_size
;
72 DPRINTF(StoreSet
, "StoreSet: Creating store set object.\n");
73 DPRINTF(StoreSet
, "StoreSet: SSIT size: %i, LFST size: %i.\n",
76 SSIT
.resize(SSITSize
);
78 validSSIT
.resize(SSITSize
);
80 for (int i
= 0; i
< SSITSize
; ++i
)
83 LFST
.resize(LFSTSize
);
85 validLFST
.resize(LFSTSize
);
87 for (int i
= 0; i
< LFSTSize
; ++i
) {
92 indexMask
= SSITSize
- 1;
99 StoreSet::violation(Addr store_PC
, Addr load_PC
)
101 int load_index
= calcIndex(load_PC
);
102 int store_index
= calcIndex(store_PC
);
104 assert(load_index
< SSITSize
&& store_index
< SSITSize
);
106 bool valid_load_SSID
= validSSIT
[load_index
];
107 bool valid_store_SSID
= validSSIT
[store_index
];
109 if (!valid_load_SSID
&& !valid_store_SSID
) {
110 // Calculate a new SSID here.
111 SSID new_set
= calcSSID(load_PC
);
113 validSSIT
[load_index
] = true;
115 SSIT
[load_index
] = new_set
;
117 validSSIT
[store_index
] = true;
119 SSIT
[store_index
] = new_set
;
121 assert(new_set
< LFSTSize
);
123 DPRINTF(StoreSet
, "StoreSet: Neither load nor store had a valid "
124 "storeset, creating a new one: %i for load %#x, store %#x\n",
125 new_set
, load_PC
, store_PC
);
126 } else if (valid_load_SSID
&& !valid_store_SSID
) {
127 SSID load_SSID
= SSIT
[load_index
];
129 validSSIT
[store_index
] = true;
131 SSIT
[store_index
] = load_SSID
;
133 assert(load_SSID
< LFSTSize
);
135 DPRINTF(StoreSet
, "StoreSet: Load had a valid store set. Adding "
136 "store to that set: %i for load %#x, store %#x\n",
137 load_SSID
, load_PC
, store_PC
);
138 } else if (!valid_load_SSID
&& valid_store_SSID
) {
139 SSID store_SSID
= SSIT
[store_index
];
141 validSSIT
[load_index
] = true;
143 SSIT
[load_index
] = store_SSID
;
145 DPRINTF(StoreSet
, "StoreSet: Store had a valid store set: %i for "
146 "load %#x, store %#x\n",
147 store_SSID
, load_PC
, store_PC
);
149 SSID load_SSID
= SSIT
[load_index
];
150 SSID store_SSID
= SSIT
[store_index
];
152 assert(load_SSID
< LFSTSize
&& store_SSID
< LFSTSize
);
154 // The store set with the lower number wins
155 if (store_SSID
> load_SSID
) {
156 SSIT
[store_index
] = load_SSID
;
158 DPRINTF(StoreSet
, "StoreSet: Load had smaller store set: %i; "
159 "for load %#x, store %#x\n",
160 load_SSID
, load_PC
, store_PC
);
162 SSIT
[load_index
] = store_SSID
;
164 DPRINTF(StoreSet
, "StoreSet: Store had smaller store set: %i; "
165 "for load %#x, store %#x\n",
166 store_SSID
, load_PC
, store_PC
);
172 StoreSet::insertLoad(Addr load_PC
, InstSeqNum load_seq_num
)
179 StoreSet::insertStore(Addr store_PC
, InstSeqNum store_seq_num
,
182 int index
= calcIndex(store_PC
);
186 assert(index
< SSITSize
);
188 if (!validSSIT
[index
]) {
189 // Do nothing if there's no valid entry.
192 store_SSID
= SSIT
[index
];
194 assert(store_SSID
< LFSTSize
);
196 // Update the last store that was fetched with the current one.
197 LFST
[store_SSID
] = store_seq_num
;
199 validLFST
[store_SSID
] = 1;
201 storeList
[store_seq_num
] = store_SSID
;
203 DPRINTF(StoreSet
, "Store %#x updated the LFST, SSID: %i\n",
204 store_PC
, store_SSID
);
209 StoreSet::checkInst(Addr PC
)
211 int index
= calcIndex(PC
);
215 assert(index
< SSITSize
);
217 if (!validSSIT
[index
]) {
218 DPRINTF(StoreSet
, "Inst %#x with index %i had no SSID\n",
221 // Return 0 if there's no valid entry.
224 inst_SSID
= SSIT
[index
];
226 assert(inst_SSID
< LFSTSize
);
228 if (!validLFST
[inst_SSID
]) {
230 DPRINTF(StoreSet
, "Inst %#x with index %i and SSID %i had no "
231 "dependency\n", PC
, index
, inst_SSID
);
235 DPRINTF(StoreSet
, "Inst %#x with index %i and SSID %i had LFST "
236 "inum of %i\n", PC
, index
, inst_SSID
, LFST
[inst_SSID
]);
238 return LFST
[inst_SSID
];
244 StoreSet::issued(Addr issued_PC
, InstSeqNum issued_seq_num
, bool is_store
)
246 // This only is updated upon a store being issued.
251 int index
= calcIndex(issued_PC
);
255 assert(index
< SSITSize
);
257 SeqNumMapIt store_list_it
= storeList
.find(issued_seq_num
);
259 if (store_list_it
!= storeList
.end()) {
260 storeList
.erase(store_list_it
);
263 // Make sure the SSIT still has a valid entry for the issued store.
264 if (!validSSIT
[index
]) {
268 store_SSID
= SSIT
[index
];
270 assert(store_SSID
< LFSTSize
);
272 // If the last fetched store in the store set refers to the store that
273 // was just issued, then invalidate the entry.
274 if (validLFST
[store_SSID
] && LFST
[store_SSID
] == issued_seq_num
) {
275 DPRINTF(StoreSet
, "StoreSet: store invalidated itself in LFST.\n");
276 validLFST
[store_SSID
] = false;
281 StoreSet::squash(InstSeqNum squashed_num
, unsigned tid
)
283 DPRINTF(StoreSet
, "StoreSet: Squashing until inum %i\n",
287 SeqNumMapIt store_list_it
= storeList
.begin();
289 //@todo:Fix to only delete from correct thread
290 while (!storeList
.empty()) {
291 idx
= (*store_list_it
).second
;
293 if ((*store_list_it
).first
<= squashed_num
) {
297 bool younger
= LFST
[idx
] > squashed_num
;
299 if (validLFST
[idx
] && younger
) {
300 DPRINTF(StoreSet
, "Squashed [sn:%lli]\n", LFST
[idx
]);
301 validLFST
[idx
] = false;
303 storeList
.erase(store_list_it
++);
304 } else if (!validLFST
[idx
] && younger
) {
305 storeList
.erase(store_list_it
++);
313 for (int i
= 0; i
< SSITSize
; ++i
) {
314 validSSIT
[i
] = false;
317 for (int i
= 0; i
< LFSTSize
; ++i
) {
318 validLFST
[i
] = false;