diff options
author | bd <bdunahu@operationnull.com> | 2025-04-12 00:44:29 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-04-12 00:44:29 -0400 |
commit | 28a2788e2c59357d9269e558b0bd45db3241c42d (patch) | |
tree | 5e001355106684d514dcb96afcec2ad102513a33 /src | |
parent | 1fb7a9bd5eb41e87871bcbb3423caaabdd8ce1d9 (diff) |
Rewrite utils functions as macros
Diffstat (limited to 'src')
-rw-r--r-- | src/cache.cc | 5 | ||||
-rw-r--r-- | src/dram.cc | 8 | ||||
-rw-r--r-- | src/utils.cc | 42 |
3 files changed, 9 insertions, 46 deletions
diff --git a/src/cache.cc b/src/cache.cc index bbb90b4..acbabcf 100644 --- a/src/cache.cc +++ b/src/cache.cc @@ -1,6 +1,5 @@ #include "cache.h" #include "definitions.h" -#include "utils.h" #include <bits/stdc++.h> #include <iterator> @@ -60,7 +59,7 @@ Cache::process(void *id, int address, std::function<void(int index, int offset)> r = this->is_access_cleared(id, address); if (r) { int tag, index, offset; - get_cache_fields(address, &tag, &index, &offset); + GET_FIELDS(address, &tag, &index, &offset); request_handler(index, offset); } return r; @@ -95,7 +94,7 @@ Cache::is_address_missing(int expected) std::array<signed int, LINE_SIZE> *actual; std::array<int, 2> *meta; - get_cache_fields(expected, &tag, &index, &offset); + GET_FIELDS(expected, &tag, &index, &offset); r = 0; meta = &this->meta.at(index); actual = &this->data->at(index); diff --git a/src/dram.cc b/src/dram.cc index d81e2d2..2fd8a91 100644 --- a/src/dram.cc +++ b/src/dram.cc @@ -4,7 +4,6 @@ #include <bits/stdc++.h> #include <bitset> #include <iterator> -#include <utils.h> Dram::Dram(int delay) : Storage(delay) { this->data->resize(MEM_LINES); } @@ -85,3 +84,10 @@ Dram::is_access_cleared(void *id) } return 0; } + +void +Dram::get_memory_index(int address, int &line, int &word) +{ + line = WRAP_ADDRESS(address) / LINE_SIZE; + word = address % LINE_SIZE; +} diff --git a/src/utils.cc b/src/utils.cc deleted file mode 100644 index e12a0e0..0000000 --- a/src/utils.cc +++ /dev/null @@ -1,42 +0,0 @@ -#include "utils.h" -#include "definitions.h" -#include <cstdarg> -#include <string> -#include <vector> - -void get_cache_fields(int address, int *tag, int *index, int *offset) -{ - *tag = GET_MID_BITS(address, L1_CACHE_LINE_SPEC + LINE_SPEC, MEM_WORD_SPEC); - *index = GET_MID_BITS(address, LINE_SPEC, L1_CACHE_LINE_SPEC + LINE_SPEC); - *offset = GET_LS_BITS(address, LINE_SPEC); -} - -const std::string string_format(const char *const zcFormat, ...) -{ - va_list vaArgs; - va_start(vaArgs, zcFormat); - - va_list vaArgsCopy; - va_copy(vaArgsCopy, vaArgs); - const int iLen = std::vsnprintf(NULL, 0, zcFormat, vaArgsCopy); - va_end(vaArgsCopy); - - std::vector<char> zc(iLen + 1); - std::vsnprintf(zc.data(), zc.size(), zcFormat, vaArgs); - va_end(vaArgs); - return std::string(zc.data(), iLen); -} - -int wrap_address(int address) -{ - if (address < 0) { - return ((address % MEM_WORDS) + MEM_WORDS) % MEM_WORDS; - } - return address % MEM_WORDS; -} - -void get_memory_index(int address, int &line, int &word) -{ - line = wrap_address(address) / LINE_SIZE; - word = address % LINE_SIZE; -} |