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 F1A6FA045E for ; Wed, 29 May 2019 17:42:20 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4452E1B9C0; Wed, 29 May 2019 17:41:54 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 6726C1B9C0 for ; Wed, 29 May 2019 17:41:52 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 May 2019 08:41:51 -0700 X-ExtLoop1: 1 Received: from silpixa00399126.ir.intel.com (HELO silpixa00399126.ger.corp.intel.com) ([10.237.223.2]) by FMSMGA003.fm.intel.com with ESMTP; 29 May 2019 08:41:51 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson Date: Wed, 29 May 2019 16:41:32 +0100 Message-Id: <20190529154132.49955-5-bruce.richardson@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190529154132.49955-1-bruce.richardson@intel.com> References: <20190529154132.49955-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 4/4] net: replace ifdefs with runtime branches 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" Use the flag checking functions and a couple of empty stubs to remove the ifdefs from the middle of the C code, and replace them with more readable regular if statements. Other ifdefs at the top of the file are kept, but are not mixed with C code, so there is a clean separation. Signed-off-by: Bruce Richardson --- lib/librte_net/rte_net_crc.c | 38 ++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/lib/librte_net/rte_net_crc.c b/lib/librte_net/rte_net_crc.c index dca0830e2..3b8a09504 100644 --- a/lib/librte_net/rte_net_crc.c +++ b/lib/librte_net/rte_net_crc.c @@ -18,8 +18,17 @@ #ifdef X86_64_SSE42_PCLMULQDQ #include -#elif defined ARM64_NEON_PMULL +#else +/* define stubs for the SSE functions to avoid compiler errors */ +#define handlers_sse42 handlers_scalar +#define rte_net_crc_sse42_init() do { } while(0) +#endif + +#ifdef ARM64_NEON_PMULL #include +#else +#define handlers_neon handlers_scalar +#define rte_net_crc_neon_init() do { } while(0) #endif /* crc tables */ @@ -140,18 +149,19 @@ void rte_net_crc_set_alg(enum rte_net_crc_alg alg) { switch (alg) { -#ifdef X86_64_SSE42_PCLMULQDQ case RTE_NET_CRC_SSE42: - handlers = handlers_sse42; - break; -#elif defined ARM64_NEON_PMULL + if (rte_cpu_get_flagname_enabled(rte_cpu_arch_x86, + "RTE_CPUFLAG_SSE4_2")) { + handlers = handlers_sse42; + break; + } /* fall-through */ case RTE_NET_CRC_NEON: - if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_PMULL)) { + if (rte_cpu_get_flagname_enabled(rte_cpu_arch_arm, + "RTE_CPUFLAG_PMULL")) { handlers = handlers_neon; break; } -#endif /* fall-through */ case RTE_NET_CRC_SCALAR: /* fall-through */ @@ -182,15 +192,17 @@ RTE_INIT(rte_net_crc_init) rte_net_crc_scalar_init(); -#ifdef X86_64_SSE42_PCLMULQDQ - alg = RTE_NET_CRC_SSE42; - rte_net_crc_sse42_init(); -#elif defined ARM64_NEON_PMULL - if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_PMULL)) { + if (rte_cpu_get_flagname_enabled(rte_cpu_arch_x86, + "RTE_CPUFLAG_SSE4_2")) { + alg = RTE_NET_CRC_SSE42; + rte_net_crc_sse42_init(); + } + + if (rte_cpu_get_flagname_enabled(rte_cpu_arch_arm, + "RTE_CPUFLAG_PMULL")) { alg = RTE_NET_CRC_NEON; rte_net_crc_neon_init(); } -#endif rte_net_crc_set_alg(alg); } -- 2.21.0