1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
7 |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
10 |
* the Free Software Foundation; either version 2 of the License, or * |
11 |
* (at your option) any later version. * |
12 |
* * |
13 |
* This program is distributed in the hope that it will be useful, * |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
* GNU General Public License for more details. * |
17 |
* * |
18 |
* You should have received a copy of the GNU General Public License * |
19 |
* along with this program; if not, write to the Free Software * |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
23 |
|
24 |
#include "Features.h" |
25 |
|
26 |
#if CONFIG_ASM && ARCH_X86 |
27 |
bool Features::bMMX(false); |
28 |
bool Features::bSSE(false); |
29 |
bool Features::bSSE2(false); |
30 |
|
31 |
void Features::detect() { |
32 |
#ifdef __x86_64__ |
33 |
int64_t edx; |
34 |
__asm__ __volatile__ ( |
35 |
"mov %%rbx,%%rdi\n\t" /*save PIC register*/ |
36 |
"movl $1,%%eax\n\t" |
37 |
"cpuid\n\t" |
38 |
"mov %%rdi,%%rbx\n\t" /*restore PIC register*/ |
39 |
: "=d" (edx) |
40 |
: : "%rax", "%rcx", "%rdi" |
41 |
); |
42 |
#else |
43 |
int edx; |
44 |
__asm__ __volatile__ ( |
45 |
"movl %%ebx,%%edi\n\t" /*save PIC register*/ |
46 |
"movl $1,%%eax\n\t" |
47 |
"cpuid\n\t" |
48 |
"movl %%edi,%%ebx\n\t" /*restore PIC register*/ |
49 |
: "=d" (edx) |
50 |
: : "%eax", "%ecx", "%edi" |
51 |
); |
52 |
#endif |
53 |
bMMX = (edx & 0x00800000); |
54 |
bSSE = (edx & 0x02000000); |
55 |
bSSE2 = (edx & 0x04000000); |
56 |
} |
57 |
#else |
58 |
void Features::detect() {} |
59 |
#endif // CONFIG_ASM && ARCH_X86 |
60 |
|
61 |
bool Features::enableDenormalsAreZeroMode() { |
62 |
#if CONFIG_ASM && ARCH_X86 |
63 |
if (supportsSSE2()) { |
64 |
int x; |
65 |
__asm__ __volatile__ ( |
66 |
"stmxcsr %0\n\t" |
67 |
"movl %0, %%eax\n\t" |
68 |
"orl $0x40, %%eax\n\t" |
69 |
"movl %%eax, %0\n\t" |
70 |
"ldmxcsr %0\n\t" |
71 |
:: "m" (x) |
72 |
: "%eax" |
73 |
); |
74 |
return true; |
75 |
} |
76 |
return false; |
77 |
#endif // CONFIG_ASM && ARCH_X86 |
78 |
} |
79 |
|
80 |
String Features::featuresAsString() { |
81 |
String sFeatures = "none"; |
82 |
#if CONFIG_ASM && ARCH_X86 |
83 |
if (supportsMMX()) sFeatures = "MMX"; |
84 |
if (supportsSSE()) sFeatures += " SSE"; |
85 |
if (supportsSSE2()) sFeatures += " SSE2"; |
86 |
#else |
87 |
sFeatures = "disabled at compile time"; |
88 |
#endif // CONFIG_ASM && ARCH_X86 |
89 |
return sFeatures; |
90 |
} |