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