systemdependent.c 2.41 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5 6
 *  that can be found in the LICENSE file in the root of the source
 *  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.
John Koleszar's avatar
John Koleszar committed
9 10 11
 */


12
#include "vpx_config.h"
13
#include "vp8_rtcd.h"
14 15 16 17 18
#if ARCH_ARM
#include "vpx_ports/arm.h"
#elif ARCH_X86 || ARCH_X86_64
#include "vpx_ports/x86.h"
#endif
19
#include "vp8/common/onyxc_int.h"
20
#include "vp8/common/systemdependent.h"
John Koleszar's avatar
John Koleszar committed
21

22
#if CONFIG_MULTITHREAD
KO Myung-Hun's avatar
KO Myung-Hun committed
23
#if HAVE_UNISTD_H && !defined(__OS2__)
24 25 26 27
#include <unistd.h>
#elif defined(_WIN32)
#include <windows.h>
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
KO Myung-Hun's avatar
KO Myung-Hun committed
28 29 30 31
#elif defined(__OS2__)
#define INCL_DOS
#define INCL_DOSSPINLOCK
#include <os2.h>
32 33 34 35 36 37 38 39
#endif
#endif

#if CONFIG_MULTITHREAD
static int get_cpu_count()
{
    int core_count = 16;

KO Myung-Hun's avatar
KO Myung-Hun committed
40
#if HAVE_UNISTD_H && !defined(__OS2__)
41 42 43 44 45 46 47
#if defined(_SC_NPROCESSORS_ONLN)
    core_count = sysconf(_SC_NPROCESSORS_ONLN);
#elif defined(_SC_NPROC_ONLN)
    core_count = sysconf(_SC_NPROC_ONLN);
#endif
#elif defined(_WIN32)
    {
48 49 50 51
#if _WIN32_WINNT >= 0x0501
        SYSTEM_INFO sysinfo;
        GetNativeSystemInfo(&sysinfo);
#else
52 53 54 55 56 57 58 59 60 61 62 63
        PGNSI pGNSI;
        SYSTEM_INFO sysinfo;

        /* Call GetNativeSystemInfo if supported or
         * GetSystemInfo otherwise. */

        pGNSI = (PGNSI) GetProcAddress(
                GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo");
        if (pGNSI != NULL)
            pGNSI(&sysinfo);
        else
            GetSystemInfo(&sysinfo);
64
#endif
65 66 67

        core_count = sysinfo.dwNumberOfProcessors;
    }
KO Myung-Hun's avatar
KO Myung-Hun committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
#elif defined(__OS2__)
    {
        ULONG proc_id;
        ULONG status;

        core_count = 0;
        for (proc_id = 1; ; proc_id++)
        {
            if (DosGetProcessorStatus(proc_id, &status))
                break;

            if (status == PROC_ONLINE)
                core_count++;
        }
    }
83 84 85 86 87 88 89 90
#else
    /* other platforms */
#endif

    return core_count > 0 ? core_count : 1;
}
#endif

91
void vp8_clear_system_state_c() {};
92

John Koleszar's avatar
John Koleszar committed
93 94
void vp8_machine_specific_config(VP8_COMMON *ctx)
{
95 96 97
#if CONFIG_MULTITHREAD
    ctx->processor_core_count = get_cpu_count();
#endif /* CONFIG_MULTITHREAD */
John Koleszar's avatar
John Koleszar committed
98

99 100 101 102 103
#if ARCH_ARM
    ctx->cpu_caps = arm_cpu_caps();
#elif ARCH_X86 || ARCH_X86_64
    ctx->cpu_caps = x86_simd_caps();
#endif
John Koleszar's avatar
John Koleszar committed
104
}