• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #include "vpx_config.h"
12 #include "vp8_rtcd.h"
13 #if VPX_ARCH_ARM
14 #include "vpx_ports/arm.h"
15 #elif VPX_ARCH_X86 || VPX_ARCH_X86_64
16 #include "vpx_ports/x86.h"
17 #elif VPX_ARCH_PPC
18 #include "vpx_ports/ppc.h"
19 #elif VPX_ARCH_MIPS
20 #include "vpx_ports/mips.h"
21 #elif VPX_ARCH_LOONGARCH
22 #include "vpx_ports/loongarch.h"
23 #endif
24 #include "vp8/common/onyxc_int.h"
25 #include "vp8/common/systemdependent.h"
26 
27 #if CONFIG_MULTITHREAD
28 #if HAVE_UNISTD_H && !defined(__OS2__)
29 #include <unistd.h>
30 #elif defined(_WIN32)
31 #include <windows.h>
32 typedef void(WINAPI *PGNSI)(LPSYSTEM_INFO);
33 #elif defined(__OS2__)
34 #define INCL_DOS
35 #define INCL_DOSSPINLOCK
36 #include <os2.h>
37 #endif
38 #endif
39 
40 #if CONFIG_MULTITHREAD
get_cpu_count()41 static int get_cpu_count() {
42   int core_count = 16;
43 
44 #if HAVE_UNISTD_H && !defined(__OS2__)
45 #if defined(_SC_NPROCESSORS_ONLN)
46   core_count = (int)sysconf(_SC_NPROCESSORS_ONLN);
47 #elif defined(_SC_NPROC_ONLN)
48   core_count = (int)sysconf(_SC_NPROC_ONLN);
49 #endif
50 #elif defined(_WIN32)
51   {
52 #if _WIN32_WINNT >= 0x0501
53     SYSTEM_INFO sysinfo;
54     GetNativeSystemInfo(&sysinfo);
55 #else
56     PGNSI pGNSI;
57     SYSTEM_INFO sysinfo;
58 
59     /* Call GetNativeSystemInfo if supported or
60      * GetSystemInfo otherwise. */
61 
62     pGNSI = (PGNSI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")),
63                                   "GetNativeSystemInfo");
64     if (pGNSI != NULL)
65       pGNSI(&sysinfo);
66     else
67       GetSystemInfo(&sysinfo);
68 #endif
69 
70     core_count = (int)sysinfo.dwNumberOfProcessors;
71   }
72 #elif defined(__OS2__)
73   {
74     ULONG proc_id;
75     ULONG status;
76 
77     core_count = 0;
78     for (proc_id = 1;; ++proc_id) {
79       if (DosGetProcessorStatus(proc_id, &status)) break;
80 
81       if (status == PROC_ONLINE) core_count++;
82     }
83   }
84 #else
85 /* other platforms */
86 #endif
87 
88   return core_count > 0 ? core_count : 1;
89 }
90 #endif
91 
vp8_machine_specific_config(VP8_COMMON * ctx)92 void vp8_machine_specific_config(VP8_COMMON *ctx) {
93 #if CONFIG_MULTITHREAD
94   ctx->processor_core_count = get_cpu_count();
95 #endif /* CONFIG_MULTITHREAD */
96 
97 #if VPX_ARCH_ARM
98   ctx->cpu_caps = arm_cpu_caps();
99 #elif VPX_ARCH_X86 || VPX_ARCH_X86_64
100   ctx->cpu_caps = x86_simd_caps();
101 #elif VPX_ARCH_PPC
102   ctx->cpu_caps = ppc_simd_caps();
103 #elif VPX_ARCH_MIPS
104   ctx->cpu_caps = mips_cpu_caps();
105 #elif VPX_ARCH_LOONGARCH
106   ctx->cpu_caps = loongarch_cpu_caps();
107 #else
108   // generic-gnu targets.
109   ctx->cpu_caps = 0;
110 #endif
111 }
112