cpuid.asm
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:6k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. ;/******************************************************************************
  2. ; *                                                                            *
  3. ; *  This file is part of XviD, a free MPEG-4 video encoder/decoder            *
  4. ; *                                                                            *
  5. ; *  XviD is an implementation of a part of one or more MPEG-4 Video tools     *
  6. ; *  as specified in ISO/IEC 14496-2 standard.  Those intending to use this    *
  7. ; *  software module in hardware or software products are advised that its     *
  8. ; *  use may infringe existing patents or copyrights, and any such use         *
  9. ; *  would be at such party's own risk.  The original developer of this        *
  10. ; *  software module and his/her company, and subsequent editors and their     *
  11. ; *  companies, will have no liability for use of this software or             *
  12. ; *  modifications or derivatives thereof.                                     *
  13. ; *                                                                            *
  14. ; *  XviD is free software; you can redistribute it and/or modify it           *
  15. ; *  under the terms of the GNU General Public License as published by         *
  16. ; *  the Free Software Foundation; either version 2 of the License, or         *
  17. ; *  (at your option) any later version.                                       *
  18. ; *                                                                            *
  19. ; *  XviD is distributed in the hope that it will be useful, but               *
  20. ; *  WITHOUT ANY WARRANTY; without even the implied warranty of                *
  21. ; *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
  22. ; *  GNU General Public License for more details.                              *
  23. ; *                                                                            *
  24. ; *  You should have received a copy of the GNU General Public License         *
  25. ; *  along with this program; if not, write to the Free Software               *
  26. ; *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *
  27. ; *                                                                            *
  28. ; ******************************************************************************/
  29. ;
  30. ;/******************************************************************************
  31. ; *                                                                            *
  32. ; *  cpuid.asm, check cpu features                                             *
  33. ; *                                                                            *
  34. ; *  Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org>,                 *
  35. ; *                                                                            *
  36. ; *  For more information visit the XviD homepage: http://www.xvid.org         *
  37. ; *                                                                            *
  38. ; ******************************************************************************/
  39. ;
  40. ;/******************************************************************************
  41. ; *                                                                            *
  42. ; *  Revision history:                                                         *
  43. ; *                                                                            *
  44. ; *  17.12.2001 initial version  (Isibaar)                                     *
  45. ; *                                                                            *
  46. ; ******************************************************************************/
  47. bits 32
  48. %define CPUID_TSC 0x00000010
  49. %define CPUID_MMX 0x00800000
  50. %define CPUID_SSE 0x02000000
  51. %define CPUID_SSE2 0x04000000
  52. %define EXT_CPUID_3DNOW 0x80000000
  53. %define EXT_CPUID_AMD_3DNOWEXT 0x40000000
  54. %define EXT_CPUID_AMD_MMXEXT 0x00400000
  55. %define XVID_CPU_MMX 0x00000001
  56. %define XVID_CPU_MMXEXT 0x00000002
  57. %define XVID_CPU_SSE         0x00000004
  58. %define XVID_CPU_SSE2 0x00000008
  59. %define XVID_CPU_3DNOW          0x00000010
  60. %define XVID_CPU_3DNOWEXT 0x00000020
  61. %define XVID_CPU_TSC            0x00000040
  62. %macro cglobal 1 
  63. %ifdef PREFIX
  64. global _%1 
  65. %define %1 _%1
  66. %else
  67. global %1
  68. %endif
  69. %endmacro
  70. ALIGN 32
  71. section .data
  72. features dd 0
  73. vendor dd 0,0,0
  74. vendorAMD db "AuthenticAMD"
  75. %macro  CHECK_FEATURE         3
  76.     mov     ecx, %1
  77.     and     ecx, edx
  78.     neg     ecx
  79.     sbb     ecx, ecx
  80.     and     ecx, %2
  81.     or      [%3], ecx
  82. %endmacro
  83. section .text
  84. ; int check_cpu_feature(void)
  85. cglobal check_cpu_features
  86. check_cpu_features:
  87. pushad
  88. pushfd                         
  89. ; CPUID command ?
  90. pop eax
  91. mov ecx, eax
  92. xor eax, 0x200000
  93. push eax
  94. popfd
  95. pushfd
  96. pop eax
  97. cmp eax, ecx
  98. jz near .cpu_quit ; no CPUID command -> exit
  99. ; get vendor string, used later
  100.     xor     eax, eax
  101.     cpuid           
  102.     mov     [vendor], ebx       ; vendor string 
  103.     mov     [vendor+4], edx     
  104.     mov     [vendor+8], ecx     
  105.     test    eax, eax
  106.     jz      near .cpu_quit
  107.     mov     eax, 1 
  108.     cpuid
  109.     ; RDTSC command ?
  110. CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, features
  111.     ; MMX support ?
  112. CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, features
  113.     ; SSE support ?
  114. CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT+XVID_CPU_SSE), features
  115. ; SSE2 support?
  116. CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, features
  117. ; extended functions?
  118.     mov     eax, 0x80000000
  119.     cpuid
  120.     cmp     eax, 0x80000000
  121.     jbe     near .cpu_quit
  122.     mov     eax, 0x80000001
  123.     cpuid
  124.          
  125.     ; 3DNow! support ?
  126. CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, features
  127. ; AMD cpu ?
  128.     lea     esi, [vendorAMD]
  129.     lea     edi, [vendor]
  130.     mov     ecx, 12
  131.     cld
  132.     repe    cmpsb
  133.     jnz     .cpu_quit
  134. ; 3DNOW extended ?
  135. CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, features
  136. ; extended MMX ?
  137. CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, features
  138.         
  139. .cpu_quit:  
  140. popad
  141. mov eax, [features]
  142. ret