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 45135A0487 for ; Tue, 2 Jul 2019 17:28:56 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 24DE01B9F0; Tue, 2 Jul 2019 17:28:55 +0200 (CEST) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by dpdk.org (Postfix) with ESMTP id 22C021B9EA for ; Tue, 2 Jul 2019 17:28:54 +0200 (CEST) Received: by mail-pg1-f194.google.com with SMTP id g15so5955803pgi.4 for ; Tue, 02 Jul 2019 08:28:53 -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=EPHFXlyXAe4ulOv9p+9klGzEqPzsGWDpIQUKqETCrG4=; b=j4ofs5kR9WN4i2yNeBUpZYoBwRTE30PzNPunaYarNqINkEEHlrJt3wbSmIJMIkhJKf UnFkhCtYfF4JAagixneNAwjs0rog6XHbwpsmHGFWU3B7iPsocEJdY0HXK7uSAFP4v5T4 ssKPbzK8/zJCOl9/OM01iz0kw6hWdmVQp3nGGNuyeifoF2qyYudlCuJ9+/MlJ4SZDlMd Pd2qwZM4KEu8pk/YWNUuwuDntONN7xfB+rnpSYzHFg8YxHz/LKE2KR8oKRY9OuaZ0UJ4 LMi6G6AmbTzhuRrU+d+JdEI6sDZSuckYbke9ecML6eIJqICvDjoi404W12Q9XpIKW7c/ c2zw== 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=EPHFXlyXAe4ulOv9p+9klGzEqPzsGWDpIQUKqETCrG4=; b=IPqRbDU3a9jBRp5rHdtYeQ6gAED+J7adXuNZacdXB/uYpfjXRHTWlCbkYiLBqh3E63 lDAJ6TltAFFXF8H/4iBodnAgjr4o3/0opVN3lFAbGe97kXWIbYXkKbmxhJ4+sU4Kx4QU 0t/TS+HA+KzBC4AsrQif7GcHK8ySi3xFNldCmc/i73yE6pHp9CiuyoVUtmjRq0Bnth7P 1RkeTRZ3RBx5DFcZCboO6Up4wY5pfdSmDMrnOk1KjmtO3K0l3DxQ0WUnhGwaDihcG3D6 GtJaclTgT43pTcbAhp7oe3cDXPRzf+EX2nBXfLQXevx847QfdGz3Gn73Rp9KaYGKoqHp yvbQ== X-Gm-Message-State: APjAAAUmEvyxdlNpbsdK7J2YvFZall6vt2OQwof5vfkKgeK9ZH/GBP1S r1E3ZobtaeXwo+xaN08x4us/6qYmNmg= X-Google-Smtp-Source: APXvYqzxEqxIo6vR8+QfFT0eRSGxDdzQkxnZL6j0/D2Tcjq+Beb1ZasjnTuaGJU9CMp3BG+yDgUypg== X-Received: by 2002:a63:7887:: with SMTP id t129mr13670038pgc.309.1562081332846; Tue, 02 Jul 2019 08:28:52 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id q63sm28408143pfb.81.2019.07.02.08.28.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 02 Jul 2019 08:28:52 -0700 (PDT) Date: Tue, 2 Jul 2019 08:28:45 -0700 From: Stephen Hemminger To: Olivier Matz Cc: dev@dpdk.org, Andrew Rybchenko Message-ID: <20190702082845.0861c488@hermes.lan> In-Reply-To: <20190702092615.rw5byhhuorjuei74@platinum> References: <20190516180427.17270-1-stephen@networkplumber.org> <20190624204435.29452-1-stephen@networkplumber.org> <20190624204435.29452-5-stephen@networkplumber.org> <20190702075314.npiao2zcsajykrob@platinum> <20190702092615.rw5byhhuorjuei74@platinum> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v5 4/8] net/ether: use bitops to speedup comparison 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 Tue, 2 Jul 2019 11:26:15 +0200 Olivier Matz wrote: > On Tue, Jul 02, 2019 at 09:53:14AM +0200, Olivier Matz wrote: > > Hi, > > > > On Mon, Jun 24, 2019 at 01:44:31PM -0700, Stephen Hemminger wrote: > > > Using bit operations like or and xor is faster than a loop > > > on all architectures. Really just explicit unrolling. > > > > > > Similar cast to uint16 unaligned is already done in > > > other functions here. > > > > > > Signed-off-by: Stephen Hemminger > > > Reviewed-by: Andrew Rybchenko > > > --- > > > lib/librte_net/rte_ether.h | 17 +++++++---------- > > > 1 file changed, 7 insertions(+), 10 deletions(-) > > > > > > diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h > > > index 8edc7e217b25..feb35a33c94b 100644 > > > --- a/lib/librte_net/rte_ether.h > > > +++ b/lib/librte_net/rte_ether.h > > > @@ -81,11 +81,10 @@ struct rte_ether_addr { > > > static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1, > > > const struct rte_ether_addr *ea2) > > > { > > > - int i; > > > - for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) > > > - if (ea1->addr_bytes[i] != ea2->addr_bytes[i]) > > > - return 0; > > > - return 1; > > > + const unaligned_uint16_t *w1 = (const uint16_t *)ea1; > > > + const unaligned_uint16_t *w2 = (const uint16_t *)ea2; > > > + > > > + return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0; > > > } > > > > > > /** > > > @@ -100,11 +99,9 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1, > > > */ > > > static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea) > > > { > > > - int i; > > > - for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) > > > - if (ea->addr_bytes[i] != 0x00) > > > - return 0; > > > - return 1; > > > + const unaligned_uint16_t *w = (const uint16_t *)ea; > > > + > > > + return (w[0] | w[1] | w[2]) == 0; > > > } > > > > > > /** > > > > I wonder if using memcmp() isn't faster with recent compilers (gcc >= 7). > > I tried it quickly, and it seems the generated code is good (no call): > > https://godbolt.org/z/9MOL7g > > > > It would avoid the use of unaligned_uint16_t, and the next patch that > > adds the alignment constraint. > > As pointed out by Konstantin privately (I guess he wanted to do a > reply-all), the size of addr_bytes is wrong in my previous link (8 > instead of 6). Thanks for catching it. > > With 6, the gcc code is not as good: there is still no call to memcmp(), > but there are some jumps. With the latest clang, the generated code is > nice: https://godbolt.org/z/nfptnY gcc matters most for current DPDK users.