summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/storage/cache.cc4
-rw-r--r--src/utils/utils.cc59
2 files changed, 56 insertions, 7 deletions
diff --git a/src/storage/cache.cc b/src/storage/cache.cc
index dccab47..80f59ef 100644
--- a/src/storage/cache.cc
+++ b/src/storage/cache.cc
@@ -69,7 +69,7 @@ Response Cache::process(
Response r = this->is_access_cleared(accessor, address);
if (r == OK) {
int tag, index, offset;
- get_bit_fields(address, &tag, &index, &offset);
+ get_cache_fields(address, &tag, &index, &offset);
request_handler(index, offset);
}
return r;
@@ -104,7 +104,7 @@ void Cache::handle_miss(int expected)
std::array<signed int, LINE_SIZE> *actual;
std::array<int, 2> *meta;
- get_bit_fields(expected, &tag, &index, &offset);
+ get_cache_fields(expected, &tag, &index, &offset);
r = OK;
meta = &this->meta.at(index);
actual = &this->data->at(index);
diff --git a/src/utils/utils.cc b/src/utils/utils.cc
index 3a11c2c..3b140e0 100644
--- a/src/utils/utils.cc
+++ b/src/utils/utils.cc
@@ -4,14 +4,62 @@
#include <string>
#include <vector>
-void get_bit_fields(int address, int *tag, int *index, int *offset)
+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);
+ *tag = GET_MID_BITS(address, L1_CACHE_LINE_SPEC + LINE_SPEC, MEM_WORD_SPEC);
*index = GET_MID_BITS(address, LINE_SPEC, L1_CACHE_LINE_SPEC + LINE_SPEC);
*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;
@@ -28,8 +76,9 @@ const std::string string_format(const char *const zcFormat, ...)
return std::string(zc.data(), iLen);
}
-int wrap_address(int address) {
- if (address < 0){
+int wrap_address(int address)
+{
+ if (address < 0) {
return ((address % MEM_WORDS) + MEM_WORDS) % MEM_WORDS;
}
return address % MEM_WORDS;