From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by dpdk.org (Postfix) with ESMTP id 2E5955F1C for ; Thu, 16 May 2019 00:20:06 +0200 (CEST) Received: by mail-pg1-f180.google.com with SMTP id t187so459263pgb.13 for ; Wed, 15 May 2019 15:20:06 -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=usySncatsxV2VcU8J+VYqa3cdTtdmtHu06jkvUhvS04=; b=Y/vfVpHeN8TDoC+xF/c/458NwxocPHgUZWIhw23dUF2TFz+v47WBRTH//eWg+PN6zg 9a3Vo4fkFWdIfwLa6ff4kLBNQH75f3c4aVo8lNHQgHAqwHw2wVijE4BmeLBeGCtiYdf6 htxM02vDnZIt53RihUVzlxVCcXkiGT7VVXchgwKjfyKVxv+VcxcLZZzfSDTPu7uH6Hwd OMB++dd/BGJmp7M/X5iLo1FudtrqQ346yH2pdtgWWZZMrmccMDJbNEAN1LyOwujGzIen VAO7AJFQgVTYIP47wlga6BuNW5z/WxdAJSOnEndgGR7V6jmXfH1PnITV25ZxxDsinwMj dfmQ== 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=usySncatsxV2VcU8J+VYqa3cdTtdmtHu06jkvUhvS04=; b=KSu4UGmd5DtQuzDEtwWvGEXF3RidS4CQPCjxaoTwPNC/CGPB4/ehd7CUBHqrG/26gA XoUNHjoHTAdy4XR9QhJIrkhjCybxnUGj0JMOKMxornTcvX4H+0BH5vHu2I4A9aRw0Yu4 mH0ncPKIOl3ZOJQw0r9LzFRXfUH2uojmk0ZxiNvPBLgAwPaH12LYYr7coPJZ0lK6E4vm fxYWxoaGLS5pxPckx7prgd3YDyBeRwhaDla2+5l5SQG5Ph/bGQFBXC7ysoiAYuCYBnhP 3A2MLlgRsdp+9MuI2AJZbIzuikFgLZ8R/AjnMk+Q3QNqITWhM9GtN7DyecLFIifqUPtM jyvw== X-Gm-Message-State: APjAAAU0iE6TmTKlnGUfVeAFFngN5xHP2t6MpM0/B68HeQ+oxG/88Un3 RgwYIua5lSMUokMfPzyzz+J+k87aLUY= X-Google-Smtp-Source: APXvYqzgjJ/WkrQMiS6AeLu6qwDmZ0JESuuaqHHJygQCr0RIPuEB69tyMFsmgBfMuR332leESJQcLw== X-Received: by 2002:a63:6ac1:: with SMTP id f184mr47439282pgc.25.1557958805080; Wed, 15 May 2019 15:20:05 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id d5sm3549964pgb.33.2019.05.15.15.20.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 May 2019 15:20:04 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Wed, 15 May 2019 15:19:52 -0700 Message-Id: <20190515221952.21959-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190515221952.21959-1-stephen@networkplumber.org> References: <20190515221952.21959-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [RFC 4/4] 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: , X-List-Received-Date: Wed, 15 May 2019 22:20:06 -0000 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 b94e64b2195e..5d9242cda230 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -78,11 +78,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 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; } /** @@ -97,11 +96,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 unaligned_uint16_t *w = (const uint16_t *)ea; + + return (w[0] | w[1] | w[2]) == 0; } /** -- 2.20.1 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 74E9CA00E6 for ; Thu, 16 May 2019 00:20:39 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3AE885F34; Thu, 16 May 2019 00:20:10 +0200 (CEST) Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by dpdk.org (Postfix) with ESMTP id 2E5955F1C for ; Thu, 16 May 2019 00:20:06 +0200 (CEST) Received: by mail-pg1-f180.google.com with SMTP id t187so459263pgb.13 for ; Wed, 15 May 2019 15:20:06 -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=usySncatsxV2VcU8J+VYqa3cdTtdmtHu06jkvUhvS04=; b=Y/vfVpHeN8TDoC+xF/c/458NwxocPHgUZWIhw23dUF2TFz+v47WBRTH//eWg+PN6zg 9a3Vo4fkFWdIfwLa6ff4kLBNQH75f3c4aVo8lNHQgHAqwHw2wVijE4BmeLBeGCtiYdf6 htxM02vDnZIt53RihUVzlxVCcXkiGT7VVXchgwKjfyKVxv+VcxcLZZzfSDTPu7uH6Hwd OMB++dd/BGJmp7M/X5iLo1FudtrqQ346yH2pdtgWWZZMrmccMDJbNEAN1LyOwujGzIen VAO7AJFQgVTYIP47wlga6BuNW5z/WxdAJSOnEndgGR7V6jmXfH1PnITV25ZxxDsinwMj dfmQ== 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=usySncatsxV2VcU8J+VYqa3cdTtdmtHu06jkvUhvS04=; b=KSu4UGmd5DtQuzDEtwWvGEXF3RidS4CQPCjxaoTwPNC/CGPB4/ehd7CUBHqrG/26gA XoUNHjoHTAdy4XR9QhJIrkhjCybxnUGj0JMOKMxornTcvX4H+0BH5vHu2I4A9aRw0Yu4 mH0ncPKIOl3ZOJQw0r9LzFRXfUH2uojmk0ZxiNvPBLgAwPaH12LYYr7coPJZ0lK6E4vm fxYWxoaGLS5pxPckx7prgd3YDyBeRwhaDla2+5l5SQG5Ph/bGQFBXC7ysoiAYuCYBnhP 3A2MLlgRsdp+9MuI2AJZbIzuikFgLZ8R/AjnMk+Q3QNqITWhM9GtN7DyecLFIifqUPtM jyvw== X-Gm-Message-State: APjAAAU0iE6TmTKlnGUfVeAFFngN5xHP2t6MpM0/B68HeQ+oxG/88Un3 RgwYIua5lSMUokMfPzyzz+J+k87aLUY= X-Google-Smtp-Source: APXvYqzgjJ/WkrQMiS6AeLu6qwDmZ0JESuuaqHHJygQCr0RIPuEB69tyMFsmgBfMuR332leESJQcLw== X-Received: by 2002:a63:6ac1:: with SMTP id f184mr47439282pgc.25.1557958805080; Wed, 15 May 2019 15:20:05 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id d5sm3549964pgb.33.2019.05.15.15.20.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 May 2019 15:20:04 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Wed, 15 May 2019 15:19:52 -0700 Message-Id: <20190515221952.21959-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190515221952.21959-1-stephen@networkplumber.org> References: <20190515221952.21959-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [RFC 4/4] 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" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190515221952.KRFF7LTFXFWU-I4ptKUnbf3c0JzGkYcWOYaKdEAYFHc@z> 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 b94e64b2195e..5d9242cda230 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -78,11 +78,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 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; } /** @@ -97,11 +96,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 unaligned_uint16_t *w = (const uint16_t *)ea; + + return (w[0] | w[1] | w[2]) == 0; } /** -- 2.20.1