diff options
author | bd <bdunahu@operationnull.com> | 2025-04-27 15:20:37 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-04-27 15:20:37 -0400 |
commit | 64efd868deec8921eac16b181f3a2e6d29f90b99 (patch) | |
tree | 096c73c3e74a2afedabd85bd62dbb6720a365ed5 | |
parent | 7aaa516c0de444c956dff88342a57e9313a19e34 (diff) | |
parent | 5653b2a033e7a4173d2f178b5ce52384666d3d7b (diff) |
Merge remote-tracking branch 'origin/master' into vector_ext
-rw-r--r-- | gui/digitlabel.cc | 10 | ||||
-rw-r--r-- | gui/digitlabel.h | 2 | ||||
-rw-r--r-- | gui/digitlabeldelegate.cc | 51 | ||||
-rw-r--r-- | gui/digitlabeldelegate.h | 46 | ||||
-rw-r--r-- | gui/gui.cc | 159 | ||||
-rw-r--r-- | gui/gui.h | 27 | ||||
-rw-r--r-- | gui/gui.ui | 2 | ||||
-rw-r--r-- | gui/resources/styles.qss | 30 | ||||
-rw-r--r-- | gui/storageview.cc | 88 | ||||
-rw-r--r-- | gui/storageview.h | 93 | ||||
-rw-r--r-- | gui/util.cc | 25 | ||||
-rw-r--r-- | gui/util.h | 27 | ||||
-rw-r--r-- | gui/worker.cc | 53 | ||||
-rw-r--r-- | gui/worker.h | 31 | ||||
-rw-r--r-- | inc/id.h | 2 | ||||
-rw-r--r-- | inc/if.h | 2 | ||||
-rw-r--r-- | inc/stage.h | 15 | ||||
-rw-r--r-- | src/id.cc | 16 | ||||
-rw-r--r-- | src/if.cc | 9 | ||||
-rw-r--r-- | src/stage.cc | 27 |
20 files changed, 516 insertions, 199 deletions
diff --git a/gui/digitlabel.cc b/gui/digitlabel.cc index 8314943..f77c1fa 100644 --- a/gui/digitlabel.cc +++ b/gui/digitlabel.cc @@ -16,6 +16,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. #include "digitlabel.h" +#include "util.h" #include "gui.h" DigitLabel::DigitLabel(QWidget *parent) : QLabel(parent) { setText(QString()); } @@ -42,11 +43,6 @@ void DigitLabel::on_hex_toggle(bool is_hex) void DigitLabel::update_display() { QString t; - if (this->is_cleared) { - setText(QString()); - } else { - t = (this->is_hex) ? QString::number(this->v, 16).toUpper() - : QString::number(this->v); - setText(t); - } + t = format_toggled_value(this->v, this->is_hex, this->is_cleared); + setText(t); } diff --git a/gui/digitlabel.h b/gui/digitlabel.h index 68b01cb..bffdd0a 100644 --- a/gui/digitlabel.h +++ b/gui/digitlabel.h @@ -59,7 +59,7 @@ class DigitLabel : public QLabel /** * If this digit should display in hexidecinmal. */ - int is_hex; + int is_hex = true; /** * If this digit should not display. */ diff --git a/gui/digitlabeldelegate.cc b/gui/digitlabeldelegate.cc new file mode 100644 index 0000000..430946c --- /dev/null +++ b/gui/digitlabeldelegate.cc @@ -0,0 +1,51 @@ +// 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 "digitlabeldelegate.h" +#include "util.h" +#include <QString> + +void DigitLabelDelegate::set_hex_display(bool hex) +{ + if (this->is_hex != hex) { + this->is_hex = hex; + if (auto v = qobject_cast<QAbstractItemView *>(parent())) + v->viewport()->update(); + } +} + +void DigitLabelDelegate::paint( + QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + int v; + QString t; + QStyleOptionViewItem o; + QStyle *s; + + v = index.data(Qt::DisplayRole).toInt(); + t = format_toggled_value(v, this->is_hex); + + o = option; + initStyleOption(&o, index); + o.text = t; + + const QWidget *w = option.widget; + s = w ? w->style() : QApplication::style(); + s->drawControl(QStyle::CE_ItemViewItem, &o, painter, w); +} diff --git a/gui/digitlabeldelegate.h b/gui/digitlabeldelegate.h new file mode 100644 index 0000000..7714d25 --- /dev/null +++ b/gui/digitlabeldelegate.h @@ -0,0 +1,46 @@ +// 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/>. + +#ifndef DIGITLABELDELEGATE_H +#define DIGITLABELDELEGATE_H + +#include <QAbstractItemView> +#include <QApplication> +#include <QPainter> +#include <QString> +#include <QStyleOptionViewItem> +#include <QStyledItemDelegate> + +class DigitLabelDelegate : public QStyledItemDelegate +{ + Q_OBJECT + public: + using QStyledItemDelegate::QStyledItemDelegate; + + public slots: + void set_hex_display(bool hex); + + private: + bool is_hex = true; + + void paint( + QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index) const override; +}; + +#endif // DIGITLABELDELEGATE_H @@ -17,10 +17,15 @@ #include "gui.h" #include "./ui_gui.h" +#include "digitlabeldelegate.h" #include "dynamicwaysentry.h" #include "messages.h" +#include "storageview.h" +#include "util.h" +#include <QHeaderView> #include <QPixmap> #include <QString> +#include <QTableView> GUI::GUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::GUI) { @@ -53,7 +58,6 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::GUI) for (DigitLabel *label : labels) { connect(this, &GUI::hex_toggled, label, &DigitLabel::on_hex_toggle); } - emit this->hex_toggled(this->is_hex); // display clock cycles and PC connect(worker, &Worker::clock_cycles, this, &GUI::on_worker_refresh_gui); @@ -92,7 +96,6 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::GUI) }); // Proper cleanup when worker finishes - connect(worker, &Worker::finished, this, &GUI::onWorkerFinished); connect(worker, &Worker::finished, &workerThread, &QThread::quit); connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); @@ -132,73 +135,43 @@ void displayArrayHTML(QTextEdit *textEdit, const std::array<int, GPR_NUM> &data) textEdit->setReadOnly(true); } -void displayTableHTML( - QTextEdit *textEdit, - const std::vector<std::array<signed int, LINE_SIZE>> &data) -{ - textEdit->setReadOnly(false); - QString tableText = "<table border='1' cellspacing='0' cellpadding='8' " - "style='border-collapse: collapse; width: 100%; " - "border: 2px solid black;'>"; - - int index = 0; - for (const auto &row : data) { - tableText += "<tr>"; - for (signed int value : row) { - 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); ui->cycle_counter->set_value(cycles); + this->set_status(get_waiting, "idle"); } -void GUI::onWorkerFetchInfo(const std::vector<int> info) +void GUI::onWorkerFetchInfo(const InstrDTO *i) { - if (!info.empty()) { - ui->fetch_squashed->setText(QString::number(info[0])); - ui->fetch_bits->set_value(info[1]); + if (i) { + ui->fetch_squashed->setText(QString::number(i->is_squashed)); + ui->fetch_bits->set_value(i->slot_A); } else { ui->fetch_squashed->clear(); ui->fetch_bits->clear(); } } -void GUI::onWorkerDecodeInfo(const std::vector<int> info) +void GUI::onWorkerDecodeInfo(const InstrDTO *i) { - if (!info.empty()) { - ui->decode_squashed->setText(QString::number(info[0])); - ui->decode_bits->set_value(info[1]); + if (i) { + ui->decode_squashed->setText(QString::number(i->is_squashed)); + ui->decode_bits->set_value(i->slot_A); } else { ui->decode_squashed->clear(); ui->decode_bits->clear(); } } -void GUI::onWorkerExecuteInfo(const std::vector<int> info) +void GUI::onWorkerExecuteInfo(const InstrDTO *i) { - if (!info.empty()) { - ui->execute_mnemonic->setText(mnemonicToString((Mnemonic)info[0])); - ui->execute_squashed->setText(QString::number(info[1])); - ui->execute_s1->set_value(info[2]); - ui->execute_s2->set_value(info[3]); - ui->execute_s3->set_value(info[4]); + if (i) { + ui->execute_mnemonic->setText(mnemonicToString(i->mnemonic)); + ui->execute_squashed->setText(QString::number(i->is_squashed)); + ui->execute_s1->set_value(i->operands.integer.slot_one); + ui->execute_s2->set_value(i->operands.integer.slot_two); + ui->execute_s3->set_value(i->operands.integer.slot_three); } else { ui->execute_mnemonic->clear(); ui->execute_squashed->clear(); @@ -208,15 +181,14 @@ void GUI::onWorkerExecuteInfo(const std::vector<int> info) } } -void GUI::onWorkerMemoryInfo(const std::vector<int> info) +void GUI::onWorkerMemoryInfo(const InstrDTO *i) { - if (!info.empty()) { - std::cout << "this " << info[3] << std::endl; - ui->memory_mnemonic->setText(mnemonicToString((Mnemonic)info[0])); - ui->memory_squashed->setText(QString::number(info[1])); - ui->memory_s1->set_value(info[2]); - ui->memory_s2->set_value(info[3]); - ui->memory_s3->set_value(info[4]); + if (i) { + ui->memory_mnemonic->setText(mnemonicToString(i->mnemonic)); + ui->memory_squashed->setText(QString::number(i->is_squashed)); + ui->memory_s1->set_value(i->operands.integer.slot_one); + ui->memory_s2->set_value(i->operands.integer.slot_two); + ui->memory_s3->set_value(i->operands.integer.slot_three); } else { ui->memory_mnemonic->clear(); ui->memory_squashed->clear(); @@ -226,14 +198,14 @@ void GUI::onWorkerMemoryInfo(const std::vector<int> info) } } -void GUI::onWorkerWriteBackInfo(const std::vector<int> info) +void GUI::onWorkerWriteBackInfo(const InstrDTO *i) { - if (!info.empty()) { - ui->write_mnemonic->setText(mnemonicToString((Mnemonic)info[0])); - ui->write_squashed->setText(QString::number(info[1])); - ui->write_s1->set_value(info[2]); - ui->write_s2->set_value(info[3]); - ui->write_s3->set_value(info[4]); + if (i) { + ui->write_mnemonic->setText(mnemonicToString(i->mnemonic)); + ui->write_squashed->setText(QString::number(i->is_squashed)); + ui->write_s1->set_value(i->operands.integer.slot_one); + ui->write_s2->set_value(i->operands.integer.slot_two); + ui->write_s3->set_value(i->operands.integer.slot_three); } else { ui->write_mnemonic->clear(); ui->write_squashed->clear(); @@ -243,24 +215,19 @@ void GUI::onWorkerWriteBackInfo(const std::vector<int> info) } } -void GUI::onWorkerShowStorage( - const std::vector<std::array<signed int, LINE_SIZE>> data, int i) +void GUI::onWorkerShowStorage(const QVector<QVector<int>> &data, int i) { - std::cout << this->tab_text_boxes.size() << std::endl; - displayTableHTML(this->tab_text_boxes.at(i), data); + this->tab_boxes.at(i)->set_data(data); } void GUI::onWorkerShowRegisters(const std::array<int, GPR_NUM> &data) { - displayArrayHTML(this->tab_text_boxes.at(0), data); + ; + // displayArrayHTML(this->tab_boxes.at(0), data); } -void GUI::onWorkerFinished() { qDebug() << "Worker has finished processing."; } - void GUI::on_upload_intructions_btn_clicked() { - qDebug() << "Upload intructions button clicked."; - // why ui->register_table, or now ui->storage QString filePath = QFileDialog::getOpenFileName( ui->storage, "Open Binary File", QDir::homePath(), @@ -312,7 +279,6 @@ void GUI::on_base_toggle_checkbox_checkStateChanged(const Qt::CheckState &state) void GUI::on_step_btn_clicked() { - qDebug() << "Run step button clicked."; // try to configure first if (!this->ready) this->on_config_clicked(); @@ -323,7 +289,6 @@ void GUI::on_step_btn_clicked() this->set_status(get_running, "busy"); int steps = step_values[ui->step_slider->value()]; emit sendRunSteps(steps); - this->set_status(get_waiting, "idle"); } void GUI::on_save_program_state_btn_clicked() @@ -368,6 +333,8 @@ void GUI::on_config_clicked() else this->set_status(get_initialize, "happy"); + this->curr_cache_levels = ways.size(); + emit sendConfigure(ways, this->p, is_pipelined); make_tabs(2 + ways.size()); } @@ -375,27 +342,43 @@ void GUI::on_config_clicked() void GUI::make_tabs(int num) { int i; - QStringList names; - QTextEdit *e; + StorageView *e; + QTableView *t; QString n; - - names = {"Registers", "DRAM"}; + DigitLabelDelegate *d; ui->storage->clear(); - this->tab_text_boxes.clear(); + + qDeleteAll(this->tab_boxes); + this->tab_boxes.clear(); for (i = 0; i < num; ++i) { - e = new QTextEdit(); - e->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + if (i == 0) { + n = "Registers"; + e = new StorageView(0, this); + } else if (i == num - 1) { + n = "DRAM"; + e = new StorageView(MEM_LINES, this); + } else { + n = QString("L%1").arg(i); + e = new StorageView( + (1 << cache_size_mapper(this->curr_cache_levels - 1, i - 1)), + this); + } + + t = new QTableView(ui->storage); + t->setModel(e); + d = new DigitLabelDelegate(t); + + connect(this, &GUI::hex_toggled, e, &StorageView::set_hex_display); + connect( + this, &GUI::hex_toggled, d, &DigitLabelDelegate::set_hex_display); - // make the name - if (i < names.size()) - n = names[i]; - else - n = QString("Level %1").arg(i - 1); + t->setItemDelegate(d); + t->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); - ui->storage->addTab(e, n); - this->tab_text_boxes.push_back(e); + ui->storage->addTab(t, n); + this->tab_boxes.push_back(e); } } @@ -18,6 +18,7 @@ #ifndef GUI_H #define GUI_H +#include "storageview.h" #include "worker.h" #include <QFile> #include <QFileDialog> @@ -57,23 +58,20 @@ class GUI : public QMainWindow private slots: void on_worker_refresh_gui(int value, int pc); - void onWorkerFetchInfo(const std::vector<int> info); + void onWorkerFetchInfo(const InstrDTO *); - void onWorkerDecodeInfo(const std::vector<int> info); + void onWorkerDecodeInfo(const InstrDTO *); - void onWorkerExecuteInfo(const std::vector<int> info); + void onWorkerExecuteInfo(const InstrDTO *); - void onWorkerMemoryInfo(const std::vector<int> info); + void onWorkerMemoryInfo(const InstrDTO *); - void onWorkerWriteBackInfo(const std::vector<int> info); + void onWorkerWriteBackInfo(const InstrDTO *); - void onWorkerShowStorage( - const std::vector<std::array<signed int, LINE_SIZE>> data, int i); + void onWorkerShowStorage(const QVector<QVector<int>> &data, int i); void onWorkerShowRegisters(const std::array<int, GPR_NUM> &data); - void onWorkerFinished(); - void on_upload_intructions_btn_clicked(); void on_upload_program_state_btn_clicked(); @@ -101,12 +99,17 @@ class GUI : public QMainWindow /** * Indicates if the program has been initialized. */ - bool ready; + bool ready = false; + + /** + * The current number of cache levels. + */ + int curr_cache_levels = 0; /** * The list of storage displays. */ - std::vector<QTextEdit *> tab_text_boxes; + std::vector<StorageView *> tab_boxes; /** * Whether or not numerical values are currently displaying in hex. @@ -135,7 +138,7 @@ class GUI : public QMainWindow /** * The possible step slider values. */ - QVector<int> step_values = {1, 5, 20, 50, 250, 1000, 10000}; + QVector<int> step_values = {1, 5, 20, 50, 250, 1000, 10000, 100000, 500000, 100000000}; QThread workerThread; @@ -630,7 +630,7 @@ <number>0</number> </property> <property name="maximum"> - <number>6</number> + <number>9</number> </property> <property name="pageStep"> <number>1</number> diff --git a/gui/resources/styles.qss b/gui/resources/styles.qss index 76d0311..a61035e 100644 --- a/gui/resources/styles.qss +++ b/gui/resources/styles.qss @@ -50,15 +50,27 @@ QGroupBox::title { QLabel { } -/* text entry */ -QLineEdit { - font-size: 18pt; - border-radius: 0px; - padding: 0 4px; - selection-background-color: "#00cc00"; +QTableView { + border: 0px; + selection-background-color: transparent; + selection-color: black; + outline: none; +} + +QTableView::item { + border: none; + padding: 4px; +} + +QHeaderView::section { + color: "#00cc00"; + background-color: "#000200"; + border: none; } -QTextEdit, QListView { +QTableView QTableCornerButton::section { + background-color: "#000200"; + border: none; } QPushButton { @@ -71,8 +83,8 @@ QPushButton { QPushButton:pressed { color: "#00cc00"; - background-color: "#000200"; -} + background-color: "#000200";} + QPushButton:flat { border: none; /* no border for a flat push button */ diff --git a/gui/storageview.cc b/gui/storageview.cc new file mode 100644 index 0000000..2f444a9 --- /dev/null +++ b/gui/storageview.cc @@ -0,0 +1,88 @@ +// 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 "storageview.h" +#include "definitions.h" +#include "util.h" +#include <QAbstractTableModel> +#include <QVector> + +StorageView::StorageView(int rows, QObject *parent) + : QAbstractTableModel(parent) +{ + this->r = rows; + this->d.resize(rows); + for (auto &row : this->d) + row.resize(LINE_SIZE, 0); +} + +int StorageView::rowCount(const QModelIndex &) const { return this->r; } + +int StorageView::columnCount(const QModelIndex &) const { return LINE_SIZE; } + +QVariant StorageView::data(const QModelIndex &i, int role) const +{ + Qt::Alignment a; + + if (role == Qt::TextAlignmentRole) { + 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()]; +} + +QVariant StorageView::headerData(int section, Qt::Orientation o, int role) const +{ + Qt::Alignment a; + + if (role == Qt::TextAlignmentRole) { + a = Qt::AlignRight | Qt::AlignVCenter; + return QVariant(static_cast<int>(a)); + } + + if (role != Qt::DisplayRole) + return QVariant(); + + if (o == Qt::Vertical) { + return format_toggled_value(section * 4, this->is_hex); + } + return QVariant(); +} + +Qt::ItemFlags StorageView::flags(const QModelIndex &i) const +{ + (void)i; + return Qt::ItemIsEnabled; +} + +void StorageView::set_data(const QVector<QVector<int>> &data) +{ + beginResetModel(); + this->d = data; + endResetModel(); +} + +void StorageView::set_hex_display(bool hex) +{ + if (this->is_hex != hex) { + beginResetModel(); + this->is_hex = hex; + endResetModel(); + } +} diff --git a/gui/storageview.h b/gui/storageview.h new file mode 100644 index 0000000..0518d8f --- /dev/null +++ b/gui/storageview.h @@ -0,0 +1,93 @@ +// 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/>. + +#ifndef STORAGEVIEW_H +#define STORAGEVIEW_H + +#include <QAbstractTableModel> +#include <QVector> + +// see https://doc.qt.io/qt-6/qabstracttablemodel.html +class StorageView : public QAbstractTableModel +{ + Q_OBJECT + public: + /** + * Constructor. Initializes a clean StorageView object with + * `rows' rows. + * @param the number of rows + */ + StorageView(int rows, QObject *parent = nullptr); + + /** + * Returns the number of rows in this table. + * @param the parent + * @return the number of rows under the given parent. + */ + int rowCount(const QModelIndex &) const override; + /** + * Returns the number of columns in this table. + * @param the parent + * @return the number of columns under the given parent (hint: it's + * LINE_SIZE) + */ + int columnCount(const QModelIndex &) const override; + + /** + * Returns a properly formatted cell, including alignment.This function is + * specific to the implementation details of QAbstractTableModel. + */ + QVariant + data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + + /** + * Adds custom formatting options for row and column headers. + */ + QVariant headerData( + int section, + Qt::Orientation o, + int role = Qt::DisplayRole) const override; + + /** + * Ensures the table is enabled, but not selectable. + */ + Qt::ItemFlags flags(const QModelIndex &i) const override; + + /** + * @param field to assign to `this->d' + */ + void set_data(const QVector<QVector<int>> &data); + + public slots: + void set_hex_display(bool hex); + + private: + /** + * The number of rows in this table. + */ + int r; + /** + * Whether or not the headers should be displayed in hex. + */ + bool is_hex = true; + /** + * The data this table displays. + */ + QVector<QVector<int>> d; +}; + +#endif // STORAGEVIEW_H diff --git a/gui/util.cc b/gui/util.cc new file mode 100644 index 0000000..b62ed81 --- /dev/null +++ b/gui/util.cc @@ -0,0 +1,25 @@ +#include "util.h" +#include "definitions.h" +#include <QString> + +int cache_size_mapper(int total_levels, int level) +{ + const int y_min = 4; + const int y_max = MEM_LINE_SPEC - 4; + double f, r; + + if (total_levels <= 0) + return 7; + + f = level / (double)total_levels; + r = y_min + f * (y_max - y_min); + + return r; +} + +QString format_toggled_value(int value, bool is_hex, bool is_cleared) +{ + if (is_cleared) + return QString(); + return is_hex ? QString::asprintf("%X", value) : QString::number(value); +} diff --git a/gui/util.h b/gui/util.h new file mode 100644 index 0000000..8e9d308 --- /dev/null +++ b/gui/util.h @@ -0,0 +1,27 @@ +#ifndef UTIL_H +#define UTIL_H + +#include <QString> + +/** + * Given `total_levels', returns an integer between 4 and 12 which is a linear + * map of `level' onto `total_levels'. This is used for generating cache sizes + * given a number of levels. + * @param the total number of cache levels, zero-indexed. + * @param a numberedcache level, zero-indexed. + * @return an integer between 4-12, linearly scaled with level. + */ +int cache_size_mapper(int total_levels, int level); + +/** + * Contains the main formatting logic used to format integers. Uses 2's + * complement for hexadecimal numbers. + * @param the value to be formated + * @param if the value should be displayed in hex. If false, displays in + * decimal. + * @param if the value should display. + * @return a string respecting the above parameters. + */ +QString format_toggled_value(int value, bool is_hex, bool is_cleared = false); + +#endif // UTIL_H diff --git a/gui/worker.cc b/gui/worker.cc index 2652fce..0ba364b 100644 --- a/gui/worker.cc +++ b/gui/worker.cc @@ -17,14 +17,13 @@ #include "worker.h" #include "storage.h" +#include "util.h" Worker::Worker(QObject *parent) : QObject(parent) {} Worker::~Worker() { emit finished(); - qDebug() << "Worker destructor called in thread:" - << QThread::currentThread(); delete this->ct; } @@ -41,10 +40,6 @@ void Worker::configure( this->s.clear(); 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); @@ -53,7 +48,8 @@ void Worker::configure( 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)); + s, cache_size_mapper(ways.size() - 1, i - 1), ways.at(i - 1), + CACHE_DELAY + i)); this->s.push_front(s); } @@ -69,30 +65,45 @@ void Worker::configure( delete old; this->ct_mutex.unlock(); - emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc()); + this->update(); } void Worker::runSteps(int steps) { + this->ct->run_for(steps); + this->update(); +} + +void Worker::update() +{ unsigned long i; this->ct_mutex.lock(); - qDebug() << "Running for " << steps << "steps"; - this->ct->run_for(steps); - - // TODO move these to separate functions emit register_storage(this->ct->get_gprs()); - emit storage(this->s.at(0)->view(0, 255), 1); - - for (i = 1; i < s.size(); ++i) - emit storage(this->s.at(i - 1)->view(0, 1 << this->size_inc * i), i + 1); + 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->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()); + 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; +} diff --git a/gui/worker.h b/gui/worker.h index 95c81d5..c62f4ed 100644 --- a/gui/worker.h +++ b/gui/worker.h @@ -50,11 +50,6 @@ class Worker : public QObject Controller *ct = nullptr; QMutex ct_mutex; - /** - * The size each progressive cache level increases by. - */ - unsigned int size_inc; - public: explicit Worker(QObject *parent = nullptr); ~Worker(); @@ -70,14 +65,28 @@ class Worker : public QObject signals: void clock_cycles(int value, int pc); void - storage(const std::vector<std::array<signed int, LINE_SIZE>> data, int i); + storage(QVector<QVector<int>> data, int i); void register_storage(const std::array<int, GPR_NUM> data); - void if_info(const std::vector<int> info); - void id_info(const std::vector<int> info); - void ex_info(const std::vector<int> info); - void mm_info(const std::vector<int> info); - void wb_info(const std::vector<int> info); + void if_info(const InstrDTO *); + void id_info(const InstrDTO *); + void ex_info(const InstrDTO *); + void mm_info(const InstrDTO *); + void wb_info(const InstrDTO *); void finished(); + + private: + /** + * Converts a vector of arrays into a QVector of QVectors. + * @param the original data + * @return a less universal version of the same thing + */ + QVector<QVector<int>> + data_to_QT(std::vector<std::array<signed int, LINE_SIZE>> data); + /** + * Sets the GUI signals to update the storage, clock cycle, and stage + * displays. + */ + void update(); }; #endif // WORKER_H @@ -56,8 +56,6 @@ class ID : public Stage Response set_vlen(); - std::vector<int> stage_info() override; - private: /** * Helper for `get_instr_fields` @@ -28,8 +28,6 @@ class IF : public Stage InstrDTO *advance(Response p) override; - std::vector<int> stage_info() override; - private: void advance_helper() override; }; diff --git a/inc/stage.h b/inc/stage.h index dde103b..4e0c252 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -53,8 +53,14 @@ class Stage * Must set the status to READY when the current instruction is evicted.. */ virtual InstrDTO *advance(Response p); - - virtual std::vector<int> stage_info(); + /** + * @return the current instruction. + */ + InstrDTO *get_instr(); + /** + * Squashes the pipeline. + */ + void squash(); /* The following methods are made public so that they may be tested, and are * not to be called from outside classes during standard execution. @@ -73,11 +79,6 @@ class Stage void set_condition(CC c, bool v); /** - * Squashes the pipeline. - */ - void squash(); - - /** * The set of registers currently checked out. */ static std::deque<signed int> checked_out; @@ -65,7 +65,7 @@ void ID::write_vec_guard(signed int v, std::array<signed int, V_R_LIMIT> &vrs){ // keep track in the instrDTO for displaying to user and writeback // keep track in checked_out so we can still access this information! this->checked_out.push_back(v); - this->curr_instr->checked_out = v; + this->curr_instr->checked_out = v; } vrs = this->dereference_register<std::array<signed int, V_R_LIMIT>>(v); } @@ -131,7 +131,7 @@ Response ID::set_vlen(){ this->curr_instr->slot_A = V_R_LIMIT; } else { this->curr_instr->slot_A = vlen_reg; - } + } } return r; } @@ -223,7 +223,7 @@ void ID::decode_I_type(signed int &s1) // vector value to be stored 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; return; case LOADV: @@ -306,13 +306,3 @@ void ID::decode_J_type(signed int &s1) } } - -std::vector<int> ID::stage_info() -{ - std::vector<int> info; - if (this->curr_instr) { - info.push_back(this->curr_instr->is_squashed); - info.push_back(this->curr_instr->slot_A); - } - return info; -} @@ -37,15 +37,6 @@ InstrDTO *IF::advance(Response p) return r; } -std::vector<int> IF::stage_info() { - std::vector<int> info; - if(this->curr_instr){ - info.push_back(this->curr_instr->is_squashed); - info.push_back(this->curr_instr->slot_A); - } - return info; -} - void IF::advance_helper() { Response r; diff --git a/src/stage.cc b/src/stage.cc index 47e7e32..ac688d8 100644 --- a/src/stage.cc +++ b/src/stage.cc @@ -66,27 +66,22 @@ InstrDTO *Stage::advance(Response p) return r; } -bool Stage::is_vector_type(Mnemonic m){ - return (m == ADDV || m == SUBV || m == MULV || m == DIVV || m == CEV || m == LOADV || m == STOREV); -} - -bool Stage::is_logical(Mnemonic m){ - return (m == ANDI || m == ORI || m == XORI || m == AND || m == OR || m == XOR || m== NOT); +bool Stage::is_vector_type(Mnemonic m) +{ + return ( + m == ADDV || m == SUBV || m == MULV || m == DIVV || m == CEV || + m == LOADV || m == STOREV); } -std::vector<int> Stage::stage_info() +bool Stage::is_logical(Mnemonic m) { - std::vector<int> info; - if (this->curr_instr) { - info.push_back(this->curr_instr->mnemonic); - info.push_back(this->curr_instr->is_squashed); - info.push_back(this->curr_instr->operands.integer.slot_one); - info.push_back(this->curr_instr->operands.integer.slot_two); - info.push_back(this->curr_instr->operands.integer.slot_three); - } - return info; + return ( + m == ANDI || m == ORI || m == XORI || m == AND || m == OR || m == XOR || + m == NOT); } +InstrDTO *Stage::get_instr() { return this->curr_instr; } + void Stage::set_condition(CC c, bool v) { if (v) |