diff options
author | bd <bdunahu@operationnull.com> | 2025-04-27 17:34:16 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-04-27 17:34:16 -0400 |
commit | 4f77c3161128ff965b26f9575853c5347c0d662d (patch) | |
tree | 7120db1a5d945d7309564bb3918a21a16928733b | |
parent | 3233a150e2024e9be51623f606bf15527a76cf1e (diff) |
Basic register display
-rw-r--r-- | gui/digitlabeldelegate.cc | 8 | ||||
-rw-r--r-- | gui/gui.cc | 44 | ||||
-rw-r--r-- | gui/gui.h | 2 | ||||
-rw-r--r-- | gui/registerview.cc | 24 | ||||
-rw-r--r-- | gui/registerview.h | 18 | ||||
-rw-r--r-- | gui/storageview.h | 2 | ||||
-rw-r--r-- | gui/worker.cc | 24 | ||||
-rw-r--r-- | gui/worker.h | 21 | ||||
-rw-r--r-- | inc/controller.h | 6 | ||||
-rw-r--r-- | src/controller.cc | 8 | ||||
-rw-r--r-- | src/id.cc | 53 |
11 files changed, 125 insertions, 85 deletions
diff --git a/gui/digitlabeldelegate.cc b/gui/digitlabeldelegate.cc index 430946c..7a6a1d5 100644 --- a/gui/digitlabeldelegate.cc +++ b/gui/digitlabeldelegate.cc @@ -37,9 +37,13 @@ void DigitLabelDelegate::paint( QString t; QStyleOptionViewItem o; QStyle *s; + QVariant a; + bool e; - v = index.data(Qt::DisplayRole).toInt(); - t = format_toggled_value(v, this->is_hex); + a = index.data(Qt::DisplayRole); + v = a.toInt(); + e = a.isNull(); + t = format_toggled_value(v, this->is_hex, e); o = option; initStyleOption(&o, index); @@ -17,11 +17,11 @@ #include "gui.h" #include "./ui_gui.h" -#include "digitlabeldelegate.h" #include "cachewaysselector.h" +#include "digitlabeldelegate.h" #include "messages.h" -#include "storageview.h" #include "registerview.h" +#include "storageview.h" #include "util.h" #include <QHeaderView> #include <QPixmap> @@ -112,32 +112,6 @@ GUI::~GUI() delete ui; } -void displayArrayHTML(QTextEdit *textEdit, const std::array<int, GPR_NUM> &data) -{ - textEdit->setReadOnly(false); - QString tableText = "<table border='1' cellspacing='0' cellpadding='8' " - "style='border-collapse: collapse; width: 100%; " - "border: 2px solid black;'>"; - - tableText += "<tr>"; - int index = 0; - for (int value : data) { - tableText += QString("<td align='center' style='border: 2px solid " - "black; min-width: 60px; padding: 10px;'>" - "%1 <sup style='font-size: 10px; font-weight: " - "bold; color: black;'>%2</sup>" - "</td>") - .arg(QString::asprintf("%04X", value)) - .arg(index); - index++; - } - tableText += "</tr>"; - tableText += "</table>"; - - textEdit->setHtml(tableText); - textEdit->setReadOnly(true); -} - void GUI::on_worker_refresh_gui(int cycles, int pc) { ui->p_counter->set_value(pc); @@ -224,10 +198,13 @@ void GUI::onWorkerShowStorage(const QVector<QVector<int>> &data, int i) this->tab_boxes.at(i)->set_data(data); } -void GUI::onWorkerShowRegisters(const std::array<int, GPR_NUM> &data) +void GUI::onWorkerShowRegisters( + const QVector<signed int> &gprs, const QVector<QVector<signed int>> &vrs) { - ; - // displayArrayHTML(this->tab_boxes.at(0), data); + RegisterView *rv; + + rv = dynamic_cast<RegisterView *>(this->tab_boxes.at(0)); + rv->set_data(gprs, vrs); } void GUI::on_upload_intructions_btn_clicked() @@ -353,7 +330,7 @@ void GUI::make_tabs(int num) for (i = 0; i < num; ++i) { if (i == 0) { n = "Registers"; - e = new RegisterView(GPR_NUM+V_NUM, V_R_LIMIT, this); + e = new RegisterView(GPR_NUM + V_NUM, V_R_LIMIT, this); } else if (i == num - 1) { n = "DRAM"; e = new StorageView(MEM_LINES, LINE_SIZE, this); @@ -361,8 +338,7 @@ void GUI::make_tabs(int num) n = QString("L%1").arg(i); e = new StorageView( (1 << cache_size_mapper(this->curr_cache_levels - 1, i - 1)), - LINE_SIZE, - this); + LINE_SIZE, this); } t = new QTableView(ui->storage); @@ -72,7 +72,7 @@ class GUI : public QMainWindow void onWorkerShowStorage(const QVector<QVector<int>> &data, int i); - void onWorkerShowRegisters(const std::array<int, GPR_NUM> &data); + void onWorkerShowRegisters(const QVector<signed int> &gprs, const QVector<QVector<signed int>> &vrs); void on_upload_intructions_btn_clicked(); diff --git a/gui/registerview.cc b/gui/registerview.cc index 5320afa..b1a1333 100644 --- a/gui/registerview.cc +++ b/gui/registerview.cc @@ -15,8 +15,8 @@ // 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 "pipe_spec.h" #include "registerview.h" -#include "definitions.h" #include "util.h" #include <QAbstractTableModel> #include <QVector> @@ -29,12 +29,22 @@ QVariant RegisterView::data(const QModelIndex &i, int role) const a = Qt::AlignRight | Qt::AlignVCenter; return QVariant(static_cast<int>(a)); } + if (!i.isValid() || role != Qt::DisplayRole) return QVariant(); - return this->d[i.row()][i.column()]; + + if (i.row() < 16) { + if (i.column() < 1) + return this->gprs[i.row()]; + else + return QVariant(); + } + + return this->vrs[i.row() - GPR_NUM][i.column() - GPR_NUM]; } -QVariant RegisterView::headerData(int section, Qt::Orientation o, int role) const +QVariant +RegisterView::headerData(int section, Qt::Orientation o, int role) const { Qt::Alignment a; @@ -47,7 +57,13 @@ QVariant RegisterView::headerData(int section, Qt::Orientation o, int role) cons return QVariant(); if (o == Qt::Vertical) { - return format_toggled_value(section * 4, this->is_hex); + return format_toggled_value(section, this->is_hex); } return QVariant(); } + +void RegisterView::set_data(const QVector<int> &gprs, const QVector<QVector<int>> &vrs) +{ + this->gprs = gprs; + this->vrs = vrs; +} diff --git a/gui/registerview.h b/gui/registerview.h index e4cb940..cc5a1f8 100644 --- a/gui/registerview.h +++ b/gui/registerview.h @@ -18,8 +18,8 @@ #ifndef REGISTERVIEW_H #define REGISTERVIEW_H -#include <QAbstractTableModel> #include "storageview.h" +#include <QAbstractTableModel> #include <QVector> // see https://doc.qt.io/qt-6/qabstracttablemodel.html @@ -43,6 +43,22 @@ class RegisterView : public StorageView int section, Qt::Orientation o, int role = Qt::DisplayRole) const override; + + /** + * @param field to assign to `this->gprs'. + * @param field to assign to `this->vrs'. + */ + void set_data(const QVector<int> &gprs, const QVector<QVector<int>> &vrs); + + private: + /** + * The general purpose registers. + */ + QVector<int> gprs; + /** + * The vector registers. + */ + QVector<QVector<int>> vrs; }; #endif // REGISTERVIEW_H diff --git a/gui/storageview.h b/gui/storageview.h index e8f3473..a0f8dbb 100644 --- a/gui/storageview.h +++ b/gui/storageview.h @@ -88,6 +88,8 @@ class StorageView : public QAbstractTableModel * Whether or not the headers should be displayed in hex. */ bool is_hex = true; + + private: /** * The data this table displays. */ diff --git a/gui/worker.cc b/gui/worker.cc index dd7b637..a48888c 100644 --- a/gui/worker.cc +++ b/gui/worker.cc @@ -78,9 +78,16 @@ void Worker::runSteps(int steps) void Worker::update() { unsigned long i; + std::array<int, GPR_NUM> gprs; + std::array<std::array<signed int, V_R_LIMIT>, V_NUM> vrs; this->ct_mutex.lock(); - emit register_storage(this->ct->get_gprs()); + gprs = this->ct->get_gprs(); + vrs = this->ct->get_vrs(); + std::vector<std::array<signed int, V_R_LIMIT>> v(vrs.begin(), vrs.end()); + + emit register_storage( + QVector<int>(gprs.begin(), gprs.end()), this->data_to_QT(v)); for (i = 0; i < s.size(); ++i) emit storage(this->data_to_QT(this->s.at(i)->get_data()), i + 1); @@ -93,18 +100,3 @@ void Worker::update() 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; -} diff --git a/gui/worker.h b/gui/worker.h index 5ffb6ef..2a362a4 100644 --- a/gui/worker.h +++ b/gui/worker.h @@ -64,9 +64,9 @@ class Worker : public QObject signals: void clock_cycles(int value, int pc); - void - storage(QVector<QVector<int>> data, int i); - void register_storage(const std::array<int, GPR_NUM> data); + void storage(QVector<QVector<int>> data, int i); + void register_storage( + QVector<signed int> gprs, QVector<QVector<signed int>> vrs); void if_info(const InstrDTO *); void id_info(const InstrDTO *); void ex_info(const InstrDTO *); @@ -81,8 +81,21 @@ class Worker : public QObject * @param the original data * @return a less universal version of the same thing */ + template <size_t N> QVector<QVector<int>> - data_to_QT(std::vector<std::array<signed int, LINE_SIZE>> data); + data_to_QT(const std::vector<std::array<signed int, N>> &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; + } /** * Sets the GUI signals to update the storage, clock cycle, and stage * displays. diff --git a/inc/controller.h b/inc/controller.h index b7fa835..cd59fc8 100644 --- a/inc/controller.h +++ b/inc/controller.h @@ -49,7 +49,11 @@ class Controller : public Stage /** * @return a copy of gprs. */ - std::array<int, GPR_NUM> get_gprs(); + std::array<signed int, GPR_NUM> get_gprs(); + /** + * @return a copy of vrs. + */ + std::array<std::array<signed int, V_R_LIMIT>, V_NUM> get_vrs(); /** * @return the pc. */ diff --git a/src/controller.cc b/src/controller.cc index 8df4b97..a84126d 100644 --- a/src/controller.cc +++ b/src/controller.cc @@ -15,6 +15,7 @@ // 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 "definitions.h" #include "controller.h" #include "ex.h" #include "response.h" @@ -47,7 +48,12 @@ void Controller::run_for(int number) int Controller::get_clock_cycle() { return this->clock_cycle; } -std::array<int, GPR_NUM> Controller::get_gprs() { return this->gprs; } +std::array<signed int, GPR_NUM> Controller::get_gprs() { return this->gprs; } + +std::array<std::array<signed int, V_R_LIMIT>, V_NUM> Controller::get_vrs() +{ + return this->vrs; +} int Controller::get_pc() { return this->pc; } @@ -34,7 +34,8 @@ Response ID::read_guard(signed int &v) return r; } -Response ID::read_vec_guard(signed int v, std::array<signed int, V_R_LIMIT> &vrs) +Response +ID::read_vec_guard(signed int v, std::array<signed int, V_R_LIMIT> &vrs) { Response r; if (this->is_checked_out(v)) @@ -58,7 +59,8 @@ void ID::write_guard(signed int &v) v = this->dereference_register<signed int>(v); } -void ID::write_vec_guard(signed int v, std::array<signed int, V_R_LIMIT> &vrs){ +void ID::write_vec_guard(signed int v, std::array<signed int, V_R_LIMIT> &vrs) +{ // zero register shouldn't be written. if (v != 0) { @@ -121,13 +123,14 @@ void ID::split_instr(signed int &raw, unsigned int &type, Mnemonic &m) raw = (unsigned int)raw >> (TYPE_SIZE + opcode_size); } -Response ID::set_vlen(){ +Response ID::set_vlen() +{ signed int vlen_reg = 4; Response r; r = this->read_guard(vlen_reg); vlen_reg = vlen_reg & 0xf; - if (r == OK){ - if (vlen_reg > V_R_LIMIT){ + if (r == OK) { + if (vlen_reg > V_R_LIMIT) { this->curr_instr->slot_A = V_R_LIMIT; } else { this->curr_instr->slot_A = vlen_reg; @@ -150,9 +153,11 @@ void ID::decode_R_type(signed int &s1) s2 = GET_MID_BITS(s1, s0b, s1b); s1 = GET_LS_BITS(s1, s0b); - if(this->is_vector_type(this->curr_instr->mnemonic)){ - r1 = this->read_vec_guard(s1, this->curr_instr->operands.vector.slot_one); - r2 = this->read_vec_guard(s2, this->curr_instr->operands.vector.slot_two); + if (this->is_vector_type(this->curr_instr->mnemonic)) { + r1 = this->read_vec_guard( + s1, this->curr_instr->operands.vector.slot_one); + r2 = this->read_vec_guard( + s2, this->curr_instr->operands.vector.slot_two); r3 = this->set_vlen(); } else { r1 = this->read_guard(s1); @@ -171,14 +176,16 @@ void ID::decode_R_type(signed int &s1) case SUBV: case MULV: case DIVV: - if(this->status == OK){ - this->write_vec_guard(s3, this->curr_instr->operands.vector.slot_three); + if (this->status == OK) { + this->write_vec_guard( + s3, this->curr_instr->operands.vector.slot_three); } break; default: - if (this->status == OK) + if (this->status == OK) { this->write_guard(s3); this->curr_instr->operands.integer.slot_three = s3; + } } } @@ -219,7 +226,8 @@ void ID::decode_I_type(signed int &s1) r1 = this->read_guard(s1); this->curr_instr->operands.load_store_vector.base_addr = s1; // vector value to be stored - r2 = this->read_vec_guard(s2,this->curr_instr->operands.load_store_vector.vector_register); + r2 = this->read_vec_guard( + s2, this->curr_instr->operands.load_store_vector.vector_register); r3 = this->set_vlen(); this->status = (r1 == OK && r2 == OK && r3 == OK) ? OK : STALLED; @@ -234,7 +242,9 @@ void ID::decode_I_type(signed int &s1) r3 = this->set_vlen(); if (r1 == OK && r3 == OK) // vector destination - this->write_vec_guard(s2, this->curr_instr->operands.load_store_vector.vector_register); + this->write_vec_guard( + s2, + this->curr_instr->operands.load_store_vector.vector_register); this->status = (r1 == OK && r3 == OK) ? OK : STALLED; return; case LOAD: @@ -249,7 +259,7 @@ void ID::decode_I_type(signed int &s1) r1 = this->read_guard(s1); this->curr_instr->operands.integer.slot_one = s1; - if (r1 == OK){ + if (r1 == OK) { this->write_guard(s2); this->curr_instr->operands.integer.slot_two = s2; } @@ -259,7 +269,7 @@ void ID::decode_I_type(signed int &s1) void ID::decode_J_type(signed int &s1) { Response r1, r2; - signed int s2,s3; + signed int s2, s3; unsigned int s0b, s1b; s0b = REG_SIZE; @@ -271,11 +281,12 @@ void ID::decode_J_type(signed int &s1) switch (this->curr_instr->mnemonic) { case PUSH: s2 = s1; // source - s3 = 2; // stack pointer + s3 = 2; // stack pointer s1 = -1; // increment amount r1 = this->read_guard(s2); this->curr_instr->operands.integer.slot_two = s2; - r2 = (this->is_checked_out(s3)) ? STALLED : OK; // we read the stack pointer + r2 = (this->is_checked_out(s3)) ? STALLED + : OK; // we read the stack pointer if (r1 == OK && r2 == OK) { this->write_guard(s3); // we write the stack pointer this->curr_instr->operands.integer.slot_three = s3; @@ -284,9 +295,10 @@ void ID::decode_J_type(signed int &s1) break; case POP: s2 = s1; // destination - s3 = 2; // stack pointer - s1 = 1; // increment amount - r1 = (this->is_checked_out(s3)) ? STALLED : OK; // we read the stack pointer + s3 = 2; // stack pointer + s1 = 1; // increment amount + r1 = (this->is_checked_out(s3)) ? STALLED + : OK; // we read the stack pointer if (r1 == OK) { this->write_guard(s2); this->curr_instr->operands.integer.slot_two = s2; @@ -302,5 +314,4 @@ void ID::decode_J_type(signed int &s1) this->status = this->read_guard(s1); this->curr_instr->operands.integer.slot_one = s1; } - } |