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