xref: /f-stack/dpdk/lib/librte_efd/rte_efd_arm64.h (revision 031be553)
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium, Inc. 2017.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium, Inc nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*
34  * rte_efd_arm64.h
35  * This file holds all arm64 specific EFD functions
36  */
37 
38 #ifndef __RTE_EFD_ARM64_H__
39 #define __RTE_EFD_ARM64_H__
40 
41 #include <rte_vect.h>
42 
43 static inline efd_value_t
44 efd_lookup_internal_neon(const efd_hashfunc_t *group_hash_idx,
45 		const efd_lookuptbl_t *group_lookup_table,
46 		const uint32_t hash_val_a, const uint32_t hash_val_b)
47 {
48 	efd_value_t value = 0;
49 	uint32_t i = 0;
50 	uint32x4_t vhash_val_a = vmovq_n_u32(hash_val_a);
51 	uint32x4_t vhash_val_b = vmovq_n_u32(hash_val_b);
52 	int32x4_t vshift = {0, 1, 2, 3};
53 	uint32x4_t vmask = vdupq_n_u32(0x1);
54 	int32x4_t vincr = vdupq_n_s32(4);
55 
56 	for (; i < RTE_EFD_VALUE_NUM_BITS; i += 4) {
57 		uint32x4_t vhash_idx = vshll_n_u16(
58 			vld1_u16((uint16_t const *)&group_hash_idx[i]), 0);
59 		uint32x4_t vlookup_table = vshll_n_u16(
60 			vld1_u16((uint16_t const *)&group_lookup_table[i]), 0);
61 		uint32x4_t vhash = vaddq_u32(vhash_val_a,
62 					vmulq_u32(vhash_idx, vhash_val_b));
63 		int32x4_t vbucket_idx = vnegq_s32(vreinterpretq_s32_u32(
64 				vshrq_n_u32(vhash, EFD_LOOKUPTBL_SHIFT)));
65 		uint32x4_t vresult = vshlq_u32(vlookup_table, vbucket_idx);
66 
67 		vresult = vandq_u32(vresult, vmask);
68 		vresult = vshlq_u32(vresult, vshift);
69 		value |= vaddvq_u32(vresult);
70 		vshift = vaddq_s32(vshift, vincr);
71 	}
72 
73 	return value;
74 }
75 
76 #endif /* __RTE_EFD_ARM64_H__ */
77