From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH v3 2/2] virtio: simplify use of pragmas
Date: Tue, 19 Aug 2025 12:25:21 +0100 [thread overview]
Message-ID: <20250819112521.1608207-2-bruce.richardson@intel.com> (raw)
In-Reply-To: <20250819112521.1608207-1-bruce.richardson@intel.com>
In virtio/vhost there is use of pragmas to get clang or gcc to unroll
loops. This was originally done using compiler version checks in the
meson.build file, but with all supported gcc and clang versions now
supporting the needed pragmas, we can simplify things by just having the
headers check directly for gcc or clang.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
drivers/net/virtio/meson.build | 5 -----
drivers/net/virtio/virtio_rxtx_packed.h | 16 ++++++----------
lib/vhost/meson.build | 5 -----
lib/vhost/vhost.h | 14 +++++---------
4 files changed, 11 insertions(+), 29 deletions(-)
diff --git a/drivers/net/virtio/meson.build b/drivers/net/virtio/meson.build
index be653edb34..54a28538c3 100644
--- a/drivers/net/virtio/meson.build
+++ b/drivers/net/virtio/meson.build
@@ -29,11 +29,6 @@ if arch_subdir == 'x86'
if cc_has_avx512
cflags += ['-DVIRTIO_RXTX_PACKED_VEC']
sources_avx512 += files('virtio_rxtx_packed.c')
- if toolchain == 'gcc'
- cflags += '-DVIRTIO_GCC_UNROLL_PRAGMA'
- elif toolchain == 'clang'
- cflags += '-DVIRTIO_CLANG_UNROLL_PRAGMA'
- endif
endif
cflags += ['-DVIRTIO_RXTX_VEC']
sources += files('virtio_rxtx_simple_sse.c')
diff --git a/drivers/net/virtio/virtio_rxtx_packed.h b/drivers/net/virtio/virtio_rxtx_packed.h
index 12bfcee809..f7cc60bb51 100644
--- a/drivers/net/virtio/virtio_rxtx_packed.h
+++ b/drivers/net/virtio/virtio_rxtx_packed.h
@@ -67,19 +67,15 @@
#endif
#define PACKED_BATCH_MASK (PACKED_BATCH_SIZE - 1)
-#ifdef VIRTIO_GCC_UNROLL_PRAGMA
-#define virtio_for_each_try_unroll(iter, val, size) _Pragma("GCC unroll 4") \
- for (iter = val; iter < size; iter++)
-#endif
-
-#ifdef VIRTIO_CLANG_UNROLL_PRAGMA
+#if defined __clang__
#define virtio_for_each_try_unroll(iter, val, size) _Pragma("unroll 4") \
for (iter = val; iter < size; iter++)
-#endif
-
-#ifndef virtio_for_each_try_unroll
-#define virtio_for_each_try_unroll(iter, val, size) \
+#elif defined __GNUC__
+#define virtio_for_each_try_unroll(iter, val, size) _Pragma("GCC unroll 4") \
for (iter = val; iter < size; iter++)
+#else
+#define virtio_for_each_try_unroll(iter, val, num) \
+ for (iter = val; iter < num; iter++)
#endif
static inline void
diff --git a/lib/vhost/meson.build b/lib/vhost/meson.build
index 0a7a76f6db..6a24981d10 100644
--- a/lib/vhost/meson.build
+++ b/lib/vhost/meson.build
@@ -8,11 +8,6 @@ endif
if has_libnuma
dpdk_conf.set10('RTE_LIBRTE_VHOST_NUMA', true)
endif
-if toolchain == 'gcc'
- cflags += '-DVHOST_GCC_UNROLL_PRAGMA'
-elif toolchain == 'clang'
- cflags += '-DVHOST_CLANG_UNROLL_PRAGMA'
-endif
dpdk_conf.set('RTE_LIBRTE_VHOST_POSTCOPY', cc.has_header('linux/userfaultfd.h'))
cflags += no_wvla_cflag
diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h
index 6ffc3f20c1..e9e71c1707 100644
--- a/lib/vhost/vhost.h
+++ b/lib/vhost/vhost.h
@@ -69,17 +69,13 @@
sizeof(struct vring_packed_desc))
#define PACKED_BATCH_MASK (PACKED_BATCH_SIZE - 1)
-#ifdef VHOST_GCC_UNROLL_PRAGMA
-#define vhost_for_each_try_unroll(iter, val, size) _Pragma("GCC unroll 4") \
- for (iter = val; iter < size; iter++)
-#endif
-
-#ifdef VHOST_CLANG_UNROLL_PRAGMA
+#if defined __clang__
#define vhost_for_each_try_unroll(iter, val, size) _Pragma("unroll 4") \
for (iter = val; iter < size; iter++)
-#endif
-
-#ifndef vhost_for_each_try_unroll
+#elif defined __GNUC__
+#define vhost_for_each_try_unroll(iter, val, size) _Pragma("GCC unroll 4") \
+ for (iter = val; iter < size; iter++)
+#else
#define vhost_for_each_try_unroll(iter, val, num) \
for (iter = val; iter < num; iter++)
#endif
--
2.48.1
prev parent reply other threads:[~2025-08-19 11:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-18 12:14 [PATCH] build: remove obsolete compiler checks Bruce Richardson
2025-07-18 12:21 ` David Marchand
2025-07-18 12:34 ` Bruce Richardson
2025-07-18 12:45 ` David Marchand
2025-07-18 13:05 ` Bruce Richardson
2025-07-18 13:36 ` David Marchand
2025-07-25 16:06 ` [PATCH v2] " Bruce Richardson
2025-07-28 18:18 ` Stephen Hemminger
2025-08-19 8:10 ` David Marchand
2025-08-19 9:04 ` Bruce Richardson
2025-08-19 11:10 ` Bruce Richardson
2025-08-19 11:25 ` [PATCH v3 1/2] " Bruce Richardson
2025-08-19 11:25 ` Bruce Richardson [this message]
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=20250819112521.1608207-2-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).