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

Annotation of /trunk/xvidcore/src/utils/x86_asm/cpuid.asm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1764 - (view) (download)

1 : edgomez 1382 ;/****************************************************************************
2 :     ; *
3 :     ; * XVID MPEG-4 VIDEO CODEC
4 :     ; * - CPUID check processors capabilities -
5 :     ; *
6 :     ; * Copyright (C) 2001 Michael Militzer <isibaar@xvid.org>
7 :     ; *
8 :     ; * 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
10 :     ; * the Free Software Foundation ; either version 2 of the License, or
11 :     ; * (at your option) any later version.
12 :     ; *
13 :     ; * This program is distributed in the hope that it will be useful,
14 :     ; * but WITHOUT ANY WARRANTY ; without even the implied warranty of
15 :     ; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 :     ; * GNU General Public License for more details.
17 :     ; *
18 :     ; * You should have received a copy of the GNU General Public License
19 :     ; * along with this program ; if not, write to the Free Software
20 :     ; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 :     ; *
22 : Isibaar 1764 ; * $Id: cpuid.asm,v 1.10 2006-12-06 19:55:07 Isibaar Exp $
23 : edgomez 1382 ; *
24 :     ; ***************************************************************************/
25 : Isibaar 3
26 : edgomez 1382 BITS 32
27 : Isibaar 3
28 : suxen_drol 309 %macro cglobal 1
29 : Isibaar 3 %ifdef PREFIX
30 : edgomez 1535 %ifdef MARK_FUNCS
31 : edgomez 1540 global _%1:function %1.endfunc-%1
32 :     %define %1 _%1:function %1.endfunc-%1
33 : edgomez 1535 %else
34 :     global _%1
35 :     %define %1 _%1
36 :     %endif
37 : Isibaar 3 %else
38 : edgomez 1535 %ifdef MARK_FUNCS
39 : edgomez 1540 global %1:function %1.endfunc-%1
40 : edgomez 1535 %else
41 :     global %1
42 :     %endif
43 : Isibaar 3 %endif
44 :     %endmacro
45 :    
46 : edgomez 1382 ;=============================================================================
47 :     ; Constants
48 :     ;=============================================================================
49 : Isibaar 3
50 : edgomez 1382 %define CPUID_TSC 0x00000010
51 :     %define CPUID_MMX 0x00800000
52 :     %define CPUID_SSE 0x02000000
53 :     %define CPUID_SSE2 0x04000000
54 : Isibaar 1764 %define CPUID_SSE3 0x00000001
55 : Isibaar 3
56 : edgomez 1382 %define EXT_CPUID_3DNOW 0x80000000
57 :     %define EXT_CPUID_AMD_3DNOWEXT 0x40000000
58 :     %define EXT_CPUID_AMD_MMXEXT 0x00400000
59 : Isibaar 3
60 : edgomez 1382 ;;; NB: Make sure these defines match the ones defined in xvid.h
61 :     %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 : Isibaar 1764 %define XVID_CPU_SSE3 (1<< 8)
66 : edgomez 1382 %define XVID_CPU_3DNOW (1<< 4)
67 :     %define XVID_CPU_3DNOWEXT (1<< 5)
68 :     %define XVID_CPU_TSC (1<< 6)
69 : Isibaar 3
70 : edgomez 1382 ;=============================================================================
71 :     ; Read only data
72 :     ;=============================================================================
73 : Isibaar 3
74 : edgomez 1382 ALIGN 32
75 :     %ifdef FORMAT_COFF
76 : edgomez 1519 SECTION .rodata
77 : edgomez 1382 %else
78 : edgomez 1519 SECTION .rodata align=16
79 : edgomez 1382 %endif
80 :    
81 :     vendorAMD:
82 :     db "AuthenticAMD"
83 :    
84 :     ;=============================================================================
85 :     ; Macros
86 :     ;=============================================================================
87 :    
88 :     %macro CHECK_FEATURE 3
89 :     mov ecx, %1
90 :     and ecx, edx
91 :     neg ecx
92 :     sbb ecx, ecx
93 :     and ecx, %2
94 :     or %3, ecx
95 : Isibaar 3 %endmacro
96 :    
97 : edgomez 1382 ;=============================================================================
98 :     ; Code
99 :     ;=============================================================================
100 : Isibaar 3
101 : edgomez 1382 SECTION .text
102 :    
103 : Isibaar 3 ; int check_cpu_feature(void)
104 :    
105 :     cglobal check_cpu_features
106 :     check_cpu_features:
107 :    
108 : edgomez 1382 push ebx
109 :     push esi
110 :     push edi
111 :     push ebp
112 : suxen_drol 309
113 : edgomez 1485 sub esp, 12 ; Stack space for vendor name
114 :    
115 : edgomez 1382 xor ebp, ebp
116 : suxen_drol 309
117 : Isibaar 3 ; CPUID command ?
118 : edgomez 1382 pushfd
119 :     pop eax
120 :     mov ecx, eax
121 :     xor eax, 0x200000
122 :     push eax
123 :     popfd
124 :     pushfd
125 :     pop eax
126 :     cmp eax, ecx
127 : Isibaar 3
128 : edgomez 1382 jz near .cpu_quit ; no CPUID command -> exit
129 : Isibaar 3
130 :    
131 :     ; get vendor string, used later
132 : edgomez 1382 xor eax, eax
133 :     cpuid
134 : edgomez 1485 mov [esp], ebx ; vendor string
135 :     mov [esp+4], edx
136 :     mov [esp+8], ecx
137 : edgomez 1382 test eax, eax
138 : Isibaar 3
139 : edgomez 1382 jz near .cpu_quit
140 : Isibaar 3
141 : edgomez 1382 mov eax, 1
142 :     cpuid
143 : Isibaar 3
144 : edgomez 1382 ; RDTSC command ?
145 :     CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, ebp
146 : Isibaar 3
147 : edgomez 1382 ; MMX support ?
148 :     CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, ebp
149 : Isibaar 3
150 : edgomez 1382 ; SSE support ?
151 :     CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT|XVID_CPU_SSE), ebp
152 : Isibaar 3
153 : edgomez 1382 ; SSE2 support?
154 :     CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, ebp
155 : Isibaar 3
156 : Isibaar 1764 ; SSE3 support?
157 :     CHECK_FEATURE CPUID_SSE3, XVID_CPU_SSE3, ebp
158 :    
159 : edgomez 1382 ; extended functions?
160 :     mov eax, 0x80000000
161 :     cpuid
162 :     cmp eax, 0x80000000
163 :     jbe near .cpu_quit
164 : Isibaar 3
165 : edgomez 1382 mov eax, 0x80000001
166 :     cpuid
167 : Isibaar 3
168 : edgomez 1382 ; AMD cpu ?
169 :     lea esi, [vendorAMD]
170 : edgomez 1485 lea edi, [esp]
171 : edgomez 1382 mov ecx, 12
172 :     cld
173 :     repe cmpsb
174 :     jnz .cpu_quit
175 : Isibaar 3
176 : edgomez 1382 ; 3DNow! support ?
177 :     CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, ebp
178 : suxen_drol 309
179 : edgomez 1382 ; 3DNOW extended ?
180 :     CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, ebp
181 : Isibaar 3
182 : edgomez 1382 ; extended MMX ?
183 :     CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, ebp
184 : Isibaar 3
185 : suxen_drol 309 .cpu_quit:
186 :    
187 : edgomez 1382 mov eax, ebp
188 : suxen_drol 309
189 : edgomez 1485 add esp, 12
190 :    
191 : edgomez 1382 pop ebp
192 :     pop edi
193 :     pop esi
194 :     pop ebx
195 : suxen_drol 309
196 : edgomez 1382 ret
197 : edgomez 1540 .endfunc
198 : suxen_drol 309
199 :     ; sse/sse2 operating support detection routines
200 :     ; these will trigger an invalid instruction signal if not supported.
201 : edgomez 1382 ALIGN 16
202 : suxen_drol 309 cglobal sse_os_trigger
203 :     sse_os_trigger:
204 : edgomez 1382 xorps xmm0, xmm0
205 :     ret
206 : edgomez 1540 .endfunc
207 : suxen_drol 309
208 :    
209 : edgomez 1382 ALIGN 16
210 : suxen_drol 309 cglobal sse2_os_trigger
211 :     sse2_os_trigger:
212 : edgomez 1382 xorpd xmm0, xmm0
213 :     ret
214 : edgomez 1540 .endfunc
215 : suxen_drol 309
216 : edgomez 851
217 :     ; enter/exit mmx state
218 : edgomez 1382 ALIGN 16
219 : edgomez 851 cglobal emms_mmx
220 :     emms_mmx:
221 : edgomez 1382 emms
222 :     ret
223 : edgomez 1540 .endfunc
224 : edgomez 851
225 :     ; faster enter/exit mmx state
226 : edgomez 1382 ALIGN 16
227 : edgomez 851 cglobal emms_3dn
228 :     emms_3dn:
229 : edgomez 1382 femms
230 :     ret
231 : edgomez 1540 .endfunc
232 :    
233 :    

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