2 * Copyright (c) 2004-2005 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 : SSIT_size(_SSIT_size
), LFST_size(_LFST_size
)
35 DPRINTF(StoreSet
, "StoreSet: Creating store set object.\n");
36 DPRINTF(StoreSet
, "StoreSet: SSIT size: %i, LFST size: %i.\n",
37 SSIT_size
, LFST_size
);
39 SSIT
= new SSID
[SSIT_size
];
41 validSSIT
.resize(SSIT_size
);
43 for (int i
= 0; i
< SSIT_size
; ++i
)
46 LFST
= new InstSeqNum
[LFST_size
];
48 validLFST
.resize(LFST_size
);
50 SSCounters
= new int[LFST_size
];
52 for (int i
= 0; i
< LFST_size
; ++i
)
58 index_mask
= SSIT_size
- 1;
64 StoreSet::violation(Addr store_PC
, Addr load_PC
)
66 int load_index
= calcIndex(load_PC
);
67 int store_index
= calcIndex(store_PC
);
69 assert(load_index
< SSIT_size
&& store_index
< SSIT_size
);
71 bool valid_load_SSID
= validSSIT
[load_index
];
72 bool valid_store_SSID
= validSSIT
[store_index
];
74 if (!valid_load_SSID
&& !valid_store_SSID
) {
75 // Calculate a new SSID here.
76 SSID new_set
= calcSSID(load_PC
);
78 validSSIT
[load_index
] = true;
80 SSIT
[load_index
] = new_set
;
82 validSSIT
[store_index
] = true;
84 SSIT
[store_index
] = new_set
;
86 assert(new_set
< LFST_size
);
88 SSCounters
[new_set
]++;
91 DPRINTF(StoreSet
, "StoreSet: Neither load nor store had a valid "
92 "storeset, creating a new one: %i for load %#x, store %#x\n",
93 new_set
, load_PC
, store_PC
);
94 } else if (valid_load_SSID
&& !valid_store_SSID
) {
95 SSID load_SSID
= SSIT
[load_index
];
97 validSSIT
[store_index
] = true;
99 SSIT
[store_index
] = load_SSID
;
101 assert(load_SSID
< LFST_size
);
103 SSCounters
[load_SSID
]++;
105 DPRINTF(StoreSet
, "StoreSet: Load had a valid store set. Adding "
106 "store to that set: %i for load %#x, store %#x\n",
107 load_SSID
, load_PC
, store_PC
);
108 } else if (!valid_load_SSID
&& valid_store_SSID
) {
109 SSID store_SSID
= SSIT
[store_index
];
111 validSSIT
[load_index
] = true;
113 SSIT
[load_index
] = store_SSID
;
115 // Because we are having a load point to an already existing set,
116 // the size of the store set is not incremented.
118 DPRINTF(StoreSet
, "StoreSet: Store had a valid store set: %i for "
119 "load %#x, store %#x\n",
120 store_SSID
, load_PC
, store_PC
);
122 SSID load_SSID
= SSIT
[load_index
];
123 SSID store_SSID
= SSIT
[store_index
];
125 assert(load_SSID
< LFST_size
&& store_SSID
< LFST_size
);
127 int load_SS_size
= SSCounters
[load_SSID
];
128 int store_SS_size
= SSCounters
[store_SSID
];
130 // If the load has the bigger store set, then assign the store
131 // to the same store set as the load. Otherwise vice-versa.
132 if (load_SS_size
> store_SS_size
) {
133 SSIT
[store_index
] = load_SSID
;
135 SSCounters
[load_SSID
]++;
136 SSCounters
[store_SSID
]--;
138 DPRINTF(StoreSet
, "StoreSet: Load had bigger store set: %i; "
139 "for load %#x, store %#x\n",
140 load_SSID
, load_PC
, store_PC
);
142 SSIT
[load_index
] = store_SSID
;
144 SSCounters
[store_SSID
]++;
145 SSCounters
[load_SSID
]--;
147 DPRINTF(StoreSet
, "StoreSet: Store had bigger store set: %i; "
148 "for load %#x, store %#x\n",
149 store_SSID
, load_PC
, store_PC
);
155 StoreSet::insertLoad(Addr load_PC
, InstSeqNum load_seq_num
)
162 StoreSet::insertStore(Addr store_PC
, InstSeqNum store_seq_num
)
164 int index
= calcIndex(store_PC
);
168 assert(index
< SSIT_size
);
170 if (!validSSIT
[index
]) {
171 // Do nothing if there's no valid entry.
174 store_SSID
= SSIT
[index
];
176 assert(store_SSID
< LFST_size
);
178 // Update the last store that was fetched with the current one.
179 LFST
[store_SSID
] = store_seq_num
;
181 validLFST
[store_SSID
] = 1;
183 DPRINTF(StoreSet
, "Store %#x updated the LFST, SSID: %i\n",
184 store_PC
, store_SSID
);
189 StoreSet::checkInst(Addr PC
)
191 int index
= calcIndex(PC
);
195 assert(index
< SSIT_size
);
197 if (!validSSIT
[index
]) {
198 DPRINTF(StoreSet
, "Inst %#x with index %i had no SSID\n",
201 // Return 0 if there's no valid entry.
204 inst_SSID
= SSIT
[index
];
206 assert(inst_SSID
< LFST_size
);
208 if (!validLFST
[inst_SSID
]) {
210 DPRINTF(StoreSet
, "Inst %#x with index %i and SSID %i had no "
211 "dependency\n", PC
, index
, inst_SSID
);
215 DPRINTF(StoreSet
, "Inst %#x with index %i and SSID %i had LFST "
216 "inum of %i\n", PC
, index
, inst_SSID
, LFST
[inst_SSID
]);
218 return LFST
[inst_SSID
];
224 StoreSet::issued(Addr issued_PC
, InstSeqNum issued_seq_num
, bool is_store
)
226 // This only is updated upon a store being issued.
231 int index
= calcIndex(issued_PC
);
235 assert(index
< SSIT_size
);
237 // Make sure the SSIT still has a valid entry for the issued store.
238 if (!validSSIT
[index
]) {
242 store_SSID
= SSIT
[index
];
244 assert(store_SSID
< LFST_size
);
246 // If the last fetched store in the store set refers to the store that
247 // was just issued, then invalidate the entry.
248 if (validLFST
[store_SSID
] && LFST
[store_SSID
] == issued_seq_num
) {
249 DPRINTF(StoreSet
, "StoreSet: store invalidated itself in LFST.\n");
250 validLFST
[store_SSID
] = false;
255 StoreSet::squash(InstSeqNum squashed_num
)
257 // Not really sure how to do this well.
258 // Generally this is small enough that it should be okay; short circuit
259 // evaluation should take care of invalid entries.
261 DPRINTF(StoreSet
, "StoreSet: Squashing until inum %i\n",
264 for (int i
= 0; i
< LFST_size
; ++i
) {
265 if (validLFST
[i
] && LFST
[i
] < squashed_num
) {
266 validLFST
[i
] = false;
274 for (int i
= 0; i
< SSIT_size
; ++i
) {
275 validSSIT
[i
] = false;
278 for (int i
= 0; i
< LFST_size
; ++i
) {
279 validLFST
[i
] = false;