summaryrefslogtreecommitdiff
path: root/gui/worker.cc
diff options
context:
space:
mode:
authorSiddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com>2025-04-18 04:08:15 -0400
committerSiddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com>2025-04-18 04:08:15 -0400
commit06632f57c9047b7e54a274b6b020bcc83f5f9a64 (patch)
tree9dc7463683f657cb56092c87c559f46ea9f2523c /gui/worker.cc
parentdbf7e900336214041da8880d6986d59126c35a72 (diff)
initialization from GUI
Diffstat (limited to 'gui/worker.cc')
-rw-r--r--gui/worker.cc75
1 files changed, 60 insertions, 15 deletions
diff --git a/gui/worker.cc b/gui/worker.cc
index e4e3bdf..fac835e 100644
--- a/gui/worker.cc
+++ b/gui/worker.cc
@@ -2,22 +2,56 @@
Worker::Worker(QObject *parent) : QObject(parent) {}
+void Worker::configure(std::vector<int> ways, std::vector<int> size, bool is_pipelined, bool is_cache_enabled) {
+ this->d = new Dram(ways.size()+1);
+ setWays(ways);
+ setSize(size);
+ qDebug() << "is cache enabled:" << is_cache_enabled;
+ qDebug() << "is pipelined:" << is_pipelined;
+ 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::setWays(std::vector<int> ways) {
+ this->cache_ways = ways;
+}
+
+void Worker::setSize(std::vector<int> size) {
+ this->cache_size = size;
+}
+
+std::vector<int> Worker::getWays() {
+ return this->cache_ways;
+}
+
+std::vector<int> Worker::getSize() {
+ return this->cache_size;
+}
+
void Worker::doWork()
{
qDebug() << "Initializing...";
- this->d = new Dram(0);
- this->c = new Cache(this->d, 8, 0, 0);
+
this->if_stage = new IF(nullptr);
this->id_stage = new ID(if_stage);
this->ex_stage = new EX(id_stage);
this->mm_stage = new MM(ex_stage);
this->wb_stage = new WB(mm_stage);
- this->ct = new Controller(wb_stage, this->c, true);
-
- emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc());
- emit dram_storage(this->d->view(0, 255));
- emit cache_storage(this->c->view(0, 255));
- emit register_storage(this->ct->get_gprs());
}
Worker::~Worker()
@@ -26,7 +60,9 @@ Worker::~Worker()
qDebug() << "Worker destructor called in thread:"
<< QThread::currentThread();
delete this->ct;
- delete this->c;
+ for(Cache *cache: this->c) {
+ delete cache;
+ }
}
void Worker::loadProgram(std::vector<signed int> p) {
@@ -36,13 +72,16 @@ void Worker::loadProgram(std::vector<signed int> p) {
void Worker::refreshDram()
{
qDebug() << "Refreshing Dram";
- emit dram_storage(this->d->view(0, 31));
+ emit dram_storage(this->d->view(0, 255));
}
void Worker::refreshCache()
{
- qDebug() << "Refreshing Dram";
- emit cache_storage(this->c->view(0, 255));
+ qDebug() << "Refreshing Cache";
+ if(getWays().size() > 0) {
+ unsigned int size = this->c.at(getWays().size()-1)->get_size();
+ emit cache_storage(this->c.at(getWays().size()-1)->view(0, 1<<size));
+ }
}
void Worker::refreshRegisters()
@@ -56,7 +95,10 @@ void Worker::runSteps(int steps)
qDebug() << "Running for steps: " << steps;
this->ct->run_for(steps);
emit dram_storage(this->d->view(0, 255));
- emit cache_storage(this->c->view(0, 255));
+ if(this->cache_enabled && getWays().size() > 0) {
+ unsigned int size = this->c.at(getWays().size()-1)->get_size();
+ emit cache_storage(this->c.at(getWays().size()-1)->view(0, 1<<size));
+ }
emit register_storage(this->ct->get_gprs());
emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc());
emit if_info(this->if_stage->stage_info());
@@ -69,9 +111,12 @@ void Worker::runSteps(int steps)
void Worker::runStep()
{
qDebug() << "Running for 1 step ";
- this->ct->run_for(1);
+ this->ct->advance(WAIT);
emit dram_storage(this->d->view(0, 255));
- emit cache_storage(this->c->view(0, 255));
+ if(this->cache_enabled && getWays().size() > 0) {
+ unsigned int size = this->c.at(getWays().size()-1)->get_size();
+ emit cache_storage(this->c.at(getWays().size()-1)->view(0, 1<<size));
+ }
emit register_storage(this->ct->get_gprs());
emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc());
emit if_info(this->if_stage->stage_info());