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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3, Fri Mar 8 02:46:11 2002 UTC revision 1839, Tue Dec 2 13:44:55 2008 UTC
# Line 1  Line 1 
1  ;/******************************************************************************  ;/****************************************************************************
2  ; *                                                                            *  ; *
3  ; *  This file is part of XviD, a free MPEG-4 video encoder/decoder            *  ; *  XVID MPEG-4 VIDEO CODEC
4  ; *                                                                            *  ; *  - CPUID check processors capabilities -
5  ; *  XviD is an implementation of a part of one or more MPEG-4 Video tools     *  ; *
6  ; *  as specified in ISO/IEC 14496-2 standard.  Those intending to use this    *  ; *  Copyright (C) 2001-2008 Michael Militzer <michael@xvid.org>
7  ; *  software module in hardware or software products are advised that its     *  ; *
8  ; *  use may infringe existing patents or copyrights, and any such use         *  ; *  This program is free software ; you can redistribute it and/or modify
9  ; *  would be at such party's own risk.  The original developer of this        *  ; *  it under the terms of the GNU General Public License as published by
10  ; *  software module and his/her company, and subsequent editors and their     *  ; *  the Free Software Foundation ; either version 2 of the License, or
11  ; *  companies, will have no liability for use of this software or             *  ; *  (at your option) any later version.
12  ; *  modifications or derivatives thereof.                                     *  ; *
13  ; *                                                                            *  ; *  This program is distributed in the hope that it will be useful,
14  ; *  XviD is free software; you can redistribute it and/or modify it           *  ; *  but WITHOUT ANY WARRANTY ; without even the implied warranty of
15  ; *  under the terms of the GNU General Public License as published by         *  ; *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  ; *  the Free Software Foundation; either version 2 of the License, or         *  ; *  GNU General Public License for more details.
17  ; *  (at your option) any later version.                                       *  ; *
18  ; *                                                                            *  ; *  You should have received a copy of the GNU General Public License
19  ; *  XviD is distributed in the hope that it will be useful, but               *  ; *  along with this program ; if not, write to the Free Software
20  ; *  WITHOUT ANY WARRANTY; without even the implied warranty of                *  ; *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  ; *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *  ; *
22  ; *  GNU General Public License for more details.                              *  ; * $Id: cpuid.asm,v 1.16 2008-12-02 13:44:55 Isibaar Exp $
23  ; *                                                                            *  ; *
24  ; *  You should have received a copy of the GNU General Public License         *  ; ***************************************************************************/
25  ; *  along with this program; if not, write to the Free Software               *  
26  ; *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *  %include "nasm.inc"
27  ; *                                                                            *  
28  ; ******************************************************************************/  ;=============================================================================
29  ;  ; Constants
30  ;/******************************************************************************  ;=============================================================================
 ; *                                                                            *  
 ; *  cpuid.asm, check cpu features                                             *  
 ; *                                                                            *  
 ; *  Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org>,                 *  
 ; *                                                                            *  
 ; *  For more information visit the XviD homepage: http://www.xvid.org         *  
 ; *                                                                            *  
 ; ******************************************************************************/  
 ;  
 ;/******************************************************************************  
 ; *                                                                            *  
 ; *  Revision history:                                                         *  
 ; *                                                                            *  
 ; *  17.12.2001 initial version  (Isibaar)                                     *  
 ; *                                                                            *  
 ; ******************************************************************************/  
   
 bits 32  
