summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-03-28 19:55:04 -0400
committerbd <bdunahu@operationnull.com>2025-03-28 19:55:04 -0400
commit579538d8c3240dcec1fd007a67b5ae4aaa832d3b (patch)
tree0e47fc8a8d34ccdf9bdc06d9e23123c51e2f7231
parent136417edd709f0e2d30931d222b658ff7dd9a5a8 (diff)
Move get_instr_fields, add all instruction mnemonics
-rw-r--r--inc/storage.h2
-rw-r--r--inc/utils.h18
-rw-r--r--src/utils/utils.cc49
-rw-r--r--tests/utils.cc108
4 files changed, 1 insertions, 176 deletions
diff --git a/inc/storage.h b/inc/storage.h
index ff1fbcb..d6fa094 100644
--- a/inc/storage.h
+++ b/inc/storage.h
@@ -80,7 +80,7 @@ class Storage
/**
* The accessor currently being serviced.
*/
- enum Accessor requester;
+ Accessor requester;
/**
* The number of cycles until the current request is completed.
*/
diff --git a/inc/utils.h b/inc/utils.h
index 7fed157..a375b68 100644
--- a/inc/utils.h
+++ b/inc/utils.h
@@ -13,24 +13,6 @@
void get_cache_fields(int address, int *tag, int *index, int *offset);
/**
- * Parse an instruction into a type, opcode, and fields. If the type is invalid,
- * only the type field will be set.
- * @param the resulting first field, which varies per type. To call this
- * function properly, this field must contain the full instruction bytes on
- * function entry.
- * @param the resulting second field, which varies per type.
- * @param the resulting third field, which varies per type.
- * @param the resulting type.
- * @param the resulting opcode.
- */
-void get_instr_fields(
- signed int &s1,
- signed int &s2,
- signed int &s3,
- unsigned int &type,
- unsigned int &opcode);
-
-/**
* Formats a string using snprintf.
* @param an object that represents the format string
* @param arguments to be formatted
diff --git a/src/utils/utils.cc b/src/utils/utils.cc
index 3b140e0..e12a0e0 100644
--- a/src/utils/utils.cc
+++ b/src/utils/utils.cc
@@ -4,8 +4,6 @@
#include <string>
#include <vector>
-static Logger *global_log = Logger::getInstance();
-
void get_cache_fields(int address, int *tag, int *index, int *offset)
{
*tag = GET_MID_BITS(address, L1_CACHE_LINE_SPEC + LINE_SPEC, MEM_WORD_SPEC);
@@ -13,53 +11,6 @@ void get_cache_fields(int address, int *tag, int *index, int *offset)
*offset = GET_LS_BITS(address, LINE_SPEC);
}
-void get_instr_fields(
- signed int &s1,
- signed int &s2,
- signed int &s3,
- unsigned int &type,
- unsigned int &opcode)
-{
- type = GET_LS_BITS(s1, TYPE_SIZE);
- switch (type) {
- case 0:
- // R-TYPE
- opcode = GET_MID_BITS(s1, TYPE_SIZE, TYPE_SIZE + R_OPCODE_SIZE);
- s3 = GET_MID_BITS(
- s1, TYPE_SIZE + R_OPCODE_SIZE + (REG_SIZE * 2),
- TYPE_SIZE + R_OPCODE_SIZE + (REG_SIZE * 3));
- s2 = GET_MID_BITS(
- s1, TYPE_SIZE + R_OPCODE_SIZE + REG_SIZE,
- TYPE_SIZE + R_OPCODE_SIZE + (REG_SIZE * 2));
- s1 = GET_MID_BITS(
- s1, TYPE_SIZE + R_OPCODE_SIZE,
- TYPE_SIZE + R_OPCODE_SIZE + REG_SIZE);
- break;
- case 1:
- // I-TYPE
- opcode = GET_MID_BITS(s1, TYPE_SIZE, TYPE_SIZE + OPCODE_SIZE);
- s3 = GET_MID_BITS(
- s1, TYPE_SIZE + OPCODE_SIZE + (REG_SIZE * 2), WORD_SPEC);
- s2 = GET_MID_BITS(
- s1, TYPE_SIZE + OPCODE_SIZE + REG_SIZE,
- TYPE_SIZE + OPCODE_SIZE + (REG_SIZE * 2));
- s1 = GET_MID_BITS(
- s1, TYPE_SIZE + OPCODE_SIZE, TYPE_SIZE + OPCODE_SIZE + REG_SIZE);
- break;
- case 2:
- // J-TYPE
- opcode = GET_MID_BITS(s1, TYPE_SIZE, TYPE_SIZE + OPCODE_SIZE);
- s2 = GET_MID_BITS(s1, TYPE_SIZE + OPCODE_SIZE + REG_SIZE, WORD_SPEC);
- s1 = GET_MID_BITS(
- s1, TYPE_SIZE + OPCODE_SIZE, TYPE_SIZE + OPCODE_SIZE + REG_SIZE);
- break;
- default:
- global_log->log(
- DEBUG,
- string_format("%s returning invalid type: %d", __FUNCTION__, type));
- }
-}
-
const std::string string_format(const char *const zcFormat, ...)
{
va_list vaArgs;
diff --git a/tests/utils.cc b/tests/utils.cc
index 6c72694..2e0e934 100644
--- a/tests/utils.cc
+++ b/tests/utils.cc
@@ -22,114 +22,6 @@ TEST_CASE("Parse arbitrary fields # two", "[utils]")
CHECK(offset == 0b11);
}
-TEST_CASE("Parse invalid type", "[utils]")
-{
- signed int s1 = 0, s2 = 0, s3 = 0;
- unsigned int type = 0, opcode = 0;
-
- s1 = 0x00FF00FF;
- get_instr_fields(s1, s2, s3, type, opcode);
-
- REQUIRE(type == 0b11);
- // behavior does nothing
- CHECK(s1 == 0x00FF00FF);
- CHECK(s2 == 0b0);
- CHECK(s3 == 0b0);
- CHECK(opcode == 0b0);
-}
-
-TEST_CASE("Parse arbitrary r-type # one", "[utils]")
-{
- signed int s1 = 0, s2 = 0, s3 = 0;
- unsigned int type = 0, opcode = 0;
-
- s1 = 0xCCCCCCCC;
- get_instr_fields(s1, s2, s3, type, opcode);
-
- REQUIRE(type == 0b00);
- CHECK(s1 == 0b11001);
- CHECK(s2 == 0b01100);
- CHECK(s3 == 0b00110);
- CHECK(opcode == 0b10011);
-}
-
-TEST_CASE("Parse arbitrary r-type # two", "[utils]")
-{
- signed int s1 = 0, s2 = 0, s3 = 0;
- unsigned int type = 0, opcode = 0;
-
- s1 = 0x99AABBCC;
- get_instr_fields(s1, s2, s3, type, opcode);
-
- REQUIRE(type == 0b00);
- CHECK(s1 == 0b10111);
- CHECK(s2 == 0b01011);
- CHECK(s3 == 0b10101);
- CHECK(opcode == 0b10011);
-}
-
-TEST_CASE("Parse arbitrary i-type # one", "[utils]")
-{
- signed int s1 = 0, s2 = 0, s3 = 0;
- unsigned int type = 0, opcode = 0;
-
- s1 = 0xDDDDDDDD;
- get_instr_fields(s1, s2, s3, type, opcode);
-
- REQUIRE(type == 0b01);
- CHECK(s1 == 0b10111);
- CHECK(s2 == 0b11011);
- CHECK(s3 == 0xDDDD);
- CHECK(opcode == 0b0111);
-}
-
-TEST_CASE("Parse arbitrary i-type # two", "[utils]")
-{
- signed int s1 = 0, s2 = 0, s3 = 0;
- unsigned int type = 0, opcode = 0;
-
- s1 = 0xAABBCCDD;
- get_instr_fields(s1, s2, s3, type, opcode);
-
- REQUIRE(type == 0b01);
- CHECK(s1 == 0b10011);
- CHECK(s2 == 0b11001);
- CHECK(s3 == 0xAABB);
- CHECK(opcode == 0b0111);
-}
-
-TEST_CASE("Parse arbitrary j-type # one", "[utils]")
-{
- signed int s1 = 0, s2 = 0, s3 = 0;
- unsigned int type = 0, opcode = 0;
-
- s1 = 0xEEEEEEEE;
- get_instr_fields(s1, s2, s3, type, opcode);
-
- REQUIRE(type == 0b10);
- CHECK(s1 == 0b11011);
- CHECK(s2 == 0b111011101110111011101);
- CHECK(opcode == 0b1011);
- // behavior does nothing
- CHECK(s3 == 0b0);
-}
-
-TEST_CASE("Parse arbitrary j-type # two", "[utils]")
-{
- signed int s1 = 0, s2 = 0, s3 = 0;
- unsigned int type = 0, opcode = 0;
-
- s1 = 0xBBCCDDEE;
- get_instr_fields(s1, s2, s3, type, opcode);
-
- REQUIRE(type == 0b10);
- CHECK(s1 == 0b10111);
- CHECK(s2 == 0b101110111100110011011);
- CHECK(opcode == 0b1011);
- // behavior does nothing
- CHECK(s3 == 0b0);
-}
-
TEST_CASE("wrap address outside upper bound", "[utils]")
{
int address = MEM_WORDS + 25;