-
Notifications
You must be signed in to change notification settings - Fork 113
argon2: fold compress_avx2 into an inner function
#444
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
tarcieri
merged 1 commit into
master
from
argon2/fold-compress-avx2-into-inner-function
Jul 13, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,8 +66,10 @@ impl Block { | |
| unsafe { &mut *(self.0.as_mut_ptr() as *mut [u8; Self::SIZE]) } | ||
| } | ||
|
|
||
| /// NOTE: do not call this directly. It should only be called via | ||
| /// `Argon2::compress`. | ||
| #[inline(always)] | ||
| pub(crate) fn compress_soft(rhs: &Self, lhs: &Self) -> Self { | ||
| pub(crate) fn compress(rhs: &Self, lhs: &Self) -> Self { | ||
| let r = *rhs ^ lhs; | ||
|
|
||
| // Apply permutations rowwise | ||
|
|
@@ -102,12 +104,6 @@ impl Block { | |
| q ^= &r; | ||
| q | ||
| } | ||
|
|
||
| #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] | ||
| #[target_feature(enable = "avx2")] | ||
| pub(crate) unsafe fn compress_avx2(rhs: &Self, lhs: &Self) -> Self { | ||
| Self::compress_soft(rhs, lhs) | ||
| } | ||
| } | ||
|
|
||
| impl Default for Block { | ||
|
|
@@ -151,21 +147,3 @@ impl Zeroize for Block { | |
| self.0.zeroize(); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod test { | ||
| use super::*; | ||
|
|
||
| #[cfg(target_arch = "x86_64")] | ||
| #[test] | ||
| fn compress_avx2() { | ||
| let mut lhs = Block([0; 128]); | ||
| lhs.0[0..7].copy_from_slice(&[0, 0, 0, 2048, 4, 2, 1]); | ||
| let rhs = Block([0; 128]); | ||
|
|
||
| let result = Block::compress_soft(&rhs, &lhs); | ||
| let result_avx2 = unsafe { Block::compress_avx2(&rhs, &lhs) }; | ||
|
|
||
| assert_eq!(result.0, result_avx2.0); | ||
| } | ||
| } | ||
|
Comment on lines
-155
to
-171
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test feels a bit superfluous as for now the implementation is just |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this would be fine as
#[inline]but haven't benchmarked yetThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK
#[inline]is effectively useless for crate-private functions. You could remove the attribute completely to check whether compiler decides to inline it by itself. But to be on the safe side and to be more robust in the face of future compiler changes, I think it's fine to use#[inline(always)].