aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorFrank Denis <github@pureftpd.org>2020-10-27 13:33:08 +0100
committerVeikka Tuominen <git@vexu.eu>2020-10-28 21:44:00 +0200
commit0adc144f88b567054e63df808aac0227445e88bb (patch)
treec41f8c7c03c26dda25a2757e3f8f1378477587a8 /lib/std
parentea45897fcc5097c4cf73a30fe009500f6efe8bc5 (diff)
downloadzig-0adc144f88b567054e63df808aac0227445e88bb.tar.gz
zig-0adc144f88b567054e63df808aac0227445e88bb.zip
std/crypto: adjust aesni parallelism to CPU models
Intel keeps changing the latency & throughput of the aes* and clmul instructions every time they release a new model. Adjust `optimal_parallel_blocks` accordingly, keeping 8 as a safe default for unknown data.
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/crypto/aes/aesni.zig12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/std/crypto/aes/aesni.zig b/lib/std/crypto/aes/aesni.zig
index 5f605a4e60..3d694875bf 100644
--- a/lib/std/crypto/aes/aesni.zig
+++ b/lib/std/crypto/aes/aesni.zig
@@ -100,8 +100,18 @@ pub const Block = struct {
/// Perform operations on multiple blocks in parallel.
pub const parallel = struct {
+ const cpu = std.Target.x86.cpu;
+
/// The recommended number of AES encryption/decryption to perform in parallel for the chosen implementation.
- pub const optimal_parallel_blocks = 8;
+ pub const optimal_parallel_blocks = switch (std.Target.current.cpu.model) {
+ &cpu.westmere => 6,
+ &cpu.sandybridge, &cpu.ivybridge => 8,
+ &cpu.haswell, &cpu.broadwell => 7,
+ &cpu.cannonlake, &cpu.skylake, &cpu.skylake_avx512 => 4,
+ &cpu.icelake_client, &cpu.icelake_server => 6,
+ &cpu.znver1, &cpu.znver2 => 8,
+ else => 8,
+ };
/// Encrypt multiple blocks in parallel, each their own round key.
pub inline fn encryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block {