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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (view) (download)

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

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