⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpu.c

📁 在dsp上实现h.264编解码
💻 C
字号:
/***************************************************************************** * cpu.c: h264 encoder library ***************************************************************************** * Copyright (C) 2003 Laurent Aimar
 * $Id: SHU264.h,v 1.1 2006/02/03 19:24:12 fenrir Exp $
 *
 * Authors: jsslq <jsslq@163.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA. *****************************************************************************/#ifdef HAVE_STDINT_H#include <stdint.h>#else#include <inttypes.h>#endif#include <stdlib.h>#include <string.h>#include <stdarg.h>#include "SHU264.h"#include "cpu.h"#if defined(ARCH_X86) || defined(ARCH_X86_64)extern int  SHU264_cpu_cpuid_test( void );extern uint32_t  SHU264_cpu_cpuid( uint32_t op, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx );extern void SHU264_emms( void );uint32_t SHU264_cpu_detect( void ){    uint32_t cpu = 0;    uint32_t eax, ebx, ecx, edx;    int      b_amd;    if( !SHU264_cpu_cpuid_test() )    {        /* No cpuid */        return 0;    }    SHU264_cpu_cpuid( 0, &eax, &ebx, &ecx, &edx);    if( eax == 0 )    {        return 0;    }    b_amd   = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);    SHU264_cpu_cpuid( 1, &eax, &ebx, &ecx, &edx );    if( (edx&0x00800000) == 0 )    {        /* No MMX */        return 0;    }    cpu = SHU264_CPU_MMX;    if( (edx&0x02000000) )    {        /* SSE - identical to AMD MMX extensions */        cpu |= SHU264_CPU_MMXEXT|SHU264_CPU_SSE;    }    if( (edx&0x04000000) )    {        /* Is it OK ? */        cpu |= SHU264_CPU_SSE2;    }    SHU264_cpu_cpuid( 0x80000000, &eax, &ebx, &ecx, &edx );    if( eax < 0x80000001 )    {        /* no extended capabilities */        return cpu;    }    SHU264_cpu_cpuid( 0x80000001, &eax, &ebx, &ecx, &edx );    if( edx&0x80000000 )    {        cpu |= SHU264_CPU_3DNOW;    }    if( b_amd && (edx&0x00400000) )    {        /* AMD MMX extensions */        cpu |= SHU264_CPU_MMXEXT;    }    return cpu;}void     SHU264_cpu_restore( uint32_t cpu ){    if( cpu&(SHU264_CPU_MMX|SHU264_CPU_MMXEXT|SHU264_CPU_3DNOW|SHU264_CPU_3DNOWEXT) )    {        SHU264_emms();    }}#elif defined( ARCH_PPC )#ifdef SYS_MACOSX#include <sys/sysctl.h>uint32_t SHU264_cpu_detect( void ){    /* Thank you VLC */    uint32_t cpu = 0;    int      selectors[2] = { CTL_HW, HW_VECTORUNIT };    int      has_altivec = 0;    size_t   length = sizeof( has_altivec );    int      error = sysctl( selectors, 2, &has_altivec, &length, NULL, 0 );    if( error == 0 && has_altivec != 0 )    {        cpu |= SHU264_CPU_ALTIVEC;    }    return cpu;}#elif defined( SYS_LINUX )uint32_t SHU264_cpu_detect( void ){    /* FIXME (Linux PPC) */    return SHU264_CPU_ALTIVEC;}#endifvoid     SHU264_cpu_restore( uint32_t cpu ){}#elseuint32_t SHU264_cpu_detect( void ){    return 0;}void     SHU264_cpu_restore( uint32_t cpu ){}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -