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