xref: /dpdk/lib/hash/compare_signatures_x86.h (revision ef801b590990c440f52cc8d3707ae269f8386027)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation
3  * Copyright(c) 2018-2024 Arm Limited
4  */
5 
6 #ifndef COMPARE_SIGNATURES_X86_H
7 #define COMPARE_SIGNATURES_X86_H
8 
9 #include <inttypes.h>
10 
11 #include <rte_common.h>
12 #include <rte_vect.h>
13 
14 #include "rte_cuckoo_hash.h"
15 
16 /* x86's version uses a sparsely packed hitmask buffer: every other bit is padding. */
17 #define DENSE_HASH_BULK_LOOKUP 0
18 
19 static inline void
compare_signatures_sparse(uint32_t * prim_hash_matches,uint32_t * sec_hash_matches,const struct rte_hash_bucket * prim_bkt,const struct rte_hash_bucket * sec_bkt,uint16_t sig,enum rte_hash_sig_compare_function sig_cmp_fn)20 compare_signatures_sparse(uint32_t *prim_hash_matches, uint32_t *sec_hash_matches,
21 			const struct rte_hash_bucket *prim_bkt,
22 			const struct rte_hash_bucket *sec_bkt,
23 			uint16_t sig,
24 			enum rte_hash_sig_compare_function sig_cmp_fn)
25 {
26 	unsigned int i;
27 
28 	/* For match mask the first bit of every two bits indicates the match */
29 	switch (sig_cmp_fn) {
30 #if defined(__SSE2__) && RTE_HASH_BUCKET_ENTRIES <= 8
31 	case RTE_HASH_COMPARE_SSE:
32 		/* Compare all signatures in the bucket */
33 		*prim_hash_matches = _mm_movemask_epi8(_mm_cmpeq_epi16(_mm_load_si128(
34 			(__m128i const *)prim_bkt->sig_current), _mm_set1_epi16(sig)));
35 		/* Extract the even-index bits only */
36 		*prim_hash_matches &= 0x5555;
37 		/* Compare all signatures in the bucket */
38 		*sec_hash_matches = _mm_movemask_epi8(_mm_cmpeq_epi16(_mm_load_si128(
39 			(__m128i const *)sec_bkt->sig_current), _mm_set1_epi16(sig)));
40 		/* Extract the even-index bits only */
41 		*sec_hash_matches &= 0x5555;
42 		break;
43 #endif
44 	default:
45 		for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
46 			*prim_hash_matches |= (sig == prim_bkt->sig_current[i]) << (i << 1);
47 			*sec_hash_matches |= (sig == sec_bkt->sig_current[i]) << (i << 1);
48 		}
49 	}
50 }
51 #endif /* COMPARE_SIGNATURES_X86_H */
52