[PATCH v3 2/2] virtio: simplify use of pragmas
Bruce Richardson
bruce.richardson at intel.com
Tue Aug 19 13:25:21 CEST 2025
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 at 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
More information about the dev
mailing list