diff --git a/src/gui/dialogs/new/newdialog.cpp b/src/gui/dialogs/new/newdialog.cpp index 1d325dea..b5499078 100644 --- a/src/gui/dialogs/new/newdialog.cpp +++ b/src/gui/dialogs/new/newdialog.cpp @@ -401,9 +401,7 @@ void NewDialog::bp_toggle_widgets() { // depending on the setting const machine::PredictorType predictor_type { config->get_bp_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_dynamic { machine::is_predictor_type_dynamic(predictor_type) }; const bool is_predictor_enabled { config->get_bp_enabled() }; ui->group_bp_bht->setEnabled(is_predictor_enabled && is_predictor_dynamic); diff --git a/src/gui/windows/predictor/predictor_bht_dock.cpp b/src/gui/windows/predictor/predictor_bht_dock.cpp index 76250294..a2b00c18 100644 --- a/src/gui/windows/predictor/predictor_bht_dock.cpp +++ b/src/gui/windows/predictor/predictor_bht_dock.cpp @@ -68,16 +68,16 @@ QTableWidgetItem* DockPredictorBHT::get_bht_cell_item(uint8_t row_index, uint8_t void DockPredictorBHT::set_table_color(QColor color) { for (uint16_t row_index = 0; row_index < bht->rowCount(); row_index++) { for (uint16_t column_index = 0; column_index < bht->columnCount(); column_index++) { - QTableWidgetItem *item { get_bht_cell_item(row_index, column_index) }; - item->setBackground(QBrush(color)); + get_bht_cell_item(row_index, column_index)->setBackground( + QBrush(color)); } } } void DockPredictorBHT::set_row_color(uint16_t row_index, QColor color) { for (uint16_t column_index = 0; column_index < bht->columnCount(); column_index++) { - QTableWidgetItem *item { get_bht_cell_item(row_index, column_index) }; - item->setBackground(QBrush(color)); + get_bht_cell_item(row_index, column_index)->setBackground( + QBrush(color)); } } @@ -91,9 +91,7 @@ void DockPredictorBHT::setup( number_of_bht_bits = branch_predictor->get_number_of_bht_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_dynamic { machine::is_predictor_type_dynamic(predictor_type) }; const bool is_predictor_enabled { branch_predictor->get_enabled() }; if (is_predictor_enabled) { @@ -173,22 +171,21 @@ void DockPredictorBHT::update_bht_row(uint16_t row_index, machine::BranchHistory } for (uint16_t column_index = 0; column_index < bht->columnCount(); column_index++) { - QTableWidgetItem *item; + get_bht_cell_item(row_index, DOCK_BHT_COL_STATE)->setData( + Qt::DisplayRole, machine::predictor_state_to_string(bht_entry.state, true).toString()); - item = get_bht_cell_item(row_index, DOCK_BHT_COL_STATE); - item->setData(Qt::DisplayRole, machine::predictor_state_to_string(bht_entry.state, true).toString()); + get_bht_cell_item(row_index, DOCK_BHT_COL_CORRECT)->setData( + Qt::DisplayRole, QString::number(bht_entry.stats.correct)); - item = get_bht_cell_item(row_index, DOCK_BHT_COL_CORRECT); - item->setData(Qt::DisplayRole, QString::number(bht_entry.stats.correct)); + get_bht_cell_item(row_index, DOCK_BHT_COL_INCORRECT)->setData( + Qt::DisplayRole, QString::number(bht_entry.stats.wrong)); - item = get_bht_cell_item(row_index, DOCK_BHT_COL_INCORRECT); - item->setData(Qt::DisplayRole, QString::number(bht_entry.stats.wrong)); - - item = get_bht_cell_item(row_index, DOCK_BHT_COL_ACCURACY); if (bht_entry.stats.total > 0) { - item->setData(Qt::DisplayRole, QString::number(bht_entry.stats.accuracy) + " %"); + get_bht_cell_item(row_index, DOCK_BHT_COL_ACCURACY)->setData( + Qt::DisplayRole, QString::number(bht_entry.stats.accuracy) + " %"); } else { - item->setData(Qt::DisplayRole, "N/A"); + get_bht_cell_item(row_index, DOCK_BHT_COL_ACCURACY)->setData( + Qt::DisplayRole, "N/A"); } } @@ -210,22 +207,20 @@ void DockPredictorBHT::clear_name() { void DockPredictorBHT::clear_bht(machine::PredictorState initial_state) { for (uint16_t row_index = 0; row_index < bht->rowCount(); row_index++) { - QTableWidgetItem *item; - - item = get_bht_cell_item(row_index, DOCK_BHT_COL_INDEX); - item->setData(Qt::DisplayRole, QString::number(row_index)); + get_bht_cell_item(row_index, DOCK_BHT_COL_INDEX)->setData( + Qt::DisplayRole, QString::number(row_index)); - item = get_bht_cell_item(row_index, DOCK_BHT_COL_STATE); - item->setData(Qt::DisplayRole, machine::predictor_state_to_string(initial_state, true).toString()); + get_bht_cell_item(row_index, DOCK_BHT_COL_STATE)->setData( + Qt::DisplayRole, machine::predictor_state_to_string(initial_state, true).toString()); - item = get_bht_cell_item(row_index, DOCK_BHT_COL_CORRECT); - item->setData(Qt::DisplayRole, QString::number(0)); + get_bht_cell_item(row_index, DOCK_BHT_COL_CORRECT)->setData( + Qt::DisplayRole, QString::number(0)); - item = get_bht_cell_item(row_index, DOCK_BHT_COL_INCORRECT); - item->setData(Qt::DisplayRole, QString::number(0)); + get_bht_cell_item(row_index, DOCK_BHT_COL_INCORRECT)->setData( + Qt::DisplayRole, QString::number(0)); - item = get_bht_cell_item(row_index, DOCK_BHT_COL_ACCURACY); - item->setData(Qt::DisplayRole, QString("N/A")); + get_bht_cell_item(row_index, DOCK_BHT_COL_ACCURACY)->setData( + Qt::DisplayRole, QString("N/A")); } bht->resizeRowsToContents(); set_table_color(Q_COLOR_DEFAULT); diff --git a/src/gui/windows/predictor/predictor_btb_dock.cpp b/src/gui/windows/predictor/predictor_btb_dock.cpp index 2cf8cf36..384ee785 100644 --- a/src/gui/windows/predictor/predictor_btb_dock.cpp +++ b/src/gui/windows/predictor/predictor_btb_dock.cpp @@ -48,16 +48,16 @@ QTableWidgetItem* DockPredictorBTB::get_btb_cell_item(uint8_t row_index, uint8_t void DockPredictorBTB::set_table_color(QColor color) { for (uint16_t row_index = 0; row_index < btb->rowCount(); row_index++) { for (uint16_t column_index = 0; column_index < btb->columnCount(); column_index++) { - QTableWidgetItem *item { get_btb_cell_item(row_index, column_index) }; - item->setBackground(QBrush(color)); + get_btb_cell_item(row_index, column_index)->setBackground( + QBrush(color)); } } } void DockPredictorBTB::set_row_color(uint16_t row_index, QColor color) { for (uint16_t column_index = 0; column_index < btb->columnCount(); column_index++) { - QTableWidgetItem *item { get_btb_cell_item(row_index, column_index) }; - item->setBackground(QBrush(color)); + get_btb_cell_item(row_index, column_index)->setBackground( + QBrush(color)); } } @@ -103,26 +103,24 @@ void DockPredictorBTB::update_btb_row( return; } - QTableWidgetItem *item; - 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)); + get_btb_cell_item(row_index, DOCK_BTB_COL_INSTR_ADDR)->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)); + get_btb_cell_item(row_index, DOCK_BTB_COL_TARGET_ADDR)->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()); + get_btb_cell_item(row_index, DOCK_BTB_COL_TYPE)->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, ""); + get_btb_cell_item(row_index, DOCK_BTB_COL_INSTR_ADDR)->setData( + Qt::DisplayRole, ""); - item = get_btb_cell_item(row_index, DOCK_BTB_COL_TARGET_ADDR); - item->setData(Qt::DisplayRole, ""); + get_btb_cell_item(row_index, DOCK_BTB_COL_TARGET_ADDR)->setData( + Qt::DisplayRole, ""); - item = get_btb_cell_item(row_index, DOCK_BTB_COL_TYPE); - item->setData(Qt::DisplayRole, ""); + get_btb_cell_item(row_index, DOCK_BTB_COL_TYPE)->setData( + Qt::DisplayRole, ""); } } @@ -140,19 +138,17 @@ void DockPredictorBTB::reset_colors() { void DockPredictorBTB::clear_btb() { for (uint16_t row_index = 0; row_index < btb->rowCount(); row_index++) { - QTableWidgetItem *item; - - item = get_btb_cell_item(row_index, DOCK_BTB_COL_INDEX); - item->setData(Qt::DisplayRole, QString::number(row_index)); + get_btb_cell_item(row_index, DOCK_BTB_COL_INDEX)->setData( + Qt::DisplayRole, QString::number(row_index)); - item = get_btb_cell_item(row_index, DOCK_BTB_COL_INSTR_ADDR); - item->setData(Qt::DisplayRole, QString("")); + get_btb_cell_item(row_index, DOCK_BTB_COL_INSTR_ADDR)->setData( + Qt::DisplayRole, QString("")); - item = get_btb_cell_item(row_index, DOCK_BTB_COL_TARGET_ADDR); - item->setData(Qt::DisplayRole, QString("")); + get_btb_cell_item(row_index, DOCK_BTB_COL_TARGET_ADDR)->setData( + Qt::DisplayRole, QString("")); - item = get_btb_cell_item(row_index, DOCK_BTB_COL_TYPE); - item->setData(Qt::DisplayRole, QString("")); + get_btb_cell_item(row_index, DOCK_BTB_COL_TYPE)->setData( + Qt::DisplayRole, QString("")); } btb->resizeRowsToContents(); set_table_color(Q_COLOR_DEFAULT); diff --git a/src/gui/windows/predictor/predictor_info_dock.cpp b/src/gui/windows/predictor/predictor_info_dock.cpp index 35b1c716..267cfae2 100644 --- a/src/gui/windows/predictor/predictor_info_dock.cpp +++ b/src/gui/windows/predictor/predictor_info_dock.cpp @@ -174,9 +174,7 @@ void DockPredictorInfo::setup( 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() }; - 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_dynamic = machine::is_predictor_type_dynamic(predictor_type); is_predictor_enabled = branch_predictor->get_enabled(); if (is_predictor_enabled) { @@ -194,40 +192,41 @@ void DockPredictorInfo::setup( this, &DockPredictorInfo::show_new_update); if (is_predictor_dynamic) { - connect( branch_predictor, &machine::BranchPredictor::bhr_updated, this, &DockPredictorInfo::update_bhr); } } - if (is_predictor_enabled) { - content->setDisabled(false); - } else { - content->setDisabled(true); - } - + // Toggle BHT index display if (is_predictor_dynamic) { 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 { 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); } - if (number_of_bhr_bits == 0) { + // Toggle BHR display + if (is_predictor_dynamic && number_of_bhr_bits > 0) { + label_bhr->setEnabled(true); + value_bhr->setEnabled(true); + } else { label_bhr->setEnabled(false); value_bhr->setEnabled(false); } + // Toggle whole widget + if (is_predictor_enabled) { + content->setDisabled(false); + } else { + content->setDisabled(true); + } + clear_bhr(); } diff --git a/src/machine/predictor.cpp b/src/machine/predictor.cpp index 1f6f7bea..e4bcdddc 100644 --- a/src/machine/predictor.cpp +++ b/src/machine/predictor.cpp @@ -51,6 +51,24 @@ QString machine::addr_to_hex_str(const machine::Address address) { return "0x" + zero_padding + hex_addr; } +bool machine::is_predictor_type_dynamic(const PredictorType type) { + switch (type) + { + case PredictorType::ALWAYS_NOT_TAKEN: + case PredictorType::ALWAYS_TAKEN: + case PredictorType::BTFNT: + return false; + + case PredictorType::SMITH_1_BIT: + case PredictorType::SMITH_2_BIT: + case PredictorType::SMITH_2_BIT_HYSTERESIS: + return true; + + default: + return false; + } +} + ///////////////////////////////// // BranchHistoryRegister class // ///////////////////////////////// diff --git a/src/machine/predictor.h b/src/machine/predictor.h index d49023ca..4aa3689c 100644 --- a/src/machine/predictor.h +++ b/src/machine/predictor.h @@ -21,6 +21,8 @@ QStringView branch_type_to_string(const BranchType type); QString addr_to_hex_str(const machine::Address address); +bool is_predictor_type_dynamic(const PredictorType type); + ///////////////////////////////// // BranchHistoryRegister class // ///////////////////////////////// @@ -138,7 +140,6 @@ class Predictor : public QObject { public: // General functions uint16_t calculate_bht_index(const uint16_t bhr_value, const Address instruction_address) const; virtual PredictorType get_type() const = 0; - virtual bool is_static() const = 0; virtual BranchResult predict(PredictionInput input) = 0; // Function which handles all actions ties // to making a branch prediction virtual void update(PredictionFeedback feedback) = 0; // Update predictor based on jump / branch @@ -169,7 +170,6 @@ class PredictorAlwaysNotTaken final : public Predictor { public: // General functions PredictorType get_type() const override { return PredictorType::ALWAYS_NOT_TAKEN; }; - bool is_static() const override { return true; }; BranchResult predict(PredictionInput input) override; void update(PredictionFeedback feedback) override; }; @@ -181,7 +181,6 @@ class PredictorAlwaysTaken final : public Predictor { public: // General functions PredictorType get_type() const override { return PredictorType::ALWAYS_TAKEN; }; - bool is_static() const override { return true; }; BranchResult predict(PredictionInput input) override; void update(PredictionFeedback feedback) override; }; @@ -193,7 +192,6 @@ class PredictorBTFNT final : public Predictor { public: // General functions PredictorType get_type() const override { return PredictorType::BTFNT; }; - bool is_static() const override { return true; }; BranchResult predict(PredictionInput input) override; void update(PredictionFeedback feedback) override; }; @@ -208,7 +206,6 @@ class PredictorSmith1Bit final : public Predictor { public: // General functions PredictorType get_type() const override { return PredictorType::SMITH_1_BIT; }; - bool is_static() const override { return false; }; BranchResult predict(PredictionInput input) override; void update(PredictionFeedback feedback) override; }; @@ -223,7 +220,6 @@ class PredictorSmith2Bit final : public Predictor { public: // General functions PredictorType get_type() const override { return PredictorType::SMITH_2_BIT; }; - bool is_static() const override { return false; }; BranchResult predict(PredictionInput input) override; void update(PredictionFeedback feedback) override; }; @@ -238,7 +234,6 @@ class PredictorSmith2BitHysteresis final : public Predictor { public: // General functions PredictorType get_type() const override { return PredictorType::SMITH_2_BIT_HYSTERESIS; }; - bool is_static() const override { return false; }; BranchResult predict(PredictionInput input) override; void update(PredictionFeedback feedback) override; };