New function to increase PC by 2 (incPCby2) instead of a parameter to incPC function, could be faster code.
This commit is contained in:
parent
429a67fbef
commit
d8a20db976
|
@ -197,7 +197,7 @@ public:
|
||||||
* @param reg_num register number
|
* @param reg_num register number
|
||||||
* @return register value
|
* @return register value
|
||||||
*/
|
*/
|
||||||
uint32_t getValue(int reg_num);
|
uint32_t getValue(int reg_num) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns PC value
|
* Returns PC value
|
||||||
|
@ -220,9 +220,12 @@ public:
|
||||||
} else {
|
} else {
|
||||||
register_PC += 4;
|
register_PC += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void incPCby2() {
|
||||||
|
register_PC += 2;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get CSR value
|
* @brief Get CSR value
|
||||||
* @param csr CSR number to access
|
* @param csr CSR number to access
|
||||||
|
@ -255,10 +258,8 @@ private:
|
||||||
/**
|
/**
|
||||||
* CSR registers (4096 maximum)
|
* CSR registers (4096 maximum)
|
||||||
*/
|
*/
|
||||||
//uint32_t CSR[4096];
|
|
||||||
std::unordered_map<unsigned int, uint32_t> CSR{0};
|
std::unordered_map<unsigned int, uint32_t> CSR{0};
|
||||||
|
|
||||||
|
|
||||||
Performance *perf;
|
Performance *perf;
|
||||||
|
|
||||||
void initCSR();
|
void initCSR();
|
||||||
|
|
25
src/CPU.cpp
25
src/CPU.cpp
|
@ -114,8 +114,6 @@ bool CPU::cpu_process_IRQ() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CPU::CPU_step() {
|
bool CPU::CPU_step() {
|
||||||
|
|
||||||
bool incPCby2 = false;
|
|
||||||
bool PC_not_affected = false;
|
bool PC_not_affected = false;
|
||||||
|
|
||||||
/* Get new PC value */
|
/* Get new PC value */
|
||||||
|
@ -142,7 +140,6 @@ bool CPU::CPU_step() {
|
||||||
}
|
}
|
||||||
|
|
||||||
perf->codeMemoryRead();
|
perf->codeMemoryRead();
|
||||||
|
|
||||||
log->SC_log(Log::INFO) << "PC: 0x" << std::hex << register_bank->getPC()
|
log->SC_log(Log::INFO) << "PC: 0x" << std::hex << register_bank->getPC()
|
||||||
<< ". ";
|
<< ". ";
|
||||||
|
|
||||||
|
@ -153,20 +150,28 @@ bool CPU::CPU_step() {
|
||||||
switch (inst->check_extension()) {
|
switch (inst->check_extension()) {
|
||||||
[[likely]] case BASE_EXTENSION:
|
[[likely]] case BASE_EXTENSION:
|
||||||
PC_not_affected = exec->process_instruction(inst, &breakpoint);
|
PC_not_affected = exec->process_instruction(inst, &breakpoint);
|
||||||
incPCby2 = false;
|
if (PC_not_affected) {
|
||||||
|
register_bank->incPC();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case C_EXTENSION:
|
case C_EXTENSION:
|
||||||
PC_not_affected = c_inst->process_instruction(inst, &breakpoint);
|
PC_not_affected = c_inst->process_instruction(inst, &breakpoint);
|
||||||
incPCby2 = true;
|
if (PC_not_affected) {
|
||||||
|
register_bank->incPCby2();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case M_EXTENSION:
|
case M_EXTENSION:
|
||||||
PC_not_affected = m_inst->process_instruction(inst);
|
PC_not_affected = m_inst->process_instruction(inst);
|
||||||
incPCby2 = false;
|
if (PC_not_affected) {
|
||||||
|
register_bank->incPC();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case A_EXTENSION:
|
case A_EXTENSION:
|
||||||
PC_not_affected = a_inst->process_instruction(inst);
|
PC_not_affected = a_inst->process_instruction(inst);
|
||||||
incPCby2 = false;
|
if (PC_not_affected) {
|
||||||
break;
|
register_bank->incPC();
|
||||||
|
}
|
||||||
|
break;
|
||||||
[[unlikely]] default:
|
[[unlikely]] default:
|
||||||
std::cout << "Extension not implemented yet" << std::endl;
|
std::cout << "Extension not implemented yet" << std::endl;
|
||||||
inst->dump();
|
inst->dump();
|
||||||
|
@ -179,10 +184,6 @@ bool CPU::CPU_step() {
|
||||||
|
|
||||||
perf->instructionsInc();
|
perf->instructionsInc();
|
||||||
|
|
||||||
if (PC_not_affected) {
|
|
||||||
register_bank->incPC(incPCby2);
|
|
||||||
}
|
|
||||||
|
|
||||||
return breakpoint;
|
return breakpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -325,7 +325,7 @@ bool C_extension::Exec_C_BEQZ() {
|
||||||
new_pc = static_cast<int32_t>(regs->getPC()) + get_imm_CB();
|
new_pc = static_cast<int32_t>(regs->getPC()) + get_imm_CB();
|
||||||
regs->setPC(new_pc);
|
regs->setPC(new_pc);
|
||||||
} else {
|
} else {
|
||||||
regs->incPC(true); //PC <- PC + 2
|
regs->incPCby2();
|
||||||
new_pc = static_cast<int32_t>(regs->getPC());
|
new_pc = static_cast<int32_t>(regs->getPC());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,7 +350,7 @@ bool C_extension::Exec_C_BNEZ() {
|
||||||
new_pc = static_cast<int32_t>(regs->getPC()) + get_imm_CB();
|
new_pc = static_cast<int32_t>(regs->getPC()) + get_imm_CB();
|
||||||
regs->setPC(new_pc);
|
regs->setPC(new_pc);
|
||||||
} else {
|
} else {
|
||||||
regs->incPC(true); //PC <- PC +2
|
regs->incPCby2(); //PC <- PC +2
|
||||||
new_pc = static_cast<int32_t>(regs->getPC());
|
new_pc = static_cast<int32_t>(regs->getPC());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,9 @@
|
||||||
#include "Registers.h"
|
#include "Registers.h"
|
||||||
|
|
||||||
Registers::Registers() {
|
Registers::Registers() {
|
||||||
|
|
||||||
perf = Performance::getInstance();
|
perf = Performance::getInstance();
|
||||||
|
|
||||||
initCSR();
|
initCSR();
|
||||||
|
|
||||||
//std::cout << "Memory size: 0x" << std::hex << Memory::SIZE << std::endl;
|
|
||||||
//std::cout << "SP address: 0x" << std::hex << (0x10000000 / 4) - 1 << std::endl;
|
|
||||||
|
|
||||||
register_bank[sp] = Memory::SIZE - 4; // default stack at the end of the memory
|
register_bank[sp] = Memory::SIZE - 4; // default stack at the end of the memory
|
||||||
register_PC = 0x80000000; // default _start address
|
register_PC = 0x80000000; // default _start address
|
||||||
}
|
}
|
||||||
|
@ -108,7 +103,7 @@ void Registers::setValue(int reg_num, int32_t value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Registers::getValue(int reg_num) {
|
uint32_t Registers::getValue(int reg_num) const {
|
||||||
if ((reg_num >= 0) && (reg_num < 32)) {
|
if ((reg_num >= 0) && (reg_num < 32)) {
|
||||||
perf->registerRead();
|
perf->registerRead();
|
||||||
return register_bank[reg_num];
|
return register_bank[reg_num];
|
||||||
|
@ -125,7 +120,7 @@ void Registers::setPC(uint32_t new_pc) {
|
||||||
register_PC = new_pc;
|
register_PC = new_pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Registers::getCSR(int csr) {
|
uint32_t Registers::getCSR(const int csr) {
|
||||||
uint32_t ret_value;
|
uint32_t ret_value;
|
||||||
|
|
||||||
switch (csr) {
|
switch (csr) {
|
||||||
|
@ -156,14 +151,14 @@ uint32_t Registers::getCSR(int csr) {
|
||||||
>> 32 & 0x00000000FFFFFFFF);
|
>> 32 & 0x00000000FFFFFFFF);
|
||||||
break;
|
break;
|
||||||
[[likely]] default:
|
[[likely]] default:
|
||||||
ret_value = CSR[csr];
|
ret_value = CSR[csr];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return ret_value;
|
return ret_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Registers::setCSR(int csr, uint32_t value) {
|
void Registers::setCSR(int csr, uint32_t value) {
|
||||||
/* @FIXME: rv32mi-p-ma_fetch tests doesn't allow MISA to writable,
|
/* @FIXME: rv32mi-p-ma_fetch tests doesn't allow MISA to be writable,
|
||||||
* but Volume II: Privileged Architecture v1.10 says MISA is writable (?)
|
* but Volume II: Privileged Architecture v1.10 says MISA is writable (?)
|
||||||
*/
|
*/
|
||||||
if (csr != CSR_MISA) {
|
if (csr != CSR_MISA) {
|
||||||
|
|
Loading…
Reference in New Issue