doc: fill nics features matrix for cxgbe
[dpdk.git] / lib / librte_hash / rte_cuckoo_hash.c
index f797aeb..71b5b76 100644 (file)
 #include "rte_cmp_x86.h"
 #endif
 
+#if defined(RTE_ARCH_ARM64)
+#include "rte_cmp_arm64.h"
+#endif
+
 TAILQ_HEAD(rte_hash_list, rte_tailq_entry);
 
 static struct rte_tailq_elem rte_hash_tailq = {
@@ -81,7 +85,7 @@ EAL_REGISTER_TAILQ(rte_hash_tailq)
 #endif
 
 /* Hash function used if none is specified */
-#ifdef RTE_MACHINE_CPUFLAG_SSE4_2
+#if defined(RTE_MACHINE_CPUFLAG_SSE4_2) || defined(RTE_MACHINE_CPUFLAG_CRC32)
 #include <rte_hash_crc.h>
 #define DEFAULT_HASH_FUNC       rte_hash_crc
 #else
@@ -98,8 +102,6 @@ EAL_REGISTER_TAILQ(rte_hash_tailq)
 
 #define LCORE_CACHE_SIZE               8
 
-typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2, size_t key_len);
-
 struct lcore_cache {
        unsigned len; /**< Cache len */
        void *objs[LCORE_CACHE_SIZE]; /**< Cache objects */
@@ -183,6 +185,11 @@ rte_hash_find_existing(const char *name)
        return h;
 }
 
+void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t func)
+{
+       h->rte_hash_cmp_eq = func;
+}
+
 struct rte_hash *
 rte_hash_create(const struct rte_hash_parameters *params)
 {
@@ -280,7 +287,8 @@ rte_hash_create(const struct rte_hash_parameters *params)
  * If x86 architecture is used, select appropriate compare function,
  * which may use x86 instrinsics, otherwise use memcmp
  */
-#if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_I686) || defined(RTE_ARCH_X86_X32)
+#if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_I686) ||\
+        defined(RTE_ARCH_X86_X32) || defined(RTE_ARCH_ARM64)
        /* Select function to compare keys */
        switch (params->key_len) {
        case 16:
@@ -417,7 +425,7 @@ rte_hash_secondary_hash(const hash_sig_t primary_hash)
 
        uint32_t tag = primary_hash >> all_bits_shift;
 
-       return (primary_hash ^ ((tag + 1) * alt_bits_xor));
+       return primary_hash ^ ((tag + 1) * alt_bits_xor);
 }
 
 void
@@ -595,7 +603,7 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key,
                                 * Return index where key is stored,
                                 * substracting the first dummy index
                                 */
-                               return (prim_bkt->key_idx[i] - 1);
+                               return prim_bkt->key_idx[i] - 1;
                        }
                }
        }
@@ -615,7 +623,7 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key,
                                 * Return index where key is stored,
                                 * substracting the first dummy index
                                 */
-                               return (sec_bkt->key_idx[i] - 1);
+                               return sec_bkt->key_idx[i] - 1;
                        }
                }
        }
@@ -647,7 +655,7 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key,
                prim_bkt->signatures[ret].current = sig;
                prim_bkt->signatures[ret].alt = alt_hash;
                prim_bkt->key_idx[ret] = new_idx;
-               return (new_idx - 1);
+               return new_idx - 1;
        }
 
        /* Error in addition, store new slot back in the ring and return error */
@@ -724,7 +732,7 @@ __rte_hash_lookup_with_hash(const struct rte_hash *h, const void *key,
                                 * Return index where key is stored,
                                 * substracting the first dummy index
                                 */
-                               return (bkt->key_idx[i] - 1);
+                               return bkt->key_idx[i] - 1;
                        }
                }
        }
@@ -747,7 +755,7 @@ __rte_hash_lookup_with_hash(const struct rte_hash *h, const void *key,
                                 * Return index where key is stored,
                                 * substracting the first dummy index
                                 */
-                               return (bkt->key_idx[i] - 1);
+                               return bkt->key_idx[i] - 1;
                        }
                }
        }
@@ -839,7 +847,7 @@ __rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key,
                                 * Return index where key is stored,
                                 * substracting the first dummy index
                                 */
