1 |
;/****************************************************************************** |
;/**************************************************************************** |
2 |
; * |
; * |
3 |
; * Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org> |
; * XVID MPEG-4 VIDEO CODEC |
4 |
|
; * - CPUID check processors capabilities - |
5 |
; * |
; * |
6 |
; * This file is part of XviD, a free MPEG-4 video encoder/decoder |
; * Copyright (C) 2001 Michael Militzer <isibaar@xvid.org> |
7 |
; * |
; * |
8 |
; * XviD is free software; you can redistribute it and/or modify it |
; * This program is free software ; you can redistribute it and/or modify |
9 |
; * under the terms of the GNU General Public License as published by |
; * 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 |
; * the Free Software Foundation; either version 2 of the License, or |
11 |
; * (at your option) any later version. |
; * (at your option) any later version. |
12 |
; * |
; * |
19 |
; * along with this program; if not, write to the Free Software |
; * along with this program; if not, write to the Free Software |
20 |
; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
; * |
; * |
22 |
; * Under section 8 of the GNU General Public License, the copyright |
; * $Id: cpuid.asm,v 1.13 2008-11-11 20:46:24 Isibaar Exp $ |
|
; * holders of XVID explicitly forbid distribution in the following |
|
|
; * countries: |
|
|
; * |
|
|
; * - Japan |
|
|
; * - United States of America |
|
|
; * |
|
|
; * Linking XviD statically or dynamically with other modules is making a |
|
|
; * combined work based on XviD. Thus, the terms and conditions of the |
|
|
; * GNU General Public License cover the whole combination. |
|
|
; * |
|
|
; * As a special exception, the copyright holders of XviD give you |
|
|
; * permission to link XviD with independent modules that communicate with |
|
|
; * XviD solely through the VFW1.1 and DShow interfaces, regardless of the |
|
|
; * license terms of these independent modules, and to copy and distribute |
|
|
; * the resulting combined work under terms of your choice, provided that |
|
|
; * every copy of the combined work is accompanied by a complete copy of |
|
|
; * the source code of XviD (the version of XviD used to produce the |
|
|
; * combined work), being distributed under the terms of the GNU General |
|
|
; * Public License plus this exception. An independent module is a module |
|
|
; * which is not derived from or based on XviD. |
|
|
; * |
|
|
; * Note that people who make modified versions of XviD are not obligated |
|
|
; * to grant this special exception for their modified versions; it is |
|
|
; * their choice whether to do so. The GNU General Public License gives |
|
|
; * permission to release a modified version without this exception; this |
|
|
; * exception also makes it possible to release a modified version which |
|
|
; * carries forward this exception. |
|
23 |
; * |
; * |
24 |
; * $Id: cpuid.asm,v 1.3 2002-11-17 00:51:11 edgomez Exp $ |
; ***************************************************************************/ |
|
; ******************************************************************************/ |
|
|
|
|
|
bits 32 |
|
|
|
|
|
%define CPUID_TSC 0x00000010 |
|
|
%define CPUID_MMX 0x00800000 |
|
|
%define CPUID_SSE 0x02000000 |
|
|
%define CPUID_SSE2 0x04000000 |
|
|
|
|
|
%define EXT_CPUID_3DNOW 0x80000000 |
|
|
%define EXT_CPUID_AMD_3DNOWEXT 0x40000000 |
|
|
%define EXT_CPUID_AMD_MMXEXT 0x00400000 |
|
|
|
|
|
%define XVID_CPU_MMX 0x00000001 |
|
|
%define XVID_CPU_MMXEXT 0x00000002 |
|
|
%define XVID_CPU_SSE 0x00000004 |
|
|
%define XVID_CPU_SSE2 0x00000008 |
|
|
%define XVID_CPU_3DNOW 0x00000010 |
|
|
%define XVID_CPU_3DNOWEXT 0x00000020 |
|
|
%define XVID_CPU_TSC 0x00000040 |
|
25 |
|
|
26 |
|
BITS 32 |
27 |
|
|
28 |
%macro cglobal 1 |
%macro cglobal 1 |
29 |
%ifdef PREFIX |
%ifdef PREFIX |
30 |
|
%ifdef MARK_FUNCS |
31 |
|
global _%1:function %1.endfunc-%1 |
32 |
|
%define %1 _%1:function %1.endfunc-%1 |
33 |
|
%define ENDFUNC .endfunc |
34 |
|
%else |
35 |
global _%1 |
global _%1 |
36 |
%define %1 _%1 |
%define %1 _%1 |
37 |
|
%define ENDFUNC |
38 |
|
%endif |
39 |
|
%else |
40 |
|
%ifdef MARK_FUNCS |
41 |
|
global %1:function %1.endfunc-%1 |
42 |
|
%define ENDFUNC .endfunc |
43 |
%else |
%else |
44 |
global %1 |
global %1 |
45 |
|
%define ENDFUNC |
46 |
|
%endif |
47 |
%endif |
%endif |
48 |
%endmacro |
%endmacro |
49 |
|
|
50 |
ALIGN 32 |
;============================================================================= |
51 |
|
; Constants |
52 |
|
;============================================================================= |
53 |
|
|
54 |
section .data |
%define CPUID_TSC 0x00000010 |
55 |
|
%define CPUID_MMX 0x00800000 |
56 |
|
%define CPUID_SSE 0x02000000 |
57 |
|
%define CPUID_SSE2 0x04000000 |
58 |
|
%define CPUID_SSE3 0x00000001 |
59 |
|
|
60 |
vendorAMD db "AuthenticAMD" |
%define EXT_CPUID_3DNOW 0x80000000 |
61 |
|
%define EXT_CPUID_AMD_3DNOWEXT 0x40000000 |
62 |
|
%define EXT_CPUID_AMD_MMXEXT 0x00400000 |
63 |
|
|
64 |
|
;;; NB: Make sure these defines match the ones defined in xvid.h |
65 |
|
%define XVID_CPU_MMX (1<< 0) |
66 |
|
%define XVID_CPU_MMXEXT (1<< 1) |
67 |
|
%define XVID_CPU_SSE (1<< 2) |
68 |
|
%define XVID_CPU_SSE2 (1<< 3) |
69 |
|
%define XVID_CPU_SSE3 (1<< 8) |
70 |
|
%define XVID_CPU_3DNOW (1<< 4) |
71 |
|
%define XVID_CPU_3DNOWEXT (1<< 5) |
72 |
|
%define XVID_CPU_TSC (1<< 6) |
73 |
|
|
74 |
|
;============================================================================= |
75 |
|
; Read only data |
76 |
|
;============================================================================= |
77 |
|
|
78 |
%macro CHECK_FEATURE 3 |
ALIGN 32 |
79 |
|
%ifdef FORMAT_COFF |
80 |
|
SECTION .rodata |
81 |
|
%else |
82 |
|
SECTION .rodata align=16 |
83 |
|
%endif |
84 |
|
|
85 |
mov ecx, %1 |
vendorAMD: |
86 |
and ecx, edx |
db "AuthenticAMD" |
|
neg ecx |
|
|
sbb ecx, ecx |
|
|
and ecx, %2 |
|
|
or %3, ecx |
|
87 |
|
|
88 |
|
;============================================================================= |
89 |
|
; Macros |
90 |
|
;============================================================================= |
91 |
|
|
92 |
|
%macro CHECK_FEATURE 4 |
93 |
|
mov eax, %1 |
94 |
|
and eax, %4 |
95 |
|
neg eax |
96 |
|
sbb eax, eax |
97 |
|
and eax, %2 |
98 |
|
or %3, eax |
99 |
%endmacro |
%endmacro |
100 |
|
|
101 |
section .text |
;============================================================================= |
102 |
|
; Code |
103 |
|
;============================================================================= |
104 |
|
|
105 |
|
SECTION .text |
106 |
|
|
107 |
; int check_cpu_feature(void) |
; int check_cpu_feature(void) |
108 |
|
|
114 |
push edi |
push edi |
115 |
push ebp |
push ebp |
116 |
|
|
117 |
|
sub esp, 12 ; Stack space for vendor name |
118 |
|
|
119 |
xor ebp,ebp |
xor ebp,ebp |
120 |
|
|
121 |
; CPUID command ? |
; CPUID command ? |
135 |
; get vendor string, used later |
; get vendor string, used later |
136 |
xor eax, eax |
xor eax, eax |
137 |
cpuid |
cpuid |
138 |
mov [esp-12], ebx ; vendor string |
mov [esp], ebx ; vendor string |
139 |
mov [esp-12+4], edx |
mov [esp+4], edx |
140 |
mov [esp-12+8], ecx |
mov [esp+8], ecx |
141 |
test eax, eax |
test eax, eax |
142 |
|
|
143 |
jz near .cpu_quit |
jz near .cpu_quit |
146 |
cpuid |
cpuid |
147 |
|
|
148 |
; RDTSC command ? |
; RDTSC command ? |
149 |
CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, ebp |
CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, ebp, edx |
150 |
|
|
151 |
; MMX support ? |
; MMX support ? |
152 |
CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, ebp |
CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, ebp, edx |
153 |
|
|
154 |
; SSE support ? |
; SSE support ? |
155 |
CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT|XVID_CPU_SSE), ebp |
CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT|XVID_CPU_SSE), ebp, edx |
156 |
|
|
157 |
; SSE2 support? |
; SSE2 support? |
158 |
CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, ebp |
CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, ebp, edx |
159 |
|
|
160 |
|
; SSE3 support? |
161 |
|
CHECK_FEATURE CPUID_SSE3, XVID_CPU_SSE3, ebp, ecx |
162 |
|
|
163 |
; extended functions? |
; extended functions? |
164 |
mov eax, 0x80000000 |
mov eax, 0x80000000 |
171 |
|
|
172 |
; AMD cpu ? |
; AMD cpu ? |
173 |
lea esi, [vendorAMD] |
lea esi, [vendorAMD] |
174 |
lea edi, [esp-12] |
lea edi, [esp] |
175 |
mov ecx, 12 |
mov ecx, 12 |
176 |
cld |
cld |
177 |
repe cmpsb |
repe cmpsb |
178 |
jnz .cpu_quit |
jnz .cpu_quit |
179 |
|
|
180 |
; 3DNow! support ? |
; 3DNow! support ? |
181 |
CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, ebp |
CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, ebp, edx |
182 |
|
|
183 |
; 3DNOW extended ? |
; 3DNOW extended ? |
184 |
CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, ebp |
CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, ebp, edx |
185 |
|
|
186 |
; extended MMX ? |
; extended MMX ? |
187 |
CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, ebp |
CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, ebp, edx |
188 |
|
|
189 |
.cpu_quit: |
.cpu_quit: |
190 |
|
|
191 |
mov eax, ebp |
mov eax, ebp |
192 |
|
|
193 |
|
add esp, 12 |
194 |
|
|
195 |
pop ebp |
pop ebp |
196 |
pop edi |
pop edi |
197 |
pop esi |
pop esi |
198 |
pop ebx |
pop ebx |
199 |
|
|
200 |
ret |
ret |
201 |
|
ENDFUNC |
|
|
|
202 |
|
|
203 |
; sse/sse2 operating support detection routines |
; sse/sse2 operating support detection routines |
204 |
; these will trigger an invalid instruction signal if not supported. |
; these will trigger an invalid instruction signal if not supported. |
205 |
|
ALIGN 16 |
206 |
cglobal sse_os_trigger |
cglobal sse_os_trigger |
|
align 16 |
|
207 |
sse_os_trigger: |
sse_os_trigger: |
208 |
xorps xmm0, xmm0 |
xorps xmm0, xmm0 |
209 |
ret |
ret |
210 |
|
ENDFUNC |
211 |
|
|
212 |
|
|
213 |
|
ALIGN 16 |
214 |
cglobal sse2_os_trigger |
cglobal sse2_os_trigger |
|
align 16 |
|
215 |
sse2_os_trigger: |
sse2_os_trigger: |
216 |
xorpd xmm0, xmm0 |
xorpd xmm0, xmm0 |
217 |
ret |
ret |
218 |
|
ENDFUNC |
219 |
|
|
220 |
|
|
221 |
|
; enter/exit mmx state |
222 |
|
ALIGN 16 |
223 |
|
cglobal emms_mmx |
224 |
|
emms_mmx: |
225 |
|
emms |
226 |
|
ret |
227 |
|
ENDFUNC |
228 |
|
|
229 |
|
; faster enter/exit mmx state |
230 |
|
ALIGN 16 |
231 |
|
cglobal emms_3dn |
232 |
|
emms_3dn: |
233 |
|
femms |
234 |
|
ret |
235 |
|
ENDFUNC |
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
%ifidn __OUTPUT_FORMAT__,elf |
240 |
|
section ".note.GNU-stack" noalloc noexec nowrite progbits |
241 |
|
%endif |
242 |
|
|