annotate src/opus-1.3/celt/arm/armcpu.c @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 7aeed7906520
children
rev   line source
Chris@69 1 /* Copyright (c) 2010 Xiph.Org Foundation
Chris@69 2 * Copyright (c) 2013 Parrot */
Chris@69 3 /*
Chris@69 4 Redistribution and use in source and binary forms, with or without
Chris@69 5 modification, are permitted provided that the following conditions
Chris@69 6 are met:
Chris@69 7
Chris@69 8 - Redistributions of source code must retain the above copyright
Chris@69 9 notice, this list of conditions and the following disclaimer.
Chris@69 10
Chris@69 11 - Redistributions in binary form must reproduce the above copyright
Chris@69 12 notice, this list of conditions and the following disclaimer in the
Chris@69 13 documentation and/or other materials provided with the distribution.
Chris@69 14
Chris@69 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Chris@69 16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Chris@69 17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Chris@69 18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
Chris@69 19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Chris@69 20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Chris@69 21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Chris@69 22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Chris@69 23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Chris@69 24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Chris@69 25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Chris@69 26 */
Chris@69 27
Chris@69 28 /* Original code from libtheora modified to suit to Opus */
Chris@69 29
Chris@69 30 #ifdef HAVE_CONFIG_H
Chris@69 31 #include "config.h"
Chris@69 32 #endif
Chris@69 33
Chris@69 34 #ifdef OPUS_HAVE_RTCD
Chris@69 35
Chris@69 36 #include "armcpu.h"
Chris@69 37 #include "cpu_support.h"
Chris@69 38 #include "os_support.h"
Chris@69 39 #include "opus_types.h"
Chris@69 40 #include "arch.h"
Chris@69 41
Chris@69 42 #define OPUS_CPU_ARM_V4_FLAG (1<<OPUS_ARCH_ARM_V4)
Chris@69 43 #define OPUS_CPU_ARM_EDSP_FLAG (1<<OPUS_ARCH_ARM_EDSP)
Chris@69 44 #define OPUS_CPU_ARM_MEDIA_FLAG (1<<OPUS_ARCH_ARM_MEDIA)
Chris@69 45 #define OPUS_CPU_ARM_NEON_FLAG (1<<OPUS_ARCH_ARM_NEON)
Chris@69 46
Chris@69 47 #if defined(_MSC_VER)
Chris@69 48 /*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/
Chris@69 49 # define WIN32_LEAN_AND_MEAN
Chris@69 50 # define WIN32_EXTRA_LEAN
Chris@69 51 # include <windows.h>
Chris@69 52
Chris@69 53 static OPUS_INLINE opus_uint32 opus_cpu_capabilities(void){
Chris@69 54 opus_uint32 flags;
Chris@69 55 flags=0;
Chris@69 56 /* MSVC has no OPUS_INLINE __asm support for ARM, but it does let you __emit
Chris@69 57 * instructions via their assembled hex code.
Chris@69 58 * All of these instructions should be essentially nops. */
Chris@69 59 # if defined(OPUS_ARM_MAY_HAVE_EDSP) || defined(OPUS_ARM_MAY_HAVE_MEDIA) \
Chris@69 60 || defined(OPUS_ARM_MAY_HAVE_NEON) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
Chris@69 61 __try{
Chris@69 62 /*PLD [r13]*/
Chris@69 63 __emit(0xF5DDF000);
Chris@69 64 flags|=OPUS_CPU_ARM_EDSP_FLAG;
Chris@69 65 }
Chris@69 66 __except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){
Chris@69 67 /*Ignore exception.*/
Chris@69 68 }
Chris@69 69 # if defined(OPUS_ARM_MAY_HAVE_MEDIA) \
Chris@69 70 || defined(OPUS_ARM_MAY_HAVE_NEON) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
Chris@69 71 __try{
Chris@69 72 /*SHADD8 r3,r3,r3*/
Chris@69 73 __emit(0xE6333F93);
Chris@69 74 flags|=OPUS_CPU_ARM_MEDIA_FLAG;
Chris@69 75 }
Chris@69 76 __except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){
Chris@69 77 /*Ignore exception.*/
Chris@69 78 }
Chris@69 79 # if defined(OPUS_ARM_MAY_HAVE_NEON) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
Chris@69 80 __try{
Chris@69 81 /*VORR q0,q0,q0*/
Chris@69 82 __emit(0xF2200150);
Chris@69 83 flags|=OPUS_CPU_ARM_NEON_FLAG;
Chris@69 84 }
Chris@69 85 __except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){
Chris@69 86 /*Ignore exception.*/
Chris@69 87 }
Chris@69 88 # endif
Chris@69 89 # endif
Chris@69 90 # endif
Chris@69 91 return flags;
Chris@69 92 }
Chris@69 93
Chris@69 94 #elif defined(__linux__)
Chris@69 95 /* Linux based */
Chris@69 96 opus_uint32 opus_cpu_capabilities(void)
Chris@69 97 {
Chris@69 98 opus_uint32 flags = 0;
Chris@69 99 FILE *cpuinfo;
Chris@69 100
Chris@69 101 /* Reading /proc/self/auxv would be easier, but that doesn't work reliably on
Chris@69 102 * Android */
Chris@69 103 cpuinfo = fopen("/proc/cpuinfo", "r");
Chris@69 104
Chris@69 105 if(cpuinfo != NULL)
Chris@69 106 {
Chris@69 107 /* 512 should be enough for anybody (it's even enough for all the flags that
Chris@69 108 * x86 has accumulated... so far). */
Chris@69 109 char buf[512];
Chris@69 110
Chris@69 111 while(fgets(buf, 512, cpuinfo) != NULL)
Chris@69 112 {
Chris@69 113 # if defined(OPUS_ARM_MAY_HAVE_EDSP) || defined(OPUS_ARM_MAY_HAVE_MEDIA) \
Chris@69 114 || defined(OPUS_ARM_MAY_HAVE_NEON) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
Chris@69 115 /* Search for edsp and neon flag */
Chris@69 116 if(memcmp(buf, "Features", 8) == 0)
Chris@69 117 {
Chris@69 118 char *p;
Chris@69 119 p = strstr(buf, " edsp");
Chris@69 120 if(p != NULL && (p[5] == ' ' || p[5] == '\n'))
Chris@69 121 flags |= OPUS_CPU_ARM_EDSP_FLAG;
Chris@69 122
Chris@69 123 # if defined(OPUS_ARM_MAY_HAVE_NEON) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
Chris@69 124 p = strstr(buf, " neon");
Chris@69 125 if(p != NULL && (p[5] == ' ' || p[5] == '\n'))
Chris@69 126 flags |= OPUS_CPU_ARM_NEON_FLAG;
Chris@69 127 # endif
Chris@69 128 }
Chris@69 129 # endif
Chris@69 130
Chris@69 131 # if defined(OPUS_ARM_MAY_HAVE_MEDIA) \
Chris@69 132 || defined(OPUS_ARM_MAY_HAVE_NEON) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
Chris@69 133 /* Search for media capabilities (>= ARMv6) */
Chris@69 134 if(memcmp(buf, "CPU architecture:", 17) == 0)
Chris@69 135 {
Chris@69 136 int version;
Chris@69 137 version = atoi(buf+17);
Chris@69 138
Chris@69 139 if(version >= 6)
Chris@69 140 flags |= OPUS_CPU_ARM_MEDIA_FLAG;
Chris@69 141 }
Chris@69 142 # endif
Chris@69 143 }
Chris@69 144
Chris@69 145 fclose(cpuinfo);
Chris@69 146 }
Chris@69 147 return flags;
Chris@69 148 }
Chris@69 149 #else
Chris@69 150 /* The feature registers which can tell us what the processor supports are
Chris@69 151 * accessible in priveleged modes only, so we can't have a general user-space
Chris@69 152 * detection method like on x86.*/
Chris@69 153 # error "Configured to use ARM asm but no CPU detection method available for " \
Chris@69 154 "your platform. Reconfigure with --disable-rtcd (or send patches)."
Chris@69 155 #endif
Chris@69 156
Chris@69 157 int opus_select_arch(void)
Chris@69 158 {
Chris@69 159 opus_uint32 flags = opus_cpu_capabilities();
Chris@69 160 int arch = 0;
Chris@69 161
Chris@69 162 if(!(flags & OPUS_CPU_ARM_EDSP_FLAG)) {
Chris@69 163 /* Asserts ensure arch values are sequential */
Chris@69 164 celt_assert(arch == OPUS_ARCH_ARM_V4);
Chris@69 165 return arch;
Chris@69 166 }
Chris@69 167 arch++;
Chris@69 168
Chris@69 169 if(!(flags & OPUS_CPU_ARM_MEDIA_FLAG)) {
Chris@69 170 celt_assert(arch == OPUS_ARCH_ARM_EDSP);
Chris@69 171 return arch;
Chris@69 172 }
Chris@69 173 arch++;
Chris@69 174
Chris@69 175 if(!(flags & OPUS_CPU_ARM_NEON_FLAG)) {
Chris@69 176 celt_assert(arch == OPUS_ARCH_ARM_MEDIA);
Chris@69 177 return arch;
Chris@69 178 }
Chris@69 179 arch++;
Chris@69 180
Chris@69 181 celt_assert(arch == OPUS_ARCH_ARM_NEON);
Chris@69 182 return arch;
Chris@69 183 }
Chris@69 184
Chris@69 185 #endif