From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C270AC46499 for ; Fri, 5 Jul 2019 17:17:11 +0000 (UTC) Received: from dpdk.org (dpdk.org [92.243.14.124]) by mail.kernel.org (Postfix) with ESMTP id 55AEC20989 for ; Fri, 5 Jul 2019 17:17:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=networkplumber-org.20150623.gappssmtp.com header.i=@networkplumber-org.20150623.gappssmtp.com header.b="pbhNqbe8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 55AEC20989 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=networkplumber.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 70CDC1BE33; Fri, 5 Jul 2019 19:16:46 +0200 (CEST) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by dpdk.org (Postfix) with ESMTP id 4373E1BE1E for ; Fri, 5 Jul 2019 19:16:40 +0200 (CEST) Received: by mail-pl1-f180.google.com with SMTP id a93so4893249pla.7 for ; Fri, 05 Jul 2019 10:16:40 -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=pbhNqbe8zA17fyuuhuZitxHMGtAIwnKdN53RRi/IzxPbo0C3uQ5U6CiBAcDawE+UDb AWGB1zAEhjt7iIMJg4X139c9hjiz0x1uHBLQUoT9Ne9YExl09i+tPEKUcHYRlX/Xakli uImEXV2A425kmL3+u58gOmRpWdFchU+tuoBunyPsnQ9nJ1owIbz3+fZ1BEIcoNOkuFoa g20r51PojBruFJMQqyO83unmTg2HSWqz4N7i9nA15RdX0eDinr15Ci6Iext6u35DxlQB Y1kS2pk9cCas7VadYqYmM5hUayVY9urMH9pzGjxGjZv+Oc04S8KHI+lixSfv/798xVKv 39kA== 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=VBYUsFntZI4AqQ4/ehEQNA4/ExFJntt+nYX3Dl+L/g6h4Ud20N33q4rfJdl7zMlZKT fMtYhgPcI5WbuHJxfxwPKlNVqetE0saZr50/zAoYBHmipa85Jp+lQJoDXB/LIEN9wM2P +NxHgkPx+rxN6KOlhEAVqKLoofS0OE66tt/Z5VXudlmuQl///7eKmAqlIGzY/6zzXvX0 EkGbas7lSotyq/eTgtBQ4gEil+046tlYBYoT5Y0x3QhR9/9ny+xtlQX3d2gRAZdMNkMI eYhg3X/ycF6mI8+3OSs84mc/wVDJQ37mmrpMLV/t1W2icB/TYX7roRlYMUyNJQyaiLLZ tkYQ== X-Gm-Message-State: APjAAAXl8E2pEgVXU2bf2IA5bGKX+rGdIA3QVuHDrUQunzobCxasOJjW MmLvOvYkGEyGKsL1+cvRfRWrEE6bsvs= X-Google-Smtp-Source: APXvYqyYVd5FZbVA4R6rWZ8CHIT6LIbPonUTY8pj82KT6QscEslRkXzeXebaJis1aF0D1ebQ2rkKJw== X-Received: by 2002:a17:902:e65:: with SMTP id 92mr6611931plw.13.1562346999243; Fri, 05 Jul 2019 10:16:39 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id 21sm8991014pjh.25.2019.07.05.10.16.38 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 05 Jul 2019 10:16:38 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Andrew Rybchenko , Olivier Matz Date: Fri, 5 Jul 2019 10:16:19 -0700 Message-Id: <20190705171626.13448-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190705171626.13448-1-stephen@networkplumber.org> References: <20190516180427.17270-1-stephen@networkplumber.org> <20190705171626.13448-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v8 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