-
Notifications
You must be signed in to change notification settings - Fork 9
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
Non-contiguous bit ranges #24
Comments
What syntax to use here? Rust itself doesn't have non-contiguous ranges, so we have to make up a syntax. We could list ranges like this:
Or introduce a range combiner:
Or have a more array-like syntax:
|
I think of the listed 3 options, I like the feel of the 1st the most, but the 2nd and 3rd have the benefit of semantically separating the bit ranges from the rw modifier. I'd also probably parse them as actual ranges instead of manually, because it would make it much easier to interweave single bits with bit ranges, so rather than |
Another feature where this is quite useful is RISC-V immediate values: They are a pain to take apart otherwise |
Looking at the various options again, I think I prefer option 3 now. I think that's the option that I have seen other projects pick the most often when confronted with similar issues |
Option 2 should probably be disqualified. The following pattern might be confusing:
According to this proposal it would mean "1 to 9 (inclusive), followed by 15". In regular Rust however, this would be parsed as |
Implemented via option 3: #52 |
Thanks for implementing this! Perfect timing too, cause I just realized I needed this today :) It looks like I might be running into a bug though. I've defined the following bitfield: #[bitfield(u64, default = 0)]
struct SegmentDescriptor {
#[bits([0..=15, 16..=19], rw)]
limit: u20,
#[bits([16..=31, 32..=39, 56..=63], rw)]
base: u32,
#[bits(40..=43, rw)]
r#type: u4,
#[bit(44, rw)]
system: bool,
} When I try to compile though, I get the following errors:
Here's a more minimal example: #[bitfield(u64)]
struct Foo {
#[bits([0..=15, 16..=31], rw)]
bar: u32,
} So far, it seems the issue occurs when using the non-contiguous syntax for a Does this look like a bug to you, or am I maybe missing something in how I'm trying to use this? |
Thanks for the report. I can reproduce this. Working on a fix. Unrelated to the issue, but |
This was reported in issue #24. The fix itself is two characters - added a ton of test coverage to go through all combinations of regular and arbitrary ints.
@mtoohey31 The fix was pretty straightforward - missing braces in the generated code: #53 I'll merge this asap and publish a version. |
Fix merged and published. Please give 1.3.1 a shot |
Thanks for the super quick fix @danlehmann! I can confirm that the issue is fixed for me! |
Occasionally, bit ranges aren't contiguous. An example would be the x64 REX prefix, which provides the upper-most bit in a u4 to extend the u3 of a later byte.
Not very common, but we could support it
The text was updated successfully, but these errors were encountered: