x86cpu.c 2.8 KB

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