Skip to content

Commit bb73dfe

Browse files
committed
Join the bits muching into a single line to improve dev builds
Also this rectifies many of the tons of https://rust-lang.github.io/rust-clippy/master/index.html#identity_op lints we're getting. Signed-off-by: Daniel Egger <[email protected]>
1 parent 0d53ed6 commit bb73dfe

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
### Changed
1515

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

1820
### Fixed
1921

src/generate/register.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ pub fn fields(
323323

324324
let bits = &f.bits;
325325
let mask = &f.mask;
326-
let offset = &f.offset;
326+
let offset: usize = f.offset.parse().unwrap();
327327
let fty = &f.ty;
328328

329329
let lookup_results = lookup(
@@ -341,8 +341,15 @@ pub fn fields(
341341
} else {
342342
quote! { as #fty }
343343
};
344-
let value = quote! {
345-
((self.bits >> #offset) & #mask) #cast
344+
let value = if offset != 0 {
345+
let offset = &f.offset;
346+
quote! {
347+
((self.bits >> #offset) & #mask) #cast
348+
}
349+
} else {
350+
quote! {
351+
(self.bits & #mask) #cast
352+
}
346353
};
347354

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

723-
proxy_items.push(quote! {
724-
///Writes raw bits to the field
725-
#[inline(always)]
726-
pub #unsafety fn #bits(self, value: #fty) -> &'a mut W {
727-
self.w.bits &= !(#mask << #offset);
728-
self.w.bits |= ((value as #rty) & #mask) << #offset;
729-
self.w
730+
proxy_items.push(if offset != 0 {
731+
let offset = &f.offset;
732+
quote! {
733+
///Writes raw bits to the field
734+
#[inline(always)]
735+
pub #unsafety fn #bits(self, value: #fty) -> &'a mut W {
736+
self.w.bits = (self.w.bits & !(#mask << #offset)) | (((value as #rty) & #mask) << #offset);
737+
self.w
738+
}
739+
}
740+
} else {
741+
quote! {
742+
///Writes raw bits to the field
743+
#[inline(always)]
744+
pub #unsafety fn #bits(self, value: #fty) -> &'a mut W {
745+
self.w.bits = (self.w.bits & !#mask) | ((value as #rty) & #mask);
746+
self.w
747+
}
730748
}
731749
});
732750

0 commit comments

Comments
 (0)