qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>
Subject: [PULL 06/30] configure, meson: move AVX tests to meson
Date: Tue, 15 Feb 2022 10:31:59 +0100	[thread overview]
Message-ID: <20220215093223.110827-7-pbonzini@redhat.com> (raw)
In-Reply-To: <20220215093223.110827-1-pbonzini@redhat.com>

For consistency with other tests, --enable-avx2 and --enable-avx512f
fail to compile on x86 systems if cpuid.h is not available.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 configure                     | 103 ----------------------------------
 meson.build                   |  50 ++++++++++++++++-
 meson_options.txt             |   4 ++
 scripts/meson-buildoptions.sh |   6 ++
 4 files changed, 58 insertions(+), 105 deletions(-)

diff --git a/configure b/configure
index 3a29eff5cc..a6a577277f 100755
--- a/configure
+++ b/configure
@@ -323,8 +323,6 @@ qom_cast_debug="yes"
 trace_backends="log"
 trace_file="trace"
 opengl="$default_feature"
-cpuid_h="no"
-avx2_opt="$default_feature"
 guest_agent="$default_feature"
 vss_win32_sdk="$default_feature"
 win_sdk="no"
@@ -1033,14 +1031,6 @@ for opt do
   ;;
   --disable-tools) want_tools="no"
   ;;
-  --disable-avx2) avx2_opt="no"
-  ;;
-  --enable-avx2) avx2_opt="yes"
-  ;;
-  --disable-avx512f) avx512f_opt="no"
-  ;;
-  --enable-avx512f) avx512f_opt="yes"
-  ;;
   --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
       echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
   ;;
@@ -1406,8 +1396,6 @@ cat << EOF
   coroutine-pool  coroutine freelist (better performance)
   tpm             TPM support
   numa            libnuma support
-  avx2            AVX2 optimization support
-  avx512f         AVX512F optimization support
   replication     replication support
   opengl          opengl support
   qom-cast-debug  cast debugging support
@@ -2740,85 +2728,6 @@ else # "$safe_stack" = ""
 fi
 fi
 
-########################################
-# check if cpuid.h is usable.
-
-cat > $TMPC << EOF
-#include <cpuid.h>
-int main(void) {
-    unsigned a, b, c, d;
-    unsigned max = __get_cpuid_max(0, 0);
-
-    if (max >= 1) {
-        __cpuid(1, a, b, c, d);
-    }
-
-    if (max >= 7) {
-        __cpuid_count(7, 0, a, b, c, d);
-    }
-
-    return 0;
-}
-EOF
-if compile_prog "" "" ; then
-    cpuid_h=yes
-fi
-
-##########################################
-# avx2 optimization requirement check
-#
-# There is no point enabling this if cpuid.h is not usable,
-# since we won't be able to select the new routines.
-
-if test "$cpuid_h" = "yes" && test "$avx2_opt" != "no"; then
-  cat > $TMPC << EOF
-#pragma GCC push_options
-#pragma GCC target("avx2")
-#include <cpuid.h>
-#include <immintrin.h>
-static int bar(void *a) {
-    __m256i x = *(__m256i *)a;
-    return _mm256_testz_si256(x, x);
-}
-int main(int argc, char *argv[]) { return bar(argv[0]); }
-EOF
-  if compile_object "-Werror" ; then
-    avx2_opt="yes"
-  else
-    avx2_opt="no"
-  fi
-fi
-
-##########################################
-# avx512f optimization requirement check
-#
-# There is no point enabling this if cpuid.h is not usable,
-# since we won't be able to select the new routines.
-# by default, it is turned off.
-# if user explicitly want to enable it, check environment
-
-if test "$cpuid_h" = "yes" && test "$avx512f_opt" = "yes"; then
-  cat > $TMPC << EOF
-#pragma GCC push_options
-#pragma GCC target("avx512f")
-#include <cpuid.h>
-#include <immintrin.h>
-static int bar(void *a) {
-    __m512i x = *(__m512i *)a;
-    return _mm512_test_epi64_mask(x, x);
-}
-int main(int argc, char *argv[])
-{
-	return bar(argv[0]);
-}
-EOF
-  if ! compile_object "-Werror" ; then
-    avx512f_opt="no"
-  fi
-else
-  avx512f_opt="no"
-fi
-
 ########################################
 # check if __[u]int128_t is usable.
 
@@ -3419,14 +3328,6 @@ if test "$opengl" = "yes" ; then
   echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
 fi
 
-if test "$avx2_opt" = "yes" ; then
-  echo "CONFIG_AVX2_OPT=y" >> $config_host_mak
-fi
-
-if test "$avx512f_opt" = "yes" ; then
-  echo "CONFIG_AVX512F_OPT=y" >> $config_host_mak
-fi
-
 # XXX: suppress that
 if [ "$bsd" = "yes" ] ; then
   echo "CONFIG_BSD=y" >> $config_host_mak
@@ -3459,10 +3360,6 @@ if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
     echo "CONFIG_TSAN=y" >> $config_host_mak
 fi
 
