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

macaw-riscv: Add ABI mnemonics for floating-point registers #454

Closed
RyanGlScott opened this issue Nov 26, 2024 · 0 comments · Fixed by #455
Closed

macaw-riscv: Add ABI mnemonics for floating-point registers #454

RyanGlScott opened this issue Nov 26, 2024 · 0 comments · Fixed by #455
Labels

Comments

@RyanGlScott
Copy link
Contributor

Per the official RISC-V Calling Conventions document, RISC-V registers can sometimes go by two names:

  • The "Name" (e.g., x2)
  • The "ABI Mnemonic" (e.g., sp)

It is common to refer to registers by their ABI mnemonics rather than their full names, so it is nice for macaw-riscv to let users refer to registers by either name. macaw-riscv already does this for integer registers: in Data.Macaw.RISCV.RISCVReg, we can see that:

  • There is a GPR newtype that wraps the integer suffix used in an integer register (e.g., the 2 in x2).
  • There are pattern synonyms for each GPR's ABI mnemonic (e.g., we have pattern SP = BuildGPR 2 for the sp mnemonic for x2).
  • There are also pattern synonyms that lift each GPR value to a full RISCVReg value (e.g., we have pattern GPR_SP = RISCV_GPR (BuildGPR bv)).
  • The Show instance for RISCVReg displays the ABI mnemonics rather than the x* names, as tools like objdump will typically display the ABI mnemonics by default.

This is great. Unfortunately, macaw-riscv's ABI mnemonic support is currently incomplete. While it supports the ABI mnemonics for integer registers, it does not support the ABI mnemonics for floating-point registers. Currently, we simply have:

-- | Floating-point registers.
FPR :: G.SizedBV 5 -> RISCVReg rv (MT.BVType (G.RVFloatWidth rv))

Which means that users have to write something like, say, FPR 8 in order to refer to the register named f8, which also goes by the ABI mnemonic fs0. I argue that users should also be able to achieve this by writing something like FPR_FS0, which would mirror the existing treatment for integer register ABI mnemonics. To that end, we should:

  1. Define an FPR newtype and define RISCVReg's FPR data constructor in terms of it.
  2. Define FPR pattern synonyms for each ABI mnemonic listed in this table.
  3. Define pattern synonyms that lift each FPR pattern synonym to a full RISCVReg.
  4. Alter the Show instance for RISCVReg to display the ABI mnemonics for each floating-point register.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant