Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.5/simd-support/amd64-cpuid.h @ 42:2cd0e3b3e1fd
Current fftw source
author | Chris Cannam |
---|---|
date | Tue, 18 Oct 2016 13:40:26 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
41:481f5f8c5634 | 42:2cd0e3b3e1fd |
---|---|
1 /* | |
2 * Copyright (c) 2003, 2007-14 Matteo Frigo | |
3 * Copyright (c) 2003, 2007-14 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 #ifdef _MSC_VER | |
23 #ifndef inline | |
24 #define inline __inline | |
25 #endif | |
26 #endif | |
27 | |
28 #ifdef _MSC_VER | |
29 #include <intrin.h> | |
30 #if (_MSC_VER >= 1600) && !defined(__INTEL_COMPILER) | |
31 #include <immintrin.h> | |
32 #endif | |
33 #endif | |
34 | |
35 /* cpuid version to get all registers. Donated by Erik Lindahl from Gromacs. */ | |
36 static inline void | |
37 cpuid_all(int level, int ecxval, int *eax, int *ebx, int *ecx, int *edx) | |
38 { | |
39 # ifdef _MSC_VER | |
40 int CPUInfo[4]; | |
41 | |
42 #if (_MSC_VER > 1500) || (_MSC_VER == 1500 & _MSC_FULL_VER >= 150030729) | |
43 /* MSVC 9.0 SP1 or later */ | |
44 __cpuidex(CPUInfo, op, ecxval); | |
45 #else | |
46 __cpuid(CPUInfo, level); | |
47 #endif | |
48 *eax = CPUInfo[0]; | |
49 *ebx = CPUInfo[1]; | |
50 *ecx = CPUInfo[2]; | |
51 *edx = CPUInfo[3]; | |
52 | |
53 # else | |
54 /* Not MSVC */ | |
55 *eax = level; | |
56 *ecx = ecxval; | |
57 *ebx = 0; | |
58 *edx = 0; | |
59 /* No need to save ebx if we are not in pic mode */ | |
60 __asm__ ("cpuid \n\t" | |
61 : "+a" (*eax), "+b" (*ebx), "+c" (*ecx), "+d" (*edx)); | |
62 # endif | |
63 } | |
64 | |
65 | |
66 static inline int cpuid_ecx(int op) | |
67 { | |
68 # ifdef _MSC_VER | |
69 # ifdef __INTEL_COMPILER | |
70 int result; | |
71 _asm { | |
72 push rbx | |
73 mov eax,op | |
74 cpuid | |
75 mov result,ecx | |
76 pop rbx | |
77 } | |
78 return result; | |
79 # else | |
80 int cpu_info[4]; | |
81 __cpuid(cpu_info,op); | |
82 return cpu_info[2]; | |
83 # endif | |
84 # else | |
85 int eax, ecx = 0, edx; | |
86 | |
87 __asm__("pushq %%rbx\n\tcpuid\n\tpopq %%rbx" | |
88 : "=a" (eax), "+c" (ecx), "=d" (edx) | |
89 : "a" (op)); | |
90 return ecx; | |
91 # endif | |
92 } | |
93 | |
94 static inline int cpuid_ebx(int op) | |
95 { | |
96 # ifdef _MSC_VER | |
97 # ifdef __INTEL_COMPILER | |
98 int result; | |
99 _asm { | |
100 push rbx | |
101 mov eax,op | |
102 cpuid | |
103 mov result,ebx | |
104 pop rbx | |
105 } | |
106 return result; | |
107 # else | |
108 int cpu_info[4]; | |
109 __cpuid(cpu_info,op); | |
110 return cpu_info[1]; | |
111 # endif | |
112 # else | |
113 int eax, ecx = 0, edx; | |
114 | |
115 __asm__("pushq %%rbx\n\tcpuid\nmov %%ebx,%%ecx\n\tpopq %%rbx" | |
116 : "=a" (eax), "+c" (ecx), "=d" (edx) | |
117 : "a" (op)); | |
118 return ecx; | |
119 # endif | |
120 } | |
121 | |
122 static inline int xgetbv_eax(int op) | |
123 { | |
124 # ifdef _MSC_VER | |
125 # ifdef __INTEL_COMPILER | |
126 int veax, vedx; | |
127 _asm { | |
128 mov ecx,op | |
129 xgetbv | |
130 mov veax,eax | |
131 mov vedx,edx | |
132 } | |
133 return veax; | |
134 # else | |
135 # if defined(_MSC_VER) && (_MSC_VER >= 1600) | |
136 unsigned __int64 result; | |
137 result = _xgetbv(op); | |
138 return (int)result; | |
139 # else | |
140 # error "Need at least Visual Studio 10 SP1 for AVX support" | |
141 # endif | |
142 # endif | |
143 # else | |
144 int eax, edx; | |
145 __asm__ (".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c" (op)); | |
146 return eax; | |
147 #endif | |
148 } |