fix many significant bugs

This commit is contained in:
2024-08-01 13:50:45 +00:00
parent c7a7524884
commit 90033d5c63
7 changed files with 156 additions and 85 deletions

View File

@ -145,6 +145,8 @@ struct ALU : public dark::Module<ALU_Input, ALU_Output> {
alu_status <= 0b10; alu_status <= 0b10;
result_ROB_index <= request_ROB_index; result_ROB_index <= request_ROB_index;
result <= static_cast<max_size_t>(operand1) + imm; result <= static_cast<max_size_t>(operand1) + imm;
std::cerr << "\taddi: operand1=" << std::hex << static_cast<max_size_t>(operand1) << " imm=" << std::hex
<< static_cast<max_size_t>(imm) << " result=" << std::hex << result.peek() << std::endl;
completed_alu_resulting_PC <= static_cast<max_size_t>(request_PC) + 4; completed_alu_resulting_PC <= static_cast<max_size_t>(request_PC) + 4;
return; return;
} }

View File

@ -255,6 +255,8 @@ struct CentralScheduleUnit
commit_has_resulting_register <= record.has_resulting_register; commit_has_resulting_register <= record.has_resulting_register;
commit_reg_index <= record.resulting_register_idx; commit_reg_index <= record.resulting_register_idx;
commit_reg_value <= record.resulting_register_value; commit_reg_value <= record.resulting_register_value;
std::cerr << "commit_reg_index=" << std::dec << commit_reg_index.peek() << " commit_reg_value=" << std::hex
<< std::setw(8) << std::setfill('0') << std::uppercase << commit_reg_value.peek() << std::endl;
commit_ins_ROB_index <= i; commit_ins_ROB_index <= i;
actual_PC <= static_cast<max_size_t>(record.resulting_PC); actual_PC <= static_cast<max_size_t>(record.resulting_PC);
if (static_cast<max_size_t>(record.PC_mismatch_mark) == 1) { if (static_cast<max_size_t>(record.PC_mismatch_mark) == 1) {
@ -266,6 +268,10 @@ struct CentralScheduleUnit
halt_signal <= (0b100000000 | static_cast<max_size_t>(a0)); halt_signal <= (0b100000000 | static_cast<max_size_t>(a0));
std::cerr << "halting with code " << std::dec << int(halt_signal.peek()) << std::endl; std::cerr << "halting with code " << std::dec << int(halt_signal.peek()) << std::endl;
} }
if (record.instruction == 0x1B07A503) {
std::cerr << "judgeResult loaded from memory is " << std::dec
<< static_cast<max_size_t>(record.resulting_register_value) << std::endl;
}
} }
} }
if (!has_committed) is_committing <= 0; if (!has_committed) is_committing <= 0;
@ -331,7 +337,8 @@ struct CentralScheduleUnit
// can issue // can issue
std::cerr << "csu is issuing mem instruct " << std::hex << std::setw(8) << std::setfill('0') << std::uppercase std::cerr << "csu is issuing mem instruct " << std::hex << std::setw(8) << std::setfill('0') << std::uppercase
<< instruction << " full_ins_id= " << std::hex << std::setw(8) << std::setfill('0') << instruction << " full_ins_id= " << std::hex << std::setw(8) << std::setfill('0')
<< std::uppercase << full_ins_id << std::endl; << std::uppercase << full_ins_id << " with ROB_index=" << std::dec
<< static_cast<max_size_t>(ROB_tail) << std::endl;
is_issuing <= 1; is_issuing <= 1;
has_instruction_issued_last_cycle <= 1; has_instruction_issued_last_cycle <= 1;
uint32_t tail = static_cast<max_size_t>(ROB_tail); uint32_t tail = static_cast<max_size_t>(ROB_tail);
@ -370,7 +377,8 @@ struct CentralScheduleUnit
// can issue // can issue
std::cerr << "csu is issuing alu instruct " << std::hex << std::setw(8) << std::setfill('0') << std::uppercase std::cerr << "csu is issuing alu instruct " << std::hex << std::setw(8) << std::setfill('0') << std::uppercase
<< instruction << " full_ins_id= " << std::hex << std::setw(8) << std::setfill('0') << instruction << " full_ins_id= " << std::hex << std::setw(8) << std::setfill('0')
<< std::uppercase << full_ins_id << std::endl; << std::uppercase << full_ins_id << " with ROB_index=" << std::dec
<< static_cast<max_size_t>(ROB_tail) << std::endl;
is_issuing <= 1; is_issuing <= 1;
has_instruction_issued_last_cycle <= 1; has_instruction_issued_last_cycle <= 1;
uint32_t tail = static_cast<max_size_t>(ROB_tail); uint32_t tail = static_cast<max_size_t>(ROB_tail);

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <iomanip>
#include "concept.h" #include "concept.h"
#ifndef LOADSTOREQUEUE_H #ifndef LOADSTOREQUEUE_H
#include <array> #include <array>
@ -134,6 +135,8 @@ struct LoadStoreQueue : public dark::Module<LoadStoreQueue_Input, LoadStoreQueue
<< static_cast<max_size_t>(has_decoded_rs1) << std::endl; << static_cast<max_size_t>(has_decoded_rs1) << std::endl;
std::cerr << "\thas_decoded_rs2: " << std::hex << std::setw(8) << std::setfill('0') std::cerr << "\thas_decoded_rs2: " << std::hex << std::setw(8) << std::setfill('0')
<< static_cast<max_size_t>(has_decoded_rs2) << std::endl; << static_cast<max_size_t>(has_decoded_rs2) << std::endl;
std::cerr << "\tstored in positon " << std::dec << static_cast<max_size_t>(cur_queue_tail) << " of LSQ"
<< std::endl;
// LSQ_queue[cur_queue_tail].Q1 <= decoded_rs1; // temporarily, no use // LSQ_queue[cur_queue_tail].Q1 <= decoded_rs1; // temporarily, no use
// LSQ_queue[cur_queue_tail].Q2 <= decoded_rs2; // temporarily, no use // LSQ_queue[cur_queue_tail].Q2 <= decoded_rs2; // temporarily, no use
} else } else
@ -156,6 +159,8 @@ struct LoadStoreQueue : public dark::Module<LoadStoreQueue_Input, LoadStoreQueue
LSQ_queue[last_idx].V2 <= rs2_value; LSQ_queue[last_idx].V2 <= rs2_value;
LSQ_queue[last_idx].D2 <= 1; LSQ_queue[last_idx].D2 <= 1;
last_cycle_V2_proccessed = true; last_cycle_V2_proccessed = true;
std::cerr << "from register file: LSQ_queue[last_idx].V2=" << std::hex << std::setw(8) << std::setfill('0')
<< static_cast<max_size_t>(LSQ_queue[last_idx].V2) << std::endl;
} }
if (bool(LSQ_queue[last_idx].E1) && (!bool(rs1_nodep)) && bool(rs1_is_in_ROB)) { if (bool(LSQ_queue[last_idx].E1) && (!bool(rs1_nodep)) && bool(rs1_is_in_ROB)) {
LSQ_queue[last_idx].V1 <= rs1_in_ROB_value; LSQ_queue[last_idx].V1 <= rs1_in_ROB_value;
@ -168,6 +173,8 @@ struct LoadStoreQueue : public dark::Module<LoadStoreQueue_Input, LoadStoreQueue
LSQ_queue[last_idx].V2 <= rs2_in_ROB_value; LSQ_queue[last_idx].V2 <= rs2_in_ROB_value;
LSQ_queue[last_idx].D2 <= 1; LSQ_queue[last_idx].D2 <= 1;
last_cycle_V2_proccessed = true; last_cycle_V2_proccessed = true;
std::cerr << "from ROB: LSQ_queue[last_idx].V2=" << std::hex << std::setw(8) << std::setfill('0')
<< static_cast<max_size_t>(LSQ_queue[last_idx].V2) << std::endl;
} }
std::cerr << "End of processing dependency information from register file and ROB" << std::endl; std::cerr << "End of processing dependency information from register file and ROB" << std::endl;
} }
@ -177,25 +184,36 @@ struct LoadStoreQueue : public dark::Module<LoadStoreQueue_Input, LoadStoreQueue
bool(has_accepted_ins_last_cycle) && bool(LSQ_queue[last_idx].E2) && !last_cycle_V2_proccessed; bool(has_accepted_ins_last_cycle) && bool(LSQ_queue[last_idx].E2) && !last_cycle_V2_proccessed;
// now alu, memory may provide data to satisfy the dependency // now alu, memory may provide data to satisfy the dependency
auto process_listend_data = [&](uint32_t res_ROB_index, uint32_t res_value) -> void { auto process_listend_data = [&](uint32_t res_ROB_index, uint32_t res_value) -> void {
std::cerr << "res_ROB_index=" << std::dec << res_ROB_index << std::endl;
std::cerr << "res_value=" << std::hex << std::setw(8) << std::setfill('0') << res_value << std::endl;
std::cerr << "rs1_deps=" << std::dec << static_cast<max_size_t>(rs1_deps) << std::endl;
std::cerr << "rs2_deps=" << std::dec << static_cast<max_size_t>(rs2_deps) << std::endl;
uint32_t ptr = static_cast<max_size_t>(LSQ_head); uint32_t ptr = static_cast<max_size_t>(LSQ_head);
while (ptr != static_cast<max_size_t>(LSQ_tail)) { while (ptr != static_cast<max_size_t>(LSQ_tail)) {
std::cerr << "\tptr=" << std::dec << ptr << std::endl;
if ((!bool(has_accepted_ins_last_cycle)) || ptr != last_idx) { if ((!bool(has_accepted_ins_last_cycle)) || ptr != last_idx) {
std::cerr << "\tnormal" << std::endl;
dark::debug::assert(LSQ_queue[ptr].state == 2, "LSQ_queue[ptr].state != 2"); dark::debug::assert(LSQ_queue[ptr].state == 2, "LSQ_queue[ptr].state != 2");
if (static_cast<max_size_t>(LSQ_queue[ptr].Q1) == res_ROB_index) { if ((!bool(LSQ_queue[ptr].D1)) && static_cast<max_size_t>(LSQ_queue[ptr].Q1) == res_ROB_index) {
LSQ_queue[ptr].V1 <= res_value; LSQ_queue[ptr].V1 <= res_value;
LSQ_queue[ptr].D1 <= 1; LSQ_queue[ptr].D1 <= 1;
} }
if (static_cast<max_size_t>(LSQ_queue[ptr].Q2) == res_ROB_index) { if ((!bool(LSQ_queue[ptr].D2)) && static_cast<max_size_t>(LSQ_queue[ptr].Q2) == res_ROB_index) {
LSQ_queue[ptr].V2 <= res_value; LSQ_queue[ptr].V2 <= res_value;
LSQ_queue[ptr].D2 <= 1; LSQ_queue[ptr].D2 <= 1;
} }
} else { } else {
std::cerr << "\timmediately listend data" << std::endl;
std::cerr << "should_monitor_V1=" << should_monitor_V1 << std::endl;
std::cerr << "should_monitor_V2=" << should_monitor_V2 << std::endl;
if (should_monitor_V1 && static_cast<max_size_t>(rs1_deps) == res_ROB_index) { if (should_monitor_V1 && static_cast<max_size_t>(rs1_deps) == res_ROB_index) {
std::cerr << "load rs1" << std::endl;
LSQ_queue[last_idx].V1 <= res_value; LSQ_queue[last_idx].V1 <= res_value;
LSQ_queue[last_idx].D1 <= 1; LSQ_queue[last_idx].D1 <= 1;
should_monitor_V1 = false; should_monitor_V1 = false;
} }
if (should_monitor_V2 && static_cast<max_size_t>(rs2_deps) == res_ROB_index) { if (should_monitor_V2 && static_cast<max_size_t>(rs2_deps) == res_ROB_index) {
std::cerr << "load rs2" << std::endl;
LSQ_queue[last_idx].V2 <= res_value; LSQ_queue[last_idx].V2 <= res_value;
LSQ_queue[last_idx].D2 <= 1; LSQ_queue[last_idx].D2 <= 1;
should_monitor_V2 = false; should_monitor_V2 = false;
@ -206,11 +224,13 @@ struct LoadStoreQueue : public dark::Module<LoadStoreQueue_Input, LoadStoreQueue
}; };
std::cerr << "Load Store Queue is listening data from alu" << std::endl; std::cerr << "Load Store Queue is listening data from alu" << std::endl;
if (static_cast<max_size_t>(alu_status_receiver) == 0b10) { if (static_cast<max_size_t>(alu_status_receiver) == 0b10) {
std::cerr << "potentially have sth from alu" << std::endl;
process_listend_data(static_cast<max_size_t>(completed_aluins_ROB_index), process_listend_data(static_cast<max_size_t>(completed_aluins_ROB_index),
static_cast<max_size_t>(completed_aluins_result)); static_cast<max_size_t>(completed_aluins_result));
} }
std::cerr << "Load Store Queue is listening data from memory" << std::endl; std::cerr << "Load Store Queue is listening data from memory" << std::endl;
if (static_cast<max_size_t>(mem_data_sign) == 0b10) { if (static_cast<max_size_t>(mem_data_sign) == 0b10) {
std::cerr << "potentially have sth from memory" << std::endl;
process_listend_data(static_cast<max_size_t>(completed_memins_ROB_index), process_listend_data(static_cast<max_size_t>(completed_memins_ROB_index),
static_cast<max_size_t>(completed_memins_read_data)); static_cast<max_size_t>(completed_memins_read_data));
} }
@ -237,7 +257,7 @@ struct LoadStoreQueue : public dark::Module<LoadStoreQueue_Input, LoadStoreQueue
((LSQ_queue[head].E2 == 0) || (LSQ_queue[head].E2 == 1 && LSQ_queue[head].D2 == 1))) { ((LSQ_queue[head].E2 == 0) || (LSQ_queue[head].E2 == 1 && LSQ_queue[head].D2 == 1))) {
// now we can execute the instruction // now we can execute the instruction
std::cerr << "Load Store queue is executing instruction" << std::endl; std::cerr << "Load Store queue is executing instruction" << std::endl;
next_remain_space--; next_remain_space++;
can_execute = true; can_execute = true;
LSQ_head <= (head + 1) % 32; LSQ_head <= (head + 1) % 32;
uint32_t ins = static_cast<uint32_t>(LSQ_queue[head].full_ins_id); uint32_t ins = static_cast<uint32_t>(LSQ_queue[head].full_ins_id);
@ -299,6 +319,14 @@ struct LoadStoreQueue : public dark::Module<LoadStoreQueue_Input, LoadStoreQueue
request_ROB_index <= static_cast<uint32_t>(LSQ_queue[head].ins_ROB_index); request_ROB_index <= static_cast<uint32_t>(LSQ_queue[head].ins_ROB_index);
request_address_output <= request_address_output <=
(static_cast<uint32_t>(LSQ_queue[head].V1) + static_cast<uint32_t>(LSQ_queue[head].ins_imm)); (static_cast<uint32_t>(LSQ_queue[head].V1) + static_cast<uint32_t>(LSQ_queue[head].ins_imm));
std::cerr << "\trequest_address_output=" << std::hex << std::setfill('0') << std::setw(8)
<< request_address_output.peek() << std::endl;
std::cerr << "\toperand1=" << std::hex << std::setfill('0') << std::setw(8)
<< static_cast<uint32_t>(LSQ_queue[head].V1) << std::endl;
std::cerr << "\timm=" << std::hex << std::setfill('0') << std::setw(8)
<< static_cast<uint32_t>(LSQ_queue[head].ins_imm) << std::endl;
std::cerr << "\tROB_index=" << std::dec << static_cast<uint32_t>(LSQ_queue[head].ins_ROB_index)
<< std::endl;
request_data_output <= static_cast<uint32_t>(LSQ_queue[head].V2); request_data_output <= static_cast<uint32_t>(LSQ_queue[head].V2);
} else { } else {
throw std::runtime_error("Invalid instruction"); throw std::runtime_error("Invalid instruction");
@ -310,6 +338,8 @@ struct LoadStoreQueue : public dark::Module<LoadStoreQueue_Input, LoadStoreQueue
if (!can_execute) request_type_output <= 0; if (!can_execute) request_type_output <= 0;
LSQ_remain_space <= next_remain_space; LSQ_remain_space <= next_remain_space;
LSQ_remain_space_output <= next_remain_space; LSQ_remain_space_output <= next_remain_space;
std::cerr << "LSQ_queue[16]'s V1: " << std::hex << std::setfill('0') << std::setw(8)
<< static_cast<max_size_t>(LSQ_queue[16].V1) << std::endl;
} }
}; };
} // namespace ZYM } // namespace ZYM

View File

@ -9,7 +9,7 @@ const static size_t kTotalRegisters = 32;
struct RegisterFile_Input { struct RegisterFile_Input {
// receive control signal from CSU // receive control signal from CSU
dark::Wire<1> reset; dark::Wire<1> reset;
// dark::Wire<1> force_clear_receiver; dark::Wire<1> force_clear_receiver;
dark::Wire<1> is_issuing; dark::Wire<1> is_issuing;
dark::Wire<1> issue_type; dark::Wire<1> issue_type;
dark::Wire<5> issue_ROB_index; dark::Wire<5> issue_ROB_index;
@ -70,11 +70,22 @@ struct RegisterFile : public dark::Module<RegisterFile_Input, RegisterFile_Outpu
registers[static_cast<max_size_t>(commit_reg_index)] <= commit_reg_value; registers[static_cast<max_size_t>(commit_reg_index)] <= commit_reg_value;
if (register_deps[static_cast<max_size_t>(commit_reg_index)] == commit_ins_ROB_index) { if (register_deps[static_cast<max_size_t>(commit_reg_index)] == commit_ins_ROB_index) {
std::cerr << "The dependency is cleared" << std::endl; std::cerr << "The dependency is cleared" << std::endl;
if (!(bool(is_issuing) && bool(has_decoded_rd) &&
(static_cast<max_size_t>(decoded_rd) == static_cast<max_size_t>(commit_reg_index))))
register_nodep[static_cast<max_size_t>(commit_reg_index)] <= 1; register_nodep[static_cast<max_size_t>(commit_reg_index)] <= 1;
dependency_cleared = true; dependency_cleared = true;
} }
} }
} }
if (bool(force_clear_receiver)) {
for (auto &reg : register_deps) {
reg <= 0;
}
for (auto &reg : register_nodep) {
reg <= 1;
}
return;
}
if (bool(is_issuing)) { if (bool(is_issuing)) {
std::cerr << "Register File Found CSU is issuing" << std::endl; std::cerr << "Register File Found CSU is issuing" << std::endl;
if (bool(has_decoded_rs1)) { if (bool(has_decoded_rs1)) {

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <iterator>
#include "concept.h" #include "concept.h"
#ifndef RESERVATIONSTATION_H #ifndef RESERVATIONSTATION_H
#include <array> #include <array>
@ -88,6 +89,7 @@ struct ReserveStation : public dark::Module<ReserveStation_Input, ReserveStation
RS_remaining_space <= 32; RS_remaining_space <= 32;
RS_remain_space_output <= 32; RS_remain_space_output <= 32;
request_full_id <= 0; request_full_id <= 0;
has_accepted_ins_last_cycle <= 0;
return; return;
} }
if (bool(force_clear_receiver)) { if (bool(force_clear_receiver)) {
@ -97,6 +99,7 @@ struct ReserveStation : public dark::Module<ReserveStation_Input, ReserveStation
RS_remaining_space <= 32; RS_remaining_space <= 32;
RS_remain_space_output <= 32; RS_remain_space_output <= 32;
request_full_id <= 0; request_full_id <= 0;
has_accepted_ins_last_cycle <= 0;
return; return;
} }
uint32_t next_remain_space = static_cast<max_size_t>(RS_remaining_space); uint32_t next_remain_space = static_cast<max_size_t>(RS_remaining_space);
@ -127,6 +130,9 @@ struct ReserveStation : public dark::Module<ReserveStation_Input, ReserveStation
RS_records[deposit_index].E2 <= has_decoded_rs2; RS_records[deposit_index].E2 <= has_decoded_rs2;
RS_records[deposit_index].D1 <= 1; RS_records[deposit_index].D1 <= 1;
RS_records[deposit_index].D2 <= 1; RS_records[deposit_index].D2 <= 1;
std::cerr << "Reserve Station has accepted an instruction from CSU" << std::endl;
std::cerr << "\tdeposit_index=" << std::dec << deposit_index << std::endl;
std::cerr << "\tROB_index=" << std::dec << static_cast<max_size_t>(issue_ROB_index) << std::endl;
} else } else
has_accepted_ins_last_cycle <= 0; has_accepted_ins_last_cycle <= 0;
uint32_t last_idx = static_cast<max_size_t>(last_cycle_ins_RS_index); uint32_t last_idx = static_cast<max_size_t>(last_cycle_ins_RS_index);
@ -167,15 +173,16 @@ struct ReserveStation : public dark::Module<ReserveStation_Input, ReserveStation
bool should_monitor_V2 = bool should_monitor_V2 =
bool(has_accepted_ins_last_cycle) && bool(RS_records[last_idx].E2) && (!last_cycle_V2_proccessed); bool(has_accepted_ins_last_cycle) && bool(RS_records[last_idx].E2) && (!last_cycle_V2_proccessed);
auto process_listend_data = [&](uint32_t res_ROB_index, uint32_t res_value) -> void { auto process_listend_data = [&](uint32_t res_ROB_index, uint32_t res_value) -> void {
std::cerr << "\tres_ROB_index=" << std::dec << res_ROB_index << std::endl;
for (uint32_t ptr = 0; ptr < 32; ptr++) { for (uint32_t ptr = 0; ptr < 32; ptr++) {
if (RS_records[ptr].state == 0) continue; if (RS_records[ptr].state == 0) continue;
if ((!bool(has_accepted_ins_last_cycle)) || ptr != last_idx) { if ((!bool(has_accepted_ins_last_cycle)) || ptr != last_idx) {
dark::debug::assert(RS_records[ptr].state == 2, "RS_records[ptr].state != 2"); dark::debug::assert(RS_records[ptr].state == 2, "RS_records[ptr].state != 2");
if (static_cast<max_size_t>(RS_records[ptr].Q1) == res_ROB_index) { if ((!bool(RS_records[ptr].D1)) && static_cast<max_size_t>(RS_records[ptr].Q1) == res_ROB_index) {
RS_records[ptr].V1 <= res_value; RS_records[ptr].V1 <= res_value;
RS_records[ptr].D1 <= 1; RS_records[ptr].D1 <= 1;
} }
if (static_cast<max_size_t>(RS_records[ptr].Q2) == res_ROB_index) { if ((!bool(RS_records[ptr].D2)) && static_cast<max_size_t>(RS_records[ptr].Q2) == res_ROB_index) {
RS_records[ptr].V2 <= res_value; RS_records[ptr].V2 <= res_value;
RS_records[ptr].D2 <= 1; RS_records[ptr].D2 <= 1;
} }
@ -191,13 +198,14 @@ struct ReserveStation : public dark::Module<ReserveStation_Input, ReserveStation
should_monitor_V2 = false; should_monitor_V2 = false;
} }
} }
ptr = (ptr + 1) % 32;
} }
}; };
std::cerr << "Reservestation is listening data from ALU" << std::endl;
if (static_cast<max_size_t>(alu_status_receiver) == 0b10) { if (static_cast<max_size_t>(alu_status_receiver) == 0b10) {
process_listend_data(static_cast<max_size_t>(completed_aluins_ROB_index), process_listend_data(static_cast<max_size_t>(completed_aluins_ROB_index),
static_cast<max_size_t>(completed_aluins_result)); static_cast<max_size_t>(completed_aluins_result));
} }
std::cerr << "Reservestation is listening data from Memory" << std::endl;
if (static_cast<max_size_t>(mem_status_receiver) == 0b10) { if (static_cast<max_size_t>(mem_status_receiver) == 0b10) {
process_listend_data(static_cast<max_size_t>(completed_memins_ROB_index), process_listend_data(static_cast<max_size_t>(completed_memins_ROB_index),
static_cast<max_size_t>(completed_memins_read_data)); static_cast<max_size_t>(completed_memins_read_data));
@ -237,6 +245,16 @@ struct ReserveStation : public dark::Module<ReserveStation_Input, ReserveStation
if (!can_execute) request_full_id <= 0; if (!can_execute) request_full_id <= 0;
RS_remaining_space <= next_remain_space; RS_remaining_space <= next_remain_space;
RS_remain_space_output <= next_remain_space; RS_remain_space_output <= next_remain_space;
std::cerr << "Reservestation: next_remain_space=" << std::dec << next_remain_space << std::endl;
int tot = 0;
for (int i = 0; i < 32; i++)
if (static_cast<max_size_t>(RS_records[i].state) == 0) tot++;
std::cerr << "\tcurrently there are " << std::dec << tot
<< " remain spaces based on state but RS_remaining_space says " << std::dec
<< static_cast<max_size_t>(RS_remaining_space) << std::endl;
if (tot != static_cast<max_size_t>(RS_remaining_space)) {
throw std::runtime_error("Reservestation: RS_remaining_space is not consistent with RS_records");
}
} }
}; };
} // namespace ZYM } // namespace ZYM

