Skip to content

Commit

Permalink
Branch predictor GUI and config: switch to custom when changed, switc…
Browse files Browse the repository at this point in the history
…h off by presets

The predictor configuration should be exactly defined for each
present. Whench chnaged presets page should switch to the custom choice.

The logic is implemented now. The switch2custom prevents its
own (possibly infinite) recursion. The switch2custom calls
are guarded by condition to check for the change.

Because labda(s) with if statements are quite complex,
they are moved to functions named descriptively.
BHT computed parameters redundant update code has
been unified into new function.

Signed-off-by: Pavel Pisa <[email protected]>
  • Loading branch information
ppisa committed Sep 24, 2024
1 parent 0547088 commit e6338c7
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 30 deletions.
101 changes: 73 additions & 28 deletions src/gui/dialogs/new/newdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,35 +130,23 @@ NewDialog::NewDialog(QWidget *parent, QSettings *settings) : QDialog(parent) {
connect(ui->osemu_fs_root, &QLineEdit::textChanged, this, &NewDialog::osemu_fs_root_change);

// Branch predictor
connect(ui->group_bp, QOverload<bool>::of(&QGroupBox::toggled), this, [this] {
config->set_bp_enabled(ui->group_bp->isChecked());
bp_toggle_widgets();
});
connect(
ui->group_bp, QOverload<bool>::of(&QGroupBox::toggled), this,
&NewDialog::bp_enabled_change);
connect(
ui->select_bp_type, QOverload<int>::of(&QComboBox::activated), this,
&NewDialog::bp_type_change);
connect(ui->select_bp_init_state, QOverload<int>::of(&QComboBox::activated), this, [this] {
config->set_bp_init_state(
ui->select_bp_init_state->currentData().value<machine::PredictorState>());
});
connect(ui->slider_bp_btb_addr_bits, &QAbstractSlider::valueChanged, this, [this] {
config->set_bp_btb_bits((uint8_t)ui->slider_bp_btb_addr_bits->value());
ui->text_bp_btb_addr_bits_number->setText(QString::number(config->get_bp_btb_bits()));
ui->text_bp_btb_bits_number->setText(QString::number(config->get_bp_btb_bits()));
ui->text_bp_btb_entries_number->setText(QString::number(qPow(2, config->get_bp_btb_bits())));
});
connect(ui->slider_bp_bht_bhr_bits, &QAbstractSlider::valueChanged, this, [this] {
config->set_bp_bhr_bits((uint8_t)ui->slider_bp_bht_bhr_bits->value());
ui->text_bp_bht_bhr_bits_number->setText(QString::number(config->get_bp_bhr_bits()));
ui->text_bp_bht_bits_number->setText(QString::number(config->get_bp_bht_bits()));
ui->text_bp_bht_entries_number->setText(QString::number(qPow(2, config->get_bp_bht_bits())));
});
connect(ui->slider_bp_bht_addr_bits, &QAbstractSlider::valueChanged, this, [this] {
config->set_bp_bht_addr_bits((uint8_t)ui->slider_bp_bht_addr_bits->value());
ui->text_bp_bht_addr_bits_number->setText(QString::number(config->get_bp_bht_addr_bits()));
ui->text_bp_bht_bits_number->setText(QString::number(config->get_bp_bht_bits()));
ui->text_bp_bht_entries_number->setText(QString::number(qPow(2, config->get_bp_bht_bits())));
});
connect(
ui->select_bp_init_state, QOverload<int>::of(&QComboBox::activated), this,
&NewDialog::bp_init_state_change);
connect(
ui->slider_bp_btb_addr_bits, &QAbstractSlider::valueChanged, this,
&NewDialog::bp_btb_addr_bits_change);
connect(
ui->slider_bp_bht_bhr_bits, &QAbstractSlider::valueChanged, this,
&NewDialog::bp_bht_bhr_bits_change);
connect(ui->slider_bp_bht_addr_bits, &QAbstractSlider::valueChanged, this,
&NewDialog::bp_bht_addr_bits_change);

cache_handler_d = new NewDialogCacheHandler(this, ui_cache_d.data());
cache_handler_p = new NewDialogCacheHandler(this, ui_cache_p.data());
Expand All @@ -172,8 +160,10 @@ NewDialog::NewDialog(QWidget *parent, QSettings *settings) : QDialog(parent) {
}

void NewDialog::switch2custom() {
ui->preset_custom->setChecked(true);
config_gui();
if (!ui->preset_custom->isChecked()) {
ui->preset_custom->setChecked(true);
config_gui();
}
}

void NewDialog::closeEvent(QCloseEvent *) {
Expand Down Expand Up @@ -414,6 +404,9 @@ void NewDialog::bp_type_change() {
const machine::PredictorType predictor_type {
ui->select_bp_type->currentData().value<machine::PredictorType>()
};

bool need_switch2custom = (config->get_bp_type() != predictor_type);

config->set_bp_type(predictor_type);

// Remove all items from init state list
Expand Down Expand Up @@ -474,6 +467,58 @@ void NewDialog::bp_type_change() {
break;
}
bp_toggle_widgets();

if (need_switch2custom)
switch2custom();
}

void NewDialog::bp_enabled_change(bool v) {
if (config->get_bp_enabled() != v) {
config->set_bp_enabled(v);
bp_toggle_widgets();
switch2custom();
}
}

void NewDialog::bp_init_state_change(void) {
auto v = ui->select_bp_init_state->currentData().value<machine::PredictorState>();
if (v != config->get_bp_init_state()) {
config->set_bp_init_state(v);
switch2custom();
}
}

void NewDialog::bp_btb_addr_bits_change(int v) {
if (config->get_bp_btb_bits() != v) {
config->set_bp_btb_bits((uint8_t)v);
switch2custom();
}
ui->text_bp_btb_addr_bits_number->setText(QString::number(config->get_bp_btb_bits()));
ui->text_bp_btb_bits_number->setText(QString::number(config->get_bp_btb_bits()));
ui->text_bp_btb_entries_number->setText(QString::number(qPow(2, config->get_bp_btb_bits())));
}

void NewDialog::bp_bht_bits_texts_update(void) {
ui->text_bp_bht_bhr_bits_number->setText(QString::number(config->get_bp_bhr_bits()));
ui->text_bp_bht_addr_bits_number->setText(QString::number(config->get_bp_bht_addr_bits()));
ui->text_bp_bht_bits_number->setText(QString::number(config->get_bp_bht_bits()));
ui->text_bp_bht_entries_number->setText(QString::number(qPow(2, config->get_bp_bht_bits())));
}

void NewDialog::bp_bht_bhr_bits_change(int v) {
if (config->get_bp_bhr_bits() != v) {
config->set_bp_bhr_bits((uint8_t)v);
switch2custom();
}
bp_bht_bits_texts_update();
}

void NewDialog::bp_bht_addr_bits_change(int v) {
if (config->get_bp_bht_addr_bits() != v) {
config->set_bp_bht_addr_bits((uint8_t)v);
switch2custom();
}
bp_bht_bits_texts_update();
}

void NewDialog::config_gui() {
Expand Down
8 changes: 7 additions & 1 deletion src/gui/dialogs/new/newdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ private slots:

// Branch Predictor
void bp_toggle_widgets();
void bp_type_change();
void bp_enabled_change(bool);
void bp_type_change(void);
void bp_init_state_change(void);
void bp_btb_addr_bits_change(int);
void bp_bht_bhr_bits_change(int);
void bp_bht_addr_bits_change(int);

private:
Box<Ui::NewDialog> ui {};
Expand All @@ -65,6 +70,7 @@ private slots:

Box<machine::MachineConfig> config;
void config_gui(); // Apply configuration to gui
void bp_bht_bits_texts_update(void);

unsigned preset_number();
void load_settings();
Expand Down
13 changes: 12 additions & 1 deletion src/machine/machineconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ void MachineConfig::preset(enum ConfigPresets p) {
set_memory_access_time_level2(DF_MEM_ACC_LEVEL2);
set_memory_access_enable_burst(DF_MEM_ACC_BURST_ENABLE);

// Branch predictor
set_bp_enabled(DFC_BP_ENABLED);
set_bp_type(DFC_BP_TYPE);
set_bp_init_state(DFC_BP_INIT_STATE);
set_bp_btb_bits(DFC_BP_BTB_BITS);
set_bp_bhr_bits(DFC_BP_BHR_BITS);
set_bp_bht_addr_bits(DFC_BP_BHT_ADDR_BITS);

access_cache_program()->preset(p);
access_cache_data()->preset(p);
access_cache_level2()->preset(p);
Expand Down Expand Up @@ -624,7 +632,10 @@ uint8_t MachineConfig::get_bp_bht_bits() const {
bool MachineConfig::operator==(const MachineConfig &c) const {
#define CMP(GETTER) (GETTER)() == (c.GETTER)()
return CMP(pipelined) && CMP(delay_slot) && CMP(hazard_unit) && CMP(get_simulated_xlen)
&& CMP(get_isa_word) && CMP(memory_execute_protection) && CMP(memory_write_protection)
&& CMP(get_isa_word) && CMP(get_bp_enabled) && CMP(get_bp_type)
&& CMP(get_bp_init_state) && CMP(get_bp_btb_bits)
&& CMP(get_bp_bhr_bits) && CMP(get_bp_bht_addr_bits)
&& CMP(memory_execute_protection) && CMP(memory_write_protection)
&& CMP(memory_access_time_read) && CMP(memory_access_time_write)
&& CMP(memory_access_time_burst) && CMP(memory_access_time_level2)
&& CMP(memory_access_enable_burst) && CMP(elf) && CMP(cache_program) && CMP(cache_data)
Expand Down

0 comments on commit e6338c7

Please sign in to comment.