Skip to content

Commit

Permalink
some cleanup in prints and branch predictor
Browse files Browse the repository at this point in the history
  • Loading branch information
renau committed Jan 11, 2025
1 parent c2678a2 commit 9be72f6
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 84 deletions.
9 changes: 0 additions & 9 deletions core/fastqueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class FastQueue {
void push(Data d) {
I(nElems <= pipeMask);

printf("fastqueue ::push:: nElems is %lu and pipemask is %ld\n", nElems, pipeMask);
pipe[end] = d;
I(end == ((start + nElems) & pipeMask));
end = (end + 1) & pipeMask;
Expand All @@ -64,18 +63,12 @@ class FastQueue {

Data end_data() const {
I(nElems);
printf("fastqueue ::end_data :: Elements are %lu and end position is %ld and new end is %ld\n",
nElems,
pipeMask,
end,
end - 1);
return pipe[end ? end - 1 : pipeMask];
}

Data nilufar_push_to_end_data(Data d) {
I(nElems <= pipeMask);

printf("fastqueue ::push:: nElems is %lu and pipemask is %ld\n", nElems, pipeMask);
pipe[end + 1] = d;
I(end == ((start + nElems) & pipeMask));
end = (end + 1) & pipeMask;
Expand All @@ -90,10 +83,8 @@ class FastQueue {

void pop_from_back() {
I(nElems);
printf("fastqueue ::pop_from_back :: Before Elements are %lu and end position is %ld\n", nElems, end);
nElems--;
end = (end - 1) & pipeMask;
printf("fastqueue ::pop_from_back :: After Elements are %lu and end position is %ld\n", nElems, end);
}

[[nodiscard]] uint32_t getIDFromTop(uint32_t i) const {
Expand Down
53 changes: 18 additions & 35 deletions simu/BPred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void BPBTB::updateOnly(Dinst *dinst) {
}

Outcome BPBTB::predict(Dinst *dinst, bool doUpdate, bool doStats) {
bool ntaken = !dinst->isTaken();
I(dinst->isTaken()); // BTB should be called only when the branch is taken (predict taken & taken -> call BTB)

if (data == 0) {
// required when BPOracle
Expand All @@ -181,11 +181,6 @@ Outcome BPBTB::predict(Dinst *dinst, bool doUpdate, bool doStats) {
nHit.inc(doUpdate && dinst->has_stats() && doStats);
}

if (ntaken) {
// Trash result because it shouldn't have reach BTB. Otherwise, the
// worse the predictor, the better the results.
return Outcome::NoBTB;
}
return Outcome::Correct;
}

Expand All @@ -199,28 +194,6 @@ Outcome BPBTB::predict(Dinst *dinst, bool doUpdate, bool doStats) {
key ^= dolc->getSign(btbHistorySize, btbHistorySize);
}

if (ntaken || !doUpdate) {
// The branch is not taken. Do not update the cache
if (dinst->getInst()->doesCtrl2Label() && btbicache) {
nHitLabel.inc(doStats && doUpdate && dinst->has_stats());
return Outcome::NoBTB;
}

BTBCache::CacheLine *cl = data->readLine(key);

if (cl == 0) {
nHit.inc(doStats && doUpdate && dinst->has_stats());
return Outcome::NoBTB; // Outcome::NoBTB because BTAC would hide the prediction
}

if (cl->inst == dinst->getAddr()) {
nHit.inc(doStats && doUpdate && dinst->has_stats());
return Outcome::Correct;
}

nMiss.inc(doStats && doUpdate && dinst->has_stats());
return Outcome::Miss;
}

I(doUpdate);

Expand Down Expand Up @@ -1450,8 +1423,7 @@ BPredictor::BPredictor(int32_t i, MemObj *iobj, MemObj *dobj, std::shared_ptr<BP
, nFixes1(fmt::format("P({})_BPred:nFixes1", id))
, nFixes2(fmt::format("P({})_BPred:nFixes2", id))
, nFixes3(fmt::format("P({})_BPred:nFixes3", id))
, nUnFixes(fmt::format("P({})_BPred:nUnFixes", id))
, nAgree3(fmt::format("P({})_BPred:nAgree3", id)) {
, nUnFixes(fmt::format("P({})_BPred:nUnFixes", id)) {
auto cpu_section = Config::get_string("soc", "core", id);
auto ras_section = Config::get_array_string(cpu_section, "bpred", 0);
ras = std::make_unique<BPRas>(id, ras_section, "");
Expand Down Expand Up @@ -1612,18 +1584,28 @@ TimeDelta_t BPredictor::predict(Dinst *dinst, bool *fastfix) {
Outcome outcome3 = Outcome::None;
dinst->setBiasBranch(false);

// FIXME: Even if RAS has none, it should call predict (and ignore it) to
// update histories (it helps to build better history)
outcome1 = ras->doPredict(dinst);
if (outcome1 == Outcome::None) {
if (outcome1 != Outcome::None) { // If RAS, still call predictors to update history
predict1(dinst);
if (pred2) {
predict2(dinst);
}
if (pred3) {
predict3(dinst);
}
outcome2 = outcome1;
outcome3 = outcome1;
}else{
outcome1 = predict1(dinst);
// outcome2 = outcome1;
if (pred2) {
outcome2 = predict2(dinst);
}else{
outcome2 = outcome1;
}
// outcome3 = outcome2;
if (pred3) {
outcome3 = predict3(dinst);
}else{
outcome3 = outcome2;
}
}

Expand Down Expand Up @@ -1695,6 +1677,7 @@ TimeDelta_t BPredictor::predict(Dinst *dinst, bool *fastfix) {

// outcome == (Outcome::Correct, Outcome::Miss, Outcome::None, Outcome::NoBTB)
if (outcome1 == Outcome::Correct && outcome2 != Outcome::Miss && outcome3 != Outcome::Miss) {
fmt::print("out1{} out2{} out3{}\n", (int)outcome1, (int)outcome2, (int)outcome3);
nFixes1.inc(dinst->has_stats());
bpred_total_delay = bpredDelay1;
} else if (outcome1 != Outcome::Correct && outcome2 == Outcome::Correct && outcome3 != Outcome::Miss) {
Expand Down
1 change: 0 additions & 1 deletion simu/bpred.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,6 @@ class BPredictor {
Stats_cntr nFixes2;
Stats_cntr nFixes3;
Stats_cntr nUnFixes;
Stats_cntr nAgree3;

protected:
Outcome predict1(Dinst *dinst);
Expand Down
4 changes: 2 additions & 2 deletions simu/cluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class Cluster {
static inline std::map<std::string, std::pair<std::shared_ptr<Cluster>, Opcode_array<std::shared_ptr<Resource>>>> clusterMap;

void delEntry() {
printf("Cluster:::delEntry()windowsize is %d\n", windowSize);
//printf("Cluster:::delEntry()windowsize is %d\n", windowSize);
windowSize++;
printf("Cluster:::delEntry()windowsize++ is %d: \n", windowSize);
//printf("Cluster:::delEntry()windowsize++ is %d: \n", windowSize);
I(windowSize <= MaxWinSize);
}
void newEntry() {
Expand Down
1 change: 0 additions & 1 deletion simu/fetchengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ bool FetchEngine::processBranch(Dinst *dinst, uint16_t n2Fetch) {
#endif

if (fastfix) {
I(globalClock);
// dinst->getGProc()->flush_transient_inst_on_fetch_ready();
unBlockFetchBPredDelayCB::schedule(delay, this, dinst, globalClock);
} else {
Expand Down
38 changes: 19 additions & 19 deletions simu/oooprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ OoOProcessor::~OoOProcessor()
/* }}} */

bool OoOProcessor::advance_clock_drain() {
printf("OOOProc::advance_clock_drain ::decode_stage() is called\n");
printf("OOOProc::advance_clock_drain ::decode_stage()::dump_rat is called\n");
//printf("OOOProc::advance_clock_drain ::decode_stage() is called\n");
//printf("OOOProc::advance_clock_drain ::decode_stage()::dump_rat is called\n");

dump_rat();
//dump_rat();
bool abort = decode_stage();

if (abort || !busy) {
Expand Down Expand Up @@ -125,9 +125,9 @@ bool OoOProcessor::advance_clock_drain() {

if (!pipeQ.instQueue.empty()) {
auto n = issue();
printf("OOOprocessor:: spaceInInstQueue Before issue is %d !!!\n", spaceInInstQueue);
//printf("OOOprocessor:: spaceInInstQueue Before issue is %d !!!\n", spaceInInstQueue);
spaceInInstQueue += n;
printf("OOOprocessor:: spaceInInstQueue after issue is %d !!!\n", spaceInInstQueue);
//printf("OOOprocessor:: spaceInInstQueue after issue is %d !!!\n", spaceInInstQueue);
} else if (ROB.empty() && rROB.empty() && !pipeQ.pipeLine.hasOutstandingItems()) {
return false;
}
Expand All @@ -145,11 +145,11 @@ bool OoOProcessor::advance_clock() {
Tracer::advance_clock();

//<<<<<<< HEAD
printf("\nOOOProc::advance_clock() Leaving with pipeQ.InstQ.bucket size %ld\n", pipeQ.instQueue.size());
printf("OOOProc::advance_clock ::fetch()::dump_rat is called\n");
//printf("\nOOOProc::advance_clock() Leaving with pipeQ.InstQ.bucket size %ld\n", pipeQ.instQueue.size());
//printf("OOOProc::advance_clock ::fetch()::dump_rat is called\n");
fetch();
dump_rat();
printf("OOOProc::advance_clock ::fetch() is called\n");
//dump_rat();
//printf("OOOProc::advance_clock ::fetch() is called\n");
/*=======
fetch();
>>>>>>> upstream/main*/
Expand All @@ -168,7 +168,7 @@ void OoOProcessor::executing(Dinst *dinst)
}

// printf("OOOProc::Executing::dump_rat is called\n");
dump_rat();
// dump_rat();

Tracer::stage(dinst, "EX");

Expand Down Expand Up @@ -223,7 +223,7 @@ void OoOProcessor::executing(Dinst *dinst)
//
void OoOProcessor::executed([[maybe_unused]] Dinst *dinst) {
// printf("OOOProc::Executed::dump_rat is called\n");
dump_rat();
// dump_rat();
// if (dinst->isTransient()) {
// printf("OOOProc::executed Transientinst starts to executed\n");
// } else {
Expand Down Expand Up @@ -365,7 +365,7 @@ StallCause OoOProcessor::add_inst(Dinst *dinst) {
I(dinst->getCluster() != 0); // Resource::schedule must set the resource field

// printf("OOOProc::add_inst and dumprat before adding in RAT%ld\n", dinst->getID());
dump_rat();
// dump_rat();
int n = 0;
if (!dinst->isSrc2Ready()) {
// It already has a src2 dep. It means that it is solved at
Expand Down Expand Up @@ -460,7 +460,7 @@ StallCause OoOProcessor::add_inst(Dinst *dinst) {
// printf("OOOPROCCESOR::add_inst : done rename instID %ld\n", dinst->getID());

// printf("OOOProc::add_inst and dumprat after adding in RAT%ld\n", dinst->getID());
dump_rat();
// dump_rat();
//=======

//>>>>>>> upstream/main
Expand Down Expand Up @@ -523,9 +523,9 @@ void OoOProcessor::try_flush(Dinst *dinst) {

void OoOProcessor::retire() {
//<<<<<<< HEAD
printf("\nOOOProc::retire Entering \n");
printf("\nOOOProc::retire dump_rat starting \n");
dump_rat();
//printf("\nOOOProc::retire Entering \n");
//printf("\nOOOProc::retire dump_rat starting \n");
// dump_rat();
#ifdef ENABLE_LDBP
int64_t gclock = int64_t(clockTicks.getDouble());
if (gclock != power_clock) {
Expand Down Expand Up @@ -810,9 +810,9 @@ void OoOProcessor::retire() {
//<<<<<<< HEAD
} // !rROB.empty()_loop_ends

printf("OOOProcessor::retire Exiting from retire \n");
printf("\nOOOProc::retire dump_rat Leaving \n");
dump_rat();
//printf("OOOProcessor::retire Exiting from retire \n");
//printf("\nOOOProc::retire dump_rat Leaving \n");
//dump_rat();
//=======
//} // !rROB.empty()_loop_ends
//>>>>>>> upstream/main
Expand Down
31 changes: 14 additions & 17 deletions simu/Pipeline.cpp → simu/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void IBucket::markFetched() {
// MSG("@%lld: markFetched Bucket[%p]",(long long int)globalClock, this);
}

printf("Pipeline::readyitem::markfetched() complete\n");
//printf("Pipeline::readyitem::markfetched() complete\n");
pipeLine->readyItem(this);
}

Expand Down Expand Up @@ -83,7 +83,7 @@ void Pipeline::readyItem(IBucket *b) {
doneItem(b);
} else {
buffer.push(b);
printf("Pipeline::readyitem::buffersize is %lu\n", buffer.size());
//printf("Pipeline::readyitem::buffersize is %lu\n", buffer.size());
}

clearItems(); // Try to insert on minItem reveiced (OoO) buckets
Expand Down Expand Up @@ -204,9 +204,6 @@ void Pipeline::flush_transient_inst_from_buffer() {
while (!bucket->empty()) {
// auto *dinst = bucket->top();
auto *dinst = bucket->end_data();
if (dinst->getID() == 3205) {
printf("\nPIPELINE::PRINT 3205\n");
}
I(dinst);
// if (dinst) {
// printf("Pipeline::flush::bucket.size is %lu and instID %ld and Transient is %b\n",
Expand Down Expand Up @@ -249,7 +246,7 @@ void Pipeline::flush_transient_inst_from_buffer() {
}
} // while_!bucket_empty buffer.pop();
if (bucket->empty()) {
printf("Pipeline::flush::bucket.empty () \n");
//printf("Pipeline::flush::bucket.empty () \n");
I(bucket->empty());
bucket->clock = 0;
buffer.pop_from_back();
Expand All @@ -266,14 +263,14 @@ void Pipeline::flush_transient_inst_from_buffer() {
IBucket *Pipeline::next_item_transient_adding_to_rob() {
if (transient_buffer.empty()) {
clearItems();
printf("Pipeline::nextItemtran return 0 ::buffer.top() \n");
//printf("Pipeline::nextItemtran return 0 ::buffer.top() \n");
return 0;
}
printf("Pipeline::nextItemtran adding_to_rob::buffer.top() \n");
// printf("Pipeline::nextItemtran adding_to_rob::buffer.top() \n");
// I(!buffer.empty());
// I(buffer.top() != 0);
IBucket *b = transient_buffer.top();
printf("Pipeline::nextItemtran after adding_to_rob::buffer.top() \n");
// printf("Pipeline::nextItemtran after adding_to_rob::buffer.top() \n");
I(!transient_buffer.empty());
transient_buffer.pop();
/*if (b->empty()) {
Expand All @@ -290,16 +287,16 @@ IBucket *Pipeline::next_item_transient_adding_to_rob() {
// I(b->top() != 0);

//<<<<<<< HEAD
printf("Pipeline::buffer->nextItem()::returns! \n");
// printf("Pipeline::buffer->nextItem()::returns! \n");
if (b) {
return b;
} else {
printf(" Pipeline::next_item_transient_adding_to_rob return no buffer.top \n");
// printf(" Pipeline::next_item_transient_adding_to_rob return no buffer.top \n");
return 0;
}
}
/*IBucket *Pipeline::next_item_transient() {
printf("Pipeline::nextItemtran::buffer.top() \n");
// printf("Pipeline::nextItemtran::buffer.top() \n");
//I(!buffer.empty());
//I(buffer.top() != 0);
IBucket *b = buffer.top();
Expand All @@ -313,11 +310,11 @@ IBucket *Pipeline::next_item_transient_adding_to_rob() {
I(b->top() != 0);
//<<<<<<< HEAD
printf("Pipeline::buffer->nextItem()::returns! \n");
// printf("Pipeline::buffer->nextItem()::returns! \n");
if(b) {
return b;
} else {
printf(" Pipeline::next_item_transient return no buffer.top \n");
// printf(" Pipeline::next_item_transient return no buffer.top \n");
return 0;
}
}
Expand All @@ -328,7 +325,7 @@ IBucket *Pipeline::next_item_transient_adding_to_rob() {
//}
//>>>>>>> upstream/main
IBucket *Pipeline::next_item_transient() {
printf("Pipeline::nextItemtran::buffer_end_data() \n");
// printf("Pipeline::nextItemtran::buffer_end_data() \n");
// I(!buffer.empty());
// I(buffer.top() != 0);
IBucket *b = buffer.end_data();
Expand All @@ -343,11 +340,11 @@ IBucket *Pipeline::next_item_transient() {
I(b->top() != 0);

//<<<<<<< HEAD
printf("Pipeline::buffer->nextItem()::returns! \n");
// printf("Pipeline::buffer->nextItem()::returns! \n");
if (b) {
return b;
} else {
printf(" Pipeline::next_item_transient return no buffer.top \n");
// printf(" Pipeline::next_item_transient return no buffer.top \n");
return 0;
}
}
Expand Down

0 comments on commit 9be72f6

Please sign in to comment.