store_set.cc revision 1689
1/* 2 * Copyright (c) 2004-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 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. 15 * 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. 27 */ 28 29#include "base/trace.hh" 30#include "cpu/beta_cpu/store_set.hh" 31 32StoreSet::StoreSet(int _SSIT_size, int _LFST_size) 33 : SSIT_size(_SSIT_size), LFST_size(_LFST_size) 34{ 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); 38 39 SSIT = new SSID[SSIT_size]; 40 41 validSSIT.resize(SSIT_size); 42 43 for (int i = 0; i < SSIT_size; ++i) 44 validSSIT[i] = false; 45 46 LFST = new InstSeqNum[LFST_size]; 47 48 validLFST.resize(LFST_size); 49 50 SSCounters = new int[LFST_size]; 51 52 for (int i = 0; i < LFST_size; ++i) 53 { 54 validLFST[i] = false; 55 SSCounters[i] = 0; 56 } 57 58 index_mask = SSIT_size - 1; 59 60 offset_bits = 2; 61} 62 63void 64StoreSet::violation(Addr store_PC, Addr load_PC) 65{ 66 int load_index = calcIndex(load_PC); 67 int store_index = calcIndex(store_PC); 68 69 assert(load_index < SSIT_size && store_index < SSIT_size); 70 71 bool valid_load_SSID = validSSIT[load_index]; 72 bool valid_store_SSID = validSSIT[store_index]; 73 74 if (!valid_load_SSID && !valid_store_SSID) { 75 // Calculate a new SSID here. 76 SSID new_set = calcSSID(load_PC); 77 78 validSSIT[load_index] = true; 79 80 SSIT[load_index] = new_set; 81 82 validSSIT[store_index] = true; 83 84 SSIT[store_index] = new_set; 85 86 assert(new_set < LFST_size); 87 88 SSCounters[new_set]++; 89 90 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]; 96 97 validSSIT[store_index] = true; 98 99 SSIT[store_index] = load_SSID; 100 101 assert(load_SSID < LFST_size); 102 103 SSCounters[load_SSID]++; 104 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]; 110 111 validSSIT[load_index] = true; 112 113 SSIT[load_index] = store_SSID; 114 115 // Because we are having a load point to an already existing set, 116 // the size of the store set is not incremented. 117 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); 121 } else { 122 SSID load_SSID = SSIT[load_index]; 123 SSID store_SSID = SSIT[store_index]; 124 125 assert(load_SSID < LFST_size && store_SSID < LFST_size); 126 127 int load_SS_size = SSCounters[load_SSID]; 128 int store_SS_size = SSCounters[store_SSID]; 129 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; 134 135 SSCounters[load_SSID]++; 136 SSCounters[store_SSID]--; 137 138 DPRINTF(StoreSet, "StoreSet: Load had bigger store set: %i; " 139 "for load %#x, store %#x\n", 140 load_SSID, load_PC, store_PC); 141 } else { 142 SSIT[load_index] = store_SSID; 143 144 SSCounters[store_SSID]++; 145 SSCounters[load_SSID]--; 146 147 DPRINTF(StoreSet, "StoreSet: Store had bigger store set: %i; " 148 "for load %#x, store %#x\n", 149 store_SSID, load_PC, store_PC); 150 } 151 } 152} 153 154void 155StoreSet::insertLoad(Addr load_PC, InstSeqNum load_seq_num) 156{ 157 // Does nothing. 158 return; 159} 160 161void 162StoreSet::insertStore(Addr store_PC, InstSeqNum store_seq_num) 163{ 164 int index = calcIndex(store_PC); 165 166 int store_SSID; 167 168 assert(index < SSIT_size); 169 170 if (!validSSIT[index]) { 171 // Do nothing if there's no valid entry. 172 return; 173 } else { 174 store_SSID = SSIT[index]; 175 176 assert(store_SSID < LFST_size); 177 178 // Update the last store that was fetched with the current one. 179 LFST[store_SSID] = store_seq_num; 180 181 validLFST[store_SSID] = 1; 182 183 DPRINTF(StoreSet, "Store %#x updated the LFST, SSID: %i\n", 184 store_PC, store_SSID); 185 } 186} 187 188InstSeqNum 189StoreSet::checkInst(Addr PC) 190{ 191 int index = calcIndex(PC); 192 193 int inst_SSID; 194 195 assert(index < SSIT_size); 196 197 if (!validSSIT[index]) { 198 DPRINTF(StoreSet, "Inst %#x with index %i had no SSID\n", 199 PC, index); 200 201 // Return 0 if there's no valid entry. 202 return 0; 203 } else { 204 inst_SSID = SSIT[index]; 205 206 assert(inst_SSID < LFST_size); 207 208 if (!validLFST[inst_SSID]) { 209 210 DPRINTF(StoreSet, "Inst %#x with index %i and SSID %i had no " 211 "dependency\n", PC, index, inst_SSID); 212 213 return 0; 214 } else { 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]); 217 218 return LFST[inst_SSID]; 219 } 220 } 221} 222 223void 224StoreSet::issued(Addr issued_PC, InstSeqNum issued_seq_num, bool is_store) 225{ 226 // This only is updated upon a store being issued. 227 if (!is_store) { 228 return; 229 } 230 231 int index = calcIndex(issued_PC); 232 233 int store_SSID; 234 235 assert(index < SSIT_size); 236 237 // Make sure the SSIT still has a valid entry for the issued store. 238 if (!validSSIT[index]) { 239 return; 240 } 241 242 store_SSID = SSIT[index]; 243 244 assert(store_SSID < LFST_size); 245 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; 251 } 252} 253 254void 255StoreSet::squash(InstSeqNum squashed_num) 256{ 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. 260 261 DPRINTF(StoreSet, "StoreSet: Squashing until inum %i\n", 262 squashed_num); 263 264 for (int i = 0; i < LFST_size; ++i) { 265 if (validLFST[i] && LFST[i] < squashed_num) { 266 validLFST[i] = false; 267 } 268 } 269} 270 271void 272StoreSet::clear() 273{ 274 for (int i = 0; i < SSIT_size; ++i) { 275 validSSIT[i] = false; 276 } 277 278 for (int i = 0; i < LFST_size; ++i) { 279 validLFST[i] = false; 280 } 281} 282 283