[PATCH] Fix CPU feature detection for fma3, avx512 and avx512icl

Zuxy Meng <[email protected]> Thu, 9 Nov 2023 22:24:52 -0800
Newsgroups gmane.comp.video.mplayer.devel
Message-ID <CA+LKdEReOTmd6-v6rzwJ_EX7F6hbDB0bT-wEtR-gqxr178Obpg@mail.gmail.com>
Greetings! I have recently got my hands on a Zen 4 machine and found
that configure's feature detection is broken for several features.

The fma3 and assembly fix is probably less controversial, but would
like to hear what you guys think about avx512 and avx512icl.

I tried to make it equivalent to ffmpeg's internal logic (
https://patchwork.ffmpeg.org/project/ffmpeg/patch/[email protected]/#70640)
but it has since become very wordy. Can we simplify it to check only
one cpuinfo word for each feature based on
https://en.wikipedia.org/wiki/AVX-512#CPUs_with_AVX-512? For example,
check avx512dq for baseline and avx512_vnni for avx512icl. ffmpeg will
do its own run time check anyway.

-- 
Zuxy
Beauty is truth,
While truth is beauty.
PGP KeyID: E8555ED6

_______________________________________________
MPlayer-dev-eng mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng
configure.diff (application/octet-stream, 2 KB)
Index: configure
===================================================================
--- configure	(revision 38442)
+++ configure	(working copy)
@@ -2083,6 +2083,22 @@
   # SSE implies MMX2, but not all SSE processors report the mmxext CPU flag.
   pparam=$(echo $pparam | sed -e 's/sse/sse mmxext/')
 
+  # fma3 is reported in cpuinfo simply as fma
+  contains_item "$pparam" "fma" && pparam="$pparam fma3"
+
+  # avx512 baseline requires F, CD, BW, DQ, VL
+  contains_item "$pparam" "avx512f" && contains_item "$pparam" "avx512cd" &&
+    contains_item "$pparam" "avx512bw" && contains_item "$pparam" "avx512dq" &&
+    contains_item "$pparam" "avx512vl" && pparam="$pparam avx512"
+
+  # IceLake equivalent avx512 has further requirements
+  contains_item "$pparam" "avx512" && contains_item "$pparam" "avx512ifma" &&
+    contains_item "$pparam" "avx512vbmi" && contains_item "$pparam" "avx512_vbmi2" &&
+    contains_item "$pparam" "gfni" && contains_item "$pparam" "vaes" &&
+    contains_item "$pparam" "vpclmulqdq" && contains_item "$pparam" "avx512_vnni" &&
+    contains_item "$pparam" "avx512_bitalg" &&
+    contains_item "$pparam" "avx512_vpopcntdq" && pparam="$pparam avx512icl"
+
   extcheck=kernel_check
   msvc && extcheck=yes
   for ext in $pparam ; do
@@ -2140,8 +2156,8 @@
   extcheck $_sse4_2   'sse4_2'   'pcmpgtq %%xmm0, %%xmm0'
   extcheck $_avx      'avx'      'vpabsw %%xmm0, %%xmm0'
   extcheck $_avx2     'avx2'     'vextracti128 $0, %%ymm0, %%xmm0'
-  extcheck $_avx512   'avx512'   'vmovdqa32 [eax]{k1}{z}, zmm0'
-  extcheck $_avx512icl 'avx512icl' 'vpdpwssds zmm31{k1}{z}, zmm29, zmm28'
+  extcheck $_avx512   'avx512'   'vmovdqa32 %%zmm0, (%%eax)%{%%k1%}'
+  extcheck $_avx512icl 'avx512icl' 'vpdpwssds %%zmm28, %%zmm29, %%zmm31%{%%k1%}%{z%}'
   extcheck $_xop      'xop'      'vpmacsdd %%xmm0, %%xmm1, %%xmm2, %%xmm3'
   extcheck $_fma3     'fma3'     'vfmadd132ps %%ymm0, %%ymm1, %%ymm2'
   extcheck $_fma4     'fma4'     'vfmaddps %%ymm0, %%ymm1, %%ymm2, %%ymm3'