xref: /dpdk/lib/hash/compare_signatures_generic.h (revision ef801b590990c440f52cc8d3707ae269f8386027)
10668f68bSYoan Picchi /* SPDX-License-Identifier: BSD-3-Clause
20668f68bSYoan Picchi  * Copyright(c) 2010-2016 Intel Corporation
30668f68bSYoan Picchi  * Copyright(c) 2018-2024 Arm Limited
40668f68bSYoan Picchi  */
50668f68bSYoan Picchi 
60668f68bSYoan Picchi #ifndef COMPARE_SIGNATURES_GENERIC_H
70668f68bSYoan Picchi #define COMPARE_SIGNATURES_GENERIC_H
80668f68bSYoan Picchi 
90668f68bSYoan Picchi #include <inttypes.h>
100668f68bSYoan Picchi 
110668f68bSYoan Picchi #include <rte_common.h>
120668f68bSYoan Picchi #include <rte_vect.h>
130668f68bSYoan Picchi 
140668f68bSYoan Picchi #include "rte_cuckoo_hash.h"
150668f68bSYoan Picchi 
16*ef801b59SYoan Picchi /*
17*ef801b59SYoan Picchi  * The generic version could use either a dense or sparsely packed hitmask buffer,
18*ef801b59SYoan Picchi  * but the dense one is slightly faster.
19*ef801b59SYoan Picchi  */
20*ef801b59SYoan Picchi #define DENSE_HASH_BULK_LOOKUP 1
21*ef801b59SYoan Picchi 
220668f68bSYoan Picchi static inline void
compare_signatures_dense(uint16_t * hitmask_buffer,const uint16_t * prim_bucket_sigs,const uint16_t * sec_bucket_sigs,uint16_t sig,__rte_unused enum rte_hash_sig_compare_function sig_cmp_fn)23*ef801b59SYoan Picchi compare_signatures_dense(uint16_t *hitmask_buffer,
24*ef801b59SYoan Picchi 			const uint16_t *prim_bucket_sigs,
25*ef801b59SYoan Picchi 			const uint16_t *sec_bucket_sigs,
260668f68bSYoan Picchi 			uint16_t sig,
270668f68bSYoan Picchi 			__rte_unused enum rte_hash_sig_compare_function sig_cmp_fn)
280668f68bSYoan Picchi {
29*ef801b59SYoan Picchi 	static_assert(sizeof(*hitmask_buffer) >= 2 * (RTE_HASH_BUCKET_ENTRIES / 8),
30*ef801b59SYoan Picchi 			"hitmask_buffer must be wide enough to fit a dense hitmask");
310668f68bSYoan Picchi 
32*ef801b59SYoan Picchi 	/* For match mask every bits indicates the match */
33*ef801b59SYoan Picchi 	for (unsigned int i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
34*ef801b59SYoan Picchi 		*hitmask_buffer |= (sig == prim_bucket_sigs[i]) << i;
35*ef801b59SYoan Picchi 		*hitmask_buffer |= ((sig == sec_bucket_sigs[i]) << i) << RTE_HASH_BUCKET_ENTRIES;
360668f68bSYoan Picchi 	}
370668f68bSYoan Picchi }
380668f68bSYoan Picchi #endif /* COMPARE_SIGNATURES_GENERIC_H */
39