diff options
author | bd <bdunahu@operationnull.com> | 2025-03-06 00:34:35 -0500 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-03-06 00:34:35 -0500 |
commit | 3322aa0845f7fe9cc98aa4e429bd5ecf72a5c27e (patch) | |
tree | 75f627ee8e75c0763ab8b048496464c60e486490 | |
parent | 20fe698a4074df4abe02f14a1a14481770e90abc (diff) |
dram write (no delay, no accessor tracking
-rw-r--r-- | inc/cache.h | 2 | ||||
-rw-r--r-- | inc/definitions.h | 10 | ||||
-rw-r--r-- | inc/dram.h | 2 | ||||
-rw-r--r-- | inc/storage.h | 5 | ||||
-rw-r--r-- | src/storage/cache.cc | 3 | ||||
-rw-r--r-- | src/storage/dram.cc | 12 | ||||
-rw-r--r-- | src/storage/storage.cc | 8 | ||||
-rw-r--r-- | tests/cache.cc | 11 | ||||
-rw-r--r-- | tests/dram.cc | 30 |
9 files changed, 64 insertions, 19 deletions
diff --git a/inc/cache.h b/inc/cache.h index 4d143aa..312f3d1 100644 --- a/inc/cache.h +++ b/inc/cache.h @@ -8,7 +8,7 @@ class Cache : public Storage /** * Constructor. * @param The number of `lines` contained in memory. The total number of - * words is this number multiplied by 4. + * words is this number multiplied by LINE_SIZE. * @param The next lowest level in storage. Methods from this object are * called in case of a cache miss. * @param The number of clock cycles each access takes. diff --git a/inc/definitions.h b/inc/definitions.h new file mode 100644 index 0000000..1593162 --- /dev/null +++ b/inc/definitions.h @@ -0,0 +1,10 @@ +#ifndef DEFINITIONS_H +#define DEFINITIONS_H + +/** + * Defines common macros. + */ + +#define LINE_SIZE 4 + +#endif /* DEFINITIONS_H_INCLUDED */ @@ -8,7 +8,7 @@ class Dram : public Storage /** * Constructor. * @param The number of `lines` contained in memory. The total number of - * words is this number multiplied by 4. + * words is this number multiplied by LINE_SIZE. * @param The number of clock cycles each access takes. * @return A new memory object. */ diff --git a/inc/storage.h b/inc/storage.h index 5ad4f99..c0f09a3 100644 --- a/inc/storage.h +++ b/inc/storage.h @@ -1,5 +1,6 @@ #ifndef STORAGE_H #define STORAGE_H +#include "definitions.h" #include "response.h" #include <array> #include <vector> @@ -37,13 +38,13 @@ class Storage * @return A matrix of data values, where each row is a line and each column * is a word. */ - std::vector<std::array<signed int, 4>> view(int base, int lines); + std::vector<std::array<signed int, LINE_SIZE>> view(int base, int lines); protected: /** * The data currently stored in this level of storage. */ - std::vector<std::array<signed int, 4>> *data; + std::vector<std::array<signed int, LINE_SIZE>> *data; /** * A pointer to the next lowest level of storage. * Used in case of cache misses. diff --git a/src/storage/cache.cc b/src/storage/cache.cc index a4df820..f4f60ba 100644 --- a/src/storage/cache.cc +++ b/src/storage/cache.cc @@ -1,10 +1,11 @@ #include "cache.h" +#include "definitions.h" #include "response.h" #include <bits/stdc++.h> Cache::Cache(int lines, Storage *lower, int delay) { - this->data = new std::vector<std::array<signed int, 4>>; + this->data = new std::vector<std::array<signed int, LINE_SIZE>>; this->data->resize(lines); this->lower = lower; this->delay = delay; diff --git a/src/storage/dram.cc b/src/storage/dram.cc index 89c7316..845db21 100644 --- a/src/storage/dram.cc +++ b/src/storage/dram.cc @@ -1,10 +1,11 @@ #include "dram.h" +#include "definitions.h" #include "response.h" #include <algorithm> Dram::Dram(int lines, int delay) { - this->data = new std::vector<std::array<signed int, 4>>; + this->data = new std::vector<std::array<signed int, LINE_SIZE>>; this->data->resize(lines); this->delay = delay; this->lower = nullptr; @@ -14,7 +15,14 @@ Dram::~Dram() { delete this->data; } Response *Dram::write(Accessor accessor, signed int data, int address) { - return new Response(); + struct Response *r = new Response(); + int line = address / LINE_SIZE; + int word = address % LINE_SIZE; + + this->data->at(line).at(word) = data; + + r->status = OK; + return r; } Response *Dram::read(Accessor accessor, int address) { return nullptr; } diff --git a/src/storage/storage.cc b/src/storage/storage.cc index 49d8e7e..a9a883a 100644 --- a/src/storage/storage.cc +++ b/src/storage/storage.cc @@ -1,10 +1,12 @@ #include "storage.h" +#include "definitions.h" #include <algorithm> -std::vector<std::array<signed int, 4>> Storage::view(int base, int lines) +std::vector<std::array<signed int, LINE_SIZE>> +Storage::view(int base, int lines) { - base = (base / 4) * 4; - std::vector<std::array<signed int, 4>> ret(lines + 1); + base = (base / LINE_SIZE) * LINE_SIZE; + std::vector<std::array<signed int, LINE_SIZE>> ret(lines + 1); std::copy( this->data->begin() + base, this->data->begin() + base + lines, ret.begin()); diff --git a/tests/cache.cc b/tests/cache.cc index 3b3787d..3c1fba6 100644 --- a/tests/cache.cc +++ b/tests/cache.cc @@ -1,11 +1,12 @@ #include "cache.h" +#include "definitions.h" #include <catch2/catch_test_macros.hpp> -TEST_CASE("Constructor initialize test 1", "[cache]") +TEST_CASE("Constructor singleton dram", "[cache]") { - Cache *c = new Cache(1, nullptr, 4); - std::array<signed int, 4> expected = {0, 0, 0, 0}; - std::array<signed int, 4> actual = c->view(0, 1)[0]; - CHECK(expected == actual); + Cache *c = new Cache(1, nullptr, LINE_SIZE); + std::array<signed int, LINE_SIZE> expected = {0, 0, 0, 0}; + std::array<signed int, LINE_SIZE> actual = c->view(0, 1)[0]; + REQUIRE(expected == actual); delete c; } diff --git a/tests/dram.cc b/tests/dram.cc index 8d5d03b..15e2990 100644 --- a/tests/dram.cc +++ b/tests/dram.cc @@ -1,12 +1,34 @@ #include "dram.h" +#include "definitions.h" #include <catch2/catch_test_macros.hpp> #include <array> -TEST_CASE("Constructor initialize test 1", "[dram]") +TEST_CASE("Construct singleton dram", "[dram]") { - Dram *d = new Dram(1, 4); - std::array<signed int, 4> expected = {0, 0, 0, 0}; - std::array<signed int, 4> actual = d->view(0, 1)[0]; + Dram *d = new Dram(1, 1); + std::array<signed int, LINE_SIZE> expected = {0, 0, 0, 0}; + std::array<signed int, LINE_SIZE> actual = d->view(0, 1)[0]; + REQUIRE(expected == actual); + delete d; +} + +TEST_CASE("Construct ingleton dram, store 0th element in zero cycles", "[dram]") +{ + Dram *d = new Dram(1, 0); + std::array<signed int, LINE_SIZE> expected = {0, 0, 0, 0}; + std::array<signed int, LINE_SIZE> actual = d->view(0, 1)[0]; CHECK(expected == actual); + + signed int w = 0x11223344; + + Response *r = d->write(MEMORY, w, 0x00000000); + REQUIRE(r->status == OK); + + + expected.at(0) = w; + actual = d->view(0, 1)[0]; + REQUIRE(expected == actual); + + delete r; delete d; } |