Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
As the issue desciption said, in the latest Ripes, the I-type instructions will check whether the given immediate part can fit in the instruction limitation.
For example, the
addi
instruction will ensure the given immediate is less than 13 bits, as the following image shows:However, the
lui
instruction's immediate part should only accept an immediate value that could fit in 20 bits, but current version doesn't handle this limitation correctly, as shown in the above image.Tracing
To find the problem, I use
std::cout
to dump thewidth
in thecheckFitsInWidth
function, which is for checking the immediate range:Then, rebuild the Ripes and test it with the following codes:
And found that the
width
oflui
instruction is misconfigured as 32, instead of 20:And this is origin from the the U-type instruction implementation, we can see that the
width
is configured as 32:Solve
By changing the width to 20, the bit range checking now works as expected, on the
lui
andauipc
:Testing
Currently I only use the provided testing utility for checking my changes didn't break it:
However, since I'm not that familiar with C++, I'm not sure whether I understood the bit range checking process correctly. If there is any problem in my changes, please me know.