31    
32  %define CPUID_TSC                               0x00000010  %define CPUID_TSC                               0x00000010
33  %define CPUID_MMX                               0x00800000  %define CPUID_MMX                               0x00800000
34  %define CPUID_SSE                               0x02000000  %define CPUID_SSE                               0x02000000
35  %define CPUID_SSE2                              0x04000000  %define CPUID_SSE2                              0x04000000
36    %define CPUID_SSE3              0x00000001
37    %define CPUID_SSE41             0x00080000
38    
39  %define EXT_CPUID_3DNOW                 0x80000000  %define EXT_CPUID_3DNOW                 0x80000000
40  %define EXT_CPUID_AMD_3DNOWEXT  0x40000000  %define EXT_CPUID_AMD_3DNOWEXT  0x40000000
41  %define EXT_CPUID_AMD_MMXEXT    0x00400000  %define EXT_CPUID_AMD_MMXEXT    0x00400000
42    
43  %define XVID_CPU_MMX                    0x00000001  ;;; NB: Make sure these defines match the ones defined in xvid.h
44  %define XVID_CPU_MMXEXT                 0x00000002  %define XVID_CPU_MMX      (1<< 0)
45  %define XVID_CPU_SSE            0x00000004  %define XVID_CPU_MMXEXT   (1<< 1)
46  %define XVID_CPU_SSE2                   0x00000008  %define XVID_CPU_SSE      (1<< 2)
47  %define XVID_CPU_3DNOW          0x00000010  %define XVID_CPU_SSE2     (1<< 3)
48  %define XVID_CPU_3DNOWEXT               0x00000020  %define XVID_CPU_SSE3     (1<< 8)
49  %define XVID_CPU_TSC            0x00000040  %define XVID_CPU_SSE41    (1<< 9)
50    %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    ALIGN SECTION_ALIGN
59    
60    DATA
61    
62    vendorAMD:
63                    db "AuthenticAMD"
64    
65    ;=============================================================================
66    ; Macros
67    ;=============================================================================
68    
69    %macro  CHECK_FEATURE         4
70      mov eax, %1
71      and eax, %4
72      neg eax
73      sbb eax, eax
74      and eax, %2
75      or %3, eax
76    %endmacro
77    
78  %macro cglobal 1  ;=============================================================================
79          %ifdef PREFIX  ; Code
80                  global _%1  ;=============================================================================
81                  %define %1 _%1  
82    %ifdef ARCH_IS_X86_64
83    %define XVID_PUSHFD pushfq
84    %define XVID_POPFD  popfq
85          %else          %else
86                  global %1  %define XVID_PUSHFD pushfd
87    %define XVID_POPFD  popfd
88          %endif          %endif
 %endmacro  
   
 ALIGN 32  
   
 section .data  
89    
90  features        dd 0  SECTION .rotext align=SECTION_ALIGN
   
 vendor          dd 0,0,0  
 vendorAMD       db "AuthenticAMD"  
   
 %macro  CHECK_FEATURE         3  
   
     mov     ecx, %1  
     and     ecx, edx  
     neg     ecx  
     sbb     ecx, ecx  
     and     ecx, %2  
     or      [%3], ecx  
   
 %endmacro  
   
 section .text  
91    
92  ; int check_cpu_feature(void)  ; int check_cpu_feature(void)
93    
94  cglobal check_cpu_features  cglobal check_cpu_features
95  check_cpu_features:  check_cpu_features:
96    
97          pushad    push _EBX
98          pushfd    push _ESI
99      push _EDI
100      push _EBP
101    
102      sub _ESP, 12             ; Stack space for vendor name
103    
104      xor ebp, ebp
105    
106          ; CPUID command ?          ; CPUID command ?
107          pop             eax    XVID_PUSHFD
108      pop _EAX
109          mov             ecx, eax          mov             ecx, eax
110          xor             eax, 0x200000          xor             eax, 0x200000
111          push    eax    push _EAX
112          popfd    XVID_POPFD
113          pushfd    XVID_PUSHFD
114          pop             eax    pop _EAX
115          cmp             eax, ecx          cmp             eax, ecx
116    
117          jz              near .cpu_quit          ; no CPUID command -> exit          jz              near .cpu_quit          ; no CPUID command -> exit
118    
   
119          ; get vendor string, used later          ; get vendor string, used later
120      xor     eax, eax      xor     eax, eax
121      cpuid      cpuid
122      mov     [vendor], ebx       ; vendor string    mov [_ESP], ebx        ; vendor string
123      mov     [vendor+4], edx    mov [_ESP+4], edx
124      mov     [vendor+8], ecx    mov [_ESP+8], ecx
125      test    eax, eax      test    eax, eax
126    
127      jz      near .cpu_quit      jz      near .cpu_quit
# Line 130  Line 129 
129      mov     eax, 1      mov     eax, 1
130      cpuid      cpuid
131    
   
