Skip to content

Commit

Permalink
xxh3: keys are xored, instead of added
Browse files Browse the repository at this point in the history
In UMAC, keys are added, instead of xored.
According to its authors, that's because adds are 10% faster on their target platform
(a Pentium IV, this was early 2000).

In measurements with SSE/AVX, it makes no difference today.

However, additions make it possible to reason about delta between fields,
meaning it's easier to engineer a collision just knowing these deltas.
Xoring instead messes that up.
Since it's performance free, let's to that.
  • Loading branch information
Cyan4973 committed Mar 18, 2019
1 parent 155f560 commit cd3ab01
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions xxh3.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ XXH3_accumulate_512(void* acc, const void *restrict data, const void *restrict k
for (i=0; i < STRIPE_LEN/sizeof(__m256i); i++) {
__m256i const d = _mm256_loadu_si256 (xdata+i);
__m256i const k = _mm256_loadu_si256 (xkey+i);
__m256i const dk = _mm256_add_epi32 (d,k); /* uint32 dk[8] = {d0+k0, d1+k1, d2+k2, d3+k3, ...} */
__m256i const dk = _mm256_xor_si256 (d,k); /* uint32 dk[8] = {d0+k0, d1+k1, d2+k2, d3+k3, ...} */
__m256i const res = _mm256_mul_epu32 (dk, _mm256_shuffle_epi32 (dk, 0x31)); /* uint64 res[4] = {dk0*dk1, dk2*dk3, ...} */
__m256i const add = _mm256_add_epi64(d, xacc[i]);
xacc[i] = _mm256_add_epi64(res, add);
Expand All @@ -391,14 +391,14 @@ XXH3_accumulate_512(void* acc, const void *restrict data, const void *restrict k
for (i=0; i < STRIPE_LEN/sizeof(__m128i); i++) {
__m128i const d = _mm_loadu_si128 (xdata+i);
__m128i const k = _mm_loadu_si128 (xkey+i);
__m128i const dk = _mm_add_epi32 (d,k); /* uint32 dk[4] = {d0+k0, d1+k1, d2+k2, d3+k3} */
__m128i const dk = _mm_xor_si128 (d,k); /* uint32 dk[4] = {d0+k0, d1+k1, d2+k2, d3+k3} */
__m128i const res = _mm_mul_epu32 (dk, _mm_shuffle_epi32 (dk, 0x31)); /* uint64 res[2] = {dk0*dk1,dk2*dk3} */
__m128i const add = _mm_add_epi64(d, xacc[i]);
xacc[i] = _mm_add_epi64(res, add);
}
}

#elif (XXH_VECTOR == XXH_NEON) /* to be updated, no longer in sync */
#elif (XXH_VECTOR == XXH_NEON) /* to be updated, no longer with latest sse/avx updates */

assert(((size_t)acc) & 15 == 0);
{ uint64x2_t* const xacc = (uint64x2_t *)acc;
Expand Down Expand Up @@ -447,7 +447,7 @@ XXH3_accumulate_512(void* acc, const void *restrict data, const void *restrict k
int const right= 2*i + 1;
U32 const dataLeft = XXH_readLE32(xdata + left);
U32 const dataRight = XXH_readLE32(xdata + right);
xacc[i] += XXH_mult32to64(dataLeft + xkey[left], dataRight + xkey[right]);
xacc[i] += XXH_mult32to64(dataLeft ^ xkey[left], dataRight ^ xkey[right]);
xacc[i] += dataLeft + ((U64)dataRight << 32);
}

Expand Down

0 comments on commit cd3ab01

Please sign in to comment.