From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id EEA3BA0520; Fri, 26 Jun 2020 20:04:37 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 40C7C1BEBF; Fri, 26 Jun 2020 20:04:37 +0200 (CEST) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id CF35F1BEAC for ; Fri, 26 Jun 2020 20:04:35 +0200 (CEST) Received: by mail-pg1-f193.google.com with SMTP id e8so5282746pgc.5 for ; Fri, 26 Jun 2020 11:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ntBC2YMntLe7MHFv0tC3e8vN4DoOg3LUrKf23mICUuQ=; b=T89GPefMEHa24PFyzwUA3/T67zV0Yt8H95bDSpOrMboV20fyVgnKLc3iXsiQdZl9fS 8QL1Kn2egtSc46IU4BWwILyeB1uNIN8ABKxOs2hnRGoNQvJFPq2Q1WDKcEx8rMovMdhv UhD42xweALS+t9+r+v7tLqsHhXqxKcYeZZ2C5J7B3qkN+amPyMEtkdB4tlTDnBuUUyE1 X60N7ViDgMaRnH3k+iVS2BVLgat7JcWFLcEss750ygjdD0q1YgYwTEVoIJrR8GQpDAP4 /cIdcjZNm4VxMtjlqSsq6DNlyOW1VSUrewhLTVxLTwMd00zUyj9QzpmwchppFDgTRN8i +hCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ntBC2YMntLe7MHFv0tC3e8vN4DoOg3LUrKf23mICUuQ=; b=gaV6pHTKiiQHQRSCF8tQGrwlufH+LvpXpKSiI81prfo7sgAC4bfxRHMRVVbkWBu6Ie WQ3fY1vqdTl6XMbHeJtlaJnACRMjfMB5pweA5a+nHXUlkDeVPMt5ksDUNtRnkvP+NL7G v26sd49CY24OU04D0s7Ki6kzcWWPPW/Stt2VKMVLY1lhSg/WxD95Lsdn3p8qLfdSu7xQ pM1/j+aYB4rmwqO1DckJMp+fi8+p5zBYcFhOK98AfEQo83OQW/ILs0aqF8VgOw0gNo5V qwDLrwA4AW1bU07HM1OwLNJldFn1gBGWhi1W1PNbhpO2Gu1P74IRJI8oJy5BkUsBJqBw ndOA== X-Gm-Message-State: AOAM532CSdKUpFFLX3CrdXrQhDbplHF9nbUSRa75sZUeDCNAHq0p5JdY tzbLXHdKUF4EwOl8JlJEngYyQw== X-Google-Smtp-Source: ABdhPJztgvgJV4TRzPPJ27lLiGlatGn5wwaEmuU/wYGALS90Q7IVdF5G/r6uwJzpZy997I6shkhCkQ== X-Received: by 2002:a63:6dc1:: with SMTP id i184mr3732120pgc.345.1593194674805; Fri, 26 Jun 2020 11:04:34 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id z19sm11044069pjn.55.2020.06.26.11.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 11:04:34 -0700 (PDT) Date: Fri, 26 Jun 2020 11:04:26 -0700 From: Stephen Hemminger To: "Van Haaren, Harry" Cc: "Yigit, Ferruh" , Morten =?UTF-8?B?QnLDuHJ1?= =?UTF-8?B?cA==?= , "dev@dpdk.org" , Olivier Matz , "Ananyev, Konstantin" Message-ID: <20200626110426.22dfb4b0@hermes.lan> In-Reply-To: References: <98CBD80474FA8B44BF855DF32C47DC35C610C4@smartserver.smartshare.dk> <6b67ce84-92ee-550d-2fba-af8c4c1bb2aa@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [dpdk-dev] rte_ether_addr_copy() strange comment X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Fri, 26 Jun 2020 17:28:49 +0000 "Van Haaren, Harry" wrote: > > -----Original Message----- > > From: Yigit, Ferruh > > Sent: Friday, June 26, 2020 4:54 PM > > To: Van Haaren, Harry ; Morten Br=C3=B8rup > > ; dev@dpdk.org > > Cc: Olivier Matz ; Ananyev, Konstantin > > > > Subject: Re: [dpdk-dev] rte_ether_addr_copy() strange comment > >=20 > > On 6/26/2020 1:41 PM, Van Haaren, Harry wrote: =20 > > >> -----Original Message----- =20 >=20 > >=20 > > > 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 t= o 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) lo= ad/store too, > > > with some masking and bitwise OR... left as an exercise to the reader= ? :) > > > =20 > > Does below work? (not for real life usage, just to experiment single st= ore > > solutions :) [https://godbolt.org/z/TmqwQh] > >=20 > > movzwl 6(%rdi), %eax > > salq $48, %rax > > orq (%rsi), %rax > > movq %rax, (%rdi) > > ret > >=20 > > ---- > >=20 > > void copy(struct mac *dst, const struct mac *src) { > > uint64_t *s =3D (uint64_t *) &src->addr; > > uint64_t *d =3D (uint64_t *) &dst->addr; > > uint16_t dd =3D ((uint16_t *)d)[3]; > > *d =3D (*s & ~(0xffffUL<48)) | ((uint64_t)dd << 48); > > } =20 >=20 > My code-golf reviewing skills are probably not 100% at end-of-day on a Fr= iday.. 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. >=20 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 =3D *(const u32 *)src; *(u16 *)(dst + 4) =3D *(const u16 *)(src + 4); #else u16 *a =3D (u16 *)dst; const u16 *b =3D (const u16 *)src; a[0] =3D b[0]; a[1] =3D b[1]; a[2] =3D b[2]; #endif }