app/testpmd: improve MAC swap performance for x86
[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 ether_hdr *eth_hdr;
15         struct rte_mbuf *mb;
16         uint64_t ol_flags;
17         int i;
18         __m128i addr;
19         /**
20          * shuffle mask be used to shuffle the 16 bytes.
21          * byte 0-5 wills be swapped with byte 6-11.
22          * byte 12-15 will keep unchanged.
23          */
24         __m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12,
25                                         5, 4, 3, 2,
26                                         1, 0, 11, 10,
27                                         9, 8, 7, 6);
28
29         ol_flags = ol_flags_init(txp->dev_conf.txmode.offloads);
30         vlan_qinq_set(pkts, nb, ol_flags,
31                         txp->tx_vlan_id, txp->tx_vlan_id_outer);
32
33         for (i = 0; i < nb; i++) {
34                 if (likely(i < nb - 1))
35                         rte_prefetch0(rte_pktmbuf_mtod(pkts[i+1], void *));
36                 mb = pkts[i];
37
38                 eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
39
40                 /* Swap dest and src mac addresses. */
41                 addr = _mm_loadu_si128((__m128i *)eth_hdr);
42                 addr = _mm_shuffle_epi8(addr, shfl_msk);
43                 _mm_storeu_si128((__m128i *)eth_hdr, addr);
44
45                 mbuf_field_set(mb, ol_flags);
46         }
47 }
48
49 #endif /* _MACSWAP_SSE_H_ */