-if test "$cpuid_h" = "yes" ; then
-  echo "CONFIG_CPUID_H=y" >> $config_host_mak
-fi
-
 if test "$int128" = "yes" ; then
   echo "CONFIG_INT128=y" >> $config_host_mak
 fi
diff --git a/meson.build b/meson.build
index 15dfd66a3e..7a262051b7 100644
--- a/meson.build
+++ b/meson.build
@@ -1762,6 +1762,52 @@ config_host_data.set('CONFIG_GETAUXVAL', cc.links(gnu_source_prefix + '''
     return getauxval(AT_HWCAP) == 0;
   }'''))
 
+have_cpuid_h = cc.links('''
+  #include <cpuid.h>
+  int main(void) {
+    unsigned a, b, c, d;
+    unsigned max = __get_cpuid_max(0, 0);
+
+    if (max >= 1) {
+        __cpuid(1, a, b, c, d);
+    }
+
+    if (max >= 7) {
+        __cpuid_count(7, 0, a, b, c, d);
+    }
+
+    return 0;
+  }''')
+config_host_data.set('CONFIG_CPUID_H', have_cpuid_h)
+
+config_host_data.set('CONFIG_AVX2_OPT', get_option('avx2') \
+  .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot enable AVX2') \
+  .require(cc.links('''
+    #pragma GCC push_options
+    #pragma GCC target("avx2")
+    #include <cpuid.h>
+    #include <immintrin.h>
+    static int bar(void *a) {
+      __m256i x = *(__m256i *)a;
+      return _mm256_testz_si256(x, x);
+    }
+    int main(int argc, char *argv[]) { return bar(argv[0]); }
+  '''), error_message: 'AVX2 not available').allowed())
+
+config_host_data.set('CONFIG_AVX512F_OPT', get_option('avx512f') \
+  .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot enable AVX512F') \
+  .require(cc.links('''
+    #pragma GCC push_options
+    #pragma GCC target("avx512f")
+    #include <cpuid.h>
+    #include <immintrin.h>
+    static int bar(void *a) {
+      __m512i x = *(__m512i *)a;
+      return _mm512_test_epi64_mask(x, x);
+    }
+    int main(int argc, char *argv[]) { return bar(argv[0]); }
+  '''), error_message: 'AVX512F not available').allowed())
+
 config_host_data.set('CONFIG_AF_VSOCK', cc.compiles(gnu_source_prefix + '''
   #include <errno.h>
   #include <sys/types.h>
@@ -3289,8 +3335,8 @@ summary_info += {'membarrier':        config_host.has_key('CONFIG_MEMBARRIER')}
 summary_info += {'debug stack usage': config_host.has_key('CONFIG_DEBUG_STACK_USAGE')}
 summary_info += {'mutex debugging':   config_host.has_key('CONFIG_DEBUG_MUTEX')}
 summary_info += {'memory allocator':  get_option('malloc')}
-summary_info += {'avx2 optimization': config_host.has_key('CONFIG_AVX2_OPT')}
-summary_info += {'avx512f optimization': config_host.has_key('CONFIG_AVX512F_OPT')}
+summary_info += {'avx2 optimization': config_host_data.get('CONFIG_AVX2_OPT')}
+summary_info += {'avx512f optimization': config_host_data.get('CONFIG_AVX512F_OPT')}
 summary_info += {'gprof enabled':     config_host.has_key('CONFIG_GPROF')}
 summary_info += {'gcov':              get_option('b_coverage')}
 summary_info += {'thread sanitizer':  config_host.has_key('CONFIG_TSAN')}
diff --git a/meson_options.txt b/meson_options.txt
index 95d527f773..6ff349023c 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -68,6 +68,10 @@ option('multiprocess', type: 'feature', value: 'auto',
        description: 'Out of process device emulation support')
 option('dbus_display', type: 'feature', value: 'auto',
        description: '-display dbus support')
+option('avx2', type: 'feature', value: 'auto',
+       description: 'AVX2 optimizations')
+option('avx512f', type: 'feature', value: 'disabled',
+       description: 'AVX512F optimizations')
 
 option('attr', type : 'feature', value : 'auto',
        description: 'attr/xattr support')
diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh
index 48a454cece..dcfc39ec6b 100644
--- a/scripts/meson-buildoptions.sh
+++ b/scripts/meson-buildoptions.sh
@@ -26,6 +26,8 @@ meson_options_help() {
   printf "%s\n" '  alsa            ALSA sound support'
   printf "%s\n" '  attr            attr/xattr support'
   printf "%s\n" '  auth-pam        PAM access control'
+  printf "%s\n" '  avx2            AVX2 optimizations'
+  printf "%s\n" '  avx512f         AVX512F optimizations'
   printf "%s\n" '  bpf             eBPF support'
   printf "%s\n" '  brlapi          brlapi character device driver'
   printf "%s\n" '  bzip2           bzip2 support for DMG images'
@@ -109,6 +111,10 @@ _meson_option_parse() {
     --disable-attr) printf "%s" -Dattr=disabled ;;
     --enable-auth-pam) printf "%s" -Dauth_pam=enabled ;;
     --disable-auth-pam) printf "%s" -Dauth_pam=disabled ;;
