summaryrefslogtreecommitdiffstats
path: root/vnet/vnet/ethernet
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2016-09-19 11:32:03 +0200
committerJohn Lo <loj@cisco.com>2016-09-20 17:37:02 +0000
commitb94bdad5c04450aad59feb8a5806a87fe37da088 (patch)
tree3b4bd38253e5b00d76c8a66ae83dc710f3a10003 /vnet/vnet/ethernet
parent48a9a54e7c8e295c0cba3491a05c8aa0a5a1f81a (diff)
Use SSE instructions for matching tagged frames by ethertype
This change improves performance in l2 scenarios for about 1-2%. Change-Id: Ie35ed8ad70a3b95dd78c0d158c485a10dabaf0eb Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'vnet/vnet/ethernet')
-rw-r--r--vnet/vnet/ethernet/ethernet.h27
-rw-r--r--vnet/vnet/ethernet/node.c5
2 files changed, 28 insertions, 4 deletions
diff --git a/vnet/vnet/ethernet/ethernet.h b/vnet/vnet/ethernet/ethernet.h
index b5c4ee919e5..8a1369c1093 100644
--- a/vnet/vnet/ethernet/ethernet.h
+++ b/vnet/vnet/ethernet/ethernet.h
@@ -60,6 +60,33 @@ ethernet_mac_address_is_multicast_u64 (u64 a)
return (a & (1ULL << (5 * 8))) != 0;
}
+static_always_inline int
+ethernet_frame_is_tagged (u16 type)
+{
+#if __SSE4_2__
+ const __m128i ethertype_mask = _mm_set_epi16 (ETHERNET_TYPE_VLAN,
+ ETHERNET_TYPE_DOT1AD,
+ ETHERNET_TYPE_VLAN_9100,
+ ETHERNET_TYPE_VLAN_9200,
+ /* duplicate last one to
+ fill register */
+ ETHERNET_TYPE_VLAN_9200,
+ ETHERNET_TYPE_VLAN_9200,
+ ETHERNET_TYPE_VLAN_9200,
+ ETHERNET_TYPE_VLAN_9200);
+
+ __m128i r = _mm_set1_epi16 (type);
+ r = _mm_cmpeq_epi16 (ethertype_mask, r);
+ return !_mm_test_all_zeros (r, r);
+#else
+ if ((type == ETHERNET_TYPE_VLAN) ||
+ (type == ETHERNET_TYPE_DOT1AD) ||
+ (type == ETHERNET_TYPE_VLAN_9100) || (type == ETHERNET_TYPE_VLAN_9200))
+ return 1;
+#endif
+ return 0;
+}
+
/* Max. sized ethernet/vlan header for parsing. */
typedef struct
{
diff --git a/vnet/vnet/ethernet/node.c b/vnet/vnet/ethernet/node.c
index a8a4fcd074d..aaa0434bc89 100644
--- a/vnet/vnet/ethernet/node.c
+++ b/vnet/vnet/ethernet/node.c
@@ -130,10 +130,7 @@ parse_header (ethernet_input_variant_t variant,
vlan_count = 0;
// check for vlan encaps
- if ((*type == ETHERNET_TYPE_VLAN) ||
- (*type == ETHERNET_TYPE_DOT1AD) ||
- (*type == ETHERNET_TYPE_VLAN_9100) ||
- (*type == ETHERNET_TYPE_VLAN_9200))
+ if (ethernet_frame_is_tagged (*type))
{
ethernet_vlan_header_t *h0;
u16 tag;