2
0

systemdependent.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2010 The WebM 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. #include "vpx_config.h"
  11. #include "vp8_rtcd.h"
  12. #if ARCH_ARM
  13. #include "vpx_ports/arm.h"
  14. #elif ARCH_X86 || ARCH_X86_64
  15. #include "vpx_ports/x86.h"
  16. #endif
  17. #include "vp8/common/onyxc_int.h"
  18. #include "vp8/common/systemdependent.h"
  19. #if CONFIG_MULTITHREAD
  20. #if HAVE_UNISTD_H && !defined(__OS2__)
  21. #include <unistd.h>
  22. #elif defined(_WIN32)
  23. #include <windows.h>
  24. typedef void(WINAPI *PGNSI)(LPSYSTEM_INFO);
  25. #elif defined(__OS2__)
  26. #define INCL_DOS
  27. #define INCL_DOSSPINLOCK
  28. #include <os2.h>
  29. #endif
  30. #endif
  31. #if CONFIG_MULTITHREAD
  32. static int get_cpu_count() {
  33. int core_count = 16;
  34. #if HAVE_UNISTD_H && !defined(__OS2__)
  35. #if defined(_SC_NPROCESSORS_ONLN)
  36. core_count = (int)sysconf(_SC_NPROCESSORS_ONLN);
  37. #elif defined(_SC_NPROC_ONLN)
  38. core_count = (int)sysconf(_SC_NPROC_ONLN);
  39. #endif
  40. #elif defined(_WIN32)
  41. {
  42. #if _WIN32_WINNT >= 0x0501
  43. SYSTEM_INFO sysinfo;
  44. GetNativeSystemInfo(&sysinfo);
  45. #else
  46. PGNSI pGNSI;
  47. SYSTEM_INFO sysinfo;
  48. /* Call GetNativeSystemInfo if supported or
  49. * GetSystemInfo otherwise. */
  50. pGNSI = (PGNSI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")),
  51. "GetNativeSystemInfo");
  52. if (pGNSI != NULL)
  53. pGNSI(&sysinfo);
  54. else
  55. GetSystemInfo(&sysinfo);
  56. #endif
  57. core_count = (int)sysinfo.dwNumberOfProcessors;
  58. }
  59. #elif defined(__OS2__)
  60. {
  61. ULONG proc_id;
  62. ULONG status;
  63. core_count = 0;
  64. for (proc_id = 1;; ++proc_id) {
  65. if (DosGetProcessorStatus(proc_id, &status)) break;
  66. if (status == PROC_ONLINE) core_count++;
  67. }
  68. }
  69. #else
  70. /* other platforms */
  71. #endif
  72. return core_count > 0 ? core_count : 1;
  73. }
  74. #endif
  75. void vp8_clear_system_state_c(){};
  76. void vp8_machine_specific_config(VP8_COMMON *ctx) {
  77. #if CONFIG_MULTITHREAD
  78. ctx->processor_core_count = get_cpu_count();
  79. #else
  80. (void)ctx;
  81. #endif /* CONFIG_MULTITHREAD */
  82. #if ARCH_ARM
  83. ctx->cpu_caps = arm_cpu_caps();
  84. #elif ARCH_X86 || ARCH_X86_64
  85. ctx->cpu_caps = x86_simd_caps();
  86. #endif
  87. }