From cb4b0a6ad27afde9cc295b0f48e234c2d6bb8a03 Mon Sep 17 00:00:00 2001 From: Henrik Lundin Date: Tue, 31 Jan 2023 15:49:55 +0000 Subject: [PATCH] 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 Commit-Queue: Henrik Lundin Reviewed-by: Harald Alvestrand Cr-Commit-Position: refs/heads/main@{#39238} --- common_audio/resampler/sinc_resampler.cc | 4 ++-- system_wrappers/include/cpu_features_wrapper.h | 2 +- system_wrappers/source/cpu_features.cc | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/common_audio/resampler/sinc_resampler.cc b/common_audio/resampler/sinc_resampler.cc index fac11aa362..66a99b6190 100644 --- a/common_audio/resampler/sinc_resampler.cc +++ b/common_audio/resampler/sinc_resampler.cc @@ -126,8 +126,8 @@ void SincResampler::InitializeCPUSpecificFeatures() { #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 612b4a5d6b..254e2d8dda 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 b676339eea..8cd701eb41 100644 --- a/system_wrappers/source/cpu_features.cc +++ b/system_wrappers/source/cpu_features.cc @@ -103,6 +103,9 @@ int GetCPUInfo(CPUFeature feature) { (cpu_info7[1] & 0x00000100) != 0 /* BMI2 */; } #endif // WEBRTC_ENABLE_AVX2 + if (feature == kFMA3) { + return 0 != (cpu_info[2] & 0x00001000); + } return 0; } #else