1 /*****************************************************************************
2 * cpu.c: h264 encoder library
3 *****************************************************************************
4 * Copyright (C) 2003 Laurent Aimar
5 * $Id: cpu.c,v 1.1 2004/06/03 19:27:06 fenrir Exp $
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
28 #if defined(ARCH_X86) || defined(ARCH_X86_64)
29 extern int x264_cpu_cpuid_test( void );
30 extern uint32_t x264_cpu_cpuid( uint32_t op, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx );
31 extern void x264_emms( void );
33 uint32_t x264_cpu_detect( void )
37 uint32_t eax, ebx, ecx, edx;
41 if( !x264_cpu_cpuid_test() )
47 x264_cpu_cpuid( 0, &eax, &ebx, &ecx, &edx);
52 b_amd = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
54 x264_cpu_cpuid( 1, &eax, &ebx, &ecx, &edx );
55 if( (edx&0x00800000) == 0 )
61 if( (edx&0x02000000) )
63 /* SSE - identical to AMD MMX extensions */
64 cpu |= X264_CPU_MMXEXT|X264_CPU_SSE;
66 if( (edx&0x04000000) )
72 x264_cpu_cpuid( 0x80000000, &eax, &ebx, &ecx, &edx );
73 if( eax < 0x80000001 )
75 /* no extended capabilities */
79 x264_cpu_cpuid( 0x80000001, &eax, &ebx, &ecx, &edx );
82 cpu |= X264_CPU_3DNOW;
84 if( b_amd && (edx&0x00400000) )
86 /* AMD MMX extensions */
87 cpu |= X264_CPU_MMXEXT;
93 void x264_cpu_restore( uint32_t cpu )
95 if( cpu&(X264_CPU_MMX|X264_CPU_MMXEXT|X264_CPU_3DNOW|X264_CPU_3DNOWEXT) )
101 #elif defined( ARCH_PPC )
104 #include <sys/sysctl.h>
105 uint32_t x264_cpu_detect( void )
109 int selectors[2] = { CTL_HW, HW_VECTORUNIT };
111 size_t length = sizeof( has_altivec );
112 int error = sysctl( selectors, 2, &has_altivec, &length, NULL, 0 );
114 if( error == 0 && has_altivec != 0 )
116 cpu |= X264_CPU_ALTIVEC;
122 #elif defined( SYS_LINUX )
123 uint32_t x264_cpu_detect( void )
125 /* FIXME (Linux PPC) */
126 return X264_CPU_ALTIVEC;
130 void x264_cpu_restore( uint32_t cpu )
136 uint32_t x264_cpu_detect( void )
141 void x264_cpu_restore( uint32_t cpu )