diff options
author | Siddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com> | 2025-03-29 22:14:42 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-29 22:14:42 -0400 |
commit | d20623d031cf909d8892c2db38cf2e2e02bc6a9b (patch) | |
tree | 56ef4ae4325a5b803c484a3e5c8d87b89572cedf /inc/id.h | |
parent | caeff52f029920e027d18bc01149425560801f82 (diff) | |
parent | 1250c3765f59801d060152d5f6eed0a9faa11b50 (diff) |
Merge pull request #37 from bdunahu/bdunahu
Instr, InstrDTO gets/sets, other structures required for decode
-- tests as we move forward
-- base classes
-- decode stage implemented
Diffstat (limited to 'inc/id.h')
-rw-r--r-- | inc/id.h | 78 |
1 files changed, 75 insertions, 3 deletions
@@ -1,5 +1,6 @@ #ifndef ID_H #define ID_H +#include "instr.h" #include "instrDTO.h" #include "response.h" #include "stage.h" @@ -7,9 +8,80 @@ class ID : public Stage { public: - using Stage::Stage; + /** + * Constructor. + * @param The next stage in the pipeline. + * @return A newly allocated ID object. + */ + ID(Stage *next); - Response advance(InstrDTO &i) override; + Response advance(InstrDTO &next_instr, Response p) override; + + /* The following methods are made public so that they may be tested, and are + * not to be called from outside classes during standard execution. + */ + + /** + * Parse an instruction into a type, opcode, and fields. If the type is + * invalid, only the type field will be set. + * + * This method is marked public so it may be tested, and is not used outside + * of this class during normal execution. + * + * @param the resulting first field, which varies per type. To call this + * function properly, this field must contain the full instruction bytes on + * function entry. + * @param the resulting second field, which varies per type. + * @param the resulting third field, which varies per type. + * @param the resulting mnemonic. + */ + void get_instr_fields( + signed int &s1, signed int &s2, signed int &s3, Mnemonic &m); + /** + * 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); + + private: + /** + * Decodes `curr_instr` and sets status to BLOCKED if a data hazard occurs. + */ + void advance_helper(); + /** + * Helper for `get_instr_fields` + * Attempts to parse and dereference instruction arguments. Uses read and + * write guards to prevent RAW conflicts. + * + * @param the resulting first field. To call this function properly, this + * field must contain the section of the instruction to be parsed. + * @param the resulting second field. + * @param the resulting third field. + */ + void decode_R_type(signed int &s1, signed int &s2, signed int &s3); + void decode_I_type(signed int &s1, signed int &s2, signed int &s3); + void decode_J_type(signed int &s1, signed int &s2); + /** + * Helper for `get_instr_fields`. + * Given a raw instruction, returns the mnemonic and type. + * This operation will destroy the original arguments. + * @param the raw bits to parse. + * @param the resulting mnemonic. + * @param the resulting type. + */ + void split_instr(signed int &raw, unsigned int &type, Mnemonic &m); }; -#endif /* ID_D_INCLUDED */ +#endif /* ID_H_INCLUDED */ |