blob: cced7614bc9dac7b3c66f9077658f9cfe9f9d206 [file] [log] [blame]
Alessio Bazzica253f8362020-11-27 16:02:38 +01001/*
2 * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "modules/audio_processing/agc2/cpu_features.h"
12
13#include "rtc_base/strings/string_builder.h"
14#include "rtc_base/system/arch.h"
15#include "system_wrappers/include/cpu_features_wrapper.h"
16
17namespace webrtc {
18
19std::string AvailableCpuFeatures::ToString() const {
20 char buf[64];
21 rtc::SimpleStringBuilder builder(buf);
22 bool first = true;
23 if (sse2) {
24 builder << (first ? "SSE2" : "_SSE2");
25 first = false;
26 }
27 if (avx2) {
28 builder << (first ? "AVX2" : "_AVX2");
29 first = false;
30 }
31 if (neon) {
32 builder << (first ? "NEON" : "_NEON");
33 first = false;
34 }
35 if (first) {
36 return "none";
37 }
38 return builder.str();
39}
40
41// Detects available CPU features.
42AvailableCpuFeatures GetAvailableCpuFeatures() {
43#if defined(WEBRTC_ARCH_X86_FAMILY)
44 return {/*sse2=*/GetCPUInfo(kSSE2) != 0,
45 /*avx2=*/GetCPUInfo(kAVX2) != 0,
46 /*neon=*/false};
47#elif defined(WEBRTC_HAS_NEON)
48 return {/*sse2=*/false,
49 /*avx2=*/false,
50 /*neon=*/true};
Alessio Bazzica3ee4af42020-12-07 13:06:57 +010051#else
52 return {/*sse2=*/false,
53 /*avx2=*/false,
54 /*neon=*/false};
Alessio Bazzica253f8362020-11-27 16:02:38 +010055#endif
56}
57
Alessio Bazzicae8ee4622020-12-08 11:30:47 +010058AvailableCpuFeatures NoAvailableCpuFeatures() {
59 return {/*sse2=*/false, /*avx2=*/false, /*neon=*/false};
60}
61
Alessio Bazzica253f8362020-11-27 16:02:38 +010062} // namespace webrtc