From d0bb0aaf39bb61736e72b30e4d8f1a4a39536a0c Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 10 May 2025 15:17:40 -0400 Subject: Combine read_vec_guard and read_guard using templates --- inc/id.h | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'inc') diff --git a/inc/id.h b/inc/id.h index ccce961..c1928ed 100644 --- a/inc/id.h +++ b/inc/id.h @@ -32,17 +32,6 @@ class ID : public Stage * 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); - Response read_vec_guard(signed int r, std::array &v); Response set_vlen(); private: @@ -104,6 +93,26 @@ class ID : public Stage r = this->dereference_register(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 replaces reg with the value of the register and + * returns OK. If false, returns STALLED. + * + * @param the registers number, to be dereferenced. + * @return OK if `reg` is not checked out, STALLED otherwise. + */ + template Response read_guard(int reg, T &result) + { + Response response; + if (this->is_checked_out(reg)) + response = STALLED; + else { + response = OK; + result = this->dereference_register(reg); + } + return response; + } }; #endif /* ID_H_INCLUDED */ -- cgit v1.2.3