Implement RV32M overflow and division by zero semantics, fixes issue
MODIFY
src/pipelineobjects.h
src/pipelineobjects.h
@@ -359,16 +359,39 @@ void ALU<n>::update() {
break;
}
case ALUOps::DIV:
+ if((int)*m_op2 == 0){
+ m_output = -1;
+ } else if((int)*m_op1 == (-(std::pow(2,32-1))) && (int)*m_op2 == -1){
+ // Overflow
+ m_output = static_cast<int>(-(std::pow(2,32-1)));
+ } else {
m_output = (int)*m_op1 / (int)*m_op2;
+ }
break;
case ALUOps::DIVU:
+ if((int)*m_op2 == 0){
+ m_output = static_cast<uint32_t>(std::pow(2,32) - 1);
+ } else {
m_output = (uint32_t)*m_op1 / (uint32_t)*m_op2;
+ }
break;
case ALUOps::REM:
+ if((int)*m_op2 == 0){
+ m_output = (int)*m_op1;
+ } else if((int)*m_op1 == (-(std::pow(2,32-1))) && (int)*m_op2 == -1){
+ // Overflow
+ m_output = 0;
+ }
+ else {
m_output = (int)*m_op1 % (int)*m_op2;
+ }
break;
case ALUOps::REMU:
+ if((uint32_t)*m_op2 == 0){
+ m_output = (uint32_t)*m_op1;
+ } else {
m_output = (uint32_t)*m_op1 % (uint32_t)*m_op2;
+ }
break;
case ALUOps::AND:
m_output = (uint32_t)*m_op1 & (uint32_t)*m_op2;

Implement RV32M overflow and division by zero semantics, fixes issue #7