+    --enable-avx2) printf "%s" -Davx2=enabled ;;
+    --disable-avx2) printf "%s" -Davx2=disabled ;;
+    --enable-avx512f) printf "%s" -Davx512f=enabled ;;
+    --disable-avx512f) printf "%s" -Davx512f=disabled ;;
     --enable-bpf) printf "%s" -Dbpf=enabled ;;
     --disable-bpf) printf "%s" -Dbpf=disabled ;;
     --enable-brlapi) printf "%s" -Dbrlapi=enabled ;;
-- 
2.34.1




  parent reply	other threads:[~2022-02-15  9:37 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-15  9:31 [PULL 00/30] Misc mostly build system patches for 2022-02-15 Paolo Bonzini
2022-02-15  9:31 ` [PULL 01/30] target/i386: add TCG support for UMIP Paolo Bonzini
2022-02-15  9:31 ` [PULL 02/30] memory: Fix qemu crash on starting dirty log twice with stopped VM Paolo Bonzini
2022-02-15  9:31 ` [PULL 03/30] tests/qemu-iotests/testrunner: Print diff to stderr in TAP mode Paolo Bonzini
2022-02-15  9:31 ` [PULL 04/30] meson: use .allowed() method for features Paolo Bonzini
2022-02-15  9:31 ` [PULL 05/30] meson: use .require() and .disable_auto_if() " Paolo Bonzini
2022-02-15  9:31 ` Paolo Bonzini [this message]
2022-02-15  9:32 ` [PULL 07/30] configure, meson: move membarrier test to meson Paolo Bonzini
2022-02-15  9:32 ` [PULL 08/30] configure, meson: move AF_ALG " Paolo Bonzini
2022-02-15  9:32 ` [PULL 09/30] configure, meson: move libnuma detection " Paolo Bonzini
2022-02-15  9:32 ` [PULL 10/30] configure, meson: move TPM check " Paolo Bonzini
2022-02-15  9:32 ` [PULL 11/30] configure, meson: cleanup qemu-ga libraries Paolo Bonzini
2022-02-15  9:32 ` [PULL 12/30] configure, meson: move image format options to meson_options.txt Paolo Bonzini
2022-02-15  9:32 ` [PULL 13/30] configure, meson: move block layer " Paolo Bonzini
2022-02-15  9:32 ` [PULL 14/30] meson: define qemu_cflags/qemu_ldflags Paolo Bonzini
2022-02-15  9:32 ` [PULL 15/30] configure, meson: move some default-disabled options to meson_options.txt Paolo Bonzini
2023-04-11  9:42   ` Peter Maydell
2022-02-15  9:32 ` [PULL 16/30] configure, meson: move coroutine " Paolo Bonzini
2022-02-15  9:32 ` [PULL 17/30] configure, meson: move smbd " Paolo Bonzini
2022-02-15  9:32 ` [PULL 18/30] configure, meson: move guest-agent, tools to meson Paolo Bonzini
2022-03-17 22:34   ` Brad Smith
2022-02-15  9:32 ` [PULL 19/30] meson: refine check for whether to look for virglrenderer Paolo Bonzini
2022-02-15  9:32 ` [PULL 20/30] configure, meson: move OpenGL check to meson Paolo Bonzini
2022-02-15  9:32 ` [PULL 21/30] qga/vss-win32: fix midl arguments Paolo Bonzini
2022-02-15  9:32 ` [PULL 22/30] meson: drop --with-win-sdk Paolo Bonzini
2022-02-15  9:32 ` [PULL 23/30] qga/vss-win32: use widl if available Paolo Bonzini
2022-02-15  9:32 ` [PULL 24/30] qga/vss: use standard windows headers location Paolo Bonzini
2022-02-15  9:32 ` [PULL 25/30] configure, meson: replace VSS SDK checks and options with --enable-vss-sdk Paolo Bonzini
2022-02-15  9:32 ` [PULL 26/30] meson: do not make qga/vss-win32/meson.build conditional on C++ presence Paolo Bonzini
2022-02-15  9:32 ` [PULL 27/30] qga/vss-win32: require widl/midl, remove pre-built TLB file Paolo Bonzini
2022-02-15  9:32 ` [PULL 28/30] meson: require dynamic linking for VSS support Paolo Bonzini
2022-02-15  9:32 ` [PULL 29/30] meson, configure: move ntddscsi API check to meson Paolo Bonzini
2022-02-15  9:32 ` [PULL 30/30] configure, meson: move CONFIG_IASL to a Meson option Paolo Bonzini
2022-02-16  9:56 ` [PULL 00/30] Misc mostly build system patches for 2022-02-15 Peter Maydell
2022-02-16 14:03   ` Paolo Bonzini
2022-02-16 14:41     ` Peter Maydell
2022-02-16 21:06       ` Paolo Bonzini

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=20220215093223.110827-7-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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).