]> code.delx.au - pulseaudio/blob - src/pulsecore/cpu-x86.c
alsa: work around slightly broken _delay implementations
[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
35 get_cpuid (uint32_t op, uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d)
36 {
37 __asm__ __volatile__ (
38 " push %%"PA_REG_b" \n\t"
39 " cpuid \n\t"
40 " mov %%ebx, %%esi \n\t"
41 " pop %%"PA_REG_b" \n\t"
42
43 : "=a" (*a), "=S" (*b), "=c" (*c), "=d" (*d)
44 : "0" (op)
45 );
46 }
47 #endif
48
49 void pa_cpu_init_x86 (void) {
50 #if defined (__i386__) || defined (__amd64__)
51 uint32_t eax, ebx, ecx, edx;
52 uint32_t level;
53 pa_cpu_x86_flag_t flags = 0;
54
55 /* get standard level */
56 get_cpuid (0x00000000, &level, &ebx, &ecx, &edx);
57 if (level >= 1) {
58 get_cpuid (0x00000001, &eax, &ebx, &ecx, &edx);
59
60 if (edx & (1<<15))
61 flags |= PA_CPU_X86_CMOV;
62
63 if (edx & (1<<23))
64 flags |= PA_CPU_X86_MMX;
65
66 if (edx & (1<<25))
67 flags |= PA_CPU_X86_SSE;
68
69 if (edx & (1<<26))
70 flags |= PA_CPU_X86_SSE2;
71
72 if (ecx & (1<<0))
73 flags |= PA_CPU_X86_SSE3;
74
75 if (ecx & (1<<9))
76 flags |= PA_CPU_X86_SSSE3;
77
78 if (ecx & (1<<19))
79 flags |= PA_CPU_X86_SSE4_1;
80
81 if (ecx & (1<<20))
82 flags |= PA_CPU_X86_SSE4_2;
83 }
84
85 /* get extended level */
86 get_cpuid (0x80000000, &level, &ebx, &ecx, &edx);
87 if (level >= 0x80000001) {
88 get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx);
89
90 if (edx & (1<<22))
91 flags |= PA_CPU_X86_MMXEXT;
92
93 if (edx & (1<<23))
94 flags |= PA_CPU_X86_MMX;
95
96 if (edx & (1<<30))
97 flags |= PA_CPU_X86_3DNOWEXT;
98
99 if (edx & (1<<31))
100 flags |= PA_CPU_X86_3DNOW;
101 }
102
103 pa_log_info ("CPU flags: %s%s%s%s%s%s%s%s%s%s%s",
104 (flags & PA_CPU_X86_CMOV) ? "CMOV " : "",
105 (flags & PA_CPU_X86_MMX) ? "MMX " : "",
106 (flags & PA_CPU_X86_SSE) ? "SSE " : "",
107 (flags & PA_CPU_X86_SSE2) ? "SSE2 " : "",
108 (flags & PA_CPU_X86_SSE3) ? "SSE3 " : "",
109 (flags & PA_CPU_X86_SSSE3) ? "SSSE3 " : "",
110 (flags & PA_CPU_X86_SSE4_1) ? "SSE4_1 " : "",
111 (flags & PA_CPU_X86_SSE4_2) ? "SSE4_2 " : "",
112 (flags & PA_CPU_X86_MMXEXT) ? "MMXEXT " : "",
113 (flags & PA_CPU_X86_3DNOW) ? "3DNOW " : "",
114 (flags & PA_CPU_X86_3DNOWEXT) ? "3DNOWEXT " : "");
115
116 /* activate various optimisations */
117 if (flags & PA_CPU_X86_MMX) {
118 pa_volume_func_init_mmx (flags);
119 pa_remap_func_init_mmx (flags);
120 }
121
122 if (flags & (PA_CPU_X86_SSE | PA_CPU_X86_SSE2)) {
123 pa_volume_func_init_sse (flags);
124 pa_remap_func_init_sse (flags);
125 pa_convert_func_init_sse (flags);
126 }
127
128 #endif /* defined (__i386__) || defined (__amd64__) */
129 }