]> code.delx.au - pulseaudio/blob - src/pulsecore/cpu-x86.c
remap: Change remapping function argument type from void to int16_t / float as approp...
[pulseaudio] / src / pulsecore / cpu-x86.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2009 Wim Taymans <wim.taymans@collabora.co.uk>
6
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2.1 of the License,
10 or (at your option) any later version.
11
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA.
21 ***/
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <stdint.h>
28
29 #include <pulsecore/log.h>
30
31 #include "cpu-x86.h"
32
33 #if defined (__i386__) || defined (__amd64__)
34 static void get_cpuid(uint32_t op, uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d) {
35 __asm__ __volatile__ (
36 " push %%"PA_REG_b" \n\t"
37 " cpuid \n\t"
38 " mov %%ebx, %%esi \n\t"
39 " pop %%"PA_REG_b" \n\t"
40
41 : "=a" (*a), "=S" (*b), "=c" (*c), "=d" (*d)
42 : "0" (op)
43 );
44 }
45 #endif
46
47 void pa_cpu_get_x86_flags(pa_cpu_x86_flag_t *flags) {
48 #if defined (__i386__) || defined (__amd64__)
49 uint32_t eax, ebx, ecx, edx;
50 uint32_t level;
51
52 *flags = 0;
53
54 /* get standard level */
55 get_cpuid(0x00000000, &level, &ebx, &ecx, &edx);
56 if (level >= 1) {
57 get_cpuid(0x00000001, &eax, &ebx, &ecx, &edx);
58
59 if (edx & (1<<15))
60 *flags |= PA_CPU_X86_CMOV;
61
62 if (edx & (1<<23))
63 *flags |= PA_CPU_X86_MMX;
64
65 if (edx & (1<<25))
66 *flags |= PA_CPU_X86_SSE;
67
68 if (edx & (1<<26))
69 *flags |= PA_CPU_X86_SSE2;
70
71 if (ecx & (1<<0))
72 *flags |= PA_CPU_X86_SSE3;
73
74 if (ecx & (1<<9))
75 *flags |= PA_CPU_X86_SSSE3;
76
77 if (ecx & (1<<19))
78 *flags |= PA_CPU_X86_SSE4_1;
79
80 if (ecx & (1<<20))
81 *flags |= PA_CPU_X86_SSE4_2;
82 }
83
84 /* get extended level */
85 get_cpuid(0x80000000, &level, &ebx, &ecx, &edx);
86 if (level >= 0x80000001) {
87 get_cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
88
89 if (edx & (1<<22))
90 *flags |= PA_CPU_X86_MMXEXT;
91
92 if (edx & (1<<23))
93 *flags |= PA_CPU_X86_MMX;
94
95 if (edx & (1<<30))
96 *flags |= PA_CPU_X86_3DNOWEXT;
97
98 if (edx & (1<<31))
99 *flags |= PA_CPU_X86_3DNOW;
100 }
101
102 pa_log_info("CPU flags: %s%s%s%s%s%s%s%s%s%s%s",
103 (*flags & PA_CPU_X86_CMOV) ? "CMOV " : "",
104 (*flags & PA_CPU_X86_MMX) ? "MMX " : "",
105 (*flags & PA_CPU_X86_SSE) ? "SSE " : "",
106 (*flags & PA_CPU_X86_SSE2) ? "SSE2 " : "",
107 (*flags & PA_CPU_X86_SSE3) ? "SSE3 " : "",
108 (*flags & PA_CPU_X86_SSSE3) ? "SSSE3 " : "",
109 (*flags & PA_CPU_X86_SSE4_1) ? "SSE4_1 " : "",
110 (*flags & PA_CPU_X86_SSE4_2) ? "SSE4_2 " : "",
111 (*flags & PA_CPU_X86_MMXEXT) ? "MMXEXT " : "",
112 (*flags & PA_CPU_X86_3DNOW) ? "3DNOW " : "",
113 (*flags & PA_CPU_X86_3DNOWEXT) ? "3DNOWEXT " : "");
114 #endif /* defined (__i386__) || defined (__amd64__) */
115 }
116
117 bool pa_cpu_init_x86(pa_cpu_x86_flag_t *flags) {
118 #if defined (__i386__) || defined (__amd64__)
119 pa_cpu_get_x86_flags(flags);
120
121 /* activate various optimisations */
122 if (*flags & PA_CPU_X86_MMX) {
123 pa_volume_func_init_mmx(*flags);
124 pa_remap_func_init_mmx(*flags);
125 }
126
127 if (*flags & (PA_CPU_X86_SSE | PA_CPU_X86_SSE2)) {
128 pa_volume_func_init_sse(*flags);
129 pa_remap_func_init_sse(*flags);
130 pa_convert_func_init_sse(*flags);
131 }
132
133 return true;
134 #else /* defined (__i386__) || defined (__amd64__) */
135 return false;
136 #endif /* defined (__i386__) || defined (__amd64__) */
137 }