diff options
author | Siddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com> | 2025-05-11 11:51:15 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-11 11:51:15 -0400 |
commit | a35eb451889f0efa99ff7fe1c0a3a76afd5e7ad5 (patch) | |
tree | 44205b454c11a2d98711cd3226b4828e12a8479a /inc/id.h | |
parent | c7132dbc9c38ff766053bd9a0b72c68b23cd08d2 (diff) | |
parent | 6f4e9e0b914c3e68691a5d884cbad0b5813fcf18 (diff) |
Merge pull request #78 from bdunahu/bdunahu
cleanup/fix existing vector extension
Diffstat (limited to 'inc/id.h')
-rw-r--r-- | inc/id.h | 67 |
1 files changed, 43 insertions, 24 deletions
@@ -25,35 +25,13 @@ class ID : public Stage { public: - using Stage::Stage; using Stage::advance; + using Stage::Stage; /* The following methods are made public so that they may be tested, and are * not to be called from outside classes during standard execution. */ - /** - * Facilitates register checkout and data hazard management. - * It does this by checking that the register passed in is not currently - * checked out. If true, then replaces r with the value of the register and - * returns OK. If false, returns STALLED. - * - * @param the registers number, to be dereferenced. - * @return OK if `r` is not checked out, STALLED otherwise. - */ - Response read_guard(signed int &r); - /** - * Facilitates register checkout and data hazard management. - * Checks out a register and returns it. - * - * @param the registers number, to be dereferenced and checked out. - */ - void write_guard(signed int &r); - - Response read_vec_guard(signed int r, std::array<signed int, V_R_LIMIT> &v); - - void write_vec_guard(signed int r, std::array<signed int, V_R_LIMIT> &v); - Response set_vlen(); private: @@ -82,7 +60,7 @@ class ID : public Stage * @param the resulting third field, which varies per type. * @param the resulting mnemonic. */ - void get_instr_fields(signed int &s1); + void get_instr_fields(signed int instr_bits); void decode_R_type(signed int &s1); void decode_I_type(signed int &s1); void decode_J_type(signed int &s1); @@ -95,6 +73,47 @@ class ID : public Stage * @param the resulting type. */ void split_instr(signed int &raw, unsigned int &type, Mnemonic &m); + /** + * Facilitates register checkout and data hazard management. + * Checks out a register and returns it. + * + * @param the registers number, to be dereferenced and checked out. + */ + template <typename T> T write_guard(int v) + { + T r; + // these registers shouldn't be written. + if (v != 0 && v != 16) { + // keep track in the instrDTO for displaying to user and writeback + // keep track in checked_out so we can still access this + // information! + this->checked_out.push_back(v); + this->curr_instr->checked_out = v; + } + r = this->dereference_register<T>(v); + return r; + } + /** + * Facilitates register checkout and data hazard management. + * It does this by checking that the register passed in is not currently + * checked out. If true, then sets `result' with the value of the register + * and returns OK. If false, returns STALLED. + * + * @param the registers number + * @param the dereferenced register value + * @return OK if `reg` is not checked out, STALLED otherwise. + */ + template <typename T> Response read_guard(int reg, T &result) + { + Response response; + if (this->is_checked_out(reg)) + response = STALLED; + else { + response = OK; + result = this->dereference_register<T>(reg); + } + return response; + } }; #endif /* ID_H_INCLUDED */ |