You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.6KB

  1. /*
  2. * CPU detection code, extracted from mmx.h
  3. * (c)1997-99 by H. Dietz and R. Fisher
  4. * Converted to C and improved by Fabrice Bellard.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <stdlib.h>
  21. #include "../dsputil.h"
  22. #ifdef ARCH_X86_64
  23. # define REG_b "rbx"
  24. # define REG_S "rsi"
  25. #else
  26. # define REG_b "ebx"
  27. # define REG_S "esi"
  28. #endif
  29. /* ebx saving is necessary for PIC. gcc seems unable to see it alone */
  30. #define cpuid(index,eax,ebx,ecx,edx)\
  31. __asm __volatile\
  32. ("mov %%"REG_b", %%"REG_S"\n\t"\
  33. "cpuid\n\t"\
  34. "xchg %%"REG_b", %%"REG_S\
  35. : "=a" (eax), "=S" (ebx),\
  36. "=c" (ecx), "=d" (edx)\
  37. : "0" (index));
  38. /* Function to test if multimedia instructions are supported... */
  39. int mm_support(void)
  40. {
  41. int rval = 0;
  42. int eax, ebx, ecx, edx;
  43. int max_std_level, max_ext_level, std_caps=0, ext_caps=0;
  44. long a, c;
  45. __asm__ __volatile__ (
  46. /* See if CPUID instruction is supported ... */
  47. /* ... Get copies of EFLAGS into eax and ecx */
  48. "pushf\n\t"
  49. "pop %0\n\t"
  50. "mov %0, %1\n\t"
  51. /* ... Toggle the ID bit in one copy and store */
  52. /* to the EFLAGS reg */
  53. "xor $0x200000, %0\n\t"
  54. "push %0\n\t"
  55. "popf\n\t"
  56. /* ... Get the (hopefully modified) EFLAGS */
  57. "pushf\n\t"
  58. "pop %0\n\t"
  59. : "=a" (a), "=c" (c)
  60. :
  61. : "cc"
  62. );
  63. if (a == c)
  64. return 0; /* CPUID not supported */
  65. cpuid(0, max_std_level, ebx, ecx, edx);
  66. if(max_std_level >= 1){
  67. cpuid(1, eax, ebx, ecx, std_caps);
  68. if (std_caps & (1<<23))
  69. rval |= MM_MMX;
  70. if (std_caps & (1<<25))
  71. rval |= MM_MMXEXT | MM_SSE;
  72. if (std_caps & (1<<26))
  73. rval |= MM_SSE2;
  74. if (ecx & 1)
  75. rval |= MM_SSE3;
  76. }
  77. cpuid(0x80000000, max_ext_level, ebx, ecx, edx);
  78. if(max_ext_level >= 0x80000001){
  79. cpuid(0x80000001, eax, ebx, ecx, ext_caps);
  80. if (ext_caps & (1<<31))
  81. rval |= MM_3DNOW;
  82. if (ext_caps & (1<<30))
  83. rval |= MM_3DNOWEXT;
  84. if (ext_caps & (1<<23))
  85. rval |= MM_MMX;
  86. if (ext_caps & (1<<22))
  87. rval |= MM_MMXEXT;
  88. }
  89. #if 0
  90. av_log(NULL, AV_LOG_DEBUG, "%s%s%s%s%s%s\n",
  91. (rval&MM_MMX) ? "MMX ":"",
  92. (rval&MM_MMXEXT) ? "MMX2 ":"",
  93. (rval&MM_SSE) ? "SSE ":"",
  94. (rval&MM_SSE2) ? "SSE2 ":"",
  95. (rval&MM_3DNOW) ? "3DNow ":"",
  96. (rval&MM_3DNOWEXT) ? "3DNowExt ":"");
  97. #endif
  98. return rval;
  99. }
  100. #ifdef __TEST__
  101. int main ( void )
  102. {
  103. int mm_flags;
  104. mm_flags = mm_support();
  105. printf("mm_support = 0x%08X\n",mm_flags);
  106. return 0;
  107. }
  108. #endif