Bug Fix: correcting immediate encoding for unsigned instructions#108
Bug Fix: correcting immediate encoding for unsigned instructions#108samsoniuk merged 1 commit intodarklife:masterfrom
Conversation
|
Wow! Thanks for the bug! =D It is amazing that such bug was hidden for so many years but, in a quick check, I grepped 1M+ lines of RISCV asm code here and found not a single sltiu or slti instruction! That explain why the bug survived across the years. Anyway, I need patch some cores by hand here and test in order to ensure everything is working but I will need some time... Meanwhile, I would suggest redo the PR to keep the changes at the minimum: Which means keep XSIMM/SIMM and XUIMM/UIMM naming, in a way that the merge with older versions is less complex. As far as XUIMM/UIMM are not used, they will be optimized out at RTL steps, while the same naming scheme keeps a more smooth path between past and future versions of the code. About the Processor CI project, it is a very interesting project and I hope you find a time to fix the bugs for all that processors in the list! For sure, not an easy task, because each processor probably have very specific requirements in order to work! Of course, case you need some help, please make me know about it! =D In the case of DarkRISCV, it was almost running in early versions but I made lots of changes in the top level in order to make it work with caches and asynchronous buses, so that changes probably broke the compatibility with your top level. Early versions of DarkRISCV relied on external control to halt the processor in order to insert wait states, while the more recent versions added a new control flow per interface, similar to Wishbone bus, so data and code interfaces can now better control the wait-states when interfacing memories, so it will probably work in the future with a reviewed top level. For now thanks for the bug and good hacking! |
|
Hi, Marcelo |
|
Thanks! =D |
Bug fix
First of all, congratulations for your work in the darkriscv core! It is a very popular processor. I'm working on a project that involves RISC-V processors verification, and I used darkriscv in my evaluation.
Our Project
The Issue
Darkriscv is failing to execute the SLTIU instruction when the immediate is negative. The darkriscv source code uses an "unsigned immediate" to perform the SLTIU comparison, which is the immediate bits extended with zeroes.
darkriscv/rtl/darkriscv.v
Lines 195 to 201 in 61bd172
However, according to the RISC-V manual v20250508, page 25, all immediate must be sign-extended, even if later evaluated as unsigned.
The only instructions that use this kind of unsigned immediate are CSR instructions that I believe were not implemented in darkriscv. This was extracted from the same manual, page 49.
How to Reproduce
This code snippet from the riscv-arch-test suite is enough to reproduce the error:
The Fix
Since all immediates must be sign-extended, I removed the unsigned immediates.