-
Notifications
You must be signed in to change notification settings - Fork 858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] instruction bugs for RV32 isa #1642
Comments
I did a simple search, it seems only c_xor/xnor/xor/xori/andn/cmix/orn are not protected with |
I disagree with this analysis. LUI will load the constant in sign-extended form (FFFFFFFFFF000000), and so the XORI will produce 0000000000FFFFFF. In general, the bitwise-logical instructions do not need sext_xlen because, if the two inputs are canonically sign-extended, the result will be canonically sign-extended, too. |
I wrote a test program based on your code, and I see the expected behavior:
I hacked Spike to print out the full 64-bit contents of the registers (by changing
Which is what I wrote in my earlier comment. So it's hard to say why you're having the problem that you're having, but I'm certain it's not because of a missing |
Thanks for a quick reply! So, to be clear. In xlen=32, should we apply all our instructions in sign-extended form? Thanks |
I see, it makes sense that the customized LUI would be at fault here. Yes, in general, you should guarantee that RV32 instructions properly sign-extended their results, but you can assume as a precondition that the inputs are properly sign-extended. |
Update:
As is replied in #1642 (comment), please ensure RV32 customized instructions properly sign-extended their results
Hi all,
Recently we try to simulate 32bit programs with "spike --with-isa rv32imac". A test program can be summarized to:
However, the bnez always cause jump where it should not have done.
Digging into the code, the reason is obvious:
not
is implemented with "xori:WRITE_RD(insn.i_imm() ^ RS1);
". However,xori.h
is written 10+ years ago and might be forgotten when we use uint64_t as reg_t instead of uint32_t.Thus, NOT 0xff000000 equals to 0xFFFFFFFF00FFFFFF. AND 0xFF000000 equals to 0xFFFFFFFF0000000, which is not zero and causes a jump.
There are already some ops (like c_not.h) apply
sext_xlen
to avoid this problem, but it is clearly not implemented to all ops.Two possible fix are:
I may able to help fix that, but which one is preferred? Thanks.
The text was updated successfully, but these errors were encountered: