[cvs] / xvidcore / src / utils / x86_asm / cpuid.asm Repository:
ViewVC logotype

Diff of /xvidcore/src/utils/x86_asm/cpuid.asm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Fri Mar 8 02:45:00 2002 UTC revision 1.11, Thu Mar 8 21:40:12 2007 UTC
# Line 1  Line 1 
1  ;/******************************************************************************  ;/****************************************************************************
2  ; *                                                                            *  ; *
3  ; *  This file is part of XviD, a free MPEG-4 video encoder/decoder            *  ; *  XVID MPEG-4 VIDEO CODEC
4  ; *                                                                            *  ; *  - CPUID check processors capabilities -
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    *  ; *  Copyright (C) 2001 Michael Militzer <isibaar@xvid.org>
7  ; *  software module in hardware or software products are advised that its     *  ; *
8  ; *  use may infringe existing patents or copyrights, and any such use         *  ; *  This program is free software ; you can redistribute it and/or modify
9  ; *  would be at such party's own risk.  The original developer of this        *  ; *  it under the terms of the GNU General Public License as published by
10  ; *  software module and his/her company, and subsequent editors and their     *  ; *  the Free Software Foundation ; either version 2 of the License, or
11  ; *  companies, will have no liability for use of this software or             *  ; *  (at your option) any later version.
12  ; *  modifications or derivatives thereof.                                     *  ; *
13  ; *                                                                            *  ; *  This program is distributed in the hope that it will be useful,
14  ; *  XviD is free software; you can redistribute it and/or modify it           *  ; *  but WITHOUT ANY WARRANTY ; without even the implied warranty of
15  ; *  under the terms of the GNU General Public License as published by         *  ; *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  ; *  the Free Software Foundation; either version 2 of the License, or         *  ; *  GNU General Public License for more details.
17  ; *  (at your option) any later version.                                       *  ; *
18  ; *                                                                            *  ; *  You should have received a copy of the GNU General Public License
19  ; *  XviD is distributed in the hope that it will be useful, but               *  ; *  along with this program ; if not, write to the Free Software
20  ; *  WITHOUT ANY WARRANTY; without even the implied warranty of                *  ; *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  ; *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *  ; *
22  ; *  GNU General Public License for more details.                              *  ; * $Id$
23  ; *                                                                            *  ; *
24  ; *  You should have received a copy of the GNU General Public License         *  ; ***************************************************************************/
 ; *  along with this program; if not, write to the Free Software               *  
 ; *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *  
 ; *                                                                            *  
 ; ******************************************************************************/  
 ;  
 ;/******************************************************************************  
 ; *                                                                            *  
 ; *  cpuid.asm, check cpu features                                             *  
 ; *                                                                            *  
 ; *  Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org>,                 *  
 ; *                                                                            *  
 ; *  For more information visit the XviD homepage: http://www.xvid.org         *  
 ; *                                                                            *  
 ; ******************************************************************************/  
 ;  
 ;/******************************************************************************  
 ; *                                                                            *  
 ; *  Revision history:                                                         *  
 ; *                                                                            *  
 ; *  17.12.2001 initial version  (Isibaar)                                     *  
 ; *                                                                            *  
 ; ******************************************************************************/  
   
 bits 32  
   
 %define CPUID_TSC                               0x00000010  
 %define CPUID_MMX                               0x00800000  
 %define CPUID_SSE                               0x02000000  
 %define CPUID_SSE2                              0x04000000  
   
 %define EXT_CPUID_3DNOW                 0x80000000  
 %define EXT_CPUID_AMD_3DNOWEXT  0x40000000  
 %define EXT_CPUID_AMD_MMXEXT    0x00400000  
   
 %define XVID_CPU_MMX                    0x00000001  
 %define XVID_CPU_MMXEXT                 0x00000002  
 %define XVID_CPU_SSE            0x00000004  
 %define XVID_CPU_SSE2                   0x00000008  
 %define XVID_CPU_3DNOW          0x00000010  
 %define XVID_CPU_3DNOWEXT               0x00000020  
 %define XVID_CPU_TSC            0x00000040  
25    
26    BITS 32
27    
28  %macro cglobal 1  %macro cglobal 1
29          %ifdef PREFIX          %ifdef PREFIX
30                    %ifdef MARK_FUNCS
31                            global _%1:function %1.endfunc-%1
32                            %define %1 _%1:function %1.endfunc-%1
33                    %else
34                  global _%1                  global _%1
35                  %define %1 _%1                  %define %1 _%1
36                    %endif
37            %else
38                    %ifdef MARK_FUNCS
39                            global %1:function %1.endfunc-%1
40          %else          %else
41                  global %1                  global %1
42          %endif          %endif
43            %endif
44  %endmacro  %endmacro
45    
46  ALIGN 32  ;=============================================================================
47    ; Constants
48    ;=============================================================================
49    
50  section .data  %define CPUID_TSC               0x00000010
51    %define CPUID_MMX               0x00800000
52    %define CPUID_SSE               0x02000000
53    %define CPUID_SSE2              0x04000000
54    %define CPUID_SSE3              0x00000001
55    
56  features        dd 0  %define EXT_CPUID_3DNOW         0x80000000
57    %define EXT_CPUID_AMD_3DNOWEXT  0x40000000
58    %define EXT_CPUID_AMD_MMXEXT    0x00400000
59    
60  vendor          dd 0,0,0  ;;; NB: Make sure these defines match the ones defined in xvid.h
61  vendorAMD       db "AuthenticAMD"  %define XVID_CPU_MMX      (1<< 0)
62    %define XVID_CPU_MMXEXT   (1<< 1)
63    %define XVID_CPU_SSE      (1<< 2)
64    %define XVID_CPU_SSE2     (1<< 3)
65    %define XVID_CPU_SSE3     (1<< 8)
66    %define XVID_CPU_3DNOW    (1<< 4)
67    %define XVID_CPU_3DNOWEXT (1<< 5)
68    %define XVID_CPU_TSC      (1<< 6)
69    
70    ;=============================================================================
71    ; Read only data
72    ;=============================================================================
73    
74  %macro  CHECK_FEATURE         3  ALIGN 32
75    %ifdef FORMAT_COFF
76    SECTION .rodata
77    %else
78    SECTION .rodata align=16
79    %endif
80    
81      mov     ecx, %1  vendorAMD:
82      and     ecx, edx                  db "AuthenticAMD"
     neg     ecx  
     sbb     ecx, ecx  
     and     ecx, %2  
     or      [%3], ecx  
