Skip to content

Commit 645e9f2

Browse files
committed
Optimize SipHash by reordering compress instructions
1 parent 2a65e9f commit 645e9f2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

core/src/hash/sip.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,19 @@ macro_rules! compress {
7676
($state:expr) => {{ compress!($state.v0, $state.v1, $state.v2, $state.v3) }};
7777
($v0:expr, $v1:expr, $v2:expr, $v3:expr) => {{
7878
$v0 = $v0.wrapping_add($v1);
79+
$v2 = $v2.wrapping_add($v3);
7980
$v1 = $v1.rotate_left(13);
8081
$v1 ^= $v0;
81-
$v0 = $v0.rotate_left(32);
82-
$v2 = $v2.wrapping_add($v3);
8382
$v3 = $v3.rotate_left(16);
8483
$v3 ^= $v2;
85-
$v0 = $v0.wrapping_add($v3);
86-
$v3 = $v3.rotate_left(21);
87-
$v3 ^= $v0;
84+
$v0 = $v0.rotate_left(32);
85+
8886
$v2 = $v2.wrapping_add($v1);
87+
$v0 = $v0.wrapping_add($v3);
8988
$v1 = $v1.rotate_left(17);
9089
$v1 ^= $v2;
90+
$v3 = $v3.rotate_left(21);
91+
$v3 ^= $v0;
9192
$v2 = $v2.rotate_left(32);
9293
}};
9394
}

0 commit comments

Comments
 (0)