Remove system_wrappers/ GetCPUInfo() function.

Functionality moved to rtc_base/ cpu_info::Supports().

Bug: webrtc:42228262
Change-Id: I0ef2fc645447779aac2339580884ea042bdd315b
No-Iwyu: Avoid unrelated changes
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/393561
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Auto-Submit: Fredrik Solenberg <solenberg@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#44768}
This commit is contained in:
Fredrik Solenberg 2025-05-26 22:44:15 +02:00 committed by WebRTC LUCI CQ
parent 0411de876e
commit 203aa90741
31 changed files with 155 additions and 181 deletions

View File

@ -48,6 +48,7 @@ rtc_library("common_audio") {
"../api:array_view",
"../api/audio:audio_frame_api",
"../rtc_base:checks",
"../rtc_base:cpu_info",
"../rtc_base:gtest_prod",
"../rtc_base:logging",
"../rtc_base:safe_conversions",
@ -56,7 +57,6 @@ rtc_library("common_audio") {
"../rtc_base/memory:aligned_malloc",
"../rtc_base/system:arch",
"../rtc_base/system:file_wrapper",
"../system_wrappers",
"third_party/ooura:fft_size_256",
]
@ -206,10 +206,10 @@ rtc_library("common_audio_cc") {
rtc_source_set("sinc_resampler") {
sources = [ "resampler/sinc_resampler.h" ]
deps = [
"../rtc_base:cpu_info",
"../rtc_base:gtest_prod",
"../rtc_base/memory:aligned_malloc",
"../rtc_base/system:arch",
"../system_wrappers",
]
}
@ -229,8 +229,8 @@ rtc_library("fir_filter_factory") {
deps = [
":fir_filter",
"../rtc_base:checks",
"../rtc_base:cpu_info",
"../rtc_base/system:arch",
"../system_wrappers",
]
if (current_cpu == "x86" || current_cpu == "x64") {
deps += [ ":common_audio_sse2" ]
@ -377,6 +377,7 @@ if (rtc_include_tests && !build_with_chromium) {
":fir_filter_factory",
":sinc_resampler",
"../rtc_base:checks",
"../rtc_base:cpu_info",
"../rtc_base:logging",
"../rtc_base:macromagic",
"../rtc_base:rtc_base_tests_utils",

View File

@ -12,6 +12,7 @@
#include "common_audio/fir_filter_c.h"
#include "rtc_base/checks.h"
#include "rtc_base/cpu_info.h"
#include "rtc_base/system/arch.h"
#if defined(WEBRTC_HAS_NEON)
@ -19,7 +20,6 @@
#elif defined(WEBRTC_ARCH_X86_FAMILY)
#include "common_audio/fir_filter_avx2.h"
#include "common_audio/fir_filter_sse.h"
#include "system_wrappers/include/cpu_features_wrapper.h" // kSSE2, WebRtc_G...
#endif
namespace webrtc {
@ -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 (GetCPUInfo(kAVX2)) {
if (cpu_info::Supports(cpu_info::ISA::kAVX2)) {
filter =
new FIRFilterAVX2(coefficients, coefficients_length, max_input_length);
} else if (GetCPUInfo(kSSE2)) {
} else if (cpu_info::Supports(cpu_info::ISA::kSSE2)) {
filter =
new FIRFilterSSE2(coefficients, coefficients_length, max_input_length);
} else {

View File

@ -94,8 +94,8 @@
#include <limits>
#include "rtc_base/checks.h"
#include "rtc_base/cpu_info.h"
#include "rtc_base/system/arch.h"
#include "system_wrappers/include/cpu_features_wrapper.h" // kSSE2, WebRtc_G...
namespace webrtc {
@ -127,9 +127,10 @@ void SincResampler::InitializeCPUSpecificFeatures() {
convolve_proc_ = Convolve_NEON;
#elif defined(WEBRTC_ARCH_X86_FAMILY)
// Using AVX2 instead of SSE2 when AVX2/FMA3 supported.
if (GetCPUInfo(kAVX2) && GetCPUInfo(kFMA3))
if (cpu_info::Supports(cpu_info::ISA::kAVX2) &&
cpu_info::Supports(cpu_info::ISA::kFMA3))
convolve_proc_ = Convolve_AVX2;
else if (GetCPUInfo(kSSE2))
else if (cpu_info::Supports(cpu_info::ISA::kSSE2))
convolve_proc_ = Convolve_SSE;
else
convolve_proc_ = Convolve_C;

View File

@ -23,6 +23,7 @@
#include <tuple>
#include "common_audio/resampler/sinusoidal_linear_chirp_source.h"
#include "rtc_base/cpu_info.h"
#include "rtc_base/system/arch.h"
#include "rtc_base/time_utils.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
@ -119,7 +120,7 @@ TEST(SincResamplerTest, DISABLED_SetRatioBench) {
// will be tested by the parameterized SincResampler tests below.
TEST(SincResamplerTest, Convolve) {
#if defined(WEBRTC_ARCH_X86_FAMILY)
ASSERT_TRUE(GetCPUInfo(kSSE2));
ASSERT_TRUE(cpu_info::Supports(cpu_info::ISA::kSSE2));
#elif defined(WEBRTC_ARCH_ARM_V7)
ASSERT_TRUE(GetCPUFeaturesARM() & kCPUFeatureNEON);
#endif
@ -179,7 +180,7 @@ TEST(SincResamplerTest, ConvolveBenchmark) {
printf("Convolve_C took %.2fms.\n", total_time_c_us / 1000);
#if defined(WEBRTC_ARCH_X86_FAMILY)
ASSERT_TRUE(GetCPUInfo(kSSE2));
ASSERT_TRUE(cpu_info::Supports(cpu_info::ISA::kSSE2));
#elif defined(WEBRTC_ARCH_ARM_V7)
ASSERT_TRUE(GetCPUFeaturesARM() & kCPUFeatureNEON);
#endif

View File

@ -15,8 +15,8 @@ rtc_library("fft_size_128") {
"fft_size_128/ooura_fft_tables_common.h",
]
deps = [
"../../../rtc_base:cpu_info",
"../../../rtc_base/system:arch",
"../../../system_wrappers",
]
cflags = []

View File

@ -24,8 +24,8 @@
#include "common_audio/third_party/ooura/fft_size_128/ooura_fft.h"
#include "common_audio/third_party/ooura/fft_size_128/ooura_fft_tables_common.h"
#include "rtc_base/cpu_info.h"
#include "rtc_base/system/arch.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
namespace webrtc {
@ -323,7 +323,7 @@ OouraFft::OouraFft([[maybe_unused]] bool sse2_available) {
OouraFft::OouraFft() {
#if defined(WEBRTC_ARCH_X86_FAMILY)
use_sse2_ = (GetCPUInfo(kSSE2) != 0);
use_sse2_ = cpu_info::Supports(cpu_info::ISA::kSSE2);
#else
use_sse2_ = false;
#endif

View File

@ -376,6 +376,7 @@ if (rtc_include_tests) {
"../../common_audio",
"../../common_audio:common_audio_c",
"../../rtc_base:checks",
"../../rtc_base:cpu_info",
"../../rtc_base:denormal_disabler",
"../../rtc_base:gtest_prod",
"../../rtc_base:macromagic",
@ -393,7 +394,6 @@ if (rtc_include_tests) {
"../../rtc_base/synchronization:mutex",
"../../rtc_base/system:arch",
"../../rtc_base/system:file_wrapper",
"../../system_wrappers",
"../../test:field_trial",
"../../test:fileutils",
"../../test:rtc_expect_death",

View File

@ -147,6 +147,7 @@ rtc_library("aec3") {
"../../../api/environment",
"../../../common_audio:common_audio_c",
"../../../rtc_base:checks",
"../../../rtc_base:cpu_info",
"../../../rtc_base:logging",
"../../../rtc_base:macromagic",
"../../../rtc_base:race_checker",
@ -154,7 +155,6 @@ rtc_library("aec3") {
"../../../rtc_base:swap_queue",
"../../../rtc_base/experiments:field_trial_parser",
"../../../rtc_base/system:arch",
"../../../system_wrappers",
"../../../system_wrappers:metrics",
"../utility:cascaded_biquad_filter",
"//third_party/abseil-cpp/absl/strings:string_view",
@ -317,12 +317,12 @@ if (rtc_include_tests) {
"../../../api/environment",
"../../../api/environment:environment_factory",
"../../../rtc_base:checks",
"../../../rtc_base:cpu_info",
"../../../rtc_base:macromagic",
"../../../rtc_base:random",
"../../../rtc_base:safe_minmax",
"../../../rtc_base:stringutils",
"../../../rtc_base/system:arch",
"../../../system_wrappers",
"../../../system_wrappers:metrics",
"../../../test:explicit_key_value_config",
"../../../test:field_trial",

View File

@ -13,12 +13,12 @@
#include <array>
#include <vector>
#include "rtc_base/cpu_info.h"
#include "rtc_base/system/arch.h"
#if defined(WEBRTC_ARCH_X86_FAMILY)
#include <emmintrin.h>
#endif
#include "system_wrappers/include/cpu_features_wrapper.h"
#include "test/gtest.h"
namespace webrtc {
@ -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 = (GetCPUInfo(kSSE2) != 0);
bool use_sse2 = cpu_info::Supports(cpu_info::ISA::kSSE2);
if (use_sse2) {
const size_t kNumPartitions = 12;
std::vector<std::array<float, kFftLengthBy2Plus1>> 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 = (GetCPUInfo(kAVX2) != 0);
bool use_avx2 = cpu_info::Supports(cpu_info::ISA::kAVX2);
if (use_avx2) {
const size_t kNumPartitions = 12;
std::vector<std::array<float, kFftLengthBy2Plus1>> H2(kNumPartitions);

View File

@ -32,6 +32,7 @@
#include "modules/audio_processing/aec3/fft_data.h"
#include "modules/audio_processing/aec3/subtractor_output.h"
#include "rtc_base/checks.h"
#include "rtc_base/cpu_info.h"
#include "rtc_base/system/arch.h"
#if defined(WEBRTC_ARCH_X86_FAMILY)
#include <emmintrin.h>
@ -50,7 +51,6 @@
#include "rtc_base/numerics/safe_minmax.h"
#include "rtc_base/random.h"
#include "rtc_base/strings/string_builder.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
#include "test/gtest.h"
namespace webrtc {
@ -191,7 +191,7 @@ TEST_P(AdaptiveFirFilterOneTwoFourEightRenderChannels,
constexpr int kSampleRateHz = 48000;
constexpr size_t kNumBands = NumBandsForRate(kSampleRateHz);
bool use_sse2 = (GetCPUInfo(kSSE2) != 0);
bool use_sse2 = cpu_info::Supports(cpu_info::ISA::kSSE2);
if (use_sse2) {
for (size_t num_partitions : {2, 5, 12, 30, 50}) {
std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
@ -263,7 +263,7 @@ TEST_P(AdaptiveFirFilterOneTwoFourEightRenderChannels,
constexpr int kSampleRateHz = 48000;
constexpr size_t kNumBands = NumBandsForRate(kSampleRateHz);
bool use_avx2 = (GetCPUInfo(kAVX2) != 0);
bool use_avx2 = cpu_info::Supports(cpu_info::ISA::kAVX2);
if (use_avx2) {
for (size_t num_partitions : {2, 5, 12, 30, 50}) {
std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
@ -332,7 +332,7 @@ TEST_P(AdaptiveFirFilterOneTwoFourEightRenderChannels,
TEST_P(AdaptiveFirFilterOneTwoFourEightRenderChannels,
ComputeFrequencyResponseSse2Optimization) {
const size_t num_render_channels = GetParam();
bool use_sse2 = (GetCPUInfo(kSSE2) != 0);
bool use_sse2 = cpu_info::Supports(cpu_info::ISA::kSSE2);
if (use_sse2) {
for (size_t num_partitions : {2, 5, 12, 30, 50}) {
std::vector<std::vector<FftData>> H(
@ -367,7 +367,7 @@ TEST_P(AdaptiveFirFilterOneTwoFourEightRenderChannels,
TEST_P(AdaptiveFirFilterOneTwoFourEightRenderChannels,
ComputeFrequencyResponseAvx2Optimization) {
const size_t num_render_channels = GetParam();
bool use_avx2 = (GetCPUInfo(kAVX2) != 0);
bool use_avx2 = cpu_info::Supports(cpu_info::ISA::kAVX2);
if (use_avx2) {
for (size_t num_partitions : {2, 5, 12, 30, 50}) {
std::vector<std::vector<FftData>> H(

View File

@ -13,16 +13,16 @@
#include <stdint.h>
#include "rtc_base/checks.h"
#include "rtc_base/cpu_info.h"
#include "rtc_base/system/arch.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
namespace webrtc {
Aec3Optimization DetectOptimization() {
#if defined(WEBRTC_ARCH_X86_FAMILY)
if (GetCPUInfo(kAVX2) != 0) {
if (cpu_info::Supports(cpu_info::ISA::kAVX2)) {
return Aec3Optimization::kAvx2;
} else if (GetCPUInfo(kSSE2) != 0) {
} else if (cpu_info::Supports(cpu_info::ISA::kSSE2)) {
return Aec3Optimization::kSse2;
}
#endif

View File

@ -15,7 +15,7 @@
#include <iterator>
#include "rtc_base/checks.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
#include "rtc_base/cpu_info.h"
namespace webrtc {
@ -73,7 +73,7 @@ const float kSqrtHanning128[kFftLength] = {
bool IsSse2Available() {
#if defined(WEBRTC_ARCH_X86_FAMILY)
return GetCPUInfo(kSSE2) != 0;
return cpu_info::Supports(cpu_info::ISA::kSSE2);
#else
return false;
#endif

View File

@ -16,9 +16,6 @@
#include "api/audio/echo_canceller3_config.h"
#include "api/environment/environment_factory.h"
#include "modules/audio_processing/aec3/aec_state.h"
#include "rtc_base/random.h"
#include "rtc_base/system/arch.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
#include "test/gtest.h"
namespace webrtc {

View File

@ -10,8 +10,8 @@
#include "modules/audio_processing/aec3/fft_data.h"
#include "rtc_base/cpu_info.h"
#include "rtc_base/system/arch.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
#include "test/gtest.h"
namespace webrtc {
@ -20,7 +20,7 @@ namespace webrtc {
// Verifies that the optimized methods are bitexact to their reference
// counterparts.
TEST(FftData, TestSse2Optimizations) {
if (GetCPUInfo(kSSE2) != 0) {
if (cpu_info::Supports(cpu_info::ISA::kSSE2)) {
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 (GetCPUInfo(kAVX2) != 0) {
if (cpu_info::Supports(cpu_info::ISA::kAVX2)) {
FftData x;
for (size_t k = 0; k < x.re.size(); ++k) {

View File

@ -22,6 +22,7 @@
#include "api/audio/echo_canceller3_config.h"
#include "modules/audio_processing/aec3/block.h"
#include "rtc_base/checks.h"
#include "rtc_base/cpu_info.h"
#include "rtc_base/system/arch.h"
#if defined(WEBRTC_ARCH_X86_FAMILY)
@ -37,7 +38,6 @@
#include "modules/audio_processing/test/echo_canceller_test_tools.h"
#include "rtc_base/random.h"
#include "rtc_base/strings/string_builder.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
#include "test/gtest.h"
namespace webrtc {
@ -126,7 +126,7 @@ TEST_P(MatchedFilterTest, TestNeonOptimizations) {
// counterparts.
TEST_P(MatchedFilterTest, TestSse2Optimizations) {
const bool kComputeAccumulatederror = GetParam();
bool use_sse2 = (GetCPUInfo(kSSE2) != 0);
bool use_sse2 = cpu_info::Supports(cpu_info::ISA::kSSE2);
if (use_sse2) {
Random random_generator(42U);
constexpr float kSmoothing = 0.7f;
@ -181,7 +181,7 @@ TEST_P(MatchedFilterTest, TestSse2Optimizations) {
}
TEST_P(MatchedFilterTest, TestAvx2Optimizations) {
bool use_avx2 = (GetCPUInfo(kAVX2) != 0);
bool use_avx2 = cpu_info::Supports(cpu_info::ISA::kAVX2);
const bool kComputeAccumulatederror = GetParam();
if (use_avx2) {
Random random_generator(42U);

View File

@ -18,7 +18,6 @@
#include "modules/audio_processing/aec3/subtractor_output.h"
#include "modules/audio_processing/logging/apm_data_dumper.h"
#include "rtc_base/checks.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
#include "test/gtest.h"
namespace webrtc {

View File

@ -12,8 +12,8 @@
#include <math.h>
#include "rtc_base/cpu_info.h"
#include "rtc_base/system/arch.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
#include "test/gtest.h"
namespace webrtc {
@ -80,7 +80,7 @@ TEST(VectorMath, Accumulate) {
#if defined(WEBRTC_ARCH_X86_FAMILY)
TEST(VectorMath, Sse2Sqrt) {
if (GetCPUInfo(kSSE2) != 0) {
if (cpu_info::Supports(cpu_info::ISA::kSSE2)) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_sse2;
@ -102,7 +102,7 @@ TEST(VectorMath, Sse2Sqrt) {
}
TEST(VectorMath, Avx2Sqrt) {
if (GetCPUInfo(kAVX2) != 0) {
if (cpu_info::Supports(cpu_info::ISA::kAVX2)) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_avx2;
@ -124,7 +124,7 @@ TEST(VectorMath, Avx2Sqrt) {
}
TEST(VectorMath, Sse2Multiply) {
if (GetCPUInfo(kSSE2) != 0) {
if (cpu_info::Supports(cpu_info::ISA::kSSE2)) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> y;
std::array<float, kFftLengthBy2Plus1> z;
@ -145,7 +145,7 @@ TEST(VectorMath, Sse2Multiply) {
}
TEST(VectorMath, Avx2Multiply) {
if (GetCPUInfo(kAVX2) != 0) {
if (cpu_info::Supports(cpu_info::ISA::kAVX2)) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> y;
std::array<float, kFftLengthBy2Plus1> z;
@ -166,7 +166,7 @@ TEST(VectorMath, Avx2Multiply) {
}
TEST(VectorMath, Sse2Accumulate) {
if (GetCPUInfo(kSSE2) != 0) {
if (cpu_info::Supports(cpu_info::ISA::kSSE2)) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_sse2;
@ -186,7 +186,7 @@ TEST(VectorMath, Sse2Accumulate) {
}
TEST(VectorMath, Avx2Accumulate) {
if (GetCPUInfo(kAVX2) != 0) {
if (cpu_info::Supports(cpu_info::ISA::kAVX2)) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_avx2;

View File

@ -21,7 +21,6 @@ rtc_library("aecm_core") {
"../../../rtc_base:checks",
"../../../rtc_base:safe_conversions",
"../../../rtc_base:sanitizer",
"../../../system_wrappers",
"../utility:legacy_delay_estimator",
]
cflags = []

View File

@ -19,10 +19,6 @@ extern "C" {
}
#include "modules/audio_processing/aecm/echo_control_mobile.h"
#include "modules/audio_processing/utility/delay_estimator_wrapper.h"
extern "C" {
#include "system_wrappers/include/cpu_features_wrapper.h"
}
#include "rtc_base/checks.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/sanitizer.h"

View File

@ -282,9 +282,9 @@ rtc_library("cpu_features") {
]
deps = [
"../../../rtc_base:cpu_info",
"../../../rtc_base:stringutils",
"../../../rtc_base/system:arch",
"../../../system_wrappers",
]
}

View File

@ -10,9 +10,9 @@
#include "modules/audio_processing/agc2/cpu_features.h"
#include "rtc_base/cpu_info.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/system/arch.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
namespace webrtc {
@ -41,8 +41,8 @@ std::string AvailableCpuFeatures::ToString() const {
// Detects available CPU features.
AvailableCpuFeatures GetAvailableCpuFeatures() {
#if defined(WEBRTC_ARCH_X86_FAMILY)
return {/*sse2=*/GetCPUInfo(kSSE2) != 0,
/*avx2=*/GetCPUInfo(kAVX2) != 0,
return {/*sse2=*/cpu_info::Supports(cpu_info::ISA::kSSE2),
/*avx2=*/cpu_info::Supports(cpu_info::ISA::kAVX2),
/*neon=*/false};
#elif defined(WEBRTC_HAS_NEON)
return {/*sse2=*/false,

View File

@ -51,6 +51,7 @@
#include "modules/audio_processing/test/test_utils.h"
#include "rtc_base/arraysize.h"
#include "rtc_base/checks.h"
#include "rtc_base/cpu_info.h"
#include "rtc_base/fake_clock.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/numerics/safe_minmax.h"
@ -59,7 +60,6 @@
#include "rtc_base/swap_queue.h"
#include "rtc_base/system/file_wrapper.h"
#include "rtc_base/task_queue_for_test.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/testsupport/file_utils.h"
@ -295,7 +295,7 @@ std::string GetReferenceFilename() {
#if defined(WEBRTC_AUDIOPROC_FIXED_PROFILE)
return test::ResourcePath("audio_processing/output_data_fixed", "pb");
#elif defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE)
if (GetCPUInfo(kAVX2) != 0) {
if (cpu_info::Supports(cpu_info::ISA::kAVX2)) {
return test::ResourcePath("audio_processing/output_data_float_avx2", "pb");
}
return test::ResourcePath("audio_processing/output_data_float", "pb");

View File

@ -161,7 +161,6 @@ if (rtc_include_tests) {
"../../rtc_base:task_queue_for_test",
"../../rtc_base:threading",
"../../rtc_base:timeutils",
"../../system_wrappers",
"../../test:test_support",
]
@ -433,6 +432,7 @@ rtc_library("desktop_capture") {
"../../api:scoped_refptr",
"../../api:sequence_checker",
"../../rtc_base:checks",
"../../rtc_base:cpu_info",
"../../rtc_base:event_tracer",
"../../rtc_base:logging",
"../../rtc_base:macromagic",
@ -443,7 +443,6 @@ rtc_library("desktop_capture") {
"../../rtc_base/system:arch",
"../../rtc_base/system:no_unique_address",
"../../rtc_base/system:rtc_export",
"../../system_wrappers",
"../../system_wrappers:metrics",
]

View File

@ -22,7 +22,6 @@
#include "modules/desktop_capture/mock_desktop_capturer_callback.h"
#include "rtc_base/random.h"
#include "rtc_base/time_utils.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
#include "test/gtest.h"
namespace webrtc {

View File

@ -12,8 +12,8 @@
#include <string.h>
#include "rtc_base/cpu_info.h"
#include "rtc_base/system/arch.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
// This needs to be after rtc_base/system/arch.h which defines
// architecture macros.
@ -36,7 +36,7 @@ bool VectorDifference(const uint8_t* image1, const uint8_t* image2) {
if (!diff_proc) {
#if defined(WEBRTC_ARCH_X86_FAMILY)
bool have_sse2 = GetCPUInfo(kSSE2) != 0;
bool have_sse2 = cpu_info::Supports(cpu_info::ISA::kSSE2);
// For x86 processors, check if SSE2 is supported.
if (have_sse2 && kBlockSize == 32) {
diff_proc = &VectorDifference_SSE2_W32;

View File

@ -1892,6 +1892,8 @@ rtc_library("cpu_info") {
deps = [
":checks",
":logging",
"system:arch",
"system:unused",
]
}

View File

@ -24,6 +24,14 @@
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/system/arch.h"
#include "rtc_base/system/unused.h" // IWYU pragma: keep
#if defined(WEBRTC_ARCH_X86_FAMILY) && defined(_MSC_VER)
#include <intrin.h>
#endif
// Parts of this file derived from Chromium's base/cpu.cc.
namespace {
@ -60,6 +68,47 @@ uint32_t DetectNumberOfCores() {
return static_cast<uint32_t>(number_of_cores);
}
#if defined(WEBRTC_ARCH_X86_FAMILY)
#if defined(WEBRTC_ENABLE_AVX2)
// xgetbv returns the value of an Intel Extended Control Register (XCR).
// Currently only XCR0 is defined by Intel so `xcr` should always be zero.
uint64_t xgetbv(uint32_t xcr) {
#if defined(_MSC_VER)
return _xgetbv(xcr);
#else
uint32_t eax, edx;
__asm__ volatile("xgetbv" : "=a"(eax), "=d"(edx) : "c"(xcr));
return (static_cast<uint64_t>(edx) << 32) | eax;
#endif // _MSC_VER
}
#endif // WEBRTC_ENABLE_AVX2
#ifndef _MSC_VER
// Intrinsic for "cpuid".
#if defined(__pic__) && defined(__i386__)
static inline void __cpuid(int cpu_info[4], int info_type) {
__asm__ volatile(
"mov %%ebx, %%edi\n"
"cpuid\n"
"xchg %%edi, %%ebx\n"
: "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]),
"=d"(cpu_info[3])
: "a"(info_type));
}
#else
static inline void __cpuid(int cpu_info[4], int info_type) {
__asm__ volatile("cpuid\n"
: "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]),
"=d"(cpu_info[3])
: "a"(info_type), "c"(0));
}
#endif
#endif // _MSC_VER
#endif // WEBRTC_ARCH_X86_FAMILY
} // namespace
namespace webrtc {
@ -75,6 +124,50 @@ uint32_t DetectNumberOfCores() {
return logical_cpus;
}
bool Supports(ISA instruction_set_architecture) {
#if defined(WEBRTC_ARCH_X86_FAMILY)
int cpu_info[4];
__cpuid(cpu_info, 1);
if (instruction_set_architecture == ISA::kSSE2) {
return 0 != (cpu_info[3] & 0x04000000);
}
if (instruction_set_architecture == ISA::kSSE3) {
return 0 != (cpu_info[2] & 0x00000001);
}
#if defined(WEBRTC_ENABLE_AVX2)
if (instruction_set_architecture == ISA::kAVX2) {
int cpu_info7[4];
__cpuid(cpu_info7, 0);
int num_ids = cpu_info7[0];
if (num_ids < 7) {
return false;
}
// Interpret CPU feature information.
__cpuid(cpu_info7, 7);
// AVX instructions can be used when
// a) AVX are supported by the CPU,
// b) XSAVE is supported by the CPU,
// c) XSAVE is enabled by the kernel.
// Compiling with MSVC and /arch:AVX2 surprisingly generates BMI2
// instructions (see crbug.com/1315519).
return (cpu_info[2] & 0x10000000) != 0 /* AVX */ &&
(cpu_info[2] & 0x04000000) != 0 /* XSAVE */ &&
(cpu_info[2] & 0x08000000) != 0 /* OSXSAVE */ &&
(xgetbv(0) & 0x00000006) == 6 /* XSAVE enabled by kernel */ &&
(cpu_info7[1] & 0x00000020) != 0 /* AVX2 */ &&
(cpu_info7[1] & 0x00000100) != 0 /* BMI2 */;
}
#endif // WEBRTC_ENABLE_AVX2
if (instruction_set_architecture == ISA::kFMA3) {
return 0 != (cpu_info[2] & 0x00001000);
}
#else // WEBRTC_ARCH_X86_FAMILY
RTC_UNUSED(instruction_set_architecture);
#endif
return false;
}
} // namespace cpu_info
} // namespace webrtc

View File

@ -20,6 +20,11 @@ namespace cpu_info {
// Returned number of cores is always >= 1.
uint32_t DetectNumberOfCores();
enum class ISA { kSSE2 = 0, kSSE3, kAVX2, kFMA3, kNeon };
// Returns true if the CPU supports the given instruction set.
bool Supports(ISA instruction_set_architecture);
} // namespace cpu_info
} // namespace webrtc

View File

@ -19,7 +19,6 @@ rtc_library("system_wrappers") {
"include/cpu_features_wrapper.h",
"include/ntp_time.h",
"source/clock.cc",
"source/cpu_features.cc",
]
defines = []

View File

@ -15,9 +15,6 @@
namespace webrtc {
// List of features in x86.
typedef enum { kSSE2, kSSE3, kAVX2, kFMA3 } CPUFeature;
// List of features in ARM.
enum {
kCPUFeatureARMv7 = (1 << 0),
@ -26,9 +23,6 @@ enum {
kCPUFeatureLDREXSTREX = (1 << 3)
};
// Returns true if the CPU supports the feature.
int GetCPUInfo(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.

View File

@ -1,111 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// Parts of this file derived from Chromium's base/cpu.cc.
#include "rtc_base/system/arch.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
#if defined(WEBRTC_ARCH_X86_FAMILY) && defined(_MSC_VER)
#include <intrin.h>
#endif
namespace webrtc {
#if defined(WEBRTC_ARCH_X86_FAMILY)
#if defined(WEBRTC_ENABLE_AVX2)
// xgetbv returns the value of an Intel Extended Control Register (XCR).
// Currently only XCR0 is defined by Intel so `xcr` should always be zero.
static uint64_t xgetbv(uint32_t xcr) {
#if defined(_MSC_VER)
return _xgetbv(xcr);
#else
uint32_t eax, edx;
__asm__ volatile("xgetbv" : "=a"(eax), "=d"(edx) : "c"(xcr));
return (static_cast<uint64_t>(edx) << 32) | eax;
#endif // _MSC_VER
}
#endif // WEBRTC_ENABLE_AVX2
#ifndef _MSC_VER
// Intrinsic for "cpuid".
#if defined(__pic__) && defined(__i386__)
static inline void __cpuid(int cpu_info[4], int info_type) {
__asm__ volatile(
"mov %%ebx, %%edi\n"
"cpuid\n"
"xchg %%edi, %%ebx\n"
: "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]),
"=d"(cpu_info[3])
: "a"(info_type));
}
#else
static inline void __cpuid(int cpu_info[4], int info_type) {
__asm__ volatile("cpuid\n"
: "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]),
"=d"(cpu_info[3])
: "a"(info_type), "c"(0));
}
#endif
#endif // _MSC_VER
#endif // WEBRTC_ARCH_X86_FAMILY
#if defined(WEBRTC_ARCH_X86_FAMILY)
// Actual feature detection for x86.
int GetCPUInfo(CPUFeature feature) {
int cpu_info[4];
__cpuid(cpu_info, 1);
if (feature == kSSE2) {
return 0 != (cpu_info[3] & 0x04000000);
}
if (feature == kSSE3) {
return 0 != (cpu_info[2] & 0x00000001);
}
#if defined(WEBRTC_ENABLE_AVX2)
if (feature == kAVX2) {
int cpu_info7[4];
__cpuid(cpu_info7, 0);
int num_ids = cpu_info7[0];
if (num_ids < 7) {
return 0;
}
// Interpret CPU feature information.
__cpuid(cpu_info7, 7);
// AVX instructions can be used when
// a) AVX are supported by the CPU,
// b) XSAVE is supported by the CPU,
// c) XSAVE is enabled by the kernel.
// Compiling with MSVC and /arch:AVX2 surprisingly generates BMI2
// instructions (see crbug.com/1315519).
return (cpu_info[2] & 0x10000000) != 0 /* AVX */ &&
(cpu_info[2] & 0x04000000) != 0 /* XSAVE */ &&
(cpu_info[2] & 0x08000000) != 0 /* OSXSAVE */ &&
(xgetbv(0) & 0x00000006) == 6 /* XSAVE enabled by kernel */ &&
(cpu_info7[1] & 0x00000020) != 0 /* AVX2 */ &&
(cpu_info7[1] & 0x00000100) != 0 /* BMI2 */;
}
#endif // WEBRTC_ENABLE_AVX2
if (feature == kFMA3) {
return 0 != (cpu_info[2] & 0x00001000);
}
return 0;
}
#else
// Default to straight C for other platforms.
int GetCPUInfo(CPUFeature feature) {
(void)feature;
return 0;
}
#endif
} // namespace webrtc