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

Conditional bitfields? #767

Open
Timmmm opened this issue Nov 11, 2024 · 1 comment
Open

Conditional bitfields? #767

Timmmm opened this issue Nov 11, 2024 · 1 comment

Comments

@Timmmm
Copy link
Contributor

Timmmm commented Nov 11, 2024

There are a few places I've noticed where the existence of bitfields depends on xlen. For example in Mstatus:

bitfield Mstatus : xlenbits = {
  // The MBE and SBE fields are in mstatus in RV64 and absent in RV32.
  // On RV32, they are in mstatush, which doesn't exist in RV64.  For now,
  // they are handled in an ad-hoc way.
  // MBE  : 37
  // SBE  : 36

  // The SXL and UXL fields don't exist on RV32, so they are modelled
  // via explicit getters and setters; see riscv_sys_regs.sail.
  // SXL  : 35 .. 34,
  // UXL  : 33 .. 32,

For these the current code basically gives up on bitfields and accesses mstatus.bits[33..32] directly, which is a bit of a shame. I wonder if it would make sense to support conditional bitfields, like this:

bitfield Mstatus : xlenbits = {
  MBE  : 37 if xlen == 64,
  SBE  : 36 if xlen == 64,

 SXL  : 35 .. 34, if xlen  == 64,
 UXL  : 33 .. 32 if xlen == 64,

That would allow you to move them as well. The condition would have to be inferable to true or false at compile time (or initialisation time or whatever we're calling it I guess).

To be honest it's probably not worth it just for the handful of times this would be useful. Just thought I'd share the idea... :-)

@Alasdair
Copy link
Collaborator

I have thought about this. I think it would work with any type constraint, not just one we know statically.

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

No branches or pull requests

2 participants