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

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