1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
5 #ifndef _MACSWAP_SSE_H_
6 #define _MACSWAP_SSE_H_
8 #include "macswap_common.h"
11 do_macswap(struct rte_mbuf *pkts[], uint16_t nb,
14 struct rte_ether_hdr *eth_hdr[4];
15 struct rte_mbuf *mb[4];
19 __m128i addr0, addr1, addr2, addr3;
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.
25 __m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12,
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);
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 *));
46 eth_hdr[0] = rte_pktmbuf_mtod(mb[0], struct rte_ether_hdr *);
47 addr0 = _mm_loadu_si128((__m128i *)eth_hdr[0]);
50 eth_hdr[1] = rte_pktmbuf_mtod(mb[1], struct rte_ether_hdr *);
51 addr1 = _mm_loadu_si128((__m128i *)eth_hdr[1]);
55 eth_hdr[2] = rte_pktmbuf_mtod(mb[2], struct rte_ether_hdr *);
56 addr2 = _mm_loadu_si128((__m128i *)eth_hdr[2]);
59 eth_hdr[3] = rte_pktmbuf_mtod(mb[3], struct rte_ether_hdr *);
60 addr3 = _mm_loadu_si128((__m128i *)eth_hdr[3]);
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);
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);
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);
79 for ( ; i < nb; i++) {
81 rte_prefetch0(rte_pktmbuf_mtod(pkts[i+1], void *));
83 eth_hdr[0] = rte_pktmbuf_mtod(mb[0], struct rte_ether_hdr *);
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);
90 mbuf_field_set(mb[0], ol_flags);
94 #endif /* _MACSWAP_SSE_H_ */