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 9BED6A0096 for ; Wed, 5 Jun 2019 20:10:33 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 341BD1B9CC; Wed, 5 Jun 2019 20:10:02 +0200 (CEST) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by dpdk.org (Postfix) with ESMTP id 89A861B9B1 for ; Wed, 5 Jun 2019 20:09:57 +0200 (CEST) Received: by mail-pg1-f196.google.com with SMTP id 196so12838215pgc.6 for ; Wed, 05 Jun 2019 11:09:57 -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=8fFcBaPZKjQQPsKQQeFeSAG72mshjjR9mGZfTCJM/8s=; b=LgWCBk+CmM8yaiNrkPlToltHnZRe7RVYPwzwwksgZ0QrygDFw1VhmUS9jf/qx8Hnqh VWSPw5PYTxk+UyL8TwKlYQiAHbe2yT8VqSntM0ECuM1IeZUxNnXXC71StU6g4O9CwTVv anLBGHF5+2F1A+/69ccROmV149kiNd+KUWkIhifwF8BMUmsqvcTHYilGwkqNXaBwgKm6 LGRgI7fUCujNS91LMJejNb4uB7+KQidakVCnftzXFinpxe94ygPacAYirLxwPs6zP8fc KYj9S2EJB4q/g1gxsviOUt/onozLWvpQS3PZBGUyTa6LUiU6LFXoe3G4nMppVUABPquD a1Sw== 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=8fFcBaPZKjQQPsKQQeFeSAG72mshjjR9mGZfTCJM/8s=; b=Gi1KFwXOp+o+BAOFSWNbdlc6ebE+V6n0qbO7yPeH2IyeUmBb/Qd2gkC5zKqImfVpmw tDzdhQTmZ/Uj4pqxOBumNBN1BLlbBPdLeML3K0Te+bKkVEkFmiN5S4YNNoBmnSDcKPBx xb5u3aFK3Z8Y71kYtGlKQyKmPMp9Lt98GTnau+7Brr4WqeGcFhZrG/S9hfyAH2RXkOVp feJFp8apu+pE/j0Gvlhr3/o5LiB9ZwJ6g/idJvRn4nJ01NMW8FvtPKlpN3lCZPjJ5K8l xH6fZTi9Y69ynWTPYKdk4zY6j+Zmk80TdEzZ2UHFBQKUz1KRdDxFORIIsXDbVryPrUN6 nL1A== X-Gm-Message-State: APjAAAUkuAP8Wr0MsMWprYPd5bpYLUADqNOd/wepHdxSpcqYOeLYFdW8 bJOHOdxrURKtWk8PjemMW70sxat0/O0= X-Google-Smtp-Source: APXvYqybI2/9FPZMXyLAwScy6moHPB9T6Ha4YI/P+5mGCNaQpQ+B9Qn5twjWn3c5u3j7oIJ4YuL6hw== X-Received: by 2002:a62:6454:: with SMTP id y81mr10566137pfb.13.1559758196517; Wed, 05 Jun 2019 11:09:56 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id a7sm19081888pgj.42.2019.06.05.11.09.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jun 2019 11:09:55 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Andrew Rybchenko Date: Wed, 5 Jun 2019 11:09:44 -0700 Message-Id: <20190605180948.22414-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190605180948.22414-1-stephen@networkplumber.org> References: <20190516180427.17270-1-stephen@networkplumber.org> <20190605180948.22414-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v4 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" 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; } /** -- 2.20.1