From 9cf12e92bbd25b2416b340b06090efbde9ad3fa6 Mon Sep 17 00:00:00 2001
From: "Timothy B. Terriberry" <tterribe@xiph.org>
Date: Thu, 22 Feb 2024 04:49:51 -0800
Subject: [PATCH] Improve AVX2 compiler support detection.

Commit 735c40706f37 added uses of intrinsics that require at least
 gcc 9.0 (cf. <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78782>),
 even though AVX2 support may appear to be available in earlier gcc
 versions.
We were not testing for this.
Update the compiler test in configure.ac to use these intrinsics
 explicitly, so it will error out and disable AVX2 if they are not
 available.
---
 configure.ac | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 63ae93294..4bfcb6ecc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -691,10 +691,17 @@ AS_IF([test x"$enable_intrinsics" = x"yes"],[
            #include <time.h>
          ]],
          [[
+             unsigned char utest[16] = {1};
              __m256 mtest;
+             __m256 mtest1;
+             __m256 mtest2;
              mtest = _mm256_set1_ps((float)time(NULL));
              mtest = _mm256_fmadd_ps(mtest, mtest, mtest);
-             return _mm256_extract_epi16(_mm256_cvttps_epi32(mtest), 0);
+             mtest1 = _mm256_set_m128i(_mm_loadu_si64(utest));
+             mtest2 =
+              _mm256_cvtepi16_epi32(_mm_loadu_si128((__m128i_u *)utest));
+             return _mm256_extract_epi16(_mm256_xor_si256(
+              _mm256_xor_si256(mtest1, mtest2), _mm256_cvttps_epi32(mtest)), 0);
          ]]
       )
       AS_IF([test x"$OPUS_X86_MAY_HAVE_AVX2" = x"1" && test x"$OPUS_X86_PRESUME_AVX2" != x"1"],
-- 
GitLab