authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2020-10-27 13:33:08+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-10-28 21:44:00+02:00
log0adc144f88b567054e63df808aac0227445e88bb
treec41f8c7c03c26dda25a2757e3f8f1378477587a8
parentea45897fcc5097c4cf73a30fe009500f6efe8bc5

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.

1 files changed, 11 insertions(+), 1 deletions(-)

lib/std/crypto/aes/aesni.zig+11-1
...@@ -100,8 +100,18 @@ pub const Block = struct {...@@ -100,8 +100,18 @@ pub const Block = struct {
100100
101 /// Perform operations on multiple blocks in parallel.101 /// Perform operations on multiple blocks in parallel.
102 pub const parallel = struct {102 pub const parallel = struct {
103 const cpu = std.Target.x86.cpu;
104
103 /// The recommended number of AES encryption/decryption to perform in parallel for the chosen implementation.105 /// The recommended number of AES encryption/decryption to perform in parallel for the chosen implementation.
104 pub const optimal_parallel_blocks = 8;106 pub const optimal_parallel_blocks = switch (std.Target.current.cpu.model) {
107 &cpu.westmere => 6,
108 &cpu.sandybridge, &cpu.ivybridge => 8,
109 &cpu.haswell, &cpu.broadwell => 7,
110 &cpu.cannonlake, &cpu.skylake, &cpu.skylake_avx512 => 4,
111 &cpu.icelake_client, &cpu.icelake_server => 6,
112 &cpu.znver1, &cpu.znver2 => 8,
113 else => 8,
114 };
105115
106 /// Encrypt multiple blocks in parallel, each their own round key.116 /// Encrypt multiple blocks in parallel, each their own round key.
107 pub inline fn encryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block {117 pub inline fn encryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block {