From 41f612789f652654b5f2fa8c3fee4e348e2081b1 Mon Sep 17 00:00:00 2001 From: Siddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com> Date: Sat, 26 Apr 2025 20:21:02 -0400 Subject: Initial vector extension changes --- inc/ex.h | 7 +------ inc/id.h | 14 ++++++++++---- inc/instrDTO.h | 5 +++++ inc/pipe_spec.h | 2 ++ inc/stage.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- inc/vec.h | 44 ------------------------------------------ 6 files changed, 75 insertions(+), 57 deletions(-) delete mode 100644 inc/vec.h (limited to 'inc') diff --git a/inc/ex.h b/inc/ex.h index c356543..58237ab 100644 --- a/inc/ex.h +++ b/inc/ex.h @@ -63,7 +63,7 @@ class EX : public Stage * @param The next stage in the pipeline. * @return A newly allocated EX object. */ - EX(Stage *next); + using Stage::Stage; using Stage::advance; private: @@ -81,11 +81,6 @@ class EX : public Stage * logic. * All instructions store the result into s1. */ - std::unordered_map< - Mnemonic, - std::function> - instr_map; }; #endif /* EX_H_INCLUDED */ diff --git a/inc/id.h b/inc/id.h index 39485b6..3c9c66b 100644 --- a/inc/id.h +++ b/inc/id.h @@ -50,6 +50,12 @@ class ID : public Stage */ void write_guard(signed int &r); + Response read_vec_guard(signed int r, std::array &v); + + void write_vec_guard(signed int r, std::array &v); + + Response set_vlen(); + std::vector stage_info() override; private: @@ -78,10 +84,10 @@ 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); - 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); + void get_instr_fields(signed int &s1); + void decode_R_type(signed int &s1); + void decode_I_type(signed int &s1); + void decode_J_type(signed int &s1); /** * Helper for `get_instr_fields`. * Given a raw instruction, returns the mnemonic and type. diff --git a/inc/instrDTO.h b/inc/instrDTO.h index 1402526..8f8e28e 100644 --- a/inc/instrDTO.h +++ b/inc/instrDTO.h @@ -18,6 +18,8 @@ #ifndef INSTRDTO_H #define INSTRDTO_H #include "instr.h" +#include "pipe_spec.h" +#include struct U_INT_TYPE { signed int slot_one; @@ -26,6 +28,9 @@ struct U_INT_TYPE { }; struct V_TYPE { + std::array slot_one; + std::array slot_two; + std::array slot_three; }; struct InstrDTO { diff --git a/inc/pipe_spec.h b/inc/pipe_spec.h index 7d65637..d8153af 100644 --- a/inc/pipe_spec.h +++ b/inc/pipe_spec.h @@ -80,6 +80,8 @@ */ #define CACHE_DELAY 1 +#define VECTOR_MEM_DELAY 10 + /** * Return the N least-significant bits from integer K using a bit mask * @param the integer to be parsed diff --git a/inc/stage.h b/inc/stage.h index 7dcb7b4..ae01723 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -82,6 +82,10 @@ class Stage */ static std::deque checked_out; + bool is_vector_type(Mnemonic m); + + bool is_logical(Mnemonic m); + protected: /** * The function expected to do the majority of the work. @@ -103,13 +107,63 @@ class Stage * @param the register number. * @param the value to store. */ - void store_register(signed int v, signed int d); + template + void store_register(signed int v, T d) + { + // if (v < 0 || v >= GPR_NUM + V_NUM) { + // throw std::out_of_range( + // "instruction tried to access register which does not exist"); + // } + + // if (v >= GPR_NUM) + // this->vrs[v % GPR_NUM] = d; + // else + // this->gprs[v] = d; + + if constexpr (std::is_same_v) { + if (v < 0 || v >= GPR_NUM) { + throw std::out_of_range("Invalid GPR index for storing scalar"); + } + gprs[v] = d; + } + else if constexpr (std::is_same_v>) { + if (v < GPR_NUM || v >= GPR_NUM + V_NUM) { + throw std::out_of_range("Invalid VR index for storing vector"); + } + vrs[v % GPR_NUM] = d; + } + } /** * Returns the value of the register corresponding to `v`. * @param the register number. * @return the value in the associated register. */ - signed int dereference_register(signed int v); + template + T dereference_register(signed int v) + { + // signed int r; + + // if (v < 0 || v >= GPR_NUM + V_NUM) { + // throw std::out_of_range( + // "instruction tried to access register which does not exist"); + // } + + // r = (v >= GPR_NUM) ? this->vrs[v % GPR_NUM] : this->gprs[v]; + // return r; + + if constexpr (std::is_same_v) { + if (v < 0 || v >= GPR_NUM) { + throw std::out_of_range("Invalid GPR index"); + } + return gprs[v]; + } + else if constexpr (std::is_same_v>) { + if (v < GPR_NUM || v >= GPR_NUM + V_NUM) { + throw std::out_of_range("Invalid vector register index"); + } + return vrs[v % GPR_NUM]; + } + } /** * The shared pool of general-purpose integer registers. */ @@ -117,7 +171,7 @@ class Stage /** * The shared pool of general-purpose vector registers. */ - static std::array vrs; + static std::array, V_NUM> vrs; /** * The address of the currently executing instruction. */ diff --git a/inc/vec.h b/inc/vec.h deleted file mode 100644 index 68482d5..0000000 --- a/inc/vec.h +++ /dev/null @@ -1,44 +0,0 @@ -// vec.h -#ifndef VEC_H -#define VEC_H - -#include -#include -#include - -template -class Vec { -private: - std::vector data; - -public: - Vec() = default; - Vec(const std::vector& values) : data(values) {} - - // Vector-Vector Operations - Vec operator+(const Vec& other) const; - Vec operator-(const Vec& other) const; - Vec operator*(const Vec& other) const; - Vec operator/(const Vec& other) const; - Vec operator%(const Vec& other) const; - - // Vector-Scalar Operations - Vec operator+(T scalar) const; - Vec operator-(T scalar) const; - Vec operator*(T scalar) const; - Vec operator/(T scalar) const; - Vec operator%(T scalar) const; - - // Utility - void print() const; - size_t size() const { return data.size(); } - - // Friend scalar-vector operations - friend Vec operator+(T scalar, const Vec& vec) { return vec + scalar; } - friend Vec operator-(T scalar, const Vec& vec); - friend Vec operator*(T scalar, const Vec& vec) { return vec * scalar; } - friend Vec operator/(T scalar, const Vec& vec); - friend Vec operator%(T scalar, const Vec& vec); -}; - -#endif -- cgit v1.2.3