View File

@ -78,7 +78,7 @@ int main(int argc, char **argv) {
RWConnect(alu.result, csu.completed_aluins_result); RWConnect(alu.result, csu.completed_aluins_result);
RWConnect(alu.completed_alu_resulting_PC, csu.completed_alu_resulting_PC); RWConnect(alu.completed_alu_resulting_PC, csu.completed_alu_resulting_PC);
// csu <-> register file // csu <-> register file
// RWConnect(csu.force_clear_announcer, rf.force_clear_receiver); RWConnect(csu.force_clear_announcer, rf.force_clear_receiver);
RWConnect(csu.is_issuing, rf.is_issuing); RWConnect(csu.is_issuing, rf.is_issuing);
RWConnect(csu.issue_type, rf.issue_type); RWConnect(csu.issue_type, rf.issue_type);
RWConnect(csu.issue_ROB_index, rf.issue_ROB_index); RWConnect(csu.issue_ROB_index, rf.issue_ROB_index);

View File

@ -12,7 +12,8 @@
#ifdef DEBUG #ifdef DEBUG
#define DEBUG_CERR std::cerr #define DEBUG_CERR std::cerr
#else #else
#define DEBUG_CERR if(0) std::cerr #define DEBUG_CERR \
if (0) std::cerr
#endif #endif
inline uint8_t ReadBit(uint32_t data, int pos) { return (data >> pos) & 1; } inline uint8_t ReadBit(uint32_t data, int pos) { return (data >> pos) & 1; }
inline void WriteBit(uint32_t &data, int pos, uint8_t bit) { inline void WriteBit(uint32_t &data, int pos, uint8_t bit) {
@ -173,7 +174,7 @@ class RV32IInterpreter {
memset(reg, 0, sizeof(reg)); memset(reg, 0, sizeof(reg));
} }
bool Fetch() { bool Fetch() {
DEBUG_CERR<<"Fetching PC: "<<std::hex<<PC<<std::endl; DEBUG_CERR << "Fetching PC: " << std::hex << PC << std::endl;
IR = *reinterpret_cast<uint32_t *>(&dat[PC]); IR = *reinterpret_cast<uint32_t *>(&dat[PC]);
if (IR == 0x0FF00513) { if (IR == 0x0FF00513) {
// DEBUG_CERR<<"ready to exit"<<std::endl; // DEBUG_CERR<<"ready to exit"<<std::endl;
@ -191,10 +192,11 @@ class RV32IInterpreter {
while (Fetch()) { while (Fetch()) {
// uint8_t opcode=IR&127; // uint8_t opcode=IR&127;
// std::cout<<"PC: "<<std::hex<<PC<<std::endl; // std::cout<<"PC: "<<std::hex<<PC<<std::endl;
std::cout << "IR= " << std::hex << std::setw(8) << std::setfill('0') <<std::uppercase<< IR << std::endl;
PrintRegisters(); PrintRegisters();
Decode(IR)(*this, IR); Decode(IR)(*this, IR);
DEBUG_CERR << std::endl; DEBUG_CERR << std::endl;
DEBUG_CERR<<"instruction to Fetch: "<<std::hex<<PC<<std::endl<<std::endl; DEBUG_CERR << "instruction to Fetch: " << std::hex << PC << std::endl << std::endl;
} }
// now set exit_code // now set exit_code
exit_code = reg[10] & 255; exit_code = reg[10] & 255;
@ -205,7 +207,7 @@ int main() {
RV32IInterpreter interpreter; RV32IInterpreter interpreter;
interpreter.LoadProgram(std::cin); interpreter.LoadProgram(std::cin);
interpreter.RunProgram(); interpreter.RunProgram();
std::cout <<std::dec<< (int)interpreter.GetExitCode() << std::endl; std::cout << std::dec << (int)interpreter.GetExitCode() << std::endl;
return 0; return 0;
} }
@ -217,7 +219,7 @@ void Execute_lui(RV32IInterpreter &interpreter, uint32_t instruction) {
uint8_t rd = (instruction >> 7) & 31; uint8_t rd = (instruction >> 7) & 31;
uint32_t imm = instruction & 0xFFFFF000; uint32_t imm = instruction & 0xFFFFF000;
interpreter.reg[rd] = imm; interpreter.reg[rd] = imm;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_auipc(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_auipc(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -228,7 +230,7 @@ void Execute_auipc(RV32IInterpreter &interpreter, uint32_t instruction) {
uint8_t rd = (instruction >> 7) & 31; uint8_t rd = (instruction >> 7) & 31;
uint32_t imm = instruction & 0xFFFFF000; uint32_t imm = instruction & 0xFFFFF000;
interpreter.reg[rd] = interpreter.PC + imm; interpreter.reg[rd] = interpreter.PC + imm;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_jal(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_jal(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -238,7 +240,7 @@ void Execute_jal(RV32IInterpreter &interpreter, uint32_t instruction) {
DEBUG_CERR << "jal: instruction=" << std::hex << std::setw(8) << std::setfill('0') << instruction << std::endl; DEBUG_CERR << "jal: instruction=" << std::hex << std::setw(8) << std::setfill('0') << instruction << std::endl;
uint32_t rd = (instruction >> 7) & 31; uint32_t rd = (instruction >> 7) & 31;
interpreter.reg[rd] = interpreter.PC + 4; interpreter.reg[rd] = interpreter.PC + 4;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
uint32_t offset = 0; uint32_t offset = 0;
// 提取并组合立即数 // 提取并组合立即数
WriteBit(offset, 20, ReadBit(instruction, 31)); WriteBit(offset, 20, ReadBit(instruction, 31));
@ -284,7 +286,7 @@ void Execute_jalr(RV32IInterpreter &interpreter, uint32_t instruction) {
interpreter.PC = (interpreter.reg[rs1] + offset_signed) & 0xFFFFFFFE; interpreter.PC = (interpreter.reg[rs1] + offset_signed) & 0xFFFFFFFE;
uint8_t rd = (instruction >> 7) & 31; uint8_t rd = (instruction >> 7) & 31;
interpreter.reg[rd] = t; interpreter.reg[rd] = t;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
DEBUG_CERR << "now PC=" << std::hex << interpreter.PC << std::endl; DEBUG_CERR << "now PC=" << std::hex << interpreter.PC << std::endl;
} }
void Execute_beq(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_beq(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -525,7 +527,7 @@ void Execute_lb(RV32IInterpreter &interpreter, uint32_t instruction) {
} }
} }
interpreter.reg[rd] = val; interpreter.reg[rd] = val;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_lh(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_lh(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -545,14 +547,14 @@ void Execute_lh(RV32IInterpreter &interpreter, uint32_t instruction) {
} }
int32_t offset_signed = *reinterpret_cast<int32_t *>(&offset); int32_t offset_signed = *reinterpret_cast<int32_t *>(&offset);
uint32_t addr = interpreter.reg[rs1] + offset_signed; uint32_t addr = interpreter.reg[rs1] + offset_signed;
uint32_t val = *(reinterpret_cast<uint16_t*>(&interpreter.dat[addr])); uint32_t val = *(reinterpret_cast<uint16_t *>(&interpreter.dat[addr]));
if (ReadBit(val, 15)) { if (ReadBit(val, 15)) {
for (int i = 16; i < 32; ++i) { for (int i = 16; i < 32; ++i) {
WriteBit(val, i, 1); WriteBit(val, i, 1);
} }
} }
interpreter.reg[rd] = val; interpreter.reg[rd] = val;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_lw(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_lw(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -572,9 +574,9 @@ void Execute_lw(RV32IInterpreter &interpreter, uint32_t instruction) {
} }
int32_t offset_signed = *reinterpret_cast<int32_t *>(&offset); int32_t offset_signed = *reinterpret_cast<int32_t *>(&offset);
uint32_t addr = interpreter.reg[rs1] + offset_signed; uint32_t addr = interpreter.reg[rs1] + offset_signed;
uint32_t val = *(reinterpret_cast<uint32_t*>(&interpreter.dat[addr])); uint32_t val = *(reinterpret_cast<uint32_t *>(&interpreter.dat[addr]));
interpreter.reg[rd] = val; interpreter.reg[rd] = val;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_lbu(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_lbu(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -596,7 +598,7 @@ void Execute_lbu(RV32IInterpreter &interpreter, uint32_t instruction) {
uint32_t addr = interpreter.reg[rs1] + offset_signed; uint32_t addr = interpreter.reg[rs1] + offset_signed;
uint32_t val = interpreter.dat[addr]; uint32_t val = interpreter.dat[addr];
interpreter.reg[rd] = val; interpreter.reg[rd] = val;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_lhu(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_lhu(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -616,9 +618,9 @@ void Execute_lhu(RV32IInterpreter &interpreter, uint32_t instruction) {
} }
int32_t offset_signed = *reinterpret_cast<int32_t *>(&offset); int32_t offset_signed = *reinterpret_cast<int32_t *>(&offset);
uint32_t addr = interpreter.reg[rs1] + offset_signed; uint32_t addr = interpreter.reg[rs1] + offset_signed;
uint32_t val = *(reinterpret_cast<uint16_t*>(&interpreter.dat[addr])); uint32_t val = *(reinterpret_cast<uint16_t *>(&interpreter.dat[addr]));
interpreter.reg[rd] = val; interpreter.reg[rd] = val;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_sb(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_sb(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -684,7 +686,7 @@ void Execute_sw(RV32IInterpreter &interpreter, uint32_t instruction) {
} }
int32_t offset_signed = *reinterpret_cast<int32_t *>(&offset); int32_t offset_signed = *reinterpret_cast<int32_t *>(&offset);
uint32_t addr = interpreter.reg[rs1] + offset_signed; uint32_t addr = interpreter.reg[rs1] + offset_signed;
*reinterpret_cast<uint32_t *>(&interpreter.dat[addr])=interpreter.reg[rs2]; *reinterpret_cast<uint32_t *>(&interpreter.dat[addr]) = interpreter.reg[rs2];
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_addi(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_addi(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -701,7 +703,7 @@ void Execute_addi(RV32IInterpreter &interpreter, uint32_t instruction) {
} }
} }
interpreter.reg[rd] = interpreter.reg[rs1] + imm; interpreter.reg[rd] = interpreter.reg[rs1] + imm;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_slti(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_slti(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -720,7 +722,7 @@ void Execute_slti(RV32IInterpreter &interpreter, uint32_t instruction) {
int32_t rs1_val = *reinterpret_cast<int32_t *>(&interpreter.reg[rs1]); int32_t rs1_val = *reinterpret_cast<int32_t *>(&interpreter.reg[rs1]);
int32_t signed_imm = *reinterpret_cast<int32_t *>(&imm); int32_t signed_imm = *reinterpret_cast<int32_t *>(&imm);
interpreter.reg[rd] = rs1_val < signed_imm ? 1 : 0; interpreter.reg[rd] = rs1_val < signed_imm ? 1 : 0;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_sltiu(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_sltiu(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -739,7 +741,7 @@ void Execute_sltiu(RV32IInterpreter &interpreter, uint32_t instruction) {
uint32_t rs1_val = interpreter.reg[rs1]; uint32_t rs1_val = interpreter.reg[rs1];
uint32_t unsigned_imm = imm; uint32_t unsigned_imm = imm;
interpreter.reg[rd] = rs1_val < unsigned_imm ? 1 : 0; interpreter.reg[rd] = rs1_val < unsigned_imm ? 1 : 0;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_xori(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_xori(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -756,7 +758,7 @@ void Execute_xori(RV32IInterpreter &interpreter, uint32_t instruction) {
} }
} }
interpreter.reg[rd] = interpreter.reg[rs1] ^ imm; interpreter.reg[rd] = interpreter.reg[rs1] ^ imm;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_ori(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_ori(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -770,7 +772,7 @@ void Execute_ori(RV32IInterpreter &interpreter, uint32_t instruction) {
} }
} }
interpreter.reg[rd] = interpreter.reg[rs1] | imm; interpreter.reg[rd] = interpreter.reg[rs1] | imm;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_andi(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_andi(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -787,7 +789,7 @@ void Execute_andi(RV32IInterpreter &interpreter, uint32_t instruction) {
} }
} }
interpreter.reg[rd] = interpreter.reg[rs1] & imm; interpreter.reg[rd] = interpreter.reg[rs1] & imm;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_slli(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_slli(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -799,7 +801,7 @@ void Execute_slli(RV32IInterpreter &interpreter, uint32_t instruction) {
uint8_t rs1 = (instruction >> 15) & 31; uint8_t rs1 = (instruction >> 15) & 31;
uint8_t shamt = (instruction >> 20) & 31; uint8_t shamt = (instruction >> 20) & 31;
interpreter.reg[rd] = interpreter.reg[rs1] << shamt; interpreter.reg[rd] = interpreter.reg[rs1] << shamt;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_srli(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_srli(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -811,7 +813,7 @@ void Execute_srli(RV32IInterpreter &interpreter, uint32_t instruction) {
uint8_t rs1 = (instruction >> 15) & 31; uint8_t rs1 = (instruction >> 15) & 31;
uint8_t shamt = (instruction >> 20) & 31; uint8_t shamt = (instruction >> 20) & 31;
interpreter.reg[rd] = interpreter.reg[rs1] >> shamt; interpreter.reg[rd] = interpreter.reg[rs1] >> shamt;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_srai(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_srai(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -827,7 +829,7 @@ void Execute_srai(RV32IInterpreter &interpreter, uint32_t instruction) {
for (int i = 31; i > 31 - shamt; --i) { for (int i = 31; i > 31 - shamt; --i) {
WriteBit(interpreter.reg[rd], i, sign_bit); WriteBit(interpreter.reg[rd], i, sign_bit);
} }
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_add(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_add(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -839,7 +841,7 @@ void Execute_add(RV32IInterpreter &interpreter, uint32_t instruction) {
uint8_t rs1 = (instruction >> 15) & 31; uint8_t rs1 = (instruction >> 15) & 31;
uint8_t rs2 = (instruction >> 20) & 31; uint8_t rs2 = (instruction >> 20) & 31;
interpreter.reg[rd] = interpreter.reg[rs1] + interpreter.reg[rs2]; interpreter.reg[rd] = interpreter.reg[rs1] + interpreter.reg[rs2];
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_sub(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_sub(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -851,7 +853,7 @@ void Execute_sub(RV32IInterpreter &interpreter, uint32_t instruction) {
uint8_t rs1 = (instruction >> 15) & 31; uint8_t rs1 = (instruction >> 15) & 31;
uint8_t rs2 = (instruction >> 20) & 31; uint8_t rs2 = (instruction >> 20) & 31;
interpreter.reg[rd] = interpreter.reg[rs1] - interpreter.reg[rs2]; interpreter.reg[rd] = interpreter.reg[rs1] - interpreter.reg[rs2];
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_sll(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_sll(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -864,7 +866,7 @@ void Execute_sll(RV32IInterpreter &interpreter, uint32_t instruction) {
uint8_t rs2 = (instruction >> 20) & 31; uint8_t rs2 = (instruction >> 20) & 31;
uint8_t shamt = interpreter.reg[rs2] & 31; uint8_t shamt = interpreter.reg[rs2] & 31;
interpreter.reg[rd] = interpreter.reg[rs1] << shamt; interpreter.reg[rd] = interpreter.reg[rs1] << shamt;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_slt(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_slt(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -878,7 +880,7 @@ void Execute_slt(RV32IInterpreter &interpreter, uint32_t instruction) {
int32_t rs1_val = *reinterpret_cast<int32_t *>(&interpreter.reg[rs1]); int32_t rs1_val = *reinterpret_cast<int32_t *>(&interpreter.reg[rs1]);
int32_t rs2_val = *reinterpret_cast<int32_t *>(&interpreter.reg[rs2]); int32_t rs2_val = *reinterpret_cast<int32_t *>(&interpreter.reg[rs2]);
interpreter.reg[rd] = rs1_val < rs2_val ? 1 : 0; interpreter.reg[rd] = rs1_val < rs2_val ? 1 : 0;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_sltu(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_sltu(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -892,7 +894,7 @@ void Execute_sltu(RV32IInterpreter &interpreter, uint32_t instruction) {
uint32_t rs1_val = interpreter.reg[rs1]; uint32_t rs1_val = interpreter.reg[rs1];
uint32_t rs2_val = interpreter.reg[rs2]; uint32_t rs2_val = interpreter.reg[rs2];
interpreter.reg[rd] = rs1_val < rs2_val ? 1 : 0; interpreter.reg[rd] = rs1_val < rs2_val ? 1 : 0;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_xor(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_xor(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -904,7 +906,7 @@ void Execute_xor(RV32IInterpreter &interpreter, uint32_t instruction) {
uint8_t rs1 = (instruction >> 15) & 31; uint8_t rs1 = (instruction >> 15) & 31;
uint8_t rs2 = (instruction >> 20) & 31; uint8_t rs2 = (instruction >> 20) & 31;
interpreter.reg[rd] = interpreter.reg[rs1] ^ interpreter.reg[rs2]; interpreter.reg[rd] = interpreter.reg[rs1] ^ interpreter.reg[rs2];
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_srl(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_srl(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -917,7 +919,7 @@ void Execute_srl(RV32IInterpreter &interpreter, uint32_t instruction) {
uint8_t rs2 = (instruction >> 20) & 31; uint8_t rs2 = (instruction >> 20) & 31;
uint8_t shamt = interpreter.reg[rs2] & 31; uint8_t shamt = interpreter.reg[rs2] & 31;
interpreter.reg[rd] = interpreter.reg[rs1] >> shamt; interpreter.reg[rd] = interpreter.reg[rs1] >> shamt;
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_sra(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_sra(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -934,7 +936,7 @@ void Execute_sra(RV32IInterpreter &interpreter, uint32_t instruction) {
for (int i = 31; i > 31 - shamt; --i) { for (int i = 31; i > 31 - shamt; --i) {
WriteBit(interpreter.reg[rd], i, sign_bit); WriteBit(interpreter.reg[rd], i, sign_bit);
} }
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_or(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_or(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -946,7 +948,7 @@ void Execute_or(RV32IInterpreter &interpreter, uint32_t instruction) {
uint8_t rs1 = (instruction >> 15) & 31; uint8_t rs1 = (instruction >> 15) & 31;
uint8_t rs2 = (instruction >> 20) & 31; uint8_t rs2 = (instruction >> 20) & 31;
interpreter.reg[rd] = interpreter.reg[rs1] | interpreter.reg[rs2]; interpreter.reg[rd] = interpreter.reg[rs1] | interpreter.reg[rs2];
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }
void Execute_and(RV32IInterpreter &interpreter, uint32_t instruction) { void Execute_and(RV32IInterpreter &interpreter, uint32_t instruction) {
@ -958,6 +960,6 @@ void Execute_and(RV32IInterpreter &interpreter, uint32_t instruction) {
uint8_t rs1 = (instruction >> 15) & 31; uint8_t rs1 = (instruction >> 15) & 31;
uint8_t rs2 = (instruction >> 20) & 31; uint8_t rs2 = (instruction >> 20) & 31;
interpreter.reg[rd] = interpreter.reg[rs1] & interpreter.reg[rs2]; interpreter.reg[rd] = interpreter.reg[rs1] & interpreter.reg[rs2];
interpreter.reg[0]=0; interpreter.reg[0] = 0;
interpreter.PC += 4; interpreter.PC += 4;
} }