annotate i386/cputest.c @ 3623:d0242f36a793 libavcodec

reduce size of vlc table, thats slightly faster here
author michael
date Fri, 25 Aug 2006 12:26:34 +0000
parents 647a677c00a4
children c537a97eec66
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
429
718a22dc121f license/copyright change
glantau
parents: 43
diff changeset
2 and R. Fisher). Converted to C and improved by Fabrice Bellard */
0
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
2293
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2129
diff changeset
7 #ifdef ARCH_X86_64
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2129
diff changeset
8 # define REG_b "rbx"
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2129
diff changeset
9 # define REG_S "rsi"
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2129
diff changeset
10 #else
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2129
diff changeset
11 # define REG_b "ebx"
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2129
diff changeset
12 # define REG_S "esi"
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2129
diff changeset
13 #endif
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2129
diff changeset
14
22
c31fb57d17a6 Suppressing external gas stuff to improve portability to Win32
nickols_k
parents: 16
diff changeset
15 /* 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
16 #define cpuid(index,eax,ebx,ecx,edx)\
43
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
17 __asm __volatile\
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
18 ("mov %%"REG_b", %%"REG_S"\n\t"\
22
c31fb57d17a6 Suppressing external gas stuff to improve portability to Win32
nickols_k
parents: 16
diff changeset
19 "cpuid\n\t"\
2293
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2129
diff changeset
20 "xchg %%"REG_b", %%"REG_S\
22
c31fb57d17a6 Suppressing external gas stuff to improve portability to Win32
nickols_k
parents: 16
diff changeset
21 : "=a" (eax), "=S" (ebx),\
c31fb57d17a6 Suppressing external gas stuff to improve portability to Win32
nickols_k
parents: 16
diff changeset
22 "=c" (ecx), "=d" (edx)\
43
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
23 : "0" (index));
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
24
986e461dc072 Initial revision
glantau
parents:
diff changeset
25 /* Function to test if multimedia instructions are supported... */
986e461dc072 Initial revision
glantau
parents:
diff changeset
26 int mm_support(void)
986e461dc072 Initial revision
glantau
parents:
diff changeset
27 {
2377
9214c91cdfb7 detect sse on athlon-xp patch by (matthieu castet <castet >.< matthieu >at< free >.< fr>)
michael
parents: 2300
diff changeset
28 int rval = 0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
29 int eax, ebx, ecx, edx;
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
30 int max_std_level, max_ext_level, std_caps=0, ext_caps=0;
2300
40542ea560d5 gcc 3.4.3 preversions do not appreciate invalid instruction and operand combinations anymore patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2293
diff changeset
31 long a, c;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
32
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
33 __asm__ __volatile__ (
986e461dc072 Initial revision
glantau
parents:
diff changeset
34 /* See if CPUID instruction is supported ... */
986e461dc072 Initial revision
glantau
parents:
diff changeset
35 /* ... Get copies of EFLAGS into eax and ecx */
986e461dc072 Initial revision
glantau
parents:
diff changeset
36 "pushf\n\t"
2293
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2129
diff changeset
37 "pop %0\n\t"
2300
40542ea560d5 gcc 3.4.3 preversions do not appreciate invalid instruction and operand combinations anymore patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2293
diff changeset
38 "mov %0, %1\n\t"
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
39
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
40 /* ... Toggle the ID bit in one copy and store */
986e461dc072 Initial revision
glantau
parents:
diff changeset
41 /* to the EFLAGS reg */
2300
40542ea560d5 gcc 3.4.3 preversions do not appreciate invalid instruction and operand combinations anymore patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2293
diff changeset
42 "xor $0x200000, %0\n\t"
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
43 "push %0\n\t"
986e461dc072 Initial revision
glantau
parents:
diff changeset
44 "popf\n\t"
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
45
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
46 /* ... Get the (hopefully modified) EFLAGS */
986e461dc072 Initial revision
glantau
parents:
diff changeset
47 "pushf\n\t"
2293
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2129
diff changeset
48 "pop %0\n\t"
2300
40542ea560d5 gcc 3.4.3 preversions do not appreciate invalid instruction and operand combinations anymore patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2293
diff changeset
49 : "=a" (a), "=c" (c)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
50 :
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
51 : "cc"
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
52 );
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
53
2300
40542ea560d5 gcc 3.4.3 preversions do not appreciate invalid instruction and operand combinations anymore patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2293
diff changeset
54 if (a == c)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
55 return 0; /* CPUID not supported */
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
56
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
57 cpuid(0, max_std_level, ebx, ecx, edx);
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
58
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
59 if(max_std_level >= 1){
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
60 cpuid(1, eax, ebx, ecx, std_caps);
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
61 if (std_caps & (1<<23))
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
62 rval |= MM_MMX;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
63 if (std_caps & (1<<25))
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
64 rval |= MM_MMXEXT | MM_SSE;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
65 if (std_caps & (1<<26))
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
66 rval |= MM_SSE2;
3279
647a677c00a4 Remove unused and unsupported Cyrix's "Extended MMX",
gpoirier
parents: 2979
diff changeset
67 if (ecx & 1)
647a677c00a4 Remove unused and unsupported Cyrix's "Extended MMX",
gpoirier
parents: 2979
diff changeset
68 rval |= MM_SSE3;
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
69 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
70
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
71 cpuid(0x80000000, max_ext_level, ebx, ecx, edx);
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
72
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
73 if(max_ext_level >= 0x80000001){
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
74 cpuid(0x80000001, eax, ebx, ecx, ext_caps);
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
75 if (ext_caps & (1<<31))
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
76 rval |= MM_3DNOW;
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
77 if (ext_caps & (1<<30))
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
78 rval |= MM_3DNOWEXT;
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
79 if (ext_caps & (1<<23))
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
80 rval |= MM_MMX;
3279
647a677c00a4 Remove unused and unsupported Cyrix's "Extended MMX",
gpoirier
parents: 2979
diff changeset
81 if (ext_caps & (1<<22))
647a677c00a4 Remove unused and unsupported Cyrix's "Extended MMX",
gpoirier
parents: 2979
diff changeset
82 rval |= MM_MMXEXT;
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
83 }
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
84
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
85 #if 0
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
86 av_log(NULL, AV_LOG_DEBUG, "%s%s%s%s%s%s\n",
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
87 (rval&MM_MMX) ? "MMX ":"",
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
88 (rval&MM_MMXEXT) ? "MMX2 ":"",
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
89 (rval&MM_SSE) ? "SSE ":"",
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
90 (rval&MM_SSE2) ? "SSE2 ":"",
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
91 (rval&MM_3DNOW) ? "3DNow ":"",
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
92 (rval&MM_3DNOWEXT) ? "3DNowExt ":"");
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
93 #endif
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
94 return rval;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
95 }
43
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
96
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
97 #ifdef __TEST__
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
98 int main ( void )
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
99 {
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
100 int mm_flags;
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
101 mm_flags = mm_support();
2129
b60148985201 10l and better MMX/SSE detection for VIA1000
michael
parents: 2092
diff changeset
102 printf("mm_support = 0x%08X\n",mm_flags);
43
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
103 return 0;
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
104 }
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
105 #endif