Alessio Bazzica | 253f836 | 2020-11-27 16:02:38 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | namespace webrtc { |
| 18 | |
| 19 | std::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. |
| 42 | AvailableCpuFeatures 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 Bazzica | 3ee4af4 | 2020-12-07 13:06:57 +0100 | [diff] [blame] | 51 | #else |
| 52 | return {/*sse2=*/false, |
| 53 | /*avx2=*/false, |
| 54 | /*neon=*/false}; |
Alessio Bazzica | 253f836 | 2020-11-27 16:02:38 +0100 | [diff] [blame] | 55 | #endif |
| 56 | } |
| 57 | |
Alessio Bazzica | e8ee462 | 2020-12-08 11:30:47 +0100 | [diff] [blame] | 58 | AvailableCpuFeatures NoAvailableCpuFeatures() { |
| 59 | return {/*sse2=*/false, /*avx2=*/false, /*neon=*/false}; |
| 60 | } |
| 61 | |
Alessio Bazzica | 253f836 | 2020-11-27 16:02:38 +0100 | [diff] [blame] | 62 | } // namespace webrtc |