54eb5d1
From c66a00dd0b9c70cef3eff1e85d941ef9608d93b9 Mon Sep 17 00:00:00 2001
54eb5d1
From: Sandro Mani <manisandro@gmail.com>
54eb5d1
Date: Wed, 4 Oct 2023 21:29:06 -0500
54eb5d1
Subject: [PATCH 7/7] Don't use SSE2 if it is not available
54eb5d1
54eb5d1
---
54eb5d1
 aconfigure.ac                                 | 22 +++++++++++++++++--
54eb5d1
 third_party/build/os-auto.mak.in              |  3 +--
54eb5d1
 .../modules/audio_processing/aec/aec_core.c   |  2 +-
54eb5d1
 .../modules/audio_processing/aec/aec_rdft.c   |  2 +-
54eb5d1
 4 files changed, 23 insertions(+), 6 deletions(-)
54eb5d1
54eb5d1
diff --git a/aconfigure.ac b/aconfigure.ac
54eb5d1
index 986a58a56..8c928d25e 100644
54eb5d1
--- a/aconfigure.ac
54eb5d1
+++ b/aconfigure.ac
54eb5d1
@@ -2322,6 +2322,24 @@ AC_SUBST(ac_no_webrtc)
5567ce8
 AC_SUBST(ac_webrtc_instset)
5567ce8
 AC_SUBST(ac_webrtc_cflags)
5567ce8
 AC_SUBST(ac_webrtc_ldflags)
5567ce8
+
5567ce8
+AC_MSG_CHECKING(for available instruction set)
5567ce8
+AC_LINK_IFELSE([
5567ce8
+	AC_LANG_PROGRAM([[
5567ce8
+		#include <xmmintrin.h>
5567ce8
+		__m128 testfunc(float *a, float *b) {
5567ce8
+			return _mm_add_ps(_mm_loadu_ps(a), _mm_loadu_ps(b));
5567ce8
+		}
5567ce8
+	]])],
5567ce8
+	[
5567ce8
+		instrset=sse2
5567ce8
+	],
5567ce8
+	[
5567ce8
+		instrset=generic
5567ce8
+	]
5567ce8
+)
5567ce8
+AC_MSG_RESULT($instrset)
5567ce8
+
5567ce8
 AC_ARG_ENABLE(libwebrtc,
5567ce8
 	      AS_HELP_STRING([--disable-libwebrtc],
5567ce8
 			     [Exclude libwebrtc in the build]),
54eb5d1
@@ -2343,7 +2361,7 @@ AC_ARG_ENABLE(libwebrtc,
5567ce8
 				ac_webrtc_instset=neon
5567ce8
 			    	;;
5567ce8
 			    *)
5567ce8
-				ac_webrtc_instset=sse2
5567ce8
+				ac_webrtc_instset=$instrset
5567ce8
 			    	;;
5567ce8
 			esac
5567ce8
 		        ;;
54eb5d1
@@ -2390,7 +2408,7 @@ AC_ARG_ENABLE(libwebrtc,
54eb5d1
 				 ac_webrtc_cflags="-DWEBRTC_ARCH_ARM64"
54eb5d1
 			    	 ;;
5567ce8
                              *)
5567ce8
-                                 ac_webrtc_instset=sse2
5567ce8
+                                 ac_webrtc_instset=$instrset
5567ce8
                                  ;;
5567ce8
                          esac
5567ce8
 			;;
54eb5d1
diff --git a/third_party/build/os-auto.mak.in b/third_party/build/os-auto.mak.in
54eb5d1
index 7a1db7fb3..aa0bb668f 100644
54eb5d1
--- a/third_party/build/os-auto.mak.in
54eb5d1
+++ b/third_party/build/os-auto.mak.in
54eb5d1
@@ -118,8 +118,7 @@ else ifneq ($(findstring mips,@ac_webrtc_instset@),)
ee3998b
 else # Generic fixed point
ee3998b
     WEBRTC_SRC = \
ee3998b
 	      modules/audio_processing/aecm/aecm_core_c.o                \
ee3998b
-	      modules/audio_processing/ns/nsx_core_c.o                   \
ee3998b
-	      common_audio/signal_processing/complex_fft.o
ee3998b
+	      modules/audio_processing/ns/nsx_core_c.o
ee3998b
 endif
ee3998b
 endif
ee3998b
 endif
54eb5d1
diff --git a/third_party/webrtc/src/webrtc/modules/audio_processing/aec/aec_core.c b/third_party/webrtc/src/webrtc/modules/audio_processing/aec/aec_core.c
54eb5d1
index 9d54b62fc..71536f638 100644
54eb5d1
--- a/third_party/webrtc/src/webrtc/modules/audio_processing/aec/aec_core.c
54eb5d1
+++ b/third_party/webrtc/src/webrtc/modules/audio_processing/aec/aec_core.c
5567ce8
@@ -1478,7 +1478,7 @@ AecCore* WebRtcAec_CreateAec() {
5567ce8
   WebRtcAec_ComfortNoise = ComfortNoise;
5567ce8
   WebRtcAec_SubbandCoherence = SubbandCoherence;
5567ce8
 
5567ce8
-#if defined(WEBRTC_ARCH_X86_FAMILY)
5567ce8
+#if defined(WEBRTC_ARCH_X86_FAMILY) && defined(__SSE2__)
5567ce8
   if (WebRtc_GetCPUInfo(kSSE2)) {
5567ce8
     WebRtcAec_InitAec_SSE2();
5567ce8
   }
54eb5d1
diff --git a/third_party/webrtc/src/webrtc/modules/audio_processing/aec/aec_rdft.c b/third_party/webrtc/src/webrtc/modules/audio_processing/aec/aec_rdft.c
54eb5d1
index 2c3cff2df..f02d99098 100644
54eb5d1
--- a/third_party/webrtc/src/webrtc/modules/audio_processing/aec/aec_rdft.c
54eb5d1
+++ b/third_party/webrtc/src/webrtc/modules/audio_processing/aec/aec_rdft.c
5567ce8
@@ -571,7 +571,7 @@ void aec_rdft_init(void) {
5567ce8
   cftfsub_128 = cftfsub_128_C;
5567ce8
   cftbsub_128 = cftbsub_128_C;
5567ce8
   bitrv2_128 = bitrv2_128_C;
5567ce8
-#if defined(WEBRTC_ARCH_X86_FAMILY)
5567ce8
+#if defined(WEBRTC_ARCH_X86_FAMILY) && defined(__SSE2__)
5567ce8
   if (WebRtc_GetCPUInfo(kSSE2)) {
5567ce8
     aec_rdft_init_sse2();
5567ce8
   }
54eb5d1
-- 
54eb5d1
2.41.0
54eb5d1