aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qtmips_machine/cache.cpp27
-rw-r--r--qtmips_machine/cache.h9
2 files changed, 19 insertions, 17 deletions
diff --git a/qtmips_machine/cache.cpp b/qtmips_machine/cache.cpp
index 8767ee1..742cdb5 100644
--- a/qtmips_machine/cache.cpp
+++ b/qtmips_machine/cache.cpp
@@ -71,18 +71,18 @@ Cache::Cache(MemoryAccess *m, const MachineConfigCache *cc, unsigned memory_acc
switch (cnf.replacement_policy()) {
case MachineConfigCache::RP_LFU:
replc.lfu = new unsigned *[cnf.sets()];
- for (unsigned row = 0; row < cnf.sets(); row++) {
+ for (unsigned int row = 0; row < cnf.sets(); row++) {
replc.lfu[row] = new unsigned[cnf.associativity()];
- for (int i = 0; i < cnf.associativity(); i++)
- replc.lfu[row][i] = 0;
+ for (unsigned int i = 0; i < cnf.associativity(); i++)
+ replc.lfu[row][i] = 0;
}
break;
case MachineConfigCache::RP_LRU:
replc.lru = new time_t*[cnf.sets()];
- for (unsigned row = 0; row < cnf.sets(); row++) {
+ for (unsigned int row = 0; row < cnf.sets(); row++) {
replc.lru[row] = new time_t[cnf.associativity()];
- for (int i = 0; i < cnf.associativity(); i++)
- replc.lru[row][i] = 0;
+ for (unsigned int i = 0; i < cnf.associativity(); i++)
+ replc.lru[row][i] = 0;
}
default:
break;
@@ -219,11 +219,8 @@ const MachineConfigCache &Cache::config() const {
}
enum LocationStatus Cache::location_status(std::uint32_t address) const {
- address = address >> 2;
- unsigned ssize = cnf.blocks() * cnf.sets();
- std::uint32_t tag = address / ssize;
- std::uint32_t index = address % ssize;
- std::uint32_t row = index / cnf.blocks();
+ std::uint32_t row, col, tag;
+ compute_row_col_tag(row, col, tag, address);
if (cnf.enabled()) {
for (unsigned indx = 0; indx < cnf.associativity(); indx++) {
@@ -241,12 +238,8 @@ enum LocationStatus Cache::location_status(std::uint32_t address) const {
bool Cache::access(std::uint32_t address, std::uint32_t *data, bool write, std::uint32_t value) const {
bool changed = false;
- address = address >> 2;
- unsigned ssize = cnf.blocks() * cnf.sets();
- std::uint32_t tag = address / ssize;
- std::uint32_t index = address % ssize;
- std::uint32_t row = index / cnf.blocks();
- std::uint32_t col = index % cnf.blocks();
+ std::uint32_t row, col, tag;
+ compute_row_col_tag(row, col, tag, address);
unsigned indx = 0;
// Try to locate exact block or some unused one
diff --git a/qtmips_machine/cache.h b/qtmips_machine/cache.h
index 6027bd3..d08e66a 100644
--- a/qtmips_machine/cache.h
+++ b/qtmips_machine/cache.h
@@ -101,6 +101,15 @@ private:
void kick(unsigned associat_indx, unsigned row) const;
std::uint32_t base_address(std::uint32_t tag, unsigned row) const;
void update_statistics() const;
+ inline void compute_row_col_tag(std::uint32_t &row, std::uint32_t &col,
+ std::uint32_t &tag, std::uint32_t address) const {
+ address = address >> 2;
+ std::uint32_t ssize = cnf.blocks() * cnf.sets();
+ tag = address / ssize;
+ std::uint32_t index = address % ssize;
+ row = index / cnf.blocks();
+ col = index % cnf.blocks();
+ }
};
}