bpf: allow self-xor operation
[dpdk.git] / app / test-pmd / macswap_sse.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #ifndef _MACSWAP_SSE_H_
6 #define _MACSWAP_SSE_H_
7
8 #include "macswap_common.h"
9
10 static inline void
11 do_macswap(struct rte_mbuf *pkts[], uint16_t nb,
12                 struct rte_port *txp)
13 {
14         struct rte_ether_hdr *eth_hdr[4];
15         struct rte_mbuf *mb[4];
16         uint64_t ol_flags;
17         int i;
18         int r;
19         __m128i addr0, addr1, addr2, addr3;
20         /**
21          * shuffle mask be used to shuffle the 16 bytes.
22          * byte 0-5 wills be swapped with byte 6-11.
23          * byte 12-15 will keep unchanged.
24          */
25         __m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12,
26                                         5, 4, 3, 2,
27                                         1, 0, 11, 10,
28                                         9, 8, 7, 6);
29
30         ol_flags = ol_flags_init(txp->dev_conf.txmode.offloads);
31         vlan_qinq_set(pkts, nb, ol_flags,
32                         txp->tx_vlan_id, txp->tx_vlan_id_outer);
33
34         i = 0;
35         r = nb;
36
37         while (r >= 4) {
38                 if (r >= 8) {
39                         rte_prefetch0(rte_pktmbuf_mtod(pkts[i + 4], void *));
40                         rte_prefetch0(rte_pktmbuf_mtod(pkts[i + 5], void *));
41                         rte_prefetch0(rte_pktmbuf_mtod(pkts[i + 6], void *));
42                         rte_prefetch0(rte_pktmbuf_mtod(pkts[i + 7], void *));
43                 }
44
45                 mb[0] = pkts[i++];
46                 eth_hdr[0] = rte_pktmbuf_mtod(mb[0], struct rte_ether_hdr *);
47                 addr0 = _mm_loadu_si128((__m128i *)eth_hdr[0]);
48
49                 mb[1] = pkts[i++];
50                 eth_hdr[1] = rte_pktmbuf_mtod(mb[1], struct rte_ether_hdr *);
51                 addr1 = _mm_loadu_si128((__m128i *)eth_hdr[1]);
52
53
54                 mb[2] = pkts[i++];
55                 eth_hdr[2] = rte_pktmbuf_mtod(mb[2], struct rte_ether_hdr *);
56                 addr2 = _mm_loadu_si128((__m128i *)eth_hdr[2]);
57
58                 mb[3] = pkts[i++];
59                 eth_hdr[3] = rte_pktmbuf_mtod(mb[3], struct rte_ether_hdr *);
60                 addr3 = _mm_loadu_si128((__m128i *)eth_hdr[3]);
61
62                 addr0 = _mm_shuffle_epi8(addr0, shfl_msk);
63                 addr1 = _mm_shuffle_epi8(addr1, shfl_msk);
64                 addr2 = _mm_shuffle_epi8(addr2, shfl_msk);
65                 addr3 = _mm_shuffle_epi8(addr3, shfl_msk);
66
67                 _mm_storeu_si128((__m128i *)eth_hdr[0], addr0);
68                 _mm_storeu_si128((__m128i *)eth_hdr[1], addr1);
69                 _mm_storeu_si128((__m128i *)eth_hdr[2], addr2);
70                 _mm_storeu_si128((__m128i *)eth_hdr[3], addr3);
71
72                 mbuf_field_set(mb[0], ol_flags);
73                 mbuf_field_set(mb[1], ol_flags);
74                 mbuf_field_set(mb[2], ol_flags);
75                 mbuf_field_set(mb[3], ol_flags);
76                 r -= 4;
77         }
78
79         for ( ; i < nb; i++) {
80                 if (i < nb - 1)
81                         rte_prefetch0(rte_pktmbuf_mtod(pkts[i+1], void *));
82                 mb[0] = pkts[i];
83                 eth_hdr[0] = rte_pktmbuf_mtod(mb[0], struct rte_ether_hdr *);
84
85                 /* Swap dest and src mac addresses. */
86                 addr0 = _mm_loadu_si128((__m128i *)eth_hdr[0]);
87                 addr0 = _mm_shuffle_epi8(addr0, shfl_msk);
88                 _mm_storeu_si128((__m128i *)eth_hdr[0], addr0);
89
90                 mbuf_field_set(mb[0], ol_flags);
91         }
92 }
93
94 #endif /* _MACSWAP_SSE_H_ */