annotate i386/cputest.c @ 6507:18a7d03d5059 libavcodec

get register names from x86_cpu.h
author mru
date Mon, 17 Mar 2008 23:08:19 +0000
parents 3dc36ec2dcad
children c121e5003fe1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3279
diff changeset
1 /*
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3279
diff changeset
2 * CPU detection code, extracted from mmx.h
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3279
diff changeset
3 * (c)1997-99 by H. Dietz and R. Fisher
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3279
diff changeset
4 * Converted to C and improved by Fabrice Bellard.
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3279
diff changeset
5 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3944
diff changeset
6 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3944
diff changeset
7 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3944
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3279
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3279
diff changeset
10 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3944
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3279
diff changeset
12 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3944
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3279
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3279
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3279
diff changeset
16 * Lesser General Public License for more details.
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3279
diff changeset
17 *
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3279
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3944
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3279
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 3279
diff changeset
21 */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
22
986e461dc072 Initial revision
glantau
parents:
diff changeset
23 #include <stdlib.h>
5010
d5ba514e3f4a Add libavcodec to compiler include flags in order to simplify header
diego
parents: 4311
diff changeset
24 #include "dsputil.h"
6507
18a7d03d5059 get register names from x86_cpu.h
mru
parents: 6391
diff changeset
25 #include "x86_cpu.h"
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
26
3944
edacbbf46a19 Compilation fix, printf gets redefined to please_use_av_log.
diego
parents: 3699
diff changeset
27 #undef printf
edacbbf46a19 Compilation fix, printf gets redefined to please_use_av_log.
diego
parents: 3699
diff changeset
28
22
c31fb57d17a6 Suppressing external gas stuff to improve portability to Win32
nickols_k
parents: 16
diff changeset
29 /* 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
30 #define cpuid(index,eax,ebx,ecx,edx)\
6391
3dc36ec2dcad __asm __volatile -> asm volatile, improves code consistency and works
reimar
parents: 6383
diff changeset
31 asm volatile\
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
32 ("mov %%"REG_b", %%"REG_S"\n\t"\
22
c31fb57d17a6 Suppressing external gas stuff to improve portability to Win32
nickols_k
parents: 16
diff changeset
33 "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
34 "xchg %%"REG_b", %%"REG_S\
22
c31fb57d17a6 Suppressing external gas stuff to improve portability to Win32
nickols_k
parents: 16
diff changeset
35 : "=a" (eax), "=S" (ebx),\
c31fb57d17a6 Suppressing external gas stuff to improve portability to Win32
nickols_k
parents: 16
diff changeset
36 "=c" (ecx), "=d" (edx)\
43
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
37 : "0" (index));
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
38
986e461dc072 Initial revision
glantau
parents:
diff changeset
39 /* Function to test if multimedia instructions are supported... */
986e461dc072 Initial revision
glantau
parents:
diff changeset
40 int mm_support(void)
986e461dc072 Initial revision
glantau
parents:
diff changeset
41 {
2377
9214c91cdfb7 detect sse on athlon-xp patch by (matthieu castet <castet >.< matthieu >at< free >.< fr>)
michael
parents: 2300
diff changeset
42 int rval = 0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
43 int eax, ebx, ecx, edx;
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
44 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
45 long a, c;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
46
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
47 __asm__ __volatile__ (
986e461dc072 Initial revision
glantau
parents:
diff changeset
48 /* See if CPUID instruction is supported ... */
986e461dc072 Initial revision
glantau
parents:
diff changeset
49 /* ... Get copies of EFLAGS into eax and ecx */
986e461dc072 Initial revision
glantau
parents:
diff changeset
50 "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
51 "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
52 "mov %0, %1\n\t"
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
53
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
54 /* ... Toggle the ID bit in one copy and store */
986e461dc072 Initial revision
glantau
parents:
diff changeset
55 /* 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
56 "xor $0x200000, %0\n\t"
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
57 "push %0\n\t"
986e461dc072 Initial revision
glantau
parents:
diff changeset
58 "popf\n\t"
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
59
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
60 /* ... Get the (hopefully modified) EFLAGS */
986e461dc072 Initial revision
glantau
parents:
diff changeset
61 "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
62 "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
63 : "=a" (a), "=c" (c)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
64 :
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
65 : "cc"
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
66 );
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
67
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
68 if (a == c)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
69 return 0; /* CPUID not supported */
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
70
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
71 cpuid(0, max_std_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_std_level >= 1){
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
74 cpuid(1, eax, ebx, ecx, std_caps);
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
75 if (std_caps & (1<<23))
5113
f1bfd716d347 Use FFmpeg-specific CPU feature definitions.
diego
parents: 5010
diff changeset
76 rval |= FF_MM_MMX;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
77 if (std_caps & (1<<25))
6383
7ba06222bda7 Disabling all SSE* code for old gcc to avoid alignment issues.
michael
parents: 5114
diff changeset
78 rval |= FF_MM_MMXEXT
7ba06222bda7 Disabling all SSE* code for old gcc to avoid alignment issues.
michael
parents: 5114
diff changeset
79 #if !defined(__GNUC__) || __GNUC__ > 2
7ba06222bda7 Disabling all SSE* code for old gcc to avoid alignment issues.
michael
parents: 5114
diff changeset
80 | FF_MM_SSE;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2388
diff changeset
81 if (std_caps & (1<<26))
5113
f1bfd716d347 Use FFmpeg-specific CPU feature definitions.
diego
parents: 5010
diff changeset
82 rval |= FF_MM_SSE2;
3279
647a677c00a4 Remove unused and unsupported Cyrix's "Extended MMX",
gpoirier
parents: 2979
diff changeset
83 if (ecx & 1)
5113
f1bfd716d347 Use FFmpeg-specific CPU feature definitions.
diego
parents: 5010
diff changeset
84 rval |= FF_MM_SSE3;
4311
f9325f2bc762 Add SSSE3 (Core2 aka Conroe/Merom/Woodcrester new instructions) detection
gpoirier
parents: 3947
diff changeset
85 if (ecx & 0x00000200 )
6383
7ba06222bda7 Disabling all SSE* code for old gcc to avoid alignment issues.
michael
parents: 5114
diff changeset
86 rval |= FF_MM_SSSE3
7ba06222bda7 Disabling all SSE* code for old gcc to avoid alignment issues.
michael
parents: 5114
diff changeset
87 #endif
7ba06222bda7 Disabling all SSE* code for old gcc to avoid alignment issues.
michael
parents: 5114
diff changeset
88 ;
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
89 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
90
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
91 cpuid(0x80000000, max_ext_level, ebx, ecx, edx);
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
92
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
93 if(max_ext_level >= 0x80000001){
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
94 cpuid(0x80000001, eax, ebx, ecx, ext_caps);
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
95 if (ext_caps & (1<<31))
5113
f1bfd716d347 Use FFmpeg-specific CPU feature definitions.
diego
parents: 5010
diff changeset
96 rval |= FF_MM_3DNOW;
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
97 if (ext_caps & (1<<30))
5113
f1bfd716d347 Use FFmpeg-specific CPU feature definitions.
diego
parents: 5010
diff changeset
98 rval |= FF_MM_3DNOWEXT;
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
99 if (ext_caps & (1<<23))
5113
f1bfd716d347 Use FFmpeg-specific CPU feature definitions.
diego
parents: 5010
diff changeset
100 rval |= FF_MM_MMX;
3279
647a677c00a4 Remove unused and unsupported Cyrix's "Extended MMX",
gpoirier
parents: 2979
diff changeset
101 if (ext_caps & (1<<22))
5113
f1bfd716d347 Use FFmpeg-specific CPU feature definitions.
diego
parents: 5010
diff changeset
102 rval |= FF_MM_MMXEXT;
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
103 }
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
104
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
105 #if 0
4311
f9325f2bc762 Add SSSE3 (Core2 aka Conroe/Merom/Woodcrester new instructions) detection
gpoirier
parents: 3947
diff changeset
106 av_log(NULL, AV_LOG_DEBUG, "%s%s%s%s%s%s%s%s\n",
5113
f1bfd716d347 Use FFmpeg-specific CPU feature definitions.
diego
parents: 5010
diff changeset
107 (rval&FF_MM_MMX) ? "MMX ":"",
f1bfd716d347 Use FFmpeg-specific CPU feature definitions.
diego
parents: 5010
diff changeset
108 (rval&FF_MM_MMXEXT) ? "MMX2 ":"",
f1bfd716d347 Use FFmpeg-specific CPU feature definitions.
diego
parents: 5010
diff changeset
109 (rval&FF_MM_SSE) ? "SSE ":"",
f1bfd716d347 Use FFmpeg-specific CPU feature definitions.
diego
parents: 5010
diff changeset
110 (rval&FF_MM_SSE2) ? "SSE2 ":"",
f1bfd716d347 Use FFmpeg-specific CPU feature definitions.
diego
parents: 5010
diff changeset
111 (rval&FF_MM_SSE3) ? "SSE3 ":"",
f1bfd716d347 Use FFmpeg-specific CPU feature definitions.
diego
parents: 5010
diff changeset
112 (rval&FF_MM_SSSE3) ? "SSSE3 ":"",
f1bfd716d347 Use FFmpeg-specific CPU feature definitions.
diego
parents: 5010
diff changeset
113 (rval&FF_MM_3DNOW) ? "3DNow ":"",
f1bfd716d347 Use FFmpeg-specific CPU feature definitions.
diego
parents: 5010
diff changeset
114 (rval&FF_MM_3DNOWEXT) ? "3DNowExt ":"");
2388
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
115 #endif
55a72627a2c5 x86 cpu capabilities detection rewrite / cleanup
michael
parents: 2377
diff changeset
116 return rval;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
117 }
43
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
118
5114
85b8ce118098 Preprocessor #defines starting with __ are reserved for the system.
diego
parents: 5113
diff changeset
119 #ifdef TEST
43
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
120 int main ( void )
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
121 {
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
122 int mm_flags;
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
123 mm_flags = mm_support();
2129
b60148985201 10l and better MMX/SSE detection for VIA1000
michael
parents: 2092
diff changeset
124 printf("mm_support = 0x%08X\n",mm_flags);
43
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
125 return 0;
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
126 }
ab64a3fc62bf Portability and testing issues
nickols_k
parents: 22
diff changeset
127 #endif