Support for vpopcntdq instruction generation by the compiler was already
checked in the OVS_CHECK_AVX512 AC function by checking if the compiler
accepted the -mavx512vpopcntdq option.  However, there can be situations
where the compiler supports vpopcntdq generation but the assembler
doesn't support the instruction.

The below OVS_CHECK_AVX512VPOPCNTDQ AC function will check for both
compiler and assembler support for the vpopcntdq instruction.

Signed-off-by: Cian Ferriter <cian.ferri...@intel.com>
---
 acinclude.m4      |  2 +-
 m4/openvswitch.m4 | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/acinclude.m4 b/acinclude.m4
index d9a33f583..30b82aae2 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -101,7 +101,7 @@ AC_DEFUN([OVS_CHECK_AVX512], [
   OVS_CONDITIONAL_CC_OPTION_DEFINE([-mavx512bw], [HAVE_AVX512BW])
   OVS_CONDITIONAL_CC_OPTION_DEFINE([-mavx512vl], [HAVE_AVX512VL])
   OVS_CONDITIONAL_CC_OPTION_DEFINE([-mavx512vbmi], [HAVE_AVX512VBMI])
-  OVS_CONDITIONAL_CC_OPTION_DEFINE([-mavx512vpopcntdq], [HAVE_AVX512VPOPCNTDQ])
+  OVS_CHECK_AVX512VPOPCNTDQ
 ])
 
 dnl OVS_ENABLE_WERROR
diff --git a/m4/openvswitch.m4 b/m4/openvswitch.m4
index 6eef1fb35..b5be5842e 100644
--- a/m4/openvswitch.m4
+++ b/m4/openvswitch.m4
@@ -450,6 +450,35 @@ AC_DEFUN([OVS_CHECK_GCC_AVX512VL], [
    AM_CONDITIONAL([HAVE_GCC_AVX512VL_GOOD],
                   [test "$ovs_cv_gcc_avx512vl_good" = yes])])
 
+dnl Checks whether the build system implements the vpopcntdq instruction. The
+dnl compiler and assembler each separately need to support vpopcntdq. In order
+dnl to test the assembler with the below code snippet, set the optimization
+dnl level of the function to "O0" so it won't be optimized away by the
+dnl compiler.
+AC_DEFUN([OVS_CHECK_AVX512VPOPCNTDQ], [
+  AC_MSG_CHECKING([whether compiler correctly emits AVX512-VPOPCNTDQ])
+  AC_COMPILE_IFELSE(
+    [AC_LANG_PROGRAM([#include <immintrin.h>
+                     void
+                     __attribute__((__target__("avx512vpopcntdq")))
+                     __attribute__((optimize("O0")))
+                     check_vpopcntdq(void)
+                     {
+                         __m512i v_test;
+                         v_test = _mm512_popcnt_epi64(v_test);
+                     }],[])],
+    [AC_MSG_RESULT([yes])
+    ovs_cv_avx512vpopcntdq_good=yes],
+    [AC_MSG_RESULT([no])
+    ovs_cv_avx512vpopcntdq_good=no])
+   if test "$ovs_cv_avx512vpopcntdq_good" = yes; then
+     AC_DEFINE([HAVE_AVX512VPOPCNTDQ], [1],
+               [Define to 1 if the build system implements the vpopcntdq
+                instruction.])
+   fi
+   AM_CONDITIONAL([HAVE_AVX512VPOPCNTDQ],
+                  [test "$ovs_cv_avx512vpopcntdq_good" = yes])])
+
 dnl Checks for binutils/assembler known issue with AVX512.
 dnl Due to backports, we probe assembling a reproducer instead of checking
 dnl binutils version string. More details, including ASM dumps and debug here:
-- 
2.25.1

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to