11b362b15af34006e6a11974088a46d42b903418eJohann/* 21b362b15af34006e6a11974088a46d42b903418eJohann * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 31b362b15af34006e6a11974088a46d42b903418eJohann * 41b362b15af34006e6a11974088a46d42b903418eJohann * Use of this source code is governed by a BSD-style license 51b362b15af34006e6a11974088a46d42b903418eJohann * that can be found in the LICENSE file in the root of the source 61b362b15af34006e6a11974088a46d42b903418eJohann * tree. An additional intellectual property rights grant can be found 71b362b15af34006e6a11974088a46d42b903418eJohann * in the file PATENTS. All contributing project authors may 81b362b15af34006e6a11974088a46d42b903418eJohann * be found in the AUTHORS file in the root of the source tree. 91b362b15af34006e6a11974088a46d42b903418eJohann */ 101b362b15af34006e6a11974088a46d42b903418eJohann 111b362b15af34006e6a11974088a46d42b903418eJohann#include "vpx_config.h" 12ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "vp8_rtcd.h" 131b362b15af34006e6a11974088a46d42b903418eJohann#if ARCH_ARM 141b362b15af34006e6a11974088a46d42b903418eJohann#include "vpx_ports/arm.h" 151b362b15af34006e6a11974088a46d42b903418eJohann#elif ARCH_X86 || ARCH_X86_64 161b362b15af34006e6a11974088a46d42b903418eJohann#include "vpx_ports/x86.h" 170a39d0a697ff3603e8c100300fda363658e10b23James Zern#elif ARCH_PPC 180a39d0a697ff3603e8c100300fda363658e10b23James Zern#include "vpx_ports/ppc.h" 191b362b15af34006e6a11974088a46d42b903418eJohann#endif 201b362b15af34006e6a11974088a46d42b903418eJohann#include "vp8/common/onyxc_int.h" 217ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#include "vp8/common/systemdependent.h" 221b362b15af34006e6a11974088a46d42b903418eJohann 231b362b15af34006e6a11974088a46d42b903418eJohann#if CONFIG_MULTITHREAD 241b362b15af34006e6a11974088a46d42b903418eJohann#if HAVE_UNISTD_H && !defined(__OS2__) 251b362b15af34006e6a11974088a46d42b903418eJohann#include <unistd.h> 261b362b15af34006e6a11974088a46d42b903418eJohann#elif defined(_WIN32) 271b362b15af34006e6a11974088a46d42b903418eJohann#include <windows.h> 287bc9febe8749e98a3812a0dc4380ceae75c29450Johanntypedef void(WINAPI *PGNSI)(LPSYSTEM_INFO); 291b362b15af34006e6a11974088a46d42b903418eJohann#elif defined(__OS2__) 301b362b15af34006e6a11974088a46d42b903418eJohann#define INCL_DOS 311b362b15af34006e6a11974088a46d42b903418eJohann#define INCL_DOSSPINLOCK 321b362b15af34006e6a11974088a46d42b903418eJohann#include <os2.h> 331b362b15af34006e6a11974088a46d42b903418eJohann#endif 341b362b15af34006e6a11974088a46d42b903418eJohann#endif 351b362b15af34006e6a11974088a46d42b903418eJohann 361b362b15af34006e6a11974088a46d42b903418eJohann#if CONFIG_MULTITHREAD 377bc9febe8749e98a3812a0dc4380ceae75c29450Johannstatic int get_cpu_count() { 387bc9febe8749e98a3812a0dc4380ceae75c29450Johann int core_count = 16; 391b362b15af34006e6a11974088a46d42b903418eJohann 401b362b15af34006e6a11974088a46d42b903418eJohann#if HAVE_UNISTD_H && !defined(__OS2__) 411b362b15af34006e6a11974088a46d42b903418eJohann#if defined(_SC_NPROCESSORS_ONLN) 427bc9febe8749e98a3812a0dc4380ceae75c29450Johann core_count = (int)sysconf(_SC_NPROCESSORS_ONLN); 431b362b15af34006e6a11974088a46d42b903418eJohann#elif defined(_SC_NPROC_ONLN) 447bc9febe8749e98a3812a0dc4380ceae75c29450Johann core_count = (int)sysconf(_SC_NPROC_ONLN); 451b362b15af34006e6a11974088a46d42b903418eJohann#endif 461b362b15af34006e6a11974088a46d42b903418eJohann#elif defined(_WIN32) 477bc9febe8749e98a3812a0dc4380ceae75c29450Johann { 487ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#if _WIN32_WINNT >= 0x0501 497bc9febe8749e98a3812a0dc4380ceae75c29450Johann SYSTEM_INFO sysinfo; 507bc9febe8749e98a3812a0dc4380ceae75c29450Johann GetNativeSystemInfo(&sysinfo); 517ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#else 527bc9febe8749e98a3812a0dc4380ceae75c29450Johann PGNSI pGNSI; 537bc9febe8749e98a3812a0dc4380ceae75c29450Johann SYSTEM_INFO sysinfo; 541b362b15af34006e6a11974088a46d42b903418eJohann 557bc9febe8749e98a3812a0dc4380ceae75c29450Johann /* Call GetNativeSystemInfo if supported or 567bc9febe8749e98a3812a0dc4380ceae75c29450Johann * GetSystemInfo otherwise. */ 571b362b15af34006e6a11974088a46d42b903418eJohann 587bc9febe8749e98a3812a0dc4380ceae75c29450Johann pGNSI = (PGNSI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), 597bc9febe8749e98a3812a0dc4380ceae75c29450Johann "GetNativeSystemInfo"); 607bc9febe8749e98a3812a0dc4380ceae75c29450Johann if (pGNSI != NULL) 617bc9febe8749e98a3812a0dc4380ceae75c29450Johann pGNSI(&sysinfo); 627bc9febe8749e98a3812a0dc4380ceae75c29450Johann else 637bc9febe8749e98a3812a0dc4380ceae75c29450Johann GetSystemInfo(&sysinfo); 647ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#endif 651b362b15af34006e6a11974088a46d42b903418eJohann 667bc9febe8749e98a3812a0dc4380ceae75c29450Johann core_count = (int)sysinfo.dwNumberOfProcessors; 677bc9febe8749e98a3812a0dc4380ceae75c29450Johann } 681b362b15af34006e6a11974088a46d42b903418eJohann#elif defined(__OS2__) 697bc9febe8749e98a3812a0dc4380ceae75c29450Johann { 707bc9febe8749e98a3812a0dc4380ceae75c29450Johann ULONG proc_id; 717bc9febe8749e98a3812a0dc4380ceae75c29450Johann ULONG status; 721b362b15af34006e6a11974088a46d42b903418eJohann 737bc9febe8749e98a3812a0dc4380ceae75c29450Johann core_count = 0; 747bc9febe8749e98a3812a0dc4380ceae75c29450Johann for (proc_id = 1;; ++proc_id) { 757bc9febe8749e98a3812a0dc4380ceae75c29450Johann if (DosGetProcessorStatus(proc_id, &status)) break; 761b362b15af34006e6a11974088a46d42b903418eJohann 777bc9febe8749e98a3812a0dc4380ceae75c29450Johann if (status == PROC_ONLINE) core_count++; 781b362b15af34006e6a11974088a46d42b903418eJohann } 797bc9febe8749e98a3812a0dc4380ceae75c29450Johann } 801b362b15af34006e6a11974088a46d42b903418eJohann#else 817bc9febe8749e98a3812a0dc4380ceae75c29450Johann/* other platforms */ 821b362b15af34006e6a11974088a46d42b903418eJohann#endif 831b362b15af34006e6a11974088a46d42b903418eJohann 847bc9febe8749e98a3812a0dc4380ceae75c29450Johann return core_count > 0 ? core_count : 1; 851b362b15af34006e6a11974088a46d42b903418eJohann} 861b362b15af34006e6a11974088a46d42b903418eJohann#endif 871b362b15af34006e6a11974088a46d42b903418eJohann 887bc9febe8749e98a3812a0dc4380ceae75c29450Johannvoid vp8_machine_specific_config(VP8_COMMON *ctx) { 891b362b15af34006e6a11974088a46d42b903418eJohann#if CONFIG_MULTITHREAD 907bc9febe8749e98a3812a0dc4380ceae75c29450Johann ctx->processor_core_count = get_cpu_count(); 9168e1c830ade592be74773e249bf94e2bbfb50de7Johann#else 927bc9febe8749e98a3812a0dc4380ceae75c29450Johann (void)ctx; 931b362b15af34006e6a11974088a46d42b903418eJohann#endif /* CONFIG_MULTITHREAD */ 941b362b15af34006e6a11974088a46d42b903418eJohann 951b362b15af34006e6a11974088a46d42b903418eJohann#if ARCH_ARM 967bc9febe8749e98a3812a0dc4380ceae75c29450Johann ctx->cpu_caps = arm_cpu_caps(); 971b362b15af34006e6a11974088a46d42b903418eJohann#elif ARCH_X86 || ARCH_X86_64 987bc9febe8749e98a3812a0dc4380ceae75c29450Johann ctx->cpu_caps = x86_simd_caps(); 990a39d0a697ff3603e8c100300fda363658e10b23James Zern#elif ARCH_PPC 1000a39d0a697ff3603e8c100300fda363658e10b23James Zern ctx->cpu_caps = ppc_simd_caps(); 1011b362b15af34006e6a11974088a46d42b903418eJohann#endif 1021b362b15af34006e6a11974088a46d42b903418eJohann} 103