diff --git a/common_audio/fir_filter_factory.cc b/common_audio/fir_filter_factory.cc index bfa198f32f..4bcf05245f 100644 --- a/common_audio/fir_filter_factory.cc +++ b/common_audio/fir_filter_factory.cc @@ -36,10 +36,10 @@ FIRFilter* CreateFirFilter(const float* coefficients, // If we know the minimum architecture at compile time, avoid CPU detection. #if defined(WEBRTC_ARCH_X86_FAMILY) // x86 CPU detection required. - if (WebRtc_GetCPUInfo(kAVX2)) { + if (GetCPUInfo(kAVX2)) { filter = new FIRFilterAVX2(coefficients, coefficients_length, max_input_length); - } else if (WebRtc_GetCPUInfo(kSSE2)) { + } else if (GetCPUInfo(kSSE2)) { filter = new FIRFilterSSE2(coefficients, coefficients_length, max_input_length); } else { diff --git a/common_audio/resampler/sinc_resampler.cc b/common_audio/resampler/sinc_resampler.cc index 831ce53d4a..4fa78c5ede 100644 --- a/common_audio/resampler/sinc_resampler.cc +++ b/common_audio/resampler/sinc_resampler.cc @@ -127,9 +127,9 @@ void SincResampler::InitializeCPUSpecificFeatures() { convolve_proc_ = Convolve_NEON; #elif defined(WEBRTC_ARCH_X86_FAMILY) // Using AVX2 instead of SSE2 when AVX2 supported. - if (WebRtc_GetCPUInfo(kAVX2)) + if (GetCPUInfo(kAVX2)) convolve_proc_ = Convolve_AVX2; - else if (WebRtc_GetCPUInfo(kSSE2)) + else if (GetCPUInfo(kSSE2)) convolve_proc_ = Convolve_SSE; else convolve_proc_ = Convolve_C; diff --git a/common_audio/resampler/sinc_resampler_unittest.cc b/common_audio/resampler/sinc_resampler_unittest.cc index ece6af0689..5bfb2d090c 100644 --- a/common_audio/resampler/sinc_resampler_unittest.cc +++ b/common_audio/resampler/sinc_resampler_unittest.cc @@ -121,9 +121,9 @@ TEST(SincResamplerTest, DISABLED_SetRatioBench) { // will be tested by the parameterized SincResampler tests below. TEST(SincResamplerTest, Convolve) { #if defined(WEBRTC_ARCH_X86_FAMILY) - ASSERT_TRUE(WebRtc_GetCPUInfo(kSSE2)); + ASSERT_TRUE(GetCPUInfo(kSSE2)); #elif defined(WEBRTC_ARCH_ARM_V7) - ASSERT_TRUE(WebRtc_GetCPUFeaturesARM() & kCPUFeatureNEON); + ASSERT_TRUE(GetCPUFeaturesARM() & kCPUFeatureNEON); #endif // Initialize a dummy resampler. @@ -182,9 +182,9 @@ TEST(SincResamplerTest, ConvolveBenchmark) { printf("Convolve_C took %.2fms.\n", total_time_c_us / 1000); #if defined(WEBRTC_ARCH_X86_FAMILY) - ASSERT_TRUE(WebRtc_GetCPUInfo(kSSE2)); + ASSERT_TRUE(GetCPUInfo(kSSE2)); #elif defined(WEBRTC_ARCH_ARM_V7) - ASSERT_TRUE(WebRtc_GetCPUFeaturesARM() & kCPUFeatureNEON); + ASSERT_TRUE(GetCPUFeaturesARM() & kCPUFeatureNEON); #endif // Benchmark with unaligned input pointer. diff --git a/common_audio/third_party/ooura/fft_size_128/ooura_fft.cc b/common_audio/third_party/ooura/fft_size_128/ooura_fft.cc index 6b6d6f1fd7..693312012b 100644 --- a/common_audio/third_party/ooura/fft_size_128/ooura_fft.cc +++ b/common_audio/third_party/ooura/fft_size_128/ooura_fft.cc @@ -323,7 +323,7 @@ OouraFft::OouraFft(bool sse2_available) { OouraFft::OouraFft() { #if defined(WEBRTC_ARCH_X86_FAMILY) - use_sse2_ = (WebRtc_GetCPUInfo(kSSE2) != 0); + use_sse2_ = (GetCPUInfo(kSSE2) != 0); #else use_sse2_ = false; #endif diff --git a/modules/audio_coding/codecs/isac/fix/source/isacfix.c b/modules/audio_coding/codecs/isac/fix/source/isacfix.c index 36fbdd6bb8..067d8f358f 100644 --- a/modules/audio_coding/codecs/isac/fix/source/isacfix.c +++ b/modules/audio_coding/codecs/isac/fix/source/isacfix.c @@ -26,7 +26,6 @@ #include "modules/audio_coding/codecs/isac/fix/source/filterbank_internal.h" #include "modules/audio_coding/codecs/isac/fix/source/lpc_masking_model.h" #include "modules/audio_coding/codecs/isac/fix/source/structs.h" -#include "system_wrappers/include/cpu_features_wrapper.h" // Declare function pointers. FilterMaLoopFix WebRtcIsacfix_FilterMaLoopFix; diff --git a/modules/audio_processing/aec3/adaptive_fir_filter_erl_unittest.cc b/modules/audio_processing/aec3/adaptive_fir_filter_erl_unittest.cc index fc30f7fd74..d2af70a9f2 100644 --- a/modules/audio_processing/aec3/adaptive_fir_filter_erl_unittest.cc +++ b/modules/audio_processing/aec3/adaptive_fir_filter_erl_unittest.cc @@ -53,7 +53,7 @@ TEST(AdaptiveFirFilter, UpdateErlNeonOptimization) { // Verifies that the optimized method for echo return loss computation is // bitexact to the reference counterpart. TEST(AdaptiveFirFilter, UpdateErlSse2Optimization) { - bool use_sse2 = (WebRtc_GetCPUInfo(kSSE2) != 0); + bool use_sse2 = (GetCPUInfo(kSSE2) != 0); if (use_sse2) { const size_t kNumPartitions = 12; std::vector> H2(kNumPartitions); @@ -78,7 +78,7 @@ TEST(AdaptiveFirFilter, UpdateErlSse2Optimization) { // Verifies that the optimized method for echo return loss computation is // bitexact to the reference counterpart. TEST(AdaptiveFirFilter, UpdateErlAvx2Optimization) { - bool use_avx2 = (WebRtc_GetCPUInfo(kAVX2) != 0); + bool use_avx2 = (GetCPUInfo(kAVX2) != 0); if (use_avx2) { const size_t kNumPartitions = 12; std::vector> H2(kNumPartitions); diff --git a/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc b/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc index a18ebd86a1..af7ea1d34c 100644 --- a/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc +++ b/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc @@ -179,7 +179,7 @@ TEST_P(AdaptiveFirFilterOneTwoFourEightRenderChannels, constexpr int kSampleRateHz = 48000; constexpr size_t kNumBands = NumBandsForRate(kSampleRateHz); - bool use_sse2 = (WebRtc_GetCPUInfo(kSSE2) != 0); + bool use_sse2 = (GetCPUInfo(kSSE2) != 0); if (use_sse2) { for (size_t num_partitions : {2, 5, 12, 30, 50}) { std::unique_ptr render_delay_buffer( @@ -254,7 +254,7 @@ TEST_P(AdaptiveFirFilterOneTwoFourEightRenderChannels, constexpr int kSampleRateHz = 48000; constexpr size_t kNumBands = NumBandsForRate(kSampleRateHz); - bool use_avx2 = (WebRtc_GetCPUInfo(kAVX2) != 0); + bool use_avx2 = (GetCPUInfo(kAVX2) != 0); if (use_avx2) { for (size_t num_partitions : {2, 5, 12, 30, 50}) { std::unique_ptr render_delay_buffer( @@ -326,7 +326,7 @@ TEST_P(AdaptiveFirFilterOneTwoFourEightRenderChannels, TEST_P(AdaptiveFirFilterOneTwoFourEightRenderChannels, ComputeFrequencyResponseSse2Optimization) { const size_t num_render_channels = GetParam(); - bool use_sse2 = (WebRtc_GetCPUInfo(kSSE2) != 0); + bool use_sse2 = (GetCPUInfo(kSSE2) != 0); if (use_sse2) { for (size_t num_partitions : {2, 5, 12, 30, 50}) { std::vector> H( @@ -361,7 +361,7 @@ TEST_P(AdaptiveFirFilterOneTwoFourEightRenderChannels, TEST_P(AdaptiveFirFilterOneTwoFourEightRenderChannels, ComputeFrequencyResponseAvx2Optimization) { const size_t num_render_channels = GetParam(); - bool use_avx2 = (WebRtc_GetCPUInfo(kAVX2) != 0); + bool use_avx2 = (GetCPUInfo(kAVX2) != 0); if (use_avx2) { for (size_t num_partitions : {2, 5, 12, 30, 50}) { std::vector> H( diff --git a/modules/audio_processing/aec3/aec3_common.cc b/modules/audio_processing/aec3/aec3_common.cc index 6aaab619fc..7bd8d6267a 100644 --- a/modules/audio_processing/aec3/aec3_common.cc +++ b/modules/audio_processing/aec3/aec3_common.cc @@ -20,9 +20,9 @@ namespace webrtc { Aec3Optimization DetectOptimization() { #if defined(WEBRTC_ARCH_X86_FAMILY) - if (WebRtc_GetCPUInfo(kAVX2) != 0) { + if (GetCPUInfo(kAVX2) != 0) { return Aec3Optimization::kAvx2; - } else if (WebRtc_GetCPUInfo(kSSE2) != 0) { + } else if (GetCPUInfo(kSSE2) != 0) { return Aec3Optimization::kSse2; } #endif diff --git a/modules/audio_processing/aec3/aec3_fft.cc b/modules/audio_processing/aec3/aec3_fft.cc index d1d4f7da06..8dfa183367 100644 --- a/modules/audio_processing/aec3/aec3_fft.cc +++ b/modules/audio_processing/aec3/aec3_fft.cc @@ -73,7 +73,7 @@ const float kSqrtHanning128[kFftLength] = { bool IsSse2Available() { #if defined(WEBRTC_ARCH_X86_FAMILY) - return WebRtc_GetCPUInfo(kSSE2) != 0; + return GetCPUInfo(kSSE2) != 0; #else return false; #endif diff --git a/modules/audio_processing/aec3/fft_data_unittest.cc b/modules/audio_processing/aec3/fft_data_unittest.cc index b0235a7fd0..d76fabdbd6 100644 --- a/modules/audio_processing/aec3/fft_data_unittest.cc +++ b/modules/audio_processing/aec3/fft_data_unittest.cc @@ -20,7 +20,7 @@ namespace webrtc { // Verifies that the optimized methods are bitexact to their reference // counterparts. TEST(FftData, TestSse2Optimizations) { - if (WebRtc_GetCPUInfo(kSSE2) != 0) { + if (GetCPUInfo(kSSE2) != 0) { FftData x; for (size_t k = 0; k < x.re.size(); ++k) { @@ -43,7 +43,7 @@ TEST(FftData, TestSse2Optimizations) { // Verifies that the optimized methods are bitexact to their reference // counterparts. TEST(FftData, TestAvx2Optimizations) { - if (WebRtc_GetCPUInfo(kAVX2) != 0) { + if (GetCPUInfo(kAVX2) != 0) { FftData x; for (size_t k = 0; k < x.re.size(); ++k) { diff --git a/modules/audio_processing/aec3/matched_filter_unittest.cc b/modules/audio_processing/aec3/matched_filter_unittest.cc index 7e16c01ed9..137275fd74 100644 --- a/modules/audio_processing/aec3/matched_filter_unittest.cc +++ b/modules/audio_processing/aec3/matched_filter_unittest.cc @@ -93,7 +93,7 @@ TEST(MatchedFilter, TestNeonOptimizations) { // Verifies that the optimized methods for SSE2 are bitexact to their reference // counterparts. TEST(MatchedFilter, TestSse2Optimizations) { - bool use_sse2 = (WebRtc_GetCPUInfo(kSSE2) != 0); + bool use_sse2 = (GetCPUInfo(kSSE2) != 0); if (use_sse2) { Random random_generator(42U); constexpr float kSmoothing = 0.7f; @@ -134,7 +134,7 @@ TEST(MatchedFilter, TestSse2Optimizations) { } TEST(MatchedFilter, TestAvx2Optimizations) { - bool use_avx2 = (WebRtc_GetCPUInfo(kAVX2) != 0); + bool use_avx2 = (GetCPUInfo(kAVX2) != 0); if (use_avx2) { Random random_generator(42U); constexpr float kSmoothing = 0.7f; diff --git a/modules/audio_processing/aec3/vector_math_unittest.cc b/modules/audio_processing/aec3/vector_math_unittest.cc index bd156b579c..a9c37e33cf 100644 --- a/modules/audio_processing/aec3/vector_math_unittest.cc +++ b/modules/audio_processing/aec3/vector_math_unittest.cc @@ -80,7 +80,7 @@ TEST(VectorMath, Accumulate) { #if defined(WEBRTC_ARCH_X86_FAMILY) TEST(VectorMath, Sse2Sqrt) { - if (WebRtc_GetCPUInfo(kSSE2) != 0) { + if (GetCPUInfo(kSSE2) != 0) { std::array x; std::array z; std::array z_sse2; @@ -102,7 +102,7 @@ TEST(VectorMath, Sse2Sqrt) { } TEST(VectorMath, Avx2Sqrt) { - if (WebRtc_GetCPUInfo(kAVX2) != 0) { + if (GetCPUInfo(kAVX2) != 0) { std::array x; std::array z; std::array z_avx2; @@ -124,7 +124,7 @@ TEST(VectorMath, Avx2Sqrt) { } TEST(VectorMath, Sse2Multiply) { - if (WebRtc_GetCPUInfo(kSSE2) != 0) { + if (GetCPUInfo(kSSE2) != 0) { std::array x; std::array y; std::array z; @@ -145,7 +145,7 @@ TEST(VectorMath, Sse2Multiply) { } TEST(VectorMath, Avx2Multiply) { - if (WebRtc_GetCPUInfo(kAVX2) != 0) { + if (GetCPUInfo(kAVX2) != 0) { std::array x; std::array y; std::array z; @@ -166,7 +166,7 @@ TEST(VectorMath, Avx2Multiply) { } TEST(VectorMath, Sse2Accumulate) { - if (WebRtc_GetCPUInfo(kSSE2) != 0) { + if (GetCPUInfo(kSSE2) != 0) { std::array x; std::array z; std::array z_sse2; @@ -186,7 +186,7 @@ TEST(VectorMath, Sse2Accumulate) { } TEST(VectorMath, Avx2Accumulate) { - if (WebRtc_GetCPUInfo(kAVX2) != 0) { + if (GetCPUInfo(kAVX2) != 0) { std::array x; std::array z; std::array z_avx2; diff --git a/modules/audio_processing/agc2/rnn_vad/common.cc b/modules/audio_processing/agc2/rnn_vad/common.cc index 744c87fea2..5d76b52e57 100644 --- a/modules/audio_processing/agc2/rnn_vad/common.cc +++ b/modules/audio_processing/agc2/rnn_vad/common.cc @@ -18,7 +18,7 @@ namespace rnn_vad { Optimization DetectOptimization() { #if defined(WEBRTC_ARCH_X86_FAMILY) - if (WebRtc_GetCPUInfo(kSSE2) != 0) { + if (GetCPUInfo(kSSE2) != 0) { return Optimization::kSse2; } #endif diff --git a/modules/audio_processing/agc2/rnn_vad/test_utils.cc b/modules/audio_processing/agc2/rnn_vad/test_utils.cc index 1a8e1a2eeb..c7bf02e74b 100644 --- a/modules/audio_processing/agc2/rnn_vad/test_utils.cc +++ b/modules/audio_processing/agc2/rnn_vad/test_utils.cc @@ -109,7 +109,7 @@ bool IsOptimizationAvailable(Optimization optimization) { switch (optimization) { case Optimization::kSse2: #if defined(WEBRTC_ARCH_X86_FAMILY) - return WebRtc_GetCPUInfo(kSSE2) != 0; + return GetCPUInfo(kSSE2) != 0; #else return false; #endif diff --git a/modules/audio_processing/agc2/signal_classifier.cc b/modules/audio_processing/agc2/signal_classifier.cc index 38334f7ec5..a06413d166 100644 --- a/modules/audio_processing/agc2/signal_classifier.cc +++ b/modules/audio_processing/agc2/signal_classifier.cc @@ -26,7 +26,7 @@ namespace { bool IsSse2Available() { #if defined(WEBRTC_ARCH_X86_FAMILY) - return WebRtc_GetCPUInfo(kSSE2) != 0; + return GetCPUInfo(kSSE2) != 0; #else return false; #endif diff --git a/modules/desktop_capture/differ_block.cc b/modules/desktop_capture/differ_block.cc index dd9ab457e0..4f0c5430c9 100644 --- a/modules/desktop_capture/differ_block.cc +++ b/modules/desktop_capture/differ_block.cc @@ -35,7 +35,7 @@ bool VectorDifference(const uint8_t* image1, const uint8_t* image2) { // TODO(hclam): Implement a NEON version. diff_proc = &VectorDifference_C; #else - bool have_sse2 = WebRtc_GetCPUInfo(kSSE2) != 0; + bool have_sse2 = GetCPUInfo(kSSE2) != 0; // For x86 processors, check if SSE2 is supported. if (have_sse2 && kBlockSize == 32) { diff_proc = &VectorDifference_SSE2_W32; diff --git a/modules/video_processing/util/denoiser_filter.cc b/modules/video_processing/util/denoiser_filter.cc index d6b5094a5b..0e1570114a 100644 --- a/modules/video_processing/util/denoiser_filter.cc +++ b/modules/video_processing/util/denoiser_filter.cc @@ -41,7 +41,7 @@ std::unique_ptr DenoiserFilter::Create( filter.reset(new DenoiserFilterSSE2()); #else // x86 CPU detection required. - if (WebRtc_GetCPUInfo(kSSE2)) { + if (GetCPUInfo(kSSE2)) { filter.reset(new DenoiserFilterSSE2()); } else { filter.reset(new DenoiserFilterC()); diff --git a/system_wrappers/include/cpu_features_wrapper.h b/system_wrappers/include/cpu_features_wrapper.h index f4b3fed2d3..612b4a5d6b 100644 --- a/system_wrappers/include/cpu_features_wrapper.h +++ b/system_wrappers/include/cpu_features_wrapper.h @@ -13,6 +13,8 @@ #include +namespace webrtc { + // List of features in x86. typedef enum { kSSE2, kSSE3, kAVX2 } CPUFeature; @@ -24,17 +26,17 @@ enum { kCPUFeatureLDREXSTREX = (1 << 3) }; -typedef int (*WebRtc_CPUInfo)(CPUFeature feature); - // Returns true if the CPU supports the feature. -extern WebRtc_CPUInfo WebRtc_GetCPUInfo; +int GetCPUInfo(CPUFeature feature); // No CPU feature is available => straight C path. -extern WebRtc_CPUInfo WebRtc_GetCPUInfoNoASM; +int GetCPUInfoNoASM(CPUFeature feature); // Return the features in an ARM device. // It detects the features in the hardware platform, and returns supported // values in the above enum definition as a bitmask. -extern uint64_t WebRtc_GetCPUFeaturesARM(void); +uint64_t GetCPUFeaturesARM(void); + +} // namespace webrtc #endif // SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_ diff --git a/system_wrappers/source/cpu_features.cc b/system_wrappers/source/cpu_features.cc index 40110ed871..e40c65a191 100644 --- a/system_wrappers/source/cpu_features.cc +++ b/system_wrappers/source/cpu_features.cc @@ -17,6 +17,8 @@ #include #endif +namespace webrtc { + // No CPU feature is available => straight C path. int GetCPUInfoNoASM(CPUFeature feature) { (void)feature; @@ -65,7 +67,7 @@ static inline void __cpuid(int cpu_info[4], int info_type) { #if defined(WEBRTC_ARCH_X86_FAMILY) // Actual feature detection for x86. -static int GetCPUInfo(CPUFeature feature) { +int GetCPUInfo(CPUFeature feature) { int cpu_info[4]; __cpuid(cpu_info, 1); if (feature == kSSE2) { @@ -102,11 +104,10 @@ static int GetCPUInfo(CPUFeature feature) { } #else // Default to straight C for other platforms. -static int GetCPUInfo(CPUFeature feature) { +int GetCPUInfo(CPUFeature feature) { (void)feature; return 0; } #endif -WebRtc_CPUInfo WebRtc_GetCPUInfo = GetCPUInfo; -WebRtc_CPUInfo WebRtc_GetCPUInfoNoASM = GetCPUInfoNoASM; +} // namespace webrtc diff --git a/system_wrappers/source/cpu_features_android.cc b/system_wrappers/source/cpu_features_android.cc index 0cb3a6c5ee..95cc609b09 100644 --- a/system_wrappers/source/cpu_features_android.cc +++ b/system_wrappers/source/cpu_features_android.cc @@ -10,6 +10,10 @@ #include -uint64_t WebRtc_GetCPUFeaturesARM(void) { +namespace webrtc { + +uint64_t GetCPUFeaturesARM(void) { return android_getCpuFeatures(); } + +} // namespace webrtc diff --git a/system_wrappers/source/cpu_features_linux.cc b/system_wrappers/source/cpu_features_linux.cc index 05ff9b31b7..335bed4da3 100644 --- a/system_wrappers/source/cpu_features_linux.cc +++ b/system_wrappers/source/cpu_features_linux.cc @@ -33,7 +33,9 @@ #if defined(WEBRTC_ARCH_ARM_FAMILY) #include -uint64_t WebRtc_GetCPUFeaturesARM(void) { +namespace webrtc { + +uint64_t GetCPUFeaturesARM(void) { uint64_t result = 0; int architecture = 0; uint64_t hwcap = 0; @@ -89,4 +91,6 @@ uint64_t WebRtc_GetCPUFeaturesARM(void) { result |= kCPUFeatureLDREXSTREX; return result; } + +} // namespace webrtc #endif // WEBRTC_ARCH_ARM_FAMILY