aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/mac/siphash/siphash.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-10-11 17:02:20 -0400
committerJack Lloyd <[email protected]>2017-10-12 11:13:11 -0400
commit175f09ffd806f2f19cd509017a67ae1384f29ae1 (patch)
tree6194884467e4720dd79797cd106a45d60211f35f /src/lib/mac/siphash/siphash.cpp
parent40b3f979723b2b3dfb5c44047d7f786a73fd7f6f (diff)
Add compile-time rotation functions
The problem with asm rol/ror is the compiler can't schedule effectively. But we only need asm in the case when the rotation is variable, so distinguish the two cases. If a compile time constant, then static_assert that the rotation is in the correct range and do the straightforward expression knowing the compiler will probably do the right thing. Otherwise do a tricky expression that both GCC and Clang happen to have recognize. Avoid the reduction case; instead require that the rotation be in range (this reverts 2b37c13dcf). Remove the asm rotations (making this branch illnamed), because now both Clang and GCC will create a roll without any extra help. Remove the reduction/mask by the word size for the variable case. The compiler can't optimize that it out well, but it's easy to ensure it is valid in the callers, especially now that the variable input cases are easy to grep for.
Diffstat (limited to 'src/lib/mac/siphash/siphash.cpp')
-rw-r--r--src/lib/mac/siphash/siphash.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/lib/mac/siphash/siphash.cpp b/src/lib/mac/siphash/siphash.cpp
index 54adcd5a5..255a35493 100644
--- a/src/lib/mac/siphash/siphash.cpp
+++ b/src/lib/mac/siphash/siphash.cpp
@@ -19,16 +19,16 @@ void SipRounds(uint64_t M, secure_vector<uint64_t>& V, size_t r)
for(size_t i = 0; i != r; ++i)
{
V0 += V1; V2 += V3;
- V1 = rotate_left(V1, 13);
- V3 = rotate_left(V3, 16);
+ V1 = rotl<13>(V1);
+ V3 = rotl<16>(V3);
V1 ^= V0; V3 ^= V2;
- V0 = rotate_left(V0, 32);
+ V0 = rotl<32>(V0);
V2 += V1; V0 += V3;
- V1 = rotate_left(V1, 17);
- V3 = rotate_left(V3, 21);
+ V1 = rotl<17>(V1);
+ V3 = rotl<21>(V3);
V1 ^= V2; V3 ^= V0;
- V2 = rotate_left(V2, 32);
+ V2 = rotl<32>(V2);
}
V0 ^= M;