From 7fe357b8c0507c305c4382b39718b621758dd45f Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Wed, 15 Apr 2015 17:44:52 +0200 Subject: [PATCH] split 64-mult hashing into two 32-bit multiplies Speed-wise equivalent on x86 and ARM (maybe a tad faster, hard to tell). Note that the two 32-bit multiples are not strictly equivalent to the 64-bit one, since we're missing one carry propagation. In practice, no observable difference was seen because of this slightly different hashing result. Change-Id: I8f2381175eae1cb20dabf149e6b27e1768fba6ab --- src/enc/backward_references.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/enc/backward_references.c b/src/enc/backward_references.c index ea838a5c..aa484250 100644 --- a/src/enc/backward_references.c +++ b/src/enc/backward_references.c @@ -21,8 +21,6 @@ #define VALUES_IN_BYTE 256 -#define HASH_MULTIPLIER (0xc6a4a7935bd1e995ULL) - #define MIN_BLOCK_SIZE 256 // minimum block size for backward references #define MAX_ENTROPY (1e30f) @@ -215,9 +213,14 @@ void VP8LHashChainClear(VP8LHashChain* const p) { // ----------------------------------------------------------------------------- +#define HASH_MULTIPLIER_HI (0xc6a4a793U) +#define HASH_MULTIPLIER_LO (0x5bd1e996U) + static WEBP_INLINE uint64_t GetPixPairHash64(const uint32_t* const argb) { - uint64_t key = ((uint64_t)argb[1] << 32) | argb[0]; - key = (key * HASH_MULTIPLIER) >> (64 - HASH_BITS); + uint32_t key; + key = argb[1] * HASH_MULTIPLIER_HI; + key += argb[0] * HASH_MULTIPLIER_LO; + key = key >> (32 - HASH_BITS); return key; }