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
12 /* This header file includes the inline functions for ARM processors in
13 * the fix point signal processing library.
14 */
15
16 #ifndef WEBRTC_SPL_SPL_INL_ARMV7_H_
17 #define WEBRTC_SPL_SPL_INL_ARMV7_H_
18
19 /* TODO(kma): Replace some assembly code with GCC intrinsics
20 * (e.g. __builtin_clz).
21 */
22
23 /* This function produces result that is not bit exact with that by the generic
24 * C version in some cases, although the former is at least as accurate as the
25 * later.
26 */
WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a,int32_t b)27 static __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a, int32_t b) {
28 int32_t tmp = 0;
29 __asm __volatile ("smulwb %0, %1, %2":"=r"(tmp):"r"(b), "r"(a));
30 return tmp;
31 }
32
WEBRTC_SPL_MUL_16_16(int16_t a,int16_t b)33 static __inline int32_t WEBRTC_SPL_MUL_16_16(int16_t a, int16_t b) {
34 int32_t tmp = 0;
35 __asm __volatile ("smulbb %0, %1, %2":"=r"(tmp):"r"(a), "r"(b));
36 return tmp;
37 }
38
39 // TODO(kma): add unit test.
WebRtc_MulAccumW16(int16_t a,int16_t b,int32_t c)40 static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) {
41 int32_t tmp = 0;
42 __asm __volatile ("smlabb %0, %1, %2, %3":"=r"(tmp):"r"(a), "r"(b), "r"(c));
43 return tmp;
44 }
45
WebRtcSpl_AddSatW16(int16_t a,int16_t b)46 static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {
47 int32_t s_sum = 0;
48
49 __asm __volatile ("qadd16 %0, %1, %2":"=r"(s_sum):"r"(a), "r"(b));
50
51 return (int16_t) s_sum;
52 }
53
WebRtcSpl_AddSatW32(int32_t l_var1,int32_t l_var2)54 static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) {
55 int32_t l_sum = 0;
56
57 __asm __volatile ("qadd %0, %1, %2":"=r"(l_sum):"r"(l_var1), "r"(l_var2));
58
59 return l_sum;
60 }
61
WebRtcSpl_SubSatW32(int32_t l_var1,int32_t l_var2)62 static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) {
63 int32_t l_sub = 0;
64
65 __asm __volatile ("qsub %0, %1, %2":"=r"(l_sub):"r"(l_var1), "r"(l_var2));
66
67 return l_sub;
68 }
69
WebRtcSpl_SubSatW16(int16_t var1,int16_t var2)70 static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {
71 int32_t s_sub = 0;
72
73 __asm __volatile ("qsub16 %0, %1, %2":"=r"(s_sub):"r"(var1), "r"(var2));
74
75 return (int16_t)s_sub;
76 }
77
WebRtcSpl_GetSizeInBits(uint32_t n)78 static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {
79 int32_t tmp = 0;
80
81 __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(n));
82
83 return (int16_t)(32 - tmp);
84 }
85
WebRtcSpl_NormW32(int32_t a)86 static __inline int16_t WebRtcSpl_NormW32(int32_t a) {
87 int32_t tmp = 0;
88
89 if (a == 0) {
90 return 0;
91 }
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) return 0;
105
106 __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a));
107
108 return (int16_t)tmp;
109 }
110
WebRtcSpl_NormW16(int16_t a)111 static __inline int16_t WebRtcSpl_NormW16(int16_t a) {
112 int32_t tmp = 0;
113 int32_t a_32 = a;
114
115 if (a_32 == 0) {
116 return 0;
117 }
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 // WEBRTC_SPL_SPL_INL_ARMV7_H_
137