Skip to content

Alternative reprs for bitfields #136

Description

@jonathanpallant

Doing a volatile write on a struct type causes LLVM to emit some annoying loads/stores using the stack. This seems to be because the volatile operation gets converted to a volatile memcpy, and both the source (RAM) and the destination (MMIO) get treated as volatile.

I suspect that selecting repr(transparent) instead of repr(C) would fix this. Is it possible to have a way to change the default repr?

Basically given:

/// Interrupt Register
#[bitbybit::bitfield(u32, debug, default = 0)]
pub struct Ir {
	#[bit(4, rw)]
	pub cr_interrupt: [bool; 4],
	#[bit(0, rw)]
	pub mr_interrupt: [bool; 4],
}

I'd like to change the output from:

#[repr(C)]
/// Interrupt Register
pub struct Ir {
    raw_value: u32,
}

to:

#[repr(transparent)]
/// Interrupt Register
pub struct Ir {
    raw_value: u32,
}
``

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions