DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: "Van Haaren, Harry" <harry.van.haaren@intel.com>
Cc: "Yigit, Ferruh" <ferruh.yigit@intel.com>,
	"Morten Brørup" <mb@smartsharesystems.com>,
	"dev@dpdk.org" <dev@dpdk.org>,
	"Olivier Matz" <olivier.matz@6wind.com>,
	"Ananyev, Konstantin" <konstantin.ananyev@intel.com>
Subject: Re: [dpdk-dev] rte_ether_addr_copy() strange comment
Date: Fri, 26 Jun 2020 11:04:26 -0700	[thread overview]
Message-ID: <20200626110426.22dfb4b0@hermes.lan> (raw)
In-Reply-To: <BYAPR11MB314396891AF5351ACCE4C7E9D7930@BYAPR11MB3143.namprd11.prod.outlook.com>

On Fri, 26 Jun 2020 17:28:49 +0000
"Van Haaren, Harry" <harry.van.haaren@intel.com> wrote:

> > -----Original Message-----
> > From: Yigit, Ferruh <ferruh.yigit@intel.com>
> > Sent: Friday, June 26, 2020 4:54 PM
> > To: Van Haaren, Harry <harry.van.haaren@intel.com>; Morten Brørup
> > <mb@smartsharesystems.com>; dev@dpdk.org
> > Cc: Olivier Matz <olivier.matz@6wind.com>; Ananyev, Konstantin
> > <konstantin.ananyev@intel.com>
> > Subject: Re: [dpdk-dev] rte_ether_addr_copy() strange comment
> > 
> > On 6/26/2020 1:41 PM, Van Haaren, Harry wrote:  
> > >> -----Original Message-----  
> 
> <snip serious conversation>
> 
> > > PS: For extra bonus points, here's a SIMD version that only uses one store
> > > https://godbolt.org/z/VAR2La. Unless you intend on copying billions of
> > > L1 resident eth addrs, this may or may not be a useful optimization.
> > > Note that it requires the 10 bytes after the ether addr to be valid to read.
> > > It loads 16B across both SRC and DST, blends 48 bits of SRC into DST and
> > > writes the result back to DST.
> > >         movdqu  (%rsi), %xmm0
> > >         movdqu  (%rdi), %xmm1
> > >         pblendw $7, %xmm1, %xmm0
> > >         movups  %xmm0, (%rdi)
> > >         ret
> > >
> > > Actually, its possible to do this using a uint64_t (8 byte scalar) load/store too,
> > > with some masking and bitwise OR... left as an exercise to the reader? :)
> > >  
> > Does below work? (not for real life usage, just to experiment single store
> > solutions :) [https://godbolt.org/z/TmqwQh]
> > 
> >         movzwl  6(%rdi), %eax
> >         salq    $48, %rax
> >         orq     (%rsi), %rax
> >         movq    %rax, (%rdi)
> >         ret
> > 
> > ----
> > 
> > void copy(struct mac *dst, const struct mac *src) {
> >     uint64_t *s = (uint64_t *) &src->addr;
> >     uint64_t *d = (uint64_t *) &dst->addr;
> >     uint16_t dd = ((uint16_t *)d)[3];
> >     *d = (*s & ~(0xffffUL<48)) | ((uint64_t)dd << 48);
> > }  
> 
> My code-golf reviewing skills are probably not 100% at end-of-day on a Friday.. so I wrote a unit test ;)
> Seems to check out yet - readers beware - this solution still overwrites 2 bytes past the dst mac data itself.
> 

The Linux kernel equivalent is:

static inline void ether_addr_copy(u8 *dst, const u8 *src)
{
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
	*(u32 *)dst = *(const u32 *)src;
	*(u16 *)(dst + 4) = *(const u16 *)(src + 4);
#else
	u16 *a = (u16 *)dst;
	const u16 *b = (const u16 *)src;

	a[0] = b[0];
	a[1] = b[1];
	a[2] = b[2];
#endif
}

      reply	other threads:[~2020-06-26 18:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-25 15:45 Morten Brørup
2020-06-26 12:08 ` Ferruh Yigit
2020-06-26 12:34   ` Morten Brørup
2020-06-26 14:37     ` Jerin Jacob
2020-06-26 12:41   ` Van Haaren, Harry
2020-06-26 15:54     ` Ferruh Yigit
2020-06-26 17:28       ` Van Haaren, Harry
2020-06-26 18:04         ` Stephen Hemminger [this message]

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=20200626110426.22dfb4b0@hermes.lan \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=harry.van.haaren@intel.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=mb@smartsharesystems.com \
    --cc=olivier.matz@6wind.com \
    /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;
as well as URLs for NNTP newsgroup(s).