aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine/cache.cpp
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-08 19:55:47 +0100
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-08 19:55:47 +0100
commitc22e9cb1e18f35d02eb76b4f03a319a673168285 (patch)
tree729e6b6bf605d3ca3a80c50fc92e210ac5e38b94 /qtmips_machine/cache.cpp
parent89afab40d3e7c3d2ec0830b0cce897954c202d14 (diff)
downloadqtmips-c22e9cb1e18f35d02eb76b4f03a319a673168285.tar.gz
qtmips-c22e9cb1e18f35d02eb76b4f03a319a673168285.tar.bz2
qtmips-c22e9cb1e18f35d02eb76b4f03a319a673168285.zip
Move computation of cache row, column and tag to single inline function.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_machine/cache.cpp')
-rw-r--r--qtmips_machine/cache.cpp27
1 files changed, 10 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