Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / common_audio / signal_processing / include / spl_inl_armv7.h
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  */
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
33 static __inline int32_t WEBRTC_SPL_MUL_32_32_RSFT32BI(int32_t a, int32_t b) {
34   int32_t tmp = 0;
35   __asm volatile ("smmulr %0, %1, %2":"=r"(tmp):"r"(a), "r"(b));
36   return tmp;
37 }
38
39 static __inline int32_t WEBRTC_SPL_MUL_16_16(int16_t a, int16_t b) {
40   int32_t tmp = 0;
41   __asm __volatile ("smulbb %0, %1, %2":"=r"(tmp):"r"(a), "r"(b));
42   return tmp;
43 }
44
45 // TODO(kma): add unit test.
46 static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) {
47   int32_t tmp = 0;
48   __asm __volatile ("smlabb %0, %1, %2, %3":"=r"(tmp):"r"(a), "r"(b), "r"(c));
49   return tmp;
50 }
51
52 static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {
53   int32_t s_sum = 0;
54
55   __asm __volatile ("qadd16 %0, %1, %2":"=r"(s_sum):"r"(a), "r"(b));
56
57   return (int16_t) s_sum;
58 }
59
60 /* TODO(kma): find the cause of unittest errors by the next two functions:
61  * http://code.google.com/p/webrtc/issues/detail?id=740.
62  */
63 #if 0
64 static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) {
65   int32_t l_sum = 0;
66
67   __asm __volatile ("qadd %0, %1, %2":"=r"(l_sum):"r"(l_var1), "r"(l_var2));
68
69   return l_sum;
70 }
71
72 static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) {
73   int32_t l_sub = 0;
74
75   __asm __volatile ("qsub %0, %1, %2":"=r"(l_sub):"r"(l_var1), "r"(l_var2));
76
77   return l_sub;
78 }
79 #endif
80
81 static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {
82   int32_t s_sub = 0;
83
84   __asm __volatile ("qsub16 %0, %1, %2":"=r"(s_sub):"r"(var1), "r"(var2));
85
86   return (int16_t)s_sub;
87 }
88
89 static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {
90   int32_t tmp = 0;
91
92   __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(n));
93
94   return (int16_t)(32 - tmp);
95 }
96
97 static __inline int WebRtcSpl_NormW32(int32_t a) {
98   int32_t tmp = 0;
99
100   if (a == 0) {
101     return 0;
102   }
103   else if (a < 0) {
104     a ^= 0xFFFFFFFF;
105   }
106
107   __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a));
108
109   return tmp - 1;
110 }
111
112 static __inline int WebRtcSpl_NormU32(uint32_t a) {
113   int tmp = 0;
114
115   if (a == 0) return 0;
116
117   __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a));
118
119   return tmp;
120 }
121
122 static __inline int WebRtcSpl_NormW16(int16_t a) {
123   int32_t tmp = 0;
124
125   if (a == 0) {
126     return 0;
127   }
128   else if (a < 0) {
129     a ^= 0xFFFFFFFF;
130   }
131
132   __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a));
133
134   return tmp - 17;
135 }
136
137 // TODO(kma): add unit test.
138 static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {
139   int32_t out = 0;
140
141   __asm __volatile ("ssat %0, #16, %1" : "=r"(out) : "r"(value32));
142
143   return (int16_t)out;
144 }
145
146 #endif  // WEBRTC_SPL_SPL_INL_ARMV7_H_