Skip to content

Commit

Permalink
inline Word fn
Browse files Browse the repository at this point in the history
after 5b84ad4: generic rc5 pefromance regression was noticed.
after analizing the generated asm I noticed that while the generic
top level generic impl does get inlined the actual algorithm impl
differs in the fact that it does not inline Word functions. After
adding inline annotations performance is once again compareable.
  • Loading branch information
antonio-dropulic committed Dec 5, 2022
1 parent 5b84ad4 commit 05893bb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion rc5/src/core/primitives.rs
Expand Up @@ -49,30 +49,36 @@ impl Word for u32 {
const P: Self = 0xb7e15163;
const Q: Self = 0x9e3779b9;

#[inline(always)]
fn wrapping_add(self, rhs: Self) -> Self {
u32::wrapping_add(self, rhs)
}

#[inline(always)]
fn wrapping_sub(self, rhs: Self) -> Self {
u32::wrapping_sub(self, rhs)
}

#[inline(always)]
fn rotate_left(self, n: Self) -> Self {
u32::rotate_left(self, n)
}

#[inline(always)]
fn rotate_right(self, n: Self) -> Self {
u32::rotate_right(self, n)
}

#[inline(always)]
fn from_le_bytes(bytes: &GenericArray<u8, Self::Bytes>) -> Self {
u32::from_le_bytes(bytes.as_slice().try_into().unwrap())
}

#[inline(always)]
fn to_le_bytes(self) -> GenericArray<u8, Self::Bytes> {
u32::to_le_bytes(self).into()
}

#[inline(always)]
fn bitxor(self, other: Self) -> Self {
<u32 as BitXor>::bitxor(self, other)
}
Expand Down

0 comments on commit 05893bb

Please sign in to comment.