132      ; RDTSC command ?      ; RDTSC command ?
133          CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, features    CHECK_FEATURE CPUID_TSC, XVID_CPU_TSC, ebp, edx
134    
135      ; MMX support ?      ; MMX support ?
136          CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, features    CHECK_FEATURE CPUID_MMX, XVID_CPU_MMX, ebp, edx
137    
138      ; SSE support ?      ; SSE support ?
139          CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT+XVID_CPU_SSE), features    CHECK_FEATURE CPUID_SSE, (XVID_CPU_MMXEXT|XVID_CPU_SSE), ebp, edx
140    
141          ; SSE2 support?          ; SSE2 support?
142          CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, features    CHECK_FEATURE CPUID_SSE2, XVID_CPU_SSE2, ebp, edx
143    
144      ; SSE3 support?
145      CHECK_FEATURE CPUID_SSE3, XVID_CPU_SSE3, ebp, ecx
146    
147      ; SSE41 support?
148      CHECK_FEATURE CPUID_SSE41, XVID_CPU_SSE41, ebp, ecx
149    
150          ; extended functions?          ; extended functions?
151      mov     eax, 0x80000000      mov     eax, 0x80000000
# Line 153  Line 156 
156      mov     eax, 0x80000001      mov     eax, 0x80000001
157      cpuid      cpuid
158    
     ; 3DNow! support ?  
         CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, features  
   
159          ; AMD cpu ?          ; AMD cpu ?
160      lea     esi, [vendorAMD]    lea _ESI, [vendorAMD]
161      lea     edi, [vendor]    lea _EDI, [_ESP]
162      mov     ecx, 12      mov     ecx, 12
163      cld      cld
164      repe    cmpsb      repe    cmpsb
165      jnz     .cpu_quit      jnz     .cpu_quit
166    
167      ; 3DNow! support ?
168      CHECK_FEATURE EXT_CPUID_3DNOW, XVID_CPU_3DNOW, ebp, edx
169    
170          ; 3DNOW extended ?          ; 3DNOW extended ?
171          CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, features    CHECK_FEATURE EXT_CPUID_AMD_3DNOWEXT, XVID_CPU_3DNOWEXT, ebp, edx
172    
173          ; extended MMX ?          ; extended MMX ?
174          CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, features    CHECK_FEATURE EXT_CPUID_AMD_MMXEXT, XVID_CPU_MMXEXT, ebp, edx
175    
176  .cpu_quit:  .cpu_quit:
177    
178          popad    mov eax, ebp
179    
180          mov eax, [features]    add _ESP, 12
181    
182      pop _EBP
183      pop _EDI
184      pop _ESI
185      pop _EBX
186    
187      ret
188    ENDFUNC
189    
190    ; sse/sse2 operating support detection routines
191    ; these will trigger an invalid instruction signal if not supported.
192    ALIGN SECTION_ALIGN
193    cglobal sse_os_trigger
194    sse_os_trigger:
195      xorps xmm0, xmm0
196      ret
197    ENDFUNC
198    
199    
200    ALIGN SECTION_ALIGN
201    cglobal sse2_os_trigger
202    sse2_os_trigger:
203      xorpd xmm0, xmm0
204      ret
205    ENDFUNC
206    
207    
208    ; enter/exit mmx state
209    ALIGN SECTION_ALIGN
210    cglobal emms_mmx
211    emms_mmx:
212      emms
213      ret
214    ENDFUNC
215    
216    ; faster enter/exit mmx state
217    ALIGN SECTION_ALIGN
218    cglobal emms_3dn
219    emms_3dn:
220      femms
221      ret
222    ENDFUNC
223    
224    %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          ret
238    %endif
239    %endif
240    
241    %ifidn __OUTPUT_FORMAT__,elf
242    section ".note.GNU-stack" noalloc noexec nowrite progbits
243    %endif
244    

Legend:
Removed from v.3  
changed lines
  Added in v.1839

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