Skip to content

Commit

Permalink
Fix DIV, DIVU, REM, and REMU from setting fcsr
Browse files Browse the repository at this point in the history
I'm not sure why I initially did this, its not in the
spec and its extra work. The values were correct and
come from the table in M extension
  • Loading branch information
TheThirdOne committed Oct 13, 2019
1 parent 92a177c commit 0ebea26
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 6 deletions.
2 changes: 0 additions & 2 deletions rars/riscv/instructions/DIV.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ public DIV() {
public int compute(int value, int value2) {
// Signal illegal division with -1
if (value2 == 0) {
ControlAndStatusRegisterFile.orRegister("fcsr", 0x8); // Set Divide by Zero flag
return -1;
}
// Overflow
if (value == Integer.MIN_VALUE && value2 == -1) {
ControlAndStatusRegisterFile.orRegister("fcsr", 0x4); // Set Overflow flag
return value;
}
return value / value2;
Expand Down
1 change: 0 additions & 1 deletion rars/riscv/instructions/DIVU.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public DIVU() {
public int compute(int value, int value2) {
// Signal illegal division with -1
if (value2 == 0) {
ControlAndStatusRegisterFile.orRegister("fcsr", 0x8); // Set Divide by Zero flag
return -1;
}
return Integer.divideUnsigned(value, value2);
Expand Down
3 changes: 1 addition & 2 deletions rars/riscv/instructions/REM.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ public REM() {
}

public int compute(int value, int value2) {
// Division by 0
if (value2 == 0) {
ControlAndStatusRegisterFile.orRegister("fcsr", 0x8); // Set Divide by Zero flag
return value;
}
// Overflow
if (value == Integer.MIN_VALUE && value2 == -1) {
ControlAndStatusRegisterFile.orRegister("fcsr", 0x4); // Set Overflow flag
return 0;
}
return value % value2;
Expand Down
1 change: 0 additions & 1 deletion rars/riscv/instructions/REMU.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public REMU() {

public int compute(int value, int value2) {
if (value2 == 0) {
ControlAndStatusRegisterFile.orRegister("fcsr", 0x8); // Set Divide by Zero flag
return value;
}
return Integer.remainderUnsigned(value, value2);
Expand Down

0 comments on commit 0ebea26

Please sign in to comment.