cpu_features.cc (1658B)
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 <string> 14 15 #include "rtc_base/cpu_info.h" 16 #include "rtc_base/strings/string_builder.h" 17 #include "rtc_base/system/arch.h" 18 19 namespace webrtc { 20 21 std::string AvailableCpuFeatures::ToString() const { 22 char buf[64]; 23 SimpleStringBuilder builder(buf); 24 bool first = true; 25 if (sse2) { 26 builder << (first ? "SSE2" : "_SSE2"); 27 first = false; 28 } 29 if (avx2) { 30 builder << (first ? "AVX2" : "_AVX2"); 31 first = false; 32 } 33 if (neon) { 34 builder << (first ? "NEON" : "_NEON"); 35 first = false; 36 } 37 if (first) { 38 return "none"; 39 } 40 return builder.str(); 41 } 42 43 // Detects available CPU features. 44 AvailableCpuFeatures GetAvailableCpuFeatures() { 45 #if defined(WEBRTC_ARCH_X86_FAMILY) 46 return {/*sse2=*/cpu_info::Supports(cpu_info::ISA::kSSE2), 47 /*avx2=*/cpu_info::Supports(cpu_info::ISA::kAVX2), 48 /*neon=*/false}; 49 #elif defined(WEBRTC_HAS_NEON) 50 return {/*sse2=*/false, 51 /*avx2=*/false, 52 /*neon=*/true}; 53 #else 54 return {/*sse2=*/false, 55 /*avx2=*/false, 56 /*neon=*/false}; 57 #endif 58 } 59 60 AvailableCpuFeatures NoAvailableCpuFeatures() { 61 return {/*sse2=*/false, /*avx2=*/false, /*neon=*/false}; 62 } 63 64 } // namespace webrtc