Add UI controls for cache write policies
MODIFY
src/cacheconfigwidget.h
src/cacheconfigwidget.h
@@ -33,5 +33,7 @@ private:
} // namespace Ripes
+Q_DECLARE_METATYPE(Ripes::CacheSim::WritePolicy);
+Q_DECLARE_METATYPE(Ripes::CacheSim::WriteAllocPolicy);
Q_DECLARE_METATYPE(Ripes::CacheSim::ReplPolicy);
Q_DECLARE_METATYPE(Ripes::CacheSim::CachePreset);

MODIFY
src/cacheconfigwidget.ui
src/cacheconfigwidget.ui
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
- <item row="1" column="2">
- <widget class="QLabel" name="label_3">
- <property name="text">
- <string>Blocks</string>
+ <item row="3" column="1">
+ <widget class="QSpinBox" name="lines">
+ <property name="maximum">
+ <number>10</number>
</property>
</widget>
</item>
- <item row="5" column="0">
- <widget class="QCheckBox" name="writeback">
- <property name="toolTip">
- <string>Setting the valid bit implies a write-back cache</string>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Ways</string>
</property>
+ </widget>
+ </item>
+ <item row="1" column="2">
+ <widget class="QLabel" name="label_3">
<property name="text">
- <string>Writeback</string>
+ <string>Blocks</string>
</property>
</widget>
</item>
</property>
</widget>
</item>
- <item row="3" column="1">
- <widget class="QSpinBox" name="lines">
+ <item row="1" column="3">
+ <widget class="QSpinBox" name="blocks">
<property name="maximum">
<number>10</number>
</property>
</widget>
</item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_2">
- <property name="text">
- <string>Ways</string>
- </property>
- </widget>
- </item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
</property>
</widget>
</item>
- <item row="1" column="3">
- <widget class="QSpinBox" name="blocks">
- <property name="maximum">
- <number>10</number>
- </property>
- </widget>
- </item>
<item row="3" column="2">
<widget class="QLabel" name="label_8">
<property name="text">
<item row="3" column="3">
<widget class="QComboBox" name="replacementPolicy"/>
</item>
+ <item row="5" column="0">
+ <widget class="QLabel" name="label_9">
+ <property name="text">
+ <string>Wr. hit</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="2">
+ <widget class="QLabel" name="label_10">
+ <property name="text">
+ <string>Wr. miss</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <widget class="QComboBox" name="wrHit"/>
+ </item>
+ <item row="5" column="3">
+ <widget class="QComboBox" name="wrMiss"/>
+ </item>
</layout>
</item>
<item>
<string>Statistics:</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
+ <item row="3" column="0">
+ <widget class="QPushButton" name="undo">
+ <property name="text">
+ <string>Undo</string>
+ </property>
+ </widget>
+ </item>
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="1">
</item>
</layout>
</item>
+ <item row="2" column="0">
+ <widget class="QPushButton" name="randomwrite">
+ <property name="text">
+ <string>Random write</string>
+ </property>
+ </widget>
+ </item>
<item row="1" column="0">
<widget class="QPushButton" name="randomread">
<property name="text">
</property>
</widget>
</item>
- <item row="4" column="0">
+ <item row="5" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</spacer>
</item>
- <item row="2" column="0">
- <widget class="QPushButton" name="randomwrite">
- <property name="text">
- <string>Random write</string>
- </property>
- </widget>
- </item>
- <item row="3" column="0">
- <widget class="QPushButton" name="undo">
+ <item row="4" column="0">
+ <widget class="QPushButton" name="autoAccess">
<property name="text">
- <string>Undo</string>
+ <string>auto</string>
</property>
</widget>
</item>

