Mercurial > libavcodec.hg
annotate i386/cputest.c @ 1891:f403b3e286b3 libavcodec
use pan_scan to remove some weight, proper pan_scan offset reading
author | iive |
---|---|
date | Tue, 16 Mar 2004 15:38:40 +0000 |
parents | d774ded81bf6 |
children | 58b6b0ce1c20 |
rev | line source |
---|---|
0 | 1 /* Cpu detection code, extracted from mmx.h ((c)1997-99 by H. Dietz |
429 | 2 and R. Fisher). Converted to C and improved by Fabrice Bellard */ |
0 | 3 |
4 #include <stdlib.h> | |
5 #include "../dsputil.h" | |
6 | |
22
c31fb57d17a6
Suppressing external gas stuff to improve portability to Win32
nickols_k
parents:
16
diff
changeset
|
7 /* ebx saving is necessary for PIC. gcc seems unable to see it alone */ |
c31fb57d17a6
Suppressing external gas stuff to improve portability to Win32
nickols_k
parents:
16
diff
changeset
|
8 #define cpuid(index,eax,ebx,ecx,edx)\ |
43 | 9 __asm __volatile\ |
10 ("movl %%ebx, %%esi\n\t"\ | |
22
c31fb57d17a6
Suppressing external gas stuff to improve portability to Win32
nickols_k
parents:
16
diff
changeset
|
11 "cpuid\n\t"\ |
c31fb57d17a6
Suppressing external gas stuff to improve portability to Win32
nickols_k
parents:
16
diff
changeset
|
12 "xchgl %%ebx, %%esi"\ |
c31fb57d17a6
Suppressing external gas stuff to improve portability to Win32
nickols_k
parents:
16
diff
changeset
|
13 : "=a" (eax), "=S" (ebx),\ |
c31fb57d17a6
Suppressing external gas stuff to improve portability to Win32
nickols_k
parents:
16
diff
changeset
|
14 "=c" (ecx), "=d" (edx)\ |
43 | 15 : "0" (index)); |
0 | 16 |
17 /* Function to test if multimedia instructions are supported... */ | |
18 int mm_support(void) | |
19 { | |
20 int rval; | |
21 int eax, ebx, ecx, edx; | |
22 | |
23 __asm__ __volatile__ ( | |
24 /* See if CPUID instruction is supported ... */ | |
25 /* ... Get copies of EFLAGS into eax and ecx */ | |
26 "pushf\n\t" | |
27 "popl %0\n\t" | |
28 "movl %0, %1\n\t" | |
29 | |
30 /* ... Toggle the ID bit in one copy and store */ | |
31 /* to the EFLAGS reg */ | |
32 "xorl $0x200000, %0\n\t" | |
33 "push %0\n\t" | |
34 "popf\n\t" | |
35 | |
36 /* ... Get the (hopefully modified) EFLAGS */ | |
37 "pushf\n\t" | |
38 "popl %0\n\t" | |
39 : "=a" (eax), "=c" (ecx) | |
40 : | |
41 : "cc" | |
42 ); | |
43 | |
44 if (eax == ecx) | |
45 return 0; /* CPUID not supported */ | |
46 | |
22
c31fb57d17a6
Suppressing external gas stuff to improve portability to Win32
nickols_k
parents:
16
diff
changeset
|
47 cpuid(0, eax, ebx, ecx, edx); |
0 | 48 |
49 if (ebx == 0x756e6547 && | |
50 edx == 0x49656e69 && | |
51 ecx == 0x6c65746e) { | |
52 | |
53 /* intel */ | |
54 inteltest: | |
22
c31fb57d17a6
Suppressing external gas stuff to improve portability to Win32
nickols_k
parents:
16
diff
changeset
|
55 cpuid(1, eax, ebx, ecx, edx); |
0 | 56 if ((edx & 0x00800000) == 0) |
57 return 0; | |
58 rval = MM_MMX; | |
59 if (edx & 0x02000000) | |
60 rval |= MM_MMXEXT | MM_SSE; | |
61 if (edx & 0x04000000) | |
62 rval |= MM_SSE2; | |
63 return rval; | |
64 } else if (ebx == 0x68747541 && | |
65 edx == 0x69746e65 && | |
66 ecx == 0x444d4163) { | |
67 /* AMD */ | |
22
c31fb57d17a6
Suppressing external gas stuff to improve portability to Win32
nickols_k
parents:
16
diff
changeset
|
68 cpuid(0x80000000, eax, ebx, ecx, edx); |
0 | 69 if ((unsigned)eax < 0x80000001) |
70 goto inteltest; | |
22
c31fb57d17a6
Suppressing external gas stuff to improve portability to Win32
nickols_k
parents:
16
diff
changeset
|
71 cpuid(0x80000001, eax, ebx, ecx, edx); |
0 | 72 if ((edx & 0x00800000) == 0) |
73 return 0; | |
74 rval = MM_MMX; | |
75 if (edx & 0x80000000) | |
76 rval |= MM_3DNOW; | |
77 if (edx & 0x00400000) | |
78 rval |= MM_MMXEXT; | |
79 return rval; | |
889
6a9c3ecf2dec
via c3 detection patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
429
diff
changeset
|
80 } else if (ebx == 0x746e6543 && |
6a9c3ecf2dec
via c3 detection patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
429
diff
changeset
|
81 edx == 0x48727561 && |
6a9c3ecf2dec
via c3 detection patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
429
diff
changeset
|
82 ecx == 0x736c7561) { /* "CentaurHauls" */ |
6a9c3ecf2dec
via c3 detection patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
429
diff
changeset
|
83 /* VIA C3 */ |
6a9c3ecf2dec
via c3 detection patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
429
diff
changeset
|
84 cpuid(0x80000000, eax, ebx, ecx, edx); |
6a9c3ecf2dec
via c3 detection patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
429
diff
changeset
|
85 if ((unsigned)eax < 0x80000001) |
6a9c3ecf2dec
via c3 detection patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
429
diff
changeset
|
86 goto inteltest; |
6a9c3ecf2dec
via c3 detection patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
429
diff
changeset
|
87 cpuid(0x80000001, eax, ebx, ecx, edx); |
6a9c3ecf2dec
via c3 detection patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
429
diff
changeset
|
88 rval = 0; |
6a9c3ecf2dec
via c3 detection patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
429
diff
changeset
|
89 if( edx & ( 1 << 31) ) |
6a9c3ecf2dec
via c3 detection patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
429
diff
changeset
|
90 rval |= MM_3DNOW; |
6a9c3ecf2dec
via c3 detection patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
429
diff
changeset
|
91 if( edx & ( 1 << 23) ) |
6a9c3ecf2dec
via c3 detection patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
429
diff
changeset
|
92 rval |= MM_MMX; |
6a9c3ecf2dec
via c3 detection patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
429
diff
changeset
|
93 if( edx & ( 1 << 24) ) |
896
d774ded81bf6
via c3 fix patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
889
diff
changeset
|
94 rval |= MM_MMXEXT; |
d774ded81bf6
via c3 fix patch by (Francisco Javier Cabello Torres <fjcabello at visual-tools dot com>)
michaelni
parents:
889
diff
changeset
|
95 return rval; |
0 | 96 } else if (ebx == 0x69727943 && |
97 edx == 0x736e4978 && | |
98 ecx == 0x64616574) { | |
99 /* Cyrix Section */ | |
100 /* See if extended CPUID level 80000001 is supported */ | |
101 /* The value of CPUID/80000001 for the 6x86MX is undefined | |
102 according to the Cyrix CPU Detection Guide (Preliminary | |
103 Rev. 1.01 table 1), so we'll check the value of eax for | |
104 CPUID/0 to see if standard CPUID level 2 is supported. | |
105 According to the table, the only CPU which supports level | |
106 2 is also the only one which supports extended CPUID levels. | |
107 */ | |
108 if (eax != 2) | |
109 goto inteltest; | |
22
c31fb57d17a6
Suppressing external gas stuff to improve portability to Win32
nickols_k
parents:
16
diff
changeset
|
110 cpuid(0x80000001, eax, ebx, ecx, edx); |
0 | 111 if ((eax & 0x00800000) == 0) |
112 return 0; | |
113 rval = MM_MMX; | |
114 if (eax & 0x01000000) | |
115 rval |= MM_MMXEXT; | |
116 return rval; | |
117 } else { | |
118 return 0; | |
119 } | |
120 } | |
43 | 121 |
122 #ifdef __TEST__ | |
123 int main ( void ) | |
124 { | |
125 int mm_flags; | |
126 mm_flags = mm_support(); | |
127 printf("mm_support = 0x%08u\n",mm_flags); | |
128 return 0; | |
129 } | |
130 #endif |