1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
// 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 <https://www.gnu.org/licenses/>.
#include "worker.h"
#include "storage.h"
#include "util.h"
Worker::Worker(QObject *parent) : QObject(parent) {}
Worker::~Worker()
{
emit finished();
delete this->ct;
}
void Worker::configure(
std::vector<unsigned int> ways,
std::vector<signed int> program,
bool is_pipelined)
{
Dram *d;
Storage *s;
Stage *old;
int i;
this->s.clear();
this->ct_mutex.lock();
d = new Dram(DRAM_DELAY);
s = static_cast<Storage *>(d);
this->s.push_front(s);
d->load(program);
for (i = ways.size(); i > 0; --i) {
s = static_cast<Storage *>(new Cache(
s, cache_size_mapper(ways.size() - 1, i - 1), 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();
this->update();
}
void Worker::runSteps(int steps)
{
this->ct->run_for(steps);
this->update();
}
void Worker::update()
{
unsigned long i;
this->ct_mutex.lock();
emit register_storage(this->ct->get_gprs());
for (i = 0; i < s.size(); ++i)
emit storage(this->data_to_QT(this->s.at(i)->get_data()), i + 1);
emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc());
emit if_info(this->if_stage->get_instr());
emit id_info(this->id_stage->get_instr());
emit ex_info(this->ex_stage->get_instr());
emit mm_info(this->mm_stage->get_instr());
emit wb_info(this->wb_stage->get_instr());
this->ct_mutex.unlock();
}
QVector<QVector<int>>
Worker::data_to_QT(std::vector<std::array<signed int, LINE_SIZE>> data)
{
QVector<QVector<int>> r;
QVector<int> tmp;
r.reserve(static_cast<int>(data.size()));
for (const auto &line : data) {
tmp = QVector<int>(line.begin(), line.end());
r.append(tmp);
}
return r;
}
|