@@ -98,26 +98,45 @@ void CacheGraphic::updateLineReplFields(unsigned lineIdx) {
98
98
return ;
99
99
}
100
100
101
- if (m_cacheTextItems.at (0 ).at (0 ).lru == nullptr ) {
101
+ if (m_cacheTextItems.at (0 ).at (0 ).lru == nullptr && m_cache. getReplacementPolicy () == ReplPolicy::LRU ) {
102
102
// The current cache configuration does not have any replacement field
103
103
return ;
104
104
}
105
-
106
- for (const auto &way : m_cacheTextItems[lineIdx]) {
107
- // If LRU was just initialized, the actual (software) LRU value may be very
108
- // large. Mask to the number of actual LRU bits.
109
- unsigned lruVal = cacheLine->at (way.first ).lru ;
110
- lruVal &= vsrtl::generateBitmask (m_cache.getWaysBits ());
111
- const QString lruText = QString::number (lruVal);
112
- way.second .lru ->setText (lruText);
113
-
114
- // LRU text might have changed; update LRU field position to center in
115
- // column
116
- const qreal y = lineIdx * m_lineHeight + way.first * m_setHeight;
117
- const qreal x =
118
- m_widthBeforeLRU + m_lruWidth / 2 - m_fm.horizontalAdvance (lruText) / 2 ;
119
-
120
- way.second .lru ->setPos (x, y);
105
+ if (m_cacheTextItems.at (0 ).at (0 ).lfu == nullptr && m_cache.getReplacementPolicy () == ReplPolicy::LFU){
106
+ return ;
107
+ }
108
+ if (m_cache.getReplacementPolicy () == ReplPolicy::LRU){
109
+ for (const auto &way : m_cacheTextItems[lineIdx]) {
110
+ // If LRU was just initialized, the actual (software) LRU value may be very
111
+ // large. Mask to the number of actual LRU bits.
112
+ unsigned lruVal = cacheLine->at (way.first ).lru ;
113
+ lruVal &= vsrtl::generateBitmask (m_cache.getWaysBits ());
114
+ const QString lruText = QString::number (lruVal);
115
+ way.second .lru ->setText (lruText);
116
+
117
+ // LRU text might have changed; update LRU field position to center in
118
+ // column
119
+ const qreal y = lineIdx * m_lineHeight + way.first * m_setHeight;
120
+ const qreal x =
121
+ m_widthBeforeLRU + m_lruWidth / 2 - m_fm.horizontalAdvance (lruText) / 2 ;
122
+ way.second .lru ->setPos (x, y);
123
+ }
124
+ }
125
+ if (m_cache.getReplacementPolicy () == ReplPolicy::LFU){
126
+ for (const auto &way : m_cacheTextItems[lineIdx]) {
127
+ // If LRU was just initialized, the actual (software) LRU value may be very
128
+ // large. Mask to the number of actual LRU bits.
129
+ int lfuVal = cacheLine->at (way.first ).lfu ;
130
+ const QString lfuText = QString::number (lfuVal);
131
+ way.second .lfu ->setText (lfuText);
132
+
133
+ // LRU text might have changed; update LRU field position to center in
134
+ // column
135
+ const qreal y = lineIdx * m_lineHeight + way.first * m_setHeight;
136
+ const qreal x =
137
+ m_widthBeforeLFU + m_lfuWidth / 2 - m_fm.horizontalAdvance (lfuText) / 2 ;
138
+ way.second .lfu ->setPos (x, y);
139
+ }
121
140
}
122
141
}
123
142
@@ -409,6 +428,7 @@ void CacheGraphic::cacheInvalidated() {
409
428
m_blockWidth = m_fm.horizontalAdvance (" " + addressString () + " " );
410
429
m_bitWidth = m_fm.horizontalAdvance (" 00" );
411
430
m_lruWidth = m_fm.horizontalAdvance (QString::number (m_cache.getWays ()) + " " );
431
+ m_lfuWidth = m_fm.horizontalAdvance (QString::number (m_cache.getWays ()) + " " );
412
432
m_cacheHeight = m_lineHeight * m_cache.getLines ();
413
433
m_tagWidth = m_blockWidth;
414
434
@@ -436,9 +456,10 @@ void CacheGraphic::cacheInvalidated() {
436
456
}
437
457
438
458
m_widthBeforeLRU = width;
459
+ m_widthBeforeLFU = width;
439
460
440
- if (m_cache.getReplacementPolicy () == ReplPolicy::LRU &&
441
- m_cache.getWays () > 1 ) {
461
+ if (m_cache.getReplacementPolicy () == ReplPolicy::LRU
462
+ && m_cache.getWays () > 1 ) {
442
463
// Draw LRU bit column
443
464
new QGraphicsLineItem (width + m_lruWidth, 0 , width + m_lruWidth,
444
465
m_cacheHeight, this );
@@ -451,6 +472,22 @@ void CacheGraphic::cacheInvalidated() {
451
472
width += m_lruWidth;
452
473
}
453
474
475
+ if (m_cache.getReplacementPolicy () == ReplPolicy::LFU
476
+ && m_cache.getWays () > 1 ) {
477
+ // Draw LFU bit column
478
+ new QGraphicsLineItem (width + m_lfuWidth, 0 , width + m_lfuWidth,
479
+ m_cacheHeight, this );
480
+ const QString LFUBitText = " LFU" ;
481
+ auto *textItem = drawText (LFUBitText,
482
+ width + m_lfuWidth / 2 -
483
+ m_fm.horizontalAdvance (LFUBitText) / 2 ,
484
+ -m_fm.height ());
485
+ textItem->setToolTip (" Least Frequently Used bits" );
486
+ width += m_lfuWidth;
487
+ }
488
+
489
+
490
+
454
491
m_widthBeforeTag = width;
455
492
456
493
// Draw tag column
@@ -705,6 +742,14 @@ void CacheGraphic::initializeControlBits() {
705
742
m_fm.horizontalAdvance (lruText) / 2 ;
706
743
line[setIdx].lru = drawText (lruText, x, y);
707
744
}
745
+ if (m_cache.getReplacementPolicy () == ReplPolicy::LFU &&
746
+ m_cache.getWays () > 1 ) {
747
+ const QString lfuText = QString::number (0 );
748
+ x = m_widthBeforeLFU + m_lfuWidth / 2 -
749
+ m_fm.horizontalAdvance (lfuText) / 2 ;
750
+ // Create LFU field
751
+ line[setIdx].lfu = drawText (" 0" , x, y);
752
+ }
708
753
}
709
754
}
710
755
}
0 commit comments