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 "base/trace.hh"
30 #include "cpu/o3/store_set.hh"
32 StoreSet::StoreSet(int _SSIT_size
, int _LFST_size
)
33 : SSITSize(_SSIT_size
), LFSTSize(_LFST_size
)
35 DPRINTF(StoreSet
, "StoreSet: Creating store set object.\n");
36 DPRINTF(StoreSet
, "StoreSet: SSIT size: %i, LFST size: %i.\n",
39 SSIT
.resize(SSITSize
);
41 validSSIT
.resize(SSITSize
);
43 for (int i
= 0; i
< SSITSize
; ++i
)
46 LFST
.resize(LFSTSize
);
48 validLFST
.resize(LFSTSize
);
50 for (int i
= 0; i
< LFSTSize
; ++i
) {
55 indexMask
= SSITSize
- 1;
65 StoreSet::init(int _SSIT_size
, int _LFST_size
)
67 SSITSize
= _SSIT_size
;
68 LFSTSize
= _LFST_size
;
70 DPRINTF(StoreSet
, "StoreSet: Creating store set object.\n");
71 DPRINTF(StoreSet
, "StoreSet: SSIT size: %i, LFST size: %i.\n",
74 SSIT
.resize(SSITSize
);
76 validSSIT
.resize(SSITSize
);
78 for (int i
= 0; i
< SSITSize
; ++i
)
81 LFST
.resize(LFSTSize
);
83 validLFST
.resize(LFSTSize
);
85 for (int i
= 0; i
< LFSTSize
; ++i
) {
90 indexMask
= SSITSize
- 1;
97 StoreSet::violation(Addr store_PC
, Addr load_PC
)
99 int load_index
= calcIndex(load_PC
);
100 int store_index
= calcIndex(store_PC
);
102 assert(load_index
< SSITSize
&& store_index
< SSITSize
);
104 bool valid_load_SSID
= validSSIT
[load_index
];
105 bool valid_store_SSID
= validSSIT
[store_index
];
107 if (!valid_load_SSID
&& !valid_store_SSID
) {
108 // Calculate a new SSID here.
109 SSID new_set
= calcSSID(load_PC
);
111 validSSIT
[load_index
] = true;
113 SSIT
[load_index
] = new_set
;
115 validSSIT
[store_index
] = true;
117 SSIT
[store_index
] = new_set
;
119 assert(new_set
< LFSTSize
);
121 DPRINTF(StoreSet
, "StoreSet: Neither load nor store had a valid "
122 "storeset, creating a new one: %i for load %#x, store %#x\n",
123 new_set
, load_PC
, store_PC
);
124 } else if (valid_load_SSID
&& !valid_store_SSID
) {
125 SSID load_SSID
= SSIT
[load_index
];
127 validSSIT
[store_index
] = true;
129 SSIT
[store_index
] = load_SSID
;
131 assert(load_SSID
< LFSTSize
);
133 DPRINTF(StoreSet
, "StoreSet: Load had a valid store set. Adding "
134 "store to that set: %i for load %#x, store %#x\n",
135 load_SSID
, load_PC
, store_PC
);
136 } else if (!valid_load_SSID
&& valid_store_SSID
) {
137 SSID store_SSID
= SSIT
[store_index
];
139 validSSIT
[load_index
] = true;
141 SSIT
[load_index
] = store_SSID
;
143 DPRINTF(StoreSet
, "StoreSet: Store had a valid store set: %i for "
144 "load %#x, store %#x\n",
145 store_SSID
, load_PC
, store_PC
);
147 SSID load_SSID
= SSIT
[load_index
];
148 SSID store_SSID
= SSIT
[store_index
];
150 assert(load_SSID
< LFSTSize
&& store_SSID
< LFSTSize
);
152 // The store set with the lower number wins
153 if (store_SSID
> load_SSID
) {
154 SSIT
[store_index
] = load_SSID
;
156 DPRINTF(StoreSet
, "StoreSet: Load had smaller store set: %i; "
157 "for load %#x, store %#x\n",
158 load_SSID
, load_PC
, store_PC
);
160 SSIT
[load_index
] = store_SSID
;
162 DPRINTF(StoreSet
, "StoreSet: Store had smaller store set: %i; "
163 "for load %#x, store %#x\n",
164 store_SSID
, load_PC
, store_PC
);
170 StoreSet::insertLoad(Addr load_PC
, InstSeqNum load_seq_num
)
177 StoreSet::insertStore(Addr store_PC
, InstSeqNum store_seq_num
,
180 int index
= calcIndex(store_PC
);
184 assert(index
< SSITSize
);
186 if (!validSSIT
[index
]) {
187 // Do nothing if there's no valid entry.
190 store_SSID
= SSIT
[index
];
192 assert(store_SSID
< LFSTSize
);
194 // Update the last store that was fetched with the current one.
195 LFST
[store_SSID
] = store_seq_num
;
197 validLFST
[store_SSID
] = 1;
199 storeList
[store_seq_num
] = store_SSID
;
201 DPRINTF(StoreSet
, "Store %#x updated the LFST, SSID: %i\n",
202 store_PC
, store_SSID
);
207 StoreSet::checkInst(Addr PC
)
209 int index
= calcIndex(PC
);
213 assert(index
< SSITSize
);
215 if (!validSSIT
[index
]) {
216 DPRINTF(StoreSet
, "Inst %#x with index %i had no SSID\n",
219 // Return 0 if there's no valid entry.
222 inst_SSID
= SSIT
[index
];
224 assert(inst_SSID
< LFSTSize
);
226 if (!validLFST
[inst_SSID
]) {
228 DPRINTF(StoreSet
, "Inst %#x with index %i and SSID %i had no "
229 "dependency\n", PC
, index
, inst_SSID
);
233 DPRINTF(StoreSet
, "Inst %#x with index %i and SSID %i had LFST "
234 "inum of %i\n", PC
, index
, inst_SSID
, LFST
[inst_SSID
]);
236 return LFST
[inst_SSID
];
242 StoreSet::issued(Addr issued_PC
, InstSeqNum issued_seq_num
, bool is_store
)
244 // This only is updated upon a store being issued.
249 int index
= calcIndex(issued_PC
);
253 assert(index
< SSITSize
);
255 SeqNumMapIt store_list_it
= storeList
.find(issued_seq_num
);
257 if (store_list_it
!= storeList
.end()) {
258 storeList
.erase(store_list_it
);
261 // Make sure the SSIT still has a valid entry for the issued store.
262 if (!validSSIT
[index
]) {
266 store_SSID
= SSIT
[index
];
268 assert(store_SSID
< LFSTSize
);
270 // If the last fetched store in the store set refers to the store that
271 // was just issued, then invalidate the entry.
272 if (validLFST
[store_SSID
] && LFST
[store_SSID
] == issued_seq_num
) {
273 DPRINTF(StoreSet
, "StoreSet: store invalidated itself in LFST.\n");
274 validLFST
[store_SSID
] = false;
279 StoreSet::squash(InstSeqNum squashed_num
, unsigned tid
)
281 DPRINTF(StoreSet
, "StoreSet: Squashing until inum %i\n",
285 SeqNumMapIt store_list_it
= storeList
.begin();
287 //@todo:Fix to only delete from correct thread
288 while (!storeList
.empty()) {
289 idx
= (*store_list_it
).second
;
291 if ((*store_list_it
).first
<= squashed_num
) {
295 bool younger
= LFST
[idx
] > squashed_num
;
297 if (validLFST
[idx
] && younger
) {
298 DPRINTF(StoreSet
, "Squashed [sn:%lli]\n", LFST
[idx
]);
299 validLFST
[idx
] = false;
301 storeList
.erase(store_list_it
++);
302 } else if (!validLFST
[idx
] && younger
) {
303 storeList
.erase(store_list_it
++);
311 for (int i
= 0; i
< SSITSize
; ++i
) {
312 validSSIT
[i
] = false;
315 for (int i
= 0; i
< LFSTSize
; ++i
) {
316 validLFST
[i
] = false;