[svn] / branches / dev-api-4 / xvidcore / src / utils / x86_asm / cpuid.asm Repository:
ViewVC logotype

Annotation of /branches/dev-api-4/xvidcore/src/utils/x86_asm/cpuid.asm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1176 - (view) (download)

1 : Isibaar 3 ;/******************************************************************************
2 : edgomez 851 ; * *
3 :     ; * This file is part of XviD, a free MPEG-4 video encoder/decoder *
4 :     ; * *
5 :     ; * XviD is an implementation of a part of one or more MPEG-4 Video tools *
6 :     ; * as specified in ISO/IEC 14496-2 standard. Those intending to use this *
7 :     ; * software module in hardware or software products are advised that its *
8 :     ; * use may infringe existing patents or copyrights, and any such use *
9 :     ; * would be at such party's own risk. The original developer of this *
10 :     ; * software module and his/her company, and subsequent editors and their *
11 :     ; * companies, will have no liability for use of this software or *
12 :     ; * modifications or derivatives thereof. *
13 :     ; * *
14 :     ; * XviD is free software; you can redistribute it and/or modify it *
15 :     ; * under the terms of the GNU General Public License as published by *
16 :     ; * the Free Software Foundation; either version 2 of the License, or *
17 :     ; * (at your option) any later version. *
18 :     ; * *
19 :     ; * XviD is distributed in the hope that it will be useful, but *
20 :     ; * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 :     ; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 :     ; * GNU General Public License for more details. *
23 :     ; * *
24 :     ; * You should have received a copy of the GNU General Public License *
25 :     ; * along with this program; if not, write to the Free Software *
26 :     ; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
27 :     ; * *
28 : Isibaar 3 ; ******************************************************************************/
29 : edgomez 851 ;
30 :     ;/******************************************************************************
31 :     ; * *
32 :     ; * cpuid.asm, check cpu features *
33 :     ; * *
34 :     ; * Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org>, *
35 :     ; * *
36 :     ; * For more information visit the XviD homepage: http://www.xvid.org *
37 :     ; * *
38 :     ; ******************************************************************************/
39 :     ;
40 :     ;/******************************************************************************
41 :     ; * *
42 :     ; * Revision history: *
43 :     ; * *
44 :     ; * 17.12.2001 initial version (Isibaar) *
45 :     ; * *
46 :     ; ******************************************************************************/
47 : Isibaar 3
48 :     bits 32
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 : edgomez 1176 %define XVID_CPU_MMX (1<< 0)
60 :     %define XVID_CPU_MMXEXT (1<< 1)
61 :     %define XVID_CPU_SSE (1<< 2)
62 :     %define XVID_CPU_SSE2 (1<< 3)
63 :     %define XVID_CPU_3DNOW (1<< 4)
64 :     %define XVID_CPU_3DNOWEXT (1<< 5)
65 :     %define XVID_CPU_TSC (1<< 6)
66 : Isibaar 3
67 : suxen_drol 309 %macro cglobal 1
68 : Isibaar 3 %ifdef PREFIX
69 : suxen_drol 309 global _%1
70 : Isibaar 3 %define %1 _%1
71 :     %else
72 :     global %1
73 :     %endif
74 :     %endmacro
75 :    
76 :     ALIGN 32
77 :    
78 :     section .data
79 :    
80 :     vendorAMD db "AuthenticAMD"
81 :    
82 :     %macro CHECK_FEATURE 3
83 :    
84 :     mov ecx, %1
85 :     and ecx, edx
86 :     neg ecx
87 :     sbb ecx, ecx
88 :     and ecx, %2
89 : suxen_drol 309 or %3, ecx
90 : Isibaar 3
91 :     %endmacro
92 :    
93 :     section .text
94 :    
95 :     ; int check_cpu_feature(void)
96 :    
97 :     cglobal check_cpu_features
98 :     check_cpu_features:
99 :    
100 : suxen_drol 309 push ebx
101 :     push esi
102 :     push edi
103 :     push ebp
104 :    
105 :     xor ebp,ebp
106 :    
107 : Isibaar 3 ; CPUID command ?
108 : suxen_drol 309 pushfd
109 : Isibaar 3 pop eax
110 :     mov ecx, eax
111 :     xor eax, 0x200000
112 :     push eax
113 :     popfd
114 :     pushfd
115 :     pop eax
116 :     cmp eax, ecx
117 :    
118 :     jz near .cpu_quit ; no CPUID command -> exit
119 :    
120 :    
121 :     ; get vendor string, used later
122 :     xor eax, eax
123 : suxen_drol 309 cpuid
124 :     mov [esp-12], ebx ; vendor string
125 :     mov [esp-12+4], edx
126 :     mov [esp-12+8], ecx
127 : Isibaar 3 test eax, eax
128 :    
129 :     jz near .cpu_quit
130 :    
131 : suxen_drol 309 mov eax, 1
132 : Isibaar 3 cpuid
133 :    
134 :     ; RDTSC command ?
135 : suxen_drol 309 CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, ebp
136 : Isibaar 3
137 :     ; MMX support ?
138 : suxen_drol 309 CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, ebp
139 : Isibaar 3
140 :     ; SSE support ?
141 : suxen_drol 309 CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT|XVID_CPU_SSE), ebp
142 : Isibaar 3
143 :     ; SSE2 support?
144 : suxen_drol 309 CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, ebp
145 : Isibaar 3
146 :     ; extended functions?
147 :     mov eax, 0x80000000
148 :     cpuid
149 :     cmp eax, 0x80000000
150 :     jbe near .cpu_quit
151 :    
152 :     mov eax, 0x80000001
153 :     cpuid
154 :    
155 :     ; AMD cpu ?
156 :     lea esi, [vendorAMD]
157 : suxen_drol 309 lea edi, [esp-12]
158 : Isibaar 3 mov ecx, 12
159 :     cld
160 :     repe cmpsb
161 :     jnz .cpu_quit
162 :    
163 : suxen_drol 309 ; 3DNow! support ?
164 :     CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, ebp
165 :    
166 : Isibaar 3 ; 3DNOW extended ?
167 : suxen_drol 309 CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, ebp
168 : Isibaar 3
169 :     ; extended MMX ?
170 : suxen_drol 309 CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, ebp
171 : Isibaar 3
172 : suxen_drol 309 .cpu_quit:
173 :    
174 :     mov eax, ebp
175 :    
176 :     pop ebp
177 :     pop edi
178 :     pop esi
179 :     pop ebx
180 :    
181 : Isibaar 3 ret
182 : suxen_drol 309
183 :    
184 :    
185 :     ; sse/sse2 operating support detection routines
186 :     ; these will trigger an invalid instruction signal if not supported.
187 :    
188 :     cglobal sse_os_trigger
189 :     align 16
190 :     sse_os_trigger:
191 :     xorps xmm0, xmm0
192 :     ret
193 :    
194 :    
195 :     cglobal sse2_os_trigger
196 :     align 16
197 :     sse2_os_trigger:
198 :     xorpd xmm0, xmm0
199 :     ret
200 :    
201 : edgomez 851
202 :     ; enter/exit mmx state
203 :    
204 :     cglobal emms_mmx
205 :     align 16
206 :     emms_mmx:
207 :     emms
208 :     ret
209 :    
210 :     ; faster enter/exit mmx state
211 :    
212 :     cglobal emms_3dn
213 :     align 16
214 :     emms_3dn:
215 :     femms
216 :     ret

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