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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1790 - (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 1790 ; * $Id: cpuid.asm,v 1.3 2008-08-19 09:06:48 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 :     %else
35 :     global _%1
36 :     %define %1 _%1
37 :     %endif
38 :     %else
39 :     %ifdef MARK_FUNCS
40 :     global %1:function %1.endfunc-%1
41 :     %else
42 :     global %1
43 :     %endif
44 :     %endif
45 :     %endmacro
46 :    
47 :     ;=============================================================================
48 :     ; Constants
49 :     ;=============================================================================
50 :    
51 :     %define CPUID_TSC 0x00000010
52 :     %define CPUID_MMX 0x00800000
53 :     %define CPUID_SSE 0x02000000
54 :     %define CPUID_SSE2 0x04000000
55 : Isibaar 1771 %define CPUID_SSE3 0x00000001
56 : edgomez 1586
57 :     %define EXT_CPUID_3DNOW 0x80000000
58 :     %define EXT_CPUID_AMD_3DNOWEXT 0x40000000
59 :     %define EXT_CPUID_AMD_MMXEXT 0x00400000
60 :    
61 :     ;;; NB: Make sure these defines match the ones defined in xvid.h
62 :     %define XVID_CPU_MMX (1<< 0)
63 :     %define XVID_CPU_MMXEXT (1<< 1)
64 :     %define XVID_CPU_SSE (1<< 2)
65 :     %define XVID_CPU_SSE2 (1<< 3)
66 : Isibaar 1771 %define XVID_CPU_SSE3 (1<< 8)
67 : edgomez 1586 %define XVID_CPU_3DNOW (1<< 4)
68 :     %define XVID_CPU_3DNOWEXT (1<< 5)
69 :     %define XVID_CPU_TSC (1<< 6)
70 :    
71 :     ;=============================================================================
72 :     ; Read only data
73 :     ;=============================================================================
74 :    
75 :     ALIGN 64
76 :     %ifdef FORMAT_COFF
77 :     SECTION .rodata
78 :     %else
79 :     SECTION .rodata align=16
80 :     %endif
81 :    
82 :     vendorAMD:
83 :     db "AuthenticAMD"
84 :    
85 :     ;=============================================================================
86 :     ; Macros
87 :     ;=============================================================================
88 :    
89 : Isibaar 1771 %macro CHECK_FEATURE 4
90 :     mov rax, %1
91 :     and rax, %4
92 :     neg rax
93 :     sbb rax, rax
94 :     and rax, %2
95 :     or %3, rax
96 : edgomez 1586 %endmacro
97 :    
98 :     ;=============================================================================
99 :     ; Code
100 :     ;=============================================================================
101 :    
102 :     SECTION .text align=16
103 :    
104 :     ; int check_cpu_feature(void)
105 :     ; NB:
106 :     ; in theory we know x86_64 CPUs support mmx, mmxext, sse, sse2 but
107 :     ; for security sake, when intel cpus will come with amd64 support
108 :     ; it will be necessary to check if 3dnow can be used or not...
109 :     ; so better use cpuid, even if it's mostly ignored for now.
110 :    
111 :     cglobal check_cpu_features
112 :     check_cpu_features:
113 :    
114 :     push rbx
115 :     push rbp
116 :    
117 :     sub rsp, 12 ; Stack space for vendor name
118 :    
119 :     xor rbp, rbp
120 :    
121 :     ; get vendor string, used later
122 :     xor rax, rax
123 :     cpuid
124 :     mov [rsp], ebx ; vendor string
125 :     mov [rsp+4], edx
126 :     mov [rsp+8], ecx
127 :     test rax, rax
128 :    
129 :     jz near .cpu_quit
130 :    
131 :     ; NB: we don't test for cpuid support like in ia32, we know
132 :     ; it is supported.
133 :     mov rax, 1
134 :     cpuid
135 :    
136 :     ; RDTSC command ?
137 : Isibaar 1771 CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, rbp, rdx
138 : edgomez 1586
139 :     ; MMX support ?
140 : Isibaar 1771 CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, rbp, rdx
141 : edgomez 1586
142 :     ; SSE support ?
143 : Isibaar 1771 CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT|XVID_CPU_SSE), rbp, rdx
144 : edgomez 1586
145 :     ; SSE2 support?
146 : Isibaar 1771 CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, rbp, rdx
147 : edgomez 1586
148 : Isibaar 1771 ; SSE3 support?
149 :     CHECK_FEATURE CPUID_SSE3, XVID_CPU_SSE3, rbp, rcx
150 :    
151 : edgomez 1586 ; extended functions?
152 :     mov rax, 0x80000000
153 :     cpuid
154 :     cmp rax, 0x80000000
155 :     jbe near .cpu_quit
156 :    
157 :     mov rax, 0x80000001
158 :     cpuid
159 :    
160 :     ; AMD cpu ?
161 :     lea rsi, [vendorAMD wrt rip]
162 :     lea rdi, [rsp]
163 :     mov rcx, 12
164 :     cld
165 :     repe cmpsb
166 :     jnz .cpu_quit
167 :    
168 :     ; 3DNow! support ?
169 : Isibaar 1771 CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, rbp, rdx
170 : edgomez 1586
171 :     ; 3DNOW extended ?
172 : Isibaar 1771 CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, rbp, rdx
173 : edgomez 1586
174 :     ; extended MMX ?
175 : Isibaar 1771 CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, rbp, rdx
176 : edgomez 1586
177 :     .cpu_quit:
178 :    
179 :     mov rax, rbp
180 :    
181 :     add rsp, 12
182 :    
183 :     pop rbp
184 :     pop rbx
185 :    
186 :     ret
187 :     .endfunc
188 :    
189 :     ; sse/sse2 operating support detection routines
190 :     ; these will trigger an invalid instruction signal if not supported.
191 :     ALIGN 16
192 :     cglobal sse_os_trigger
193 :     sse_os_trigger:
194 :     xorps xmm0, xmm0
195 :     ret
196 :     .endfunc
197 :    
198 :    
199 :     ALIGN 16
200 :     cglobal sse2_os_trigger
201 :     sse2_os_trigger:
202 :     xorpd xmm0, xmm0
203 :     ret
204 :     .endfunc
205 :    
206 :    
207 :     ; enter/exit mmx state
208 :     ALIGN 16
209 :     cglobal emms_mmx
210 :     emms_mmx:
211 :     emms
212 :     ret
213 :     .endfunc
214 :    
215 :     ; faster enter/exit mmx state
216 :     ALIGN 16
217 :     cglobal emms_3dn
218 :     emms_3dn:
219 :     femms
220 :     ret
221 :     .endfunc
222 :    
223 :    
224 : Isibaar 1790
225 :     %ifidn __OUTPUT_FORMAT__,elf
226 :     section ".note.GNU-stack" noalloc noexec nowrite progbits
227 :     %endif
228 :    
229 :    
230 :     %ifidn __OUTPUT_FORMAT__,elf
231 :     section ".note.GNU-stack" noalloc noexec nowrite progbits
232 :     %endif
233 :    

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