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

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