Skip to content

Join the bits muching into a single line to improve dev builds #344

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 1 commit into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- Break ultra-long single line output into multiple lines for better usability
- Joined field write proxy into a single line to help dev builds
- Elimated useless 0 shifts to reduce generated code size and fix a clippy lint

### Fixed

Expand Down
38 changes: 28 additions & 10 deletions src/generate/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ pub fn fields(

let bits = &f.bits;
let mask = &f.mask;
let offset = &f.offset;
let offset: usize = f.offset.parse().unwrap();
let fty = &f.ty;

let lookup_results = lookup(
Expand All @@ -341,8 +341,15 @@ pub fn fields(
} else {
quote! { as #fty }
};
let value = quote! {
((self.bits >> #offset) & #mask) #cast
let value = if offset != 0 {
let offset = &f.offset;
quote! {
((self.bits >> #offset) & #mask) #cast
}
} else {
quote! {
(self.bits & #mask) #cast
}
};

if let Some((evs, base)) = lookup_filter(&lookup_results, Usage::Read) {
Expand Down Expand Up @@ -720,13 +727,24 @@ pub fn fields(
});
}

proxy_items.push(quote! {
///Writes raw bits to the field
#[inline(always)]
pub #unsafety fn #bits(self, value: #fty) -> &'a mut W {
self.w.bits &= !(#mask << #offset);
self.w.bits |= ((value as #rty) & #mask) << #offset;
self.w
proxy_items.push(if offset != 0 {
let offset = &f.offset;
quote! {
///Writes raw bits to the field
#[inline(always)]
pub #unsafety fn #bits(self, value: #fty) -> &'a mut W {
self.w.bits = (self.w.bits & !(#mask << #offset)) | (((value as #rty) & #mask) << #offset);
self.w
}
}
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else if f.width == rsize {
 ...
     self.w.bits = value
     self.w
} else {

for 0xffff_ffff etc.
rsize you can pass with fields() instead of rty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. 😅Small steps please so our fellow reviewers/approvers can follow what's going on.

quote! {
///Writes raw bits to the field
#[inline(always)]
pub #unsafety fn #bits(self, value: #fty) -> &'a mut W {
self.w.bits = (self.w.bits & !#mask) | ((value as #rty) & #mask);
self.w
}
}
});

Expand Down