83    
84    ;=============================================================================
85    ; Macros
86    ;=============================================================================
87    
88    %macro  CHECK_FEATURE         4
89      mov eax, %1
90      and eax, %4
91      neg eax
92      sbb eax, eax
93      and eax, %2
94      or %3, eax
95  %endmacro  %endmacro
96    
97  section .text  ;=============================================================================
98    ; Code
99    ;=============================================================================
100    
101    SECTION .text
102    
103  ; int check_cpu_feature(void)  ; int check_cpu_feature(void)
104    
105  cglobal check_cpu_features  cglobal check_cpu_features
106  check_cpu_features:  check_cpu_features:
107    
108          pushad    push ebx
109          pushfd    push esi
110      push edi
111      push ebp
112    
113      sub esp, 12             ; Stack space for vendor name
114    
115      xor ebp, ebp
116    
117          ; CPUID command ?          ; CPUID command ?
118      pushfd
119          pop             eax          pop             eax
120          mov             ecx, eax          mov             ecx, eax
121          xor             eax, 0x200000          xor             eax, 0x200000
# Line 120  Line 131 
131          ; get vendor string, used later          ; get vendor string, used later
132      xor     eax, eax      xor     eax, eax
133      cpuid      cpuid
134      mov     [vendor], ebx       ; vendor string    mov [esp], ebx       ; vendor string
135      mov     [vendor+4], edx    mov [esp+4], edx
136      mov     [vendor+8], ecx    mov [esp+8], ecx
137      test    eax, eax      test    eax, eax
138    
139      jz      near .cpu_quit      jz      near .cpu_quit
# Line 130  Line 141 
141      mov     eax, 1      mov     eax, 1
142      cpuid      cpuid
143    
   
144      ; RDTSC command ?      ; RDTSC command ?
145          CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, features    CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, ebp, edx
146    
147      ; MMX support ?      ; MMX support ?
148          CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, features    CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, ebp, edx
149    
150      ; SSE support ?      ; SSE support ?
151          CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT+XVID_CPU_SSE), features    CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT|XVID_CPU_SSE), ebp, edx
152    
153          ; SSE2 support?          ; SSE2 support?
154          CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, features    CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, ebp, edx
155    
156      ; SSE3 support?
157      CHECK_FEATURE CPUID_SSE3, XVID_CPU_SSE3, ebp, ecx
158    
159          ; extended functions?          ; extended functions?
160      mov     eax, 0x80000000      mov     eax, 0x80000000
# Line 153  Line 165 
165      mov     eax, 0x80000001      mov     eax, 0x80000001
166      cpuid      cpuid
167    
     ; 3DNow! support ?  
         CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, features  
   
168          ; AMD cpu ?          ; AMD cpu ?
169      lea     esi, [vendorAMD]      lea     esi, [vendorAMD]
170      lea     edi, [vendor]    lea edi, [esp]
171      mov     ecx, 12      mov     ecx, 12
172      cld      cld
173      repe    cmpsb      repe    cmpsb
174      jnz     .cpu_quit      jnz     .cpu_quit
175    
176      ; 3DNow! support ?
177      CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, ebp, edx
178    
179          ; 3DNOW extended ?          ; 3DNOW extended ?
180          CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, features    CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, ebp, edx
181    
182          ; extended MMX ?          ; extended MMX ?
183          CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, features    CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, ebp, edx
184    
185  .cpu_quit:  .cpu_quit:
186    
187          popad    mov eax, ebp
188    
189      add esp, 12
190    
191          mov eax, [features]    pop ebp
192      pop edi
193      pop esi
194      pop ebx
195    
196          ret          ret
197    .endfunc
198    
199    ; sse/sse2 operating support detection routines
200    ; these will trigger an invalid instruction signal if not supported.
201    ALIGN 16
202    cglobal sse_os_trigger
203    sse_os_trigger:
204      xorps xmm0, xmm0
205      ret
206    .endfunc
207    
208    
209    ALIGN 16
210    cglobal sse2_os_trigger
211    sse2_os_trigger:
212      xorpd xmm0, xmm0
213      ret
214    .endfunc
215    
216    
217    ; enter/exit mmx state
218    ALIGN 16
219    cglobal emms_mmx
220    emms_mmx:
221      emms
222      ret
223    .endfunc
224    
225    ; faster enter/exit mmx state
226    ALIGN 16
227    cglobal emms_3dn
228    emms_3dn:
229      femms
230      ret
231    .endfunc
232    
233    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.11

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4