efd: move AVX2 lookup in its own compilation unit
[dpdk.git] / lib / librte_efd / rte_efd_x86.c
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.c
35  * This file holds all x86 specific EFD functions
36  */
37 #include <rte_efd.h>
38 #include <rte_efd_x86.h>
39
40 #if (RTE_EFD_VALUE_NUM_BITS == 8 || RTE_EFD_VALUE_NUM_BITS == 16 || \
41         RTE_EFD_VALUE_NUM_BITS == 24 || RTE_EFD_VALUE_NUM_BITS == 32)
42 #define EFD_LOAD_SI128(val) _mm_load_si128(val)
43 #else
44 #define EFD_LOAD_SI128(val) _mm_lddqu_si128(val)
45 #endif
46
47 efd_value_t
48 efd_lookup_internal_avx2(const efd_hashfunc_t *group_hash_idx,
49                 const efd_lookuptbl_t *group_lookup_table,
50                 const uint32_t hash_val_a, const uint32_t hash_val_b)
51 {
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 }