RE: [PATCH 1/2] net: ethernet address comparison optimizations

Konstantin Ananyev
2026-01-30T16:31:24Z

> >
> > > +__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
> > > }
> > >
> >
> > FYI in Linux:
> >
> > static inline bool ether_addr_equal(const u8 *addr1, const u8 *addr2)
> > {
> > #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
> > u32 fold = ((*(const u32 *)addr1) ^ (*(const u32 *)addr2)) |
> > ((*(const u16 *)(addr1 + 4)) ^ (*(const u16 *)(addr2 + 4)));
> >
> > return fold == 0;
> > #else
> > const u16 *a = (const u16 *)addr1;
> > const u16 *b = (const u16 *)addr2;
> >
> > return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) == 0;
> > #endif
> > }
> >
> > In FreeBSD kernel, there is no helper they just use memcmp
>
> +1 for just memcmp :-)

Same thoughts :)