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 9D1CEA00E6 for ; Thu, 16 May 2019 20:05:39 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 28A411B108; Thu, 16 May 2019 20:04:50 +0200 (CEST) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by dpdk.org (Postfix) with ESMTP id 34C30E3EB for ; Thu, 16 May 2019 20:04:44 +0200 (CEST) Received: by mail-pf1-f195.google.com with SMTP id u17so2243529pfn.7 for ; Thu, 16 May 2019 11:04:44 -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=1ICmW9YuE04Am3/8hB7X4T/qBkWnZRHwCB74spjpPtI=; b=DMX2KM5noFczZQ16Kq8AdMkUALweR7lAmxjWWWLTwupmVZJ9uE881slTpNQT6g4p14 POgE5itxTYRLVwgDjFImOjLSWO2cPufuDvxatlViE1ojp8xVUYURUBSnv1oijSy2e1iA bzhpcr8N+NSCwK2Zuxm3hPNdAodomHWf/hj/yUcReyek5yTtiMo0Wx7a+cb5RQ+mANAY ZxGUzaZP6iw1px50f7bg0NYNjXxraZ/w9DhgF+GGLR03MfvdaPNUdrwTeRg3yvO8HZHk QP+LpFRJaWNd9N+Nh3rHb+PkCoc3jPtW9Jx8PJb4CCRuRF0kXCzx9ss2k0qKlhwbsoWj SEGQ== 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=1ICmW9YuE04Am3/8hB7X4T/qBkWnZRHwCB74spjpPtI=; b=VconHogzVWmJImWc2vVir2HZz9ocMbybMke8Rep22btJ5Gm1j6mx+cmqlKuBuo+VYk 3EdGrY3kPdyXB6BXAF535PY6NAOSxhfpgbbLIz61J1DcX77WBZLmDmQIuaTfOx/I5CZc oqEOVBvlF0Ktmyr74ALjWSNu+eB7f9CSZxgRT4RtTqq53wKOzKM3CRonO8YrBJT5xltQ E5XnmSZdf6zkVQn0ZwQRVAbcNFRtRG+NbfRH6viz4JkMWTTQkxqAT1AJ53SS7sG2swuB yj1ammKRoUOfKVJ7pEx949x1AMZVizPLDdRLYM8J1yc9Hx/QUuuiTWVKxcU+R/VfogDX tvvA== X-Gm-Message-State: APjAAAUwR6c7viEyOmyq7GXrsa6NvuWaKdnhIgjtFSVpImCGT0DhvGKB dbIjsilm1VaTjo0Q52X3vissUhyCAeA= X-Google-Smtp-Source: APXvYqwtcRrkfQHcvrCtE3r70tXXYISKlkqpk2RnMnGkLlHf8PZY5x+gHVPX1ttoKJkZF/BOnZ7aVw== X-Received: by 2002:a62:582:: with SMTP id 124mr55910928pff.209.1558029882834; Thu, 16 May 2019 11:04:42 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id d67sm9376657pfa.35.2019.05.16.11.04.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 May 2019 11:04:42 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 16 May 2019 11:04:26 -0700 Message-Id: <20190516180427.17270-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190516180427.17270-1-stephen@networkplumber.org> References: <20190516180427.17270-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 6/7] 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 0fa4481d266b..799996dc7e1b 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -79,11 +79,10 @@ struct ether_addr { static inline int is_same_ether_addr(const struct ether_addr *ea1, const struct ether_addr *ea2) { - int i; - for (i = 0; i < ETHER_ADDR_LEN; i++) - if (ea1->addr_bytes[i] != ea2->addr_bytes[i]) - return 0; - return 1; + const uint16_t *w1 = (const uint16_t *)ea1; + const uint16_t *w2 = (const uint16_t *)ea2; + + return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0; } /** @@ -98,11 +97,9 @@ static inline int is_same_ether_addr(const struct ether_addr *ea1, */ static inline int is_zero_ether_addr(const struct ether_addr *ea) { - int i; - for (i = 0; i < ETHER_ADDR_LEN; i++) - if (ea->addr_bytes[i] != 0x00) - return 0; - return 1; + const uint16_t *w = (const uint16_t *)ea; + + return (w[0] | w[1] | w[2]) == 0; } /** -- 2.20.1