DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH 1/2] build/x86: remove conditional checks for AVX2 support
Date: Thu, 27 Jul 2023 10:31:06 +0100	[thread overview]
Message-ID: <20230727093107.7242-2-bruce.richardson@intel.com> (raw)
In-Reply-To: <20230727093107.7242-1-bruce.richardson@intel.com>

In a number of libraries and drivers we have multiple levels of checks
for enabling AVX2 support. In these cases:

* we first check for AVX2 support in the build-time ISA, i.e. through
  the instruction-set/-march flag. If present, we add source file to the
  list of sources.
* if not enabled at the minimum instruction-set level, i.e. a
  default/generic build, we then check for compiler support for AVX2
  and, if available, did a separate build of the AVX2 file using an
  additional flag to enable the instruction set.

While this works, and was necessary in older releases, we no longer need
this level of complexity, as all supported DPDK compilers have support
for AVX2. This makes the second check unnecessary.

However, when we look at the effect of the second option above vs the
first, the only real difference is that in the second case, we add an
additional "-mavx2" to the build flags. This flag simply makes the
instruction set available for use, so should be harmless in the case
where the "march" flag already has that instruction set available.
Therefore, we can remove the check for the first case also, and always
use the fallback case with the extra flag.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 drivers/net/bnxt/meson.build | 27 ++++++++++-----------------
 drivers/net/enic/meson.build | 10 +++-------
 drivers/net/i40e/meson.build | 23 +++++++----------------
 drivers/net/iavf/meson.build | 23 +++++++----------------
 drivers/net/ice/meson.build  | 22 +++++++---------------
 lib/acl/meson.build          | 24 ++++++------------------
 6 files changed, 40 insertions(+), 89 deletions(-)

diff --git a/drivers/net/bnxt/meson.build b/drivers/net/bnxt/meson.build
index c7a0d5f6c9..c223a21002 100644
--- a/drivers/net/bnxt/meson.build
+++ b/drivers/net/bnxt/meson.build
@@ -53,23 +53,16 @@ subdir('hcapi/cfa')
 
 if arch_subdir == 'x86'
     sources += files('bnxt_rxtx_vec_sse.c')
-    # compile AVX2 version if either:
-    # a. we have AVX supported in minimum instruction set baseline
-    # b. it's not minimum instruction set, but supported by compiler
-    if cc.get_define('__AVX2__', args: machine_args) != ''
-            cflags += ['-DCC_AVX2_SUPPORT']
-            sources += files('bnxt_rxtx_vec_avx2.c')
-    elif cc.has_argument('-mavx2')
-            cflags += ['-DCC_AVX2_SUPPORT']
-            bnxt_avx2_lib = static_library('bnxt_avx2_lib',
-                            'bnxt_rxtx_vec_avx2.c',
-                            dependencies: [static_rte_ethdev,
-                                    static_rte_bus_pci,
-                                    static_rte_kvargs, static_rte_hash],
-                            include_directories: includes,
-                            c_args: [cflags, '-mavx2'])
-            objs += bnxt_avx2_lib.extract_objects('bnxt_rxtx_vec_avx2.c')
-     endif
+    cflags += ['-DCC_AVX2_SUPPORT']
+    # build AVX2 code with instruction set explicitly enabled for runtime selection
+    bnxt_avx2_lib = static_library('bnxt_avx2_lib',
+            'bnxt_rxtx_vec_avx2.c',
+            dependencies: [static_rte_ethdev,
+                static_rte_bus_pci,
+                static_rte_kvargs, static_rte_hash],
+            include_directories: includes,
+            c_args: [cflags, '-mavx2'])
+     objs += bnxt_avx2_lib.extract_objects('bnxt_rxtx_vec_avx2.c')
 elif arch_subdir == 'arm' and dpdk_conf.get('RTE_ARCH_64')
     sources += files('bnxt_rxtx_vec_neon.c')
 endif
