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