summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-03-09 12:05:12 -0400
committerbd <bdunahu@operationnull.com>2025-03-09 12:05:12 -0400
commit0b1b537697185613a2da8d5ed374f8f1e1ea9ffe (patch)
treea5dd7456fe035bad6c310215d4f6076ff92f90c6
parent87bc2a9e172a0f693184c85f0d9661d47c99cd7e (diff)
Add bitset field to cache.h for keeping track of write/validity
-rw-r--r--inc/cache.h14
-rw-r--r--src/storage/cache.cc20
-rw-r--r--src/utils/utils.cc2
3 files changed, 31 insertions, 5 deletions
diff --git a/inc/cache.h b/inc/cache.h
index f1fb942..0c86e97 100644
--- a/inc/cache.h
+++ b/inc/cache.h
@@ -1,6 +1,9 @@
#ifndef CACHE_H
#define CACHE_H
-#include <storage.h>
+#include "definitions.h"
+#include "storage.h"
+#include <array>
+#include <bitset>
class Cache : public Storage
{
@@ -19,6 +22,15 @@ class Cache : public Storage
Response write(Accessor accessor, signed int data, int address) override;
Response read(Accessor accessor, int address) override;
+
+ private:
+ /**
+ * An array of paired bits.
+ * If the least significant bit of an element is set, the corresponding
+ * element in `data` is invalid. If the most significant bit of an element
+ * is set, the corresponding element in `data` is dirty.
+ */
+ std::array<std::bitset<2>, L1_CACHE_SIZE> stat;
};
#endif /* CACHE_H_INCLUDED */
diff --git a/src/storage/cache.cc b/src/storage/cache.cc
index bbefb2a..bf1126a 100644
--- a/src/storage/cache.cc
+++ b/src/storage/cache.cc
@@ -6,17 +6,31 @@
Cache::Cache(int lines, Storage *lower, int delay)
{
this->data = new std::vector<std::array<signed int, LINE_SIZE>>;
- this->data->resize(lines);
+ this->data->resize(L1_CACHE_SIZE);
this->lower = lower;
this->delay = delay;
- this->lower = nullptr;
+ for (int i = 0; i < L1_CACHE_SIZE; ++i)
+ this->stat[i] = 0b01;
}
Cache::~Cache() { delete this->data; }
Response Cache::write(Accessor accessor, signed int data, int address)
{
- return WAIT;
+ Response r = WAIT;
+
+ /* Do this first--then process the first cycle immediately. */
+ if (this->requester == IDLE)
+ this->requester = accessor;
+
+ if (this->requester == accessor) {
+ if (this->wait_time == 0) {
+ this->do_write(data, address);
+ r = OK;
+ }
+ }
+
+ return r;
}
Response Cache::read(Accessor accessor, int address) { return WAIT; }
diff --git a/src/utils/utils.cc b/src/utils/utils.cc
index b4bdb2f..52be177 100644
--- a/src/utils/utils.cc
+++ b/src/utils/utils.cc
@@ -1,5 +1,5 @@
-#include "definitions.h"
#include "utils.h"
+#include "definitions.h"
void get_bit_fields(int address, int *tag, int *index, int *offset)
{