Skip to content

Commit

Permalink
BTB now updates with NT, restructured predictor code, changed how sta…
Browse files Browse the repository at this point in the history
…ts are updated, GUI fixes
  • Loading branch information
jiristefan authored and ppisa committed Aug 26, 2024
1 parent 0f2d64d commit edf5156
Show file tree
Hide file tree
Showing 9 changed files with 396 additions and 405 deletions.
37 changes: 25 additions & 12 deletions src/gui/windows/predictor/predictor_bht_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ void DockPredictorBHT::setup(
const machine::BranchPredictor *branch_predictor,
const machine::Core *core) {

clear();

number_of_bhr_bits = branch_predictor->get_number_of_bhr_bits();
number_of_bht_bits = branch_predictor->get_number_of_bht_bits();
initial_state = branch_predictor->get_initial_state();
Expand Down Expand Up @@ -119,9 +121,6 @@ void DockPredictorBHT::setup(
connect(
branch_predictor, &machine::BranchPredictor::predictor_bht_row_updated,
this, &DockPredictorBHT::update_bht_row);
connect(
branch_predictor, &machine::BranchPredictor::cleared,
this, &DockPredictorBHT::clear);
} else {
bht->setDisabled(true);
bht->setRowCount(0);
Expand All @@ -136,26 +135,35 @@ void DockPredictorBHT::show_new_prediction(
uint16_t btb_index,
uint16_t bht_index,
machine::PredictionInput input,
machine::BranchResult result) {
machine::BranchResult result,
machine::BranchType branch_type) {
UNUSED(btb_index);
UNUSED(input);
UNUSED(result);
set_row_color(bht_index, Q_COLOR_PREDICT);
if (branch_type == machine::BranchType::BRANCH) {
set_row_color(bht_index, Q_COLOR_PREDICT);
}
}

void DockPredictorBHT::show_new_update(
uint16_t btb_index,
uint16_t bht_index,
machine::PredictionFeedback feedback) {
UNUSED(btb_index);
UNUSED(feedback);
set_row_color(bht_index, Q_COLOR_UPDATE);
if (feedback.branch_type == machine::BranchType::BRANCH) {
set_row_color(bht_index, Q_COLOR_UPDATE);
}
}

void DockPredictorBHT::update_predictor_stats(machine::PredictionStatistics stats) {
label_stats_correct_value->setText(QString::number(stats.number_of_correct_predictions));
label_stats_wrong_value->setText(QString::number(stats.number_of_wrong_predictions));
label_stats_correct_value->setText(QString::number(stats.correct));
label_stats_wrong_value->setText(QString::number(stats.wrong));
label_stats_accuracy_value->setText(QString::number(stats.accuracy) + " %");
if (stats.total > 0) {
label_stats_accuracy_value->setText(QString::number(stats.accuracy) + " %");
} else {
label_stats_accuracy_value->setText("N/A");
}
}

void DockPredictorBHT::update_bht_row(uint16_t row_index, machine::BranchHistoryTableEntry bht_entry) {
Expand All @@ -171,13 +179,18 @@ void DockPredictorBHT::update_bht_row(uint16_t row_index, machine::BranchHistory
item->setData(Qt::DisplayRole, machine::predictor_state_to_string(bht_entry.state, true).toString());

item = get_bht_cell_item(row_index, DOCK_BHT_COL_CORRECT);
item->setData(Qt::DisplayRole, QString::number(bht_entry.stats.number_of_correct_predictions));
item->setData(Qt::DisplayRole, QString::number(bht_entry.stats.correct));

item = get_bht_cell_item(row_index, DOCK_BHT_COL_INCORRECT);
item->setData(Qt::DisplayRole, QString::number(bht_entry.stats.number_of_wrong_predictions));
item->setData(Qt::DisplayRole, QString::number(bht_entry.stats.wrong));

item = get_bht_cell_item(row_index, DOCK_BHT_COL_ACCURACY);
item->setData(Qt::DisplayRole, QString::number(bht_entry.stats.accuracy) + " %");
if (bht_entry.stats.total > 0) {
item->setData(Qt::DisplayRole, QString::number(bht_entry.stats.accuracy) + " %");
} else {
item->setData(Qt::DisplayRole, "N/A");
}

}
}

Expand Down
3 changes: 2 additions & 1 deletion src/gui/windows/predictor/predictor_bht_dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public slots:
uint16_t btb_index,
uint16_t bht_index,
machine::PredictionInput input,
machine::BranchResult result);
machine::BranchResult result,
machine::BranchType branch_type);
void show_new_update(
uint16_t btb_index,
uint16_t bht_index,
Expand Down
32 changes: 20 additions & 12 deletions src/gui/windows/predictor/predictor_btb_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ void DockPredictorBTB::setup(
const machine::BranchPredictor *branch_predictor,
const machine::Core *core) {

clear();

number_of_bits = init_number_of_bits(branch_predictor->get_number_of_btb_bits());
const bool is_predictor_enabled { branch_predictor->get_enabled() };

Expand All @@ -77,14 +79,11 @@ void DockPredictorBTB::setup(
branch_predictor, &machine::BranchPredictor::btb_row_updated,
this, &DockPredictorBTB::update_btb_row);
connect(
branch_predictor, &machine::BranchPredictor::btb_target_address_requested,
branch_predictor, &machine::BranchPredictor::prediction_done,
this, &DockPredictorBTB::highligh_row_after_prediction);
connect(
branch_predictor, &machine::BranchPredictor::btb_row_updated,
branch_predictor, &machine::BranchPredictor::update_done,
this, &DockPredictorBTB::highligh_row_after_update);
connect(
branch_predictor, &machine::BranchPredictor::cleared,
this, &DockPredictorBTB::clear_btb);
connect(
core, &machine::Core::step_started,
this, &DockPredictorBTB::reset_colors);
Expand All @@ -106,16 +105,25 @@ void DockPredictorBTB::update_btb_row(

QTableWidgetItem *item;

item = get_btb_cell_item(row_index, DOCK_BTB_COL_INSTR_ADDR);
item->setData(Qt::DisplayRole, machine::addr_to_hex_str(btb_entry.instruction_address));
if (btb_entry.entry_valid) {
item = get_btb_cell_item(row_index, DOCK_BTB_COL_INSTR_ADDR);
item->setData(Qt::DisplayRole, machine::addr_to_hex_str(btb_entry.instruction_address));

item = get_btb_cell_item(row_index, DOCK_BTB_COL_TARGET_ADDR);
item->setData(Qt::DisplayRole, machine::addr_to_hex_str(btb_entry.target_address));
item = get_btb_cell_item(row_index, DOCK_BTB_COL_TARGET_ADDR);
item->setData(Qt::DisplayRole, machine::addr_to_hex_str(btb_entry.target_address));

item = get_btb_cell_item(row_index, DOCK_BTB_COL_TYPE);
item->setData(Qt::DisplayRole, machine::branch_type_to_string(btb_entry.branch_type).toString());
item = get_btb_cell_item(row_index, DOCK_BTB_COL_TYPE);
item->setData(Qt::DisplayRole, machine::branch_type_to_string(btb_entry.branch_type).toString());
} else {
item = get_btb_cell_item(row_index, DOCK_BTB_COL_INSTR_ADDR);
item->setData(Qt::DisplayRole, "");

set_row_color(row_index, Q_COLOR_UPDATE);
item = get_btb_cell_item(row_index, DOCK_BTB_COL_TARGET_ADDR);
item->setData(Qt::DisplayRole, "");

item = get_btb_cell_item(row_index, DOCK_BTB_COL_TYPE);
item->setData(Qt::DisplayRole, "");
}
}

void DockPredictorBTB::highligh_row_after_prediction(uint16_t row_index) {
Expand Down
4 changes: 2 additions & 2 deletions src/gui/windows/predictor/predictor_btb_dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class DockPredictorBTB : public QDockWidget {

public slots:
void update_btb_row(uint16_t row_index, machine::BranchTargetBufferEntry btb_entry);
void highligh_row_after_prediction(uint16_t row_index);
void highligh_row_after_update(uint16_t row_index);
void highligh_row_after_prediction(uint16_t btb_index);
void highligh_row_after_update(uint16_t btb_index);
void reset_colors();
void clear_btb();
void clear();
Expand Down
68 changes: 47 additions & 21 deletions src/gui/windows/predictor/predictor_info_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,51 +149,55 @@ void DockPredictorInfo::set_predict_widget_color(QString color_stylesheet) {
value_event_predict_instruction->setStyleSheet(color_stylesheet);
value_event_predict_address->setStyleSheet(color_stylesheet);
value_event_predict_index_btb->setStyleSheet(color_stylesheet);
value_event_predict_index_bht->setStyleSheet(color_stylesheet);
if (is_predictor_dynamic) {
value_event_predict_index_bht->setStyleSheet(color_stylesheet);
}
value_event_predict_result->setStyleSheet(color_stylesheet);
}

void DockPredictorInfo::set_update_widget_color(QString color_stylesheet) {
value_event_update_instruction->setStyleSheet(color_stylesheet);
value_event_update_address->setStyleSheet(color_stylesheet);
value_event_update_index_btb->setStyleSheet(color_stylesheet);
value_event_update_index_bht->setStyleSheet(color_stylesheet);
if (is_predictor_dynamic) {
value_event_update_index_bht->setStyleSheet(color_stylesheet);
}
value_event_update_result->setStyleSheet(color_stylesheet);
}

void DockPredictorInfo::setup(
const machine::BranchPredictor *branch_predictor,
const machine::Core *core) {

clear();

number_of_bhr_bits = branch_predictor->get_number_of_bhr_bits();
initial_state = branch_predictor->get_initial_state();
const machine::PredictorType predictor_type { branch_predictor->get_predictor_type() };
const bool is_predictor_dynamic { predictor_type == machine::PredictorType::SMITH_1_BIT
|| predictor_type == machine::PredictorType::SMITH_2_BIT
|| predictor_type == machine::PredictorType::SMITH_2_BIT_HYSTERESIS };
const bool is_predictor_enabled { branch_predictor->get_enabled() };
is_predictor_dynamic = predictor_type == machine::PredictorType::SMITH_1_BIT
|| predictor_type == machine::PredictorType::SMITH_2_BIT
|| predictor_type == machine::PredictorType::SMITH_2_BIT_HYSTERESIS;
is_predictor_enabled = branch_predictor->get_enabled();

if (is_predictor_enabled) {
connect(
branch_predictor, &machine::BranchPredictor::predictor_stats_updated,
branch_predictor, &machine::BranchPredictor::total_stats_updated,
this, &DockPredictorInfo::update_stats);
connect(
branch_predictor, &machine::BranchPredictor::prediction_done,
this, &DockPredictorInfo::show_new_prediction);
connect(
core, &machine::Core::step_started,
this, &DockPredictorInfo::reset_colors);
connect(
branch_predictor, &machine::BranchPredictor::update_done,
this, &DockPredictorInfo::show_new_update);

if (is_predictor_dynamic) {
connect(
branch_predictor, &machine::BranchPredictor::update_done,
this, &DockPredictorInfo::show_new_update);

connect(
branch_predictor, &machine::BranchPredictor::bhr_updated,
this, &DockPredictorInfo::update_bhr);
connect(
branch_predictor, &machine::BranchPredictor::cleared,
this, &DockPredictorInfo::clear_bhr);
}
}

Expand All @@ -204,9 +208,19 @@ void DockPredictorInfo::setup(
}

if (is_predictor_dynamic) {
group_event_update->setDisabled(false);
label_event_predict_index_bht->setEnabled(true);
value_event_predict_index_bht->setEnabled(true);
label_event_update_index_bht->setEnabled(true);
value_event_update_index_bht->setEnabled(true);
label_bhr->setEnabled(true);
value_bhr->setEnabled(true);
} else {
group_event_update->setDisabled(true);
label_event_predict_index_bht->setEnabled(false);
value_event_predict_index_bht->setEnabled(false);
label_event_update_index_bht->setEnabled(false);
value_event_update_index_bht->setEnabled(false);
label_bhr->setEnabled(false);
value_bhr->setEnabled(false);
}

clear_bhr();
Expand All @@ -227,11 +241,18 @@ void DockPredictorInfo::show_new_prediction(
uint16_t btb_index,
uint16_t bht_index,
machine::PredictionInput input,
machine::BranchResult result) {
machine::BranchResult result,
machine::BranchType branch_type) {
value_event_predict_instruction->setText(input.instruction.to_str());
value_event_predict_address->setText(addr_to_hex_str(input.instruction_address));
value_event_predict_index_btb->setText(QString::number(btb_index));
value_event_predict_index_bht->setText(QString::number(bht_index));
if (!is_predictor_dynamic) {
value_event_predict_index_bht->setText("");
} else if (branch_type == machine::BranchType::BRANCH) {
value_event_predict_index_bht->setText(QString::number(bht_index));
} else {
value_event_predict_index_bht->setText("N/A");
}
value_event_predict_result->setText(machine::branch_result_to_string(result).toString());
set_predict_widget_color(STYLESHEET_COLOR_PREDICT);
}
Expand All @@ -243,16 +264,21 @@ void DockPredictorInfo::show_new_update(
value_event_update_instruction->setText(feedback.instruction.to_str());
value_event_update_address->setText(addr_to_hex_str(feedback.instruction_address));
value_event_update_index_btb->setText(QString::number(btb_index));
value_event_update_index_bht->setText(QString::number(bht_index));
if (!is_predictor_dynamic) {
value_event_update_index_bht->setText("");
} else if (feedback.branch_type == machine::BranchType::BRANCH ) {
value_event_update_index_bht->setText(QString::number(bht_index));
} else {
value_event_update_index_bht->setText("N/A");
}
value_event_update_result->setText(
machine::branch_result_to_string(feedback.result).toString());
set_update_widget_color(STYLESHEET_COLOR_UPDATE);
}

void DockPredictorInfo::update_stats(machine::PredictionStatistics stats) {
// TODO
label_stats_total_value->setText(QString::number(stats.number_of_correct_predictions));
label_stats_miss_value->setText(QString::number(stats.number_of_wrong_predictions));
label_stats_total_value->setText(QString::number(stats.correct));
label_stats_miss_value->setText(QString::number(stats.wrong));
label_stats_accuracy_value->setText(QString::number(stats.accuracy) + " %");
}

Expand Down
5 changes: 4 additions & 1 deletion src/gui/windows/predictor/predictor_info_dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public slots:
uint16_t btb_index,
uint16_t bht_index,
machine::PredictionInput input,
machine::BranchResult result);
machine::BranchResult result,
machine::BranchType branch_type);
void show_new_update(
uint16_t btb_index,
uint16_t bht_index,
Expand All @@ -67,6 +68,8 @@ public slots:
void clear();

private: // Internal variables
bool is_predictor_enabled{ false };
bool is_predictor_dynamic{ false };
uint8_t number_of_bhr_bits{ 0 };
machine::PredictorState initial_state{ machine::PredictorState::UNDEFINED };

Expand Down
8 changes: 6 additions & 2 deletions src/machine/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ enum ExceptionCause Core::memory_special(
case AC_CACHE_OP:
mem_data->sync();
mem_program->sync();
predictor->clear();
predictor->flush();
break;
case AC_LR32:
if (!memread) { break; }
Expand Down Expand Up @@ -721,7 +721,11 @@ void CorePipelined::handle_stall(const FetchInterstage &saved_if_id) {
}

bool CorePipelined::detect_mispredicted_jump() const {
return mem_wb.computed_next_inst_addr != mem_wb.predicted_next_inst_addr;
bool misprediction = mem_wb.computed_next_inst_addr != mem_wb.predicted_next_inst_addr;
if (misprediction) {
predictor->increment_mispredictions();
}
return misprediction;
}

bool CorePipelined::is_stall_requested() const {
Expand Down
Loading

0 comments on commit edf5156

Please sign in to comment.