Refactor cpu_features_wrapper.h functions from C to C++.
As mentioned on https://webrtc-review.googlesource.com/c/src/+/183380,
then relanded as https://webrtc-review.googlesource.com/c/src/+/183444,
functions in cpu_features_wrapper.h should be refactored to use
C++ features like namespaces and drop the WebRtc_ prefix.
Bug: None
Change-Id: I3e83e1668f9bf48a5d8e85d809f006666b7fa45e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/183445
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32045}
diff --git a/common_audio/fir_filter_factory.cc b/common_audio/fir_filter_factory.cc
index bfa198f..4bcf052 100644
--- a/common_audio/fir_filter_factory.cc
+++ b/common_audio/fir_filter_factory.cc
@@ -36,10 +36,10 @@
// 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 831ce53..4fa78c5 100644
--- a/common_audio/resampler/sinc_resampler.cc
+++ b/common_audio/resampler/sinc_resampler.cc
@@ -127,9 +127,9 @@
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 ece6af0..5bfb2d0 100644
--- a/common_audio/resampler/sinc_resampler_unittest.cc
+++ b/common_audio/resampler/sinc_resampler_unittest.cc
@@ -121,9 +121,9 @@
// 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 @@
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 6b6d6f1..6933120 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() {
#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 36fbdd6..067d8f3 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 fc30f7f..d2af70a 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 @@
// 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<std::array<float, kFftLengthBy2Plus1>> H2(kNumPartitions);
@@ -78,7 +78,7 @@
// 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<std::array<float, kFftLengthBy2Plus1>> 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 a18ebd8..af7ea1d 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 @@
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<RenderDelayBuffer> render_delay_buffer(
@@ -254,7 +254,7 @@
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<RenderDelayBuffer> render_delay_buffer(
@@ -326,7 +326,7 @@
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<std::vector<FftData>> H(
@@ -361,7 +361,7 @@
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<std::vector<FftData>> H(
diff --git a/modules/audio_processing/aec3/aec3_common.cc b/modules/audio_processing/aec3/aec3_common.cc
index 6aaab61..7bd8d62 100644
--- a/modules/audio_processing/aec3/aec3_common.cc
+++ b/modules/audio_processing/aec3/aec3_common.cc
@@ -20,9 +20,9 @@
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 d1d4f7d..8dfa183 100644
--- a/modules/audio_processing/aec3/aec3_fft.cc
+++ b/modules/audio_processing/aec3/aec3_fft.cc
@@ -73,7 +73,7 @@
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 b0235a7..d76fabd 100644
--- a/modules/audio_processing/aec3/fft_data_unittest.cc
+++ b/modules/audio_processing/aec3/fft_data_unittest.cc
@@ -20,7 +20,7 @@
// 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 @@
// 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 7e16c01..137275f 100644
--- a/modules/audio_processing/aec3/matched_filter_unittest.cc
+++ b/modules/audio_processing/aec3/matched_filter_unittest.cc
@@ -93,7 +93,7 @@
// 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, 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 bd156b5..a9c37e3 100644
--- a/modules/audio_processing/aec3/vector_math_unittest.cc
+++ b/modules/audio_processing/aec3/vector_math_unittest.cc
@@ -80,7 +80,7 @@
#if defined(WEBRTC_ARCH_X86_FAMILY)
TEST(VectorMath, Sse2Sqrt) {
- if (WebRtc_GetCPUInfo(kSSE2) != 0) {
+ if (GetCPUInfo(kSSE2) != 0) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_sse2;
@@ -102,7 +102,7 @@
}
TEST(VectorMath, Avx2Sqrt) {
- if (WebRtc_GetCPUInfo(kAVX2) != 0) {
+ if (GetCPUInfo(kAVX2) != 0) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_avx2;
@@ -124,7 +124,7 @@
}
TEST(VectorMath, Sse2Multiply) {
- if (WebRtc_GetCPUInfo(kSSE2) != 0) {
+ if (GetCPUInfo(kSSE2) != 0) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> y;
std::array<float, kFftLengthBy2Plus1> z;
@@ -145,7 +145,7 @@
}
TEST(VectorMath, Avx2Multiply) {
- if (WebRtc_GetCPUInfo(kAVX2) != 0) {
+ if (GetCPUInfo(kAVX2) != 0) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> y;
std::array<float, kFftLengthBy2Plus1> z;
@@ -166,7 +166,7 @@
}
TEST(VectorMath, Sse2Accumulate) {
- if (WebRtc_GetCPUInfo(kSSE2) != 0) {
+ if (GetCPUInfo(kSSE2) != 0) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_sse2;
@@ -186,7 +186,7 @@
}
TEST(VectorMath, Avx2Accumulate) {
- if (WebRtc_GetCPUInfo(kAVX2) != 0) {
+ if (GetCPUInfo(kAVX2) != 0) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_avx2;
diff --git a/modules/audio_processing/agc2/rnn_vad/common.cc b/modules/audio_processing/agc2/rnn_vad/common.cc
index 744c87f..5d76b52 100644
--- a/modules/audio_processing/agc2/rnn_vad/common.cc
+++ b/modules/audio_processing/agc2/rnn_vad/common.cc
@@ -18,7 +18,7 @@
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 1a8e1a2..c7bf02e 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 @@
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 38334f7..a06413d 100644
--- a/modules/audio_processing/agc2/signal_classifier.cc
+++ b/modules/audio_processing/agc2/signal_classifier.cc
@@ -26,7 +26,7 @@
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 dd9ab45..4f0c543 100644
--- a/modules/desktop_capture/differ_block.cc
+++ b/modules/desktop_capture/differ_block.cc
@@ -35,7 +35,7 @@
// 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 d6b5094..0e15701 100644
--- a/modules/video_processing/util/denoiser_filter.cc
+++ b/modules/video_processing/util/denoiser_filter.cc
@@ -41,7 +41,7 @@
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 f4b3fed..612b4a5 100644
--- a/system_wrappers/include/cpu_features_wrapper.h
+++ b/system_wrappers/include/cpu_features_wrapper.h
@@ -13,6 +13,8 @@
#include <stdint.h>
+namespace webrtc {
+
// List of features in x86.
typedef enum { kSSE2, kSSE3, kAVX2 } CPUFeature;
@@ -24,17 +26,17 @@
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 40110ed..e40c65a 100644
--- a/system_wrappers/source/cpu_features.cc
+++ b/system_wrappers/source/cpu_features.cc
@@ -17,6 +17,8 @@
#include <intrin.h>
#endif
+namespace webrtc {
+
// No CPU feature is available => straight C path.
int GetCPUInfoNoASM(CPUFeature feature) {
(void)feature;
@@ -65,7 +67,7 @@
#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 @@
}
#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 0cb3a6c..95cc609 100644
--- a/system_wrappers/source/cpu_features_android.cc
+++ b/system_wrappers/source/cpu_features_android.cc
@@ -10,6 +10,10 @@
#include <cpu-features.h>
-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 05ff9b3..335bed4 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 <asm/hwcap.h>
-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 @@
result |= kCPUFeatureLDREXSTREX;
return result;
}
+
+} // namespace webrtc
#endif // WEBRTC_ARCH_ARM_FAMILY