summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-05-08 20:00:14 -0400
committerbd <bdunahu@operationnull.com>2025-05-08 20:00:14 -0400
commit2aabad6ed432831d6686700118cd189cb157e5cc (patch)
tree335b2af259956cdda5f4cedd7209991ad533d857 /inc
parentf4a5db14436ddbb2820c0abefcb34e5482105a12 (diff)
Use templates rather than two write guard methods
Diffstat (limited to 'inc')
-rw-r--r--inc/id.h33
1 files changed, 21 insertions, 12 deletions
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<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:
@@ -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 <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;
+ }
};
#endif /* ID_H_INCLUDED */