| ... | @@ -32,9 +32,9 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { | ... | @@ -32,9 +32,9 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { |
| 32 | pub const key_length = 16; | 32 | pub const key_length = 16; |
| 33 | | 33 | |
| 34 | const pc_count = if (builtin.mode != .ReleaseSmall) 16 else 2; | 34 | const pc_count = if (builtin.mode != .ReleaseSmall) 16 else 2; |
| 35 | const agg_4_treshold = 22; | 35 | const agg_4_threshold = 22; |
| 36 | const agg_8_treshold = 84; | 36 | const agg_8_threshold = 84; |
| 37 | const agg_16_treshold = 328; | 37 | const agg_16_threshold = 328; |
| 38 | | 38 | |
| 39 | // Before the Haswell architecture, the carryless multiplication instruction was | 39 | // Before the Haswell architecture, the carryless multiplication instruction was |
| 40 | // extremely slow. Even with 128-bit operands, using Karatsuba multiplication was | 40 | // extremely slow. Even with 128-bit operands, using Karatsuba multiplication was |
| ... | @@ -65,13 +65,13 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { | ... | @@ -65,13 +65,13 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { |
| 65 | if (builtin.mode != .ReleaseSmall) { | 65 | if (builtin.mode != .ReleaseSmall) { |
| 66 | hx[2] = reduce(clmul128(hx[1], h)); // h^3 | 66 | hx[2] = reduce(clmul128(hx[1], h)); // h^3 |
| 67 | hx[3] = reduce(clsq128(hx[1])); // h^4 = h^2^2 | 67 | hx[3] = reduce(clsq128(hx[1])); // h^4 = h^2^2 |
| 68 | if (block_count >= agg_8_treshold) { | 68 | if (block_count >= agg_8_threshold) { |
| 69 | hx[4] = reduce(clmul128(hx[3], h)); // h^5 | 69 | hx[4] = reduce(clmul128(hx[3], h)); // h^5 |
| 70 | hx[5] = reduce(clsq128(hx[2])); // h^6 = h^3^2 | 70 | hx[5] = reduce(clsq128(hx[2])); // h^6 = h^3^2 |
| 71 | hx[6] = reduce(clmul128(hx[5], h)); // h^7 | 71 | hx[6] = reduce(clmul128(hx[5], h)); // h^7 |
| 72 | hx[7] = reduce(clsq128(hx[3])); // h^8 = h^4^2 | 72 | hx[7] = reduce(clsq128(hx[3])); // h^8 = h^4^2 |
| 73 | } | 73 | } |
| 74 | if (block_count >= agg_16_treshold) { | 74 | if (block_count >= agg_16_threshold) { |
| 75 | var i: usize = 8; | 75 | var i: usize = 8; |
| 76 | while (i < 16) : (i += 2) { | 76 | while (i < 16) : (i += 2) { |
| 77 | hx[i] = reduce(clmul128(hx[i - 1], h)); | 77 | hx[i] = reduce(clmul128(hx[i - 1], h)); |
| ... | @@ -263,7 +263,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { | ... | @@ -263,7 +263,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { |
| 263 | | 263 | |
| 264 | var i: usize = 0; | 264 | var i: usize = 0; |
| 265 | | 265 | |
| 266 | if (builtin.mode != .ReleaseSmall and msg.len >= agg_16_treshold * block_length) { | 266 | if (builtin.mode != .ReleaseSmall and msg.len >= agg_16_threshold * block_length) { |
| 267 | // 16-blocks aggregated reduction | 267 | // 16-blocks aggregated reduction |
| 268 | while (i + 256 <= msg.len) : (i += 256) { | 268 | while (i + 256 <= msg.len) : (i += 256) { |
| 269 | var u = clmul128(acc ^ mem.readInt(u128, msg[i..][0..16], endian), st.hx[15 - 0]); | 269 | var u = clmul128(acc ^ mem.readInt(u128, msg[i..][0..16], endian), st.hx[15 - 0]); |
| ... | @@ -273,7 +273,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { | ... | @@ -273,7 +273,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { |
| 273 | } | 273 | } |
| 274 | acc = reduce(u); | 274 | acc = reduce(u); |
| 275 | } | 275 | } |
| 276 | } else if (builtin.mode != .ReleaseSmall and msg.len >= agg_8_treshold * block_length) { | 276 | } else if (builtin.mode != .ReleaseSmall and msg.len >= agg_8_threshold * block_length) { |
| 277 | // 8-blocks aggregated reduction | 277 | // 8-blocks aggregated reduction |
| 278 | while (i + 128 <= msg.len) : (i += 128) { | 278 | while (i + 128 <= msg.len) : (i += 128) { |
| 279 | var u = clmul128(acc ^ mem.readInt(u128, msg[i..][0..16], endian), st.hx[7 - 0]); | 279 | var u = clmul128(acc ^ mem.readInt(u128, msg[i..][0..16], endian), st.hx[7 - 0]); |
| ... | @@ -283,7 +283,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { | ... | @@ -283,7 +283,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { |
| 283 | } | 283 | } |
| 284 | acc = reduce(u); | 284 | acc = reduce(u); |
| 285 | } | 285 | } |
| 286 | } else if (builtin.mode != .ReleaseSmall and msg.len >= agg_4_treshold * block_length) { | 286 | } else if (builtin.mode != .ReleaseSmall and msg.len >= agg_4_threshold * block_length) { |
| 287 | // 4-blocks aggregated reduction | 287 | // 4-blocks aggregated reduction |
| 288 | while (i + 64 <= msg.len) : (i += 64) { | 288 | while (i + 64 <= msg.len) : (i += 64) { |
| 289 | var u = clmul128(acc ^ mem.readInt(u128, msg[i..][0..16], endian), st.hx[3 - 0]); | 289 | var u = clmul128(acc ^ mem.readInt(u128, msg[i..][0..16], endian), st.hx[3 - 0]); |