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 1BBAEA00E6 for ; Mon, 8 Jul 2019 20:27:07 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9FDD41BC07; Mon, 8 Jul 2019 20:26:33 +0200 (CEST) Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by dpdk.org (Postfix) with ESMTP id 6FC541B9A8 for ; Mon, 8 Jul 2019 20:26:27 +0200 (CEST) Received: by mail-pg1-f172.google.com with SMTP id p10so8112633pgn.1 for ; Mon, 08 Jul 2019 11:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MgG6DtlT3vsBQdmLfi4W05pcLSDYewGH702P0I6PUok=; b=w8qvoHosbFcfkio+Ufa4pnVSke5M71tJ7F9+cj6HqIxb9E6V1ShaiUI5pgEESuZMBY tb6gjqmxub7T0f0JRJzUalde+X53Dm/Ac5YQ8BzIkkeuRj50x4Spe5mOLV+IJhUAo6mM mTvLvkjRzY6cGsOgqFYDSlGeDvCZt3x4cpqB+fykr5dWT7fUtUFhboiOKSFq0pb5Dmdj J7dOwQ+BO2OFolITSa4FyoPYwz4XfP8FmuB6KrH5cE2D+TlyopNIi8BRcaLMb432aaiy JwvPi/ZB0q23hH3gYShpY927UQ1YNOHi7OhMPgscgvXSzJiLvgNbsHaksYO9xM5qvOYT vW9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MgG6DtlT3vsBQdmLfi4W05pcLSDYewGH702P0I6PUok=; b=bwMBRIFASceu0lCW8Z8cNRrCS0iSpR4MYyZBosw/dMU2endU5UyvWF1vUN7DdU01uT /Iwz48F2TxeKeoGnoy75xKADqag9pAvEBhkYNEouMnQkTK1tUmkW1ThifinW+XKcSHZP GvF0fjWRBCL899yVIw3eV4Fp/0Y86HrVLbb/3QC22JcQKIy1L4g/8oCC1mGYA6Y90OaU j9hgtDekyEXZW3++pTlLREKPx8lGnAr2USWcLlUpIs/J+yY/Brpj7F4QwVMkE0VpVbac Li2PpXU4jYKgZId2tArIKf6UgxCMk2szspwXvBWcM7u3JmMkhqQNHwgxe2nkR5RjkKU3 bHUg== X-Gm-Message-State: APjAAAXVsq33LRtY45UzF6dwB3iXyp/ItHApVeO3xePufK7mTBSyyj/3 e6H1X24ihPxdBdM5NqUxdg3IQgnbRf8= X-Google-Smtp-Source: APXvYqxcIXxH6hyZCCwzZ/Sd8VUML1Jf6EZSvf2L+yrW/blXDfn4mc6KLdCq2k9WLIYtXMMtmD/Rpg== X-Received: by 2002:a17:90a:bb0c:: with SMTP id u12mr27968621pjr.132.1562610386439; Mon, 08 Jul 2019 11:26:26 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id o15sm18769295pgj.18.2019.07.08.11.26.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 08 Jul 2019 11:26:25 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Andrew Rybchenko , Olivier Matz Date: Mon, 8 Jul 2019 11:26:07 -0700 Message-Id: <20190708182614.1677-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190708182614.1677-1-stephen@networkplumber.org> References: <20190516180427.17270-1-stephen@networkplumber.org> <20190708182614.1677-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v9 04/11] 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" 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 Acked-by: Olivier Matz --- 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 77b4569b1ad4..6c07f4696a95 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; } /** -- 2.20.1