xref: /dpdk/lib/hash/rte_cmp_arm64.h (revision 1d69e219255da29b48d87e824e3b3c8108c5ab7a)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015 Cavium, Inc
3  */
4 
5 /* Functions to compare multiple of 16 byte keys (up to 128 bytes) */
6 static inline int
rte_hash_k16_cmp_eq(const void * key1,const void * key2,size_t key_len __rte_unused)7 rte_hash_k16_cmp_eq(const void *key1, const void *key2,
8 		    size_t key_len __rte_unused)
9 {
10 	uint64_t x0, x1, y0, y1;
11 
12 	asm volatile(
13 		"ldp %x[x1], %x[x0], [%x[p1]]"
14 		: [x1]"=r"(x1), [x0]"=r"(x0)
15 		: [p1]"r"(key1)
16 		);
17 	asm volatile(
18 		"ldp %x[y1], %x[y0], [%x[p2]]"
19 		: [y1]"=r"(y1), [y0]"=r"(y0)
20 		: [p2]"r"(key2)
21 		);
22 	x0 ^= y0;
23 	x1 ^= y1;
24 	return !(x0 == 0 && x1 == 0);
25 }
26 
27 static inline int
rte_hash_k32_cmp_eq(const void * key1,const void * key2,size_t key_len)28 rte_hash_k32_cmp_eq(const void *key1, const void *key2, size_t key_len)
29 {
30 	return rte_hash_k16_cmp_eq(key1, key2, key_len) ||
31 		rte_hash_k16_cmp_eq((const char *) key1 + 16,
32 				(const char *) key2 + 16, key_len);
33 }
34 
35 static inline int
rte_hash_k48_cmp_eq(const void * key1,const void * key2,size_t key_len)36 rte_hash_k48_cmp_eq(const void *key1, const void *key2, size_t key_len)
37 {
38 	return rte_hash_k16_cmp_eq(key1, key2, key_len) ||
39 		rte_hash_k16_cmp_eq((const char *) key1 + 16,
40 				(const char *) key2 + 16, key_len) ||
41 		rte_hash_k16_cmp_eq((const char *) key1 + 32,
42 				(const char *) key2 + 32, key_len);
43 }
44 
45 static inline int
rte_hash_k64_cmp_eq(const void * key1,const void * key2,size_t key_len)46 rte_hash_k64_cmp_eq(const void *key1, const void *key2, size_t key_len)
47 {
48 	return rte_hash_k32_cmp_eq(key1, key2, key_len) ||
49 		rte_hash_k32_cmp_eq((const char *) key1 + 32,
50 				(const char *) key2 + 32, key_len);
51 }
52 
53 static inline int
rte_hash_k80_cmp_eq(const void * key1,const void * key2,size_t key_len)54 rte_hash_k80_cmp_eq(const void *key1, const void *key2, size_t key_len)
55 {
56 	return rte_hash_k64_cmp_eq(key1, key2, key_len) ||
57 		rte_hash_k16_cmp_eq((const char *) key1 + 64,
58 				(const char *) key2 + 64, key_len);
59 }
60 
61 static inline int
rte_hash_k96_cmp_eq(const void * key1,const void * key2,size_t key_len)62 rte_hash_k96_cmp_eq(const void *key1, const void *key2, size_t key_len)
63 {
64 	return rte_hash_k64_cmp_eq(key1, key2, key_len) ||
65 		rte_hash_k32_cmp_eq((const char *) key1 + 64,
66 				(const char *) key2 + 64, key_len);
67 }
68 
69 static inline int
rte_hash_k112_cmp_eq(const void * key1,const void * key2,size_t key_len)70 rte_hash_k112_cmp_eq(const void *key1, const void *key2, size_t key_len)
71 {
72 	return rte_hash_k64_cmp_eq(key1, key2, key_len) ||
73 		rte_hash_k32_cmp_eq((const char *) key1 + 64,
74 				(const char *) key2 + 64, key_len) ||
75 		rte_hash_k16_cmp_eq((const char *) key1 + 96,
76 				(const char *) key2 + 96, key_len);
77 }
78 
79 static inline int
rte_hash_k128_cmp_eq(const void * key1,const void * key2,size_t key_len)80 rte_hash_k128_cmp_eq(const void *key1, const void *key2, size_t key_len)
81 {
82 	return rte_hash_k64_cmp_eq(key1, key2, key_len) ||
83 		rte_hash_k64_cmp_eq((const char *) key1 + 64,
84 				(const char *) key2 + 64, key_len);
85 }
86