xref: /f-stack/dpdk/lib/librte_efd/rte_efd_x86.h (revision 031be553)
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /* rte_efd_x86.h
35  * This file holds all x86 specific EFD functions
36  */
37 #include <immintrin.h>
38 
39 #if (RTE_EFD_VALUE_NUM_BITS == 8 || RTE_EFD_VALUE_NUM_BITS == 16 || \
40 	RTE_EFD_VALUE_NUM_BITS == 24 || RTE_EFD_VALUE_NUM_BITS == 32)
41 #define EFD_LOAD_SI128(val) _mm_load_si128(val)
42 #else
43 #define EFD_LOAD_SI128(val) _mm_lddqu_si128(val)
44 #endif
45 
46 static inline efd_value_t
47 efd_lookup_internal_avx2(const efd_hashfunc_t *group_hash_idx,
48 		const efd_lookuptbl_t *group_lookup_table,
49 		const uint32_t hash_val_a, const uint32_t hash_val_b)
50 {
51 #ifdef RTE_MACHINE_CPUFLAG_AVX2
52 	efd_value_t value = 0;
53 	uint32_t i = 0;
54 	__m256i vhash_val_a = _mm256_set1_epi32(hash_val_a);
55 	__m256i vhash_val_b = _mm256_set1_epi32(hash_val_b);
56 
57 	for (; i < RTE_EFD_VALUE_NUM_BITS; i += 8) {
58 		__m256i vhash_idx =
59 				_mm256_cvtepu16_epi32(EFD_LOAD_SI128(
60 				(__m128i const *) &group_hash_idx[i]));
61 		__m256i vlookup_table = _mm256_cvtepu16_epi32(
62 				EFD_LOAD_SI128((__m128i const *)
63 				&group_lookup_table[i]));
64 		__m256i vhash = _mm256_add_epi32(vhash_val_a,
65 				_mm256_mullo_epi32(vhash_idx, vhash_val_b));
66 		__m256i vbucket_idx = _mm256_srli_epi32(vhash,
67 				EFD_LOOKUPTBL_SHIFT);
68 		__m256i vresult = _mm256_srlv_epi32(vlookup_table,
69 				vbucket_idx);
70 
71 		value |= (_mm256_movemask_ps(
72 			(__m256) _mm256_slli_epi32(vresult, 31))
73 			& ((1 << (RTE_EFD_VALUE_NUM_BITS - i)) - 1)) << i;
74 	}
75 
76 	return value;
77 #else
78 	RTE_SET_USED(group_hash_idx);
79 	RTE_SET_USED(group_lookup_table);
80 	RTE_SET_USED(hash_val_a);
81 	RTE_SET_USED(hash_val_b);
82 	/* Return dummy value, only to avoid compilation breakage */
83 	return 0;
84 #endif
85 
86 }
87