From d21a1a9caa1f1791343a5376121936e552b1124c Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 29 Mar 2025 17:11:17 -0400 Subject: Fetch stage properly holds objects until parent is ready --- inc/ex.h | 2 +- inc/id.h | 2 +- inc/if.h | 12 +++++++++++- inc/mm.h | 2 +- inc/stage.h | 26 +++++++++++++++++--------- inc/wb.h | 2 +- 6 files changed, 32 insertions(+), 14 deletions(-) (limited to 'inc') diff --git a/inc/ex.h b/inc/ex.h index c7b7663..e67980d 100644 --- a/inc/ex.h +++ b/inc/ex.h @@ -14,7 +14,7 @@ class EX : public Stage */ EX(Stage *next); - Response advance(InstrDTO &i, Response p) override; + Response advance(InstrDTO &next_instr, Response p) override; }; #endif /* EX_H_INCLUDED */ diff --git a/inc/id.h b/inc/id.h index 95dde37..34e1a47 100644 --- a/inc/id.h +++ b/inc/id.h @@ -15,7 +15,7 @@ class ID : public Stage */ ID(Stage *next); - Response advance(InstrDTO &i, Response p) override; + Response advance(InstrDTO &next_instr, Response p) override; /** * Parse an instruction into a type, opcode, and fields. If the type is diff --git a/inc/if.h b/inc/if.h index a6869f7..9f84e51 100644 --- a/inc/if.h +++ b/inc/if.h @@ -15,7 +15,17 @@ class IF : public Stage */ IF(Stage *next); - Response advance(InstrDTO &i, Response p) override; + Response advance(InstrDTO &next_instr, Response p) override; + + private: + /** + * Performs a fetch only if a current fetch is not pending. Pending means + * that a fetch has completed successfully, but the caller stage in the + * pipeline is not ready to receive it. In this case, `curr_instr` is not + * the nullptr. + * @return STALLED if we are waiting on the storage devices, OK otherwise. + */ + void fetch_with_buffer(); }; #endif /* IF_H_INCLUDED */ diff --git a/inc/mm.h b/inc/mm.h index edee589..0d2ce82 100644 --- a/inc/mm.h +++ b/inc/mm.h @@ -14,7 +14,7 @@ class MM : public Stage */ MM(Stage *next); - Response advance(InstrDTO &i, Response p) override; + Response advance(InstrDTO &next_instr, Response p) override; }; #endif /* MM_H_INCLUDED */ diff --git a/inc/stage.h b/inc/stage.h index 761b9f6..ff4455b 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -7,6 +7,7 @@ #include "storage.h" #include #include +#include class Stage { @@ -17,17 +18,16 @@ class Stage * @return A newly allocated stage object. */ Stage(Stage *next); - virtual ~Stage() = default; + virtual ~Stage(); /** * Advances this stage by a single clock cycle. - * @param a DTO object containing various information about an instruction - * moving through the pipeline. + * @param a DTO object containing the next instruction to be processed. * @param a response, indicating whether or not the parent pipe stage is - * busy. + * ready to accept a new instruction object next cycle. * @return a response, indicating whether this pipeline stage is stalling, * busy, or done. */ - virtual Response advance(InstrDTO &i, Response p) = 0; + virtual Response advance(InstrDTO &next_instr, Response p) = 0; protected: /** @@ -56,10 +56,6 @@ class Stage * The address of the currently executing instruction. */ static unsigned int pc; - /** - * A pointer to the next stage in the pipeline. - */ - Stage *next; /** * A pointer to the top-level storage device. */ @@ -72,6 +68,18 @@ class Stage * The current clock cycle. */ static int clock_cycle; + /** + * A pointer to the next stage in the pipeline. + */ + Stage *next; + /** + * A pointer to the current instruction this stage is processing. + */ + std::unique_ptr curr_instr; + /** + * The current status of this stage. + */ + Response status; private: /** diff --git a/inc/wb.h b/inc/wb.h index c1a6a32..9a708a6 100644 --- a/inc/wb.h +++ b/inc/wb.h @@ -14,7 +14,7 @@ class WB : public Stage */ WB(Stage *next); - Response advance(InstrDTO &i, Response p) override; + Response advance(InstrDTO &next_instr, Response p) override; }; #endif /* WB_H_INCLUDED */ -- cgit v1.2.3