From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [dpdk-dev] [PATCH 4/4] net: replace ifdefs with runtime branches
Date: Wed, 29 May 2019 16:41:32 +0100 [thread overview]
Message-ID: <20190529154132.49955-5-bruce.richardson@intel.com> (raw)
In-Reply-To: <20190529154132.49955-1-bruce.richardson@intel.com>
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 <bruce.richardson@intel.com>
---
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 <net_crc_sse.h>
-#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 <net_crc_neon.h>
+#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
next prev parent reply other threads:[~2019-05-29 15:42 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-29 15:41 [dpdk-dev] [PATCH 0/4] Enhance CPU flag support Bruce Richardson
2019-05-29 15:41 ` [dpdk-dev] [PATCH 1/4] build: fix quoting on RTE_ARCH string value Bruce Richardson
2019-05-29 15:53 ` Luca Boccassi
2019-05-29 15:41 ` [dpdk-dev] [PATCH 2/4] config/arm: fix missing define for arm platforms Bruce Richardson
2019-05-29 15:41 ` [dpdk-dev] [PATCH 3/4] eal: allow checking CPU flags by name Bruce Richardson
2019-06-27 13:22 ` David Marchand
2019-06-28 12:40 ` Bruce Richardson
2019-06-28 13:34 ` David Marchand
2019-05-29 15:41 ` Bruce Richardson [this message]
2019-07-01 19:30 ` [dpdk-dev] [PATCH 4/4] net: replace ifdefs with runtime branches Thomas Monjalon
2019-07-01 20:41 ` Bruce Richardson
2019-07-04 20:20 ` Thomas Monjalon
2019-07-08 17:24 ` David Christensen
2019-06-27 12:39 ` [dpdk-dev] [PATCH 0/4] Enhance CPU flag support Ananyev, Konstantin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190529154132.49955-5-bruce.richardson@intel.com \
--to=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).