annotate i386/cputest.c @ 403:2c3e25f4c496 libavcodec

removed unused stuff - added dsputil_set_bit_exact() support for easier testing
author glantau
date Mon, 20 May 2002 16:37:58 +0000
parents ab64a3fc62bf
children 718a22dc121f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1 /* Cpu detection code, extracted from mmx.h ((c)1997-99 by H. Dietz
986e461dc072 Initial revision
glantau
parents:
diff changeset
2 and R. Fisher). Converted to C and improved by Gerard Lantau */
986e461dc072 Initial revision
glantau
parents:
diff changeset
3
986e461dc072 Initial revision
glantau
parents:
diff changeset
4 #include <stdlib.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
5 #include "../dsputil.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
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
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
9 __asm __volatile\
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
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
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
15 : "0" (index));
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
16
986e461dc072 Initial revision
glantau
parents:
diff changeset
17 /* Function to test if multimedia instructions are supported... */
986e461dc072 Initial revision
glantau
parents:
diff changeset
18 int mm_support(void)
986e461dc072 Initial revision
glantau
parents:
diff changeset
19 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
20 int rval;
986e461dc072 Initial revision
glantau
parents:
diff changeset
21 int eax, ebx, ecx, edx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
22
986e461dc072 Initial revision
glantau
parents:
diff changeset
23 __asm__ __volatile__ (
986e461dc072 Initial revision
glantau
parents:
diff changeset
24 /* See if CPUID instruction is supported ... */
986e461dc072 Initial revision
glantau
parents:
diff changeset
25 /* ... Get copies of EFLAGS into eax and ecx */
986e461dc072 Initial revision
glantau
parents:
diff changeset
26 "pushf\n\t"
986e461dc072 Initial revision
glantau
parents:
diff changeset
27 "popl %0\n\t"
986e461dc072 Initial revision
glantau
parents:
diff changeset
28 "movl %0, %1\n\t"
986e461dc072 Initial revision
glantau
parents:
diff changeset
29
986e461dc072 Initial revision
glantau
parents:
diff changeset
30 /* ... Toggle the ID bit in one copy and store */
986e461dc072 Initial revision
glantau
parents:
diff changeset
31 /* to the EFLAGS reg */
986e461dc072 Initial revision
glantau
parents:
diff changeset
32 "xorl $0x200000, %0\n\t"
986e461dc072 Initial revision
glantau
parents:
diff changeset
33 "push %0\n\t"
986e461dc072 Initial revision
glantau
parents:
diff changeset
34 "popf\n\t"
986e461dc072 Initial revision
glantau
parents:
diff changeset
35
986e461dc072 Initial revision
glantau
parents:
diff changeset
36 /* ... Get the (hopefully modified) EFLAGS */
986e461dc072 Initial revision
glantau
parents:
diff changeset
37 "pushf\n\t"
986e461dc072 Initial revision
glantau
parents:
diff changeset
38 "popl %0\n\t"
986e461dc072 Initial revision
glantau
parents:
diff changeset
39 : "=a" (eax), "=c" (ecx)
986e461dc072 Initial revision
glantau
parents:
diff changeset
40 :
986e461dc072 Initial revision
glantau
parents:
diff changeset
41 : "cc"
986e461dc072 Initial revision
glantau
parents:
diff changeset
42 );
986e461dc072 Initial revision
glantau
parents:
diff changeset
43
986e461dc072 Initial revision
glantau
parents:
diff changeset
44 if (eax == ecx)
986e461dc072 Initial revision
glantau
parents:
diff changeset
45 return 0; /* CPUID not supported */
986e461dc072 Initial revision
glantau
parents:
diff changeset
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
986e461dc072 Initial revision
glantau
parents:
diff changeset
48
986e461dc072 Initial revision
glantau
parents:
diff changeset
49 if (ebx == 0x756e6547 &&
986e461dc072 Initial revision
glantau
parents:
diff changeset
50 edx == 0x49656e69 &&
986e461dc072 Initial revision
glantau
parents:
diff changeset
51 ecx == 0x6c65746e) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
52
986e461dc072 Initial revision
glantau
parents:
diff changeset
53 /* intel */
986e461dc072 Initial revision
glantau
parents:
diff changeset
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
986e461dc072 Initial revision
glantau
parents:
diff changeset
56 if ((edx & 0x00800000) == 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
57 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
58 rval = MM_MMX;
986e461dc072 Initial revision
glantau
parents:
diff changeset
59 if (edx & 0x02000000)
986e461dc072 Initial revision
glantau
parents:
diff changeset
60 rval |= MM_MMXEXT | MM_SSE;
986e461dc072 Initial revision
glantau
parents:
diff changeset
61 if (edx & 0x04000000)
986e461dc072 Initial revision
glantau
parents:
diff changeset
62 rval |= MM_SSE2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
63 return rval;
986e461dc072 Initial revision
glantau
parents:
diff changeset
64 } else if (ebx == 0x68747541 &&
986e461dc072 Initial revision
glantau
parents:
diff changeset
65 edx == 0x69746e65 &&
986e461dc072 Initial revision
glantau
parents:
diff changeset
66 ecx == 0x444d4163) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
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
986e461dc072 Initial revision
glantau
parents:
diff changeset
69 if ((unsigned)eax < 0x80000001)
986e461dc072 Initial revision
glantau
parents:
diff changeset
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
986e461dc072 Initial revision
glantau
parents:
diff changeset
72 if ((edx & 0x00800000) == 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
73 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
74 rval = MM_MMX;
986e461dc072 Initial revision
glantau
parents:
diff changeset
75 if (edx & 0x80000000)
986e461dc072 Initial revision
glantau
parents:
diff changeset
76 rval |= MM_3DNOW;
986e461dc072 Initial revision
glantau
parents:
diff changeset
77 if (edx & 0x00400000)
986e461dc072 Initial revision
glantau
parents:
diff changeset
78 rval |= MM_MMXEXT;
986e461dc072 Initial revision
glantau
parents:
diff changeset
79 return rval;
986e461dc072 Initial revision
glantau
parents:
diff changeset
80 } else if (ebx == 0x69727943 &&
986e461dc072 Initial revision
glantau
parents:
diff changeset
81 edx == 0x736e4978 &&
986e461dc072 Initial revision
glantau
parents:
diff changeset
82 ecx == 0x64616574) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
83 /* Cyrix Section */
986e461dc072 Initial revision
glantau
parents:
diff changeset
84 /* See if extended CPUID level 80000001 is supported */
986e461dc072 Initial revision
glantau
parents:
diff changeset
85 /* The value of CPUID/80000001 for the 6x86MX is undefined
986e461dc072 Initial revision
glantau
parents:
diff changeset
86 according to the Cyrix CPU Detection Guide (Preliminary
986e461dc072 Initial revision
glantau
parents:
diff changeset
87 Rev. 1.01 table 1), so we'll check the value of eax for
986e461dc072 Initial revision
glantau
parents:
diff changeset
88 CPUID/0 to see if standard CPUID level 2 is supported.
986e461dc072 Initial revision
glantau
parents:
diff changeset
89 According to the table, the only CPU which supports level
986e461dc072 Initial revision
glantau
parents:
diff changeset
90 2 is also the only one which supports extended CPUID levels.
986e461dc072 Initial revision
glantau
parents:
diff changeset
91 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
92 if (eax != 2)
986e461dc072 Initial revision
glantau
parents:
diff changeset
93 goto inteltest;
22
c31fb57d17a6 Suppressing external gas stuff to improve portability to Win32
nickols_k
parents: 16
diff changeset
94 cpuid(0x80000001, eax, ebx, ecx, edx);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
95 if ((eax & 0x00800000) == 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
96 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
97 rval = MM_MMX;
986e461dc072 Initial revision
glantau
parents:
diff changeset
98 if (eax & 0x01000000)
986e461dc072 Initial revision
glantau
parents:
diff changeset
99 rval |= MM_MMXEXT;
986e461dc072 Initial revision
glantau
parents:
diff changeset
100 return rval;
986e461dc072 Initial revision
glantau
parents:
diff changeset
101 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
102 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
103 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
104 }
43
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
105
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
106 #ifdef __TEST__
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
107 int main ( void )
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
108 {
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
109 int mm_flags;
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
110 mm_flags = mm_support();
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
111 printf("mm_support = 0x%08u\n",mm_flags);
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
112 return 0;
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
113 }
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
114 #endif