-                               return (bkt->key_idx[i] - 1);
+                               return bkt->key_idx[i] - 1;
                        }
                }
        }
@@ -862,7 +870,7 @@ __rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key,
                                 * Return index where key is stored,
                                 * substracting the first dummy index
                                 */
-                               return (bkt->key_idx[i] - 1);
+                               return bkt->key_idx[i] - 1;
                        }
                }
        }
@@ -966,15 +974,22 @@ lookup_stage2(unsigned idx, hash_sig_t prim_hash, hash_sig_t sec_hash,
 /* Lookup bulk stage 3: Check if key matches, update hit mask and return data */
 static inline void
 lookup_stage3(unsigned idx, const struct rte_hash_key *key_slot, const void * const *keys,
-               void *data[], uint64_t *hits, const struct rte_hash *h)
+               const int32_t *positions, void *data[], uint64_t *hits,
+               const struct rte_hash *h)
 {
        unsigned hit;
+       unsigned key_idx;
 
        hit = !h->rte_hash_cmp_eq(key_slot->key, keys[idx], h->key_len);
        if (data != NULL)
                data[idx] = key_slot->pdata;
 
-       *hits |= (uint64_t)(hit) << idx;
+       key_idx = positions[idx] + 1;
+       /*
+        * If key index is 0, force hit to be 0, in case key to be looked up
+        * is all zero (as in the dummy slot), which would result in a wrong hit
+        */
+       *hits |= (uint64_t)(hit && !!key_idx)  << idx;
 }
 
 static inline void
@@ -1066,8 +1081,8 @@ __rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys,
                lookup_stage2(idx21, primary_hash21, secondary_hash21,
                        primary_bkt21, secondary_bkt21, &k_slot21, positions,
                        &extra_hits_mask, key_store, h);
-               lookup_stage3(idx30, k_slot30, keys, data, &hits, h);
-               lookup_stage3(idx31, k_slot31, keys, data, &hits, h);
+               lookup_stage3(idx30, k_slot30, keys, positions, data, &hits, h);
+               lookup_stage3(idx31, k_slot31, keys, positions, data, &hits, h);
        }
 
        k_slot30 = k_slot20, k_slot31 = k_slot21;
@@ -1093,8 +1108,8 @@ __rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys,
        lookup_stage2(idx21, primary_hash21, secondary_hash21, primary_bkt21,
                secondary_bkt21, &k_slot21, positions, &extra_hits_mask,
                key_store, h);
-       lookup_stage3(idx30, k_slot30, keys, data, &hits, h);
-       lookup_stage3(idx31, k_slot31, keys, data, &hits, h);
+       lookup_stage3(idx30, k_slot30, keys, positions, data, &hits, h);
+       lookup_stage3(idx31, k_slot31, keys, positions, data, &hits, h);
 
        k_slot30 = k_slot20, k_slot31 = k_slot21;
        idx30 = idx20, idx31 = idx21;
@@ -1114,14 +1129,14 @@ __rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys,
        lookup_stage2(idx21, primary_hash21, secondary_hash21, primary_bkt21,
                secondary_bkt21, &k_slot21, positions, &extra_hits_mask,
                key_store, h);
-       lookup_stage3(idx30, k_slot30, keys, data, &hits, h);
-       lookup_stage3(idx31, k_slot31, keys, data, &hits, h);
+       lookup_stage3(idx30, k_slot30, keys, positions, data, &hits, h);
+       lookup_stage3(idx31, k_slot31, keys, positions, data, &hits, h);
 
        k_slot30 = k_slot20, k_slot31 = k_slot21;
        idx30 = idx20, idx31 = idx21;
 
-       lookup_stage3(idx30, k_slot30, keys, data, &hits, h);
-       lookup_stage3(idx31, k_slot31, keys, data, &hits, h);
+       lookup_stage3(idx30, k_slot30, keys, positions, data, &hits, h);
+       lookup_stage3(idx31, k_slot31, keys, positions, data, &hits, h);
 
        /* ignore any items we have already found */
        extra_hits_mask &= ~hits;
@@ -1224,5 +1239,5 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32
        /* Increment iterator */
        (*next)++;
 
-       return (position - 1);
+       return position - 1;
 }