annotate src/fftw-3.3.8/simd-support/x86-cpuid.h @ 168:ceec0dd9ec9c

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 07 Feb 2020 11:51:13 +0000
parents bd3cc4d1df30
children
rev   line source
cannam@167 1 /*
cannam@167 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
cannam@167 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
cannam@167 4 *
cannam@167 5 * This program is free software; you can redistribute it and/or modify
cannam@167 6 * it under the terms of the GNU General Public License as published by
cannam@167 7 * the Free Software Foundation; either version 2 of the License, or
cannam@167 8 * (at your option) any later version.
cannam@167 9 *
cannam@167 10 * This program is distributed in the hope that it will be useful,
cannam@167 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@167 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@167 13 * GNU General Public License for more details.
cannam@167 14 *
cannam@167 15 * You should have received a copy of the GNU General Public License
cannam@167 16 * along with this program; if not, write to the Free Software
cannam@167 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@167 18 *
cannam@167 19 */
cannam@167 20
cannam@167 21
cannam@167 22 /* this code was kindly donated by Eric J. Korpela */
cannam@167 23
cannam@167 24 #ifdef _MSC_VER
cannam@167 25 #ifndef inline
cannam@167 26 #define inline __inline
cannam@167 27 #endif
cannam@167 28 #endif
cannam@167 29
cannam@167 30 static inline int is_386()
cannam@167 31 {
cannam@167 32 #ifdef _MSC_VER
cannam@167 33 unsigned int result,tst;
cannam@167 34 _asm {
cannam@167 35 pushfd
cannam@167 36 pop eax
cannam@167 37 mov edx,eax
cannam@167 38 xor eax,40000h
cannam@167 39 push eax
cannam@167 40 popfd
cannam@167 41 pushfd
cannam@167 42 pop eax
cannam@167 43 push edx
cannam@167 44 popfd
cannam@167 45 mov tst,edx
cannam@167 46 mov result,eax
cannam@167 47 }
cannam@167 48 #else
cannam@167 49 register unsigned int result,tst;
cannam@167 50 __asm__ (
cannam@167 51 "pushfl\n\t"
cannam@167 52 "popl %0\n\t"
cannam@167 53 "movl %0,%1\n\t"
cannam@167 54 "xorl $0x40000,%0\n\t"
cannam@167 55 "pushl %0\n\t"
cannam@167 56 "popfl\n\t"
cannam@167 57 "pushfl\n\t"
cannam@167 58 "popl %0\n\t"
cannam@167 59 "pushl %1\n\t"
cannam@167 60 "popfl"
cannam@167 61 : "=r" (result), "=r" (tst) /* output */
cannam@167 62 : /* no inputs */
cannam@167 63 );
cannam@167 64 #endif
cannam@167 65 return (result == tst);
cannam@167 66 }
cannam@167 67
cannam@167 68 static inline int has_cpuid()
cannam@167 69 {
cannam@167 70 #ifdef _MSC_VER
cannam@167 71 unsigned int result,tst;
cannam@167 72 _asm {
cannam@167 73 pushfd
cannam@167 74 pop eax
cannam@167 75 mov edx,eax
cannam@167 76 xor eax,200000h
cannam@167 77 push eax
cannam@167 78 popfd
cannam@167 79 pushfd
cannam@167 80 pop eax
cannam@167 81 push edx
cannam@167 82 popfd
cannam@167 83 mov tst,edx
cannam@167 84 mov result,eax
cannam@167 85 }
cannam@167 86 #else
cannam@167 87 register unsigned int result,tst;
cannam@167 88 __asm__ (
cannam@167 89 "pushfl\n\t"
cannam@167 90 "pop %0\n\t"
cannam@167 91 "movl %0,%1\n\t"
cannam@167 92 "xorl $0x200000,%0\n\t"
cannam@167 93 "pushl %0\n\t"
cannam@167 94 "popfl\n\t"
cannam@167 95 "pushfl\n\t"
cannam@167 96 "popl %0\n\t"
cannam@167 97 "pushl %1\n\t"
cannam@167 98 "popfl"
cannam@167 99 : "=r" (result), "=r" (tst) /* output */
cannam@167 100 : /* no inputs */
cannam@167 101 );
cannam@167 102 #endif
cannam@167 103 return (result != tst);
cannam@167 104 }
cannam@167 105
cannam@167 106 /* cpuid version to get all registers. Donated by Erik Lindahl from Gromacs. */
cannam@167 107 static inline void
cannam@167 108 cpuid_all(int level, int ecxval, int *eax, int *ebx, int *ecx, int *edx)
cannam@167 109 {
cannam@167 110 #if (defined _MSC_VER)
cannam@167 111 int CPUInfo[4];
cannam@167 112
cannam@167 113 # if (_MSC_VER > 1500) || (_MSC_VER == 1500 & _MSC_FULL_VER >= 150030729)
cannam@167 114 /* MSVC 9.0 SP1 or later */
cannam@167 115 __cpuidex(CPUInfo, level, ecxval);
cannam@167 116 # else
cannam@167 117 __cpuid(CPUInfo, level);
cannam@167 118 /* Set an error code if the user wanted a non-zero ecxval, since we did not have cpuidex */
cannam@167 119 # endif
cannam@167 120 *eax = CPUInfo[0];
cannam@167 121 *ebx = CPUInfo[1];
cannam@167 122 *ecx = CPUInfo[2];
cannam@167 123 *edx = CPUInfo[3];
cannam@167 124
cannam@167 125 #else
cannam@167 126 /* Not MSVC */
cannam@167 127 *eax = level;
cannam@167 128 *ecx = ecxval;
cannam@167 129 *ebx = 0;
cannam@167 130 *edx = 0;
cannam@167 131 /* Avoid clobbering global offset table in 32-bit pic code (ebx) */
cannam@167 132 # if defined(__PIC__)
cannam@167 133 __asm__ ("xchgl %%ebx, %1 \n\t"
cannam@167 134 "cpuid \n\t"
cannam@167 135 "xchgl %%ebx, %1 \n\t"
cannam@167 136 : "+a" (*eax), "+r" (*ebx), "+c" (*ecx), "+d" (*edx));
cannam@167 137 # else
cannam@167 138 /* No need to save ebx if we are not in pic mode */
cannam@167 139 __asm__ ("cpuid \n\t"
cannam@167 140 : "+a" (*eax), "+b" (*ebx), "+c" (*ecx), "+d" (*edx));
cannam@167 141 # endif
cannam@167 142 #endif
cannam@167 143 }
cannam@167 144
cannam@167 145 static inline int cpuid_edx(int op)
cannam@167 146 {
cannam@167 147 # ifdef _MSC_VER
cannam@167 148 int result;
cannam@167 149 _asm {
cannam@167 150 push ebx
cannam@167 151 mov eax,op
cannam@167 152 cpuid
cannam@167 153 mov result,edx
cannam@167 154 pop ebx
cannam@167 155 }
cannam@167 156 return result;
cannam@167 157 # else
cannam@167 158 int eax, ecx, edx;
cannam@167 159
cannam@167 160 __asm__("push %%ebx\n\tcpuid\n\tpop %%ebx"
cannam@167 161 : "=a" (eax), "=c" (ecx), "=d" (edx)
cannam@167 162 : "a" (op));
cannam@167 163 return edx;
cannam@167 164 # endif
cannam@167 165 }
cannam@167 166
cannam@167 167 static inline int cpuid_ecx(int op)
cannam@167 168 {
cannam@167 169 # ifdef _MSC_VER
cannam@167 170 int result;
cannam@167 171 _asm {
cannam@167 172 push ebx
cannam@167 173 mov eax,op
cannam@167 174 cpuid
cannam@167 175 mov result,ecx
cannam@167 176 pop ebx
cannam@167 177 }
cannam@167 178 return result;
cannam@167 179 # else
cannam@167 180 int eax, ecx, edx;
cannam@167 181
cannam@167 182 __asm__("push %%ebx\n\tcpuid\n\tpop %%ebx"
cannam@167 183 : "=a" (eax), "=c" (ecx), "=d" (edx)
cannam@167 184 : "a" (op));
cannam@167 185 return ecx;
cannam@167 186 # endif
cannam@167 187 }
cannam@167 188
cannam@167 189 static inline int xgetbv_eax(int op)
cannam@167 190 {
cannam@167 191 # ifdef _MSC_VER
cannam@167 192 int veax, vedx;
cannam@167 193 _asm {
cannam@167 194 mov ecx,op
cannam@167 195 # if defined(__INTEL_COMPILER) || (_MSC_VER >= 1600)
cannam@167 196 xgetbv
cannam@167 197 # else
cannam@167 198 __emit 15
cannam@167 199 __emit 1
cannam@167 200 __emit 208
cannam@167 201 # endif
cannam@167 202 mov veax,eax
cannam@167 203 mov vedx,edx
cannam@167 204 }
cannam@167 205 return veax;
cannam@167 206 # else
cannam@167 207 int eax, edx;
cannam@167 208 __asm__ (".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c" (op));
cannam@167 209 return eax;
cannam@167 210 #endif
cannam@167 211 }