Skip to content

Commit

Permalink
argon2: align blocks to 128-byte boundaries for modern x86-64 and aar…
Browse files Browse the repository at this point in the history
…ch64

Based on notes in crossbeam-utils::CachePadded:

https://github.com/crossbeam-rs/crossbeam/blob/17fb8417a83a/crossbeam-utils/src/cache_padded.rs#L63-L79

In summary:

- while x86-64 cache lines are still 64 bytes, modern prefetchers pull
  them in pairs, so for the purpose of preventing false sharing, we need
  128-byte alignment.

- on aarch64 big.LITTLE, the "big" cores use 128-byte cache lines.
  • Loading branch information
jonasmalacofilho committed Jan 13, 2025
1 parent 57fe8f6 commit 1342037
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion argon2/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ macro_rules! permute {
}

/// Structure for the (1 KiB) memory block implemented as 128 64-bit words.
//
// Blocks are 128-byte aligned to prevent false sharing. The specific alignment value is based on
// the notes in `crossbeam-utils::CachePadded` for modern architectures, which either use 128-byte
// cache lines (aarch64) or pull 64-byte cache lines in pairs (x86-64).
#[derive(Copy, Clone, Debug)]
#[repr(align(64))]
#[repr(align(128))]
pub struct Block([u64; Self::SIZE / 8]);

impl Block {
Expand Down

0 comments on commit 1342037

Please sign in to comment.