From 03c95d2de3f0693b5e4a67a6a19febb023082889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A0rius=20Mont=C3=B3n?= Date: Mon, 1 Feb 2021 12:24:25 +0100 Subject: [PATCH] removed duplicate code --- inc/A_extension.h | 33 ------------------------------ inc/BASE_ISA.h | 48 -------------------------------------------- inc/M_extension.h | 31 ---------------------------- inc/extension_base.h | 32 +++++++++++++++++++++++------ 4 files changed, 26 insertions(+), 118 deletions(-) diff --git a/inc/A_extension.h b/inc/A_extension.h index 6fab905..96d4e5a 100644 --- a/inc/A_extension.h +++ b/inc/A_extension.h @@ -67,39 +67,6 @@ public: return m_instr.range(31, 27); } - - /** - * @brief Access to rs1 field - * @return rs1 field - */ - inline int32_t get_rs1() const override { - return m_instr.range(19, 15); - } - - inline void set_rs1(int32_t value) override { - m_instr.range(19, 15) = value; - } - - /** - * @brief Access to rs2 field - * @return rs2 field - */ - inline int32_t get_rs2() const override { - return m_instr.range(24, 20); - } - - inline void set_rs2(int32_t value) override { - m_instr.range(24, 20) = value; - } - - inline int32_t get_funct3() const override { - return m_instr.range(14, 12); - } - - inline void set_funct3(int32_t value) override { - m_instr.range(14, 12) = value; - } - /** * @brief Decodes opcode of instruction * @return opcode of instruction diff --git a/inc/BASE_ISA.h b/inc/BASE_ISA.h index 06527ad..f981b40 100644 --- a/inc/BASE_ISA.h +++ b/inc/BASE_ISA.h @@ -100,54 +100,6 @@ public: */ using extension_base::extension_base; - /** - * @brief Access to rs1 field - * @return rs1 field - */ - inline int32_t get_rs1() const override { - return m_instr.range(19, 15); - } - - /** - * @brief Sets rs1 field - * @param value desired rs1 value - */ - inline void set_rs1(int32_t value) override { - m_instr.range(19, 15) = value; - } - - /** - * @brief Access to rs2 field - * @return rs2 field - */ - inline int32_t get_rs2() const override { - return m_instr.range(24, 20); - } - - /** - * @brief Sets rs2 field - * @param value desired rs2 value - */ - inline void set_rs2(int32_t value) override { - m_instr.range(24, 10) = value; - } - - /** - * @brief Access to funct3 field - * @return funct3 field - */ - inline int32_t get_funct3() const override { - return m_instr.range(14, 12); - } - - /** - * @brief Sets func3 field - * @param value desired func3 value - */ - inline void set_funct3(int32_t value) override { - m_instr.range(14, 12) = value; - } - /** * @brief Access to funct7 field * @return funct7 field diff --git a/inc/M_extension.h b/inc/M_extension.h index d030c94..6f9fe0e 100644 --- a/inc/M_extension.h +++ b/inc/M_extension.h @@ -81,37 +81,6 @@ private: return m_instr.range(14, 12); } - /** - * @brief Access to rs1 field - * @return rs1 field - */ - inline int32_t get_rs1() const { - return m_instr.range(19, 15); - } - - inline void set_rs1(int32_t value) { - m_instr.range(19, 15) = value; - } - - /** - * @brief Access to rs2 field - * @return rs2 field - */ - inline int32_t get_rs2() const { - return m_instr.range(24, 20); - } - - inline void set_rs2(int32_t value) { - m_instr.range(24, 20) = value; - } - - inline int32_t get_funct3() const { - return m_instr.range(14, 12); - } - - inline void set_funct3(int32_t value) { - m_instr.range(14, 12) = value; - } }; #endif diff --git a/inc/extension_base.h b/inc/extension_base.h index 2a9a085..b8caf1f 100644 --- a/inc/extension_base.h +++ b/inc/extension_base.h @@ -36,18 +36,38 @@ public: /* pure virtual functions */ virtual int32_t opcode() const = 0; + virtual int32_t get_rd() const { return m_instr.range(11, 7); } + virtual void set_rd(int32_t value) { m_instr.range(11, 7) = value; } - virtual int32_t get_rs1() const = 0; - virtual void set_rs1(int32_t value) = 0; - virtual int32_t get_rs2() const = 0; - virtual void set_rs2(int32_t value) = 0; - virtual int32_t get_funct3() const = 0; - virtual void set_funct3(int32_t value) = 0; + + virtual int32_t get_rs1() const { + return m_instr.range(19, 15); + } + + virtual void set_rs1(int32_t value) { + m_instr.range(19, 15) = value; + } + + virtual int32_t get_rs2() const { + return m_instr.range(24, 20); + } + + virtual void set_rs2(int32_t value) { + m_instr.range(24, 20) = value; + } + + virtual int32_t get_funct3() const { + return m_instr.range(14, 12); + } + + virtual void set_funct3(int32_t value) { + m_instr.range(14, 12) = value; + } virtual void dump() const;