From 7c226db9f04de7061596b98763dc408d601d74e1 Mon Sep 17 00:00:00 2001 From: bd Date: Tue, 11 Mar 2025 11:54:21 -0400 Subject: Clarify size of mem and cache in definitions, CLI print invalid tags --- src/utils/utils.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/utils/utils.cc') 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); } -- cgit v1.2.3 From 256fd73b42ae7d10fe0190984d032f839a2127bd Mon Sep 17 00:00:00 2001 From: bd Date: Tue, 11 Mar 2025 17:24:49 -0400 Subject: clarify macro names, implement load in CLI, fix many display issues --- src/cli/cli.cc | 8 ++++---- src/storage/cache.cc | 2 +- src/utils/utils.cc | 4 ++-- tests/utils.cc | 16 ++++++++-------- 4 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/utils/utils.cc') diff --git a/src/cli/cli.cc b/src/cli/cli.cc index d90edef..8dc7e2e 100644 --- a/src/cli/cli.cc +++ b/src/cli/cli.cc @@ -104,10 +104,10 @@ void Cli::load(Accessor accessor, int address) const auto default_fill = std::cout.fill(); signed int data; - // Response r = this->cache->read_word(accessor, address, data); - // std::cout << r << " to " << accessor << " reading " << address << std::endl; - // if (r == OK) - // std::cout << "\tGot:" << std::hex << data; + Response r = this->cache->read_word(accessor, address, data); + std::cout << r << " to " << accessor << " reading " << address << std::endl; + if (r == OK) + std::cout << " Got:" << std::hex << data << std::endl; std::cout.flags(default_flags); std::cout.fill(default_fill); diff --git a/src/storage/cache.cc b/src/storage/cache.cc index a73390b..14a6e61 100644 --- a/src/storage/cache.cc +++ b/src/storage/cache.cc @@ -135,7 +135,7 @@ void Cache::fetch_resource(int expected) r = this->lower->write_line( L1CACHE, actual, ((index << LINE_SPEC) + - (meta->at(0) << (L1_CACHE_SPEC + LINE_SPEC)))); + (meta->at(0) << (L1_CACHE_LINE_SPEC + LINE_SPEC)))); if (r == OK) { meta->at(1) = -1; } diff --git a/src/utils/utils.cc b/src/utils/utils.cc index b5a4d55..87ce488 100644 --- a/src/utils/utils.cc +++ b/src/utils/utils.cc @@ -31,7 +31,7 @@ const std::string string_format(const char *const zcFormat, ...) int wrap_address(int address) { if (address < 0){ - return ((address % MEM_SIZE) + MEM_SIZE) % MEM_SIZE; + return ((address % MEM_LINES) + MEM_LINES) % MEM_LINES; } - return address % MEM_SIZE; + return address % MEM_LINES; } diff --git a/tests/utils.cc b/tests/utils.cc index f0e4c24..900db1a 100644 --- a/tests/utils.cc +++ b/tests/utils.cc @@ -24,21 +24,21 @@ TEST_CASE("Parse arbitrary fields # two", "[cache]") TEST_CASE("wrap address outside upper bound", "[utils]") { - int address = MEM_SIZE + 25; + int address = MEM_LINES + 25; int wrapped = wrap_address(address); REQUIRE(wrapped == 25); } TEST_CASE("wrap address inside upper bound", "[utils]") { - int address = MEM_SIZE - 25; + int address = MEM_LINES - 25; int wrapped = wrap_address(address); - REQUIRE(wrapped == MEM_SIZE - 25); + REQUIRE(wrapped == MEM_LINES - 25); } TEST_CASE("wrap address at upper bound", "[utils]") { - int address = MEM_SIZE; + int address = MEM_LINES; int wrapped = wrap_address(address); REQUIRE(wrapped == 0); } @@ -47,14 +47,14 @@ TEST_CASE("wrap address lower than 0 with magnitude lesser than mem size", "[uti { int address = -10; int wrapped = wrap_address(address); - REQUIRE(wrapped == MEM_SIZE - 10); + REQUIRE(wrapped == MEM_LINES - 10); } TEST_CASE("wrap address lower than 0 but with magnitude greater than mem size", "[utils]") { - int address = -(MEM_SIZE + 10); + int address = -(MEM_LINES + 10); int wrapped = wrap_address(address); - REQUIRE(wrapped == MEM_SIZE - 10); + REQUIRE(wrapped == MEM_LINES - 10); } TEST_CASE("wrap address at 0", "[utils]") @@ -62,4 +62,4 @@ TEST_CASE("wrap address at 0", "[utils]") int address = 0; int wrapped = wrap_address(address); REQUIRE(wrapped == 0); -} \ No newline at end of file +} -- cgit v1.2.3 From fb7735049f571ac45a193481e962f497b4759fa4 Mon Sep 17 00:00:00 2001 From: bd Date: Tue, 11 Mar 2025 19:02:55 -0400 Subject: fix lots of bugs --- inc/definitions.h | 1 + src/storage/cache.cc | 10 ++++++---- src/utils/utils.cc | 7 +++---- tests/utils.cc | 22 +++++++++++----------- 4 files changed, 21 insertions(+), 19 deletions(-) (limited to 'src/utils/utils.cc') diff --git a/inc/definitions.h b/inc/definitions.h index 1d68a60..80fccbe 100644 --- a/inc/definitions.h +++ b/inc/definitions.h @@ -19,6 +19,7 @@ */ #define MEM_WORD_SPEC 10 #define MEM_LINE_SPEC static_cast(MEM_WORD_SPEC - LINE_SPEC) +#define MEM_WORDS static_cast(pow(2, MEM_WORD_SPEC)) #define MEM_LINES static_cast(pow(2, MEM_LINE_SPEC)) /** diff --git a/src/storage/cache.cc b/src/storage/cache.cc index 14a6e61..ea90f50 100644 --- a/src/storage/cache.cc +++ b/src/storage/cache.cc @@ -138,6 +138,7 @@ void Cache::fetch_resource(int expected) (meta->at(0) << (L1_CACHE_LINE_SPEC + LINE_SPEC)))); if (r == OK) { meta->at(1) = -1; + r = WAIT; } } else { r = this->lower->read_line(L1CACHE, expected, actual); @@ -165,11 +166,12 @@ std::ostream &operator<<(std::ostream &os, const Cache &c) std::vector> data = c.view(0, L1_CACHE_LINES); std::array, L1_CACHE_LINES> meta = c.get_meta(); + std::cout << "FOO " << meta.at(31)[0]; 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_LINE_SPEC - LINE_SPEC - L1_CACHE_LINE_SPEC + 2) << "TAG" + << std::setw(MEM_LINE_SPEC - L1_CACHE_LINE_SPEC + 2) << "TAG" << " | D" << std::endl; for (int i = 0; i < L1_CACHE_LINES; ++i) { os << " 0b" << std::setw(L1_CACHE_LINE_SPEC) << std::bitset(i) @@ -178,12 +180,12 @@ std::ostream &operator<<(std::ostream &os, const Cache &c) os << "0x" << std::setfill('0') << std::setw(8) << std::hex << data.at(i).at(j) << " "; } - os << "| 0x" << std::setfill(' '); + os << "| 0b" << std::setfill(' '); if (meta.at(i)[0] < 0) - os << "?"; + os << std::setfill('?') << std::setw(MEM_LINE_SPEC - L1_CACHE_LINE_SPEC) << ""; else - os << std::bitset(meta.at(i)[0]); + os << std::bitset(meta.at(i)[0]); os << " | " << (int)(meta.at(i)[0] >= 0) << std::endl; } diff --git a/src/utils/utils.cc b/src/utils/utils.cc index 87ce488..ebbc1e9 100644 --- a/src/utils/utils.cc +++ b/src/utils/utils.cc @@ -7,8 +7,7 @@ void get_bit_fields(int address, int *tag, int *index, int *offset) { *tag = GET_MID_BITS( - address, LINE_SPEC + L1_CACHE_LINE_SPEC, - MEM_LINE_SPEC + LINE_SPEC + L1_CACHE_LINE_SPEC); + 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); } @@ -31,7 +30,7 @@ const std::string string_format(const char *const zcFormat, ...) int wrap_address(int address) { if (address < 0){ - return ((address % MEM_LINES) + MEM_LINES) % MEM_LINES; + return ((address % MEM_WORDS) + MEM_WORDS) % MEM_WORDS; } - return address % MEM_LINES; + return address % MEM_WORDS; } diff --git a/tests/utils.cc b/tests/utils.cc index 900db1a..ea1a1ed 100644 --- a/tests/utils.cc +++ b/tests/utils.cc @@ -5,9 +5,9 @@ TEST_CASE("Parse arbitrary fields # one", "[cache]") { int tag, index, offset; - int address = 0b111110001010101; + int address = 0b0001010101; get_bit_fields(address, &tag, &index, &offset); - CHECK(tag == 0b11111000); + CHECK(tag == 0b000); CHECK(index == 0b10101); CHECK(offset == 0b01); } @@ -15,30 +15,30 @@ TEST_CASE("Parse arbitrary fields # one", "[cache]") TEST_CASE("Parse arbitrary fields # two", "[cache]") { int tag, index, offset; - int address = 0b000110100111011; + int address = 0b0100111011; get_bit_fields(address, &tag, &index, &offset); - CHECK(tag == 0b00011010); + CHECK(tag == 0b010); CHECK(index == 0b01110); CHECK(offset == 0b11); } TEST_CASE("wrap address outside upper bound", "[utils]") { - int address = MEM_LINES + 25; + int address = MEM_WORDS + 25; int wrapped = wrap_address(address); REQUIRE(wrapped == 25); } TEST_CASE("wrap address inside upper bound", "[utils]") { - int address = MEM_LINES - 25; + int address = MEM_WORDS - 25; int wrapped = wrap_address(address); - REQUIRE(wrapped == MEM_LINES - 25); + REQUIRE(wrapped == MEM_WORDS - 25); } TEST_CASE("wrap address at upper bound", "[utils]") { - int address = MEM_LINES; + int address = MEM_WORDS; int wrapped = wrap_address(address); REQUIRE(wrapped == 0); } @@ -47,14 +47,14 @@ TEST_CASE("wrap address lower than 0 with magnitude lesser than mem size", "[uti { int address = -10; int wrapped = wrap_address(address); - REQUIRE(wrapped == MEM_LINES - 10); + REQUIRE(wrapped == MEM_WORDS - 10); } TEST_CASE("wrap address lower than 0 but with magnitude greater than mem size", "[utils]") { - int address = -(MEM_LINES + 10); + int address = -(MEM_WORDS + 10); int wrapped = wrap_address(address); - REQUIRE(wrapped == MEM_LINES - 10); + REQUIRE(wrapped == MEM_WORDS - 10); } TEST_CASE("wrap address at 0", "[utils]") -- cgit v1.2.3