reenable building internal ffmpeg
[cinelerra_cv/ct.git] / mpeg2enc / cpu_accel.c
blobf898d25f088df6f6dbced51c7a0c2c756412251a
1 /*
2 * cpu_accel.c
3 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
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.
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.
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
22 #include <stdio.h>
23 #include <inttypes.h>
25 #include "cpu_accel.h"
27 #ifdef X86_CPU
28 static int x86_accel (void)
30 int eax, ebx, ecx, edx;
31 int AMD;
32 int caps;
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")
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)
54 : "cc");
56 if (eax == ebx) // no cpuid
57 return 0;
59 cpuid (0x00000000, eax, ebx, ecx, edx);
60 if (!eax) // vendor string only
61 return 0;
63 AMD = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
65 cpuid (0x00000001, eax, ebx, ecx, edx);
66 if (! (edx & 0x00800000)) // no MMX
67 return 0;
69 caps = ACCEL_X86_MMX;
70 if (edx & 0x02000000) // SSE - identical to AMD MMX extensions
71 caps = ACCEL_X86_MMX | ACCEL_X86_MMXEXT;
73 cpuid (0x80000000, eax, ebx, ecx, edx);
74 if (eax < 0x80000001) // no extended capabilities
75 return caps;
77 cpuid (0x80000001, eax, ebx, ecx, edx);
79 if (edx & 0x80000000)
80 caps |= ACCEL_X86_3DNOW;
82 if (AMD && (edx & 0x00400000)) // AMD MMX extensions
84 caps |= ACCEL_X86_MMXEXT;
87 return caps;
89 #endif
91 int cpu_accel (void)
93 #ifdef X86_CPU
94 static int got_accel = 0;
95 static int accel;
97 if (!got_accel) {
98 got_accel = 1;
99 accel = x86_accel ();
102 return accel;
103 #else
104 return 0;
105 #endif