[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 1793 - (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 1793 ; * $Id: cpuid.asm,v 1.13 2008-11-11 20:46:24 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 : Isibaar 1793 %define ENDFUNC .endfunc
34 : edgomez 1535 %else
35 :     global _%1
36 :     %define %1 _%1
37 : Isibaar 1793 %define ENDFUNC
38 : edgomez 1535 %endif
39 : Isibaar 3 %else
40 : edgomez 1535 %ifdef MARK_FUNCS
41 : edgomez 1540 global %1:function %1.endfunc-%1
42 : Isibaar 1793 %define ENDFUNC .endfunc
43 : edgomez 1535 %else
44 :     global %1
45 : Isibaar 1793 %define ENDFUNC
46 : edgomez 1535 %endif
47 : Isibaar 3 %endif
48 :     %endmacro
49 :    
50 : edgomez 1382 ;=============================================================================
51 :     ; Constants
52 :     ;=============================================================================
53 : Isibaar 3
54 : edgomez 1382 %define CPUID_TSC 0x00000010
55 :     %define CPUID_MMX 0x00800000
56 :     %define CPUID_SSE 0x02000000
57 :     %define CPUID_SSE2 0x04000000
58 : Isibaar 1764 %define CPUID_SSE3 0x00000001
59 : Isibaar 3
60 : edgomez 1382 %define EXT_CPUID_3DNOW 0x80000000
61 :     %define EXT_CPUID_AMD_3DNOWEXT 0x40000000
62 :     %define EXT_CPUID_AMD_MMXEXT 0x00400000
63 : Isibaar 3
64 : edgomez 1382 ;;; NB: Make sure these defines match the ones defined in xvid.h
65 :     %define XVID_CPU_MMX (1<< 0)
66 :     %define XVID_CPU_MMXEXT (1<< 1)
67 :     %define XVID_CPU_SSE (1<< 2)
68 :     %define XVID_CPU_SSE2 (1<< 3)
69 : Isibaar 1764 %define XVID_CPU_SSE3 (1<< 8)
70 : edgomez 1382 %define XVID_CPU_3DNOW (1<< 4)
71 :     %define XVID_CPU_3DNOWEXT (1<< 5)
72 :     %define XVID_CPU_TSC (1<< 6)
73 : Isibaar 3
74 : edgomez 1382 ;=============================================================================
75 :     ; Read only data
76 :     ;=============================================================================
77 : Isibaar 3
78 : edgomez 1382 ALIGN 32
79 :     %ifdef FORMAT_COFF
80 : edgomez 1519 SECTION .rodata
81 : edgomez 1382 %else
82 : edgomez 1519 SECTION .rodata align=16
83 : edgomez 1382 %endif
84 :    
85 :     vendorAMD:
86 :     db "AuthenticAMD"
87 :    
88 :     ;=============================================================================
89 :     ; Macros
90 :     ;=============================================================================
91 :    
92 : Isibaar 1771 %macro CHECK_FEATURE 4
93 :     mov eax, %1
94 :     and eax, %4
95 :     neg eax
96 :     sbb eax, eax
97 :     and eax, %2
98 :     or %3, eax
99 : Isibaar 3 %endmacro
100 :    
101 : edgomez 1382 ;=============================================================================
102 :     ; Code
103 :     ;=============================================================================
104 : Isibaar 3
105 : edgomez 1382 SECTION .text
106 :    
107 : Isibaar 3 ; int check_cpu_feature(void)
108 :    
109 :     cglobal check_cpu_features
110 :     check_cpu_features:
111 :    
112 : edgomez 1382 push ebx
113 :     push esi
114 :     push edi
115 :     push ebp
116 : suxen_drol 309
117 : edgomez 1485 sub esp, 12 ; Stack space for vendor name
118 :    
119 : edgomez 1382 xor ebp, ebp
120 : suxen_drol 309
121 : Isibaar 3 ; CPUID command ?
122 : edgomez 1382 pushfd
123 :     pop eax
124 :     mov ecx, eax
125 :     xor eax, 0x200000
126 :     push eax
127 :     popfd
128 :     pushfd
129 :     pop eax
130 :     cmp eax, ecx
131 : Isibaar 3
132 : edgomez 1382 jz near .cpu_quit ; no CPUID command -> exit
133 : Isibaar 3
134 :    
135 :     ; get vendor string, used later
136 : edgomez 1382 xor eax, eax
137 :     cpuid
138 : edgomez 1485 mov [esp], ebx ; vendor string
139 :     mov [esp+4], edx
140 :     mov [esp+8], ecx
141 : edgomez 1382 test eax, eax
142 : Isibaar 3
143 : edgomez 1382 jz near .cpu_quit
144 : Isibaar 3
145 : edgomez 1382 mov eax, 1
146 :     cpuid
147 : Isibaar 3
148 : edgomez 1382 ; RDTSC command ?
149 : Isibaar 1771 CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, ebp, edx
150 : Isibaar 3
151 : edgomez 1382 ; MMX support ?
152 : Isibaar 1771 CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, ebp, edx
153 : Isibaar 3
154 : edgomez 1382 ; SSE support ?
155 : Isibaar 1771 CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT|XVID_CPU_SSE), ebp, edx
156 : Isibaar 3
157 : edgomez 1382 ; SSE2 support?
158 : Isibaar 1771 CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, ebp, edx
159 : Isibaar 3
160 : Isibaar 1764 ; SSE3 support?
161 : Isibaar 1771 CHECK_FEATURE CPUID_SSE3, XVID_CPU_SSE3, ebp, ecx
162 : Isibaar 1764
163 : edgomez 1382 ; extended functions?
164 :     mov eax, 0x80000000
165 :     cpuid
166 :     cmp eax, 0x80000000
167 :     jbe near .cpu_quit
168 : Isibaar 3
169 : edgomez 1382 mov eax, 0x80000001
170 :     cpuid
171 : Isibaar 3
172 : edgomez 1382 ; AMD cpu ?
173 :     lea esi, [vendorAMD]
174 : edgomez 1485 lea edi, [esp]
175 : edgomez 1382 mov ecx, 12
176 :     cld
177 :     repe cmpsb
178 :     jnz .cpu_quit
179 : Isibaar 3
180 : edgomez 1382 ; 3DNow! support ?
181 : Isibaar 1771 CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, ebp, edx
182 : suxen_drol 309
183 : edgomez 1382 ; 3DNOW extended ?
184 : Isibaar 1771 CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, ebp, edx
185 : Isibaar 3
186 : edgomez 1382 ; extended MMX ?
187 : Isibaar 1771 CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, ebp, edx
188 : Isibaar 3
189 : suxen_drol 309 .cpu_quit:
190 :    
191 : edgomez 1382 mov eax, ebp
192 : suxen_drol 309
193 : edgomez 1485 add esp, 12
194 :    
195 : edgomez 1382 pop ebp
196 :     pop edi
197 :     pop esi
198 :     pop ebx
199 : suxen_drol 309
200 : edgomez 1382 ret
201 : Isibaar 1793 ENDFUNC
202 : suxen_drol 309
203 :     ; sse/sse2 operating support detection routines
204 :     ; these will trigger an invalid instruction signal if not supported.
205 : edgomez 1382 ALIGN 16
206 : suxen_drol 309 cglobal sse_os_trigger
207 :     sse_os_trigger:
208 : edgomez 1382 xorps xmm0, xmm0
209 :     ret
210 : Isibaar 1793 ENDFUNC
211 : suxen_drol 309
212 :    
213 : edgomez 1382 ALIGN 16
214 : suxen_drol 309 cglobal sse2_os_trigger
215 :     sse2_os_trigger:
216 : edgomez 1382 xorpd xmm0, xmm0
217 :     ret
218 : Isibaar 1793 ENDFUNC
219 : suxen_drol 309
220 : edgomez 851
221 :     ; enter/exit mmx state
222 : edgomez 1382 ALIGN 16
223 : edgomez 851 cglobal emms_mmx
224 :     emms_mmx:
225 : edgomez 1382 emms
226 :     ret
227 : Isibaar 1793 ENDFUNC
228 : edgomez 851
229 :     ; faster enter/exit mmx state
230 : edgomez 1382 ALIGN 16
231 : edgomez 851 cglobal emms_3dn
232 :     emms_3dn:
233 : edgomez 1382 femms
234 :     ret
235 : Isibaar 1793 ENDFUNC
236 : edgomez 1540
237 :    
238 : Isibaar 1790
239 :     %ifidn __OUTPUT_FORMAT__,elf
240 :     section ".note.GNU-stack" noalloc noexec nowrite progbits
241 :     %endif
242 :    

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