1 /*
2 * Copyright (c) 2011 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 #ifndef WEBRTC_SPL_SPL_INL_ARMV7_H_
16 #define WEBRTC_SPL_SPL_INL_ARMV7_H_
17
WEBRTC_SPL_MUL_16_32_RSFT16(WebRtc_Word16 a,WebRtc_Word32 b)18 static __inline WebRtc_Word32 WEBRTC_SPL_MUL_16_32_RSFT16(WebRtc_Word16 a,
19 WebRtc_Word32 b) {
20 WebRtc_Word32 tmp;
21 __asm__("smulwb %0, %1, %2":"=r"(tmp):"r"(b), "r"(a));
22 return tmp;
23 }
24
WEBRTC_SPL_MUL_32_32_RSFT32(WebRtc_Word16 a,WebRtc_Word16 b,WebRtc_Word32 c)25 static __inline WebRtc_Word32 WEBRTC_SPL_MUL_32_32_RSFT32(WebRtc_Word16 a,
26 WebRtc_Word16 b,
27 WebRtc_Word32 c) {
28 WebRtc_Word32 tmp;
29 __asm__("pkhbt %0, %1, %2, lsl #16" : "=r"(tmp) : "r"(b), "r"(a));
30 __asm__("smmul %0, %1, %2":"=r"(tmp):"r"(tmp), "r"(c));
31 return tmp;
32 }
33
WEBRTC_SPL_MUL_32_32_RSFT32BI(WebRtc_Word32 a,WebRtc_Word32 b)34 static __inline WebRtc_Word32 WEBRTC_SPL_MUL_32_32_RSFT32BI(WebRtc_Word32 a,
35 WebRtc_Word32 b) {
36 WebRtc_Word32 tmp;
37 __asm__("smmul %0, %1, %2":"=r"(tmp):"r"(a), "r"(b));
38 return tmp;
39 }
40
WEBRTC_SPL_MUL_16_16(WebRtc_Word16 a,WebRtc_Word16 b)41 static __inline WebRtc_Word32 WEBRTC_SPL_MUL_16_16(WebRtc_Word16 a,
42 WebRtc_Word16 b) {
43 WebRtc_Word32 tmp;
44 __asm__("smulbb %0, %1, %2":"=r"(tmp):"r"(a), "r"(b));
45 return tmp;
46 }
47
WebRtc_MulAccumW16(int16_t a,int16_t b,int32_t c)48 static __inline int32_t WebRtc_MulAccumW16(int16_t a,
49 int16_t b,
50 int32_t c) {
51 int32_t tmp = 0;
52 __asm__("smlabb %0, %1, %2, %3":"=r"(tmp):"r"(a), "r"(b), "r"(c));
53 return tmp;
54 }
55
WebRtcSpl_AddSatW16(WebRtc_Word16 a,WebRtc_Word16 b)56 static __inline WebRtc_Word16 WebRtcSpl_AddSatW16(WebRtc_Word16 a,
57 WebRtc_Word16 b) {
58 WebRtc_Word32 s_sum;
59
60 __asm__("qadd16 %0, %1, %2":"=r"(s_sum):"r"(a), "r"(b));
61
62 return (WebRtc_Word16) s_sum;
63 }
64
WebRtcSpl_AddSatW32(WebRtc_Word32 l_var1,WebRtc_Word32 l_var2)65 static __inline WebRtc_Word32 WebRtcSpl_AddSatW32(WebRtc_Word32 l_var1,
66 WebRtc_Word32 l_var2) {
67 WebRtc_Word32 l_sum;
68
69 __asm__("qadd %0, %1, %2":"=r"(l_sum):"r"(l_var1), "r"(l_var2));
70
71 return l_sum;
72 }
73
WebRtcSpl_SubSatW16(WebRtc_Word16 var1,WebRtc_Word16 var2)74 static __inline WebRtc_Word16 WebRtcSpl_SubSatW16(WebRtc_Word16 var1,
75 WebRtc_Word16 var2) {
76 WebRtc_Word32 s_sub;
77
78 __asm__("qsub16 %0, %1, %2":"=r"(s_sub):"r"(var1), "r"(var2));
79
80 return (WebRtc_Word16)s_sub;
81 }
82
WebRtcSpl_SubSatW32(WebRtc_Word32 l_var1,WebRtc_Word32 l_var2)83 static __inline WebRtc_Word32 WebRtcSpl_SubSatW32(WebRtc_Word32 l_var1,
84 WebRtc_Word32 l_var2) {
85 WebRtc_Word32 l_sub;
86
87 __asm__("qsub %0, %1, %2":"=r"(l_sub):"r"(l_var1), "r"(l_var2));
88
89 return l_sub;
90 }
91
WebRtcSpl_GetSizeInBits(WebRtc_UWord32 n)92 static __inline WebRtc_Word16 WebRtcSpl_GetSizeInBits(WebRtc_UWord32 n) {
93 WebRtc_Word32 tmp;
94
95 __asm__("clz %0, %1":"=r"(tmp):"r"(n));
96
97 return (WebRtc_Word16)(32 - tmp);
98 }
99
WebRtcSpl_NormW32(WebRtc_Word32 a)100 static __inline int WebRtcSpl_NormW32(WebRtc_Word32 a) {
101 WebRtc_Word32 tmp;
102
103 if (a <= 0) a ^= 0xFFFFFFFF;
104
105 __asm__("clz %0, %1":"=r"(tmp):"r"(a));
106
107 return tmp - 1;
108 }
109
WebRtcSpl_NormU32(WebRtc_UWord32 a)110 static __inline int WebRtcSpl_NormU32(WebRtc_UWord32 a) {
111 int tmp;
112
113 if (a == 0) return 0;
114
115 __asm__("clz %0, %1":"=r"(tmp):"r"(a));
116
117 return tmp;
118 }
119
WebRtcSpl_NormW16(WebRtc_Word16 a)120 static __inline int WebRtcSpl_NormW16(WebRtc_Word16 a) {
121 WebRtc_Word32 tmp;
122
123 if (a <= 0) a ^= 0xFFFFFFFF;
124
125 __asm__("clz %0, %1":"=r"(tmp):"r"(a));
126
127 return tmp - 17;
128 }
129
WebRtcSpl_SatW32ToW16(WebRtc_Word32 value32)130 static __inline WebRtc_Word16 WebRtcSpl_SatW32ToW16(WebRtc_Word32 value32) {
131 WebRtc_Word16 out16;
132
133 __asm__("ssat %r0, #16, %r1" : "=r"(out16) : "r"(value32));
134
135 return out16;
136 }
137 #endif // WEBRTC_SPL_SPL_INL_ARMV7_H_
138