annotate src/fftw-3.3.3/simd-support/x86-cpuid.h @ 23:619f715526df sv_v2.1

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