2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
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.
12 // This header file includes the inline functions in
13 // the fix point signal processing library.
15 #ifndef WEBRTC_SPL_SPL_INL_MIPS_H_
16 #define WEBRTC_SPL_SPL_INL_MIPS_H_
18 static __inline int32_t WEBRTC_SPL_MUL_16_16(int32_t a,
21 int32_t a1 = 0, b1 = 0;
24 #if defined(MIPS32_R2_LE)
25 "seh %[a1], %[a] \n\t"
26 "seh %[b1], %[b] \n\t"
28 "sll %[a1], %[a], 16 \n\t"
29 "sll %[b1], %[b], 16 \n\t"
30 "sra %[a1], %[a1], 16 \n\t"
31 "sra %[b1], %[b1], 16 \n\t"
33 "mul %[value32], %[a1], %[b1] \n\t"
34 : [value32] "=r" (value32), [a1] "=&r" (a1), [b1] "=&r" (b1)
35 : [a] "r" (a), [b] "r" (b)
41 static __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a,
43 int32_t value32 = 0, b1 = 0, b2 = 0;
47 #if defined(MIPS32_R2_LE)
48 "seh %[a1], %[a] \n\t"
50 "sll %[a1], %[a], 16 \n\t"
51 "sra %[a1], %[a1], 16 \n\t"
53 "andi %[b2], %[b], 0xFFFF \n\t"
54 "sra %[b1], %[b], 16 \n\t"
55 "sra %[b2], %[b2], 1 \n\t"
56 "mul %[value32], %[a1], %[b1] \n\t"
57 "mul %[b2], %[a1], %[b2] \n\t"
58 "addiu %[b2], %[b2], 0x4000 \n\t"
59 "sra %[b2], %[b2], 15 \n\t"
60 "addu %[value32], %[value32], %[b2] \n\t"
61 : [value32] "=&r" (value32), [b1] "=&r" (b1), [b2] "=&r" (b2),
63 : [a] "r" (a), [b] "r" (b)
69 #if defined(MIPS_DSP_R1_LE)
70 static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {
72 "shll_s.w %[value32], %[value32], 16 \n\t"
73 "sra %[value32], %[value32], 16 \n\t"
74 : [value32] "+r" (value32)
77 int16_t out16 = (int16_t)value32;
81 static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {
85 "addq_s.ph %[value32], %[a], %[b] \n\t"
86 : [value32] "=r" (value32)
87 : [a] "r" (a), [b] "r" (b)
89 return (int16_t)value32;
92 static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) {
96 "addq_s.w %[l_sum], %[l_var1], %[l_var2] \n\t"
97 : [l_sum] "=r" (l_sum)
98 : [l_var1] "r" (l_var1), [l_var2] "r" (l_var2)
104 static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {
108 "subq_s.ph %[value32], %[var1], %[var2] \n\t"
109 : [value32] "=r" (value32)
110 : [var1] "r" (var1), [var2] "r" (var2)
113 return (int16_t)value32;
116 static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) {
120 "subq_s.w %[l_diff], %[l_var1], %[l_var2] \n\t"
121 : [l_diff] "=r" (l_diff)
122 : [l_var1] "r" (l_var1), [l_var2] "r" (l_var2)
129 static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {
134 "clz %[bits], %[n] \n\t"
135 "subu %[bits], %[i32], %[bits] \n\t"
136 : [bits] "=&r" (bits)
137 : [n] "r" (n), [i32] "r" (i32)
140 return (int16_t)bits;
143 static __inline int16_t WebRtcSpl_NormW32(int32_t a) {
148 ".set noreorder \n\t"
150 " sra %[zeros], %[a], 31 \n\t"
152 " move %[zeros], $zero \n\t"
154 "xor %[zeros], %[a], %[zeros] \n\t"
155 "clz %[zeros], %[zeros] \n\t"
156 "addiu %[zeros], %[zeros], -1 \n\t"
159 : [zeros]"=&r"(zeros)
163 return (int16_t)zeros;
166 static __inline int16_t WebRtcSpl_NormU32(uint32_t a) {
170 "clz %[zeros], %[a] \n\t"
171 : [zeros] "=r" (zeros)
175 return (int16_t)(zeros & 0x1f);
178 static __inline int16_t WebRtcSpl_NormW16(int16_t a) {
184 ".set noreorder \n\t"
185 "bnez %[a0], 1f \n\t"
186 " sra %[zeros], %[a0], 31 \n\t"
188 " move %[zeros], $zero \n\t"
190 "xor %[zeros], %[a0], %[zeros] \n\t"
191 "clz %[zeros], %[zeros] \n\t"
192 "addiu %[zeros], %[zeros], -1 \n\t"
195 : [zeros]"=&r"(zeros)
199 return (int16_t)zeros;
202 static __inline int32_t WebRtc_MulAccumW16(int16_t a,
205 int32_t res = 0, c1 = 0;
207 #if defined(MIPS32_R2_LE)
208 "seh %[a], %[a] \n\t"
209 "seh %[b], %[b] \n\t"
211 "sll %[a], %[a], 16 \n\t"
212 "sll %[b], %[b], 16 \n\t"
213 "sra %[a], %[a], 16 \n\t"
214 "sra %[b], %[b], 16 \n\t"
216 "mul %[res], %[a], %[b] \n\t"
217 "addu %[c1], %[c], %[res] \n\t"
218 : [c1] "=r" (c1), [res] "=&r" (res)
219 : [a] "r" (a), [b] "r" (b), [c] "r" (c)
225 #endif // WEBRTC_SPL_SPL_INL_MIPS_H_