diff --git a/drivers/net/enic/meson.build b/drivers/net/enic/meson.build
index 77dcd9e7ec..8700ae27f2 100644
--- a/drivers/net/enic/meson.build
+++ b/drivers/net/enic/meson.build
@@ -28,14 +28,10 @@ sources = files(
 deps += ['hash']
 includes += include_directories('base')
 
-# The current implementation assumes 64-bit pointers
-if cc.get_define('__AVX2__', args: machine_args) != '' and dpdk_conf.get('RTE_ARCH_64')
-    sources += files('enic_rxtx_vec_avx2.c')
-# Build the avx2 handler if the compiler supports it, even though 'machine'
-# does not. This is to support users who build for the min supported machine
+# Build the avx2 handler for 64-bit X86 targets, even though 'machine'
+# may not. This is to support users who build for the min supported machine
 # and need to run the binary on newer CPUs too.
-# This part is from i40e meson.build
-elif cc.has_argument('-mavx2') and dpdk_conf.get('RTE_ARCH_64')
+if dpdk_conf.has('RTE_ARCH_X86_64')
     enic_avx2_lib = static_library('enic_avx2_lib',
             'enic_rxtx_vec_avx2.c',
             dependencies: [static_rte_ethdev, static_rte_bus_pci],
diff --git a/drivers/net/i40e/meson.build b/drivers/net/i40e/meson.build
index 8e53b87a65..46600520e1 100644
--- a/drivers/net/i40e/meson.build
+++ b/drivers/net/i40e/meson.build
@@ -49,22 +49,13 @@ if arch_subdir == 'x86'
         cflags += ['-fno-asynchronous-unwind-tables']
     endif
 
-    # compile AVX2 version if either:
-    # a. we have AVX supported in minimum instruction set baseline
-    # b. it's not minimum instruction set, but supported by compiler
-    if cc.get_define('__AVX2__', args: machine_args) != ''
-        cflags += ['-DCC_AVX2_SUPPORT']
-        sources += files('i40e_rxtx_vec_avx2.c')
-    elif cc.has_argument('-mavx2')
-        cflags += ['-DCC_AVX2_SUPPORT']
-        i40e_avx2_lib = static_library('i40e_avx2_lib',
-                'i40e_rxtx_vec_avx2.c',
-                dependencies: [static_rte_ethdev,
-                    static_rte_kvargs, static_rte_hash],
-                include_directories: includes,
-                c_args: [cflags, '-mavx2'])
-        objs += i40e_avx2_lib.extract_objects('i40e_rxtx_vec_avx2.c')
-    endif
+    cflags += ['-DCC_AVX2_SUPPORT']
+    i40e_avx2_lib = static_library('i40e_avx2_lib',
+            'i40e_rxtx_vec_avx2.c',
+            dependencies: [static_rte_ethdev, static_rte_kvargs, static_rte_hash],
+            include_directories: includes,
+            c_args: [cflags, '-mavx2'])
+    objs += i40e_avx2_lib.extract_objects('i40e_rxtx_vec_avx2.c')
 
     i40e_avx512_cpu_support = (
         cc.get_define('__AVX512F__', args: machine_args) != '' and
diff --git a/drivers/net/iavf/meson.build b/drivers/net/iavf/meson.build
index fc09ffa2ae..ff949ef92b 100644
--- a/drivers/net/iavf/meson.build
+++ b/drivers/net/iavf/meson.build
@@ -29,22 +29,13 @@ if arch_subdir == 'x86'
         cflags += ['-fno-asynchronous-unwind-tables']
     endif
 
-    # compile AVX2 version if either:
-    # a. we have AVX supported in minimum instruction set baseline
-    # b. it's not minimum instruction set, but supported by compiler
-    if cc.get_define('__AVX2__', args: machine_args) != ''
-        cflags += ['-DCC_AVX2_SUPPORT']
-        sources += files('iavf_rxtx_vec_avx2.c')
-    elif cc.has_argument('-mavx2')
-        cflags += ['-DCC_AVX2_SUPPORT']
-        iavf_avx2_lib = static_library('iavf_avx2_lib',
-                'iavf_rxtx_vec_avx2.c',
-                dependencies: [static_rte_ethdev,
-                    static_rte_kvargs, static_rte_hash],
-                include_directories: includes,
-                c_args: [cflags, '-mavx2'])
-        objs += iavf_avx2_lib.extract_objects('iavf_rxtx_vec_avx2.c')
-    endif
+    cflags += ['-DCC_AVX2_SUPPORT']
+    iavf_avx2_lib = static_library('iavf_avx2_lib',
+            'iavf_rxtx_vec_avx2.c',
+            dependencies: [static_rte_ethdev, static_rte_kvargs, static_rte_hash],
+            include_directories: includes,
+            c_args: [cflags, '-mavx2'])
+    objs += iavf_avx2_lib.extract_objects('iavf_rxtx_vec_avx2.c')
 
     iavf_avx512_cpu_support = (
         cc.get_define('__AVX512F__', args: machine_args) != '' and
diff --git a/drivers/net/ice/meson.build b/drivers/net/ice/meson.build
index 460528854a..98288f6ac0 100644
--- a/drivers/net/ice/meson.build
+++ b/drivers/net/ice/meson.build
@@ -28,21 +28,13 @@ if arch_subdir == 'x86'
         cflags += ['-fno-asynchronous-unwind-tables']
     endif
 
-    # compile AVX2 version if either:
-    # a. we have AVX supported in minimum instruction set baseline
-    # b. it's not minimum instruction set, but supported by compiler
-    if cc.get_define('__AVX2__', args: machine_args) != ''
-        cflags += ['-DCC_AVX2_SUPPORT']
-        sources += files('ice_rxtx_vec_avx2.c')
-    elif cc.has_argument('-mavx2')
-        cflags += ['-DCC_AVX2_SUPPORT']
-        ice_avx2_lib = static_library('ice_avx2_lib',
-                'ice_rxtx_vec_avx2.c',
-                dependencies: [static_rte_ethdev, static_rte_kvargs, static_rte_hash],
-                include_directories: includes,
-                c_args: [cflags, '-mavx2'])
-        objs += ice_avx2_lib.extract_objects('ice_rxtx_vec_avx2.c')
-    endif
+    cflags += ['-DCC_AVX2_SUPPORT']
+    ice_avx2_lib = static_library('ice_avx2_lib',
+            'ice_rxtx_vec_avx2.c',
+            dependencies: [static_rte_ethdev, static_rte_kvargs, static_rte_hash],
+            include_directories: includes,
+            c_args: [cflags, '-mavx2'])
+    objs += ice_avx2_lib.extract_objects('ice_rxtx_vec_avx2.c')
 
     ice_avx512_cpu_support = (
             cc.get_define('__AVX512F__', args: machine_args) != '' and
diff --git a/lib/acl/meson.build b/lib/acl/meson.build
index fbe17f9454..87f19757a8 100644
--- a/lib/acl/meson.build
+++ b/lib/acl/meson.build
@@ -14,24 +14,12 @@ headers = files('rte_acl.h', 'rte_acl_osdep.h')
 if dpdk_conf.has('RTE_ARCH_X86')
     sources += files('acl_run_sse.c')
 
-    # compile AVX2 version if either:
-    # a. we have AVX supported in minimum instruction set baseline
-    # b. it's not minimum instruction set, but supported by compiler
-    #
-    # in former case, just add avx2 C file to files list
-    # in latter case, compile c file to static lib, using correct compiler
-    # flags, and then have the .o file from static lib linked into main lib.
-    if cc.get_define('__AVX2__', args: machine_args) != ''
-        sources += files('acl_run_avx2.c')
-        cflags += '-DCC_AVX2_SUPPORT'
-    elif cc.has_argument('-mavx2')
-        avx2_tmplib = static_library('avx2_tmp',
-                'acl_run_avx2.c',
-                dependencies: static_rte_eal,
-                c_args: cflags + ['-mavx2'])
-        objs += avx2_tmplib.extract_objects('acl_run_avx2.c')
-        cflags += '-DCC_AVX2_SUPPORT'
-    endif
+    cflags += '-DCC_AVX2_SUPPORT'
+    avx2_tmplib = static_library('avx2_tmp',
+            'acl_run_avx2.c',
+            dependencies: static_rte_eal,
+            c_args: cflags + ['-mavx2'])
+    objs += avx2_tmplib.extract_objects('acl_run_avx2.c')
 
     # compile AVX512 version if:
     # we are building 64-bit binary AND binutils can generate proper code
-- 
2.39.2


  reply	other threads:[~2023-07-27  9:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-27  9:31 [PATCH 0/2] simplify building x86 code with " Bruce Richardson
2023-07-27  9:31 ` Bruce Richardson [this message]
2023-07-27  9:31 ` [PATCH 2/2] build: remove unnecessary AVX2 compiler flag Bruce Richardson
2023-10-12 12:37 ` [PATCH 0/2] simplify building x86 code with AVX2 support David Marchand

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=20230727093107.7242-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).