1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | #include "dplib.h" |
30 | #include <string.h> |
31 | |
32 | #if __GNUC__4 |
33 | #define ALWAYS_INLINE__attribute__((always_inline)) __attribute__((always_inline)) |
34 | #else |
35 | #define ALWAYS_INLINE__attribute__((always_inline)) |
36 | #endif |
37 | |
38 | #define LOOP_ALIGN |
39 | |
40 | void init_coefs( int16_t * coefs, uint32_t denshift, int32_t numPairs ) |
41 | { |
42 | int32_t k; |
43 | int32_t den = 1 << denshift; |
44 | |
45 | coefs[0] = (AINIT38 * den) >> 4; |
46 | coefs[1] = (BINIT(-29) * den) >> 4; |
47 | coefs[2] = (CINIT(-2) * den) >> 4; |
48 | for ( k = 3; k < numPairs; k++ ) |
49 | coefs[k] = 0; |
50 | } |
51 | |
52 | void copy_coefs( int16_t * srcCoefs, int16_t * dstCoefs, int32_t numPairs ) |
53 | { |
54 | int32_t k; |
55 | |
56 | for ( k = 0; k < numPairs; k++ ) |
57 | dstCoefs[k] = srcCoefs[k]; |
58 | } |
59 | |
60 | static inline int32_t ALWAYS_INLINE__attribute__((always_inline)) sign_of_int( int32_t i ) |
61 | { |
62 | int32_t negishift; |
63 | |
64 | negishift = ((uint32_t)-i) >> 31; |
65 | return negishift | (i >> 31); |
66 | } |
67 | |
68 | void pc_block( int32_t * in, int32_t * pc1, int32_t num, int16_t * coefs, int32_t numactive, uint32_t chanbits, uint32_t denshift ) |
69 | { |
70 | register int16_t a0, a1, a2, a3; |
71 | register int32_t b0, b1, b2, b3; |
72 | int32_t j, k, lim; |
73 | int32_t * pin; |
74 | int32_t sum1, dd; |
75 | int32_t sg, sgn; |
76 | int32_t top; |
77 | int32_t del, del0; |
78 | uint32_t chanshift = 32 - chanbits; |
79 | int32_t denhalf = 1 << (denshift - 1); |
80 | |
81 | pc1[0] = in[0]; |
82 | if ( numactive == 0 ) |
83 | { |
84 | |
85 | if ( (num > 1) && (in != pc1) ) |
86 | memcpy( &pc1[1], &in[1], (num - 1) * sizeof(int32_t) ); |
87 | return; |
88 | } |
89 | if ( numactive == 31 ) |
90 | { |
91 | |
92 | for( j = 1; j < num; j++ ) |
93 | { |
94 | del = in[j] - in[j-1]; |
95 | pc1[j] = (del << chanshift) >> chanshift; |
96 | } |
97 | return; |
98 | } |
99 | |
100 | for ( j = 1; j <= numactive; j++ ) |
101 | { |
102 | del = in[j] - in[j-1]; |
103 | pc1[j] = (del << chanshift) >> chanshift; |
104 | } |
105 | |
106 | lim = numactive + 1; |
107 | |
108 | if ( numactive == 4 ) |
109 | { |
110 | |
111 | a0 = coefs[0]; |
112 | a1 = coefs[1]; |
113 | a2 = coefs[2]; |
114 | a3 = coefs[3]; |
115 | |
116 | for ( j = lim; j < num; j++ ) |
117 | { |
118 | LOOP_ALIGN |
119 | |
120 | top = in[j - lim]; |
121 | pin = in + j - 1; |
122 | |
123 | b0 = top - pin[0]; |
124 | b1 = top - pin[-1]; |
125 | b2 = top - pin[-2]; |
126 | b3 = top - pin[-3]; |
127 | |
128 | sum1 = (denhalf - a0 * b0 - a1 * b1 - a2 * b2 - a3 * b3) >> denshift; |
129 | |
130 | del = in[j] - top - sum1; |
131 | del = (del << chanshift) >> chanshift; |
132 | pc1[j] = del; |
133 | del0 = del; |
134 | |
135 | sg = sign_of_int(del); |
136 | if ( sg > 0 ) |
137 | { |
138 | sgn = sign_of_int( b3 ); |
139 | a3 -= sgn; |
140 | del0 -= (4 - 3) * ((sgn * b3) >> denshift); |
141 | if ( del0 <= 0 ) |
142 | continue; |
143 | |
144 | sgn = sign_of_int( b2 ); |
145 | a2 -= sgn; |
146 | del0 -= (4 - 2) * ((sgn * b2) >> denshift); |
147 | if ( del0 <= 0 ) |
148 | continue; |
149 | |
150 | sgn = sign_of_int( b1 ); |
151 | a1 -= sgn; |
152 | del0 -= (4 - 1) * ((sgn * b1) >> denshift); |
153 | if ( del0 <= 0 ) |
154 | continue; |
155 | |
156 | a0 -= sign_of_int( b0 ); |
157 | } |
158 | else if ( sg < 0 ) |
159 | { |
160 | |
161 | sgn = -sign_of_int( b3 ); |
162 | a3 -= sgn; |
163 | del0 -= (4 - 3) * ((sgn * b3) >> denshift); |
164 | if ( del0 >= 0 ) |
165 | continue; |
166 | |
167 | sgn = -sign_of_int( b2 ); |
168 | a2 -= sgn; |
169 | del0 -= (4 - 2) * ((sgn * b2) >> denshift); |
170 | if ( del0 >= 0 ) |
171 | continue; |
172 | |
173 | sgn = -sign_of_int( b1 ); |
174 | a1 -= sgn; |
175 | del0 -= (4 - 1) * ((sgn * b1) >> denshift); |
176 | if ( del0 >= 0 ) |
177 | continue; |
178 | |
179 | a0 += sign_of_int( b0 ); |
180 | } |
181 | } |
182 | |
183 | coefs[0] = a0; |
184 | coefs[1] = a1; |
185 | coefs[2] = a2; |
186 | coefs[3] = a3; |
187 | } |
188 | else if ( numactive == 8 ) |
189 | { |
190 | |
191 | register int16_t a4, a5, a6, a7; |
192 | register int32_t b4, b5, b6, b7; |
193 | |
194 | a0 = coefs[0]; |
195 | a1 = coefs[1]; |
196 | a2 = coefs[2]; |
197 | a3 = coefs[3]; |
198 | a4 = coefs[4]; |
199 | a5 = coefs[5]; |
200 | a6 = coefs[6]; |
201 | a7 = coefs[7]; |
202 | |
203 | for ( j = lim; j < num; j++ ) |
204 | { |
205 | LOOP_ALIGN |
206 | |
207 | top = in[j - lim]; |
208 | pin = in + j - 1; |
209 | |
210 | b0 = top - (*pin--); |
211 | b1 = top - (*pin--); |
212 | b2 = top - (*pin--); |
213 | b3 = top - (*pin--); |
214 | b4 = top - (*pin--); |
215 | b5 = top - (*pin--); |
216 | b6 = top - (*pin--); |
217 | b7 = top - (*pin); |
218 | pin += 8; |
| Value stored to 'pin' is never read |
219 | |
220 | sum1 = (denhalf - a0 * b0 - a1 * b1 - a2 * b2 - a3 * b3 |
221 | - a4 * b4 - a5 * b5 - a6 * b6 - a7 * b7) >> denshift; |
222 | |
223 | del = in[j] - top - sum1; |
224 | del = (del << chanshift) >> chanshift; |
225 | pc1[j] = del; |
226 | del0 = del; |
227 | |
228 | sg = sign_of_int(del); |
229 | if ( sg > 0 ) |
230 | { |
231 | sgn = sign_of_int( b7 ); |
232 | a7 -= sgn; |
233 | del0 -= 1 * ((sgn * b7) >> denshift); |
234 | if ( del0 <= 0 ) |
235 | continue; |
236 | |
237 | sgn = sign_of_int( b6 ); |
238 | a6 -= sgn; |
239 | del0 -= 2 * ((sgn * b6) >> denshift); |
240 | if ( del0 <= 0 ) |
241 | continue; |
242 | |
243 | sgn = sign_of_int( b5 ); |
244 | a5 -= sgn; |
245 | del0 -= 3 * ((sgn * b5) >> denshift); |
246 | if ( del0 <= 0 ) |
247 | continue; |
248 | |
249 | sgn = sign_of_int( b4 ); |
250 | a4 -= sgn; |
251 | del0 -= 4 * ((sgn * b4) >> denshift); |
252 | if ( del0 <= 0 ) |
253 | continue; |
254 | |
255 | sgn = sign_of_int( b3 ); |
256 | a3 -= sgn; |
257 | del0 -= 5 * ((sgn * b3) >> denshift); |
258 | if ( del0 <= 0 ) |
259 | continue; |
260 | |
261 | sgn = sign_of_int( b2 ); |
262 | a2 -= sgn; |
263 | del0 -= 6 * ((sgn * b2) >> denshift); |
264 | if ( del0 <= 0 ) |
265 | continue; |
266 | |
267 | sgn = sign_of_int( b1 ); |
268 | a1 -= sgn; |
269 | del0 -= 7 * ((sgn * b1) >> denshift); |
270 | if ( del0 <= 0 ) |
271 | continue; |
272 | |
273 | a0 -= sign_of_int( b0 ); |
274 | } |
275 | else if ( sg < 0 ) |
276 | { |
277 | |
278 | sgn = -sign_of_int( b7 ); |
279 | a7 -= sgn; |
280 | del0 -= 1 * ((sgn * b7) >> denshift); |
281 | if ( del0 >= 0 ) |
282 | continue; |
283 | |
284 | sgn = -sign_of_int( b6 ); |
285 | a6 -= sgn; |
286 | del0 -= 2 * ((sgn * b6) >> denshift); |
287 | if ( del0 >= 0 ) |
288 | continue; |
289 | |
290 | sgn = -sign_of_int( b5 ); |
291 | a5 -= sgn; |
292 | del0 -= 3 * ((sgn * b5) >> denshift); |
293 | if ( del0 >= 0 ) |
294 | continue; |
295 | |
296 | sgn = -sign_of_int( b4 ); |
297 | a4 -= sgn; |
298 | del0 -= 4 * ((sgn * b4) >> denshift); |
299 | if ( del0 >= 0 ) |
300 | continue; |
301 | |
302 | sgn = -sign_of_int( b3 ); |
303 | a3 -= sgn; |
304 | del0 -= 5 * ((sgn * b3) >> denshift); |
305 | if ( del0 >= 0 ) |
306 | continue; |
307 | |
308 | sgn = -sign_of_int( b2 ); |
309 | a2 -= sgn; |
310 | del0 -= 6 * ((sgn * b2) >> denshift); |
311 | if ( del0 >= 0 ) |
312 | continue; |
313 | |
314 | sgn = -sign_of_int( b1 ); |
315 | a1 -= sgn; |
316 | del0 -= 7 * ((sgn * b1) >> denshift); |
317 | if ( del0 >= 0 ) |
318 | continue; |
319 | |
320 | a0 += sign_of_int( b0 ); |
321 | } |
322 | } |
323 | |
324 | coefs[0] = a0; |
325 | coefs[1] = a1; |
326 | coefs[2] = a2; |
327 | coefs[3] = a3; |
328 | coefs[4] = a4; |
329 | coefs[5] = a5; |
330 | coefs[6] = a6; |
331 | coefs[7] = a7; |
332 | } |
333 | else |
334 | { |
335 | |
336 | |
337 | for ( j = lim; j < num; j++ ) |
338 | { |
339 | LOOP_ALIGN |
340 | |
341 | top = in[j - lim]; |
342 | pin = in + j - 1; |
343 | |
344 | sum1 = 0; |
345 | for ( k = 0; k < numactive; k++ ) |
346 | sum1 -= coefs[k] * (top - pin[-k]); |
347 | |
348 | del = in[j] - top - ((sum1 + denhalf) >> denshift); |
349 | del = (del << chanshift) >> chanshift; |
350 | pc1[j] = del; |
351 | del0 = del; |
352 | |
353 | sg = sign_of_int( del ); |
354 | if ( sg > 0 ) |
355 | { |
356 | for ( k = (numactive - 1); k >= 0; k-- ) |
357 | { |
358 | dd = top - pin[-k]; |
359 | sgn = sign_of_int( dd ); |
360 | coefs[k] -= sgn; |
361 | del0 -= (numactive - k) * ((sgn * dd) >> denshift); |
362 | if ( del0 <= 0 ) |
363 | break; |
364 | } |
365 | } |
366 | else if ( sg < 0 ) |
367 | { |
368 | for ( k = (numactive - 1); k >= 0; k-- ) |
369 | { |
370 | dd = top - pin[-k]; |
371 | sgn = sign_of_int( dd ); |
372 | coefs[k] += sgn; |
373 | del0 -= (numactive - k) * ((-sgn * dd) >> denshift); |
374 | if ( del0 >= 0 ) |
375 | break; |
376 | } |
377 | } |
378 | } |
379 | } |
380 | } |