media/libtheora/lib/arm/armcpu.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libtheora/lib/arm/armcpu.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,116 @@
     1.4 +/********************************************************************
     1.5 + *                                                                  *
     1.6 + * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE.   *
     1.7 + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
     1.8 + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
     1.9 + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
    1.10 + *                                                                  *
    1.11 + * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2010                *
    1.12 + * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
    1.13 + *                                                                  *
    1.14 + ********************************************************************
    1.15 +
    1.16 + CPU capability detection for ARM processors.
    1.17 +
    1.18 + function:
    1.19 +  last mod: $Id: cpu.c 17344 2010-07-21 01:42:18Z tterribe $
    1.20 +
    1.21 + ********************************************************************/
    1.22 +
    1.23 +#include "armcpu.h"
    1.24 +
    1.25 +#if !defined(OC_ARM_ASM)|| \
    1.26 + !defined(OC_ARM_ASM_EDSP)&&!defined(OC_ARM_ASM_ARMV6)&& \
    1.27 + !defined(OC_ARM_ASM_NEON)
    1.28 +ogg_uint32_t oc_cpu_flags_get(void){
    1.29 +  return 0;
    1.30 +}
    1.31 +
    1.32 +#elif defined(_MSC_VER)
    1.33 +/*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/
    1.34 +# define WIN32_LEAN_AND_MEAN
    1.35 +# define WIN32_EXTRA_LEAN
    1.36 +# include <windows.h>
    1.37 +
    1.38 +ogg_uint32_t oc_cpu_flags_get(void){
    1.39 +  ogg_uint32_t flags;
    1.40 +  flags=0;
    1.41 +  /*MSVC has no inline __asm support for ARM, but it does let you __emit
    1.42 +     instructions via their assembled hex code.
    1.43 +    All of these instructions should be essentially nops.*/
    1.44 +# if defined(OC_ARM_ASM_EDSP)
    1.45 +  __try{
    1.46 +    /*PLD [r13]*/
    1.47 +    __emit(0xF5DDF000);
    1.48 +    flags|=OC_CPU_ARM_EDSP;
    1.49 +  }
    1.50 +  __except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){
    1.51 +    /*Ignore exception.*/
    1.52 +  }
    1.53 +#  if defined(OC_ARM_ASM_MEDIA)
    1.54 +  __try{
    1.55 +    /*SHADD8 r3,r3,r3*/
    1.56 +    __emit(0xE6333F93);
    1.57 +    flags|=OC_CPU_ARM_MEDIA;
    1.58 +  }
    1.59 +  __except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){
    1.60 +    /*Ignore exception.*/
    1.61 +  }
    1.62 +#   if defined(OC_ARM_ASM_NEON)
    1.63 +  __try{
    1.64 +    /*VORR q0,q0,q0*/
    1.65 +    __emit(0xF2200150);
    1.66 +    flags|=OC_CPU_ARM_NEON;
    1.67 +  }
    1.68 +  __except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){
    1.69 +    /*Ignore exception.*/
    1.70 +  }
    1.71 +#   endif
    1.72 +#  endif
    1.73 +# endif
    1.74 +  return flags;
    1.75 +}
    1.76 +
    1.77 +#elif defined(__linux__)
    1.78 +# include <stdio.h>
    1.79 +# include <stdlib.h>
    1.80 +# include <string.h>
    1.81 +
    1.82 +ogg_uint32_t oc_cpu_flags_get(void){
    1.83 +  ogg_uint32_t  flags;
    1.84 +  FILE         *fin;
    1.85 +  flags=0;
    1.86 +  /*Reading /proc/self/auxv would be easier, but that doesn't work reliably on
    1.87 +     Android.
    1.88 +    This also means that detection will fail in Scratchbox.*/
    1.89 +  fin=fopen("/proc/cpuinfo","r");
    1.90 +  if(fin!=NULL){
    1.91 +    /*512 should be enough for anybody (it's even enough for all the flags that
    1.92 +       x86 has accumulated... so far).*/
    1.93 +    char buf[512];
    1.94 +    while(fgets(buf,511,fin)!=NULL){
    1.95 +      if(memcmp(buf,"Features",8)==0){
    1.96 +        char *p;
    1.97 +        p=strstr(buf," edsp");
    1.98 +        if(p!=NULL&&(p[5]==' '||p[5]=='\n'))flags|=OC_CPU_ARM_EDSP;
    1.99 +        p=strstr(buf," neon");
   1.100 +        if(p!=NULL&&(p[5]==' '||p[5]=='\n'))flags|=OC_CPU_ARM_NEON;
   1.101 +      }
   1.102 +      if(memcmp(buf,"CPU architecture:",17)==0){
   1.103 +        int version;
   1.104 +        version=atoi(buf+17);
   1.105 +        if(version>=6)flags|=OC_CPU_ARM_MEDIA;
   1.106 +      }
   1.107 +    }
   1.108 +    fclose(fin);
   1.109 +  }
   1.110 +  return flags;
   1.111 +}
   1.112 +
   1.113 +#else
   1.114 +/*The feature registers which can tell us what the processor supports are
   1.115 +   accessible in priveleged modes only, so we can't have a general user-space
   1.116 +   detection method like on x86.*/
   1.117 +# error "Configured to use ARM asm but no CPU detection method available for " \
   1.118 + "your platform.  Reconfigure with --disable-asm (or send patches)."
   1.119 +#endif

mercurial