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 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 eth_hdr[0] = rte_pktmbuf_mtod(mb[0], struct ether_hdr *);
40 addr0 = _mm_loadu_si128((__m128i *)eth_hdr[0]);
43 eth_hdr[1] = rte_pktmbuf_mtod(mb[1], struct ether_hdr *);
44 addr1 = _mm_loadu_si128((__m128i *)eth_hdr[1]);
48 eth_hdr[2] = rte_pktmbuf_mtod(mb[2], struct ether_hdr *);
49 addr2 = _mm_loadu_si128((__m128i *)eth_hdr[2]);
52 eth_hdr[3] = rte_pktmbuf_mtod(mb[3], struct ether_hdr *);
53 addr3 = _mm_loadu_si128((__m128i *)eth_hdr[3]);
55 addr0 = _mm_shuffle_epi8(addr0, shfl_msk);
56 addr1 = _mm_shuffle_epi8(addr1, shfl_msk);
57 addr2 = _mm_shuffle_epi8(addr2, shfl_msk);
58 addr3 = _mm_shuffle_epi8(addr3, shfl_msk);
60 _mm_storeu_si128((__m128i *)eth_hdr[0], addr0);
61 _mm_storeu_si128((__m128i *)eth_hdr[1], addr1);
62 _mm_storeu_si128((__m128i *)eth_hdr[2], addr2);
63 _mm_storeu_si128((__m128i *)eth_hdr[3], addr3);
65 mbuf_field_set(mb[0], ol_flags);
66 mbuf_field_set(mb[1], ol_flags);
67 mbuf_field_set(mb[2], ol_flags);
68 mbuf_field_set(mb[3], ol_flags);
72 for ( ; i < nb; i++) {
74 rte_prefetch0(rte_pktmbuf_mtod(pkts[i+1], void *));
76 eth_hdr[0] = rte_pktmbuf_mtod(mb[0], struct ether_hdr *);
78 /* Swap dest and src mac addresses. */
79 addr0 = _mm_loadu_si128((__m128i *)eth_hdr[0]);
80 addr0 = _mm_shuffle_epi8(addr0, shfl_msk);
81 _mm_storeu_si128((__m128i *)eth_hdr[0], addr0);
83 mbuf_field_set(mb[0], ol_flags);
87 #endif /* _MACSWAP_SSE_H_ */