MODIFY
src/cachegraphic.cpp
src/cachegraphic.cpp
@@ -48,6 +48,7 @@ void CacheGraphic::dataChanged(const CacheSim::CacheTransaction& transaction) {
QGraphicsSimpleTextItem* blockTextItem = cacheWay.blocks[transaction.blockIdx];
const QString text = encodeRadixValue(data, Radix::Hex);
blockTextItem->setText(text);
+ blockTextItem->setToolTip("Address: " + encodeRadixValue(transaction.address, Radix::Hex));
} else {
/* The access is a miss. This implies that:
* - The entirety of the cache way must be reread/reinitialized given that a new cache line is to be read.

MODIFY
src/cachesim.cpp
src/cachesim.cpp
@@ -245,6 +245,10 @@ void CacheSim::setPreset(const CachePreset& preset) {
m_blocks = preset.blocks;
m_ways = preset.ways;
m_lines = preset.lines;
+ m_wrPolicy = preset.wrPolicy;
+ m_wrAllocPolicy = preset.wrAllocPolicy;
+ m_replPolicy = preset.replPolicy;
+
updateConfiguration();
}

MODIFY
src/cachesim.h
src/cachesim.h
@@ -11,6 +11,7 @@ namespace Ripes {
class CacheSim : public QObject {
Q_OBJECT
public:
+ enum class WriteAllocPolicy { WriteAllocate, NoWriteAllocate };
enum class WritePolicy { WriteThrough, WriteBack };
enum class ReplPolicy { Random, LRU };
enum class AccessType { Read, Write };
@@ -24,6 +25,10 @@ public:
int blocks;
int lines;
int ways;
+
+ WritePolicy wrPolicy;
+ WriteAllocPolicy wrAllocPolicy;
+ ReplPolicy replPolicy;
};
struct CacheTransaction {
@@ -59,6 +64,11 @@ public:
updateConfiguration();
}
+ void setWriteAllocatePolicy(WriteAllocPolicy policy) {
+ m_wrAllocPolicy = policy;
+ updateConfiguration();
+ }
+
void setReplacementPolicy(ReplPolicy policy) {
m_replPolicy = policy;
updateConfiguration();
@@ -68,6 +78,7 @@ public:
void undo();
void reset();
+ WriteAllocPolicy getWriteAllocPolicy() const { return m_wrAllocPolicy; }
ReplPolicy getReplacementPolicy() const { return m_replPolicy; }
WritePolicy getWritePolicy() const { return m_wrPolicy; }
@@ -111,6 +122,7 @@ private:
ReplPolicy m_replPolicy = ReplPolicy::LRU;
WritePolicy m_wrPolicy = WritePolicy::WriteBack;
+ WriteAllocPolicy m_wrAllocPolicy = WriteAllocPolicy::WriteAllocate;
unsigned m_blockMask = -1;
unsigned m_lineMask = -1;
@@ -142,7 +154,14 @@ private:
std::map<unsigned, CacheAccessTrace> m_accessTrace;
};
-static std::map<CacheSim::ReplPolicy, QString> s_cachePolicyStrings{{CacheSim::ReplPolicy::Random, "Random"},
+static std::map<CacheSim::ReplPolicy, QString> s_cacheReplPolicyStrings{{CacheSim::ReplPolicy::Random, "Random"},
{CacheSim::ReplPolicy::LRU, "LRU"}};
+static std::map<CacheSim::WriteAllocPolicy, QString> s_cacheWriteAllocateStrings{
+ {CacheSim::WriteAllocPolicy::WriteAllocate, "Write allocate"},
+ {CacheSim::WriteAllocPolicy::NoWriteAllocate, "No write allocate"}};
+
+static std::map<CacheSim::WritePolicy, QString> s_cacheWritePolicyStrings{
+ {CacheSim::WritePolicy::WriteThrough, "Write-through"},
+ {CacheSim::WritePolicy::WriteBack, "Write-back"}};
} // namespace Ripes

MODIFY
src/cacheview.cpp
src/cacheview.cpp
@@ -8,7 +8,6 @@ namespace Ripes {
CacheView::CacheView(QWidget* parent) : QGraphicsView(parent) {
m_zoom = 250;
- setDragMode(QGraphicsView::RubberBandDrag);
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setRenderHint(QPainter::Antialiasing, false);
setInteractive(true);

Add UI controls for cache write policies