|
5 | 5 |
|
6 | 6 | #include "base/types.hh" |
7 | 7 | #include "cpu/pred/btb/btb_tage.hh" |
8 | | -#include "cpu/pred/btb/btb_tage_ub.hh" |
9 | 8 | #include "cpu/pred/btb/common.hh" |
10 | 9 | #include "cpu/pred/btb/folded_hist.hh" |
11 | 10 |
|
@@ -1064,83 +1063,11 @@ TEST_F(BTBTAGETest, NewConditionalEntryWithoutPredictionMetaStillTrains) { |
1064 | 1063 | } |
1065 | 1064 |
|
1066 | 1065 | /** |
1067 | | - * @brief Test bank conflict detection |
| 1066 | + * @brief Test resolve-train bank conflict detection |
1068 | 1067 | * |
1069 | | - * Verifies: |
1070 | | - * 1. Same bank access causes conflict and drops update (when enabled) |
1071 | | - * 2. Different bank access has no conflict |
1072 | | - * 3. Disabled flag prevents conflict detection |
| 1068 | + * Verifies that a same-bank resolve-train update is rejected when bank |
| 1069 | + * conflict checking is enabled. |
1073 | 1070 | */ |
1074 | | -TEST_F(BTBTAGETest, BankConflict) { |
1075 | | - // Create TAGE with 4 banks |
1076 | | - BTBTAGE *bankTage = new BTBTAGE(4, 2, 1024, 4); |
1077 | | - boost::dynamic_bitset<> testHistory(128); |
1078 | | - std::vector<FullBTBPrediction> testStagePreds(5); |
1079 | | - |
1080 | | - // Bank ID derives from bits [2:1] (pc >> 1) & 0x3 when instShiftAmt == 1. |
1081 | | - // Bank 0: ..., 0x100, 0x108 ... Bank 1: ..., 0x102, 0x10A ... |
1082 | | - // Bank 2: ..., 0x104, 0x10C ... Bank 3: ..., 0x106, 0x10E ... |
1083 | | - |
1084 | | - // Test 1: Same bank conflict (enabled) |
1085 | | - bankTage->enableBankConflict = true; |
1086 | | - { |
1087 | | - // Predict on bank 1 (0x20), then update on bank 1 (0xa0) |
1088 | | - testStagePreds[1].btbEntries = {createBTBEntry(0x20)}; |
1089 | | - bankTage->putPCHistory(0x20, testHistory, testStagePreds); |
1090 | | - EXPECT_TRUE(bankTage->predBankValid); |
1091 | | - |
1092 | | - auto meta = bankTage->getPredictionMeta(); |
1093 | | - FetchTarget stream = createStream(0xa0, createBTBEntry(0xa0), true, meta); |
1094 | | - setupTageEntry(bankTage, 0xa0, 0, 1, false); |
1095 | | - |
1096 | | - uint64_t conflicts_before = bankTage->tageStats.updateBankConflict; |
1097 | | - bool can_update = bankTage->canResolveUpdate(stream); |
1098 | | - |
1099 | | - // Should detect conflict and defer update |
1100 | | - EXPECT_EQ(bankTage->tageStats.updateBankConflict, conflicts_before + 1); |
1101 | | - EXPECT_FALSE(can_update); |
1102 | | - EXPECT_FALSE(bankTage->predBankValid); |
1103 | | - } |
1104 | | - |
1105 | | - // Test 2: Different bank, no conflict |
1106 | | - { |
1107 | | - // Predict on bank 0 (0x100), update on bank 2 (0x104) |
1108 | | - testStagePreds[1].btbEntries = {createBTBEntry(0x100)}; |
1109 | | - bankTage->putPCHistory(0x100, testHistory, testStagePreds); |
1110 | | - |
1111 | | - auto meta = bankTage->getPredictionMeta(); |
1112 | | - FetchTarget stream = createStream(0x104, createBTBEntry(0x104), true, meta); |
1113 | | - |
1114 | | - uint64_t conflicts_before = bankTage->tageStats.updateBankConflict; |
1115 | | - bool can_update = bankTage->canResolveUpdate(stream); |
1116 | | - ASSERT_TRUE(can_update); |
1117 | | - bankTage->doResolveUpdate(stream); |
1118 | | - |
1119 | | - // Should not detect conflict |
1120 | | - EXPECT_EQ(bankTage->tageStats.updateBankConflict, conflicts_before); |
1121 | | - } |
1122 | | - |
1123 | | - // Test 3: Disabled flag prevents conflict |
1124 | | - bankTage->enableBankConflict = false; |
1125 | | - { |
1126 | | - // Same bank (0x20 and 0xa0), but conflict disabled |
1127 | | - testStagePreds[1].btbEntries = {createBTBEntry(0x20)}; |
1128 | | - bankTage->putPCHistory(0x20, testHistory, testStagePreds); |
1129 | | - |
1130 | | - auto meta = bankTage->getPredictionMeta(); |
1131 | | - FetchTarget stream = createStream(0xa0, createBTBEntry(0xa0), true, meta); |
1132 | | - setupTageEntry(bankTage, 0xa0, 0, 1, false); |
1133 | | - |
1134 | | - uint64_t conflicts_before = bankTage->tageStats.updateBankConflict; |
1135 | | - bool can_update = bankTage->canResolveUpdate(stream); |
1136 | | - ASSERT_TRUE(can_update); |
1137 | | - bankTage->doResolveUpdate(stream); |
1138 | | - |
1139 | | - // No conflict even with same bank |
1140 | | - EXPECT_EQ(bankTage->tageStats.updateBankConflict, conflicts_before); |
1141 | | - } |
1142 | | -} |
1143 | | - |
1144 | 1071 | TEST_F(BTBTAGETest, ResolveTrainBankConflict) { |
1145 | 1072 | BTBTAGE bankTage(4, 2, 1024, 4); |
1146 | 1073 | memset(&bankTage.tageStats, 0, sizeof(BTBTAGE::TageStats)); |
@@ -1282,132 +1209,6 @@ TEST_F(BTBTAGETest, ResolveTrainRepeatedShortPatternMatchesLegacyProviderGrowth) |
1282 | 1209 | << "Full resolve-train should build the same set of TAGE tables as legacy update"; |
1283 | 1210 | } |
1284 | 1211 |
|
1285 | | -class BTBTAGEUpperBoundTest : public ::testing::Test |
1286 | | -{ |
1287 | | - protected: |
1288 | | - void SetUp() override { |
1289 | | - tage = new BTBTAGEUpperBound(); |
1290 | | - memset(&tage->tageStats, 0, sizeof(BTBTAGE::TageStats)); |
1291 | | - history.resize(128, false); |
1292 | | - stagePreds.resize(2); |
1293 | | - } |
1294 | | - |
1295 | | - BTBTAGEUpperBound *tage; |
1296 | | - boost::dynamic_bitset<> history; |
1297 | | - std::vector<FullBTBPrediction> stagePreds; |
1298 | | -}; |
1299 | | - |
1300 | | -class BTBTAGEUpperBoundPathHashTest : public ::testing::Test |
1301 | | -{ |
1302 | | - protected: |
1303 | | - void SetUp() override { |
1304 | | - tage = new BTBTAGEUpperBound(4, 1024, 4, |
1305 | | - BTBTAGEUpperBound::HistorySource::PathHash); |
1306 | | - memset(&tage->tageStats, 0, sizeof(BTBTAGE::TageStats)); |
1307 | | - outcomeHistory.resize(128, false); |
1308 | | - pathHistory.resize(128, false); |
1309 | | - stagePreds.resize(2); |
1310 | | - } |
1311 | | - |
1312 | | - BTBTAGEUpperBound *tage; |
1313 | | - boost::dynamic_bitset<> outcomeHistory; |
1314 | | - boost::dynamic_bitset<> pathHistory; |
1315 | | - std::vector<FullBTBPrediction> stagePreds; |
1316 | | -}; |
1317 | | - |
1318 | | -TEST_F(BTBTAGEUpperBoundTest, ExactContextLookup) { |
1319 | | - BTBEntry entry = createBTBEntry(0x1000, true, true, false, -1); |
1320 | | - boost::dynamic_bitset<> historyA(128, 0); |
1321 | | - boost::dynamic_bitset<> historyB(128, 0); |
1322 | | - historyB[0] = true; |
1323 | | - |
1324 | | - ASSERT_TRUE(tage->insertExactEntry(3, entry.pc, historyA, 2)); |
1325 | | - EXPECT_TRUE(tage->hasExactEntry(3, entry.pc, historyA)); |
1326 | | - EXPECT_FALSE(tage->hasExactEntry(3, entry.pc, historyB)); |
1327 | | - |
1328 | | - bool predA = predictTAGE(tage, 0x1000, {entry}, historyA, stagePreds); |
1329 | | - bool predB = predictTAGE(tage, 0x1000, {entry}, historyB, stagePreds); |
1330 | | - |
1331 | | - EXPECT_TRUE(predA); |
1332 | | - EXPECT_FALSE(predB); |
1333 | | -} |
1334 | | - |
1335 | | -TEST_F(BTBTAGEUpperBoundTest, ProviderAltSelection) { |
1336 | | - BTBEntry entry = createBTBEntry(0x1000, true, true, false, -1); |
1337 | | - |
1338 | | - ASSERT_TRUE(tage->insertExactEntry(3, entry.pc, history, 0)); |
1339 | | - ASSERT_TRUE(tage->insertExactEntry(1, entry.pc, history, -2)); |
1340 | | - |
1341 | | - predictTAGE(tage, 0x1000, {entry}, history, stagePreds); |
1342 | | - auto meta = std::static_pointer_cast<BTBTAGE::TageMeta>(tage->getPredictionMeta()); |
1343 | | - auto pred = meta->preds[entry.pc]; |
1344 | | - |
1345 | | - EXPECT_EQ(pred.mainInfo.table, 3u); |
1346 | | - EXPECT_EQ(pred.altInfo.table, 1u); |
1347 | | - EXPECT_TRUE(pred.useAlt); |
1348 | | - EXPECT_FALSE(pred.taken); |
1349 | | -} |
1350 | | - |
1351 | | -TEST_F(BTBTAGEUpperBoundTest, AllocationUsesPredictionTimeHistory) { |
1352 | | - BTBEntry entry = createBTBEntry(0x1000, true, true, false, -1); |
1353 | | - boost::dynamic_bitset<> historyA(128, 0); |
1354 | | - boost::dynamic_bitset<> historyB(128, 0); |
1355 | | - historyB[0] = true; |
1356 | | - |
1357 | | - predictTAGE(tage, 0x1000, {entry}, historyA, stagePreds); |
1358 | | - auto meta = tage->getPredictionMeta(); |
1359 | | - |
1360 | | - FetchTarget stream = createStream(0x1000, entry, true, meta); |
1361 | | - stream = setMispredStream(stream); |
1362 | | - |
1363 | | - tage->recoverHist(historyB, stream, 1, true); |
1364 | | - tage->update(stream); |
1365 | | - |
1366 | | - EXPECT_TRUE(tage->hasExactEntry(0, entry.pc, historyA)); |
1367 | | - EXPECT_FALSE(tage->hasExactEntry(0, entry.pc, historyB)); |
1368 | | -} |
1369 | | - |
1370 | | -TEST_F(BTBTAGEUpperBoundTest, NewConditionalEntryWithoutPredictionMetaStillTrains) { |
1371 | | - boost::dynamic_bitset<> historyA(128, 0); |
1372 | | - stagePreds[1].btbEntries.clear(); |
1373 | | - tage->putPCHistory(0x1000, historyA, stagePreds); |
1374 | | - auto meta = tage->getPredictionMeta(); |
1375 | | - |
1376 | | - BTBEntry newEntry = createBTBEntry(0x1010, true, true, false, -1); |
1377 | | - FetchTarget stream; |
1378 | | - stream.startPC = 0x1000; |
1379 | | - stream.exeBranchInfo = newEntry; |
1380 | | - stream.exeTaken = true; |
1381 | | - stream.resolved = true; |
1382 | | - stream.predBranchInfo = newEntry; |
1383 | | - stream.updateBTBEntries.clear(); |
1384 | | - stream.updateIsOldEntry = false; |
1385 | | - stream.updateNewBTBEntry = newEntry; |
1386 | | - stream.predMetas[0] = meta; |
1387 | | - stream = setMispredStream(stream); |
1388 | | - |
1389 | | - tage->update(stream); |
1390 | | - |
1391 | | - EXPECT_TRUE(tage->hasExactEntry(0, newEntry.pc, historyA)); |
1392 | | -} |
1393 | | - |
1394 | | -TEST_F(BTBTAGEUpperBoundPathHashTest, PredictionUsesPathHashHistorySnapshot) { |
1395 | | - BTBEntry entry = createBTBEntry(0x1000, true, true, false, -1, 0x2000); |
1396 | | - boost::dynamic_bitset<> pathHistoryA(128, 0); |
1397 | | - boost::dynamic_bitset<> pathHistoryB(128, 0); |
1398 | | - applyPathHistoryTaken(pathHistoryB, entry.pc, entry.target); |
1399 | | - |
1400 | | - ASSERT_TRUE(tage->insertExactEntry(2, entry.pc, pathHistoryB, 2)); |
1401 | | - |
1402 | | - FullBTBPrediction pred; |
1403 | | - pred.btbEntries.push_back(entry); |
1404 | | - pred.condTakens.push_back({entry.pc, true}); |
1405 | | - tage->specUpdatePHist(pathHistoryA, pred); |
1406 | | - |
1407 | | - bool predicted = predictTAGE(tage, 0x1000, {entry}, outcomeHistory, stagePreds); |
1408 | | - |
1409 | | - EXPECT_TRUE(predicted); |
1410 | | -} |
1411 | 1212 |
|
1412 | 1213 |
|
1413 | 1214 | } // namespace test |
|
0 commit comments