spl_inl_armv7.h (3507B)
1 /* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 /* This header file includes the inline functions for ARM processors in 12 * the fix point signal processing library. 13 */ 14 15 #ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_ 16 #define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_ 17 18 #include <stdint.h> 19 20 /* TODO(kma): Replace some assembly code with GCC intrinsics 21 * (e.g. __builtin_clz). 22 */ 23 24 /* This function produces result that is not bit exact with that by the generic 25 * C version in some cases, although the former is at least as accurate as the 26 * later. 27 */ 28 static __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a, int32_t b) { 29 int32_t tmp = 0; 30 __asm __volatile("smulwb %0, %1, %2" : "=r"(tmp) : "r"(b), "r"(a)); 31 return tmp; 32 } 33 34 static __inline int32_t WEBRTC_SPL_MUL_16_16(int16_t a, int16_t b) { 35 int32_t tmp = 0; 36 __asm __volatile("smulbb %0, %1, %2" : "=r"(tmp) : "r"(a), "r"(b)); 37 return tmp; 38 } 39 40 // TODO(kma): add unit test. 41 static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) { 42 int32_t tmp = 0; 43 __asm __volatile("smlabb %0, %1, %2, %3" 44 : "=r"(tmp) 45 : "r"(a), "r"(b), "r"(c)); 46 return tmp; 47 } 48 49 static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) { 50 int32_t s_sum = 0; 51 52 __asm __volatile("qadd16 %0, %1, %2" : "=r"(s_sum) : "r"(a), "r"(b)); 53 54 return (int16_t)s_sum; 55 } 56 57 static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) { 58 int32_t l_sum = 0; 59 60 __asm __volatile("qadd %0, %1, %2" : "=r"(l_sum) : "r"(l_var1), "r"(l_var2)); 61 62 return l_sum; 63 } 64 65 static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) { 66 int32_t l_sub = 0; 67 68 __asm __volatile("qsub %0, %1, %2" : "=r"(l_sub) : "r"(l_var1), "r"(l_var2)); 69 70 return l_sub; 71 } 72 73 static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) { 74 int32_t s_sub = 0; 75 76 __asm __volatile("qsub16 %0, %1, %2" : "=r"(s_sub) : "r"(var1), "r"(var2)); 77 78 return (int16_t)s_sub; 79 } 80 81 static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) { 82 int32_t tmp = 0; 83 84 __asm __volatile("clz %0, %1" : "=r"(tmp) : "r"(n)); 85 86 return (int16_t)(32 - tmp); 87 } 88 89 static __inline int16_t WebRtcSpl_NormW32(int32_t a) { 90 int32_t tmp = 0; 91 92 if (a == 0) { 93 return 0; 94 } else if (a < 0) { 95 a ^= 0xFFFFFFFF; 96 } 97 98 __asm __volatile("clz %0, %1" : "=r"(tmp) : "r"(a)); 99 100 return (int16_t)(tmp - 1); 101 } 102 103 static __inline int16_t WebRtcSpl_NormU32(uint32_t a) { 104 int tmp = 0; 105 106 if (a == 0) 107 return 0; 108 109 __asm __volatile("clz %0, %1" : "=r"(tmp) : "r"(a)); 110 111 return (int16_t)tmp; 112 } 113 114 static __inline int16_t WebRtcSpl_NormW16(int16_t a) { 115 int32_t tmp = 0; 116 int32_t a_32 = a; 117 118 if (a_32 == 0) { 119 return 0; 120 } else if (a_32 < 0) { 121 a_32 ^= 0xFFFFFFFF; 122 } 123 124 __asm __volatile("clz %0, %1" : "=r"(tmp) : "r"(a_32)); 125 126 return (int16_t)(tmp - 17); 127 } 128 129 // TODO(kma): add unit test. 130 static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) { 131 int32_t out = 0; 132 133 __asm __volatile("ssat %0, #16, %1" : "=r"(out) : "r"(value32)); 134 135 return (int16_t)out; 136 } 137 138 #endif // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_