[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.9, Sun Aug 29 10:02:38 2004 UTC revision 1.15, Wed Nov 26 01:04:34 2008 UTC
# Line 3  Line 3 
3  ; *  XVID MPEG-4 VIDEO CODEC  ; *  XVID MPEG-4 VIDEO CODEC
4  ; *  - CPUID check processors capabilities -  ; *  - CPUID check processors capabilities -
5  ; *  ; *
6  ; *  Copyright (C) 2001 Michael Militzer <isibaar@xvid.org>  ; *  Copyright (C) 2001-2008 Michael Militzer <michael@xvid.org>
7  ; *  ; *
8  ; *  This program is free software ; you can redistribute it and/or modify  ; *  This program is free software ; you can redistribute it and/or modify
9  ; *  it under the terms of the GNU General Public License as published by  ; *  it under the terms of the GNU General Public License as published by
# Line 23  Line 23 
23  ; *  ; *
24  ; ***************************************************************************/  ; ***************************************************************************/
25    
26  BITS 32  %include "nasm.inc"
   
 %macro cglobal 1  
         %ifdef PREFIX  
                 %ifdef MARK_FUNCS  
                         global _%1:function %1.endfunc-%1  
                         %define %1 _%1:function %1.endfunc-%1  
                 %else  
                         global _%1  
                         %define %1 _%1  
                 %endif  
         %else  
                 %ifdef MARK_FUNCS  
                         global %1:function %1.endfunc-%1  
                 %else  
                         global %1  
                 %endif  
         %endif  
 %endmacro  
27    
28  ;=============================================================================  ;=============================================================================
29  ; Constants  ; Constants
# Line 51  Line 33 
33  %define CPUID_MMX               0x00800000  %define CPUID_MMX               0x00800000
34  %define CPUID_SSE               0x02000000  %define CPUID_SSE               0x02000000
35  %define CPUID_SSE2              0x04000000  %define CPUID_SSE2              0x04000000
36    %define CPUID_SSE3              0x00000001
37    %define CPUID_SSE41             0x00080000
38    
39  %define EXT_CPUID_3DNOW         0x80000000  %define EXT_CPUID_3DNOW         0x80000000
40  %define EXT_CPUID_AMD_3DNOWEXT  0x40000000  %define EXT_CPUID_AMD_3DNOWEXT  0x40000000
# Line 61  Line 45 
45  %define XVID_CPU_MMXEXT   (1<< 1)  %define XVID_CPU_MMXEXT   (1<< 1)
46  %define XVID_CPU_SSE      (1<< 2)  %define XVID_CPU_SSE      (1<< 2)
47  %define XVID_CPU_SSE2     (1<< 3)  %define XVID_CPU_SSE2     (1<< 3)
48    %define XVID_CPU_SSE3     (1<< 8)
49    %define XVID_CPU_SSE41    (1<< 9)
50  %define XVID_CPU_3DNOW    (1<< 4)  %define XVID_CPU_3DNOW    (1<< 4)
51  %define XVID_CPU_3DNOWEXT (1<< 5)  %define XVID_CPU_3DNOWEXT (1<< 5)
52  %define XVID_CPU_TSC      (1<< 6)  %define XVID_CPU_TSC      (1<< 6)
# Line 69  Line 55 
55  ; Read only data  ; Read only data
56  ;=============================================================================  ;=============================================================================
57    
58  ALIGN 32  ALIGN SECTION_ALIGN
59  %ifdef FORMAT_COFF  
60  SECTION .rodata  DATA
 %else  
 SECTION .rodata align=16  
 %endif  
61    
62  vendorAMD:  vendorAMD:
63                  db "AuthenticAMD"                  db "AuthenticAMD"
# Line 83  Line 66 
66  ; Macros  ; Macros
67  ;=============================================================================  ;=============================================================================
68    
69  %macro  CHECK_FEATURE         3  %macro  CHECK_FEATURE         4
70    mov ecx, %1    mov eax, %1
71    and ecx, edx    and eax, %4
72    neg ecx    neg eax
73    sbb ecx, ecx    sbb eax, eax
74    and ecx, %2    and eax, %2
75    or %3, ecx    or %3, eax
76  %endmacro  %endmacro
77    
78  ;=============================================================================  ;=============================================================================
79  ; Code  ; Code
80  ;=============================================================================  ;=============================================================================
81    
82  SECTION .text  %ifdef ARCH_IS_X86_64
83    %define XVID_PUSHFD pushfq
84    %define XVID_POPFD  popfq
85    %else
86    %define XVID_PUSHFD pushfd
87    %define XVID_POPFD  popfd
88    %endif
89    
90    SECTION .rotext align=SECTION_ALIGN
91    
92  ; int check_cpu_feature(void)  ; int check_cpu_feature(void)
93    
94  cglobal check_cpu_features  cglobal check_cpu_features
95  check_cpu_features:  check_cpu_features:
96    
97    push ebx    push _EBX
98    push esi    push _ESI
99    push edi    push _EDI
100    push ebp    push _EBP
101    
102    sub esp, 12             ; Stack space for vendor name    sub _ESP, 12             ; Stack space for vendor name
103    
104    xor ebp, ebp    xor ebp, ebp
105    
106          ; CPUID command ?          ; CPUID command ?
107    pushfd    XVID_PUSHFD
108    pop eax    pop _EAX
109    mov ecx, eax    mov ecx, eax
110    xor eax, 0x200000    xor eax, 0x200000
111    push eax    push _EAX
112    popfd    XVID_POPFD
113    pushfd    XVID_PUSHFD
114    pop eax    pop _EAX
115    cmp eax, ecx    cmp eax, ecx
116    
117    jz near .cpu_quit             ; no CPUID command -> exit    jz near .cpu_quit             ; no CPUID command -> exit
118    
   
119          ; get vendor string, used later          ; get vendor string, used later
120    xor eax, eax    xor eax, eax
121    cpuid    cpuid
122    mov [esp], ebx       ; vendor string    mov [_ESP], ebx        ; vendor string
123    mov [esp+4], edx    mov [_ESP+4], edx
124    mov [esp+8], ecx    mov [_ESP+8], ecx
125    test eax, eax    test eax, eax
126    
127    jz near .cpu_quit    jz near .cpu_quit
# Line 140  Line 130 
130    cpuid    cpuid
131    
132   ; RDTSC command ?   ; RDTSC command ?
133    CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, ebp    CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, ebp, edx
134    
135    ; MMX support ?    ; MMX support ?
136    CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, ebp    CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, ebp, edx
137    
138    ; SSE support ?    ; SSE support ?
139    CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT|XVID_CPU_SSE), ebp    CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT|XVID_CPU_SSE), ebp, edx
140    
141    ; SSE2 support?    ; SSE2 support?
142    CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, ebp    CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, ebp, edx
143    
144      ; SSE3 support?
145      CHECK_FEATURE CPUID_SSE3, XVID_CPU_SSE3, ebp, ecx
146    
147      ; SSE41 support?
148      CHECK_FEATURE CPUID_SSE41, XVID_CPU_SSE41, ebp, ecx
149    
150    ; extended functions?    ; extended functions?
151    mov eax, 0x80000000    mov eax, 0x80000000
# Line 161  Line 157 
157    cpuid    cpuid
158    
159   ; AMD cpu ?   ; AMD cpu ?
160    lea esi, [vendorAMD]    lea _ESI, [vendorAMD]
161    lea edi, [esp]    lea _EDI, [_ESP]
162    mov ecx, 12    mov ecx, 12
163    cld    cld
164    repe cmpsb    repe cmpsb
165    jnz .cpu_quit    jnz .cpu_quit
166    
167    ; 3DNow! support ?    ; 3DNow! support ?
168    CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, ebp    CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, ebp, edx
169    
170    ; 3DNOW extended ?    ; 3DNOW extended ?
171    CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, ebp    CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, ebp, edx
172    
173    ; extended MMX ?    ; extended MMX ?
174    CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, ebp    CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, ebp, edx
175    
176  .cpu_quit:  .cpu_quit:
177    
178    mov eax, ebp    mov eax, ebp
179    
180    add esp, 12    add _ESP, 12
181    
182    pop ebp    pop _EBP
183    pop edi    pop _EDI
184    pop esi    pop _ESI
185    pop ebx    pop _EBX
186    
187    ret    ret
188  .endfunc  ENDFUNC
189    
190  ; sse/sse2 operating support detection routines  ; sse/sse2 operating support detection routines
191  ; these will trigger an invalid instruction signal if not supported.  ; these will trigger an invalid instruction signal if not supported.
192  ALIGN 16  ALIGN SECTION_ALIGN
193  cglobal sse_os_trigger  cglobal sse_os_trigger
194  sse_os_trigger:  sse_os_trigger:
195    xorps xmm0, xmm0    xorps xmm0, xmm0
196    ret    ret
197  .endfunc  ENDFUNC
198    
199    
200  ALIGN 16  ALIGN SECTION_ALIGN
201  cglobal sse2_os_trigger  cglobal sse2_os_trigger
202  sse2_os_trigger:  sse2_os_trigger:
203    xorpd xmm0, xmm0    xorpd xmm0, xmm0
204    ret    ret
205  .endfunc  ENDFUNC
206    
207    
208  ; enter/exit mmx state  ; enter/exit mmx state
209  ALIGN 16  ALIGN SECTION_ALIGN
210  cglobal emms_mmx  cglobal emms_mmx
211  emms_mmx:  emms_mmx:
212    emms    emms
213    ret    ret
214  .endfunc  ENDFUNC
215    
216  ; faster enter/exit mmx state  ; faster enter/exit mmx state
217  ALIGN 16  ALIGN SECTION_ALIGN
218  cglobal emms_3dn  cglobal emms_3dn
219  emms_3dn:  emms_3dn:
220    femms    femms
221    ret    ret
222  .endfunc  ENDFUNC
223    
224    
225    
226    %ifidn __OUTPUT_FORMAT__,elf
227    section ".note.GNU-stack" noalloc noexec nowrite progbits
228    %endif
229    

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.15

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