Skip to content

Remove Mask offset consts #315

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

Merged
merged 4 commits into from
Jul 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/generate/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn render(
w_impl_items.push(quote! {
/// Reset value of the register
#[inline]
pub fn reset_value() -> W {
pub const fn reset_value() -> W {
W { bits: #rv }
}

Expand Down Expand Up @@ -257,7 +257,7 @@ pub fn fields(
access: f.access,
evs: &f.enumerated_values,
sc: Ident::new(&*sc),
mask: util::hex_or_bool((((1 as u64) << width) - 1) as u32, width),
mask: util::hex((((1 as u64) << width) - 1) as u32),
name: &f.name,
offset: util::unsuffixed(u64::from(f.bit_range.offset)),
ty: width.to_ty()?,
Expand Down Expand Up @@ -285,10 +285,7 @@ pub fn fields(
quote! { as #fty }
};
let value = quote! {
const MASK: #fty = #mask;
const OFFSET: u8 = #offset;

((self.bits >> OFFSET) & MASK as #rty) #cast
((self.bits >> #offset) & #mask) #cast
};

if let Some((evs, base)) = lookup(
Expand Down Expand Up @@ -519,7 +516,7 @@ pub fn fields(
#[doc = #description]
#[inline]
pub fn #sc(&self) -> #pc_r {
let bits = { #value };
let bits = #value;
#pc_r { bits }
}
});
Expand Down Expand Up @@ -763,11 +760,8 @@ pub fn fields(
/// Writes raw bits to the field
#[inline]
pub #unsafety fn #bits(self, value: #fty) -> &'a mut W {
const MASK: #fty = #mask;
const OFFSET: u8 = #offset;

self.w.bits &= !((MASK as #rty) << OFFSET);
self.w.bits |= ((value & MASK) as #rty) << OFFSET;
self.w.bits &= !(#mask << #offset);
self.w.bits |= ((value as #rty) & #mask) << #offset;
self.w
}
});
Expand Down