> From: Morten Brørup [mailto:[email protected]] > 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 <[email protected]> > --- > 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

