summaryrefslogtreecommitdiff
path: root/src/post/goom/cpu_info.c
blob: 67d0a19ded7d2a73c9dc348e9c86a785dea22ac8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 *  cpu_info.c
 *  Goom
 *
 *  Created by Guillaume Borios on Sun Dec 28 2003.
 *  Copyright (c) 2003 iOS. All rights reserved.
 *
 */

#include "cpu_info.h"

#ifdef HAVE_MMX
#include "mmx.h"
#endif


static unsigned int CPU_FLAVOUR = 0;
static unsigned int CPU_NUMBER = 1;
static unsigned int CPU_DETECTED = 0;

static void autoset_cpu_info (void)
{
    CPU_DETECTED = 1;
    
#ifdef CPU_POWERPC
    int result;
    size_t size;
    
    result = 0;
    size = 4;
    if (sysctlbyname("hw.optional.altivec",&result,&size,NULL,NULL) == 0)
    {
        if (result != 0) CPU_FLAVOUR |= CPU_OPTION_ALTIVEC;
    }
    
    result = 0;
    size = 4;
    if (sysctlbyname("hw.optional.64bitops",&result,&size,NULL,NULL) == 0)
    {
        if (result != 0) CPU_FLAVOUR |= CPU_OPTION_64_BITS;
    }
    
    result = 0;
    size = 4;
    if (sysctlbyname("hw.ncpu",&result,&size,NULL,NULL) == 0)
    {
        if (result != 0) CPU_NUMBER = result;
    }
#endif /* CPU_POWERPC */
    
#ifdef CPU_X86
    if (mmx_supported()) CPU_FLAVOUR |= CPU_OPTION_MMX;
    if (xmmx_supported()) CPU_FLAVOUR |= CPU_OPTION_XMMX;
#endif /* CPU_X86 */
}

unsigned int cpu_flavour (void)
{
    if (CPU_DETECTED == 0) autoset_cpu_info();
    return CPU_FLAVOUR;
}

unsigned int cpu_number (void)
{
    if (CPU_DETECTED == 0) autoset_cpu_info();
    return CPU_NUMBER;
}