[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 1192 - (view) (download)

1 : edgomez 1192 ;/****************************************************************************
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 :     ; * $Id: cpuid.asm,v 1.4.2.2 2003-10-28 22:23:03 edgomez Exp $
23 :     ; *
24 :     ; ***************************************************************************/
25 : Isibaar 3
26 : edgomez 1192 BITS 32
27 : Isibaar 3
28 : edgomez 1192 %macro cglobal 1
29 :     %ifdef PREFIX
30 :     global _%1
31 :     %define %1 _%1
32 :     %else
33 :     global %1
34 :     %endif
35 :     %endmacro
36 : Isibaar 3
37 : edgomez 1192 ;=============================================================================
38 :     ; Constants
39 :     ;=============================================================================
40 : Isibaar 3
41 : edgomez 1192 %define CPUID_TSC 0x00000010
42 :     %define CPUID_MMX 0x00800000
43 :     %define CPUID_SSE 0x02000000
44 :     %define CPUID_SSE2 0x04000000
45 :    
46 :     %define EXT_CPUID_3DNOW 0x80000000
47 :     %define EXT_CPUID_AMD_3DNOWEXT 0x40000000
48 :     %define EXT_CPUID_AMD_MMXEXT 0x00400000
49 :    
50 :     ;;; NB: Make sure these defines match the ones defined in xvid.h
51 : edgomez 1176 %define XVID_CPU_MMX (1<< 0)
52 :     %define XVID_CPU_MMXEXT (1<< 1)
53 :     %define XVID_CPU_SSE (1<< 2)
54 :     %define XVID_CPU_SSE2 (1<< 3)
55 :     %define XVID_CPU_3DNOW (1<< 4)
56 :     %define XVID_CPU_3DNOWEXT (1<< 5)
57 :     %define XVID_CPU_TSC (1<< 6)
58 : Isibaar 3
59 : edgomez 1192 ;=============================================================================
60 :     ; Read only data
61 :     ;=============================================================================
62 : Isibaar 3
63 :     ALIGN 32
64 : edgomez 1192 SECTION .rodata
65 : Isibaar 3
66 : edgomez 1192 vendorAMD:
67 :     db "AuthenticAMD"
68 : Isibaar 3
69 : edgomez 1192 ;=============================================================================
70 :     ; Macros
71 :     ;=============================================================================
72 : Isibaar 3
73 :     %macro CHECK_FEATURE 3
74 : edgomez 1192 mov ecx, %1
75 :     and ecx, edx
76 :     neg ecx
77 :     sbb ecx, ecx
78 :     and ecx, %2
79 :     or %3, ecx
80 : Isibaar 3 %endmacro
81 :    
82 : edgomez 1192 ;=============================================================================
83 :     ; Code
84 :     ;=============================================================================
85 : Isibaar 3
86 : edgomez 1192 SECTION .text
87 :    
88 : Isibaar 3 ; int check_cpu_feature(void)
89 :    
90 :     cglobal check_cpu_features
91 :     check_cpu_features:
92 :    
93 : edgomez 1192 push ebx
94 :     push esi
95 :     push edi
96 :     push ebp
97 : suxen_drol 309
98 : edgomez 1192 xor ebp, ebp
99 : suxen_drol 309
100 : Isibaar 3 ; CPUID command ?
101 : edgomez 1192 pushfd
102 :     pop eax
103 :     mov ecx, eax
104 :     xor eax, 0x200000
105 :     push eax
106 :     popfd
107 :     pushfd
108 :     pop eax
109 :     cmp eax, ecx
110 : Isibaar 3
111 : edgomez 1192 jz near .cpu_quit ; no CPUID command -> exit
112 : Isibaar 3
113 :    
114 :     ; get vendor string, used later
115 : edgomez 1192 xor eax, eax
116 :     cpuid
117 :     mov [esp-12], ebx ; vendor string
118 :     mov [esp-12+4], edx
119 :     mov [esp-12+8], ecx
120 :     test eax, eax
121 : Isibaar 3
122 : edgomez 1192 jz near .cpu_quit
123 : Isibaar 3
124 : edgomez 1192 mov eax, 1
125 :     cpuid
126 : Isibaar 3
127 : edgomez 1192 ; RDTSC command ?
128 :     CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, ebp
129 : Isibaar 3
130 : edgomez 1192 ; MMX support ?
131 :     CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, ebp
132 : Isibaar 3
133 : edgomez 1192 ; SSE support ?
134 :     CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT|XVID_CPU_SSE), ebp
135 : Isibaar 3
136 : edgomez 1192 ; SSE2 support?
137 :     CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, ebp
138 : Isibaar 3
139 : edgomez 1192 ; extended functions?
140 :     mov eax, 0x80000000
141 :     cpuid
142 :     cmp eax, 0x80000000
143 :     jbe near .cpu_quit
144 : Isibaar 3
145 : edgomez 1192 mov eax, 0x80000001
146 :     cpuid
147 : Isibaar 3
148 : edgomez 1192 ; AMD cpu ?
149 :     lea esi, [vendorAMD]
150 :     lea edi, [esp-12]
151 :     mov ecx, 12
152 :     cld
153 :     repe cmpsb
154 :     jnz .cpu_quit
155 : Isibaar 3
156 : edgomez 1192 ; 3DNow! support ?
157 :     CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, ebp
158 : suxen_drol 309
159 : edgomez 1192 ; 3DNOW extended ?
160 :     CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, ebp
161 : Isibaar 3
162 : edgomez 1192 ; extended MMX ?
163 :     CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, ebp
164 : Isibaar 3
165 : suxen_drol 309 .cpu_quit:
166 :    
167 : edgomez 1192 mov eax, ebp
168 : suxen_drol 309
169 : edgomez 1192 pop ebp
170 :     pop edi
171 :     pop esi
172 :     pop ebx
173 : suxen_drol 309
174 : edgomez 1192 ret
175 : suxen_drol 309
176 :     ; sse/sse2 operating support detection routines
177 :     ; these will trigger an invalid instruction signal if not supported.
178 : edgomez 1192 ALIGN 16
179 : suxen_drol 309 cglobal sse_os_trigger
180 :     sse_os_trigger:
181 : edgomez 1192 xorps xmm0, xmm0
182 :     ret
183 : suxen_drol 309
184 :    
185 : edgomez 1192 ALIGN 16
186 : suxen_drol 309 cglobal sse2_os_trigger
187 :     sse2_os_trigger:
188 : edgomez 1192 xorpd xmm0, xmm0
189 :     ret
190 : suxen_drol 309
191 : edgomez 851
192 :     ; enter/exit mmx state
193 : edgomez 1192 ALIGN 16
194 : edgomez 851 cglobal emms_mmx
195 :     emms_mmx:
196 : edgomez 1192 emms
197 :     ret
198 : edgomez 851
199 :     ; faster enter/exit mmx state
200 : edgomez 1192 ALIGN 16
201 : edgomez 851 cglobal emms_3dn
202 :     emms_3dn:
203 : edgomez 1192 femms
204 :     ret

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