From a78163745b43a0c420ae4ea5792def30a94420eb Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 26 Apr 2025 03:39:28 -0400 Subject: Partial cache size generation, full cache display --- gui/util.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 gui/util.cc (limited to 'gui/util.cc') diff --git a/gui/util.cc b/gui/util.cc new file mode 100644 index 0000000..ee75e56 --- /dev/null +++ b/gui/util.cc @@ -0,0 +1,16 @@ +#include "util.h" + +int cache_size_mapper(int total_levels, int level) +{ + const int y_min = 4; + const int y_max = 12; + double f, r; + + if (total_levels <= 1) + return 8; + + f = level / total_levels; + r = y_min + f * (y_max - y_min); + + return r; +} -- cgit v1.2.3 From 6382d595cf947eb54249ff5fea20d8eb073ef3c1 Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 26 Apr 2025 15:11:19 -0400 Subject: Move digit formatter to util.h --- gui/digitlabel.cc | 4 ++-- gui/digitlabeldelegate.cc | 4 ++-- gui/digitlabelhelper.h | 43 ------------------------------------------- gui/storageview.cc | 4 ++-- gui/util.cc | 8 ++++++++ gui/util.h | 23 +++++++++++++++++++++-- 6 files changed, 35 insertions(+), 51 deletions(-) delete mode 100644 gui/digitlabelhelper.h (limited to 'gui/util.cc') diff --git a/gui/digitlabel.cc b/gui/digitlabel.cc index a24a1e1..f77c1fa 100644 --- a/gui/digitlabel.cc +++ b/gui/digitlabel.cc @@ -16,7 +16,7 @@ // along with this program. If not, see . #include "digitlabel.h" -#include "digitlabelhelper.h" +#include "util.h" #include "gui.h" DigitLabel::DigitLabel(QWidget *parent) : QLabel(parent) { setText(QString()); } @@ -43,6 +43,6 @@ void DigitLabel::on_hex_toggle(bool is_hex) void DigitLabel::update_display() { QString t; - t = DigitLabelHelper::format_value(this->v, this->is_hex, this->is_cleared); + t = format_toggled_value(this->v, this->is_hex, this->is_cleared); setText(t); } diff --git a/gui/digitlabeldelegate.cc b/gui/digitlabeldelegate.cc index bf4b175..430946c 100644 --- a/gui/digitlabeldelegate.cc +++ b/gui/digitlabeldelegate.cc @@ -16,7 +16,7 @@ // along with this program. If not, see . #include "digitlabeldelegate.h" -#include "digitlabelhelper.h" +#include "util.h" #include void DigitLabelDelegate::set_hex_display(bool hex) @@ -39,7 +39,7 @@ void DigitLabelDelegate::paint( QStyle *s; v = index.data(Qt::DisplayRole).toInt(); - t = DigitLabelHelper::format_value(v, this->is_hex); + t = format_toggled_value(v, this->is_hex); o = option; initStyleOption(&o, index); diff --git a/gui/digitlabelhelper.h b/gui/digitlabelhelper.h deleted file mode 100644 index 744bf0f..0000000 --- a/gui/digitlabelhelper.h +++ /dev/null @@ -1,43 +0,0 @@ -// 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 . - -#ifndef DIGITLABELHELPER_H -#define DIGITLABELHELPER_H - -#include - -class DigitLabelHelper -{ - public: - /** - * 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. - */ - static QString format_value(int value, bool is_hex, bool is_cleared = false) - { - if (is_cleared) - return QString(); - return is_hex ? QString::asprintf("%08X", value) : QString::number(value); - } -}; - -#endif // DIGITLABELHELPER_H diff --git a/gui/storageview.cc b/gui/storageview.cc index 22baca0..2f444a9 100644 --- a/gui/storageview.cc +++ b/gui/storageview.cc @@ -17,7 +17,7 @@ #include "storageview.h" #include "definitions.h" -#include "digitlabelhelper.h" +#include "util.h" #include #include @@ -60,7 +60,7 @@ QVariant StorageView::headerData(int section, Qt::Orientation o, int role) const return QVariant(); if (o == Qt::Vertical) { - return DigitLabelHelper::format_value(section * 4, this->is_hex); + return format_toggled_value(section * 4, this->is_hex); } return QVariant(); } diff --git a/gui/util.cc b/gui/util.cc index ee75e56..72c0d87 100644 --- a/gui/util.cc +++ b/gui/util.cc @@ -1,4 +1,5 @@ #include "util.h" +#include int cache_size_mapper(int total_levels, int level) { @@ -14,3 +15,10 @@ int cache_size_mapper(int total_levels, int level) 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 index 87c33f6..8e9d308 100644 --- a/gui/util.h +++ b/gui/util.h @@ -1,8 +1,27 @@ +#ifndef UTIL_H +#define UTIL_H + +#include + /** - * 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. + * 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 -- cgit v1.2.3 From d449750f789076459de8d47c2960a1279e543c32 Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 26 Apr 2025 16:38:07 -0400 Subject: Fix some issues in GUI looking for memory leak --- gui/gui.cc | 19 +++++++++++-------- gui/gui.h | 4 ++-- gui/util.cc | 5 +++-- 3 files changed, 16 insertions(+), 12 deletions(-) (limited to 'gui/util.cc') diff --git a/gui/gui.cc b/gui/gui.cc index 2555435..7df1bfc 100644 --- a/gui/gui.cc +++ b/gui/gui.cc @@ -349,28 +349,31 @@ void GUI::make_tabs(int num) ui->storage->clear(); - this->tab_boxes.clear(); qDeleteAll(this->tab_boxes); + this->tab_boxes.clear(); for (i = 0; i < num; ++i) { if (i == 0) { n = "Registers"; e = new StorageView(0, this); - } else if (i == 1) { + } else if (i == num - 1) { n = "DRAM"; - e = new StorageView(MEM_LINES, this); + e = new StorageView(4, this); } else { - n = QString("L%1").arg(i - 1); + n = QString("L%1").arg(i); e = new StorageView( - cache_size_mapper(this->curr_cache_levels, i), this); + // cache_size_mapper(this->curr_cache_levels-1, i-1) + 4, this); } + std::cout << "total levels: " << num << ":" + << this->curr_cache_levels - 1 << " level: " << i + << std::endl; - t = new QTableView; + 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, e, &StorageView::set_hex_display); connect( this, &GUI::hex_toggled, d, &DigitLabelDelegate::set_hex_display); diff --git a/gui/gui.h b/gui/gui.h index 10c8f67..3db88ff 100644 --- a/gui/gui.h +++ b/gui/gui.h @@ -99,12 +99,12 @@ 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; + int curr_cache_levels = 0; /** * The list of storage displays. diff --git a/gui/util.cc b/gui/util.cc index 72c0d87..21bf0be 100644 --- a/gui/util.cc +++ b/gui/util.cc @@ -1,16 +1,17 @@ #include "util.h" +#include "definitions.h" #include int cache_size_mapper(int total_levels, int level) { const int y_min = 4; - const int y_max = 12; + const int y_max = MEM_LINES - 2; double f, r; if (total_levels <= 1) return 8; - f = level / total_levels; + f = level / (double)total_levels; r = y_min + f * (y_max - y_min); return r; -- cgit v1.2.3 From 270d5c95c46385b7f8c3ad5ffd1adb4ac5a43acb Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 26 Apr 2025 23:49:35 -0400 Subject: Fix bug which caused a very large allocation --- gui/gui.cc | 9 +++------ gui/util.cc | 2 +- gui/worker.cc | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) (limited to 'gui/util.cc') diff --git a/gui/gui.cc b/gui/gui.cc index 7df1bfc..6e7da5f 100644 --- a/gui/gui.cc +++ b/gui/gui.cc @@ -358,16 +358,13 @@ void GUI::make_tabs(int num) e = new StorageView(0, this); } else if (i == num - 1) { n = "DRAM"; - e = new StorageView(4, this); + e = new StorageView(MEM_LINES, this); } else { n = QString("L%1").arg(i); e = new StorageView( - // cache_size_mapper(this->curr_cache_levels-1, i-1) - 4, this); + (1 << cache_size_mapper(this->curr_cache_levels - 1, i - 1)), + this); } - std::cout << "total levels: " << num << ":" - << this->curr_cache_levels - 1 << " level: " << i - << std::endl; t = new QTableView(ui->storage); t->setModel(e); diff --git a/gui/util.cc b/gui/util.cc index 21bf0be..f3486fb 100644 --- a/gui/util.cc +++ b/gui/util.cc @@ -5,7 +5,7 @@ int cache_size_mapper(int total_levels, int level) { const int y_min = 4; - const int y_max = MEM_LINES - 2; + const int y_max = MEM_LINE_SPEC - 2; double f, r; if (total_levels <= 1) diff --git a/gui/worker.cc b/gui/worker.cc index 93ccbea..f490fb4 100644 --- a/gui/worker.cc +++ b/gui/worker.cc @@ -48,7 +48,7 @@ void Worker::configure( for (i = ways.size(); i > 0; --i) { s = static_cast(new Cache( - s, cache_size_mapper(ways.size() - 1, i), ways.at(i - 1), + s, cache_size_mapper(ways.size() - 1, i - 1), ways.at(i - 1), CACHE_DELAY + i)); this->s.push_front(s); } -- cgit v1.2.3 From af643762a1627b85f779ea9d864393f7d7035e6a Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 27 Apr 2025 00:04:56 -0400 Subject: Adjust cache size generation algorithm --- gui/util.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gui/util.cc') diff --git a/gui/util.cc b/gui/util.cc index f3486fb..b62ed81 100644 --- a/gui/util.cc +++ b/gui/util.cc @@ -5,11 +5,11 @@ int cache_size_mapper(int total_levels, int level) { const int y_min = 4; - const int y_max = MEM_LINE_SPEC - 2; + const int y_max = MEM_LINE_SPEC - 4; double f, r; - if (total_levels <= 1) - return 8; + if (total_levels <= 0) + return 7; f = level / (double)total_levels; r = y_min + f * (y_max - y_min); -- cgit v1.2.3