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

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

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