From 9793bf119cc6314e264bdfc9e98bc27c81db0adb Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 29 Mar 2025 12:30:54 -0400 Subject: Add implementation functions for checking out a register. --- inc/instrDTO.h | 21 +++++++++++++-------- inc/response.h | 1 + inc/stage.h | 40 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 9 deletions(-) (limited to 'inc') diff --git a/inc/instrDTO.h b/inc/instrDTO.h index 2a6ab1f..77a223e 100644 --- a/inc/instrDTO.h +++ b/inc/instrDTO.h @@ -1,9 +1,10 @@ #ifndef INSTRDTO_H #define INSTRDTO_H -#include +#include "accessor.h" +#include "instr.h" #include +#include #include -#include "accessor.h" class InstrDTO { @@ -39,9 +40,9 @@ class InstrDTO */ signed int get_s3(); /** - * @return the string representation of oper. + * @return the mnemonic of the instruction */ - std::string get_oper_name(); + Mnemonic get_mnemonic(); /** * @param set hist key @@ -63,6 +64,10 @@ class InstrDTO * @param s3 */ void set_s3(signed int); + /** + * @param the mnemonic of the instruction + */ + void set_mnemonic(Mnemonic); private: /** @@ -82,10 +87,10 @@ class InstrDTO signed int s1; signed int s2; signed int s3; - /** - * The operation to be conducted during the execute phase. - */ - std::function instr; + /** + * The mnemonic of the operation. + */ + Mnemonic mnemonic; }; #endif /* INSTRDTO_H_INCLUDED */ diff --git a/inc/response.h b/inc/response.h index 6cd6678..05e9352 100644 --- a/inc/response.h +++ b/inc/response.h @@ -6,6 +6,7 @@ enum Response { OK, WAIT, BLOCKED, + STALLED, }; std::ostream &operator<<(std::ostream &os, Response r); diff --git a/inc/stage.h b/inc/stage.h index f6bad41..0348263 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -1,11 +1,12 @@ #ifndef STAGE_H #define STAGE_H +#include "accessor.h" #include "definitions.h" #include "instrDTO.h" #include "response.h" #include "storage.h" -#include "accessor.h" #include +#include class Stage { @@ -27,6 +28,16 @@ class Stage virtual Response advance(InstrDTO &i) = 0; protected: + /** + * Facilitates register checkout. + * 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 check_out(unsigned int &r); /** * The name of the pipeline stage. */ @@ -59,6 +70,33 @@ class Stage * The current clock cycle. */ static int clock_cycle; + + private: + /** + * Helper for `check_out`. + * Returns true if r are not checked out, false otherwise. + * @param a list of register numbers. + * @return true if registers are not in checked_out, false otherwise. + */ + bool is_checked_out(unsigned int r); + /** + * Helper for `check_out`. + * Checks out a single register, and places it in checked_out. + * @param a register number. + * @return the value in the register. + */ + signed int check_out_register(unsigned int r); + // TODO fix this comment after writeback stage + /** + * Helper for `check_out_register` + * @param the register number. + * @return the value in the associated register. + */ + signed int dereference_register(unsigned int r); + /** + * The set of registers currently checked out. + */ + static std::set checked_out; }; #endif /* STAGE_H_INCLUDED */ -- cgit v1.2.3