From df580c5352528a4837b996a838f486d3838050a4 Mon Sep 17 00:00:00 2001 From: bd Date: Fri, 11 Apr 2025 23:09:49 -0400 Subject: Move storage to a separate git repository. --- inc/cache.h | 84 --------------------------------------------------- inc/cli.h | 97 ----------------------------------------------------------- inc/dram.h | 62 -------------------------------------- inc/storage.h | 95 --------------------------------------------------------- 4 files changed, 338 deletions(-) delete mode 100644 inc/cache.h delete mode 100644 inc/cli.h delete mode 100644 inc/dram.h delete mode 100644 inc/storage.h (limited to 'inc') diff --git a/inc/cache.h b/inc/cache.h deleted file mode 100644 index 88fd352..0000000 --- a/inc/cache.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef CACHE_H -#define CACHE_H -#include "definitions.h" -#include "storage.h" -#include -#include -#include - -class Cache : public Storage -{ - public: - /** - * Constructor. - * @param The number of `lines` contained in memory. The total number of - * 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. - * @return A new cache object. - */ - Cache(Storage *lower, int delay); - ~Cache(); - - Response - write_word(Accessor accessor, signed int data, int address) override; - Response write_line( - Accessor accessor, - std::array data_line, - int address) override; - Response read_line( - Accessor accessor, - int address, - std::array &data_line) override; - Response - read_word(Accessor accessor, int address, signed int &data) override; - - /** - * Getter for the meta attribute. - * TODO this doesn't seem like good object-oriented practice. - * @return this->meta - */ - std::array, L1_CACHE_LINES> get_meta() const; - - private: - /** - * Helper for all access methods. - * Calls `request_handler` when `accessor` is allowed to complete its - * request cycle. - * @param the source making the request - * @param the address to write to - * @param the function to call when an access should be completed - */ - Response process( - Accessor accessor, - int address, - std::function request_handler); - /** - * Returns OK if `accessor` is allowed to complete its request this cycle. - * Handles cache misses, wait times, and setting the current accessor this - * storage is serving. - * @param the accessor asking for a resource - * @return whether or not the access can be carried out this function call. - */ - Response is_access_cleared(Accessor accessor, int address); - /** - * Helper for access_cleared. - * Fetches `address` from a lower level of storage if it is not already - * present. If it is not, temporarily sets the is_blocked attribute of this - * cache level to true, and the victim line is chosen/written back. - * @param the address that must be present in cache. - */ - void handle_miss(int address); - /** - * An array of metadata about elements in `data`. - * If the first value of an element is negative, the corresponding - * element in `data` is invalid. If the most second value of an element - * is nonzero, the corresponding element in `data` is dirty. - */ - std::array, L1_CACHE_LINES> meta; -}; - -std::ostream &operator<<(std::ostream &os, const Cache &c); - -#endif /* CACHE_H_INCLUDED */ diff --git a/inc/cli.h b/inc/cli.h deleted file mode 100644 index a0c698a..0000000 --- a/inc/cli.h +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef CLI_H -#define CLI_H -#include "cache.h" -#include -#include -#include - -class Cli -{ - public: - /** - * Constructor. - * @return A newly allocated CLI object. - */ - Cli(); - ~Cli(); - - /** - * Prints all available commands to the console. - */ - void help(); - - /** - * Loads data from memory from the specified memory address. - * @param memory_address address of the memory where data needs to be loaded - * from - */ - void load(Accessor accessor, int memory_address); - - /** - * Stores data into memory at the specified address. - * @param accessor the pipline stage that is making this request - * @param data data value to be written to the memory - * @param address address of the memory where data needs to be stored - * @return the response from the storage device - */ - void store(Accessor accessor, int data, int address); - - /** - * Resets the memory configuration and cycles to their initial state. - * This function provides a side door reset interface to the memory system, - * allowing the user to reset the memory configuration directly. - */ - void reset(); - - /** - * Advance the clock one cycle, refreshing the storage devices. - */ - void clock(); - - /** - * Displays `lines` lines of the data in `level`, starting from `base`. - * - * - * This function provides a side door view into the storage system, showing - * its current state and configuration. - * @param level the level specifying the storage device. The first level - * one cache is level zero, with descending levels incrementing by a factor - * of one. - */ - void peek(int level); - - /** - * Runs the command line interface - * This function is the main entry point for the command line interface. - */ - void run(); - - private: - /** - * Initializes the cache object. - */ - void initialize(); - /** - * Attempts to match string to either fetch or mem, or throws - * std::invalid_argument otherwise. - * @param the string to be converted accessor - * @return the corresponding accessor - * @throws invalid_argument if the string is not fetch or mem - */ - Accessor match_accessor_or_die(std::string s); - /** Map of commands and their corresponding functions. - * This map is used to store the commands and their corresponding functions. - */ - std::unordered_map)>> - commands; - /** - * The cache object to interface with. - */ - Cache *cache; - /** - * The current cycle. - */ - int cycle; -}; - -#endif /* CLI_H_INCLUDED */ diff --git a/inc/dram.h b/inc/dram.h deleted file mode 100644 index 102ec0f..0000000 --- a/inc/dram.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef DRAM_H -#define DRAM_H -#include "definitions.h" -#include "storage.h" -#include -#include - -class Dram : public Storage -{ - public: - /** - * Constructor. - * @param The number of clock cycles each access takes. - * @return A new memory object. - */ - Dram(int delay); - ~Dram(); - - Response - write_word(Accessor accessor, signed int data, int address) override; - Response read_line( - Accessor accessor, - int address, - std::array &data_line) override; - Response write_line( - Accessor accessor, - std::array data_line, - int address) override; - Response - read_word(Accessor accessor, int address, signed int &data) override; - - /** - * TODO This will accept a file at a later date. - */ - void load(std::vector program); - - private: - /** - * Helper for all access methods. - * Calls `request_handler` when `accessor` is allowed to complete its - * request cycle. - * @param the source making the request - * @param the address to write to - * @param the function to call when an access should be completed - */ - Response process( - Accessor accessor, - int address, - std::function request_handler); - /** - * Returns OK if `accessor` is allowed to complete its request this cycle. - * Handles wait times, side door, and setting the current accessor this - * storage is serving. - * @param the accessor asking for a resource - * @return whether or not the access can be carried out this function call. - */ - Response is_access_cleared(Accessor accessor); -}; - -std::ostream &operator<<(std::ostream &os, const Dram &d); - -#endif /* DRAM_H_INCLUDED */ diff --git a/inc/storage.h b/inc/storage.h deleted file mode 100644 index d6fa094..0000000 --- a/inc/storage.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef STORAGE_H -#define STORAGE_H -#include "accessor.h" -#include "definitions.h" -#include "response.h" -#include -#include -#include -#include - -class Storage -{ - public: - virtual ~Storage() = default; - - /** - * Write `data` word into `address`. - * @param the source making the request. - * @param the data (hexadecimal) to write. - * @param the address to write to. - * @return a status code reflecting the state of the request. - */ - virtual Response write_word(Accessor accessor, signed int data, int address) = 0; - - /** - * Write a data line to given address in this level of storage - */ - virtual Response write_line(Accessor accessor, std::array data_line, int address) = 0; - - - /** - * Get the data line at `address`. - * @param the source making the request. - * @param the address being accessed. - * @return a status code reflecting the state of the request, and the - * data being returned. - */ - virtual Response read_line( - Accessor accessor, - int address, - std::array &data) = 0; - - /** - * Read a word from given address in this level of storage - */ - virtual Response read_word(Accessor accessor, int address, signed int &data) = 0; - - /** - * Sidedoor view of `lines` of memory starting at `base`. - * @param The base line to start getting memory from. - * @param The amount of lines to fetch. - * @return A matrix of data values, where each row is a line and each column - * is a word. - */ - std::vector> - view(int base, int lines) const; - - /** - * Getter for lower attribute. - * TODO this doesn't seem like good object-oriented practice. - * @return this->lower - */ - Storage *get_lower(); - - protected: - /** - * The data currently stored in this level of storage. - */ - std::vector> *data; - /** - * A pointer to the next lowest level of storage. - * Used in case of cache misses. - */ - Storage *lower; - /** - * The number of clock cycles this level of storage takes to complete - * requests. - */ - int delay; - /** - * The accessor currently being serviced. - */ - Accessor requester; - /** - * The number of cycles until the current request is completed. - */ - int wait_time; - /** - * A flag indicating whether this level of storage is currently waiting for - * a lower level. - */ - int is_waiting; -}; - -#endif /* STORAGE_H_INCLUDED */ -- cgit v1.2.3 From 249e5bc94ef86307ecf68f8a07c65b2672ebb21c Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 12 Apr 2025 00:10:52 -0400 Subject: Delete some more storage-only files --- CMakeLists.txt | 7 ++-- gui/CMakeLists.txt | 3 +- gui/main.cc | 2 +- inc/definitions.h | 102 ----------------------------------------------------- inc/stage.h | 2 +- inc/utils.h | 39 -------------------- src/sim/ex.cc | 2 +- src/utils/utils.cc | 42 ---------------------- tests/utils.cc | 65 ---------------------------------- 9 files changed, 7 insertions(+), 257 deletions(-) delete mode 100644 inc/definitions.h delete mode 100644 inc/utils.h delete mode 100644 src/utils/utils.cc delete mode 100644 tests/utils.cc (limited to 'inc') diff --git a/CMakeLists.txt b/CMakeLists.txt index c7918b5..cb614b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,11 +26,6 @@ set(RAM ram) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -# header files -include_directories( - ${PROJECT_SOURCE_DIR}/inc -) - # don't build RAM's tests set(RAM_TESTS OF CACHE BOOL "" FORCE) @@ -47,6 +42,7 @@ qt_standard_project_setup() # binary executable add_library(${PROJECT_NAME}_lib ${SRCS}) +target_include_directories(${PROJECT_NAME}_lib PRIVATE ${PROJECT_SOURCE_DIR}/inc) target_link_libraries(${PROJECT_NAME}_lib ${RAM}_lib) find_package(Catch2 REQUIRED) @@ -56,6 +52,7 @@ file(GLOB_RECURSE TESTS "tests/*.cc") # test executable add_executable(test_rv ${SRCS} ${TESTS}) +target_include_directories(test_rv PRIVATE ${PROJECT_SOURCE_DIR}/inc) target_link_libraries(test_rv PRIVATE Catch2::Catch2WithMain PRIVATE ${RAM}_lib) # test discovery diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 5b177d2..0d73527 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -21,7 +21,8 @@ file(GLOB SRCS qt_add_resources(GUI_RESOURCES "resources.qrc") add_executable(risc_vector ${SRCS} ${GUI_RESOURCES}) -target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_lib ram_lib Qt6::Widgets) +target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/inc) +target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_lib ram_lib Qt6::Widgets) set_target_properties(risc_vector PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" diff --git a/gui/main.cc b/gui/main.cc index e873d1c..5e45465 100644 --- a/gui/main.cc +++ b/gui/main.cc @@ -1,4 +1,4 @@ -#include "definitions.h" +#include "pipe_spec.h" #include "gui.h" #include "logger.h" #include diff --git a/inc/definitions.h b/inc/definitions.h deleted file mode 100644 index c81c4e3..0000000 --- a/inc/definitions.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef DEFINITIONS_H -#define DEFINITIONS_H -#include "logger.h" -#include - -/** - * The number of bits to specify a word in a line - */ -#define LINE_SPEC 2 -/** - * The total number of words in a line - */ -#define LINE_SIZE static_cast(pow(2, 2)) -/** - * Number of bits in a word - */ -#define WORD_SPEC 32 - -/** - * The number of bits to specify a memory word - * The number of bits to specify a memory line - * The total number of lines in memory - */ -#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)) - -/** - * The number of bits to specify a l1 cache word - * The number of bits to specify a l1 cache line - * The total number of lines in l1 cache - */ -#define L1_CACHE_WORD_SPEC 7 -#define L1_CACHE_LINE_SPEC \ - static_cast(L1_CACHE_WORD_SPEC - LINE_SPEC) -#define L1_CACHE_LINES static_cast(pow(2, L1_CACHE_LINE_SPEC)) - -/** - * The total number of cycles a memory access takes - */ -#define MEM_DELAY 3 - -/** - * The total number of cycles a level one cache access takes - */ -#define L1_CACHE_DELAY 0 - -/** - * The number of general purpose registers - */ -#define GPR_NUM 16 - -/** - * The number of vector registers - */ -#define V_NUM 8 - -/** - * The number of bits to specify an instruction type - */ -#define TYPE_SIZE 2 - -/** - * The number of bits to specify a register - */ -#define REG_SIZE 5 - -/** - * The number of bits to specify an R-Type opcode. - */ -#define R_OPCODE_SIZE 5 - -/** - * The number of bits to specify an opcode. - */ -#define OPCODE_SIZE 4 - -/** - * The maximum value an integer can hold. - * The minimum is always this number plus one negated. - */ -#define MAX_INT 2147483647 - -/** - * Return the N least-significant bits from integer K using a bit mask - * @param the integer to be parsed - * @param the number of bits to be parsed - * @return the N least-significant bits from K - */ -#define GET_LS_BITS(k, n) ((k) & ((1 << (n)) - 1)) -/** - * Return the bits from integer K starting at N and ending at M using a bit - * mask - * @param the integer to be parsed - * @param the index of the starting bit to be parsed - * @param the index of the ending bit to be parsed - * @return a section of bits from K - */ -#define GET_MID_BITS(k, m, n) GET_LS_BITS((k) >> (m), ((n) - (m))) - -#endif /* DEFINITIONS_H_INCLUDED */ diff --git a/inc/stage.h b/inc/stage.h index 51ab667..da33075 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -1,8 +1,8 @@ #ifndef STAGE_H #define STAGE_H #include "accessor.h" -#include "definitions.h" #include "instrDTO.h" +#include "pipe_spec.h" #include "response.h" #include "storage.h" #include diff --git a/inc/utils.h b/inc/utils.h deleted file mode 100644 index a375b68..0000000 --- a/inc/utils.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef UTILS_H -#define UTILS_H -#include - -/** - * Parse an address into a tag, index into the cache table, and a line - * offset. - * @param the address to be parsed - * @param the resulting tag - * @param the resulting index - * @param the resulting offset - */ -void get_cache_fields(int address, int *tag, int *index, int *offset); - -/** - * Formats a string using snprintf. - * @param an object that represents the format string - * @param arguments to be formatted - * @return a string object holding the formatted result - */ -const std::string string_format(const char *const zcFormat, ...); - -/** - * Given `address`, returns an address that is within the current memory size - * using a clean wrap. - * @param an address - * @return an address guaranteed to be within range. - */ -int wrap_address(int address); - -/** - * Given `address`, returns the line and word it is in. - * @param an address - * @param the line (row) `address` is in - * @param the word (column) `address` corresponds to - */ -void get_memory_index(int address, int &line, int &word); - -#endif /* UTILS_H_INCLUDED */ diff --git a/src/sim/ex.cc b/src/sim/ex.cc index b6f8a1d..50f00a8 100644 --- a/src/sim/ex.cc +++ b/src/sim/ex.cc @@ -1,6 +1,6 @@ #include "ex.h" #include "accessor.h" -#include "definitions.h" +#include "pipe_spec.h" #include "instrDTO.h" #include "response.h" #include "stage.h" diff --git a/src/utils/utils.cc b/src/utils/utils.cc deleted file mode 100644 index e12a0e0..0000000 --- a/src/utils/utils.cc +++ /dev/null @@ -1,42 +0,0 @@ -#include "utils.h" -#include "definitions.h" -#include -#include -#include - -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 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; -} diff --git a/tests/utils.cc b/tests/utils.cc deleted file mode 100644 index 2e0e934..0000000 --- a/tests/utils.cc +++ /dev/null @@ -1,65 +0,0 @@ -#include "utils.h" -#include "definitions.h" -#include - -TEST_CASE("Parse arbitrary fields # one", "[utils]") -{ - int tag, index, offset; - int address = 0b0001010101; - get_cache_fields(address, &tag, &index, &offset); - CHECK(tag == 0b000); - CHECK(index == 0b10101); - CHECK(offset == 0b01); -} - -TEST_CASE("Parse arbitrary fields # two", "[utils]") -{ - int tag, index, offset; - int address = 0b0100111011; - get_cache_fields(address, &tag, &index, &offset); - CHECK(tag == 0b010); - CHECK(index == 0b01110); - CHECK(offset == 0b11); -} - -TEST_CASE("wrap address outside upper bound", "[utils]") -{ - int address = MEM_WORDS + 25; - int wrapped = wrap_address(address); - REQUIRE(wrapped == 25); -} - -TEST_CASE("wrap address inside upper bound", "[utils]") -{ - int address = MEM_WORDS - 25; - int wrapped = wrap_address(address); - REQUIRE(wrapped == MEM_WORDS - 25); -} - -TEST_CASE("wrap address at upper bound", "[utils]") -{ - int address = MEM_WORDS; - int wrapped = wrap_address(address); - REQUIRE(wrapped == 0); -} - -TEST_CASE("wrap address lower than 0 with magnitude lesser than mem size", "[utils]") -{ - int address = -10; - int wrapped = wrap_address(address); - REQUIRE(wrapped == MEM_WORDS - 10); -} - -TEST_CASE("wrap address lower than 0 but with magnitude greater than mem size", "[utils]") -{ - int address = -(MEM_WORDS + 10); - int wrapped = wrap_address(address); - REQUIRE(wrapped == MEM_WORDS - 10); -} - -TEST_CASE("wrap address at 0", "[utils]") -{ - int address = 0; - int wrapped = wrap_address(address); - REQUIRE(wrapped == 0); -} -- cgit v1.2.3 From 3ae113c7d6f1b6f46d8960b284837a44fbeb2e77 Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 12 Apr 2025 00:11:05 -0400 Subject: Add pipe_spec.h --- inc/pipe_spec.h | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 inc/pipe_spec.h (limited to 'inc') diff --git a/inc/pipe_spec.h b/inc/pipe_spec.h new file mode 100644 index 0000000..772314e --- /dev/null +++ b/inc/pipe_spec.h @@ -0,0 +1,68 @@ +#ifndef PIPE_SPEC_H +#define PIPE_SPEC_H +#include "logger.h" +#include + +/** + * The number of bits to specify a word in a line + */ +#define LINE_SPEC 2 +/** + * The total number of words in a line + */ +#define LINE_SIZE static_cast(pow(2, 2)) + +/** + * The number of general purpose registers + */ +#define GPR_NUM 16 + +/** + * The number of vector registers + */ +#define V_NUM 8 + +/** + * The number of bits to specify an instruction type + */ +#define TYPE_SIZE 2 + +/** + * The number of bits to specify a register + */ +#define REG_SIZE 5 + +/** + * The number of bits to specify an R-Type opcode. + */ +#define R_OPCODE_SIZE 5 + +/** + * The number of bits to specify an opcode. + */ +#define OPCODE_SIZE 4 + +/** + * The maximum value an integer can hold. + * The minimum is always this number plus one negated. + */ +#define MAX_INT 2147483647 + +/** + * Return the N least-significant bits from integer K using a bit mask + * @param the integer to be parsed + * @param the number of bits to be parsed + * @return the N least-significant bits from K + */ +#define GET_LS_BITS(k, n) ((k) & ((1 << (n)) - 1)) +/** + * Return the bits from integer K starting at N and ending at M using a bit + * mask + * @param the integer to be parsed + * @param the index of the starting bit to be parsed + * @param the index of the ending bit to be parsed + * @return a section of bits from K + */ +#define GET_MID_BITS(k, m, n) GET_LS_BITS((k) >> (m), ((n) - (m))) + +#endif /* DEFINITIONS_H_INCLUDED */ -- cgit v1.2.3