[PATCH 1/2] net: ethernet address comparison optimizations
Bruce Richardson
bruce.richardson at intel.com
Fri Jan 30 11:52:55 CET 2026
On Fri, Jan 30, 2026 at 10:46:16AM +0000, Morten Brørup wrote:
> 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 at 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
> }
Is this actually faster? For architectures that support strict alignment,
this looks like something that the compilers should be doing using proper
cost-benefit evaluation based on target architecture, rather than us doing
it in our code.
/Bruce
More information about the dev
mailing list