diff options
Diffstat (limited to 'gui/worker.cc')
-rw-r--r-- | gui/worker.cc | 101 |
1 files changed, 47 insertions, 54 deletions
diff --git a/gui/worker.cc b/gui/worker.cc index 4b5277c..ba0723e 100644 --- a/gui/worker.cc +++ b/gui/worker.cc @@ -16,79 +16,71 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. #include "worker.h" +#include "storage.h" Worker::Worker(QObject *parent) : QObject(parent) {} -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() { emit finished(); qDebug() << "Worker destructor called in thread:" << QThread::currentThread(); delete this->ct; - delete this->c; -} - -void Worker::loadProgram(std::vector<signed int> p) { - this->d->load(p); } -void Worker::refreshDram() +void Worker::configure( + std::vector<unsigned int> ways, + std::vector<signed int> program, + bool is_pipelined) { - qDebug() << "Refreshing Dram"; - emit dram_storage(this->d->view(0, 31)); -} + Dram *d; + Storage *s; + Stage *old; + int i; -void Worker::refreshCache() -{ - qDebug() << "Refreshing Dram"; - emit cache_storage(this->c->view(0, 255)); -} + this->ct_mutex.lock(); + if (ways.size() != 0) { + // TODO optimal proper sizes + this->size_inc = ((MEM_LINE_SPEC * 0.75) / ways.size()); + } + d = new Dram(DRAM_DELAY); + s = static_cast<Storage *>(d); -void Worker::refreshRegisters() -{ - qDebug() << "Refreshing Registers"; - emit register_storage(this->ct->get_gprs()); -} + this->s.push_front(s); + d->load(program); -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)); - emit register_storage(this->ct->get_gprs()); + for (i = ways.size(); i > 0; --i) { + s = static_cast<Storage *>(new Cache( + s, this->size_inc * (i), ways.at(i - 1), CACHE_DELAY + i)); + this->s.push_front(s); + } + + 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); + + old = static_cast<Stage *>(this->ct); + this->ct = new Controller(wb_stage, s, is_pipelined); + if (old) + delete old; + this->ct_mutex.unlock(); + + std::cout << this->ct->get_clock_cycle() << ":" << this->ct->get_pc() << std::endl; emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc()); - emit if_info(this->if_stage->stage_info()); - emit id_info(this->id_stage->stage_info()); - emit ex_info(this->ex_stage->stage_info()); - emit mm_info(this->mm_stage->stage_info()); - emit wb_info(this->wb_stage->stage_info()); } -void Worker::runStep() +void Worker::runSteps(int steps) { - qDebug() << "Running for 1 step "; - this->ct->run_for(1); - emit dram_storage(this->d->view(0, 255)); - emit cache_storage(this->c->view(0, 255)); + this->ct_mutex.lock(); + qDebug() << "Running for " << steps << "steps"; + this->ct->run_for(steps); + // TODO move these to separate functions + emit dram_storage(this->s.back()->view(0, 255)); + if (this->s.size() > 1) { + emit cache_storage(this->s.at(0)->view(0, 1 << this->size_inc)); + } 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()); @@ -96,4 +88,5 @@ void Worker::runStep() emit ex_info(this->ex_stage->stage_info()); emit mm_info(this->mm_stage->stage_info()); emit wb_info(this->wb_stage->stage_info()); + this->ct_mutex.unlock(); } |