cannam@95: /* cannam@95: * Copyright (c) 2003, 2007-11 Matteo Frigo cannam@95: * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology cannam@95: * cannam@95: * This program is free software; you can redistribute it and/or modify cannam@95: * it under the terms of the GNU General Public License as published by cannam@95: * the Free Software Foundation; either version 2 of the License, or cannam@95: * (at your option) any later version. cannam@95: * cannam@95: * This program is distributed in the hope that it will be useful, cannam@95: * but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@95: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@95: * GNU General Public License for more details. cannam@95: * cannam@95: * You should have received a copy of the GNU General Public License cannam@95: * along with this program; if not, write to the Free Software cannam@95: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA cannam@95: * cannam@95: */ cannam@95: cannam@95: cannam@95: #ifdef _MSC_VER cannam@95: #ifndef inline cannam@95: #define inline __inline cannam@95: #endif cannam@95: #endif cannam@95: cannam@95: #ifdef _MSC_VER cannam@95: #include cannam@95: #if (_MSC_VER >= 1600) && !defined(__INTEL_COMPILER) cannam@95: #include cannam@95: #endif cannam@95: #endif cannam@95: cannam@95: static inline int cpuid_ecx(int op) cannam@95: { cannam@95: # ifdef _MSC_VER cannam@95: # ifdef __INTEL_COMPILER cannam@95: int result; cannam@95: _asm { cannam@95: push rbx cannam@95: mov eax,op cannam@95: cpuid cannam@95: mov result,ecx cannam@95: pop rbx cannam@95: } cannam@95: return result; cannam@95: # else cannam@95: int cpu_info[4]; cannam@95: __cpuid(cpu_info,op); cannam@95: return cpu_info[2]; cannam@95: # endif cannam@95: # else cannam@95: int eax, ecx, edx; cannam@95: cannam@95: __asm__("pushq %%rbx\n\tcpuid\n\tpopq %%rbx" cannam@95: : "=a" (eax), "=c" (ecx), "=d" (edx) cannam@95: : "a" (op)); cannam@95: return ecx; cannam@95: # endif cannam@95: } cannam@95: cannam@95: static inline int xgetbv_eax(int op) cannam@95: { cannam@95: # ifdef _MSC_VER cannam@95: # ifdef __INTEL_COMPILER cannam@95: int veax, vedx; cannam@95: _asm { cannam@95: mov ecx,op cannam@95: xgetbv cannam@95: mov veax,eax cannam@95: mov vedx,edx cannam@95: } cannam@95: return veax; cannam@95: # else cannam@95: # if defined(_MSC_VER) && (_MSC_VER >= 1600) cannam@95: unsigned __int64 result; cannam@95: result = _xgetbv(op); cannam@95: return (int)result; cannam@95: # else cannam@95: # error "Need at least Visual Studio 10 SP1 for AVX support" cannam@95: # endif cannam@95: # endif cannam@95: # else cannam@95: int eax, edx; cannam@95: __asm__ (".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c" (op)); cannam@95: return eax; cannam@95: #endif cannam@95: }