Parent Directory | Revision Log
Revision 1794 - (view) (download)
1 : | edgomez | 1586 | ;/**************************************************************************** |
2 : | ; * | ||
3 : | ; * XVID MPEG-4 VIDEO CODEC | ||
4 : | ; * - CPUID check processors capabilities - | ||
5 : | ; * | ||
6 : | ; * Copyright (C) 2001 Michael Militzer <isibaar@xvid.org> | ||
7 : | ; * 2004 Andre Werthmann <wertmann@aei.mpg.de> | ||
8 : | ; * | ||
9 : | ; * This program is free software ; you can redistribute it and/or modify | ||
10 : | ; * it under the terms of the GNU General Public License as published by | ||
11 : | ; * the Free Software Foundation ; either version 2 of the License, or | ||
12 : | ; * (at your option) any later version. | ||
13 : | ; * | ||
14 : | ; * This program is distributed in the hope that it will be useful, | ||
15 : | ; * but WITHOUT ANY WARRANTY ; without even the implied warranty of | ||
16 : | ; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 : | ; * GNU General Public License for more details. | ||
18 : | ; * | ||
19 : | ; * You should have received a copy of the GNU General Public License | ||
20 : | ; * along with this program ; if not, write to the Free Software | ||
21 : | ; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 : | ; * | ||
23 : | Isibaar | 1794 | ; * $Id: cpuid.asm,v 1.6 2008-11-14 15:43:27 Isibaar Exp $ |
24 : | edgomez | 1586 | ; * |
25 : | ; ***************************************************************************/ | ||
26 : | |||
27 : | BITS 64 | ||
28 : | |||
29 : | %macro cglobal 1 | ||
30 : | %ifdef PREFIX | ||
31 : | %ifdef MARK_FUNCS | ||
32 : | global _%1:function %1.endfunc-%1 | ||
33 : | %define %1 _%1:function %1.endfunc-%1 | ||
34 : | Isibaar | 1793 | %define ENDFUNC .endfunc |
35 : | edgomez | 1586 | %else |
36 : | global _%1 | ||
37 : | %define %1 _%1 | ||
38 : | Isibaar | 1793 | %define ENDFUNC |
39 : | edgomez | 1586 | %endif |
40 : | %else | ||
41 : | %ifdef MARK_FUNCS | ||
42 : | global %1:function %1.endfunc-%1 | ||
43 : | Isibaar | 1793 | %define ENDFUNC .endfunc |
44 : | edgomez | 1586 | %else |
45 : | global %1 | ||
46 : | Isibaar | 1793 | %define ENDFUNC |
47 : | edgomez | 1586 | %endif |
48 : | %endif | ||
49 : | %endmacro | ||
50 : | |||
51 : | ;============================================================================= | ||
52 : | ; Constants | ||
53 : | ;============================================================================= | ||
54 : | |||
55 : | %define CPUID_TSC 0x00000010 | ||
56 : | %define CPUID_MMX 0x00800000 | ||
57 : | %define CPUID_SSE 0x02000000 | ||
58 : | %define CPUID_SSE2 0x04000000 | ||
59 : | Isibaar | 1771 | %define CPUID_SSE3 0x00000001 |
60 : | Isibaar | 1794 | %define CPUID_SSE41 0x00080000 |
61 : | edgomez | 1586 | |
62 : | %define EXT_CPUID_3DNOW 0x80000000 | ||
63 : | %define EXT_CPUID_AMD_3DNOWEXT 0x40000000 | ||
64 : | %define EXT_CPUID_AMD_MMXEXT 0x00400000 | ||
65 : | |||
66 : | ;;; NB: Make sure these defines match the ones defined in xvid.h | ||
67 : | %define XVID_CPU_MMX (1<< 0) | ||
68 : | %define XVID_CPU_MMXEXT (1<< 1) | ||
69 : | %define XVID_CPU_SSE (1<< 2) | ||
70 : | %define XVID_CPU_SSE2 (1<< 3) | ||
71 : | Isibaar | 1771 | %define XVID_CPU_SSE3 (1<< 8) |
72 : | Isibaar | 1794 | %define XVID_CPU_SSE41 (1<< 9) |
73 : | edgomez | 1586 | %define XVID_CPU_3DNOW (1<< 4) |
74 : | %define XVID_CPU_3DNOWEXT (1<< 5) | ||
75 : | %define XVID_CPU_TSC (1<< 6) | ||
76 : | |||
77 : | ;============================================================================= | ||
78 : | ; Read only data | ||
79 : | ;============================================================================= | ||
80 : | |||
81 : | ALIGN 64 | ||
82 : | %ifdef FORMAT_COFF | ||
83 : | SECTION .rodata | ||
84 : | %else | ||
85 : | SECTION .rodata align=16 | ||
86 : | %endif | ||
87 : | |||
88 : | vendorAMD: | ||
89 : | db "AuthenticAMD" | ||
90 : | |||
91 : | ;============================================================================= | ||
92 : | ; Macros | ||
93 : | ;============================================================================= | ||
94 : | |||
95 : | Isibaar | 1771 | %macro CHECK_FEATURE 4 |
96 : | mov rax, %1 | ||
97 : | and rax, %4 | ||
98 : | neg rax | ||
99 : | sbb rax, rax | ||
100 : | and rax, %2 | ||
101 : | or %3, rax | ||
102 : | edgomez | 1586 | %endmacro |
103 : | |||
104 : | ;============================================================================= | ||
105 : | ; Code | ||
106 : | ;============================================================================= | ||
107 : | |||
108 : | SECTION .text align=16 | ||
109 : | |||
110 : | ; int check_cpu_feature(void) | ||
111 : | ; NB: | ||
112 : | ; in theory we know x86_64 CPUs support mmx, mmxext, sse, sse2 but | ||
113 : | ; for security sake, when intel cpus will come with amd64 support | ||
114 : | ; it will be necessary to check if 3dnow can be used or not... | ||
115 : | ; so better use cpuid, even if it's mostly ignored for now. | ||
116 : | |||
117 : | cglobal check_cpu_features | ||
118 : | check_cpu_features: | ||
119 : | |||
120 : | push rbx | ||
121 : | push rbp | ||
122 : | |||
123 : | sub rsp, 12 ; Stack space for vendor name | ||
124 : | |||
125 : | xor rbp, rbp | ||
126 : | |||
127 : | ; get vendor string, used later | ||
128 : | xor rax, rax | ||
129 : | cpuid | ||
130 : | mov [rsp], ebx ; vendor string | ||
131 : | mov [rsp+4], edx | ||
132 : | mov [rsp+8], ecx | ||
133 : | test rax, rax | ||
134 : | |||
135 : | jz near .cpu_quit | ||
136 : | |||
137 : | ; NB: we don't test for cpuid support like in ia32, we know | ||
138 : | ; it is supported. | ||
139 : | mov rax, 1 | ||
140 : | cpuid | ||
141 : | |||
142 : | ; RDTSC command ? | ||
143 : | Isibaar | 1771 | CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, rbp, rdx |
144 : | edgomez | 1586 | |
145 : | ; MMX support ? | ||
146 : | Isibaar | 1771 | CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, rbp, rdx |
147 : | edgomez | 1586 | |
148 : | ; SSE support ? | ||
149 : | Isibaar | 1771 | CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT|XVID_CPU_SSE), rbp, rdx |
150 : | edgomez | 1586 | |
151 : | ; SSE2 support? | ||
152 : | Isibaar | 1771 | CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, rbp, rdx |
153 : | edgomez | 1586 | |
154 : | Isibaar | 1771 | ; SSE3 support? |
155 : | CHECK_FEATURE CPUID_SSE3, XVID_CPU_SSE3, rbp, rcx | ||
156 : | |||
157 : | Isibaar | 1794 | ; SSE41 support? |
158 : | CHECK_FEATURE CPUID_SSE41, XVID_CPU_SSE41, rbp, rcx | ||
159 : | |||
160 : | edgomez | 1586 | ; extended functions? |
161 : | mov rax, 0x80000000 | ||
162 : | cpuid | ||
163 : | cmp rax, 0x80000000 | ||
164 : | jbe near .cpu_quit | ||
165 : | |||
166 : | mov rax, 0x80000001 | ||
167 : | cpuid | ||
168 : | |||
169 : | ; AMD cpu ? | ||
170 : | lea rsi, [vendorAMD wrt rip] | ||
171 : | lea rdi, [rsp] | ||
172 : | mov rcx, 12 | ||
173 : | cld | ||
174 : | repe cmpsb | ||
175 : | jnz .cpu_quit | ||
176 : | |||
177 : | ; 3DNow! support ? | ||
178 : | Isibaar | 1771 | CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, rbp, rdx |
179 : | edgomez | 1586 | |
180 : | ; 3DNOW extended ? | ||
181 : | Isibaar | 1771 | CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, rbp, rdx |
182 : | edgomez | 1586 | |
183 : | ; extended MMX ? | ||
184 : | Isibaar | 1771 | CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, rbp, rdx |
185 : | edgomez | 1586 | |
186 : | .cpu_quit: | ||
187 : | |||
188 : | mov rax, rbp | ||
189 : | |||
190 : | add rsp, 12 | ||
191 : | |||
192 : | pop rbp | ||
193 : | pop rbx | ||
194 : | |||
195 : | ret | ||
196 : | Isibaar | 1793 | ENDFUNC |
197 : | edgomez | 1586 | |
198 : | ; sse/sse2 operating support detection routines | ||
199 : | ; these will trigger an invalid instruction signal if not supported. | ||
200 : | ALIGN 16 | ||
201 : | cglobal sse_os_trigger | ||
202 : | sse_os_trigger: | ||
203 : | xorps xmm0, xmm0 | ||
204 : | ret | ||
205 : | Isibaar | 1793 | ENDFUNC |
206 : | edgomez | 1586 | |
207 : | |||
208 : | ALIGN 16 | ||
209 : | cglobal sse2_os_trigger | ||
210 : | sse2_os_trigger: | ||
211 : | xorpd xmm0, xmm0 | ||
212 : | ret | ||
213 : | Isibaar | 1793 | ENDFUNC |
214 : | edgomez | 1586 | |
215 : | |||
216 : | ; enter/exit mmx state | ||
217 : | ALIGN 16 | ||
218 : | cglobal emms_mmx | ||
219 : | emms_mmx: | ||
220 : | emms | ||
221 : | ret | ||
222 : | Isibaar | 1793 | ENDFUNC |
223 : | edgomez | 1586 | |
224 : | ; faster enter/exit mmx state | ||
225 : | ALIGN 16 | ||
226 : | cglobal emms_3dn | ||
227 : | emms_3dn: | ||
228 : | femms | ||
229 : | ret | ||
230 : | Isibaar | 1793 | ENDFUNC |
231 : | edgomez | 1586 | |
232 : | Isibaar | 1790 | %ifidn __OUTPUT_FORMAT__,elf |
233 : | section ".note.GNU-stack" noalloc noexec nowrite progbits | ||
234 : | %endif | ||
235 : |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |