Check FMA3 support before use it in SincResampler
This is a port of crrev.com/c/2936677.
Previously we only checked avx2 support and then use avx2/fma
intrinsics in SincResampler(crrev.com/c/2654647),this CL also
checks the fma support and avoids using avx2 code if fma is not
supported.
Bug: chromium:1410691
Change-Id: Ibf7c0a1bead87ebe5d3978cfd20cc23525169f40
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/291702
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Henrik Lundin <henrik.lundin@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39238}
diff --git a/common_audio/resampler/sinc_resampler.cc b/common_audio/resampler/sinc_resampler.cc
index fac11aa..66a99b6 100644
--- a/common_audio/resampler/sinc_resampler.cc
+++ b/common_audio/resampler/sinc_resampler.cc
@@ -126,8 +126,8 @@
#if defined(WEBRTC_HAS_NEON)
convolve_proc_ = Convolve_NEON;
#elif defined(WEBRTC_ARCH_X86_FAMILY)
- // Using AVX2 instead of SSE2 when AVX2 supported.
- if (GetCPUInfo(kAVX2))
+ // Using AVX2 instead of SSE2 when AVX2/FMA3 supported.
+ if (GetCPUInfo(kAVX2) && GetCPUInfo(kFMA3))
convolve_proc_ = Convolve_AVX2;
else if (GetCPUInfo(kSSE2))
convolve_proc_ = Convolve_SSE;
diff --git a/system_wrappers/include/cpu_features_wrapper.h b/system_wrappers/include/cpu_features_wrapper.h
index 612b4a5..254e2d8 100644
--- a/system_wrappers/include/cpu_features_wrapper.h
+++ b/system_wrappers/include/cpu_features_wrapper.h
@@ -16,7 +16,7 @@
namespace webrtc {
// List of features in x86.
-typedef enum { kSSE2, kSSE3, kAVX2 } CPUFeature;
+typedef enum { kSSE2, kSSE3, kAVX2, kFMA3 } CPUFeature;
// List of features in ARM.
enum {
diff --git a/system_wrappers/source/cpu_features.cc b/system_wrappers/source/cpu_features.cc
index b676339..8cd701e 100644
--- a/system_wrappers/source/cpu_features.cc
+++ b/system_wrappers/source/cpu_features.cc
@@ -103,6 +103,9 @@
(cpu_info7[1] & 0x00000100) != 0 /* BMI2 */;
}
#endif // WEBRTC_ENABLE_AVX2
+ if (feature == kFMA3) {
+ return 0 != (cpu_info[2] & 0x00001000);
+ }
return 0;
}
#else