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 |
; * |
; * |
|
; * Under section 8 of the GNU General Public License, the copyright |
|
|
; * 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. |
|
|
; * |
|
22 |
; * $Id$ |
; * $Id$ |
23 |
; ******************************************************************************/ |
; * |
24 |
|
; ***************************************************************************/ |
25 |
|
|
26 |
bits 32 |
BITS 32 |
27 |
|
|
28 |
|
%macro cglobal 1 |
29 |
|
%ifdef PREFIX |
30 |
|
%ifdef MARK_FUNCS |
31 |
|
global _%1:function %1.endfunc-%1 |
32 |
|
%define %1 _%1:function %1.endfunc-%1 |
33 |
|
%else |
34 |
|
global _%1 |
35 |
|
%define %1 _%1 |
36 |
|
%endif |
37 |
|
%else |
38 |
|
%ifdef MARK_FUNCS |
39 |
|
global %1:function %1.endfunc-%1 |
40 |
|
%else |
41 |
|
global %1 |
42 |
|
%endif |
43 |
|
%endif |
44 |
|
%endmacro |
45 |
|
|
46 |
|
;============================================================================= |
47 |
|
; Constants |
48 |
|
;============================================================================= |
49 |
|
|
50 |
%define CPUID_TSC 0x00000010 |
%define CPUID_TSC 0x00000010 |
51 |
%define CPUID_MMX 0x00800000 |
%define CPUID_MMX 0x00800000 |
52 |
%define CPUID_SSE 0x02000000 |
%define CPUID_SSE 0x02000000 |
53 |
%define CPUID_SSE2 0x04000000 |
%define CPUID_SSE2 0x04000000 |
54 |
|
%define CPUID_SSE3 0x00000001 |
55 |
|
|
56 |
%define EXT_CPUID_3DNOW 0x80000000 |
%define EXT_CPUID_3DNOW 0x80000000 |
57 |
%define EXT_CPUID_AMD_3DNOWEXT 0x40000000 |
%define EXT_CPUID_AMD_3DNOWEXT 0x40000000 |
58 |
%define EXT_CPUID_AMD_MMXEXT 0x00400000 |
%define EXT_CPUID_AMD_MMXEXT 0x00400000 |
59 |
|
|
60 |
%define XVID_CPU_MMX 0x00000001 |
;;; NB: Make sure these defines match the ones defined in xvid.h |
61 |
%define XVID_CPU_MMXEXT 0x00000002 |
%define XVID_CPU_MMX (1<< 0) |
62 |
%define XVID_CPU_SSE 0x00000004 |
%define XVID_CPU_MMXEXT (1<< 1) |
63 |
%define XVID_CPU_SSE2 0x00000008 |
%define XVID_CPU_SSE (1<< 2) |
64 |
%define XVID_CPU_3DNOW 0x00000010 |
%define XVID_CPU_SSE2 (1<< 3) |
65 |
%define XVID_CPU_3DNOWEXT 0x00000020 |
%define XVID_CPU_SSE3 (1<< 8) |
66 |
%define XVID_CPU_TSC 0x00000040 |
%define XVID_CPU_3DNOW (1<< 4) |
67 |
|
%define XVID_CPU_3DNOWEXT (1<< 5) |
68 |
|
%define XVID_CPU_TSC (1<< 6) |
69 |
|
|
70 |
|
;============================================================================= |
71 |
|
; Read only data |
72 |
|
;============================================================================= |
73 |
|
|
74 |
|
ALIGN 32 |
75 |
%macro cglobal 1 |
%ifdef FORMAT_COFF |
76 |
%ifdef PREFIX |
SECTION .rodata |
|
global _%1 |
|
|
%define %1 _%1 |
|
77 |
%else |
%else |
78 |
global %1 |
SECTION .rodata align=16 |
79 |
%endif |
%endif |
|
%endmacro |
|
|
|
|
|
ALIGN 32 |
|
80 |
|
|
81 |
section .data |
vendorAMD: |
82 |
|
db "AuthenticAMD" |
83 |
|
|
84 |
vendorAMD db "AuthenticAMD" |
;============================================================================= |
85 |
|
; Macros |
86 |
|
;============================================================================= |
87 |
|
|
88 |
%macro CHECK_FEATURE 3 |
%macro CHECK_FEATURE 3 |
|
|
|
89 |
mov ecx, %1 |
mov ecx, %1 |
90 |
and ecx, edx |
and ecx, edx |
91 |
neg ecx |
neg ecx |
92 |
sbb ecx, ecx |
sbb ecx, ecx |
93 |
and ecx, %2 |
and ecx, %2 |
94 |
or %3, ecx |
or %3, ecx |
|
|
|
95 |
%endmacro |
%endmacro |
96 |
|
|
97 |
section .text |
;============================================================================= |
98 |
|
; Code |
99 |
|
;============================================================================= |
100 |
|
|
101 |
|
SECTION .text |
102 |
|
|
103 |
; int check_cpu_feature(void) |
; int check_cpu_feature(void) |
104 |
|
|
110 |
push edi |
push edi |
111 |
push ebp |
push ebp |
112 |
|
|
113 |
|
sub esp, 12 ; Stack space for vendor name |
114 |
|
|
115 |
xor ebp,ebp |
xor ebp,ebp |
116 |
|
|
117 |
; CPUID command ? |
; CPUID command ? |
131 |
; get vendor string, used later |
; get vendor string, used later |
132 |
xor eax, eax |
xor eax, eax |
133 |
cpuid |
cpuid |
134 |
mov [esp-12], ebx ; vendor string |
mov [esp], ebx ; vendor string |
135 |
mov [esp-12+4], edx |
mov [esp+4], edx |
136 |
mov [esp-12+8], ecx |
mov [esp+8], ecx |
137 |
test eax, eax |
test eax, eax |
138 |
|
|
139 |
jz near .cpu_quit |
jz near .cpu_quit |
153 |
; SSE2 support? |
; SSE2 support? |
154 |
CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, ebp |
CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, ebp |
155 |
|
|
156 |
|
; SSE3 support? |
157 |
|
CHECK_FEATURE CPUID_SSE3, XVID_CPU_SSE3, ebp |
158 |
|
|
159 |
; extended functions? |
; extended functions? |
160 |
mov eax, 0x80000000 |
mov eax, 0x80000000 |
161 |
cpuid |
cpuid |
167 |
|
|
168 |
; AMD cpu ? |
; AMD cpu ? |
169 |
lea esi, [vendorAMD] |
lea esi, [vendorAMD] |
170 |
lea edi, [esp-12] |
lea edi, [esp] |
171 |
mov ecx, 12 |
mov ecx, 12 |
172 |
cld |
cld |
173 |
repe cmpsb |
repe cmpsb |
186 |
|
|
187 |
mov eax, ebp |
mov eax, ebp |
188 |
|
|
189 |
|
add esp, 12 |
190 |
|
|
191 |
pop ebp |
pop ebp |
192 |
pop edi |
pop edi |
193 |
pop esi |
pop esi |
194 |
pop ebx |
pop ebx |
195 |
|
|
196 |
ret |
ret |
197 |
|
.endfunc |
|
|
|
198 |
|
|
199 |
; sse/sse2 operating support detection routines |
; sse/sse2 operating support detection routines |
200 |
; these will trigger an invalid instruction signal if not supported. |
; these will trigger an invalid instruction signal if not supported. |
201 |
|
ALIGN 16 |
202 |
cglobal sse_os_trigger |
cglobal sse_os_trigger |
|
align 16 |
|
203 |
sse_os_trigger: |
sse_os_trigger: |
204 |
xorps xmm0, xmm0 |
xorps xmm0, xmm0 |
205 |
ret |
ret |
206 |
|
.endfunc |
207 |
|
|
208 |
|
|
209 |
|
ALIGN 16 |
210 |
cglobal sse2_os_trigger |
cglobal sse2_os_trigger |
|
align 16 |
|
211 |
sse2_os_trigger: |
sse2_os_trigger: |
212 |
xorpd xmm0, xmm0 |
xorpd xmm0, xmm0 |
213 |
ret |
ret |
214 |
|
.endfunc |
215 |
|
|
216 |
|
|
217 |
|
; enter/exit mmx state |
218 |
|
ALIGN 16 |
219 |
|
cglobal emms_mmx |
220 |
|
emms_mmx: |
221 |
|
emms |
222 |
|
ret |
223 |
|
.endfunc |
224 |
|
|
225 |
|
; faster enter/exit mmx state |
226 |
|
ALIGN 16 |
227 |
|
cglobal emms_3dn |
228 |
|
emms_3dn: |
229 |
|
femms |
230 |
|
ret |
231 |
|
.endfunc |
232 |
|
|
233 |
|
|