From: "Morten Brørup" <mb@smartsharesystems.com>
To: dev@dpdk.org
Cc: "Morten Brørup" <mb@smartsharesystems.com>
Subject: [PATCH 1/2] net: ethernet address comparison optimizations
Date: Fri, 30 Jan 2026 10:46:16 +0000 [thread overview]
Message-ID: <20260130104617.535413-1-mb@smartsharesystems.com> (raw)
For CPU architectures without strict alignment requirements, operations on
6-byte Ethernet addresses using three 2-byte operations were replaced by a
4-byte and a 2-byte operation, i.e. two operations instead of three.
Comparison functions are pure, so added __rte_pure.
Removed superfluous parentheses. (No functional change.)
Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
---
lib/net/rte_ether.h | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/lib/net/rte_ether.h b/lib/net/rte_ether.h
index c9a0b536c3..5552d3c1f6 100644
--- a/lib/net/rte_ether.h
+++ b/lib/net/rte_ether.h
@@ -99,13 +99,19 @@ static_assert(alignof(struct rte_ether_addr) == 2,
* True (1) if the given two ethernet address are the same;
* False (0) otherwise.
*/
+__rte_pure
static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
const struct rte_ether_addr *ea2)
{
+#if !defined(RTE_ARCH_STRICT_ALIGN)
+ return ((((const unaligned_uint32_t *)ea1)[0] ^ ((const unaligned_uint32_t *)ea2)[0]) |
+ (((const uint16_t *)ea1)[2] ^ ((const uint16_t *)ea2)[2])) == 0;
+#else
const uint16_t *w1 = (const uint16_t *)ea1;
const uint16_t *w2 = (const uint16_t *)ea2;
return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
+#endif
}
/**
@@ -118,11 +124,16 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
* True (1) if the given ethernet address is filled with zeros;
* false (0) otherwise.
*/
+__rte_pure
static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
{
+#if !defined(RTE_ARCH_STRICT_ALIGN)
+ return (((const unaligned_uint32_t *)ea)[0] | ((const uint16_t *)ea)[2]) == 0;
+#else
const uint16_t *w = (const uint16_t *)ea;
return (w[0] | w[1] | w[2]) == 0;
+#endif
}
/**
@@ -135,6 +146,7 @@ static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
* True (1) if the given ethernet address is a unicast address;
* false (0) otherwise.
*/
+__rte_pure
static inline int rte_is_unicast_ether_addr(const struct rte_ether_addr *ea)
{
return (ea->addr_bytes[0] & RTE_ETHER_GROUP_ADDR) == 0;
@@ -150,6 +162,7 @@ static inline int rte_is_unicast_ether_addr(const struct rte_ether_addr *ea)
* True (1) if the given ethernet address is a multicast address;
* false (0) otherwise.
*/
+__rte_pure
static inline int rte_is_multicast_ether_addr(const struct rte_ether_addr *ea)
{
return ea->addr_bytes[0] & RTE_ETHER_GROUP_ADDR;
@@ -165,6 +178,7 @@ static inline int rte_is_multicast_ether_addr(const struct rte_ether_addr *ea)
* True (1) if the given ethernet address is a broadcast address;
* false (0) otherwise.
*/
+__rte_pure
static inline int rte_is_broadcast_ether_addr(const struct rte_ether_addr *ea)
{
const uint16_t *w = (const uint16_t *)ea;
@@ -182,6 +196,7 @@ static inline int rte_is_broadcast_ether_addr(const struct rte_ether_addr *ea)
* True (1) if the given ethernet address is a universally assigned address;
* false (0) otherwise.
*/
+__rte_pure
static inline int rte_is_universal_ether_addr(const struct rte_ether_addr *ea)
{
return (ea->addr_bytes[0] & RTE_ETHER_LOCAL_ADMIN_ADDR) == 0;
@@ -197,6 +212,7 @@ static inline int rte_is_universal_ether_addr(const struct rte_ether_addr *ea)
* True (1) if the given ethernet address is a locally assigned address;
* false (0) otherwise.
*/
+__rte_pure
static inline int rte_is_local_admin_ether_addr(const struct rte_ether_addr *ea)
{
return (ea->addr_bytes[0] & RTE_ETHER_LOCAL_ADMIN_ADDR) != 0;
@@ -213,9 +229,10 @@ static inline int rte_is_local_admin_ether_addr(const struct rte_ether_addr *ea)
* True (1) if the given ethernet address is valid;
* false (0) otherwise.
*/
+__rte_pure
static inline int rte_is_valid_assigned_ether_addr(const struct rte_ether_addr *ea)
{
- return rte_is_unicast_ether_addr(ea) && (!rte_is_zero_ether_addr(ea));
+ return rte_is_unicast_ether_addr(ea) && !rte_is_zero_ether_addr(ea);
}
/**
--
2.43.0
next reply other threads:[~2026-01-30 10:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-30 10:46 Morten Brørup [this message]
2026-01-30 10:46 ` [PATCH 2/2] [RFC] net: introduce fast ethernet address comparison function Morten Brørup
2026-01-30 14:03 ` Morten Brørup
2026-01-30 10:52 ` [PATCH 1/2] net: ethernet address comparison optimizations Bruce Richardson
2026-01-30 11:16 ` Morten Brørup
2026-01-30 11:26 ` Bruce Richardson
2026-01-30 13:54 ` Morten Brørup
2026-01-30 14:02 ` Bruce Richardson
2026-01-30 14:25 ` Morten Brørup
2026-01-30 14:32 ` Bruce Richardson
2026-01-30 14:59 ` Morten Brørup
2026-01-30 16:20 ` Stephen Hemminger
2026-01-30 16:24 ` Bruce Richardson
2026-01-30 16:31 ` Konstantin Ananyev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260130104617.535413-1-mb@smartsharesystems.com \
--to=mb@smartsharesystems.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox