为什么 RISC-V 输出 -1 或 xFFFFFFFF 除以 0?

Why has RISC-V output -1 or xFFFFFFFF from dividing by 0?

据我所知,RISC-V中除以0的结果是-1(有符号),0xFFFFFFFF(十六进制)。 但我不知道 RISC-V 输出这段代码的原因。 还有这个程序如何合理?

谢谢!

We considered raising exceptions on integer divide by zero, with these exceptions causing a trap in most execution environments. However, this would be the only arithmetic trap in the standard ISA (floating-point exceptions set flags and write default values, but do not cause traps) and would require language implementors to interact with the execution environment’s trap handlers for this case. Further, where language standards mandate that a divide-by-zero exception must cause an immediate control flow change, only a single branch instruction needs to be added to each divide operation, and this branch instruction can be inserted after the divide and should normally be very predictably not taken, adding little runtime overhead.

The value of all bits set is returned for both unsigned and signed divide by zero to simplify the divider circuitry. The value of all 1s is both the natural value to return for unsigned divide, representing the largest unsigned number, and also the natural result for simple unsigned divider implementations. Signed division is often implemented using an unsigned division circuit and specifying the same overflow result simplifies the hardware.

来自 https://five-embeddev.com/riscv-isa-manual/latest/m.html