4 * Copyright(c) 2017 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
16 * * Neither the name of Intel Corporation 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.
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.
34 #include "rte_distributor_private.h"
35 #include "rte_distributor.h"
36 #include "smmintrin.h"
37 #include "nmmintrin.h"
41 find_match_vec(struct rte_distributor *d,
46 __m128i incoming_fids;
47 __m128i inflight_fids;
48 __m128i preflight_fids;
53 struct rte_distributor_backlog *bl;
58 * 2. Loop through all worker ID's
59 * 2a. Load the current inflights for that worker into an xmm reg
60 * 2b. Load the current backlog for that worker into an xmm reg
61 * 2c. use cmpestrm to intersect flow_ids with backlog and inflights
62 * 2d. Add any matches to the output
63 * 3. Write the output xmm (matching worker ids).
67 output = _mm_set1_epi16(0);
68 incoming_fids = _mm_load_si128((__m128i *)data_ptr);
70 for (i = 0; i < d->num_workers; i++) {
74 _mm_load_si128((__m128i *)&(d->in_flight_tags[i]));
76 _mm_load_si128((__m128i *)(bl->tags));
79 * Any incoming_fid that exists anywhere in inflight_fids will
80 * have 0xffff in same position of the mask as the incoming fid
81 * Example (shortened to bytes for brevity):
82 * incoming_fids 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08
83 * inflight_fids 0x03 0x05 0x07 0x00 0x00 0x00 0x00 0x00
84 * mask 0x00 0x00 0xff 0x00 0xff 0x00 0xff 0x00
87 mask1 = _mm_cmpestrm(inflight_fids, 8, incoming_fids, 8,
91 mask2 = _mm_cmpestrm(preflight_fids, 8, incoming_fids, 8,
96 mask1 = _mm_or_si128(mask1, mask2);
98 * Now mask contains 0xffff where there's a match.
99 * Next we need to store the worker_id in the relevant position
103 wkr = _mm_set1_epi16(i+1);
104 mask1 = _mm_and_si128(mask1, wkr);
105 output = _mm_or_si128(mask1, output);
109 * At this stage, the output 128-bit contains 8 16-bit values, with
110 * each non-zero value containing the worker ID on which the
111 * corresponding flow is pinned to.
113 _mm_store_si128((__m128i *)output_ptr, output);