store_set.cc revision 2329
112027Sjungma@eit.uni-kl.de/* 212027Sjungma@eit.uni-kl.de * Copyright (c) 2004-2006 The Regents of The University of Michigan 312027Sjungma@eit.uni-kl.de * All rights reserved. 412027Sjungma@eit.uni-kl.de * 512027Sjungma@eit.uni-kl.de * Redistribution and use in source and binary forms, with or without 612027Sjungma@eit.uni-kl.de * modification, are permitted provided that the following conditions are 712027Sjungma@eit.uni-kl.de * met: redistributions of source code must retain the above copyright 812027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer; 912027Sjungma@eit.uni-kl.de * redistributions in binary form must reproduce the above copyright 1012027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer in the 1112027Sjungma@eit.uni-kl.de * documentation and/or other materials provided with the distribution; 1212027Sjungma@eit.uni-kl.de * neither the name of the copyright holders nor the names of its 1312027Sjungma@eit.uni-kl.de * contributors may be used to endorse or promote products derived from 1412027Sjungma@eit.uni-kl.de * this software without specific prior written permission. 1512027Sjungma@eit.uni-kl.de * 1612027Sjungma@eit.uni-kl.de * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712027Sjungma@eit.uni-kl.de * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812027Sjungma@eit.uni-kl.de * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912027Sjungma@eit.uni-kl.de * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012027Sjungma@eit.uni-kl.de * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112027Sjungma@eit.uni-kl.de * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212027Sjungma@eit.uni-kl.de * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312027Sjungma@eit.uni-kl.de * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412027Sjungma@eit.uni-kl.de * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512027Sjungma@eit.uni-kl.de * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612027Sjungma@eit.uni-kl.de * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712027Sjungma@eit.uni-kl.de */ 2812027Sjungma@eit.uni-kl.de 2912027Sjungma@eit.uni-kl.de#include "base/trace.hh" 3012027Sjungma@eit.uni-kl.de#include "cpu/o3/store_set.hh" 3112027Sjungma@eit.uni-kl.de 3212027Sjungma@eit.uni-kl.deStoreSet::StoreSet(int _SSIT_size, int _LFST_size) 3312027Sjungma@eit.uni-kl.de : SSITSize(_SSIT_size), LFSTSize(_LFST_size) 3412027Sjungma@eit.uni-kl.de{ 3512027Sjungma@eit.uni-kl.de DPRINTF(StoreSet, "StoreSet: Creating store set object.\n"); 3612027Sjungma@eit.uni-kl.de DPRINTF(StoreSet, "StoreSet: SSIT size: %i, LFST size: %i.\n", 3712027Sjungma@eit.uni-kl.de SSITSize, LFSTSize); 3812027Sjungma@eit.uni-kl.de 3912027Sjungma@eit.uni-kl.de SSIT.resize(SSITSize); 4012027Sjungma@eit.uni-kl.de 4112027Sjungma@eit.uni-kl.de validSSIT.resize(SSITSize); 4212027Sjungma@eit.uni-kl.de 4312027Sjungma@eit.uni-kl.de for (int i = 0; i < SSITSize; ++i) 4412027Sjungma@eit.uni-kl.de validSSIT[i] = false; 4512027Sjungma@eit.uni-kl.de 4612027Sjungma@eit.uni-kl.de LFST.resize(LFSTSize); 4712027Sjungma@eit.uni-kl.de 4812027Sjungma@eit.uni-kl.de validLFST.resize(LFSTSize); 4912027Sjungma@eit.uni-kl.de 5012027Sjungma@eit.uni-kl.de for (int i = 0; i < LFSTSize; ++i) { 5112027Sjungma@eit.uni-kl.de validLFST[i] = false; 5212027Sjungma@eit.uni-kl.de LFST[i] = 0; 5312027Sjungma@eit.uni-kl.de } 5412027Sjungma@eit.uni-kl.de 5512027Sjungma@eit.uni-kl.de indexMask = SSITSize - 1; 5612027Sjungma@eit.uni-kl.de 5712027Sjungma@eit.uni-kl.de offsetBits = 2; 5812027Sjungma@eit.uni-kl.de} 5912027Sjungma@eit.uni-kl.de 6012027Sjungma@eit.uni-kl.deStoreSet::~StoreSet() 6112027Sjungma@eit.uni-kl.de{ 6212027Sjungma@eit.uni-kl.de} 6312027Sjungma@eit.uni-kl.de 6412027Sjungma@eit.uni-kl.devoid 6512027Sjungma@eit.uni-kl.deStoreSet::init(int _SSIT_size, int _LFST_size) 6612027Sjungma@eit.uni-kl.de{ 6712027Sjungma@eit.uni-kl.de SSITSize = _SSIT_size; 6812027Sjungma@eit.uni-kl.de LFSTSize = _LFST_size; 6912027Sjungma@eit.uni-kl.de 7012027Sjungma@eit.uni-kl.de DPRINTF(StoreSet, "StoreSet: Creating store set object.\n"); 7112027Sjungma@eit.uni-kl.de DPRINTF(StoreSet, "StoreSet: SSIT size: %i, LFST size: %i.\n", 7212027Sjungma@eit.uni-kl.de SSITSize, LFSTSize); 7312027Sjungma@eit.uni-kl.de 7412027Sjungma@eit.uni-kl.de SSIT.resize(SSITSize); 7512027Sjungma@eit.uni-kl.de 7612027Sjungma@eit.uni-kl.de validSSIT.resize(SSITSize); 7712027Sjungma@eit.uni-kl.de 7812027Sjungma@eit.uni-kl.de for (int i = 0; i < SSITSize; ++i) 7912027Sjungma@eit.uni-kl.de validSSIT[i] = false; 8012027Sjungma@eit.uni-kl.de 8112027Sjungma@eit.uni-kl.de LFST.resize(LFSTSize); 8212027Sjungma@eit.uni-kl.de 8312027Sjungma@eit.uni-kl.de validLFST.resize(LFSTSize); 8412027Sjungma@eit.uni-kl.de 8512027Sjungma@eit.uni-kl.de for (int i = 0; i < LFSTSize; ++i) { 8612027Sjungma@eit.uni-kl.de validLFST[i] = false; 8712027Sjungma@eit.uni-kl.de LFST[i] = 0; 8812027Sjungma@eit.uni-kl.de } 8912027Sjungma@eit.uni-kl.de 9012027Sjungma@eit.uni-kl.de indexMask = SSITSize - 1; 9112027Sjungma@eit.uni-kl.de 9212027Sjungma@eit.uni-kl.de offsetBits = 2; 9312027Sjungma@eit.uni-kl.de} 9412027Sjungma@eit.uni-kl.de 9512027Sjungma@eit.uni-kl.de 9612027Sjungma@eit.uni-kl.devoid 9712027Sjungma@eit.uni-kl.deStoreSet::violation(Addr store_PC, Addr load_PC) 9812027Sjungma@eit.uni-kl.de{ 9912027Sjungma@eit.uni-kl.de int load_index = calcIndex(load_PC); 10012027Sjungma@eit.uni-kl.de int store_index = calcIndex(store_PC); 10112027Sjungma@eit.uni-kl.de 10212027Sjungma@eit.uni-kl.de assert(load_index < SSITSize && store_index < SSITSize); 10312027Sjungma@eit.uni-kl.de 10412027Sjungma@eit.uni-kl.de bool valid_load_SSID = validSSIT[load_index]; 10512027Sjungma@eit.uni-kl.de bool valid_store_SSID = validSSIT[store_index]; 10612027Sjungma@eit.uni-kl.de 10712027Sjungma@eit.uni-kl.de if (!valid_load_SSID && !valid_store_SSID) { 10812027Sjungma@eit.uni-kl.de // Calculate a new SSID here. 10912027Sjungma@eit.uni-kl.de SSID new_set = calcSSID(load_PC); 11012027Sjungma@eit.uni-kl.de 11112027Sjungma@eit.uni-kl.de validSSIT[load_index] = true; 11212027Sjungma@eit.uni-kl.de 11312027Sjungma@eit.uni-kl.de SSIT[load_index] = new_set; 11412027Sjungma@eit.uni-kl.de 115 validSSIT[store_index] = true; 116 117 SSIT[store_index] = new_set; 118 119 assert(new_set < LFSTSize); 120 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]; 126 127 validSSIT[store_index] = true; 128 129 SSIT[store_index] = load_SSID; 130 131 assert(load_SSID < LFSTSize); 132 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]; 138 139 validSSIT[load_index] = true; 140 141 SSIT[load_index] = store_SSID; 142 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); 146 } else { 147 SSID load_SSID = SSIT[load_index]; 148 SSID store_SSID = SSIT[store_index]; 149 150 assert(load_SSID < LFSTSize && store_SSID < LFSTSize); 151 152 // The store set with the lower number wins 153 if (store_SSID > load_SSID) { 154 SSIT[store_index] = load_SSID; 155 156 DPRINTF(StoreSet, "StoreSet: Load had smaller store set: %i; " 157 "for load %#x, store %#x\n", 158 load_SSID, load_PC, store_PC); 159 } else { 160 SSIT[load_index] = store_SSID; 161 162 DPRINTF(StoreSet, "StoreSet: Store had smaller store set: %i; " 163 "for load %#x, store %#x\n", 164 store_SSID, load_PC, store_PC); 165 } 166 } 167} 168 169void 170StoreSet::insertLoad(Addr load_PC, InstSeqNum load_seq_num) 171{ 172 // Does nothing. 173 return; 174} 175 176void 177StoreSet::insertStore(Addr store_PC, InstSeqNum store_seq_num, 178 unsigned tid) 179{ 180 int index = calcIndex(store_PC); 181 182 int store_SSID; 183 184 assert(index < SSITSize); 185 186 if (!validSSIT[index]) { 187 // Do nothing if there's no valid entry. 188 return; 189 } else { 190 store_SSID = SSIT[index]; 191 192 assert(store_SSID < LFSTSize); 193 194 // Update the last store that was fetched with the current one. 195 LFST[store_SSID] = store_seq_num; 196 197 validLFST[store_SSID] = 1; 198 199 storeList[store_seq_num] = store_SSID; 200 201 DPRINTF(StoreSet, "Store %#x updated the LFST, SSID: %i\n", 202 store_PC, store_SSID); 203 } 204} 205 206InstSeqNum 207StoreSet::checkInst(Addr PC) 208{ 209 int index = calcIndex(PC); 210 211 int inst_SSID; 212 213 assert(index < SSITSize); 214 215 if (!validSSIT[index]) { 216 DPRINTF(StoreSet, "Inst %#x with index %i had no SSID\n", 217 PC, index); 218 219 // Return 0 if there's no valid entry. 220 return 0; 221 } else { 222 inst_SSID = SSIT[index]; 223 224 assert(inst_SSID < LFSTSize); 225 226 if (!validLFST[inst_SSID]) { 227 228 DPRINTF(StoreSet, "Inst %#x with index %i and SSID %i had no " 229 "dependency\n", PC, index, inst_SSID); 230 231 return 0; 232 } else { 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]); 235 236 return LFST[inst_SSID]; 237 } 238 } 239} 240 241void 242StoreSet::issued(Addr issued_PC, InstSeqNum issued_seq_num, bool is_store) 243{ 244 // This only is updated upon a store being issued. 245 if (!is_store) { 246 return; 247 } 248 249 int index = calcIndex(issued_PC); 250 251 int store_SSID; 252 253 assert(index < SSITSize); 254 255 SeqNumMapIt store_list_it = storeList.find(issued_seq_num); 256 257 if (store_list_it != storeList.end()) { 258 storeList.erase(store_list_it); 259 } 260 261 // Make sure the SSIT still has a valid entry for the issued store. 262 if (!validSSIT[index]) { 263 return; 264 } 265 266 store_SSID = SSIT[index]; 267 268 assert(store_SSID < LFSTSize); 269 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; 275 } 276} 277 278void 279StoreSet::squash(InstSeqNum squashed_num, unsigned tid) 280{ 281 DPRINTF(StoreSet, "StoreSet: Squashing until inum %i\n", 282 squashed_num); 283 284 int idx; 285 SeqNumMapIt store_list_it = storeList.begin(); 286 287 //@todo:Fix to only delete from correct thread 288 while (!storeList.empty()) { 289 idx = (*store_list_it).second; 290 291 if ((*store_list_it).first <= squashed_num) { 292 break; 293 } 294 295 bool younger = LFST[idx] > squashed_num; 296 297 if (validLFST[idx] && younger) { 298 DPRINTF(StoreSet, "Squashed [sn:%lli]\n", LFST[idx]); 299 validLFST[idx] = false; 300 301 storeList.erase(store_list_it++); 302 } else if (!validLFST[idx] && younger) { 303 storeList.erase(store_list_it++); 304 } 305 } 306} 307 308void 309StoreSet::clear() 310{ 311 for (int i = 0; i < SSITSize; ++i) { 312 validSSIT[i] = false; 313 } 314 315 for (int i = 0; i < LFSTSize; ++i) { 316 validLFST[i] = false; 317 } 318 319 storeList.clear(); 320} 321