Skip to content

Commit 230c5f8

Browse files
committed
Add comments about block size choices
1 parent 1ba6590 commit 230c5f8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

aes/src/x86.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,24 @@ macro_rules! define_aes_impl {
451451
}
452452
#[cfg(all(target_arch = "x86_64", any(aes_avx256, aes_avx512)))]
453453
impl<'a> ParBlocksSizeUser for $name_backend::Vaes256<'a> {
454+
// Block size of 30 is chosen based on AVX2's 16 YMM registers.
455+
//
456+
// * 1 register holds 2 keys per round (loads interleaved with rounds)
457+
// * 15 registers hold 2 data blocks
458+
//
459+
// This gives (16 <total> - 1 <round key>) * 2 <data> = 30 <data>.
454460
type ParBlocksSize = U30;
455461
}
456462
#[cfg(all(target_arch = "x86_64", aes_avx512))]
457463
impl<'a> ParBlocksSizeUser for $name_backend::Vaes512<'a> {
464+
// Block size of 64 is chosen based on AVX512's 32 ZMM registers.
465+
//
466+
// * 11, 13, 15 registers for keys, correspond to AES-128, AES-192, AES-256
467+
// * 11, 13, 15 registers hold 4 keys each (no interleaved loading like VAES256)
468+
// * 16 registers hold 4 data blocks
469+
// * 1-4 registers remain unused (could use them but probably not worth it)
470+
//
471+
// This gives (32 <total> - 15 <AES-256 round keys> - 1 <unused>) * 4 <data> = 64 <data>.
458472
type ParBlocksSize = U64;
459473
}
460474

0 commit comments

Comments
 (0)