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

Added the rest of 1:1 PseudoInstructions #278

Conversation

AFOliveira
Copy link
Contributor

@AFOliveira AFOliveira commented Aug 27, 2024

Complementing #277, there were a few 1:1 pseudo instructions that were missing.
Below is the list with the link to the asm manual:

I

j
jal
jr
jalr

Zicsr

csrr
csrw
csrs
csrc
csrwi
csrsi
csrci

…to be made

Co-authored-by: Alfredo Rodrigues <[email protected]>
Signed-off-by: Afonso Oliveira <[email protected]>
Copy link
Member

@aswaterman aswaterman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was worried that pseduo-ops with the same name as real instructions might cause problems somewhere, but so far, everything seems OK. We can always roll back the addition of jal and jalr pseudoinstructions in the future if need be.

@aswaterman aswaterman merged commit 07b95c5 into riscv:master Aug 27, 2024
2 checks passed
@AFOliveira
Copy link
Contributor Author

AFOliveira commented Aug 28, 2024

After your comment, I looked deeper on what's really happening with those specific cases, and, even though they are not breaking anything, your instinct is in fact correct.
Here's what's happening:
They are being wrongfully handled by this code block:

    # if a pseudo instruction has already been added to the filtered
    # instruction dictionary but the extension is not in the current
    # list, add it
    ext_name = single_dict['extension']
    if ext_name not in instr_dict[name]['extension']:
        instr_dict[name]['extension'].extend(ext_name)

This results in:

  • Creates a bug in the extensions they belong to (doubling the rv_i)
  • Ignores the JAL and JALR Pseudo instruction encoding and actually does nothing with it
jal:
  encoding: '-------------------------1101111'
  extension:
  - rv_i
  - rv_i
  mask: '0x7f'
  match: '0x6f'
  variable_fields:
  - rd
  - jimm20

I can actually fix this, but the way I found to be more straight-forward is to actually add a "Pseudo" keyword before this intructions. This can be done either on the processing code (for all the pseudo-instructions) or in the definition (like this: $pseudo_op rv_i::jalr pseudo_jalr rs1 31..20=0 14..12=0 11..7=0x01 6..2=0x19 1..0=3)

The second, seems to be smoother since it would only affect the targeted instructions, but I'm not sure if this problem may appear again in the future and therefore I would like to hear your opinion on this.

@aswaterman
Copy link
Member

I think it would be much cleaner to have the script detect this case automatically (by observing the name collision) and do whatever is necessary. We don't want the extra boilerplate pseudo_; the $pseudo_op directive should be smart enough to do whatever is necessary.

@AFOliveira
Copy link
Contributor Author

Ok, then, I will do that and reference this PR then. Thank you.

@aswaterman
Copy link
Member

Thank you for your help, @AFOliveira!

@AFOliveira AFOliveira deleted the F/D/CSR_Pseudoinstructions branch September 4, 2024 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants