public inbox for dev@dpdk.org
 help / color / mirror / Atom feed
From: "Morten Brørup" <mb@smartsharesystems.com>
To: "Bruce Richardson" <bruce.richardson@intel.com>, <dev@dpdk.org>
Subject: RE: [PATCH 2/2] [RFC] net: introduce fast ethernet address comparison function
Date: Fri, 30 Jan 2026 15:03:03 +0100	[thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35F656D6@smartserver.smartshare.dk> (raw)
In-Reply-To: <20260130104617.535413-2-mb@smartsharesystems.com>

> From: Morten Brørup [mailto:mb@smartsharesystems.com]
> Sent: Friday, 30 January 2026 11.46
> 
> Added a fast ethernet address comparison function for 64-bit CPU
> architectures without strict alignment requirements, loading the
> ethernet
> addresses as 64-bit words and comparing the relevant 6 bytes.

Some quick testing in a real application shows this is ~2 cycles faster than the standard rte_is_same_ether_addr() implementation (without the patch 1/2 changes).

> 
> Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
> ---
>  lib/net/rte_ether.h | 46 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/lib/net/rte_ether.h b/lib/net/rte_ether.h
> index 5552d3c1f6..1b640d81c2 100644
> --- a/lib/net/rte_ether.h
> +++ b/lib/net/rte_ether.h
> @@ -114,6 +114,52 @@ static inline int rte_is_same_ether_addr(const
> struct rte_ether_addr *ea1,
>  #endif
>  }
> 
> +/**
> + * @warning
> + * @b EXPERIMENTAL: this API may change, or be removed, without prior
> notice
> + *
> + * Check if two Ethernet addresses are the same, performance
> optimized.
> + *
> + * @warning
> + * Intentional buffer overrun:
> + * The Ethernet addresses are loaded as 64-bit integers, i.e.
> + * two bytes past the memory holding the Ethernet addresses are
> loaded.
> + * The caller must ensure that this does not cause problems.
> + * If an Ethernet address 'ea' is a field in a structure 'S', it can
> be verified as follows:
> + * \code{.c}
> + *   static_assert(sizeof(struct S) >= offsetof(struct S, ea) +
> sizeof(uint64_t));
> + * \endcode
> + *
> + * @param ea1
> + *   A pointer to the first ether_addr structure containing the
> Ethernet address.
> + * @param ea2
> + *   A pointer to the second ether_addr structure containing the
> Ethernet address.
> + *
> + * @return
> + *   - true if the given two Ethernet addresses are the same;
> + *   - false otherwise.
> + */
> +__rte_experimental
> +__rte_pure
> +static inline bool
> +rte_is_same_ether_addr_fast(const struct rte_ether_addr *ea1,
> +		const struct rte_ether_addr *ea2)
> +{
> +#if defined(RTE_ARCH_64) && !defined(RTE_ARCH_STRICT_ALIGN)
> +	const unaligned_uint64_t * const a1 = (const unaligned_uint64_t
> *)ea1;
> +	const unaligned_uint64_t * const a2 = (const unaligned_uint64_t
> *)ea2;
> +#if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
> +	return (*a1 ^ *a2) >> 16 == 0;
> +#elif RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
> +	return (*a1 ^ *a2) << 16 == 0;
> +#else
> +#error "Unknown byte order."
> +#endif /* RTE_BYTE_ORDER */
> +#else
> +	return rte_is_same_ether_addr(ea1, ea2);
> +#endif
> +}
> +
>  /**
>   * Check if an Ethernet address is filled with zeros.
>   *
> --
> 2.43.0


  reply	other threads:[~2026-01-30 14:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-30 10:46 [PATCH 1/2] net: ethernet address comparison optimizations Morten Brørup
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 [this message]
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=98CBD80474FA8B44BF855DF32C47DC35F656D6@smartserver.smartshare.dk \
    --to=mb@smartsharesystems.com \
    --cc=bruce.richardson@intel.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