systemdependent.c 2.4 KB

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