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 /* TODO(kma): Replace some assembly code with GCC intrinsics
19 * (e.g. __builtin_clz).
20 */
21
22 /* This function produces result that is not bit exact with that by the generic
23 * C version in some cases, although the former is at least as accurate as the
24 * later.
25 */
WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a,int32_t b)26 static __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a, int32_t b) {
27 int32_t tmp = 0;
28 __asm __volatile("smulwb %0, %1, %2" : "=r"(tmp) : "r"(b), "r"(a));
29 return tmp;
30 }
31
WEBRTC_SPL_MUL_16_16(int16_t a,int16_t b)32 static __inline int32_t WEBRTC_SPL_MUL_16_16(int16_t a, int16_t b) {
33 int32_t tmp = 0;
34 __asm __volatile("smulbb %0, %1, %2" : "=r"(tmp) : "r"(a), "r"(b));
35 return tmp;
36 }
37
38 // TODO(kma): add unit test.
WebRtc_MulAccumW16(int16_t a,int16_t b,int32_t c)39 static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) {
40 int32_t tmp = 0;
41 __asm __volatile("smlabb %0, %1, %2, %3"
42 : "=r"(tmp)
43 : "r"(a), "r"(b), "r"(c));
44 return tmp;
45 }
46
WebRtcSpl_AddSatW16(int16_t a,int16_t b)47 static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {
48 int32_t s_sum = 0;
49
50 __asm __volatile("qadd16 %0, %1, %2" : "=r"(s_sum) : "r"(a), "r"(b));
51
52 return (int16_t)s_sum;
53 }
54
WebRtcSpl_AddSatW32(int32_t l_var1,int32_t l_var2)55 static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) {
56 int32_t l_sum = 0;
57
58 __asm __volatile("qadd %0, %1, %2" : "=r"(l_sum) : "r"(l_var1), "r"(l_var2));
59
60 return l_sum;
61 }
62
WebRtcSpl_SubSatW32(int32_t l_var1,int32_t l_var2)63 static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) {
64 int32_t l_sub = 0;
65
66 __asm __volatile("qsub %0, %1, %2" : "=r"(l_sub) : "r"(l_var1), "r"(l_var2));
67
68 return l_sub;
69 }
70
WebRtcSpl_SubSatW16(int16_t var1,int16_t var2)71 static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {
72 int32_t s_sub = 0;
73
74 __asm __volatile("qsub16 %0, %1, %2" : "=r"(s_sub) : "r"(var1), "r"(var2));
75
76 return (int16_t)s_sub;
77 }
78
WebRtcSpl_GetSizeInBits(uint32_t n)79 static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {
80 int32_t tmp = 0;
81
82 __asm __volatile("clz %0, %1" : "=r"(tmp) : "r"(n));
83
84 return (int16_t)(32 - tmp);
85 }
86
WebRtcSpl_NormW32(int32_t a)87 static __inline int16_t WebRtcSpl_NormW32(int32_t a) {
88 int32_t tmp = 0;
89
90 if (a == 0) {
91 return 0;
92 } else if (a < 0) {
93 a ^= 0xFFFFFFFF;
94 }
95
96 __asm __volatile("clz %0, %1" : "=r"(tmp) : "r"(a));
97
98 return (int16_t)(tmp - 1);
99 }
100
WebRtcSpl_NormU32(uint32_t a)101 static __inline int16_t WebRtcSpl_NormU32(uint32_t a) {
102 int tmp = 0;
103
104 if (a == 0)
105 return 0;
106
107 __asm __volatile("clz %0, %1" : "=r"(tmp) : "r"(a));
108
109 return (int16_t)tmp;
110 }
111
WebRtcSpl_NormW16(int16_t a)112 static __inline int16_t WebRtcSpl_NormW16(int16_t a) {
113 int32_t tmp = 0;
114 int32_t a_32 = a;
115
116 if (a_32 == 0) {
117 return 0;
118 } else if (a_32 < 0) {
119 a_32 ^= 0xFFFFFFFF;
120 }
121
122 __asm __volatile("clz %0, %1" : "=r"(tmp) : "r"(a_32));
123
124 return (int16_t)(tmp - 17);
125 }
126
127 // TODO(kma): add unit test.
WebRtcSpl_SatW32ToW16(int32_t value32)128 static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {
129 int32_t out = 0;
130
131 __asm __volatile("ssat %0, #16, %1" : "=r"(out) : "r"(value32));
132
133 return (int16_t)out;
134 }
135
136 #endif // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_
137