File: cpu_compute.c

package info (click to toggle)
faac 1.40-1
  • links: PTS, VCS
  • area: non-free
  • in suites:
  • size: 644 kB
  • sloc: ansic: 7,401; makefile: 3
file content (66 lines) | stat: -rw-r--r-- 1,869 bytes parent folder | download | duplicates (2)
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
/*
 * FAAC - Freeware Advanced Audio Coder
 * Copyright (C) 2026 Nils Schimmelmann
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "cpu_compute.h"

#if defined(SSE2_ARCH)
# ifdef _MSC_VER
#  include <intrin.h>
# elif defined(__GNUC__) || defined(__clang__)
#  include <cpuid.h>
# endif
#endif

CPUCaps get_cpu_caps(void)
{
    CPUCaps caps = CPU_CAP_NONE;

#if defined(SSE2_ARCH)
    unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0;
    unsigned int max_leaf = 0;

# ifdef _MSC_VER
    int cpu_info[4] = {0};
    __cpuid(cpu_info, 0);
    max_leaf = (unsigned int)cpu_info[0];
# elif defined(__GNUC__) || defined(__clang__)
    __cpuid(0, max_leaf, ebx, ecx, edx);
# endif

    if (max_leaf >= 1) {
# ifdef _MSC_VER
        __cpuid(cpu_info, 1);
        eax = (unsigned int)cpu_info[0];
        ebx = (unsigned int)cpu_info[1];
        ecx = (unsigned int)cpu_info[2];
        edx = (unsigned int)cpu_info[3];
# elif defined(__GNUC__) || defined(__clang__)
        __get_cpuid(1, &eax, &ebx, &ecx, &edx);
# endif
        if (edx & (1 << 26)) // SSE2
            caps |= CPU_CAP_SSE2;
    }
#endif

    return caps;
}