Skip to content

Commit

Permalink
fix: enable BTB ckpt
Browse files Browse the repository at this point in the history
feat: add BTB json ckpt (back)

Because of the modification brought by TAGE to the BTB,
it was necessary to work it out again.
  • Loading branch information
branylagaffe committed Jul 16, 2024
1 parent 3690076 commit c58536c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
34 changes: 34 additions & 0 deletions components/BranchPredictor/BTB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,40 @@ BTB::update(BranchFeedback const& aFeedback)
return update(aFeedback.thePC, aFeedback.theActualType, aFeedback.theActualTarget);
}

json
BTB::saveState() const {

json checkpoint;

for(size_t i = 0; i < theBTBSets; i++){

checkpoint.emplace_back(json::array());

auto block = theBTB[i].blocks.begin();
auto end = theBTB[i].blocks.end();

size_t j = 0;
for (; block != end; block++, j++) {
uint8_t type = 15;
switch(block->theBranchType){
case kNonBranch: type = 0; break;
case kConditional: type = 1; break;
case kUnconditional: type = 2; break;
case kCall: type = 3; break;
case kIndirectReg: type = 4; break;
case kIndirectCall: type = 5; break;
case kReturn: type = 6; break;
default:
//DBG_Assert(false, (<< "Don't know how to save type " << block->theBranchType));
break;
}
checkpoint[i][j] = {{"PC", (uint64_t)block->thePC}, {"target", (uint64_t)block->theTarget}, {"type", (uint8_t)type}};
}
}

return checkpoint;

}
// void
// BTB::loadState(json checkpoint)
//{
Expand Down
4 changes: 4 additions & 0 deletions components/BranchPredictor/BTB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

#include "BTBSet.hpp"
#include "core/types.hpp"
#include "core/checkpoint/json.hpp"

#include <vector>

using json = nlohmann::json;
using namespace Flexus::SharedTypes;

class BTB
Expand Down Expand Up @@ -35,6 +37,8 @@ class BTB
// Update or add a new entry to the BTB
bool update(VirtualMemoryAddress aPC, eBranchType aType, VirtualMemoryAddress aTarget);
bool update(BranchFeedback const& aFeedback);

json saveState() const;
};

#endif
6 changes: 3 additions & 3 deletions components/BranchPredictor/BTBSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
*/
class BTBSet
{
private:
public:
std::vector<BTBEntry> blocks; // Array of blocks make up a set
private:
std::vector<uint32_t> replacementQueue;

void updateReplacementQueue(uint32_t index); // [MADHUR] Right now, it is LRU

//
public:
BTBSet();

Expand Down
4 changes: 2 additions & 2 deletions components/BranchPredictor/BranchPredictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ void BranchPredictor::saveState(std::string const& aDirName) {

json checkpoint;

// checkpoint["BTB"] = theBTB.saveState();
checkpoint["TAGE"] = theTage.saveState();
checkpoint["btb"] = theBTB.saveState();
checkpoint["tage"] = theTage.saveState();

ofs << std::setw(4) << checkpoint << std::endl;
ofs.close();
Expand Down

0 comments on commit c58536c

Please sign in to comment.