Skip to content

Commit

Permalink
br_pred
Browse files Browse the repository at this point in the history
  • Loading branch information
William Song authored and William Song committed May 14, 2023
1 parent 603994a commit ed1e995
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions br_predictor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ br_predictor_t::~br_predictor_t() {
}

// Is a branch predicted to be taken?
bool br_predictor_t::is_taken(uint64_t m_pc) {
bool br_predictor_t::is_taken(inst_t *m_inst) {
// Predict always not taken.
return false;
}

// Update a prediction counter.
void br_predictor_t::update(uint64_t m_pc, bool m_taken) {
void br_predictor_t::update(inst_t *m_inst) {
}


Expand Down
5 changes: 3 additions & 2 deletions br_predictor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
#define __BR_PRED_H__

#include <cstdint>
#include "inst.h"

// Branch predictor
class br_predictor_t {
public:
br_predictor_t(unsigned m_bht_bits, unsigned m_pht_bits, unsigned m_hist_len);
~br_predictor_t();

bool is_taken(uint64_t m_pc); // Is a branch predicted to be taken?
void update(uint64_t m_pc, bool m_taken); // Update a prediction counter.
bool is_taken(inst_t *m_inst); // Is a branch predicted to be taken?
void update(inst_t *m_inst); // Update a prediction counter.

private:
unsigned *bht; // Branch history table (BHT)
Expand Down
4 changes: 2 additions & 2 deletions proc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void proc_t::writeback() {
if(inst->branch_target) {
#ifdef BR_PRED
num_br_predicts++;
br_predictor->update(inst->pc, inst->branch_taken);
br_predictor->update(inst);
if(inst->branch_taken) {
br_target_buffer->update(inst->pc, inst->branch_target);
}
Expand Down Expand Up @@ -211,7 +211,7 @@ void proc_t::fetch() {
if(get_op_type(inst->op) == op_sb_type) {
#ifdef BR_PRED
// Set the PC to a branch target if the branch is predicted to be taken.
inst->pred_taken = br_predictor->is_taken(inst->pc);
inst->pred_taken = br_predictor->is_taken(inst);
pc = inst->pred_target = inst->pred_taken ?
br_target_buffer->get_target(inst->pc) : pc;
#else
Expand Down

0 comments on commit ed1e995

Please sign in to comment.