1 /** 2 @file cpusupport.h 3 */ 4 /* 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions 7 are met: 8 9 - Redistributions of source code must retain the above copyright 10 notice, this list of conditions and the following disclaimer. 11 12 - Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in the 14 documentation and/or other materials provided with the distribution. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef OPUSTOOLS_CPUSUPPORT_H 30 # define OPUSTOOLS_CPUSUPPORT_H 31 32 /* We want to warn if we're built with SSE support, but running 33 on a host without those instructions. Therefore we disable 34 the query both if the compiler isn't supporting SSE, and on 35 targets which are guaranteed to have SSE. */ 36 # if !defined(__SSE__) || defined(_M_X64) || defined(__amd64__) 37 # define query_cpu_support() 0 38 # else 39 40 #if defined WIN32 || defined _WIN32 41 #include <intrin.h> 42 static inline int query_cpu_support(void) 43 { 44 int buffer[4]; 45 __cpuid(buffer, 1); 46 return ((buffer[3] & (1<<25)) == 0) /*SSE*/ 47 # ifdef __SSE2__ 48 + ((buffer[3] & (1<<26)) == 0) /*SSE2*/ 49 # endif 50 ; 51 } 52 #else 53 #include <cpuid.h> 54 static inline int query_cpu_support(void) 55 { 56 unsigned int eax, ebx, ecx, edx=0; 57 __get_cpuid(1, &eax, &ebx, &ecx, &edx); 58 return ((edx & 1<<25) == 0) /*SSE*/ 59 #ifdef __SSE2__ 60 + ((edx & 1<<26) == 0) /*SSE2*/ 61 #endif 62 ; 63 } 64 #endif 65 66 # endif 67 #endif 68