| ... | @@ -100,8 +100,18 @@ pub const Block = struct { | ... | @@ -100,8 +100,18 @@ pub const Block = struct { |
| 100 | | 100 | |
| 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 | }; |
| 105 | | 115 | |
| 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 { |