Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /******************************************************************** |
michael@0 | 2 | * * |
michael@0 | 3 | * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. * |
michael@0 | 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
michael@0 | 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
michael@0 | 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
michael@0 | 7 | * * |
michael@0 | 8 | * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2010 * |
michael@0 | 9 | * by the Xiph.Org Foundation and contributors http://www.xiph.org/ * |
michael@0 | 10 | * * |
michael@0 | 11 | ******************************************************************** |
michael@0 | 12 | |
michael@0 | 13 | CPU capability detection for ARM processors. |
michael@0 | 14 | |
michael@0 | 15 | function: |
michael@0 | 16 | last mod: $Id: cpu.c 17344 2010-07-21 01:42:18Z tterribe $ |
michael@0 | 17 | |
michael@0 | 18 | ********************************************************************/ |
michael@0 | 19 | |
michael@0 | 20 | #include "armcpu.h" |
michael@0 | 21 | |
michael@0 | 22 | #if !defined(OC_ARM_ASM)|| \ |
michael@0 | 23 | !defined(OC_ARM_ASM_EDSP)&&!defined(OC_ARM_ASM_ARMV6)&& \ |
michael@0 | 24 | !defined(OC_ARM_ASM_NEON) |
michael@0 | 25 | ogg_uint32_t oc_cpu_flags_get(void){ |
michael@0 | 26 | return 0; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | #elif defined(_MSC_VER) |
michael@0 | 30 | /*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/ |
michael@0 | 31 | # define WIN32_LEAN_AND_MEAN |
michael@0 | 32 | # define WIN32_EXTRA_LEAN |
michael@0 | 33 | # include <windows.h> |
michael@0 | 34 | |
michael@0 | 35 | ogg_uint32_t oc_cpu_flags_get(void){ |
michael@0 | 36 | ogg_uint32_t flags; |
michael@0 | 37 | flags=0; |
michael@0 | 38 | /*MSVC has no inline __asm support for ARM, but it does let you __emit |
michael@0 | 39 | instructions via their assembled hex code. |
michael@0 | 40 | All of these instructions should be essentially nops.*/ |
michael@0 | 41 | # if defined(OC_ARM_ASM_EDSP) |
michael@0 | 42 | __try{ |
michael@0 | 43 | /*PLD [r13]*/ |
michael@0 | 44 | __emit(0xF5DDF000); |
michael@0 | 45 | flags|=OC_CPU_ARM_EDSP; |
michael@0 | 46 | } |
michael@0 | 47 | __except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){ |
michael@0 | 48 | /*Ignore exception.*/ |
michael@0 | 49 | } |
michael@0 | 50 | # if defined(OC_ARM_ASM_MEDIA) |
michael@0 | 51 | __try{ |
michael@0 | 52 | /*SHADD8 r3,r3,r3*/ |
michael@0 | 53 | __emit(0xE6333F93); |
michael@0 | 54 | flags|=OC_CPU_ARM_MEDIA; |
michael@0 | 55 | } |
michael@0 | 56 | __except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){ |
michael@0 | 57 | /*Ignore exception.*/ |
michael@0 | 58 | } |
michael@0 | 59 | # if defined(OC_ARM_ASM_NEON) |
michael@0 | 60 | __try{ |
michael@0 | 61 | /*VORR q0,q0,q0*/ |
michael@0 | 62 | __emit(0xF2200150); |
michael@0 | 63 | flags|=OC_CPU_ARM_NEON; |
michael@0 | 64 | } |
michael@0 | 65 | __except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){ |
michael@0 | 66 | /*Ignore exception.*/ |
michael@0 | 67 | } |
michael@0 | 68 | # endif |
michael@0 | 69 | # endif |
michael@0 | 70 | # endif |
michael@0 | 71 | return flags; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | #elif defined(__linux__) |
michael@0 | 75 | # include <stdio.h> |
michael@0 | 76 | # include <stdlib.h> |
michael@0 | 77 | # include <string.h> |
michael@0 | 78 | |
michael@0 | 79 | ogg_uint32_t oc_cpu_flags_get(void){ |
michael@0 | 80 | ogg_uint32_t flags; |
michael@0 | 81 | FILE *fin; |
michael@0 | 82 | flags=0; |
michael@0 | 83 | /*Reading /proc/self/auxv would be easier, but that doesn't work reliably on |
michael@0 | 84 | Android. |
michael@0 | 85 | This also means that detection will fail in Scratchbox.*/ |
michael@0 | 86 | fin=fopen("/proc/cpuinfo","r"); |
michael@0 | 87 | if(fin!=NULL){ |
michael@0 | 88 | /*512 should be enough for anybody (it's even enough for all the flags that |
michael@0 | 89 | x86 has accumulated... so far).*/ |
michael@0 | 90 | char buf[512]; |
michael@0 | 91 | while(fgets(buf,511,fin)!=NULL){ |
michael@0 | 92 | if(memcmp(buf,"Features",8)==0){ |
michael@0 | 93 | char *p; |
michael@0 | 94 | p=strstr(buf," edsp"); |
michael@0 | 95 | if(p!=NULL&&(p[5]==' '||p[5]=='\n'))flags|=OC_CPU_ARM_EDSP; |
michael@0 | 96 | p=strstr(buf," neon"); |
michael@0 | 97 | if(p!=NULL&&(p[5]==' '||p[5]=='\n'))flags|=OC_CPU_ARM_NEON; |
michael@0 | 98 | } |
michael@0 | 99 | if(memcmp(buf,"CPU architecture:",17)==0){ |
michael@0 | 100 | int version; |
michael@0 | 101 | version=atoi(buf+17); |
michael@0 | 102 | if(version>=6)flags|=OC_CPU_ARM_MEDIA; |
michael@0 | 103 | } |
michael@0 | 104 | } |
michael@0 | 105 | fclose(fin); |
michael@0 | 106 | } |
michael@0 | 107 | return flags; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | #else |
michael@0 | 111 | /*The feature registers which can tell us what the processor supports are |
michael@0 | 112 | accessible in priveleged modes only, so we can't have a general user-space |
michael@0 | 113 | detection method like on x86.*/ |
michael@0 | 114 | # error "Configured to use ARM asm but no CPU detection method available for " \ |
michael@0 | 115 | "your platform. Reconfigure with --disable-asm (or send patches)." |
michael@0 | 116 | #endif |