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

Allow empty bitfield? #899

Open
trdthg opened this issue Jan 21, 2025 · 4 comments · May be fixed by #902
Open

Allow empty bitfield? #899

trdthg opened this issue Jan 21, 2025 · 4 comments · May be fixed by #902

Comments

@trdthg
Copy link
Contributor

trdthg commented Jan 21, 2025

Some registers in riscv currently have no bits defined.

like mstateen1, mstateen2 ...

https://riscv-specs.timhutt.co.uk/spec/riscv-isa-release-b5aa38c-2025-01-17/riscv-privileged.html#_state_enable_0_registers

But sail doesn't accept empty bitfield

| bitfield <id> : <typ> = { <r_def_body> }

I can use

type Mstateen1 = xlenbits

But things like mstateen1.bits are not avaliable. So could we make sail accept empty bitfield for future use?

bitfield Mstateen1 : xlenbits = {}
@Alasdair
Copy link
Collaborator

I don't see any harm in allowing an empty bitfield, but I think a plain bitvector would be fine for most use cases - you would just use mstateen1 directly without needing mstateen1.bits.

@martinberger
Copy link

There are some interesting issues to do with empty bitranges: in a normal Turing-complete software setting, an empty bitvector is type-isomorphic to the unit type. This is because we can still communicate termination/non-termination with unit. So even a value of unit type communicates information.

But what happens with RTL, e.g. Verilog? Should we still generate a port for empty bitvectors? There are reasonable arguments either way ...

@Alasdair
Copy link
Collaborator

In this case it's about having a bitfield with no fields, but the underlying bits type would still be non-empty like bits(xlen).

I don't think it's correct to say that unit tells you anything about termination, as both:

function f1() = ()
// and
function f2() = while true do ()

have type unit. The current SystemVerilog generation will try to remove unit ports where possible, as there really isn't a good way to represent a zero-width type in SystemVerilog.

@Alasdair
Copy link
Collaborator

For Sail zero-width bitvectors, i.e. bits(0) the SystemVerilog translation will translate them into a variable-width representation as a length * value pair. Not sure if they are common enough to warrant a more sophisticated encoding.

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 a pull request may close this issue.

3 participants