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