add mask color radio btn sel, fix del all mask btn, fix mask dflt kfrm draw name...
[goodguy/cinelerra.git] / cinelerra-5.1 / mpeg2enc / cpu_accel.c
1 /*
2  * cpu_accel.c
3  * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
4  *
5  * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
6  *
7  * mpeg2dec is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * mpeg2dec is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <stdio.h>
23 #include <inttypes.h>
24
25 #include "cpu_accel.h"
26
27 #ifdef X86_CPU
28 static int x86_accel (void)
29 {
30     int eax, ebx, ecx, edx;
31     int AMD;
32     int caps;
33
34 #define cpuid(op,eax,ebx,ecx,edx)       \
35     asm ("cpuid"                        \
36          : "=a" (eax),                  \
37            "=b" (ebx),                  \
38            "=c" (ecx),                  \
39            "=d" (edx)                   \
40          : "a" (op)                     \
41          : "cc")
42
43     asm ("pushfl\n\t"
44          "popl %0\n\t"
45          "movl %0,%1\n\t"
46          "xorl $0x200000,%0\n\t"
47          "pushl %0\n\t"
48          "popfl\n\t"
49          "pushfl\n\t"
50          "popl %0"
51          : "=a" (eax),
52            "=b" (ebx)
53          :
54          : "cc");
55
56     if (eax == ebx)             // no cpuid
57         return 0;
58
59     cpuid (0x00000000, eax, ebx, ecx, edx);
60     if (!eax)                   // vendor string only
61         return 0;
62
63     AMD = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
64
65     cpuid (0x00000001, eax, ebx, ecx, edx);
66     if (! (edx & 0x00800000))   // no MMX
67         return 0;
68
69     caps = ACCEL_X86_MMX;
70     if (edx & 0x02000000)       // SSE - identical to AMD MMX extensions
71         caps = ACCEL_X86_MMX | ACCEL_X86_MMXEXT;
72
73     cpuid (0x80000000, eax, ebx, ecx, edx);
74     if (eax < 0x80000001)       // no extended capabilities
75         return caps;
76
77     cpuid (0x80000001, eax, ebx, ecx, edx);
78
79     if (edx & 0x80000000)
80         caps |= ACCEL_X86_3DNOW;
81
82     if (AMD && (edx & 0x00400000))      // AMD MMX extensions
83         {
84                 caps |= ACCEL_X86_MMXEXT;
85         }
86
87     return caps;
88 }
89 #endif
90
91 int cpu_accel (void)
92 {
93 #ifdef X86_CPU
94     static int got_accel = 0;
95     static int accel;
96
97     if (!got_accel) {
98         got_accel = 1;
99         accel = x86_accel ();
100     }
101
102     return accel;
103 #else
104     return 0;
105 #endif
106 }