diff options
author | Siddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com> | 2025-04-26 20:21:02 -0400 |
---|---|---|
committer | Siddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com> | 2025-04-26 20:21:02 -0400 |
commit | 41f612789f652654b5f2fa8c3fee4e348e2081b1 (patch) | |
tree | 386658b4231c6c1daa4f2f9769959d0934b2b44e /inc | |
parent | 73633535288711de4850b9d9eec6326eb5de06c0 (diff) |
Initial vector extension changes
Diffstat (limited to 'inc')
-rw-r--r-- | inc/ex.h | 7 | ||||
-rw-r--r-- | inc/id.h | 14 | ||||
-rw-r--r-- | inc/instrDTO.h | 5 | ||||
-rw-r--r-- | inc/pipe_spec.h | 2 | ||||
-rw-r--r-- | inc/stage.h | 60 | ||||
-rw-r--r-- | inc/vec.h | 44 |
6 files changed, 75 insertions, 57 deletions
@@ -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<void( - signed int &s1, signed int s2, signed int s3, unsigned int pc)>> - instr_map; }; #endif /* EX_H_INCLUDED */ @@ -50,6 +50,12 @@ class ID : public Stage */ void write_guard(signed int &r); + Response read_vec_guard(signed int r, std::array<signed int, V_R_LIMIT> &v); + + void write_vec_guard(signed int r, std::array<signed int, V_R_LIMIT> &v); + + Response set_vlen(); + std::vector<int> 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<array> struct U_INT_TYPE { signed int slot_one; @@ -26,6 +28,9 @@ struct U_INT_TYPE { }; struct V_TYPE { + std::array<signed int, V_R_LIMIT> slot_one; + std::array<signed int, V_R_LIMIT> slot_two; + std::array<signed int, V_R_LIMIT> 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<signed int> 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 <typename T> + 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<T, signed int>) { + 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<T, std::array<signed int, V_R_LIMIT>>) { + 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 <typename T> + 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<T, signed int>) { + if (v < 0 || v >= GPR_NUM) { + throw std::out_of_range("Invalid GPR index"); + } + return gprs[v]; + } + else if constexpr (std::is_same_v<T, std::array<signed int, V_R_LIMIT>>) { + 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<signed int, V_NUM> vrs; + static std::array<std::array<signed int, V_R_LIMIT>, 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 <iostream> -#include <vector> -#include <stdexcept> - -template<typename T> -class Vec { -private: - std::vector<T> data; - -public: - Vec() = default; - Vec(const std::vector<T>& values) : data(values) {} - - // Vector-Vector Operations - Vec<T> operator+(const Vec<T>& other) const; - Vec<T> operator-(const Vec<T>& other) const; - Vec<T> operator*(const Vec<T>& other) const; - Vec<T> operator/(const Vec<T>& other) const; - Vec<T> operator%(const Vec<T>& other) const; - - // Vector-Scalar Operations - Vec<T> operator+(T scalar) const; - Vec<T> operator-(T scalar) const; - Vec<T> operator*(T scalar) const; - Vec<T> operator/(T scalar) const; - Vec<T> operator%(T scalar) const; - - // Utility - void print() const; - size_t size() const { return data.size(); } - - // Friend scalar-vector operations - friend Vec<T> operator+(T scalar, const Vec<T>& vec) { return vec + scalar; } - friend Vec<T> operator-(T scalar, const Vec<T>& vec); - friend Vec<T> operator*(T scalar, const Vec<T>& vec) { return vec * scalar; } - friend Vec<T> operator/(T scalar, const Vec<T>& vec); - friend Vec<T> operator%(T scalar, const Vec<T>& vec); -}; - -#endif |