From 2aabad6ed432831d6686700118cd189cb157e5cc Mon Sep 17 00:00:00 2001 From: bd Date: Thu, 8 May 2025 20:00:14 -0400 Subject: Use templates rather than two write guard methods --- inc/id.h | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'inc') diff --git a/inc/id.h b/inc/id.h index e8e9c36..ccce961 100644 --- a/inc/id.h +++ b/inc/id.h @@ -25,8 +25,8 @@ 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. @@ -42,18 +42,7 @@ class ID : public Stage * @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 &v); - - void write_vec_guard(signed int r, std::array &v); - Response set_vlen(); private: @@ -95,6 +84,26 @@ 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 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(v); + return r; + } }; #endif /* ID_H_INCLUDED */ -- cgit v1.2.3