From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 5B3B8A0096 for ; Wed, 5 Jun 2019 03:09:34 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 054951B9AC; Wed, 5 Jun 2019 03:09:07 +0200 (CEST) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id 3AB661B96E for ; Wed, 5 Jun 2019 03:09:01 +0200 (CEST) Received: by mail-pf1-f193.google.com with SMTP id q10so3569734pff.9 for ; Tue, 04 Jun 2019 18:09:01 -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=3gRaZTEpP089WqB2TCweuXbKeyAmUk694oE/sGpovbs=; b=gPDRUUvW8Go5WlmLGah2i5Oiv7zgKvwW+TWQwGAFY4IK5vBjfpKh1oa25exzMiseqL 8bS8V2NPzvNY9b8mdbkFH7yy25IEgHp+OklTuydPPdVdI8DtnciyZXxWsJU4JlBKOUMg rjQi7aG4FlGM47je7v3jfEHxKFLY2qRn9O+sN10WcgpnUX1g0JO5wcZVbd54d2lJHRy9 F9b1gPBRRgD0S9b4PlQ75AoQGEVRO3cr/utctNxL1pZDcgJ3jaJ6COauMSNIgrWzEk8i esuNDFbGE/03acVs5fuDP3GbMhUW/r2d3yYxWeV6l+1Z0U2e/HAJRNxDwc+khW1xPwPv CqGQ== 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=3gRaZTEpP089WqB2TCweuXbKeyAmUk694oE/sGpovbs=; b=lkpU83Zl6hQzpF3zLCh8S40+gEEJMwQ6YpaTNVv0c2KOx+otcZU/EWLkjgdVgdJUlW qsLOHLpSotWnDOTVNxgdLjpfQvuvZdI/D8Q0Hl0/uE1eGk3GluOF9q+fXRI/j8E4YnQL dcnzvbIFGWbawhpfmt09hZA11n1DGxj51G0O2p9NPIeNgOl0PaRX1huOESChpIH5BbbP ONeY/ndGulrDR6cGo4xlXhW+iCvW3oNBMKH5OVfwKCG5yngOV3H52tI78qjUbACjDJC6 jJLtSg1VOUTnunBcq6X/wCLvbHBnhRvHEH7gLtzbCQ1TgYowJ+jZqgAtHBJKgrWMQf0r zVVw== X-Gm-Message-State: APjAAAX34oW2BaKR56ba29je+OKs8jLLdae6CgjMDqvdGMziiR+zYfQ1 fcYa41++aSOn4mKsL7l29uz3TqS/Dek= X-Google-Smtp-Source: APXvYqx45MvfEVeErFqi9EBQLzFtFSo9GjkDsTzipMUkSN6ndgSxPBFr4GCBF6ogzaCenADivyo2ng== X-Received: by 2002:a63:4104:: with SMTP id o4mr718604pga.345.1559696940182; Tue, 04 Jun 2019 18:09:00 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id 12sm8645936pfi.60.2019.06.04.18.08.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jun 2019 18:08:59 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Tue, 4 Jun 2019 18:08:50 -0700 Message-Id: <20190605010852.28395-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190605010852.28395-1-stephen@networkplumber.org> References: <20190516180427.17270-1-stephen@networkplumber.org> <20190605010852.28395-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 4/6] 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 --- 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; } /** -- 2.20.1