From da25748edb6997629ffb380683c8c736f24033a8 Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 19 Apr 2025 02:23:03 -0400 Subject: Add custom QWidget to keep track of up to 4 user cache ways --- gui/dynamicwaysentry.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 gui/dynamicwaysentry.h (limited to 'gui/dynamicwaysentry.h') diff --git a/gui/dynamicwaysentry.h b/gui/dynamicwaysentry.h new file mode 100644 index 0000000..be42696 --- /dev/null +++ b/gui/dynamicwaysentry.h @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include + +class DynamicWaysEntry : public QWidget +{ + public: + DynamicWaysEntry(QWidget *parent = nullptr); + QStringList get_entries() const; + /** + * Parses a string from this entry field, if it is valid. + * @param a string + * @param -1 if the string is not suitable as a way, an integer compatible + * with the cache constructor otherwise. + */ + int parse_valid_way(QString t); + private slots: + void on_number_enter(const QString &t); + + private: + QVBoxLayout *l; + QVector fields; + QStringList entries; + void add_field(); + void remove_last_field(); +}; -- cgit v1.2.3 From bb3d940fb4ce0dd3efc56b934a7b4ea8ffab4b13 Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 19 Apr 2025 03:37:43 -0400 Subject: GUI validate program --- gui/dynamicwaysentry.h | 6 ++++++ gui/gui.cc | 54 +++++++++++++++++++++++++++++++++++++++++++++++--- gui/gui.h | 27 +++++++++++++++++-------- gui/messages.h | 19 +++++++++++++++++- gui/worker.cc | 27 +++++++++++++++++++++++++ gui/worker.h | 1 + inc/pipe_spec.h | 10 ++++++++++ 7 files changed, 132 insertions(+), 12 deletions(-) (limited to 'gui/dynamicwaysentry.h') diff --git a/gui/dynamicwaysentry.h b/gui/dynamicwaysentry.h index be42696..de001ee 100644 --- a/gui/dynamicwaysentry.h +++ b/gui/dynamicwaysentry.h @@ -1,3 +1,7 @@ +#ifndef DYNAMICWAYSENTRY_H +#define DYNAMICWAYSENTRY_H + + #include #include #include @@ -26,3 +30,5 @@ class DynamicWaysEntry : public QWidget void add_field(); void remove_last_field(); }; + +#endif // DYNAMICWAYSENTRY_H diff --git a/gui/gui.cc b/gui/gui.cc index a36920b..3a1027a 100644 --- a/gui/gui.cc +++ b/gui/gui.cc @@ -1,5 +1,6 @@ #include "gui.h" #include "./ui_gui.h" +#include "dynamicwaysentry.h" #include "messages.h" GUI::GUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::GUI) @@ -43,6 +44,11 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::GUI) connect( worker, &Worker::register_storage, this, &GUI::onWorkerShowRegisters); + // Configure pipeline + connect( + this, &GUI::sendConfigure, worker, &Worker::configure, + Qt::QueuedConnection); + // // Refresh DRAM from worker thread // connect(this, &GUI::sendRefreshDram, worker, &Worker::refreshDram, // Qt::QueuedConnection); @@ -56,7 +62,7 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::GUI) this, &GUI::sendRefreshRegisters, worker, &Worker::refreshRegisters, Qt::QueuedConnection); - // Advance controller by somes steps + // Advance controller by some steps connect( this, &GUI::sendRunSteps, worker, &Worker::runSteps, Qt::QueuedConnection); @@ -269,7 +275,7 @@ void GUI::on_upload_intructions_btn_clicked() } if (this->p.empty()) - this->set_status(get_no_instructions); + this->set_status(get_no_instructions); else this->set_status(get_load_file); @@ -297,6 +303,8 @@ void GUI::on_enable_pipeline_checkbox_checkStateChanged( void GUI::on_step_btn_clicked() { qDebug() << "Run step button clicked."; + if (!this->ready) + return this->on_config_clicked(); int steps = step_values[ui->step_slider->value()]; emit sendRunSteps(steps); } @@ -307,7 +315,47 @@ void GUI::on_save_program_state_btn_clicked() qDebug() << "save program state button is clicked."; } +void GUI::on_config_clicked() +{ + std::vector ways; + QStringList entries; + signed int i; + DynamicWaysEntry *dwe = ui->cache_way_selector; + + for (const QString &s : dwe->get_entries()) { + + if (s.isEmpty()) + continue; + + i = dwe->parse_valid_way(s); + if (i != -1) { + ways.push_back((unsigned int)i); + } else { + this->set_status(get_bad_cache); + return; + } + } + + if (this->p.empty()) { + this->set_status(get_no_instructions); + return; + } + + this->ready = true; + + // say something snarky + if (!is_pipelined) + this->set_status(get_no_pipeline); + else if (ways.size() == 0) + this->set_status(get_no_cache); + else + this->set_status(get_initialize); + + emit sendConfigure(ways, is_pipelined); +} + void GUI::set_status(const std::function &func) { - this->status_label->setText("COMPUTER SAYS: \"" + QString::fromStdString(func()) + "\""); + this->status_label->setText( + "COMPUTER SAYS: \"" + QString::fromStdString(func()) + "\""); } diff --git a/gui/gui.h b/gui/gui.h index 09fe0d9..97f131a 100644 --- a/gui/gui.h +++ b/gui/gui.h @@ -5,8 +5,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -42,6 +42,7 @@ class GUI : public QMainWindow void sendRefreshCache(); void sendRefreshRegisters(); void sendRunSteps(int steps); + void sendConfigure(std::vector ways, bool is_pipelined); private slots: void onWorkerClockCycles(int value, int pc); @@ -77,9 +78,22 @@ class GUI : public QMainWindow void on_save_program_state_btn_clicked(); + /** + * Validates that the user has provided a valid program and cache. + * If so, `this->ready' is set and the user options are passed to the + * worker. + * If not, rudely complains. + */ + void on_config_clicked(); + private: Ui::GUI *ui; + /** + * Indicates if the program has been initialized. + */ + bool ready; + /** * The message displayed on the status bar. */ @@ -91,21 +105,19 @@ class GUI : public QMainWindow std::vector p; /** - * The current cache configurations. + * If this stage is pipelined or not. */ - std::vector c; + bool is_pipelined = false; /** - * If this stage is pipelined or not. + * The possible step slider values. */ - bool is_pipelined = false; + QVector step_values = {1, 5, 20, 50, 250, 1000, 10000}; QThread workerThread; Worker *worker; - QVector step_values = {1, 5, 20, 50, 250, 1000, 10000}; - const std::map mnemonicNameMap = { {Mnemonic::ADD, "ADD"}, {Mnemonic::SUB, "SUB"}, {Mnemonic::MUL, "MUL"}, {Mnemonic::QUOT, "QUOT"}, @@ -132,6 +144,5 @@ class GUI : public QMainWindow auto it = mnemonicNameMap.find(mnemonic); return (it != mnemonicNameMap.end()) ? it->second : "Unknown"; } - }; #endif // GUI_H diff --git a/gui/messages.h b/gui/messages.h index 2af8e6b..c2a86b9 100644 --- a/gui/messages.h +++ b/gui/messages.h @@ -13,8 +13,17 @@ const std::vector waiting = { const std::vector load_file = { "FILE LOADED", "FINISHED READING DATA. EAGERLY WAITING"}; const std::vector no_instructions = { - "NO PROGRAM PROVIDED", "RISC V[ECTOR]: INSTRUCTIONS NOT INCLUDED", + "NO PROGRAM PROVIDED", "INSTRUCTIONS NOT INCLUDED", "NOTHING TO DO, GIVING UP"}; +const std::vector bad_cache = { + "INVALID NUMBER OF WAYS", "WAYS CANNOT BE BELOW 0 OR ABOVE 5"}; +const std::vector no_pipeline = { + "PIPELINE--HUMANS PROBABLY WORKED HARD ON THAT", + "I WOULD PREFER YOU LEAVE THE PIPE ON", "SLOW MODE ENABLED", + "SIMULATION READY"}; +const std::vector no_cache = { + "NO CACHE HAS NO WAY TO GO", "SLOW MODE ENABLED", "SIMULATION READY"}; +const std::vector initialize = {"SIMULATION READY"}; /** * @return an unsolicited waiting message @@ -30,5 +39,13 @@ std::string get_load_file() { return RANDOM_MESSAGE(load_file); } * @return a friendly reminder that the simulation is not configured yet */ std::string get_no_instructions() { return RANDOM_MESSAGE(no_instructions); } +std::string get_bad_cache() { return RANDOM_MESSAGE(bad_cache); } + +/** + * @return unsolicited complaints for successful initialization + */ +std::string get_no_pipeline() { return RANDOM_MESSAGE(no_pipeline); } +std::string get_no_cache() { return RANDOM_MESSAGE(no_cache); } +std::string get_initialize() { return RANDOM_MESSAGE(initialize); } #endif // MESSAGES_H diff --git a/gui/worker.cc b/gui/worker.cc index 1d87fd3..558552f 100644 --- a/gui/worker.cc +++ b/gui/worker.cc @@ -10,6 +10,33 @@ Worker::~Worker() delete this->ct; } +void Worker::configure(std::vector ways, bool is_pipelined) +{ + // this->d = new Dram(DRAM_DELAY); + // setWays(ways); + // setSize(size); + // this->cache_enabled = is_cache_enabled; + // if (!is_cache_enabled || ways.size() == 0) { + // this->ct = new Controller(wb_stage, this->d, is_pipelined); + // } else { + // // 0th index cache has largest delay + // for (int i = 0; i < ways.size(); i++) { + // if (i == 0) { + // Cache *cache = + // new Cache(this->d, size[i], ways[i], ways.size()); + // this->c.push_back(cache); + // } else { + // Cache *cache = new Cache( + // this->c[i - 1], size[i], ways[i], ways.size() - i); + // this->c.push_back(cache); + // } + // } + // this->ct = + // new Controller(wb_stage, this->c.at(ways.size() - 1), is_pipelined); + // } + emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc()); +} + void Worker::refreshDram() { qDebug() << "Refreshing Dram"; diff --git a/gui/worker.h b/gui/worker.h index 53e4851..df7d9cc 100644 --- a/gui/worker.h +++ b/gui/worker.h @@ -31,6 +31,7 @@ public slots: void refreshCache(); void refreshRegisters(); void runSteps(int steps); + void configure(std::vector ways, bool is_pipelined); signals: void clock_cycles(int value, int pc); diff --git a/inc/pipe_spec.h b/inc/pipe_spec.h index d211b72..4f5bc46 100644 --- a/inc/pipe_spec.h +++ b/inc/pipe_spec.h @@ -48,6 +48,16 @@ */ #define MAX_INT 2147483647 +/** + * The delay on DRAM objects. + */ +#define DRAM_DELAY 10 + +/** + * The (base) on cache objects. + */ +#define CACHE_DELAY 1 + /** * Return the N least-significant bits from integer K using a bit mask * @param the integer to be parsed -- cgit v1.2.3 From dbf5d3986e5fe271b072cd3d32e73e4fa26a5fae Mon Sep 17 00:00:00 2001 From: bd Date: Mon, 21 Apr 2025 11:59:32 -0400 Subject: Add licensing to new files --- gui/digitlabel.cc | 17 +++++++++++++++++ gui/digitlabel.h | 17 +++++++++++++++++ gui/dynamicwaysentry.cc | 17 +++++++++++++++++ gui/dynamicwaysentry.h | 17 +++++++++++++++++ 4 files changed, 68 insertions(+) (limited to 'gui/dynamicwaysentry.h') diff --git a/gui/digitlabel.cc b/gui/digitlabel.cc index a5c84f1..ffecfff 100644 --- a/gui/digitlabel.cc +++ b/gui/digitlabel.cc @@ -1,3 +1,20 @@ +// Simulator for the RISC-V[ECTOR] mini-ISA +// Copyright (C) 2025 Siddarth Suresh +// Copyright (C) 2025 bdunahu + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + #include "digitlabel.h" DigitLabel::DigitLabel(QWidget *parent) : QLabel(parent) diff --git a/gui/digitlabel.h b/gui/digitlabel.h index 9106cc9..2916426 100644 --- a/gui/digitlabel.h +++ b/gui/digitlabel.h @@ -1,3 +1,20 @@ +// Simulator for the RISC-V[ECTOR] mini-ISA +// Copyright (C) 2025 Siddarth Suresh +// Copyright (C) 2025 bdunahu + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + #ifndef DIGITLABEL_H #define DIGITLABEL_H diff --git a/gui/dynamicwaysentry.cc b/gui/dynamicwaysentry.cc index 4e2cd66..e1f740e 100644 --- a/gui/dynamicwaysentry.cc +++ b/gui/dynamicwaysentry.cc @@ -1,3 +1,20 @@ +// Simulator for the RISC-V[ECTOR] mini-ISA +// Copyright (C) 2025 Siddarth Suresh +// Copyright (C) 2025 bdunahu + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + #include "dynamicwaysentry.h" #include #include diff --git a/gui/dynamicwaysentry.h b/gui/dynamicwaysentry.h index de001ee..26b8b3e 100644 --- a/gui/dynamicwaysentry.h +++ b/gui/dynamicwaysentry.h @@ -1,3 +1,20 @@ +// Simulator for the RISC-V[ECTOR] mini-ISA +// Copyright (C) 2025 Siddarth Suresh +// Copyright (C) 2025 bdunahu + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + #ifndef DYNAMICWAYSENTRY_H #define DYNAMICWAYSENTRY_H -- cgit v1.2.3