Debian Codegraph @

3rdparty/iaxclient/lib/libspeex/fixed_arm4.h

raw symbols SCIP
1 /* Copyright (C) 2004 Jean-Marc Valin */
2 /**
3 @file fixed_generic.h
4 @brief ARM4 fixed-point operations
5 */
6 /*
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10
11 - Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13
14 - Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
17
18 - Neither the name of the Xiph.org Foundation nor the names of its
19 contributors may be used to endorse or promote products derived from
20 this software without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
26 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #ifndef FIXED_ARM4_H
36 #define FIXED_ARM4_H
37
38 #define NEG16(x) (-(x))
39 #define NEG32(x) (-(x))
40 #define EXTRACT16(x) ((spx_word16_t)x)
41 #define EXTEND32(x) ((spx_word32_t)x)
42 #define SHR16(a,shift) ((a) >> (shift))
43 #define SHL16(a,shift) ((a) << (shift))
44 #define SHR32(a,shift) ((a) >> (shift))
45 #define SHL32(a,shift) ((a) << (shift))
46 #define PSHR16(a,shift) (SHR16((a)+(1<<((shift)-1)),shift))
47 #define PSHR32(a,shift) (SHR32((a)+(1<<((shift)-1)),shift))
48 #define SATURATE16(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
49 #define SATURATE32(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
50
51 #define SHR(a,shift) ((a) >> (shift))
52 #define SHL(a,shift) ((a) << (shift))
53 #define SATURATE(x,a) ((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))
54 #define PSHR(a,shift) (SHR((a)+(1<<((shift)-1)),shift))
55
56 #define ADD16(a,b) ((a)+(b))
57 #define SUB16(a,b) ((a)-(b))
58 #define ADD32(a,b) ((a)+(b))
59 #define SUB32(a,b) ((a)-(b))
60 #define ADD64(a,b) ((a)+(b))
61
62
63 /* result fits in 16 bits */
64 #define MULT16_16_16(a,b) ((a)*(b))
65
66 #define MULT16_16(a,b) ((a)*(b))
67
68
69
70
71 #define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b))))
72 #define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR((b),12)), SHR(MULT16_16((a),((b)&0x00000fff)),12))
73 #define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13))
74 //#define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR((b),14)), SHR(MULT16_16((a),((b)&0x00003fff)),14))
75 static inline spx_word32_t MULT16_32_Q14(spx_word16_t x, spx_word32_t y) {
76 int res;
77 int dummy;
78 asm (
79 "smull %0,%1,%2,%3 \n\t"
80 "mov %0, %0, lsr #14 \n\t"
81 "add %0, %0, %1, lsl #18 \n\t"
82 : "=&r"(res), "=&r" (dummy)
83 : "r"(y),"r"((int)x));
84 return(res);
85 }
86
87 #define MULT16_32_Q11(a,b) ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11))
88 #define MAC16_32_Q11(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11)))
89
90 //#define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))
91 static inline spx_word32_t MULT16_32_Q15(spx_word16_t x, spx_word32_t y) {
92 int res;
93 int dummy;
94 asm (
95 "smull %0,%1,%2,%3 \n\t"
96 "mov %0, %0, lsr #15 \n\t"
97 "add %0, %0, %1, lsl #17 \n\t"
98 : "=&r"(res), "=&r" (dummy)
99 : "r"(y),"r"((int)x));
100 return(res);
101 }
102
103 #define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15)))
104
105
106 #define MAC16_16_Q11(c,a,b) (ADD32((c),SHR(MULT16_16((a),(b)),11)))
107 #define MAC16_16_Q13(c,a,b) (ADD32((c),SHR(MULT16_16((a),(b)),13)))
108
109 #define MULT16_16_Q11_32(a,b) (SHR(MULT16_16((a),(b)),11))
110 #define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13))
111 #define MULT16_16_Q14(a,b) (SHR(MULT16_16((a),(b)),14))
112 #define MULT16_16_Q15(a,b) (SHR(MULT16_16((a),(b)),15))
113
114 #define MULT16_16_P13(a,b) (SHR(ADD32(4096,MULT16_16((a),(b))),13))
115 #define MULT16_16_P14(a,b) (SHR(ADD32(8192,MULT16_16((a),(b))),14))
116 #define MULT16_16_P15(a,b) (SHR(ADD32(16384,MULT16_16((a),(b))),15))
117
118 #define MUL_16_32_R15(a,bh,bl) ADD32(MULT16_16((a),(bh)), SHR(MULT16_16((a),(bl)),15))
119
120
121
122 static inline short DIV32_16(int a, int b)
123 {
124 int res=0;
125 int dead1, dead2, dead3, dead4, dead5;
126 __asm__ __volatile__ (
127 "\teor %5, %0, %1\n"
128 "\tmovs %4, %0\n"
129 "\trsbmi %0, %0, #0 \n"
130 "\tmovs %4, %1\n"
131 "\trsbmi %1, %1, #0 \n"
132 "\tmov %4, #1\n"
133
134 "\tsubs %3, %0, %1, asl #14 \n"
135 "\tmovpl %0, %3 \n"
136 "\torrpl %2, %2, %4, asl #14 \n"
137
138 "\tsubs %3, %0, %1, asl #13 \n"
139 "\tmovpl %0, %3 \n"
140 "\torrpl %2, %2, %4, asl #13 \n"
141
142 "\tsubs %3, %0, %1, asl #12 \n"
143 "\tmovpl %0, %3 \n"
144 "\torrpl %2, %2, %4, asl #12 \n"
145
146 "\tsubs %3, %0, %1, asl #11 \n"
147 "\tmovpl %0, %3 \n"
148 "\torrpl %2, %2, %4, asl #11 \n"
149
150 "\tsubs %3, %0, %1, asl #10 \n"
151 "\tmovpl %0, %3 \n"
152 "\torrpl %2, %2, %4, asl #10 \n"
153
154 "\tsubs %3, %0, %1, asl #9 \n"
155 "\tmovpl %0, %3 \n"
156 "\torrpl %2, %2, %4, asl #9 \n"
157
158 "\tsubs %3, %0, %1, asl #8 \n"
159 "\tmovpl %0, %3 \n"
160 "\torrpl %2, %2, %4, asl #8 \n"
161
162 "\tsubs %3, %0, %1, asl #7 \n"
163 "\tmovpl %0, %3 \n"
164 "\torrpl %2, %2, %4, asl #7 \n"
165
166 "\tsubs %3, %0, %1, asl #6 \n"
167 "\tmovpl %0, %3 \n"
168 "\torrpl %2, %2, %4, asl #6 \n"
169
170 "\tsubs %3, %0, %1, asl #5 \n"
171 "\tmovpl %0, %3 \n"
172 "\torrpl %2, %2, %4, asl #5 \n"
173
174 "\tsubs %3, %0, %1, asl #4 \n"
175 "\tmovpl %0, %3 \n"
176 "\torrpl %2, %2, %4, asl #4 \n"
177
178 "\tsubs %3, %0, %1, asl #3 \n"
179 "\tmovpl %0, %3 \n"
180 "\torrpl %2, %2, %4, asl #3 \n"
181
182 "\tsubs %3, %0, %1, asl #2 \n"
183 "\tmovpl %0, %3 \n"
184 "\torrpl %2, %2, %4, asl #2 \n"
185
186 "\tsubs %3, %0, %1, asl #1 \n"
187 "\tmovpl %0, %3 \n"
188 "\torrpl %2, %2, %4, asl #1 \n"
189
190 "\tsubs %3, %0, %1 \n"
191 "\tmovpl %0, %3 \n"
192 "\torrpl %2, %2, %4 \n"
193
194 "\tmovs %5, %5, lsr #31 \n"
195 "\trsbne %2, %2, #0 \n"
196 : "=r" (dead1), "=r" (dead2), "=r" (res),
197 "=r" (dead3), "=r" (dead4), "=r" (dead5)
198 : "0" (a), "1" (b), "2" (res)
199 : "cc"
200 );
201 return res;
202 }
203
204 #define DIV32(a,b) (((signed int)(a))/((signed int)(b)))
205
206
207
208 #endif