buildtools: make AVX512 check portable
authorDmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Fri, 12 Nov 2021 21:48:25 +0000 (00:48 +0300)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 17 Nov 2021 08:41:16 +0000 (09:41 +0100)
buildtools/binutils-avx512-check.sh was Unix-only
and could not be used in cross builds:
1) written in shell;
2) used the assembler binary that may be missing,
   e.g. when building on Windows with LLVM;
3) located the assembler as ${AS:-as} and referenced objdump,
   but those binaries may be overridden via --cross-file.

Rewrite the script in Python.
Use the C compiler for the check.
Locate objdump and the C compiler using Meson.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
MAINTAINERS
buildtools/binutils-avx512-check.py [new file with mode: 0644]
buildtools/binutils-avx512-check.sh [deleted file]
buildtools/meson.build

index 387aa25..b1d4ded 100644 (file)
@@ -297,7 +297,7 @@ M: Bruce Richardson <bruce.richardson@intel.com>
 M: Konstantin Ananyev <konstantin.ananyev@intel.com>
 F: config/x86/
 F: doc/guides/linux_gsg/nic_perf_intel_platform.rst
-F: buildtools/binutils-avx512-check.sh
+F: buildtools/binutils-avx512-check.py
 F: doc/guides/howto/avx512.rst
 F: lib/eal/x86/
 F: lib/*/*_sse*
diff --git a/buildtools/binutils-avx512-check.py b/buildtools/binutils-avx512-check.py
new file mode 100644 (file)
index 0000000..a4e14f3
--- /dev/null
@@ -0,0 +1,21 @@
+#! /usr/bin/env python3
+# SPDX-License-Identitifer: BSD-3-Clause
+# Copyright(c) 2020 Intel Corporation
+
+import subprocess
+import sys
+import tempfile
+
+objdump, *cc = sys.argv[1:]
+with tempfile.NamedTemporaryFile() as obj:
+    # On Windows, the file is opened exclusively and is not writable.
+    obj.close()
+    # from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028
+    gather_params = '0x8(,%ymm1,1),%ymm0{%k2}'
+    src = '__asm__("vpgatherqq {}");'.format(gather_params).encode('utf-8')
+    subprocess.run(cc + ['-c', '-xc', '-o', obj.name, '-'], input=src, check=True)
+    asm = subprocess.run([objdump, '-d', '--no-show-raw-insn', obj.name],
+                         capture_output=True, check=True).stdout.decode('utf-8')
+    if gather_params not in asm:
+           print('vpgatherqq displacement error with as')
+           sys.exit(1)
diff --git a/buildtools/binutils-avx512-check.sh b/buildtools/binutils-avx512-check.sh
deleted file mode 100755 (executable)
index 2a833b6..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#! /bin/sh
-# SPDX-License-Identifier: BSD-3-Clause
-# Copyright(c) 2020 Intel Corporation
-
-AS=${AS:-as}
-OBJFILE=$(mktemp -t dpdk.binutils-check.XXXXXX)
-trap 'rm -f "$OBJFILE"' EXIT
-# from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028
-GATHER_PARAMS='0x8(,%ymm1,1),%ymm0{%k2}'
-
-# assemble vpgather to file and similarly check
-echo "vpgatherqq $GATHER_PARAMS" | $AS --64 -o $OBJFILE -
-objdump -d  --no-show-raw-insn $OBJFILE | grep -q $GATHER_PARAMS || {
-       echo "vpgatherqq displacement error with as"
-       exit 1
-}
index f776316..22ea0ba 100644 (file)
@@ -4,7 +4,7 @@
 pkgconf = find_program('pkg-config', 'pkgconf', required: false)
 check_symbols = find_program('check-symbols.sh')
 ldflags_ibverbs_static = find_program('options-ibverbs-static.sh')
-binutils_avx512_check = find_program('binutils-avx512-check.sh')
+objdump = find_program('objdump', 'llvm-objdump')
 
 python3 = import('python').find_installation(required: false)
 if python3.found()
@@ -18,6 +18,8 @@ map_to_win_cmd = py3 + files('map_to_win.py')
 sphinx_wrapper = py3 + files('call-sphinx-build.py')
 get_cpu_count_cmd = py3 + files('get-cpu-count.py')
 get_numa_count_cmd = py3 + files('get-numa-count.py')
+binutils_avx512_check = (py3 + files('binutils-avx512-check.py') +
+                        [objdump] + cc.cmd_array())
 
 # select library and object file format
 pmdinfo = py3 + files('gen-pmdinfo-cfile.py') + [meson.current_build_dir()]