diff options
author | bd <bdunahu@operationnull.com> | 2025-03-11 11:54:21 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-03-11 11:54:21 -0400 |
commit | 7c226db9f04de7061596b98763dc408d601d74e1 (patch) | |
tree | c6d4ff93026441bff50de16633706ee3dd2ea196 /src | |
parent | 202f9a05d449ddc1160584c4e8a87f397f248e94 (diff) |
Clarify size of mem and cache in definitions, CLI print invalid tags
Diffstat (limited to 'src')
-rw-r--r-- | src/cli/cli.cc | 4 | ||||
-rw-r--r-- | src/storage/cache.cc | 29 | ||||
-rw-r--r-- | src/storage/dram.cc | 8 | ||||
-rw-r--r-- | src/utils/utils.cc | 6 |
4 files changed, 26 insertions, 21 deletions
diff --git a/src/cli/cli.cc b/src/cli/cli.cc index 0729e00..c9f83e9 100644 --- a/src/cli/cli.cc +++ b/src/cli/cli.cc @@ -116,7 +116,7 @@ void Cli::load(Accessor accessor, int address) void Cli::store(Accessor accessor, int data, int address) { Response r = this->cache->write(accessor, data, address); - std::cout << r << " to " << accessor << " storing " << data << " in" + std::cout << r << " to " << accessor << " storing " << data << " in " << address << std::endl; } @@ -209,7 +209,7 @@ void Cli::initialize() if (this->cache != nullptr) delete this->cache; - Dram *d = new Dram(MEM_SIZE, MEM_DELAY); + Dram *d = new Dram(MEM_LINES, MEM_DELAY); this->cache = new Cache(d, L1_CACHE_DELAY); this->cycle = 1; } diff --git a/src/storage/cache.cc b/src/storage/cache.cc index 1a8a10b..ddab551 100644 --- a/src/storage/cache.cc +++ b/src/storage/cache.cc @@ -10,7 +10,7 @@ Cache::Cache(Storage *lower, int delay) { this->data = new std::vector<std::array<signed int, LINE_SIZE>>; - this->data->resize(L1_CACHE_SIZE); + this->data->resize(L1_CACHE_LINES); this->delay = delay; this->is_waiting = false; this->lower = lower; @@ -84,9 +84,9 @@ void Cache::fetch_resource(int expected) this->is_waiting = (r == OK) ? false : true; } -std::array<std::array<int, 2>, L1_CACHE_SIZE> Cache::get_meta() const +std::array<std::array<int, 2>, L1_CACHE_LINES> Cache::get_meta() const { - std::array<std::array<int, 2>, L1_CACHE_SIZE> ret; + std::array<std::array<int, 2>, L1_CACHE_LINES> ret; std::copy(std::begin(this->meta), std::end(this->meta), std::begin(ret)); return ret; } @@ -97,24 +97,29 @@ std::ostream &operator<<(std::ostream &os, const Cache &c) const auto default_fill = std::cout.fill(); std::vector<std::array<signed int, LINE_SIZE>> data = - c.view(0, L1_CACHE_SIZE); - std::array<std::array<int, 2>, L1_CACHE_SIZE> meta = c.get_meta(); + c.view(0, L1_CACHE_LINES); + std::array<std::array<int, 2>, L1_CACHE_LINES> meta = c.get_meta(); - os << " " << std::setfill(' ') << std::setw(L1_CACHE_SPEC + 2) << "INDEX" + os << " " << std::setfill(' ') << std::setw(L1_CACHE_LINE_SPEC + 2) << "INDEX" << " | " << std::setfill(' ') << std::setw((8 + 3) * 4 - 1) << "DATA" << " | " << std::setfill(' ') - << std::setw(MEM_SPEC - LINE_SPEC - L1_CACHE_SPEC + 2) << "TAG" + << std::setw(MEM_LINE_SPEC - LINE_SPEC - L1_CACHE_LINE_SPEC + 2) << "TAG" << " | D" << std::endl; - for (int i = 0; i < L1_CACHE_SIZE; ++i) { - os << " 0b" << std::setw(L1_CACHE_SPEC) << std::bitset<L1_CACHE_SPEC>(i) + for (int i = 0; i < L1_CACHE_LINES; ++i) { + os << " 0b" << std::setw(L1_CACHE_LINE_SPEC) << std::bitset<L1_CACHE_LINE_SPEC>(i) << " | "; for (int j = 0; j < LINE_SIZE; ++j) { os << "0x" << std::setfill('0') << std::setw(8) << std::hex << data.at(i).at(j) << " "; } - os << "| 0x" << std::setfill(' ') - << std::bitset<MEM_SPEC - LINE_SPEC - L1_CACHE_SPEC>(meta.at(i)[0]) - << " | " << (int)(meta.at(i)[0] >= 0) << std::endl; + os << "| 0x" << std::setfill(' '); + + if (meta.at(i)[0] < 0) + os << "?"; + else + os << std::bitset<MEM_LINE_SPEC - LINE_SPEC - L1_CACHE_LINE_SPEC>(meta.at(i)[0]); + + os << " | " << (int)(meta.at(i)[0] >= 0) << std::endl; } std::cout.flags(default_flags); diff --git a/src/storage/dram.cc b/src/storage/dram.cc index e755c2a..d239cb1 100644 --- a/src/storage/dram.cc +++ b/src/storage/dram.cc @@ -80,13 +80,13 @@ std::ostream &operator<<(std::ostream &os, const Dram &d) const auto default_flags = std::cout.flags(); const auto default_fill = std::cout.fill(); - std::vector<std::array<signed int, LINE_SIZE>> data = d.view(0, MEM_SIZE); + std::vector<std::array<signed int, LINE_SIZE>> data = d.view(0, MEM_LINES); - os << " " << std::setfill(' ') << std::setw(MEM_SPEC + 2) << "INDEX" + os << " " << std::setfill(' ') << std::setw(MEM_LINE_SPEC + 2) << "INDEX" << " | " << std::setfill(' ') << std::setw((8 + 3) * 4 - 1) << "DATA" << std::endl; - for (int i = 0; i < MEM_SIZE; ++i) { - os << " 0b" << std::setw(MEM_SPEC) << std::bitset<MEM_SPEC>(i) << " | "; + for (int i = 0; i < MEM_LINES; ++i) { + os << " 0b" << std::setw(MEM_LINE_SPEC) << std::bitset<MEM_LINE_SPEC>(i) << " | "; for (int j = 0; j < LINE_SIZE; ++j) { os << "0x" << std::setfill('0') << std::setw(8) << std::hex << data.at(i).at(j) << ' '; diff --git a/src/utils/utils.cc b/src/utils/utils.cc index 5de8e89..3a99cec 100644 --- a/src/utils/utils.cc +++ b/src/utils/utils.cc @@ -7,9 +7,9 @@ void get_bit_fields(int address, int *tag, int *index, int *offset) { *tag = GET_MID_BITS( - address, LINE_SPEC + L1_CACHE_SPEC, - MEM_SPEC + LINE_SPEC + L1_CACHE_SPEC); - *index = GET_MID_BITS(address, LINE_SPEC, L1_CACHE_SPEC + LINE_SPEC); + address, LINE_SPEC + L1_CACHE_LINE_SPEC, + MEM_LINE_SPEC + LINE_SPEC + L1_CACHE_LINE_SPEC); + *index = GET_MID_BITS(address, LINE_SPEC, L1_CACHE_LINE_SPEC + LINE_SPEC); *offset = GET_LS_BITS(address, LINE_SPEC); } |