AVX2 configure fixes
PATCH v2 1/2 Make avx2 configure test work with -O2
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
When configured with --extra-cflags=-O2 gcc optimised out the test and the readelf failed the check leaving avx2 disabled.
--- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
configure +1 -1
@@ -1783,7 +1783,7 @@ fi cat > $TMPC << EOF static void bar(void) {} static void *bar_ifunc(void) {return (void*) bar;} -static void foo(void) __attribute__((ifunc("bar_ifunc"))); +void foo(void) __attribute__((ifunc("bar_ifunc"))); int main(void) { foo(); return 0; } EOF if compile_prog "-mavx2" "" ; then
Signature · 1 line
2.7.4
v2 cover AVX2 configure fixes
From: "Dr. David Alan Gilbert" <[email protected]>
Hi,
This pair of patches fixes a couple of issues that we found during test.
The first is that the configure test is pessimistic when compiled with -O2, the second is that the explicit 4.9 gcc test is a bit coarse; I've removed that test but beefed up the ./configure test to actually use the avx2 intrinsics and that fails in the same way as the main code, so it works in the same way as the explicit check but allows older gcc's to work when -save-temps isn't used.
Dave
v2
Remove the explicit version check
Split the patches
Dr. David Alan Gilbert (2):
Make avx2 configure test work with -O2
avx2 configure: Use primitives in test
configure | 15 +++++++++++---- util/cutils.c | 8 +------- 2 files changed, 12 insertions(+), 11 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 2/2 avx2 configure: Use primitives in test
From: "Dr. David Alan Gilbert" <[email protected]>
Use the avx2 primitives during the test, thus making sure that the compiler and assembler could actually use avx2.
This also detects the failure case on gcc 4.8.x with -save-temps and avoids the need for the gcc version check in cutils.
--- configure | 15 +++++++++++---- util/cutils.c | 8 +------- 2 files changed, 12 insertions(+), 11 deletions(-)
configure +11 -4
@@ -1781,12 +1781,19 @@ fi # avx2 optimization requirement check cat > $TMPC << EOF -static void bar(void) {} +#pragma GCC push_options +#pragma GCC target("avx2") +#include <cpuid.h> +#include <immintrin.h> + +static int bar(void *a) { + return _mm256_movemask_epi8(_mm256_cmpeq_epi8(*(__m256i *)a, (__m256i){0})); +} static void *bar_ifunc(void) {return (void*) bar;} -void foo(void) __attribute__((ifunc("bar_ifunc"))); -int main(void) { foo(); return 0; } +int foo(void *a) __attribute__((ifunc("bar_ifunc"))); +int main(int argc, char *argv[]) { return foo(argv[0]);} EOF -if compile_prog "-mavx2" "" ; then +if compile_prog "" ; then if readelf --syms $TMPE |grep "IFUNC.*foo" >/dev/null 2>&1; then avx2_opt="yes" fi
util/cutils.c +1 -7
@@ -256,13 +256,7 @@ static size_t buffer_find_nonzero_offset_inner(const void *buf, size_t len)return i *sizeof (VECTYPE ); } -/* -* GCC before version 4.9 has a bug which will cause the target -* attribute work incorrectly and failed to compile in some case, -* restrict the gcc version to 4.9+ to prevent the failure. -*/ - -#if definedCONFIG_AVX2_OPT &&QEMU_GNUC_PREREQ (4 ,9 ) +#if definedCONFIG_AVX2_OPT #pragma GCC push_options#pragma GCC target("avx2")#include <cpuid.h>
Signature · 1 line
2.7.4
Quoted 23 lines
Cc: [email protected]
Subject: [PATCH v2 0/2] AVX2 configure fixesFrom: "Dr. David Alan Gilbert" <[email protected]>
Hi,
This pair of patches fixes a couple of issues that we found during test.
The first is that the configure test is pessimistic when compiled with -O2, the second is that the explicit 4.9 gcc test is a bit coarse; I've removed that test but beefed up the ./configure test to actually use the avx2 intrinsics and that fails in the same way as the main code, so it works in the same way as the explicit check but allows older gcc's to work when -save-temps isn't used.Dave
v2
Remove the explicit version check
Split the patchesDr. David Alan Gilbert (2):
Make avx2 configure test work with -O2
avx2 configure: Use primitives in test
Quoted 6 lines
configure | 15 +++++++++++---- util/cutils.c | 8 +------- 2 files changed, 12 insertions(+), 11 deletions(-)--
2.7.4
Looks good. Thank!
Liang