argon2: fold compress_avx2 into an inner function#444
Merged
Conversation
This changes `Argon2::compress` to contain all AVX2-related logic, so it doesn't bleed into the `Block` type yet (especially since that lacks any AVX2-specific implementation).
Member
Author
|
Followup to #440 cc @dyc3 @newpavlov |
tarcieri
commented
Jul 12, 2023
|
|
||
| /// NOTE: do not call this directly. It should only be called via | ||
| /// `Argon2::compress`. | ||
| #[inline(always)] |
Member
Author
There was a problem hiding this comment.
I suspect this would be fine as #[inline] but haven't benchmarked yet
Member
There was a problem hiding this comment.
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)].
newpavlov
approved these changes
Jul 12, 2023
tarcieri
commented
Jul 12, 2023
Comment on lines
-155
to
-171
| #[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); | ||
| } | ||
| } |
Member
Author
There was a problem hiding this comment.
This test feels a bit superfluous as for now the implementation is just Block::compress with optimizations enabled
dyc3
approved these changes
Jul 12, 2023
Contributor
dyc3
left a comment
There was a problem hiding this comment.
Ah, now I see what you were saying before. This looks good to me.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This changes
Argon2::compressto contain all AVX2-related logic, so it doesn't bleed into theBlocktype yet (especially since that lacks any AVX2-specific implementation).