From patchwork Fri Jun 26 16:51:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Morten_Br=C3=B8rup?= X-Patchwork-Id: 72275 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9A0C0A0520; Fri, 26 Jun 2020 18:51:43 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 905AC1BEB1; Fri, 26 Jun 2020 18:51:42 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by dpdk.org (Postfix) with ESMTP id E272E1BE9D for ; Fri, 26 Jun 2020 18:51:40 +0200 (CEST) Received: from dkrd2.smartsharesys.local ([192.168.4.12]) by smartserver.smartsharesystems.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 26 Jun 2020 18:51:40 +0200 From: =?utf-8?q?Morten_Br=C3=B8rup?= To: olivier.matz@6wind.com, ferruh.yigit@intel.com, harry.van.haaren@intel.com, konstantin.ananyev@intel.com, jerinjacobk@gmail.com Cc: dev@dpdk.org, =?utf-8?q?Morten_Br=C3=B8rup?= Date: Fri, 26 Jun 2020 18:51:35 +0200 Message-Id: <20200626165135.119557-1-mb@smartsharesystems.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-OriginalArrivalTime: 26 Jun 2020 16:51:40.0364 (UTC) FILETIME=[105F40C0:01D64BDA] Subject: [dpdk-dev] [PATCH] net: rte_ether minor optimizations 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" * rte_is_broadcast_ether_addr(): Use binary logic instead of comparisons and boolean logic, thus reducing the number of branches. It now resembles rte_is_zero_ether_addr(). * rte_ether_addr_copy(): The source code modifications were discussed on the mailing list: http://mails.dpdk.org/archives/dev/2020-June/171584.html Remove obsolete ICC-specific code and related comment. Restrict pointer aliasing (suggested by Jerin Jacob). Remove superfluous "Fast" from function description headline; all DPDK data plane functions are supposed to be fast. Signed-off-by: Morten Brørup Acked-by: Olivier Matz --- lib/librte_net/rte_ether.h | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h index 0ae4e75b6..184d972b6 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -146,10 +146,9 @@ static inline int rte_is_multicast_ether_addr(const struct rte_ether_addr *ea) */ static inline int rte_is_broadcast_ether_addr(const struct rte_ether_addr *ea) { - const uint16_t *ea_words = (const uint16_t *)ea; + const uint16_t *w = (const uint16_t *)ea; - return (ea_words[0] == 0xFFFF && ea_words[1] == 0xFFFF && - ea_words[2] == 0xFFFF); + return (w[0] & w[1] & w[2]) == 0xFFFF; } /** @@ -208,29 +207,18 @@ void rte_eth_random_addr(uint8_t *addr); /** - * Fast copy an Ethernet address. + * Copy an Ethernet address. * * @param ea_from * A pointer to a ether_addr structure holding the Ethernet address to copy. * @param ea_to * A pointer to a ether_addr structure where to copy the Ethernet address. */ -static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from, - struct rte_ether_addr *ea_to) +static inline void +rte_ether_addr_copy(const struct rte_ether_addr *__restrict ea_from, + struct rte_ether_addr *__restrict ea_to) { -#ifdef __INTEL_COMPILER - uint16_t *from_words = (uint16_t *)(ea_from->addr_bytes); - uint16_t *to_words = (uint16_t *)(ea_to->addr_bytes); - - to_words[0] = from_words[0]; - to_words[1] = from_words[1]; - to_words[2] = from_words[2]; -#else - /* - * Use the common way, because of a strange gcc warning. - */ *ea_to = *ea_from; -#endif } #define RTE_ETHER_ADDR_FMT_SIZE 18