You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2011 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. // Parts of this file derived from Chromium's base/cpu.cc.
  11. #include "rtc_base/system/arch.h"
  12. #include "system_wrappers/include/cpu_features_wrapper.h"
  13. #if defined(WEBRTC_ARCH_X86_FAMILY) && defined(_MSC_VER)
  14. #include <intrin.h>
  15. #endif
  16. // No CPU feature is available => straight C path.
  17. int GetCPUInfoNoASM(CPUFeature feature) {
  18. (void)feature;
  19. return 0;
  20. }
  21. #if defined(WEBRTC_ARCH_X86_FAMILY)
  22. #ifndef _MSC_VER
  23. // Intrinsic for "cpuid".
  24. #if defined(__pic__) && defined(__i386__)
  25. static inline void __cpuid(int cpu_info[4], int info_type) {
  26. __asm__ volatile(
  27. "mov %%ebx, %%edi\n"
  28. "cpuid\n"
  29. "xchg %%edi, %%ebx\n"
  30. : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]),
  31. "=d"(cpu_info[3])
  32. : "a"(info_type));
  33. }
  34. #else
  35. static inline void __cpuid(int cpu_info[4], int info_type) {
  36. __asm__ volatile("cpuid\n"
  37. : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]),
  38. "=d"(cpu_info[3])
  39. : "a"(info_type));
  40. }
  41. #endif
  42. #endif // _MSC_VER
  43. #endif // WEBRTC_ARCH_X86_FAMILY
  44. #if defined(WEBRTC_ARCH_X86_FAMILY)
  45. // Actual feature detection for x86.
  46. static int GetCPUInfo(CPUFeature feature) {
  47. int cpu_info[4];
  48. __cpuid(cpu_info, 1);
  49. if (feature == kSSE2) {
  50. return 0 != (cpu_info[3] & 0x04000000);
  51. }
  52. if (feature == kSSE3) {
  53. return 0 != (cpu_info[2] & 0x00000001);
  54. }
  55. return 0;
  56. }
  57. #else
  58. // Default to straight C for other platforms.
  59. static int GetCPUInfo(CPUFeature feature) {
  60. (void)feature;
  61. return 0;
  62. }
  63. #endif
  64. WebRtc_CPUInfo WebRtc_GetCPUInfo = GetCPUInfo;
  65. WebRtc_CPUInfo WebRtc_GetCPUInfoNoASM = GetCPUInfoNoASM;