diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/accessor.h | 35 | ||||
-rw-r--r-- | inc/dum.h | 45 | ||||
-rw-r--r-- | inc/ex.h | 2 | ||||
-rw-r--r-- | inc/id.h | 11 | ||||
-rw-r--r-- | inc/if.h | 10 | ||||
-rw-r--r-- | inc/instr.h | 7 | ||||
-rw-r--r-- | inc/instrDTO.h | 133 | ||||
-rw-r--r-- | inc/mm.h | 7 | ||||
-rw-r--r-- | inc/pipe_spec.h | 5 | ||||
-rw-r--r-- | inc/response.h | 3 | ||||
-rw-r--r-- | inc/stage.h | 22 | ||||
-rw-r--r-- | inc/wb.h | 7 |
12 files changed, 43 insertions, 244 deletions
diff --git a/inc/accessor.h b/inc/accessor.h deleted file mode 100644 index 67a68b9..0000000 --- a/inc/accessor.h +++ /dev/null @@ -1,35 +0,0 @@ -// Simulator for the RISC-V[ECTOR] mini-ISA -// Copyright (C) 2025 Siddarth Suresh -// Copyright (C) 2025 bdunahu - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see <https://www.gnu.org/licenses/>. - -#ifndef ACCESSOR_H -#define ACCESSOR_H -#include <iostream> - -enum Accessor { - IDLE, - WRITE, - MEM, - EXEC, - DCDE, - FETCH, - L1CACHE, - SIDE, -}; - -std::ostream &operator<<(std::ostream &os, Accessor a); - -#endif /* ACCESSOR_H_INCLUDED */ diff --git a/inc/dum.h b/inc/dum.h deleted file mode 100644 index 4a3069a..0000000 --- a/inc/dum.h +++ /dev/null @@ -1,45 +0,0 @@ -// Simulator for the RISC-V[ECTOR] mini-ISA -// Copyright (C) 2025 Siddarth Suresh -// Copyright (C) 2025 bdunahu - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see <https://www.gnu.org/licenses/>. - -#ifndef DUM_H -#define DUM_H -#include "instrDTO.h" -#include "response.h" -#include "stage.h" - -/** - * Don't underestimate mocks (the DUM pipe stage). - */ -class DUM : public Stage -{ - public: - /** - * Constructor. - * @param The next stage in the pipeline. - * @return A newly allocated DUM object. - */ - DUM(Stage *next); - - InstrDTO *advance(Response p) override; - - void set_curr_instr(InstrDTO *); - - private: - void advance_helper() override; -}; - -#endif /* DUM_H_INCLUDED */ @@ -41,7 +41,7 @@ ((b < 0) && (a < 0) && (a < MAX_INT / b))) #define MULTIPLICATION_UF_GUARD(a, b) \ - (b != 0) && \ + (b != 0) && (b != -1) && \ (((b > 0) && (a < 0) && (a < (-(MAX_INT)-1) / b)) || \ ((b < 0) && (a > 0) && (a > (-(MAX_INT)-1) / b))) @@ -25,12 +25,7 @@ class ID : public Stage { public: - /** - * Constructor. - * @param The next stage in the pipeline. - * @return A newly allocated ID object. - */ - ID(Stage *next); + using Stage::Stage; using Stage::advance; /* The following methods are made public so that they may be tested, and are @@ -55,8 +50,6 @@ class ID : public Stage */ void write_guard(signed int &r); - std::vector<int> stage_info() override; - private: /** * Helper for `get_instr_fields` @@ -83,7 +76,7 @@ class ID : public Stage * @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, Type &t); + void get_instr_fields(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m); void decode_R_type(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m); void decode_I_type(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m); void decode_J_type(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m); @@ -17,7 +17,6 @@ #ifndef IF_H #define IF_H -#include "accessor.h" #include "instrDTO.h" #include "response.h" #include "stage.h" @@ -25,17 +24,10 @@ class IF : public Stage { public: - /** - * Constructor. - * @param The next stage in the pipeline. - * @return A newly allocated IF object. - */ - IF(Stage *next); + using Stage::Stage; InstrDTO *advance(Response p) override; - std::vector<int> stage_info() override; - private: void advance_helper() override; }; diff --git a/inc/instr.h b/inc/instr.h index 62af09a..98a1f0e 100644 --- a/inc/instr.h +++ b/inc/instr.h @@ -17,7 +17,6 @@ #ifndef INSTR_H #define INSTR_H -#include <functional> #include <unordered_map> enum Mnemonic { @@ -62,13 +61,9 @@ enum Mnemonic { NOP, }; -enum Type { R, I, J, INV }; - namespace instr { -// clang-format off - extern const std::unordered_map<unsigned int, Mnemonic> mnemonic_map; -// clang-format on +extern const std::unordered_map<unsigned int, Mnemonic> mnemonic_map; } // namespace instr #endif /* INSTR_H_INCLUDED */ diff --git a/inc/instrDTO.h b/inc/instrDTO.h index d4af389..1402526 100644 --- a/inc/instrDTO.h +++ b/inc/instrDTO.h @@ -17,133 +17,42 @@ #ifndef INSTRDTO_H #define INSTRDTO_H -#include "accessor.h" #include "instr.h" -#include <functional> -#include <string> -#include <unordered_map> -class InstrDTO -{ - public: - /** - * Constructor. - */ - InstrDTO(); - ~InstrDTO() = default; - - int get_id_cycle(); - /** - * @return instr_bits - */ - signed int get_instr_bits(); - /** - * @return checked_out - */ - signed int get_checked_out(); - /** - * @return s1 - */ - signed int get_s1(); - /** - * @return s2 - */ - signed int get_s2(); - /** - * @return s3 - */ - signed int get_s3(); - /** - * @return the mnemonic of the instruction - */ - Mnemonic get_mnemonic(); - /** - * @return the type of the instruction - */ - Type get_type(); - /** - * @return the program counter at the time this instruction was fetched - */ - unsigned int get_pc(); - /** - * @return 1 if this instruction is invalid, 0 otherwise - */ - int is_squashed(); - - /** - * @param instr_bits - */ - void set_instr_bits(signed int); - /** - * @param checked_out - */ - void set_checked_out(signed int); - /** - * @param s1 - */ - void set_s1(signed int); - /** - * @param s2 - */ - void set_s2(signed int); - /** - * @param s3 - */ - void set_s3(signed int); - /** - * @param the mnemonic of the instruction - */ - void set_mnemonic(Mnemonic); +struct U_INT_TYPE { + signed int slot_one; + signed int slot_two; + signed int slot_three; +}; - /** - * @param the type of the instruction - */ - void set_type(Type); - /** - * @param the program counter at the time this instruction was fetched - */ - void set_pc(unsigned int pc); - /** - * squashes this instruction - */ - void squash(); +struct V_TYPE { +}; - private: +struct InstrDTO { /** - * The raw bits encoding the instruction. + * If this instruction is squashed or not. */ - signed int instr_bits; + unsigned int is_squashed : 1; /** - * The register, if any, this instruction has checked out. A checked out - * register cannot be checked out by another register. This prevents RAW - * conflicts. + * Optional slot for holding the Instruction Bits */ - signed int checked_out; + signed int slot_A; /** - * Slots in this instruction, for storing temporary registers, immediates, - * or other. - * Some instruction types may use these differently. - * The `oper` function is in charge of knowing how to parse these. + * Optional slot for holding PC */ - signed int s1; - signed int s2; - signed int s3; + signed int slot_B; /** - * The mnemonic of the operation. + * The mnemonic of the instruction. */ Mnemonic mnemonic; /** - * Type of the instruction - */ - Type type; - /** - * The PC of the instruction + * The register this instruction checks out. */ - unsigned int pc; - /** - * If this instruction was made dead - */ - unsigned int squashed; + signed int checked_out; + union { + struct U_INT_TYPE integer; + struct V_TYPE vector; + } operands; }; #endif /* INSTRDTO_H_INCLUDED */ @@ -24,12 +24,7 @@ class MM : public Stage { public: - /** - * Constructor. - * @param The next stage in the pipeline. - * @return A newly allocated MM object. - */ - MM(Stage *next); + using Stage::Stage; using Stage::advance; private: diff --git a/inc/pipe_spec.h b/inc/pipe_spec.h index 0433f23..7d65637 100644 --- a/inc/pipe_spec.h +++ b/inc/pipe_spec.h @@ -40,6 +40,11 @@ #define V_NUM 8 /** + * The size, in 32-bit integers, of a vector register. + */ +#define V_R_LIMIT 8 + +/** * The number of bits to specify an instruction type */ #define TYPE_SIZE 2 diff --git a/inc/response.h b/inc/response.h index 501923a..c1f38e7 100644 --- a/inc/response.h +++ b/inc/response.h @@ -21,8 +21,7 @@ enum Response { OK, - WAIT, - BLOCKED, + READY, STALLED, }; diff --git a/inc/stage.h b/inc/stage.h index 448c61a..16f1235 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -17,7 +17,6 @@ #ifndef STAGE_H #define STAGE_H -#include "accessor.h" #include "instrDTO.h" #include "pipe_spec.h" #include "response.h" @@ -51,11 +50,17 @@ class Stage * ready to accept a new instruction object next cycle. * @return a DTO object containing the next instruction to be processed. * - * Must set the status to WAIT when the current instruction is evicted.. + * Must set the status to READY when the current instruction is evicted.. */ virtual InstrDTO *advance(Response p); - - virtual std::vector<int> stage_info(); + /** + * @return the current instruction. + */ + InstrDTO *get_instr(); + /** + * Squashes the pipeline. + */ + void squash(); /* The following methods are made public so that they may be tested, and are * not to be called from outside classes during standard execution. @@ -74,11 +79,6 @@ class Stage void set_condition(CC c, bool v); /** - * Squashes the pipeline. - */ - void squash(); - - /** * The set of registers currently checked out. */ static std::deque<signed int> checked_out; @@ -112,10 +112,6 @@ class Stage */ signed int dereference_register(signed int v); /** - * The name of the pipeline stage. - */ - Accessor id; - /** * The shared pool of general-purpose integer registers. */ static std::array<signed int, GPR_NUM> gprs; @@ -24,12 +24,7 @@ class WB : public Stage { public: - /** - * Constructor. - * @param The next stage in the pipeline. - * @return A newly allocated WB object. - */ - WB(Stage *next); + using Stage::Stage; using Stage::advance; private: |