mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 13:50:40 +01:00

Specifically, this CL was generated by the following shell commands: cd system_wrappers for f in $(find . -type f | grep -E '[.](h|cc)$'); do echo >> $f; done git cl format --full Followed by a revert of the changes to asm_defines.h since that file is assembly and not C++, and a manual edit to clock.cc to add some blank lines in the #include list to prevent `git cl format` from sorting <MMSystem.h> before "rtc_base/win32.h". I needed to do this because otherwise `git cl format` introduces a lot of unrelated formatting changes in other CLs that move these files (since `git cl format` will try to re-format all lines of a moved file). BUG=none Change-Id: I083e23a57ce2899add3e60bbd539f03343c7c219 Reviewed-on: https://webrtc-review.googlesource.com/21161 Reviewed-by: Henrik Andreassson <henrika@webrtc.org> Commit-Queue: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20600}
73 lines
2 KiB
C++
73 lines
2 KiB
C++
/*
|
|
* 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 "system_wrappers/include/cpu_features_wrapper.h"
|
|
|
|
#if defined(WEBRTC_ARCH_X86_FAMILY) && defined(_MSC_VER)
|
|
#include <intrin.h>
|
|
#endif
|
|
|
|
#include "typedefs.h" // NOLINT(build/include)
|
|
|
|
// No CPU feature is available => straight C path.
|
|
int GetCPUInfoNoASM(CPUFeature feature) {
|
|
(void)feature;
|
|
return 0;
|
|
}
|
|
|
|
#if defined(WEBRTC_ARCH_X86_FAMILY)
|
|
#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));
|
|
}
|
|
#endif
|
|
#endif // _MSC_VER
|
|
#endif // WEBRTC_ARCH_X86_FAMILY
|
|
|
|
#if defined(WEBRTC_ARCH_X86_FAMILY)
|
|
// Actual feature detection for x86.
|
|
static 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);
|
|
}
|
|
return 0;
|
|
}
|
|
#else
|
|
// Default to straight C for other platforms.
|
|
static int GetCPUInfo(CPUFeature feature) {
|
|
(void)feature;
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
WebRtc_CPUInfo WebRtc_GetCPUInfo = GetCPUInfo;
|
|
WebRtc_CPUInfo WebRtc_GetCPUInfoNoASM = GetCPUInfoNoASM;
|