hash: jhash optimisation
authorIntel <intel.com>
Mon, 3 Jun 2013 00:00:00 +0000 (00:00 +0000)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Tue, 17 Sep 2013 12:09:22 +0000 (14:09 +0200)
Signed-off-by: Intel
lib/librte_hash/rte_jhash.h

index 356e0e4..a49c8ca 100644 (file)
@@ -97,24 +97,22 @@ static inline uint32_t
 rte_jhash(const void *key, uint32_t length, uint32_t initval)
 {
        uint32_t a, b, c, len;
-       const uint8_t *k = (const uint8_t *) key;
+       const uint8_t *k = (const uint8_t *)key;
+       const uint32_t *k32 = (const uint32_t *)key;
 
        len = length;
        a = b = RTE_JHASH_GOLDEN_RATIO;
        c = initval;
 
        while (len >= 12) {
-               a += (k[0] + ((uint32_t)k[1] << 8) + ((uint32_t)k[2] << 16) +
-                     ((uint32_t)k[3] << 24));
-               b += (k[4] + ((uint32_t)k[5] << 8) + ((uint32_t)k[6] << 16) +
-                     ((uint32_t)k[7] << 24));
-               c += (k[8] + ((uint32_t)k[9] << 8) + ((uint32_t)k[10] << 16) +
-                     ((uint32_t)k[11] << 24));
+               a += k32[0];
+               b += k32[1];
+               c += k32[2];
 
                __rte_jhash_mix(a,b,c);
 
-               k += 12;
-               len -= 12;
+               k += (3 * sizeof(uint32_t)), k32 += 3;
+               len -= (3 * sizeof(uint32_t));
        }
 
        c += length;