[del] tock-registers: Inline more aggressively

This commit is contained in:
Berkus Decker 2020-11-22 15:08:57 +02:00
parent b3ddfc5665
commit e3c9926a43
1 changed files with 8 additions and 0 deletions

View File

@ -503,6 +503,7 @@ impl<T: IntLike, R: RegisterLongName> Field<T, R> {
} }
/// Get the raw bitmask used by this Field. /// Get the raw bitmask used by this Field.
#[inline]
pub fn mask(&self) -> T { pub fn mask(&self) -> T {
(self.mask as T) << self.shift (self.mask as T) << self.shift
} }
@ -580,6 +581,7 @@ FieldValue_impl_for!(u8, u16, u32, u64, u128);
impl<T: IntLike, R: RegisterLongName> FieldValue<T, R> { impl<T: IntLike, R: RegisterLongName> FieldValue<T, R> {
/// Get the raw bitmask represented by this FieldValue. /// Get the raw bitmask represented by this FieldValue.
#[inline]
pub fn mask(&self) -> T { pub fn mask(&self) -> T {
self.mask as T self.mask as T
} }
@ -590,16 +592,19 @@ impl<T: IntLike, R: RegisterLongName> FieldValue<T, R> {
} }
/// Modify fields in a register value /// Modify fields in a register value
#[inline]
pub fn modify(self, val: T) -> T { pub fn modify(self, val: T) -> T {
(val & !self.mask) | self.value (val & !self.mask) | self.value
} }
/// Check if any specified parts of a field match /// Check if any specified parts of a field match
#[inline]
pub fn matches_any(self, val: T) -> bool { pub fn matches_any(self, val: T) -> bool {
val & self.mask != T::zero() val & self.mask != T::zero()
} }
/// Check if all specified parts of a field match /// Check if all specified parts of a field match
#[inline]
pub fn matches_all(self, val: T) -> bool { pub fn matches_all(self, val: T) -> bool {
val & self.mask == self.value val & self.mask == self.value
} }
@ -608,6 +613,8 @@ impl<T: IntLike, R: RegisterLongName> FieldValue<T, R> {
// Combine two fields with the addition operator // Combine two fields with the addition operator
impl<T: IntLike, R: RegisterLongName> Add for FieldValue<T, R> { impl<T: IntLike, R: RegisterLongName> Add for FieldValue<T, R> {
type Output = Self; type Output = Self;
#[inline]
fn add(self, rhs: Self) -> Self { fn add(self, rhs: Self) -> Self {
FieldValue { FieldValue {
mask: self.mask | rhs.mask, mask: self.mask | rhs.mask,
@ -619,6 +626,7 @@ impl<T: IntLike, R: RegisterLongName> Add for FieldValue<T, R> {
// Combine two fields with the += operator // Combine two fields with the += operator
impl<T: IntLike, R: RegisterLongName> AddAssign for FieldValue<T, R> { impl<T: IntLike, R: RegisterLongName> AddAssign for FieldValue<T, R> {
#[inline]
fn add_assign(&mut self, rhs: FieldValue<T, R>) { fn add_assign(&mut self, rhs: FieldValue<T, R>) {
self.mask |= rhs.mask; self.mask |= rhs.mask;
self.value |= rhs.value; self.value |= rhs.value;