From c8f3fb514c8e9817e5e64d9d3d4295349620dbb8 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 30 Sep 2019 22:36:07 -0700 Subject: [PATCH] factorized mix32B changing xxh128 results for len within 129-240. --- xxh3.h | 56 +++++++++++++++++++++----------------------------------- xxhsum.c | 8 ++++---- 2 files changed, 25 insertions(+), 39 deletions(-) diff --git a/xxh3.h b/xxh3.h index 8ea82b9..4fe0f94 100644 --- a/xxh3.h +++ b/xxh3.h @@ -1401,6 +1401,17 @@ XXH3_hashLong_128b_withSeed(const void* data, size_t len, XXH64_hash_t seed) return XXH3_hashLong_128b_internal(data, len, secret, sizeof(secret)); } + +XXH_FORCE_INLINE XXH128_hash_t +XXH128_mix32B(XXH128_hash_t acc, const BYTE* p1, const BYTE* p2, const char* secret, XXH64_hash_t seed) +{ + acc.low64 += XXH3_mix16B (p1, secret+0, seed); + acc.low64 ^= XXH_readLE64(p2) + XXH_readLE64(p2+8); + acc.high64 += XXH3_mix16B (p2, secret+16, seed); + acc.high64 ^= XXH_readLE64(p1) + XXH_readLE64(p1+8); + return acc; +} + XXH_NO_INLINE XXH128_hash_t XXH3_len_129to240_128b(const void* XXH_RESTRICT data, size_t len, const void* XXH_RESTRICT secret, size_t secretSize, @@ -1412,33 +1423,25 @@ XXH3_len_129to240_128b(const void* XXH_RESTRICT data, size_t len, XXH_ASSERT(secretSize >= XXH3_SECRET_SIZE_MIN); (void)secretSize; XXH_ASSERT(128 < len && len <= XXH3_MIDSIZE_MAX); - { U64 acc1 = len * PRIME64_1; - U64 acc2 = 0; + { XXH128_hash_t acc; int const nbRounds = (int)len / 32; int i; + acc.low64 = len * PRIME64_1; + acc.high64 = 0; for (i=0; i<4; i++) { - acc1 += XXH3_mix16B (p+(32*i), key+(32*i), seed); - acc1 ^= XXH_readLE64(p+(32*i)+16) + XXH_readLE64(p+(32*i)+24); - acc2 += XXH3_mix16B (p+(32*i)+16, key+(32*i)+16, 0ULL-seed); - acc2 ^= XXH_readLE64(p+(32*i)) + XXH_readLE64(p+(32*i)+8); + acc = XXH128_mix32B(acc, p+(32*i), p+(32*i)+16, key+(32*i), seed); } - acc1 = XXH3_avalanche(acc1); - acc2 = XXH3_avalanche(acc2); + acc.low64 = XXH3_avalanche(acc.low64); + acc.high64 = XXH3_avalanche(acc.high64); XXH_ASSERT(nbRounds >= 4); for (i=4 ; i < nbRounds; i++) { - acc1 += XXH3_mix16B (p+(32*i) , key+(32*(i-4)) + XXH3_MIDSIZE_STARTOFFSET, seed); - acc1 ^= XXH_readLE64(p+(32*i)+16) + XXH_readLE64(p+(32*i)+24); - acc2 += XXH3_mix16B (p+(32*i)+16, key+(32*(i-4))+16 + XXH3_MIDSIZE_STARTOFFSET, 0ULL-seed); - acc2 ^= XXH_readLE64(p+(32*i)) + XXH_readLE64(p+(32*i)+8); + acc = XXH128_mix32B(acc, p+(32*i), p+(32*i)+16, key+XXH3_MIDSIZE_STARTOFFSET+(32*(i-4)), seed); } /* last bytes */ - acc1 += XXH3_mix16B (p + len - 16, key + XXH3_SECRET_SIZE_MIN - XXH3_MIDSIZE_LASTOFFSET , seed); - acc1 ^= XXH_readLE64(p+len-32) + XXH_readLE64(p+len-24); - acc2 += XXH3_mix16B (p + len - 32, key + XXH3_SECRET_SIZE_MIN - XXH3_MIDSIZE_LASTOFFSET - 16, 0ULL-seed); - acc2 ^= XXH_readLE64(p+len-16) + XXH_readLE64(p+len-8); + acc = XXH128_mix32B(acc, p + len - 16, p + len - 32, key + XXH3_SECRET_SIZE_MIN - XXH3_MIDSIZE_LASTOFFSET - 16, 0ULL - seed); - { U64 const low64 = acc1 + acc2; - U64 const high64 = (acc1 * PRIME64_1) + (acc2 * PRIME64_4) + ((len - seed) * PRIME64_2); + { U64 const low64 = acc.low64 + acc.high64; + U64 const high64 = (acc.low64 * PRIME64_1) + (acc.high64 * PRIME64_4) + ((len - seed) * PRIME64_2); XXH128_hash_t const h128 = { XXH3_avalanche(low64), (XXH64_hash_t)0 - XXH3_avalanche(high64) }; return h128; } @@ -1446,16 +1449,6 @@ XXH3_len_129to240_128b(const void* XXH_RESTRICT data, size_t len, } -XXH_FORCE_INLINE XXH128_hash_t -XXH128_mix32B(XXH128_hash_t acc, const BYTE* p1, const BYTE* p2, const char* secret, XXH64_hash_t seed) -{ - acc.low64 += XXH3_mix16B (p1, secret+0, seed); - acc.low64 ^= XXH_readLE64(p2) + XXH_readLE64(p2+8); - acc.high64 += XXH3_mix16B (p2, secret+16, seed); - acc.high64 ^= XXH_readLE64(p1) + XXH_readLE64(p1+8); - return acc; -} - XXH_FORCE_INLINE XXH128_hash_t XXH3_len_17to128_128b(const void* XXH_RESTRICT data, size_t len, const void* XXH_RESTRICT secret, size_t secretSize, @@ -1473,14 +1466,7 @@ XXH3_len_17to128_128b(const void* XXH_RESTRICT data, size_t len, if (len > 32) { if (len > 64) { if (len > 96) { -#if 0 - acc.low64 += XXH3_mix16B(p+48, key+96, seed); - acc.low64 ^= XXH_readLE64(p+len-64) + XXH_readLE64(p+len-56); - acc.high64 += XXH3_mix16B(p+len-64, key+112, seed); - acc.high64 ^= XXH_readLE64(p+48) + XXH_readLE64(p+56); -#else acc = XXH128_mix32B(acc, p+48, p+len-64, key+96, seed); -#endif } acc = XXH128_mix32B(acc, p+32, p+len-48, key+64, seed); } diff --git a/xxhsum.c b/xxhsum.c index b831cf8..386497b 100644 --- a/xxhsum.c +++ b/xxhsum.c @@ -844,16 +844,16 @@ static void BMK_sanityCheck(void) { XXH128_hash_t const expected = { 0x784D8A364F48D048ULL, 0x9010B884DAA01151ULL }; BMK_testXXH128(sanityBuffer, 103, prime, expected); /* 97-128 */ } - { XXH128_hash_t const expected = { 0x44D1C25FE64177F0ULL, 0xFAD36798F8CFF331ULL }; + { XXH128_hash_t const expected = { 0x5FA77B9DFE8B5CAEULL, 0x2834B37CEC6A753FULL }; BMK_testXXH128(sanityBuffer, 192, 0, expected); /* 129-240 */ } - { XXH128_hash_t const expected = { 0x6EA8E25C1908B2F1ULL, 0x0FE029DC274DEF34ULL }; + { XXH128_hash_t const expected = { 0x75441CE0359A979AULL, 0x399E2847427B3904ULL }; BMK_testXXH128(sanityBuffer, 192, prime, expected); /* 129-240 */ } - { XXH128_hash_t const expected = { 0xB944359DBAAE26FBULL, 0x5FA52A65D423092AULL }; + { XXH128_hash_t const expected = { 0xB02CC10BCFE61194ULL, 0xA27C9ABC8C06E4DDULL }; BMK_testXXH128(sanityBuffer, 222, 0, expected); /* 129-240 */ } - { XXH128_hash_t const expected = { 0x9FC2FB64EE8EE116ULL, 0xFE82C0903701C6F5ULL }; + { XXH128_hash_t const expected = { 0x972CB9C6BD8123EDULL, 0x3488C87B4B6FCE5FULL }; BMK_testXXH128(sanityBuffer, 222, prime, expected); /* 129-240 */ } { XXH128_hash_t const expected = { 0xB0C48E6D18E9D084ULL, 0xB16FC17E992FF45DULL };