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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1795 - (view) (download)

1 : edgomez 1382 ;/****************************************************************************
2 :     ; *
3 :     ; * XVID MPEG-4 VIDEO CODEC
4 :     ; * - CPUID check processors capabilities -
5 :     ; *
6 : Isibaar 1795 ; * Copyright (C) 2001-2008 Michael Militzer <michael@xvid.org>
7 : edgomez 1382 ; *
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 1795 ; * $Id: cpuid.asm,v 1.15 2008-11-26 01:04:34 Isibaar Exp $
23 : edgomez 1382 ; *
24 :     ; ***************************************************************************/
25 : Isibaar 3
26 : Isibaar 1795 %include "nasm.inc"
27 : Isibaar 3
28 : edgomez 1382 ;=============================================================================
29 :     ; Constants
30 :     ;=============================================================================
31 : Isibaar 3
32 : edgomez 1382 %define CPUID_TSC 0x00000010
33 :     %define CPUID_MMX 0x00800000
34 :     %define CPUID_SSE 0x02000000
35 :     %define CPUID_SSE2 0x04000000
36 : Isibaar 1764 %define CPUID_SSE3 0x00000001
37 : Isibaar 1794 %define CPUID_SSE41 0x00080000
38 : Isibaar 3
39 : edgomez 1382 %define EXT_CPUID_3DNOW 0x80000000
40 :     %define EXT_CPUID_AMD_3DNOWEXT 0x40000000
41 :     %define EXT_CPUID_AMD_MMXEXT 0x00400000
42 : Isibaar 3
43 : edgomez 1382 ;;; NB: Make sure these defines match the ones defined in xvid.h
44 :     %define XVID_CPU_MMX (1<< 0)
45 :     %define XVID_CPU_MMXEXT (1<< 1)
46 :     %define XVID_CPU_SSE (1<< 2)
47 :     %define XVID_CPU_SSE2 (1<< 3)
48 : Isibaar 1764 %define XVID_CPU_SSE3 (1<< 8)
49 : Isibaar 1794 %define XVID_CPU_SSE41 (1<< 9)
50 : edgomez 1382 %define XVID_CPU_3DNOW (1<< 4)
51 :     %define XVID_CPU_3DNOWEXT (1<< 5)
52 :     %define XVID_CPU_TSC (1<< 6)
53 : Isibaar 3
54 : edgomez 1382 ;=============================================================================
55 :     ; Read only data
56 :     ;=============================================================================
57 : Isibaar 3
58 : Isibaar 1795 ALIGN SECTION_ALIGN
59 : edgomez 1382
60 : Isibaar 1795 DATA
61 :    
62 : edgomez 1382 vendorAMD:
63 :     db "AuthenticAMD"
64 :    
65 :     ;=============================================================================
66 :     ; Macros
67 :     ;=============================================================================
68 :    
69 : Isibaar 1771 %macro CHECK_FEATURE 4
70 :     mov eax, %1
71 :     and eax, %4
72 : Isibaar 1795 neg eax
73 :     sbb eax, eax
74 : Isibaar 1771 and eax, %2
75 : Isibaar 1795 or %3, eax
76 : Isibaar 3 %endmacro
77 :    
78 : edgomez 1382 ;=============================================================================
79 :     ; Code
80 :     ;=============================================================================
81 : Isibaar 3
82 : Isibaar 1795 %ifdef ARCH_IS_X86_64
83 :     %define XVID_PUSHFD pushfq
84 :     %define XVID_POPFD popfq
85 :     %else
86 :     %define XVID_PUSHFD pushfd
87 :     %define XVID_POPFD popfd
88 :     %endif
89 : edgomez 1382
90 : Isibaar 1795 SECTION .rotext align=SECTION_ALIGN
91 :    
92 : Isibaar 3 ; int check_cpu_feature(void)
93 :    
94 :     cglobal check_cpu_features
95 :     check_cpu_features:
96 :    
97 : Isibaar 1795 push _EBX
98 :     push _ESI
99 :     push _EDI
100 :     push _EBP
101 : suxen_drol 309
102 : Isibaar 1795 sub _ESP, 12 ; Stack space for vendor name
103 : edgomez 1485
104 : Isibaar 1795 xor ebp, ebp
105 : suxen_drol 309
106 : Isibaar 3 ; CPUID command ?
107 : Isibaar 1795 XVID_PUSHFD
108 :     pop _EAX
109 :     mov ecx, eax
110 : edgomez 1382 xor eax, 0x200000
111 : Isibaar 1795 push _EAX
112 :     XVID_POPFD
113 :     XVID_PUSHFD
114 :     pop _EAX
115 :     cmp eax, ecx
116 : Isibaar 3
117 : edgomez 1382 jz near .cpu_quit ; no CPUID command -> exit
118 : Isibaar 3
119 :     ; get vendor string, used later
120 : Isibaar 1795 xor eax, eax
121 : edgomez 1382 cpuid
122 : Isibaar 1795 mov [_ESP], ebx ; vendor string
123 :     mov [_ESP+4], edx
124 :     mov [_ESP+8], ecx
125 :     test eax, eax
126 : Isibaar 3
127 : edgomez 1382 jz near .cpu_quit
128 : Isibaar 3
129 : edgomez 1382 mov eax, 1
130 :     cpuid
131 : Isibaar 3
132 : edgomez 1382 ; RDTSC command ?
133 : Isibaar 1795 CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, ebp, edx
134 : Isibaar 3
135 : edgomez 1382 ; MMX support ?
136 : Isibaar 1795 CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, ebp, edx
137 : Isibaar 3
138 : edgomez 1382 ; SSE support ?
139 : Isibaar 1795 CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT|XVID_CPU_SSE), ebp, edx
140 : Isibaar 3
141 : edgomez 1382 ; SSE2 support?
142 : Isibaar 1795 CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, ebp, edx
143 : Isibaar 3
144 : Isibaar 1764 ; SSE3 support?
145 : Isibaar 1795 CHECK_FEATURE CPUID_SSE3, XVID_CPU_SSE3, ebp, ecx
146 : Isibaar 1764
147 : Isibaar 1794 ; SSE41 support?
148 : Isibaar 1795 CHECK_FEATURE CPUID_SSE41, XVID_CPU_SSE41, ebp, ecx
149 : Isibaar 1794
150 : edgomez 1382 ; extended functions?
151 :     mov eax, 0x80000000
152 :     cpuid
153 :     cmp eax, 0x80000000
154 :     jbe near .cpu_quit
155 : Isibaar 3
156 : edgomez 1382 mov eax, 0x80000001
157 :     cpuid
158 : Isibaar 3
159 : edgomez 1382 ; AMD cpu ?
160 : Isibaar 1795 lea _ESI, [vendorAMD]
161 :     lea _EDI, [_ESP]
162 : edgomez 1382 mov ecx, 12
163 :     cld
164 :     repe cmpsb
165 :     jnz .cpu_quit
166 : Isibaar 3
167 : edgomez 1382 ; 3DNow! support ?
168 : Isibaar 1795 CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, ebp, edx
169 : suxen_drol 309
170 : edgomez 1382 ; 3DNOW extended ?
171 : Isibaar 1795 CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, ebp, edx
172 : Isibaar 3
173 : edgomez 1382 ; extended MMX ?
174 : Isibaar 1795 CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, ebp, edx
175 : Isibaar 3
176 : suxen_drol 309 .cpu_quit:
177 :    
178 : Isibaar 1795 mov eax, ebp
179 : suxen_drol 309
180 : Isibaar 1795 add _ESP, 12
181 : edgomez 1485
182 : Isibaar 1795 pop _EBP
183 :     pop _EDI
184 :     pop _ESI
185 :     pop _EBX
186 : suxen_drol 309
187 : edgomez 1382 ret
188 : Isibaar 1793 ENDFUNC
189 : suxen_drol 309
190 :     ; sse/sse2 operating support detection routines
191 :     ; these will trigger an invalid instruction signal if not supported.
192 : Isibaar 1795 ALIGN SECTION_ALIGN
193 : suxen_drol 309 cglobal sse_os_trigger
194 :     sse_os_trigger:
195 : edgomez 1382 xorps xmm0, xmm0
196 :     ret
197 : Isibaar 1793 ENDFUNC
198 : suxen_drol 309
199 :    
200 : Isibaar 1795 ALIGN SECTION_ALIGN
201 : suxen_drol 309 cglobal sse2_os_trigger
202 :     sse2_os_trigger:
203 : edgomez 1382 xorpd xmm0, xmm0
204 :     ret
205 : Isibaar 1793 ENDFUNC
206 : suxen_drol 309
207 : edgomez 851
208 :     ; enter/exit mmx state
209 : Isibaar 1795 ALIGN SECTION_ALIGN
210 : edgomez 851 cglobal emms_mmx
211 :     emms_mmx:
212 : edgomez 1382 emms
213 :     ret
214 : Isibaar 1793 ENDFUNC
215 : edgomez 851
216 :     ; faster enter/exit mmx state
217 : Isibaar 1795 ALIGN SECTION_ALIGN
218 : edgomez 851 cglobal emms_3dn
219 :     emms_3dn:
220 : edgomez 1382 femms
221 :     ret
222 : Isibaar 1793 ENDFUNC
223 : edgomez 1540
224 :    
225 : Isibaar 1790
226 :     %ifidn __OUTPUT_FORMAT__,elf
227 :     section ".note.GNU-stack" noalloc noexec nowrite progbits
228 :     %endif
229 :    

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