comparison src/fftw-3.3.3/simd-support/x86-cpuid.h @ 95:89f5e221ed7b

Add FFTW3
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
comparison
equal deleted inserted replaced
94:d278df1123f9 95:89f5e221ed7b
1 /*
2 * Copyright (c) 2003, 2007-11 Matteo Frigo
3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21
22 /* this code was kindly donated by Eric J. Korpela */
23
24 #ifdef _MSC_VER
25 #ifndef inline
26 #define inline __inline
27 #endif
28 #endif
29
30 static inline int is_386()
31 {
32 #ifdef _MSC_VER
33 unsigned int result,tst;
34 _asm {
35 pushfd
36 pop eax
37 mov edx,eax
38 xor eax,40000h
39 push eax
40 popfd
41 pushfd
42 pop eax
43 push edx
44 popfd
45 mov tst,edx
46 mov result,eax
47 }
48 #else
49 register unsigned int result,tst;
50 __asm__ (
51 "pushfl\n\t"
52 "popl %0\n\t"
53 "movl %0,%1\n\t"
54 "xorl $0x40000,%0\n\t"
55 "pushl %0\n\t"
56 "popfl\n\t"
57 "pushfl\n\t"
58 "popl %0\n\t"
59 "pushl %1\n\t"
60 "popfl"
61 : "=r" (result), "=r" (tst) /* output */
62 : /* no inputs */
63 );
64 #endif
65 return (result == tst);
66 }
67
68 static inline int has_cpuid()
69 {
70 #ifdef _MSC_VER
71 unsigned int result,tst;
72 _asm {
73 pushfd
74 pop eax
75 mov edx,eax
76 xor eax,200000h
77 push eax
78 popfd
79 pushfd
80 pop eax
81 push edx
82 popfd
83 mov tst,edx
84 mov result,eax
85 }
86 #else
87 register unsigned int result,tst;
88 __asm__ (
89 "pushfl\n\t"
90 "pop %0\n\t"
91 "movl %0,%1\n\t"
92 "xorl $0x200000,%0\n\t"
93 "pushl %0\n\t"
94 "popfl\n\t"
95 "pushfl\n\t"
96 "popl %0\n\t"
97 "pushl %1\n\t"
98 "popfl"
99 : "=r" (result), "=r" (tst) /* output */
100 : /* no inputs */
101 );
102 #endif
103 return (result != tst);
104 }
105
106 static inline int cpuid_edx(int op)
107 {
108 # ifdef _MSC_VER
109 int result;
110 _asm {
111 push ebx
112 mov eax,op
113 cpuid
114 mov result,edx
115 pop ebx
116 }
117 return result;
118 # else
119 int eax, ecx, edx;
120
121 __asm__("push %%ebx\n\tcpuid\n\tpop %%ebx"
122 : "=a" (eax), "=c" (ecx), "=d" (edx)
123 : "a" (op));
124 return edx;
125 # endif
126 }
127
128 static inline int cpuid_ecx(int op)
129 {
130 # ifdef _MSC_VER
131 int result;
132 _asm {
133 push ebx
134 mov eax,op
135 cpuid
136 mov result,ecx
137 pop ebx
138 }
139 return result;
140 # else
141 int eax, ecx, edx;
142
143 __asm__("push %%ebx\n\tcpuid\n\tpop %%ebx"
144 : "=a" (eax), "=c" (ecx), "=d" (edx)
145 : "a" (op));
146 return ecx;
147 # endif
148 }
149
150 static inline int xgetbv_eax(int op)
151 {
152 # ifdef _MSC_VER
153 int veax, vedx;
154 _asm {
155 mov ecx,op
156 # if defined(__INTEL_COMPILER) || (_MSC_VER >= 1600)
157 xgetbv
158 # else
159 __emit 15
160 __emit 1
161 __emit 208
162 # endif
163 mov veax,eax
164 mov vedx,edx
165 }
166 return veax;
167 # else
168 int eax, edx;
169 __asm__ (".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c" (op));
170 return eax;
171 #endif
172 }