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

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