Skip to content
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

C.ADDI disassembly inaccurate when immediate value is negative #21

Closed
scottj97 opened this issue Sep 17, 2019 · 8 comments
Closed

C.ADDI disassembly inaccurate when immediate value is negative #21

scottj97 opened this issue Sep 17, 2019 · 8 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@scottj97
Copy link
Contributor

The opcode 0x1541 should decode into c.addi x10, -16 (according to Spike). Sail is reporting it as c.addi x10, 48.

It seems to execute correctly; if x10 is 0, it gets written with 0xffffffff_fffffff0. It's only the immediate value shown in the disassembly that looks incorrect.

@allenjbaum
Copy link
Collaborator

Any progress on this one? It's been 2 years....

@allenjbaum
Copy link
Collaborator

This is not a problem with the disassembly of C.ADDI; It appears to be a problem for every instruction with an immediate value..
@jrtc27 We can fix this particular mnemonic pretty easily by defining an signed variant - but it is a fair number of uses in some dozen or so files. Should we do this, or suffer along with a different disassembly? @ben-marshall: the crypto scalar has a bunch of immediate fields. Are the signed or unsigned or neither (in which case they're effectively unsigned)

@allenjbaum
Copy link
Collaborator

Looking a bit deeper: the following instructions improperly decode signed constants as unsigned:
[F]Loads/Stores, (LUI,AUIPC), JAL[R], btype ops (B**), Addi[w]/xori/ori/andi/slti[u], c.addi[w/16sp], c.[l[u]/and]i, c.j[al], c.bneq, c.beqz

I am assuming that crypto constants, hints, CSR#s, fences and shift amounts are not sign extended.
There a bunch of compressed immediates that are specifically zero extended

That's 19 lines in 3 files: base, cext, fext (plus defining signed versions of the hex_bits_n functions, or explicitly sign extending in those 19 lines

@martinberger
Copy link
Collaborator

That's 19 lines in 3 files: base, cext, fext

@allenjbaum It's remarkable that this remained undetected for several years.

@jrtc27
Copy link
Collaborator

jrtc27 commented Dec 15, 2021

We've known about it for years, just not a priority as it only affects the human-readable disassembly. If someone wants to fix it then great, but the string<->int handling is a bit nasty, so be warned...

@martinberger martinberger added good first issue Good for newcomers help wanted Extra attention is needed labels Dec 15, 2021
@allenjbaum
Copy link
Collaborator

You're right; it is rather...opaque (not good for something that's supposed to be readable and nasty code should be at least comments) and the hex_bits_n function don't seem to have anything to do with hex; it looks strictly binary to decimal string. I'd really prefer if it was hex (I'm not adept at reading Sail, so I could be misreading that... and no comments ....).

@KotorinMinami
Copy link
Contributor

I tried using the dec_str function in string.sail, and it seems to work well. I'm wondering if it would be possible to solve this issue by making the disassembly display an optional feature or directly changing it to decimal representation. Admittedly, there would be quite a bit of work involved in modifying the corresponding references, but I would like to participate in completing this task. I'm unsure if there is a maintainer willing to accept my pull request (PR), but if it's possible, I will provide detailed explanations of the modifications in my PR. Or is there other thoughts on my proposal?

@jordancarlin
Copy link
Contributor

Should be closed by #456

@Timmmm Timmmm closed this as completed May 28, 2024
billmcspadden-riscv pushed a commit to billmcspadden-riscv/sail-riscv that referenced this issue May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

7 participants