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.

153 lines
4.5KB

  1. /* Cpu detection code, extracted from mmx.h ((c)1997-99 by H. Dietz
  2. and R. Fisher). Converted to C and improved by Fabrice Bellard */
  3. #include <stdlib.h>
  4. #include "../dsputil.h"
  5. #ifdef ARCH_X86_64
  6. # define REG_b "rbx"
  7. # define REG_S "rsi"
  8. #else
  9. # define REG_b "ebx"
  10. # define REG_S "esi"
  11. #endif
  12. /* ebx saving is necessary for PIC. gcc seems unable to see it alone */
  13. #define cpuid(index,eax,ebx,ecx,edx)\
  14. __asm __volatile\
  15. ("mov %%"REG_b", %%"REG_S"\n\t"\
  16. "cpuid\n\t"\
  17. "xchg %%"REG_b", %%"REG_S\
  18. : "=a" (eax), "=S" (ebx),\
  19. "=c" (ecx), "=d" (edx)\
  20. : "0" (index));
  21. /* Function to test if multimedia instructions are supported... */
  22. int mm_support(void)
  23. {
  24. int rval;
  25. int eax, ebx, ecx, edx;
  26. long a, c;
  27. __asm__ __volatile__ (
  28. /* See if CPUID instruction is supported ... */
  29. /* ... Get copies of EFLAGS into eax and ecx */
  30. "pushf\n\t"
  31. "pop %0\n\t"
  32. "mov %0, %1\n\t"
  33. /* ... Toggle the ID bit in one copy and store */
  34. /* to the EFLAGS reg */
  35. "xor $0x200000, %0\n\t"
  36. "push %0\n\t"
  37. "popf\n\t"
  38. /* ... Get the (hopefully modified) EFLAGS */
  39. "pushf\n\t"
  40. "pop %0\n\t"
  41. : "=a" (a), "=c" (c)
  42. :
  43. : "cc"
  44. );
  45. if (a == c)
  46. return 0; /* CPUID not supported */
  47. cpuid(0, eax, ebx, ecx, edx);
  48. if (ebx == 0x756e6547 &&
  49. edx == 0x49656e69 &&
  50. ecx == 0x6c65746e) {
  51. /* intel */
  52. inteltest:
  53. cpuid(1, eax, ebx, ecx, edx);
  54. if ((edx & 0x00800000) == 0)
  55. return 0;
  56. rval = MM_MMX;
  57. if (edx & 0x02000000)
  58. rval |= MM_MMXEXT | MM_SSE;
  59. if (edx & 0x04000000)
  60. rval |= MM_SSE2;
  61. return rval;
  62. } else if (ebx == 0x68747541 &&
  63. edx == 0x69746e65 &&
  64. ecx == 0x444d4163) {
  65. /* AMD */
  66. cpuid(0x80000000, eax, ebx, ecx, edx);
  67. if ((unsigned)eax < 0x80000001)
  68. goto inteltest;
  69. cpuid(0x80000001, eax, ebx, ecx, edx);
  70. if ((edx & 0x00800000) == 0)
  71. return 0;
  72. rval = MM_MMX;
  73. if (edx & 0x80000000)
  74. rval |= MM_3DNOW;
  75. if (edx & 0x00400000)
  76. rval |= MM_MMXEXT;
  77. return rval;
  78. } else if (ebx == 0x746e6543 &&
  79. edx == 0x48727561 &&
  80. ecx == 0x736c7561) { /* "CentaurHauls" */
  81. /* VIA C3 */
  82. cpuid(0x80000000, eax, ebx, ecx, edx);
  83. if ((unsigned)eax < 0x80000001)
  84. goto inteltest;
  85. cpuid(0x80000001, eax, ebx, ecx, edx);
  86. rval = 0;
  87. if( edx & ( 1 << 31) )
  88. rval |= MM_3DNOW;
  89. if( edx & ( 1 << 23) )
  90. rval |= MM_MMX;
  91. if( edx & ( 1 << 24) )
  92. rval |= MM_MMXEXT;
  93. if(rval==0)
  94. goto inteltest;
  95. return rval;
  96. } else if (ebx == 0x69727943 &&
  97. edx == 0x736e4978 &&
  98. ecx == 0x64616574) {
  99. /* Cyrix Section */
  100. /* See if extended CPUID level 80000001 is supported */
  101. /* The value of CPUID/80000001 for the 6x86MX is undefined
  102. according to the Cyrix CPU Detection Guide (Preliminary
  103. Rev. 1.01 table 1), so we'll check the value of eax for
  104. CPUID/0 to see if standard CPUID level 2 is supported.
  105. According to the table, the only CPU which supports level
  106. 2 is also the only one which supports extended CPUID levels.
  107. */
  108. if (eax != 2)
  109. goto inteltest;
  110. cpuid(0x80000001, eax, ebx, ecx, edx);
  111. if ((eax & 0x00800000) == 0)
  112. return 0;
  113. rval = MM_MMX;
  114. if (eax & 0x01000000)
  115. rval |= MM_MMXEXT;
  116. return rval;
  117. } else if (ebx == 0x756e6547 &&
  118. edx == 0x54656e69 &&
  119. ecx == 0x3638784d) {
  120. /* Tranmeta Crusoe */
  121. cpuid(0x80000000, eax, ebx, ecx, edx);
  122. if ((unsigned)eax < 0x80000001)
  123. return 0;
  124. cpuid(0x80000001, eax, ebx, ecx, edx);
  125. if ((edx & 0x00800000) == 0)
  126. return 0;
  127. return MM_MMX;
  128. } else {
  129. return 0;
  130. }
  131. }
  132. #ifdef __TEST__
  133. int main ( void )
  134. {
  135. int mm_flags;
  136. mm_flags = mm_support();
  137. printf("mm_support = 0x%08X\n",mm_flags);
  138. return 0;
  139. }
  140. #endif