DIV and REM: erronous results for -1/1
Created by: ASintzoff
When performing integer division -1/1
, the quotient should be -1
and the remainder should be 0
.
The observed results are not the expected ones:
- quotient:
0
- remainder:
-1
These results are obtained thanks to the riscv-compliance test suite.
https://github.com/riscv/riscv-compliance/blob/master/riscv-test-suite/rv32im/src/DIV.S
https://github.com/riscv/riscv-compliance/blob/master/riscv-test-suite/rv32im/src/REM.S
Extract of riscv-compliance rv32im/DIV.S test log:
core 0: 0x0000000080000182 (0x000057fd) c.li a5, -1
3 0x0000000080000182 (0x000057fd) x15 0xffffffffffffffff
core 0: 0x0000000080000184 (0x00004705) c.li a4, 1
3 0x0000000080000184 (0x00004705) x14 0x0000000000000001
core 0: 0x0000000080000186 (0x02e7c733) div a4, a5, a4
3 0x0000000080000186 (0x02e7c733) x14 0x0000000000000000
And rv32im/REM.S test log:
core 0: 0x0000000080000182 (0x000057fd) c.li a5, -1
3 0x0000000080000182 (0x000057fd) x15 0xffffffffffffffff
core 0: 0x0000000080000184 (0x00004705) c.li a4, 1
3 0x0000000080000184 (0x00004705) x14 0x0000000000000001
core 0: 0x0000000080000186 (0x02e7e733) rem a4, a5, a4
3 0x0000000080000186 (0x02e7e733) x14 0xffffffffffffffff