OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2014, Cisco Systems, INC |
| 2 Written by XiangMingZhu WeiZhou MinPeng YanWang |
| 3 |
| 4 Redistribution and use in source and binary forms, with or without |
| 5 modification, are permitted provided that the following conditions |
| 6 are met: |
| 7 |
| 8 - Redistributions of source code must retain the above copyright |
| 9 notice, this list of conditions and the following disclaimer. |
| 10 |
| 11 - Redistributions in binary form must reproduce the above copyright |
| 12 notice, this list of conditions and the following disclaimer in the |
| 13 documentation and/or other materials provided with the distribution. |
| 14 |
| 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
| 19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ |
| 27 |
| 28 #ifdef HAVE_CONFIG_H |
| 29 #include "config.h" |
| 30 #endif |
| 31 |
| 32 #include "cpu_support.h" |
| 33 #include "macros.h" |
| 34 #include "main.h" |
| 35 #include "pitch.h" |
| 36 #include "x86cpu.h" |
| 37 |
| 38 #if defined(_MSC_VER) |
| 39 |
| 40 #include <intrin.h> |
| 41 #define cpuid(info,x) __cpuid(info,x) |
| 42 #else |
| 43 |
| 44 #if defined(CPU_INFO_BY_C) |
| 45 #include <cpuid.h> |
| 46 #endif |
| 47 |
| 48 static void cpuid(unsigned int CPUInfo[4], unsigned int InfoType) |
| 49 { |
| 50 #if defined(CPU_INFO_BY_ASM) |
| 51 __asm__ __volatile__ ( |
| 52 "cpuid": |
| 53 "=a" (CPUInfo[0]), |
| 54 "=b" (CPUInfo[1]), |
| 55 "=c" (CPUInfo[2]), |
| 56 "=d" (CPUInfo[3]) : |
| 57 "a" (InfoType), "c" (0) |
| 58 ); |
| 59 #elif defined(CPU_INFO_BY_C) |
| 60 __get_cpuid(InfoType, &(CPUInfo[0]), &(CPUInfo[1]), &(CPUInfo[2]), &(CPUInfo
[3])); |
| 61 #endif |
| 62 } |
| 63 |
| 64 #endif |
| 65 |
| 66 #include "SigProc_FIX.h" |
| 67 #include "celt_lpc.h" |
| 68 |
| 69 typedef struct CPU_Feature{ |
| 70 /* SIMD: 128-bit */ |
| 71 int HW_SSE2; |
| 72 int HW_SSE41; |
| 73 } CPU_Feature; |
| 74 |
| 75 static void opus_cpu_feature_check(CPU_Feature *cpu_feature) |
| 76 { |
| 77 unsigned int info[4] = {0}; |
| 78 unsigned int nIds = 0; |
| 79 |
| 80 cpuid(info, 0); |
| 81 nIds = info[0]; |
| 82 |
| 83 if (nIds >= 1){ |
| 84 cpuid(info, 1); |
| 85 cpu_feature->HW_SSE2 = (info[3] & (1 << 26)) != 0; |
| 86 cpu_feature->HW_SSE41 = (info[2] & (1 << 19)) != 0; |
| 87 } |
| 88 } |
| 89 |
| 90 int opus_select_arch(void) |
| 91 { |
| 92 CPU_Feature cpu_feature = {0}; |
| 93 int arch; |
| 94 |
| 95 opus_cpu_feature_check(&cpu_feature); |
| 96 |
| 97 arch = 0; |
| 98 if (!cpu_feature.HW_SSE2) |
| 99 { |
| 100 return arch; |
| 101 } |
| 102 arch++; |
| 103 |
| 104 if (!cpu_feature.HW_SSE41) |
| 105 { |
| 106 return arch; |
| 107 } |
| 108 arch++; |
| 109 |
| 110 return arch; |
| 111 } |
OLD | NEW |