summaryrefslogtreecommitdiff
path: root/src/id.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/id.cc')
-rw-r--r--src/id.cc159
1 files changed, 54 insertions, 105 deletions
diff --git a/src/id.cc b/src/id.cc
index e4790ef..85637a6 100644
--- a/src/id.cc
+++ b/src/id.cc
@@ -22,87 +22,34 @@
#include "response.h"
#include "stage.h"
-Response ID::read_guard(signed int &v)
-{
- Response r;
- if (this->is_checked_out(v))
- r = STALLED;
- else {
- r = OK;
- v = this->dereference_register<signed int>(v);
- }
- return r;
-}
-
-Response
-ID::read_vec_guard(signed int v, std::array<signed int, V_R_LIMIT> &vrs)
-{
- Response r;
- if (this->is_checked_out(v))
- r = STALLED;
- else {
- r = OK;
- vrs = this->dereference_register<std::array<signed int, V_R_LIMIT>>(v);
- }
- return r;
-}
-
-void ID::write_guard(signed int &v)
-{
- // zero register shouldn't be written.
- if (v != 0) {
- // keep track in the instrDTO for displaying to user and writeback
- // keep track in checked_out so we can still access this information!
- this->checked_out.push_back(v);
- this->curr_instr->checked_out = v;
- }
- v = this->dereference_register<signed int>(v);
-}
-
-void ID::write_vec_guard(signed int v, std::array<signed int, V_R_LIMIT> &vrs)
-{
-
- // zero register shouldn't be written.
- if (v != 0) {
- // keep track in the instrDTO for displaying to user and writeback
- // keep track in checked_out so we can still access this information!
- this->checked_out.push_back(v);
- this->curr_instr->checked_out = v;
- }
- vrs = this->dereference_register<std::array<signed int, V_R_LIMIT>>(v);
-}
-
void ID::advance_helper()
{
- signed int s1;
-
if (this->curr_instr->mnemonic == NOP)
this->status = OK;
else {
// instuction in bits in s1
- s1 = this->curr_instr->slot_A;
- get_instr_fields(s1);
+ get_instr_fields(this->curr_instr->slot_A);
}
}
-void ID::get_instr_fields(signed int &s1)
+void ID::get_instr_fields(signed int instr_bits)
{
unsigned int type;
Mnemonic m;
- this->split_instr(s1, type, m);
+ this->split_instr(instr_bits, type, m);
this->curr_instr->mnemonic = m;
+ this->curr_instr->type = instr::get_field_types(m);
switch (type) {
case 0b00:
- this->decode_R_type(s1);
+ this->decode_R_type(instr_bits);
break;
case 0b01:
- this->decode_I_type(s1);
+ this->decode_I_type(instr_bits);
break;
case 0b10:
- this->decode_J_type(s1);
+ this->decode_J_type(instr_bits);
break;
case 0b11:
- // not defined, m = NOP
this->status = OK;
}
}
@@ -127,13 +74,13 @@ Response ID::set_vlen()
{
signed int vlen_reg = 4;
Response r;
- r = this->read_guard(vlen_reg);
+ r = this->read_guard<signed int>(vlen_reg, vlen_reg);
vlen_reg = vlen_reg & 0xf;
if (r == OK) {
if (vlen_reg > V_R_LIMIT) {
- this->curr_instr->slot_A = V_R_LIMIT;
+ this->curr_instr->slot_B = V_R_LIMIT;
} else {
- this->curr_instr->slot_A = vlen_reg;
+ this->curr_instr->slot_B = vlen_reg;
}
}
return r;
@@ -143,8 +90,7 @@ void ID::decode_R_type(signed int &s1)
{
unsigned int s0b, s1b, s2b;
signed int s2, s3;
- Response r1, r2;
- Response r3 = OK;
+ Response r1, r2, r3;
s0b = REG_SIZE;
s1b = s0b + REG_SIZE;
@@ -153,17 +99,18 @@ void ID::decode_R_type(signed int &s1)
s2 = GET_MID_BITS(s1, s0b, s1b);
s1 = GET_LS_BITS(s1, s0b);
- if (this->is_vector_type(this->curr_instr->mnemonic)) {
- r1 = this->read_vec_guard(
+ if (this->curr_instr->type == SI_INT) {
+ r1 = this->read_guard<signed int>(
+ s1, this->curr_instr->operands.integer.slot_one);
+ r2 = this->read_guard<signed int>(
+ s2, this->curr_instr->operands.integer.slot_two);
+ r3 = OK;
+ } else {
+ r1 = this->read_guard<std::array<signed int, V_R_LIMIT>>(
s1, this->curr_instr->operands.vector.slot_one);
- r2 = this->read_vec_guard(
+ r2 = this->read_guard<std::array<signed int, V_R_LIMIT>>(
s2, this->curr_instr->operands.vector.slot_two);
r3 = this->set_vlen();
- } else {
- r1 = this->read_guard(s1);
- this->curr_instr->operands.integer.slot_one = s1;
- r2 = this->read_guard(s2);
- this->curr_instr->operands.integer.slot_two = s2;
}
this->status = (r1 == OK && r2 == OK && r3 == OK) ? OK : STALLED;
@@ -177,14 +124,14 @@ void ID::decode_R_type(signed int &s1)
case MULV:
case DIVV:
if (this->status == OK) {
- this->write_vec_guard(
- s3, this->curr_instr->operands.vector.slot_three);
+ this->curr_instr->operands.vector.slot_three =
+ this->write_guard<std::array<signed int, V_R_LIMIT>>(s3);
}
break;
default:
if (this->status == OK) {
- this->write_guard(s3);
- this->curr_instr->operands.integer.slot_three = s3;
+ this->curr_instr->operands.integer.slot_three =
+ this->write_guard<signed int>(s3);
}
}
}
@@ -199,7 +146,7 @@ void ID::decode_I_type(signed int &s1)
s0b = REG_SIZE;
s1b = s0b + REG_SIZE;
s2b = WORD_SPEC - LINE_SPEC - OPCODE_SIZE;
- // s3 is immediate
+ // s3 is slot_two
s3 = GET_BITS_SIGN_EXTEND(s1, s1b, s2b);
switch (this->curr_instr->mnemonic) {
@@ -210,41 +157,40 @@ void ID::decode_I_type(signed int &s1)
// both operands are read values
// s1 is base address
- r1 = this->read_guard(s1);
+ r1 = this->read_guard<signed int>(s1, s1);
this->curr_instr->operands.integer.slot_one = s1;
// s2 is value to be stored
- r2 = this->read_guard(s2);
+ r2 = this->read_guard<signed int>(s2, s2);
this->curr_instr->operands.integer.slot_two = s2;
this->status = (r1 == OK && r2 == OK) ? OK : STALLED;
return;
case STOREV:
- this->curr_instr->operands.load_store_vector.immediate = s3;
+ this->curr_instr->operands.i_vector.slot_two = s3;
s2 = GET_MID_BITS(s1, s0b, s1b);
s1 = GET_LS_BITS(s1, s0b);
// base address
- r1 = this->read_guard(s1);
- this->curr_instr->operands.load_store_vector.base_addr = s1;
+ r1 = this->read_guard<signed int>(s1, s1);
+ this->curr_instr->operands.i_vector.slot_one = s1;
// vector value to be stored
- r2 = this->read_vec_guard(
- s2, this->curr_instr->operands.load_store_vector.vector_register);
+ r2 = this->read_guard<std::array<signed int, V_R_LIMIT>>(
+ s2, this->curr_instr->operands.i_vector.slot_three);
r3 = this->set_vlen();
this->status = (r1 == OK && r2 == OK && r3 == OK) ? OK : STALLED;
return;
case LOADV:
- this->curr_instr->operands.load_store_vector.immediate = s3;
+ this->curr_instr->operands.i_vector.slot_two = s3;
s2 = GET_LS_BITS(s1, s0b);
s1 = GET_MID_BITS(s1, s0b, s1b);
// base address
- r1 = this->read_guard(s1);
- this->curr_instr->operands.load_store_vector.base_addr = s1;
+ r1 = this->read_guard<signed int>(s1, s1);
+ this->curr_instr->operands.i_vector.slot_one = s1;
r3 = this->set_vlen();
if (r1 == OK && r3 == OK)
// vector destination
- this->write_vec_guard(
- s2,
- this->curr_instr->operands.load_store_vector.vector_register);
+ this->curr_instr->operands.i_vector.slot_three =
+ this->write_guard<std::array<signed int, V_R_LIMIT>>(s2);
this->status = (r1 == OK && r3 == OK) ? OK : STALLED;
return;
case LOAD:
@@ -258,11 +204,11 @@ void ID::decode_I_type(signed int &s1)
s1 = GET_LS_BITS(s1, s0b);
}
- r1 = this->read_guard(s1);
+ r1 = this->read_guard<signed int>(s1, s1);
this->curr_instr->operands.integer.slot_one = s1;
if (r1 == OK) {
- this->write_guard(s2);
- this->curr_instr->operands.integer.slot_two = s2;
+ this->curr_instr->operands.integer.slot_two =
+ this->write_guard<int>(s2);
}
this->status = r1;
}
@@ -284,14 +230,16 @@ void ID::decode_J_type(signed int &s1)
s2 = s1; // source
s3 = 2; // stack pointer
s1 = -1; // increment amount
- r1 = this->read_guard(s2);
+
this->curr_instr->operands.integer.slot_one = s1;
- this->curr_instr->operands.integer.slot_two = s2;
+ r1 = this->read_guard<signed int>(
+ s2, this->curr_instr->operands.integer.slot_two);
r2 = (this->is_checked_out(s3)) ? STALLED
: OK; // we read the stack pointer
if (r1 == OK && r2 == OK) {
- this->write_guard(s3); // we write the stack pointer
- this->curr_instr->operands.integer.slot_three = s3;
+ // we write the stack pointer
+ this->curr_instr->operands.integer.slot_three =
+ this->write_guard<int>(s3);
}
this->status = (r1 == OK && r2 == OK) ? OK : STALLED;
break;
@@ -303,10 +251,11 @@ void ID::decode_J_type(signed int &s1)
r1 = (this->is_checked_out(s3)) ? STALLED
: OK; // we read the stack pointer
if (r1 == OK) {
- this->write_guard(s2);
- this->curr_instr->operands.integer.slot_two = s2;
- this->write_guard(s3); // we write the stack pointer
- this->curr_instr->operands.integer.slot_three = s3;
+ this->curr_instr->operands.integer.slot_two =
+ this->write_guard<int>(s2);
+ // we write the stack pointer
+ this->curr_instr->operands.integer.slot_three =
+ this->write_guard<int>(s3);
}
this->status = r1;
break;
@@ -314,9 +263,9 @@ void ID::decode_J_type(signed int &s1)
s1 = 1; // link register
[[fallthrough]];
default:
- this->status = this->read_guard(s1);
- if(this->status == OK){
- this->curr_instr->operands.integer.slot_one = s1;
+ this->status = this->read_guard<signed int>(
+ s1, this->curr_instr->operands.integer.slot_one);
+ if (this->status == OK) {
this->curr_instr->operands.integer.slot_two = s2;
this->curr_instr->operands.integer.slot_three = s3;
}