[cvs] / xvidcore / src / utils / x86_asm / cpuid.asm Repository:
ViewVC logotype

Annotation of /xvidcore/src/utils/x86_asm/cpuid.asm

Parent Directory Parent Directory | Revision Log Revision Log


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

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