diff options
author | bd <bdunahu@operationnull.com> | 2025-04-14 23:10:18 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-04-14 23:10:18 -0400 |
commit | 661ba30d5233e1b95ac312e88cd51380e664933b (patch) | |
tree | bc9bba3e3e87025eebf86e6b5013485088cf0ccf /inc | |
parent | 432e6f63ab4742ebf34ba7d031e269af810aa93f (diff) |
Initial refactor of is_access_cleared
Diffstat (limited to 'inc')
-rw-r--r-- | inc/cache.h | 10 | ||||
-rw-r--r-- | inc/dram.h | 28 | ||||
-rw-r--r-- | inc/storage.h | 22 |
3 files changed, 20 insertions, 40 deletions
diff --git a/inc/cache.h b/inc/cache.h index 325d46f..3177f59 100644 --- a/inc/cache.h +++ b/inc/cache.h @@ -54,15 +54,7 @@ nn * Constructor. */ int process(void *id, int address, std::function<void(int index, int offset)> request_handler); /** - * Returns OK if `id` is allowed to complete its request this cycle. - * Handles cache misses, wait times, and setting the current id this - * storage is serving. - * @param the id asking for a resource - * @return 1 if the access can be carried out this function call, 0 otherwise. - */ - int is_access_cleared(void *id, int address); - /** - * Helper for is_access_cleared. + * Helper for process. * Fetches `address` from a lower level of storage if it is not already * present. The victim line is chosen/written back. * @param the address that must be present in cache. @@ -25,42 +25,28 @@ class Dram : public Storage Dram(int delay); ~Dram(); - int - write_word(void *, signed int, int) override; - int - write_line(void *, std::array<signed int, LINE_SIZE>, int) override; - int - read_word(void *, int, signed int &) override; - int - read_line(void *, int, std::array<signed int, LINE_SIZE> &) override; + int write_word(void *, signed int, int) override; + int write_line(void *, std::array<signed int, LINE_SIZE>, int) override; + int read_word(void *, int, signed int &) override; + int read_line(void *, int, std::array<signed int, LINE_SIZE> &) override; /** * TODO This will accept a file at a later date. */ - void - load(std::vector<signed int> program); + void load(std::vector<signed int> program); private: /** * Helper for all access methods. * Calls `request_handler` when `id` is allowed to complete its * request cycle. + * Handles wait times and setting the current id this storage is serving. * @param the source making the request * @param the address to write to * @param the function to call when an access should be completed * @return 1 if the access completed successfully, 0 otherwise */ - int - process(void *id, int address, std::function<void(int line, int word)> request_handler); - /** - * Returns OK if `id` is allowed to complete its request this cycle. - * Handles wait times, side door, and setting the current id this - * storage is serving. - * @param the source making the request - * @return 1 if the access can be completed this function call, 0 otherwise - */ - int - is_access_cleared(void *id); + int process(void *id, int address, std::function<void(int line, int word)> request_handler); /** * Given `address`, returns the line and word it is in. * @param an address diff --git a/inc/storage.h b/inc/storage.h index 81194da..1b71794 100644 --- a/inc/storage.h +++ b/inc/storage.h @@ -24,10 +24,8 @@ class Storage * @param the address to write to. * @return 1 if the request was completed, 0 otherwise. */ - virtual int - write_word(void *id, signed int data, int address) = 0; - virtual int - write_line(void *id, std::array<signed int, LINE_SIZE> data_line, int address) = 0; + virtual int write_word(void *id, signed int data, int address) = 0; + virtual int write_line(void *id, std::array<signed int, LINE_SIZE> data_line, int address) = 0; /** * Get the data line at `address`. @@ -36,10 +34,8 @@ class Storage * @param the data being returned * @return 1 if the request was completed, 0 otherwise */ - virtual int - read_line(void *id, int address, std::array<signed int, LINE_SIZE> &data) = 0; - virtual int - read_word(void *id, int address, signed int &data) = 0; + virtual int read_line(void *id, int address, std::array<signed int, LINE_SIZE> &data) = 0; + virtual int read_word(void *id, int address, signed int &data) = 0; /** * Sidedoor view of `lines` of memory starting at `base`. @@ -48,11 +44,17 @@ 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, LINE_SIZE>> - view(int base, int lines) const; + std::vector<std::array<signed int, LINE_SIZE>> view(int base, int lines) const; protected: /** + * Returns OK if `id` should complete its request this cycle. In the case it can, automatically + * clears the current requester. + * @param the id asking for a resource + * @return 1 if the access can be carried out this function call, 0 otherwise. + */ + int is_access_cleared(); + /** * The data currently stored in this level of storage. */ std::vector<std::array<signed int, LINE_SIZE>> *data; |