MPEGPlayer: Fix leakage of file decriptors if file wasn't accepted by playback engine...
[kugel-rb.git] / apps / codecs / libmad / layer3.c
bloba598ff2c95f16e896bdc5c48a4299a5279e13a71
1 /*
2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * $Id$
22 # ifdef HAVE_CONFIG_H
23 # include "config.h"
24 # endif
26 # include "global.h"
28 # include <string.h>
30 # ifdef HAVE_ASSERT_H
31 # include <assert.h>
32 # endif
34 # ifdef HAVE_LIMITS_H
35 # include <limits.h>
36 # else
37 # undef CHAR_BIT
38 # define CHAR_BIT 8
39 # endif
41 # include "fixed.h"
42 # include "bit.h"
43 # include "stream.h"
44 # include "frame.h"
45 # include "huffman.h"
46 # include "layer3.h"
48 /* depending on the cpu "leftshift32" may be supported or not */
49 # if defined(CPU_COLDFIRE)
50 #define MAXLSHIFT 32
51 #else
52 #define MAXLSHIFT 31
53 #endif
55 /* --- Layer III ----------------------------------------------------------- */
57 enum {
58 count1table_select = 0x01,
59 scalefac_scale = 0x02,
60 preflag = 0x04,
61 mixed_block_flag = 0x08
64 enum {
65 I_STEREO = 0x1,
66 MS_STEREO = 0x2
69 struct sideinfo {
70 unsigned int main_data_begin;
71 unsigned int private_bits;
73 unsigned char scfsi[2];
75 struct granule {
76 struct channel {
77 /* from side info */
78 unsigned short part2_3_length;
79 unsigned short big_values;
80 unsigned short global_gain;
81 unsigned short scalefac_compress;
83 unsigned char flags;
84 unsigned char block_type;
85 unsigned char table_select[3];
86 unsigned char subblock_gain[3];
87 unsigned char region0_count;
88 unsigned char region1_count;
90 /* from main_data */
91 unsigned char scalefac[39]; /* scalefac_l and/or scalefac_s */
92 } ch[2];
93 } gr[2];
97 * scalefactor bit lengths
98 * derived from section 2.4.2.7 of ISO/IEC 11172-3
100 static
101 struct {
102 unsigned char slen1;
103 unsigned char slen2;
104 } const sflen_table[16] = {
105 { 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 },
106 { 3, 0 }, { 1, 1 }, { 1, 2 }, { 1, 3 },
107 { 2, 1 }, { 2, 2 }, { 2, 3 }, { 3, 1 },
108 { 3, 2 }, { 3, 3 }, { 4, 2 }, { 4, 3 }
112 * number of LSF scalefactor band values
113 * derived from section 2.4.3.2 of ISO/IEC 13818-3
115 static
116 unsigned char const nsfb_table[6][3][4] = {
117 { { 6, 5, 5, 5 },
118 { 9, 9, 9, 9 },
119 { 6, 9, 9, 9 } },
121 { { 6, 5, 7, 3 },
122 { 9, 9, 12, 6 },
123 { 6, 9, 12, 6 } },
125 { { 11, 10, 0, 0 },
126 { 18, 18, 0, 0 },
127 { 15, 18, 0, 0 } },
129 { { 7, 7, 7, 0 },
130 { 12, 12, 12, 0 },
131 { 6, 15, 12, 0 } },
133 { { 6, 6, 6, 3 },
134 { 12, 9, 9, 6 },
135 { 6, 12, 9, 6 } },
137 { { 8, 8, 5, 0 },
138 { 15, 12, 9, 0 },
139 { 6, 18, 9, 0 } }
143 * MPEG-1 scalefactor band widths
144 * derived from Table B.8 of ISO/IEC 11172-3
146 static
147 unsigned char const sfb_48000_long[] = {
148 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 10,
149 12, 16, 18, 22, 28, 34, 40, 46, 54, 54, 192
152 static
153 unsigned char const sfb_44100_long[] = {
154 4, 4, 4, 4, 4, 4, 6, 6, 8, 8, 10,
155 12, 16, 20, 24, 28, 34, 42, 50, 54, 76, 158
158 static
159 unsigned char const sfb_32000_long[] = {
160 4, 4, 4, 4, 4, 4, 6, 6, 8, 10, 12,
161 16, 20, 24, 30, 38, 46, 56, 68, 84, 102, 26
164 static
165 unsigned char const sfb_48000_short[] = {
166 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
167 6, 6, 6, 6, 6, 10, 10, 10, 12, 12, 12, 14, 14,
168 14, 16, 16, 16, 20, 20, 20, 26, 26, 26, 66, 66, 66
171 static
172 unsigned char const sfb_44100_short[] = {
173 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
174 6, 6, 8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14,
175 14, 18, 18, 18, 22, 22, 22, 30, 30, 30, 56, 56, 56
178 static
179 unsigned char const sfb_32000_short[] = {
180 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
181 6, 6, 8, 8, 8, 12, 12, 12, 16, 16, 16, 20, 20,
182 20, 26, 26, 26, 34, 34, 34, 42, 42, 42, 12, 12, 12
185 static
186 unsigned char const sfb_48000_mixed[] = {
187 /* long */ 4, 4, 4, 4, 4, 4, 6, 6,
188 /* short */ 4, 4, 4, 6, 6, 6, 6, 6, 6, 10,
189 10, 10, 12, 12, 12, 14, 14, 14, 16, 16,
190 16, 20, 20, 20, 26, 26, 26, 66, 66, 66
193 static
194 unsigned char const sfb_44100_mixed[] = {
195 /* long */ 4, 4, 4, 4, 4, 4, 6, 6,
196 /* short */ 4, 4, 4, 6, 6, 6, 8, 8, 8, 10,
197 10, 10, 12, 12, 12, 14, 14, 14, 18, 18,
198 18, 22, 22, 22, 30, 30, 30, 56, 56, 56
201 static
202 unsigned char const sfb_32000_mixed[] = {
203 /* long */ 4, 4, 4, 4, 4, 4, 6, 6,
204 /* short */ 4, 4, 4, 6, 6, 6, 8, 8, 8, 12,
205 12, 12, 16, 16, 16, 20, 20, 20, 26, 26,
206 26, 34, 34, 34, 42, 42, 42, 12, 12, 12
210 * MPEG-2 scalefactor band widths
211 * derived from Table B.2 of ISO/IEC 13818-3
213 static
214 unsigned char const sfb_24000_long[] = {
215 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
216 18, 22, 26, 32, 38, 46, 54, 62, 70, 76, 36
219 static
220 unsigned char const sfb_22050_long[] = {
221 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
222 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54
225 # define sfb_16000_long sfb_22050_long
227 static
228 unsigned char const sfb_24000_short[] = {
229 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8,
230 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18,
231 18, 24, 24, 24, 32, 32, 32, 44, 44, 44, 12, 12, 12
234 static
235 unsigned char const sfb_22050_short[] = {
236 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6,
237 6, 6, 8, 8, 8, 10, 10, 10, 14, 14, 14, 18, 18,
238 18, 26, 26, 26, 32, 32, 32, 42, 42, 42, 18, 18, 18
241 static
242 unsigned char const sfb_16000_short[] = {
243 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8,
244 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18,
245 18, 24, 24, 24, 30, 30, 30, 40, 40, 40, 18, 18, 18
248 static
249 unsigned char const sfb_24000_mixed[] = {
250 /* long */ 6, 6, 6, 6, 6, 6,
251 /* short */ 6, 6, 6, 8, 8, 8, 10, 10, 10, 12,
252 12, 12, 14, 14, 14, 18, 18, 18, 24, 24,
253 24, 32, 32, 32, 44, 44, 44, 12, 12, 12
256 static
257 unsigned char const sfb_22050_mixed[] = {
258 /* long */ 6, 6, 6, 6, 6, 6,
259 /* short */ 6, 6, 6, 6, 6, 6, 8, 8, 8, 10,
260 10, 10, 14, 14, 14, 18, 18, 18, 26, 26,
261 26, 32, 32, 32, 42, 42, 42, 18, 18, 18
264 static
265 unsigned char const sfb_16000_mixed[] = {
266 /* long */ 6, 6, 6, 6, 6, 6,
267 /* short */ 6, 6, 6, 8, 8, 8, 10, 10, 10, 12,
268 12, 12, 14, 14, 14, 18, 18, 18, 24, 24,
269 24, 30, 30, 30, 40, 40, 40, 18, 18, 18
273 * MPEG 2.5 scalefactor band widths
274 * derived from public sources
276 # define sfb_12000_long sfb_16000_long
277 # define sfb_11025_long sfb_12000_long
279 static
280 unsigned char const sfb_8000_long[] = {
281 12, 12, 12, 12, 12, 12, 16, 20, 24, 28, 32,
282 40, 48, 56, 64, 76, 90, 2, 2, 2, 2, 2
285 # define sfb_12000_short sfb_16000_short
286 # define sfb_11025_short sfb_12000_short
288 static
289 unsigned char const sfb_8000_short[] = {
290 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 16,
291 16, 16, 20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36,
292 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26
295 # define sfb_12000_mixed sfb_16000_mixed
296 # define sfb_11025_mixed sfb_12000_mixed
298 /* the 8000 Hz short block scalefactor bands do not break after
299 the first 36 frequency lines, so this is probably wrong */
300 static
301 unsigned char const sfb_8000_mixed[] = {
302 /* long */ 12, 12, 12,
303 /* short */ 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16,
304 20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36, 36,
305 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26
308 static
309 struct {
310 unsigned char const *l;
311 unsigned char const *s;
312 unsigned char const *m;
313 } const sfbwidth_table[9] = {
314 { sfb_48000_long, sfb_48000_short, sfb_48000_mixed },
315 { sfb_44100_long, sfb_44100_short, sfb_44100_mixed },
316 { sfb_32000_long, sfb_32000_short, sfb_32000_mixed },
317 { sfb_24000_long, sfb_24000_short, sfb_24000_mixed },
318 { sfb_22050_long, sfb_22050_short, sfb_22050_mixed },
319 { sfb_16000_long, sfb_16000_short, sfb_16000_mixed },
320 { sfb_12000_long, sfb_12000_short, sfb_12000_mixed },
321 { sfb_11025_long, sfb_11025_short, sfb_11025_mixed },
322 { sfb_8000_long, sfb_8000_short, sfb_8000_mixed }
326 * scalefactor band preemphasis (used only when preflag is set)
327 * derived from Table B.6 of ISO/IEC 11172-3
329 static
330 unsigned char const pretab[22] = {
331 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0
335 * table for requantization
337 * rq_table[x].mantissa * 2^(rq_table[x].exponent) = x^(4/3)
339 * format rq_table: bit31-27=exponent bit26-0=mantissa
341 static
342 unsigned long const rq_table[8207] = {
343 # include "rq_table.dat"
347 * fractional powers of two
348 * used for requantization and joint stereo decoding
350 * root_table[3 + x] = 2^(x/4)
352 mad_fixed_t const root_table[7] ICONST_ATTR MEM_ALIGN_ATTR = {
353 MAD_F(0x09837f05) /* 2^(-3/4) == 0.59460355750136 */,
354 MAD_F(0x0b504f33) /* 2^(-2/4) == 0.70710678118655 */,
355 MAD_F(0x0d744fcd) /* 2^(-1/4) == 0.84089641525371 */,
356 MAD_F(0x10000000) /* 2^( 0/4) == 1.00000000000000 */,
357 MAD_F(0x1306fe0a) /* 2^(+1/4) == 1.18920711500272 */,
358 MAD_F(0x16a09e66) /* 2^(+2/4) == 1.41421356237310 */,
359 MAD_F(0x1ae89f99) /* 2^(+3/4) == 1.68179283050743 */
363 * coefficients for aliasing reduction
364 * derived from Table B.9 of ISO/IEC 11172-3
366 * c[] = { -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037 }
367 * cs[i] = 1 / sqrt(1 + c[i]^2)
368 * ca[i] = c[i] / sqrt(1 + c[i]^2)
370 mad_fixed_t const cs[8] ICONST_ATTR MEM_ALIGN_ATTR = {
371 +MAD_F(0x0db84a81) /* +0.857492926 */, +MAD_F(0x0e1b9d7f) /* +0.881741997 */,
372 +MAD_F(0x0f31adcf) /* +0.949628649 */, +MAD_F(0x0fbba815) /* +0.983314592 */,
373 +MAD_F(0x0feda417) /* +0.995517816 */, +MAD_F(0x0ffc8fc8) /* +0.999160558 */,
374 +MAD_F(0x0fff964c) /* +0.999899195 */, +MAD_F(0x0ffff8d3) /* +0.999993155 */
377 mad_fixed_t const ca[8] ICONST_ATTR MEM_ALIGN_ATTR = {
378 -MAD_F(0x083b5fe7) /* -0.514495755 */, -MAD_F(0x078c36d2) /* -0.471731969 */,
379 -MAD_F(0x05039814) /* -0.313377454 */, -MAD_F(0x02e91dd1) /* -0.181913200 */,
380 -MAD_F(0x0183603a) /* -0.094574193 */, -MAD_F(0x00a7cb87) /* -0.040965583 */,
381 -MAD_F(0x003a2847) /* -0.014198569 */, -MAD_F(0x000f27b4) /* -0.003699975 */
385 * IMDCT coefficients for short blocks
386 * derived from section 2.4.3.4.10.2 of ISO/IEC 11172-3
388 * imdct_s[i/even][k] = cos((PI / 24) * (2 * (i / 2) + 7) * (2 * k + 1))
389 * imdct_s[i /odd][k] = cos((PI / 24) * (2 * (6 + (i-1)/2) + 7) * (2 * k + 1))
391 mad_fixed_t const imdct_s[6][6] ICONST_ATTR MEM_ALIGN_ATTR = {
392 # include "imdct_s.dat"
395 # if !defined(FPM_ARM)
397 * windowing coefficients for long blocks
398 * derived from section 2.4.3.4.10.3 of ISO/IEC 11172-3
400 * window_l[i] = sin((PI / 36) * (i + 1/2))
402 static
403 mad_fixed_t const window_l[36] ICONST_ATTR MEM_ALIGN_ATTR = {
404 MAD_F(0x00b2aa3e) /* 0.043619387 */, MAD_F(0x0216a2a2) /* 0.130526192 */,
405 MAD_F(0x03768962) /* 0.216439614 */, MAD_F(0x04cfb0e2) /* 0.300705800 */,
406 MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x07635284) /* 0.461748613 */,
407 MAD_F(0x0898c779) /* 0.537299608 */, MAD_F(0x09bd7ca0) /* 0.608761429 */,
408 MAD_F(0x0acf37ad) /* 0.675590208 */, MAD_F(0x0bcbe352) /* 0.737277337 */,
409 MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x0d7e8807) /* 0.843391446 */,
411 MAD_F(0x0e313245) /* 0.887010833 */, MAD_F(0x0ec835e8) /* 0.923879533 */,
412 MAD_F(0x0f426cb5) /* 0.953716951 */, MAD_F(0x0f9ee890) /* 0.976296007 */,
413 MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ffc19fd) /* 0.999048222 */,
414 MAD_F(0x0ffc19fd) /* 0.999048222 */, MAD_F(0x0fdcf549) /* 0.991444861 */,
415 MAD_F(0x0f9ee890) /* 0.976296007 */, MAD_F(0x0f426cb5) /* 0.953716951 */,
416 MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0e313245) /* 0.887010833 */,
418 MAD_F(0x0d7e8807) /* 0.843391446 */, MAD_F(0x0cb19346) /* 0.793353340 */,
419 MAD_F(0x0bcbe352) /* 0.737277337 */, MAD_F(0x0acf37ad) /* 0.675590208 */,
420 MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0898c779) /* 0.537299608 */,
421 MAD_F(0x07635284) /* 0.461748613 */, MAD_F(0x061f78aa) /* 0.382683432 */,
422 MAD_F(0x04cfb0e2) /* 0.300705800 */, MAD_F(0x03768962) /* 0.216439614 */,
423 MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x00b2aa3e) /* 0.043619387 */,
425 # endif /* FPM_ARM */
428 * windowing coefficients for short blocks
429 * derived from section 2.4.3.4.10.3 of ISO/IEC 11172-3
431 * window_s[i] = sin((PI / 12) * (i + 1/2))
433 mad_fixed_t const window_s[12] ICONST_ATTR MEM_ALIGN_ATTR = {
434 MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x061f78aa) /* 0.382683432 */,
435 MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0cb19346) /* 0.793353340 */,
436 MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0fdcf549) /* 0.991444861 */,
437 MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ec835e8) /* 0.923879533 */,
438 MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x09bd7ca0) /* 0.608761429 */,
439 MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x0216a2a2) /* 0.130526192 */,
443 * coefficients for intensity stereo processing
444 * derived from section 2.4.3.4.9.3 of ISO/IEC 11172-3
446 * is_ratio[i] = tan(i * (PI / 12))
447 * is_table[i] = is_ratio[i] / (1 + is_ratio[i])
449 static
450 mad_fixed_t const is_table[7] = {
451 MAD_F(0x00000000) /* 0.000000000 */,
452 MAD_F(0x0361962f) /* 0.211324865 */,
453 MAD_F(0x05db3d74) /* 0.366025404 */,
454 MAD_F(0x08000000) /* 0.500000000 */,
455 MAD_F(0x0a24c28c) /* 0.633974596 */,
456 MAD_F(0x0c9e69d1) /* 0.788675135 */,
457 MAD_F(0x10000000) /* 1.000000000 */
461 * coefficients for LSF intensity stereo processing
462 * derived from section 2.4.3.2 of ISO/IEC 13818-3
464 * is_lsf_table[0][i] = (1 / sqrt(sqrt(2)))^(i + 1)
465 * is_lsf_table[1][i] = (1 / sqrt(2)) ^(i + 1)
467 static
468 mad_fixed_t const is_lsf_table[2][15] = {
470 MAD_F(0x0d744fcd) /* 0.840896415 */,
471 MAD_F(0x0b504f33) /* 0.707106781 */,
472 MAD_F(0x09837f05) /* 0.594603558 */,
473 MAD_F(0x08000000) /* 0.500000000 */,
474 MAD_F(0x06ba27e6) /* 0.420448208 */,
475 MAD_F(0x05a8279a) /* 0.353553391 */,
476 MAD_F(0x04c1bf83) /* 0.297301779 */,
477 MAD_F(0x04000000) /* 0.250000000 */,
478 MAD_F(0x035d13f3) /* 0.210224104 */,
479 MAD_F(0x02d413cd) /* 0.176776695 */,
480 MAD_F(0x0260dfc1) /* 0.148650889 */,
481 MAD_F(0x02000000) /* 0.125000000 */,
482 MAD_F(0x01ae89fa) /* 0.105112052 */,
483 MAD_F(0x016a09e6) /* 0.088388348 */,
484 MAD_F(0x01306fe1) /* 0.074325445 */
485 }, {
486 MAD_F(0x0b504f33) /* 0.707106781 */,
487 MAD_F(0x08000000) /* 0.500000000 */,
488 MAD_F(0x05a8279a) /* 0.353553391 */,
489 MAD_F(0x04000000) /* 0.250000000 */,
490 MAD_F(0x02d413cd) /* 0.176776695 */,
491 MAD_F(0x02000000) /* 0.125000000 */,
492 MAD_F(0x016a09e6) /* 0.088388348 */,
493 MAD_F(0x01000000) /* 0.062500000 */,
494 MAD_F(0x00b504f3) /* 0.044194174 */,
495 MAD_F(0x00800000) /* 0.031250000 */,
496 MAD_F(0x005a827a) /* 0.022097087 */,
497 MAD_F(0x00400000) /* 0.015625000 */,
498 MAD_F(0x002d413d) /* 0.011048543 */,
499 MAD_F(0x00200000) /* 0.007812500 */,
500 MAD_F(0x0016a09e) /* 0.005524272 */
505 * NAME: III_sideinfo()
506 * DESCRIPTION: decode frame side information from a bitstream
508 static
509 enum mad_error III_sideinfo(struct mad_bitptr *ptr, unsigned int nch,
510 int lsf, struct sideinfo *si,
511 unsigned int *data_bitlen,
512 unsigned int *priv_bitlen)
514 unsigned int ngr, gr, ch, i;
515 enum mad_error result = MAD_ERROR_NONE;
517 *data_bitlen = 0;
518 *priv_bitlen = lsf ? ((nch == 1) ? 1 : 2) : ((nch == 1) ? 5 : 3);
520 si->main_data_begin = mad_bit_read(ptr, lsf ? 8 : 9);
521 si->private_bits = mad_bit_read(ptr, *priv_bitlen);
523 ngr = 1;
524 if (!lsf) {
525 ngr = 2;
527 for (ch = 0; ch < nch; ++ch)
528 si->scfsi[ch] = mad_bit_read(ptr, 4);
531 for (gr = 0; gr < ngr; ++gr) {
532 struct granule *granule = &si->gr[gr];
534 for (ch = 0; ch < nch; ++ch) {
535 struct channel *channel = &granule->ch[ch];
537 channel->part2_3_length = mad_bit_read(ptr, 12);
538 channel->big_values = mad_bit_read(ptr, 9);
539 channel->global_gain = mad_bit_read(ptr, 8);
540 channel->scalefac_compress = mad_bit_read(ptr, lsf ? 9 : 4);
542 *data_bitlen += channel->part2_3_length;
544 if (channel->big_values > 288 && result == 0)
545 result = MAD_ERROR_BADBIGVALUES;
547 channel->flags = 0;
549 /* window_switching_flag */
550 if (mad_bit_read(ptr, 1)) {
551 channel->block_type = mad_bit_read(ptr, 2);
553 if (channel->block_type == 0 && result == 0)
554 result = MAD_ERROR_BADBLOCKTYPE;
556 if (!lsf && channel->block_type == 2 && si->scfsi[ch] && result == 0)
557 result = MAD_ERROR_BADSCFSI;
559 channel->region0_count = 7;
560 channel->region1_count = 36;
562 if (mad_bit_read(ptr, 1))
563 channel->flags |= mixed_block_flag;
564 else if (channel->block_type == 2)
565 channel->region0_count = 8;
567 for (i = 0; i < 2; ++i)
568 channel->table_select[i] = mad_bit_read(ptr, 5);
570 # if defined(DEBUG)
571 channel->table_select[2] = 4; /* not used */
572 # endif
574 for (i = 0; i < 3; ++i)
575 channel->subblock_gain[i] = mad_bit_read(ptr, 3);
577 else {
578 channel->block_type = 0;
580 for (i = 0; i < 3; ++i)
581 channel->table_select[i] = mad_bit_read(ptr, 5);
583 channel->region0_count = mad_bit_read(ptr, 4);
584 channel->region1_count = mad_bit_read(ptr, 3);
587 /* [preflag,] scalefac_scale, count1table_select */
588 channel->flags |= mad_bit_read(ptr, lsf ? 2 : 3);
592 return result;
596 * NAME: III_scalefactors_lsf()
597 * DESCRIPTION: decode channel scalefactors for LSF from a bitstream
599 static
600 unsigned int III_scalefactors_lsf(struct mad_bitptr *ptr,
601 struct channel *channel,
602 struct channel *gr1ch, int mode_extension)
604 struct mad_bitptr start;
605 unsigned int scalefac_compress, index, slen[4], part, n, i;
606 unsigned char const *nsfb;
608 start = *ptr;
610 scalefac_compress = channel->scalefac_compress;
611 index = (channel->block_type == 2) ?
612 ((channel->flags & mixed_block_flag) ? 2 : 1) : 0;
614 if (!((mode_extension & I_STEREO) && gr1ch)) {
615 if (scalefac_compress < 400) {
616 slen[0] = (scalefac_compress >> 4) / 5;
617 slen[1] = (scalefac_compress >> 4) % 5;
618 slen[2] = (scalefac_compress % 16) >> 2;
619 slen[3] = scalefac_compress % 4;
621 nsfb = nsfb_table[0][index];
623 else if (scalefac_compress < 500) {
624 scalefac_compress -= 400;
626 slen[0] = (scalefac_compress >> 2) / 5;
627 slen[1] = (scalefac_compress >> 2) % 5;
628 slen[2] = scalefac_compress % 4;
629 slen[3] = 0;
631 nsfb = nsfb_table[1][index];
633 else {
634 scalefac_compress -= 500;
636 slen[0] = scalefac_compress / 3;
637 slen[1] = scalefac_compress % 3;
638 slen[2] = 0;
639 slen[3] = 0;
641 channel->flags |= preflag;
643 nsfb = nsfb_table[2][index];
646 n = 0;
647 for (part = 0; part < 4; ++part) {
648 for (i = 0; i < nsfb[part]; ++i)
649 channel->scalefac[n++] = mad_bit_read(ptr, slen[part]);
652 while (n < 39)
653 channel->scalefac[n++] = 0;
655 else { /* (mode_extension & I_STEREO) && gr1ch (i.e. ch == 1) */
656 scalefac_compress >>= 1;
658 if (scalefac_compress < 180) {
659 slen[0] = scalefac_compress / 36;
660 slen[1] = (scalefac_compress % 36) / 6;
661 slen[2] = (scalefac_compress % 36) % 6;
662 slen[3] = 0;
664 nsfb = nsfb_table[3][index];
666 else if (scalefac_compress < 244) {
667 scalefac_compress -= 180;
669 slen[0] = (scalefac_compress % 64) >> 4;
670 slen[1] = (scalefac_compress % 16) >> 2;
671 slen[2] = scalefac_compress % 4;
672 slen[3] = 0;
674 nsfb = nsfb_table[4][index];
676 else {
677 scalefac_compress -= 244;
679 slen[0] = scalefac_compress / 3;
680 slen[1] = scalefac_compress % 3;
681 slen[2] = 0;
682 slen[3] = 0;
684 nsfb = nsfb_table[5][index];
687 n = 0;
688 for (part = 0; part < 4; ++part) {
689 unsigned int max, is_pos;
691 max = (1 << slen[part]) - 1;
693 for (i = 0; i < nsfb[part]; ++i) {
694 is_pos = mad_bit_read(ptr, slen[part]);
696 channel->scalefac[n] = is_pos;
697 gr1ch->scalefac[n++] = (is_pos == max);
701 while (n < 39) {
702 channel->scalefac[n] = 0;
703 gr1ch->scalefac[n++] = 0; /* apparently not illegal */
707 return mad_bit_length(&start, ptr);
711 * NAME: III_scalefactors()
712 * DESCRIPTION: decode channel scalefactors of one granule from a bitstream
714 static
715 unsigned int III_scalefactors(struct mad_bitptr *ptr, struct channel *channel,
716 struct channel const *gr0ch, unsigned int scfsi)
718 struct mad_bitptr start;
719 unsigned int slen1, slen2, sfbi;
721 start = *ptr;
723 slen1 = sflen_table[channel->scalefac_compress].slen1;
724 slen2 = sflen_table[channel->scalefac_compress].slen2;
726 if (channel->block_type == 2) {
727 unsigned int nsfb;
729 sfbi = 0;
731 nsfb = (channel->flags & mixed_block_flag) ? 8 + 3 * 3 : 6 * 3;
732 while (nsfb--)
733 channel->scalefac[sfbi++] = mad_bit_read(ptr, slen1);
735 nsfb = 6 * 3;
736 while (nsfb--)
737 channel->scalefac[sfbi++] = mad_bit_read(ptr, slen2);
739 nsfb = 1 * 3;
740 while (nsfb--)
741 channel->scalefac[sfbi++] = 0;
743 else { /* channel->block_type != 2 */
744 if (scfsi & 0x8) {
745 for (sfbi = 0; sfbi < 6; ++sfbi)
746 channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
748 else {
749 for (sfbi = 0; sfbi < 6; ++sfbi)
750 channel->scalefac[sfbi] = mad_bit_read(ptr, slen1);
753 if (scfsi & 0x4) {
754 for (sfbi = 6; sfbi < 11; ++sfbi)
755 channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
757 else {
758 for (sfbi = 6; sfbi < 11; ++sfbi)
759 channel->scalefac[sfbi] = mad_bit_read(ptr, slen1);
762 if (scfsi & 0x2) {
763 for (sfbi = 11; sfbi < 16; ++sfbi)
764 channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
766 else {
767 for (sfbi = 11; sfbi < 16; ++sfbi)
768 channel->scalefac[sfbi] = mad_bit_read(ptr, slen2);
771 if (scfsi & 0x1) {
772 for (sfbi = 16; sfbi < 21; ++sfbi)
773 channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
775 else {
776 for (sfbi = 16; sfbi < 21; ++sfbi)
777 channel->scalefac[sfbi] = mad_bit_read(ptr, slen2);
780 channel->scalefac[21] = 0;
783 return mad_bit_length(&start, ptr);
787 * The Layer III formula for requantization and scaling is defined by
788 * section 2.4.3.4.7.1 of ISO/IEC 11172-3, as follows:
790 * long blocks:
791 * xr[i] = sign(is[i]) * abs(is[i])^(4/3) *
792 * 2^((1/4) * (global_gain - 210)) *
793 * 2^-(scalefac_multiplier *
794 * (scalefac_l[sfb] + preflag * pretab[sfb]))
796 * short blocks:
797 * xr[i] = sign(is[i]) * abs(is[i])^(4/3) *
798 * 2^((1/4) * (global_gain - 210 - 8 * subblock_gain[w])) *
799 * 2^-(scalefac_multiplier * scalefac_s[sfb][w])
801 * where:
802 * scalefac_multiplier = (scalefac_scale + 1) / 2
804 * The routines III_exponents() and III_requantize() facilitate this
805 * calculation.
809 * NAME: III_exponents()
810 * DESCRIPTION: calculate scalefactor exponents
812 static
813 void III_exponents(struct channel const *channel,
814 unsigned char const *sfbwidth, signed int exponents[39])
816 signed int gain;
817 unsigned int scalefac_multiplier, sfbi;
819 gain = (signed int) channel->global_gain - 210;
820 scalefac_multiplier = (channel->flags & scalefac_scale) ? 2 : 1;
822 if (channel->block_type == 2) {
823 unsigned int l;
824 signed int gain0, gain1, gain2;
826 sfbi = l = 0;
828 if (channel->flags & mixed_block_flag) {
829 unsigned int premask;
831 premask = (channel->flags & preflag) ? ~0 : 0;
833 /* long block subbands 0-1 */
835 while (l < 36) {
836 exponents[sfbi] = gain -
837 (signed int) ((channel->scalefac[sfbi] + (pretab[sfbi] & premask)) <<
838 scalefac_multiplier);
840 l += sfbwidth[sfbi++];
844 /* this is probably wrong for 8000 Hz short/mixed blocks */
846 gain0 = gain - 8 * (signed int) channel->subblock_gain[0];
847 gain1 = gain - 8 * (signed int) channel->subblock_gain[1];
848 gain2 = gain - 8 * (signed int) channel->subblock_gain[2];
850 while (l < 576) {
851 exponents[sfbi + 0] = gain0 -
852 (signed int) (channel->scalefac[sfbi + 0] << scalefac_multiplier);
853 exponents[sfbi + 1] = gain1 -
854 (signed int) (channel->scalefac[sfbi + 1] << scalefac_multiplier);
855 exponents[sfbi + 2] = gain2 -
856 (signed int) (channel->scalefac[sfbi + 2] << scalefac_multiplier);
857 unsigned int w = sfbwidth[sfbi];
858 l += 3 * w;
859 sfbi += 3;
862 else { /* channel->block_type != 2 */
863 if (channel->flags & preflag) {
864 for (sfbi = 0; sfbi < 22; ++sfbi) {
865 exponents[sfbi] = gain -
866 (signed int) ((channel->scalefac[sfbi] + pretab[sfbi]) <<
867 scalefac_multiplier);
870 else {
871 for (sfbi = 0; sfbi < 22; ++sfbi) {
872 exponents[sfbi] = gain -
873 (signed int) (channel->scalefac[sfbi] << scalefac_multiplier);
880 * NAME: III_requantize()
881 * DESCRIPTION: requantize one (positive) value
883 static
884 mad_fixed_t III_requantize(unsigned int value, signed int exp)
886 mad_fixed_t requantized;
887 signed int frac;
888 unsigned long power;
890 frac = exp % 4; /* assumes sign(frac) == sign(exp) */
891 exp /= 4;
893 /* format rq_table: bit31-27=exponent bit26-0=mantissa */
894 power = rq_table[value];
895 requantized = power & 0x07ffffff;
896 exp += power >> 27;
898 if (exp < 0) {
899 if (-exp >= (signed int) (sizeof(mad_fixed_t) * CHAR_BIT)) {
900 /* underflow */
901 requantized = 0;
903 else {
904 requantized += 1L << (-exp - 1);
905 requantized >>= -exp;
908 else {
909 if (exp >= 5) {
910 /* overflow */
911 # if defined(DEBUG)
912 fprintf(stderr, "requantize overflow (%f * 2^%d)\n",
913 mad_f_todouble(requantized), exp);
914 # endif
915 requantized = MAD_F_MAX;
917 else
918 requantized <<= exp;
921 return frac ? mad_f_mul(requantized, root_table[3 + frac]) : requantized;
924 /* we must take care that sz >= bits and sz < sizeof(long) lest bits == 0 */
925 # if defined(CPU_ARM)
926 # define MASK(cache, sz, bits) \
927 ({ unsigned long res; \
928 asm ("mov %0, #1\n\t" \
929 "rsb %0, %0, %0, lsl %3\n\t" \
930 "and %0, %0, %1, lsr %2" \
931 : "=&r" (res) : "r" (cache), "r" ((sz) - (bits)), "r" (bits)); \
932 res; \
934 #else
935 # define MASK(cache, sz, bits) \
936 (((cache) >> ((sz) - (bits))) & ((1 << (bits)) - 1))
937 #endif
938 # define MASK1BIT(cache, sz) \
939 ((cache) & (1 << ((sz) - 1)))
942 * NAME: III_huffdecode()
943 * DESCRIPTION: decode Huffman code words of one channel of one granule
945 static
946 enum mad_error III_huffdecode(struct mad_bitptr *ptr, mad_fixed_t xrarr[576],
947 struct channel *channel,
948 unsigned char const *sfbwidth,
949 unsigned int part2_length)
951 unsigned int bits;
952 signed int exponents[39], exp;
953 signed int const *expptr;
954 struct mad_bitptr peek;
955 signed int bits_left, cachesz;
956 register mad_fixed_t *xr;
957 mad_fixed_t const *sfbound;
958 register unsigned long bitcache;
960 bits_left = (signed) channel->part2_3_length - (signed) part2_length;
961 if (bits_left < 0)
962 return MAD_ERROR_BADPART3LEN;
964 III_exponents(channel, sfbwidth, exponents);
966 peek = *ptr;
967 cachesz = 0;
968 sfbound = xr = xrarr;
969 mad_bit_skip(ptr, bits_left);
971 /* big_values */
973 int region;
974 struct hufftable const *entry;
975 union huffpair const *table;
976 unsigned int linbits, startbits, rcount;
977 mad_fixed_t reqcache[16];
978 mad_fixed_t const *xr_end, *xr_big_val;
980 rcount = 1;
981 expptr = &exponents[0];
982 region = -1;
983 exp = 0x3210; /* start value */
984 bitcache = 0;
985 linbits = startbits = 0;
986 table = NULL;
987 xr_big_val = xr + 2 * channel->big_values;
989 while(xr < xr_big_val)
991 sfbound += *sfbwidth++;
992 xr_end = sfbound > xr_big_val ? xr_big_val : sfbound;
994 /* change table if region boundary */
995 if(--rcount == 0)
997 if(exp == 0x3210)
998 rcount = channel->region0_count + 1;
999 else
1000 if(region == 0)
1001 rcount = channel->region1_count + 1;
1002 else
1003 rcount = 0; /* all remaining */
1005 entry = &mad_huff_pair_table[channel->table_select[++region]];
1006 table = entry->table;
1007 linbits = entry->linbits;
1008 startbits = entry->startbits;
1010 if(table == 0)
1011 return MAD_ERROR_BADHUFFTABLE;
1014 if(exp != *expptr)
1016 exp = *expptr;
1017 /* clear cache */
1018 memset(reqcache, 0, sizeof(reqcache));
1021 ++expptr;
1023 if(linbits)
1025 for( ; xr<xr_end; xr+=2)
1027 union huffpair const *pair;
1028 register mad_fixed_t requantized;
1029 unsigned int clumpsz, value;
1031 /* maxhuffcode(hufftab16,hufftab24)=17bit + sign(x,y)=2bit */
1032 if(cachesz < 19)
1034 if(cachesz < 0)
1035 return MAD_ERROR_BADHUFFDATA; /* cache underrun */
1037 bits = MAXLSHIFT - cachesz;
1038 bitcache = (bitcache << bits) | mad_bit_read(&peek, bits);
1039 cachesz += bits;
1042 /* hcod (0..19) */
1043 clumpsz = startbits;
1044 pair = &table[MASK(bitcache, cachesz, clumpsz)];
1046 while(!pair->final)
1048 cachesz -= clumpsz;
1049 clumpsz = pair->ptr.bits;
1050 pair = &table[pair->ptr.offset + MASK(bitcache, cachesz, clumpsz)];
1053 cachesz -= pair->value.hlen;
1055 /* x (0..14) */
1056 value = pair->value.x;
1057 if(value == 0)
1058 xr[0] = 0;
1059 else
1061 if(value == 15)
1063 /* maxlinbits=13bit + sign(x,y)=2bit */
1064 if(cachesz < 15)
1066 if(cachesz < 0)
1067 return MAD_ERROR_BADHUFFDATA; /* cache underrun */
1069 bits = MAXLSHIFT - cachesz;
1070 bitcache = (bitcache << bits) | mad_bit_read(&peek, bits);
1071 cachesz += bits;
1074 requantized = III_requantize(15+MASK(bitcache, cachesz, linbits), exp);
1075 cachesz -= linbits;
1077 else
1079 if(reqcache[value])
1080 requantized = reqcache[value];
1081 else
1082 requantized = reqcache[value] = III_requantize(value, exp);
1085 xr[0] = MASK1BIT(bitcache, cachesz--) ? -requantized : requantized;
1088 /* y (0..14) */
1089 value = pair->value.y;
1090 if(value == 0)
1091 xr[1] = 0;
1092 else
1094 if(value == 15)
1096 /* maxlinbits=13bit + sign(y)=1bit */
1097 if(cachesz < 14)
1099 if(cachesz < 0)
1100 return MAD_ERROR_BADHUFFDATA; /* cache underrun */
1102 bits = MAXLSHIFT - cachesz;
1103 bitcache = (bitcache << bits) | mad_bit_read(&peek, bits);
1104 cachesz += bits;
1107 requantized = III_requantize(15+MASK(bitcache, cachesz, linbits), exp);
1108 cachesz -= linbits;
1110 else
1112 if(reqcache[value])
1113 requantized = reqcache[value];
1114 else
1115 requantized = reqcache[value] = III_requantize(value, exp);
1117 xr[1] = MASK1BIT(bitcache, cachesz--) ? -requantized : requantized;
1121 else
1123 for( ; xr<xr_end; xr+=2)
1125 union huffpair const *pair;
1126 register mad_fixed_t requantized;
1127 unsigned int clumpsz, value;
1129 /* maxlookup=4bit + sign(x,y)=2bit */
1130 if(cachesz < 6)
1132 if(cachesz < 0)
1133 return MAD_ERROR_BADHUFFDATA; /* cache underrun */
1135 bits = MAXLSHIFT - cachesz;
1136 bitcache = (bitcache << bits) | mad_bit_read(&peek, bits);
1137 cachesz += bits;
1140 /* hcod (0..19) */
1141 clumpsz = startbits;
1142 pair = &table[MASK(bitcache, cachesz, clumpsz)];
1144 while(!pair->final)
1146 cachesz -= clumpsz;
1148 /* maxlookup=4bit + sign(x,y)=2bit */
1149 if(cachesz < 6)
1151 if(cachesz < 0)
1152 return MAD_ERROR_BADHUFFDATA; /* cache underrun */
1154 bits = MAXLSHIFT - cachesz;
1155 bitcache = (bitcache << bits) | mad_bit_read(&peek, bits);
1156 cachesz += bits;
1159 clumpsz = pair->ptr.bits;
1160 pair = &table[pair->ptr.offset + MASK(bitcache, cachesz, clumpsz)];
1163 cachesz -= pair->value.hlen;
1165 /* x (0..1) */
1166 value = pair->value.x;
1167 if(value == 0)
1168 xr[0] = 0;
1169 else
1171 if(reqcache[value])
1172 requantized = reqcache[value];
1173 else
1174 requantized = reqcache[value] = III_requantize(value, exp);
1176 xr[0] = MASK1BIT(bitcache, cachesz--) ? -requantized : requantized;
1179 /* y (0..1) */
1180 value = pair->value.y;
1181 if(value == 0)
1182 xr[1] = 0;
1183 else
1185 if(reqcache[value])
1186 requantized = reqcache[value];
1187 else
1188 requantized = reqcache[value] = III_requantize(value, exp);
1190 xr[1] = MASK1BIT(bitcache, cachesz--) ? -requantized : requantized;
1197 bits_left = ptr->readbit - peek.readbit;
1199 if(bits_left + cachesz < 0)
1200 return MAD_ERROR_BADHUFFDATA; /* big_values overrun */
1202 /* count1 */
1204 union huffquad const *table;
1205 register mad_fixed_t requantized;
1207 table = mad_huff_quad_table[channel->flags & count1table_select];
1209 requantized = III_requantize(1, exp);
1211 while(xr <= &xrarr[572] && bits_left + cachesz > 0)
1213 union huffquad const *quad;
1215 /* hcod (1..6) */
1216 if(cachesz < 10)
1218 if(cachesz < 0)
1219 return MAD_ERROR_BADHUFFDATA; /* cache underrun */
1221 bits = MAXLSHIFT - cachesz;
1222 bitcache = (bitcache << bits) | mad_bit_read(&peek, bits);
1223 cachesz += bits;
1224 bits_left -= bits;
1227 quad = &table[MASK(bitcache, cachesz, 4)];
1229 /* quad tables guaranteed to have at most one extra lookup */
1230 if (!quad->final) {
1231 cachesz -= 4;
1233 quad = &table[quad->ptr.offset +
1234 MASK(bitcache, cachesz, quad->ptr.bits)];
1237 cachesz -= quad->value.hlen;
1239 if (xr == sfbound) {
1240 sfbound += *sfbwidth++;
1242 if (exp != *expptr) {
1243 exp = *expptr;
1244 requantized = III_requantize(1, exp);
1247 ++expptr;
1250 /* v (0..1) */
1251 xr[0] = quad->value.v ?
1252 (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
1254 /* w (0..1) */
1255 xr[1] = quad->value.w ?
1256 (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
1258 xr += 2;
1260 if (xr == sfbound) {
1261 sfbound += *sfbwidth++;
1263 if (exp != *expptr) {
1264 exp = *expptr;
1265 requantized = III_requantize(1, exp);
1268 ++expptr;
1271 /* x (0..1) */
1272 xr[0] = quad->value.x ?
1273 (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
1275 /* y (0..1) */
1276 xr[1] = quad->value.y ?
1277 (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
1279 xr += 2;
1282 if(bits_left + cachesz < 0)
1284 /* technically the bitstream is misformatted, but apparently
1285 some encoders are just a bit sloppy with stuffing bits */
1286 xr -= 4;
1290 /* rzero */
1291 memset(xr, 0, (char*)&xrarr[576] - (char*)xr);
1293 return MAD_ERROR_NONE;
1296 # undef MASK
1297 # undef MASK1BIT
1300 * NAME: III_reorder()
1301 * DESCRIPTION: reorder frequency lines of a short block into subband order
1303 static
1304 void III_reorder(mad_fixed_t xr[576], struct channel const *channel,
1305 unsigned char const sfbwidth[39])
1307 mad_fixed_t tmp[32][3][6];
1308 unsigned int sb, l, f, w, sbw[3], sw[3];
1310 /* this is probably wrong for 8000 Hz mixed blocks */
1312 sb = 0;
1313 if (channel->flags & mixed_block_flag) {
1314 sb = 2;
1316 l = 0;
1317 while (l < 36)
1318 l += *sfbwidth++;
1321 for (w = 0; w < 3; ++w) {
1322 sbw[w] = sb;
1323 sw[w] = 0;
1326 f = *sfbwidth++;
1327 w = 0;
1329 for (l = 18 * sb; l < 576; ++l) {
1330 if (f-- == 0) {
1331 f = *sfbwidth++ - 1;
1332 w = (w + 1) % 3;
1335 unsigned int sbww = sbw[w];
1336 tmp[sbww][w][sw[w]++] = xr[l];
1338 if (sw[w] == 6) {
1339 sw[w] = 0;
1340 ++sbw[w];
1344 memcpy(&xr[18 * sb], &tmp[sb], (576 - 18 * sb) * sizeof(mad_fixed_t));
1348 * NAME: III_stereo()
1349 * DESCRIPTION: perform joint stereo processing on a granule
1351 static
1352 enum mad_error III_stereo(mad_fixed_t xr[2][576],
1353 struct granule const *granule,
1354 struct mad_header *header,
1355 unsigned char const *sfbwidth)
1357 short modes[39];
1358 unsigned int sfbi, l, n, i;
1360 if (granule->ch[0].block_type !=
1361 granule->ch[1].block_type ||
1362 (granule->ch[0].flags & mixed_block_flag) !=
1363 (granule->ch[1].flags & mixed_block_flag))
1364 return MAD_ERROR_BADSTEREO;
1366 for (i = 0; i < 39; ++i)
1367 modes[i] = header->mode_extension;
1369 /* intensity stereo */
1371 if (header->mode_extension & I_STEREO) {
1372 struct channel const *right_ch = &granule->ch[1];
1373 mad_fixed_t const *right_xr = xr[1];
1374 unsigned int is_pos;
1376 header->flags |= MAD_FLAG_I_STEREO;
1378 /* first determine which scalefactor bands are to be processed */
1380 if (right_ch->block_type == 2) {
1381 unsigned int lower, start, max, bound[3], w;
1383 lower = start = max = bound[0] = bound[1] = bound[2] = 0;
1385 sfbi = l = 0;
1387 if (right_ch->flags & mixed_block_flag) {
1388 while (l < 36) {
1389 n = sfbwidth[sfbi++];
1391 for (i = 0; i < n; ++i) {
1392 if (right_xr[i]) {
1393 lower = sfbi;
1394 break;
1398 right_xr += n;
1399 l += n;
1402 start = sfbi;
1405 w = 0;
1406 while (l < 576) {
1407 n = sfbwidth[sfbi++];
1409 for (i = 0; i < n; ++i) {
1410 if (right_xr[i]) {
1411 max = bound[w] = sfbi;
1412 break;
1416 right_xr += n;
1417 l += n;
1418 w = (w + 1) % 3;
1421 if (max)
1422 lower = start;
1424 /* long blocks */
1426 for (i = 0; i < lower; ++i)
1427 modes[i] = header->mode_extension & ~I_STEREO;
1429 /* short blocks */
1431 w = 0;
1432 for (i = start; i < max; ++i) {
1433 if (i < bound[w])
1434 modes[i] = header->mode_extension & ~I_STEREO;
1436 w = (w + 1) % 3;
1439 else { /* right_ch->block_type != 2 */
1440 unsigned int bound;
1442 bound = 0;
1443 for (sfbi = l = 0; l < 576; l += n) {
1444 n = sfbwidth[sfbi++];
1446 for (i = 0; i < n; ++i) {
1447 if (right_xr[i]) {
1448 bound = sfbi;
1449 break;
1453 right_xr += n;
1456 for (i = 0; i < bound; ++i)
1457 modes[i] = header->mode_extension & ~I_STEREO;
1460 /* now do the actual processing */
1462 if (header->flags & MAD_FLAG_LSF_EXT) {
1463 unsigned char const *illegal_pos = granule[1].ch[1].scalefac;
1464 mad_fixed_t const *lsf_scale;
1466 /* intensity_scale */
1467 lsf_scale = is_lsf_table[right_ch->scalefac_compress & 0x1];
1469 for (sfbi = l = 0; l < 576; ++sfbi, l += n) {
1470 n = sfbwidth[sfbi];
1472 if (!(modes[sfbi] & I_STEREO))
1473 continue;
1475 if (illegal_pos[sfbi]) {
1476 modes[sfbi] &= ~I_STEREO;
1477 continue;
1480 is_pos = right_ch->scalefac[sfbi];
1482 for (i = 0; i < n; ++i) {
1483 register mad_fixed_t left;
1485 left = xr[0][l + i];
1487 if (is_pos == 0)
1488 xr[1][l + i] = left;
1489 else {
1490 register mad_fixed_t opposite;
1492 opposite = mad_f_mul(left, lsf_scale[(is_pos - 1) / 2]);
1494 if (is_pos & 1) {
1495 xr[0][l + i] = opposite;
1496 xr[1][l + i] = left;
1498 else
1499 xr[1][l + i] = opposite;
1504 else { /* !(header->flags & MAD_FLAG_LSF_EXT) */
1505 for (sfbi = l = 0; l < 576; ++sfbi, l += n) {
1506 n = sfbwidth[sfbi];
1508 if (!(modes[sfbi] & I_STEREO))
1509 continue;
1511 is_pos = right_ch->scalefac[sfbi];
1513 if (is_pos >= 7) { /* illegal intensity position */
1514 modes[sfbi] &= ~I_STEREO;
1515 continue;
1518 for (i = 0; i < n; ++i) {
1519 register mad_fixed_t left;
1521 left = xr[0][l + i];
1523 xr[0][l + i] = mad_f_mul(left, is_table[ is_pos]);
1524 xr[1][l + i] = mad_f_mul(left, is_table[6 - is_pos]);
1530 /* middle/side stereo */
1532 if (header->mode_extension & MS_STEREO) {
1533 register mad_fixed_t invsqrt2;
1535 header->flags |= MAD_FLAG_MS_STEREO;
1537 invsqrt2 = root_table[3 + -2];
1539 for (sfbi = l = 0; l < 576; ++sfbi, l += n) {
1540 n = sfbwidth[sfbi];
1542 if (modes[sfbi] != MS_STEREO)
1543 continue;
1545 for (i = 0; i < n; ++i) {
1546 register mad_fixed_t m, s;
1548 m = xr[0][l + i];
1549 s = xr[1][l + i];
1551 xr[0][l + i] = mad_f_mul(m + s, invsqrt2); /* l = (m + s) / sqrt(2) */
1552 xr[1][l + i] = mad_f_mul(m - s, invsqrt2); /* r = (m - s) / sqrt(2) */
1557 return MAD_ERROR_NONE;
1560 #if defined(CPU_ARM)
1561 void III_aliasreduce(mad_fixed_t xr[576], int lines);
1562 #else
1564 * NAME: III_aliasreduce()
1565 * DESCRIPTION: perform frequency line alias reduction
1567 static
1568 void III_aliasreduce(mad_fixed_t xr[576], int lines)
1570 mad_fixed_t const *bound;
1571 int i;
1573 bound = &xr[lines];
1574 for (xr += 18; xr < bound; xr += 18) {
1575 for (i = 0; i < 8; ++i) {
1576 register mad_fixed_t a, b;
1577 register mad_fixed64hi_t hi;
1578 register mad_fixed64lo_t lo;
1580 a = xr[-1 - i];
1581 b = xr[ i];
1583 # if defined(CPU_COLDFIRE)
1584 (void)hi, (void)lo;
1585 asm volatile ("mac.l %[a], %[csi], %%acc0\n\t"
1586 "msac.l %[b], %[cai], %%acc0\n\t"
1587 "mac.l %[b], %[csi], %%acc1\n\t"
1588 "mac.l %[a], %[cai], %%acc1\n\t"
1589 "movclr.l %%acc0, %[a]\n\t"
1590 "asl.l #3, %[a]\n\t"
1591 "movclr.l %%acc1, %[b]\n\t"
1592 "asl.l #3, %[b]\n\t"
1593 : [a] "+d" (a), [b] "+d" (b)
1594 : [csi] "r" (cs[i]), [cai] "r" (ca[i]));
1595 xr[-1 - i] = a;
1596 xr[ i] = b;
1597 # else
1598 MAD_F_ML0(hi, lo, a, cs[i]);
1599 MAD_F_MLA(hi, lo, -b, ca[i]);
1601 xr[-1 - i] = MAD_F_MLZ(hi, lo);
1603 MAD_F_ML0(hi, lo, b, cs[i]);
1604 MAD_F_MLA(hi, lo, a, ca[i]);
1606 xr[ i] = MAD_F_MLZ(hi, lo);
1607 # endif
1611 #endif
1613 # if defined(FPM_ARM)
1614 void III_imdct_l(mad_fixed_t const [18], mad_fixed_t [36], unsigned int);
1615 # else
1617 * NAME: imdct36
1618 * DESCRIPTION: perform X[18]->x[36] IMDCT
1620 # if defined(CPU_COLDFIRE)
1621 /* emac optimized imdct36, it is very ugly and i hope to replace it soon.
1622 * for now it is actually somewhat faster than the stock implementation.
1624 static inline
1625 void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36])
1627 mad_fixed_t t[16];
1628 /* assumes FRACBITS = 28 */
1629 asm volatile (
1630 /* MAD_F_ML0(hi, lo, X[4], MAD_F(0x0ec835e8)); */
1631 /* MAD_F_MLA(hi, lo, X[13], MAD_F(0x061f78aa)); */
1632 /* t6 = MAD_F_MLZ(hi, lo); */
1633 "move.l (4*4, %[X]), %%d0\n"
1634 "move.l #0x0ec835e8, %%d1\n"
1635 "move.l #0x061f78aa, %%d2\n"
1636 "mac.l %%d1, %%d0, (13*4, %[X]), %%d0, %%acc0\n"
1637 "mac.l %%d2, %%d0, ( 1*4, %[X]), %%d0, %%acc0\n"
1638 "move.l %%acc0, %%d7\n"
1639 "asl.l #3, %%d7\n"
1640 "move.l %%d7, (6*4, %[t])\n"
1642 /* MAD_F_ML0(hi, lo, (t14 = X[1] - X[10]), -MAD_F(0x0ec835e8)); */
1643 /* MAD_F_MLA(hi, lo, (t15 = X[7] + X[16]), MAD_F(0x061f78aa)); */
1644 /* t4 = MAD_F_MLZ(hi, lo); */
1645 /* MAD_F_MLA(hi, lo, t14, -MAD_F(0x061f78aa)); */
1646 /* MAD_F_MLA(hi, lo, t15, -MAD_F(0x0ec835e8)); */
1647 /* t0 = MAD_F_MLZ(hi, lo); */
1648 "sub.l (10*4, %[X]), %%d0\n" /* t14 */
1649 "msac.l %%d0, %%d1, %%acc1\n"
1650 "msac.l %%d0, %%d2, (7*4, %[X]), %%d5, %%acc0\n"
1651 "add.l (16*4, %[X]), %%d5\n" /* t15 */
1652 "mac.l %%d5, %%d2, %%acc1\n"
1653 "msac.l %%d5, %%d1, ( %[X]), %%d5, %%acc0\n"
1654 "movclr.l %%acc1, %%d6\n"
1655 "asl.l #3, %%d6\n" /* t4 */
1656 "move.l %%d6, (4*4, %[t])\n"
1657 "move.l %%acc0, %%d0\n"
1658 "asl.l #3, %%d0\n" /* t0 */
1659 "move.l %%d0, (0*4, %[t])\n"
1661 /* MAD_F_MLA(hi, lo, (t8 =X[0]-X[11]-X[12]), MAD_F(0x0216a2a2)); */
1662 /* MAD_F_MLA(hi, lo, (t9 =X[2]-X[ 9]-X[14]), MAD_F(0x09bd7ca0)); */
1663 /* MAD_F_MLA(hi, lo, (t10=X[3]-X[ 8]-X[15]), -MAD_F(0x0cb19346)); */
1664 /* MAD_F_MLA(hi, lo, (t11=X[5]-X[ 6]-X[17]), -MAD_F(0x0fdcf549)); */
1665 /* x[10] = -(x[7] = MAD_F_MLZ(hi, lo)); */
1667 /* MAD_F_ML0(hi, lo, t8, -MAD_F(0x0cb19346)); */
1668 /* MAD_F_MLA(hi, lo, t9, MAD_F(0x0fdcf549)); */
1669 /* MAD_F_MLA(hi, lo, t10, MAD_F(0x0216a2a2)); */
1670 /* MAD_F_MLA(hi, lo, t11, -MAD_F(0x09bd7ca0)); */
1671 /* x[19] = x[34] = MAD_F_MLZ(hi, lo) - t0; */
1673 /* MAD_F_ML0(hi, lo, t8, MAD_F(0x09bd7ca0)); */
1674 /* MAD_F_MLA(hi, lo, t9, -MAD_F(0x0216a2a2)); */
1675 /* MAD_F_MLA(hi, lo, t10, MAD_F(0x0fdcf549)); */
1676 /* MAD_F_MLA(hi, lo, t11, -MAD_F(0x0cb19346)); */
1677 /* x[ 1] = MAD_F_MLZ(hi, lo); */
1679 /* MAD_F_ML0(hi, lo, t8, -MAD_F(0x0fdcf549)); */
1680 /* MAD_F_MLA(hi, lo, t9, -MAD_F(0x0cb19346)); */
1681 /* MAD_F_MLA(hi, lo, t10, -MAD_F(0x09bd7ca0)); */
1682 /* MAD_F_MLA(hi, lo, t11, -MAD_F(0x0216a2a2)); */
1683 /* x[25] = MAD_F_MLZ(hi, lo); */
1685 /* t12 = t8 - t10; */
1686 /* t13 = t9 + t11; */
1687 "move.l #0x0216a2a2, %%d1\n"
1688 "move.l #0x0cb19346, %%d2\n"
1689 "move.l #0x09bd7ca0, %%d3\n"
1690 "move.l #0x0fdcf549, %%d4\n"
1691 "sub.l (11*4, %[X]), %%d5\n"
1692 "sub.l (12*4, %[X]), %%d5\n"
1693 "mac.l %%d1, %%d5, %%acc0\n"
1694 "msac.l %%d2, %%d5, %%acc1\n"
1695 "mac.l %%d3, %%d5, %%acc2\n"
1696 "msac.l %%d4, %%d5, (2*4, %[X]), %%d6, %%acc3\n"
1697 "sub.l ( 9*4, %[X]), %%d6\n"
1698 "sub.l (14*4, %[X]), %%d6\n"
1699 "mac.l %%d3, %%d6, %%acc0\n"
1700 "mac.l %%d4, %%d6, %%acc1\n"
1701 "msac.l %%d1, %%d6, %%acc2\n"
1702 "msac.l %%d2, %%d6, (3*4, %[X]), %%d7, %%acc3\n"
1703 "sub.l ( 8*4, %[X]), %%d7\n"
1704 "sub.l (15*4, %[X]), %%d7\n"
1705 "sub.l %%d7, %%d5\n" /* d5: t12 */
1706 "move.l %%d5, (12*4, %[t])\n"
1707 "msac.l %%d2, %%d7, %%acc0\n"
1708 "mac.l %%d1, %%d7, %%acc1\n"
1709 "mac.l %%d4, %%d7, %%acc2\n"
1710 "msac.l %%d3, %%d7, (5*4, %[X]), %%d7, %%acc3\n"
1711 "sub.l ( 6*4, %[X]), %%d7\n"
1712 "sub.l (17*4, %[X]), %%d7\n"
1713 "add.l %%d7, %%d6\n" /* d6: t13 */
1714 "move.l %%d6, (13*4, %[t])\n"
1715 "msac.l %%d4, %%d7, %%acc0\n"
1716 "msac.l %%d3, %%d7, %%acc1\n"
1717 "msac.l %%d2, %%d7, %%acc2\n"
1718 "msac.l %%d1, %%d7, (1*4, %[X]), %%d5, %%acc3\n"
1720 "movclr.l %%acc0, %%d7\n"
1721 "asl.l #3, %%d7\n"
1722 "move.l %%d7, (7*4, %[x])\n"
1723 "neg.l %%d7\n"
1724 "move.l %%d7, (10*4, %[x])\n"
1726 "movclr.l %%acc1, %%d7\n"
1727 "asl.l #3, %%d7\n"
1728 "sub.l %%d0, %%d7\n"
1729 "move.l %%d7, (19*4, %[x])\n"
1730 "move.l %%d7, (34*4, %[x])\n"
1732 "movclr.l %%acc2, %%d7\n"
1733 "asl.l #3, %%d7\n"
1734 "move.l %%d7, ( 1*4, %[x])\n"
1736 "movclr.l %%acc3, %%d7\n"
1737 "asl.l #3, %%d7\n"
1738 "move.l %%d7, (25*4, %[x])\n"
1740 /* MAD_F_ML0(hi, lo, X[1], -MAD_F(0x09bd7ca0)); */
1741 /* MAD_F_MLA(hi, lo, X[7], MAD_F(0x0216a2a2)); */
1742 /* MAD_F_MLA(hi, lo, X[10], -MAD_F(0x0fdcf549)); */
1743 /* MAD_F_MLA(hi, lo, X[16], MAD_F(0x0cb19346)); */
1744 /* t1 = MAD_F_MLZ(hi, lo) + t6; */
1746 /* MAD_F_ML0(hi, lo, X[1], -MAD_F(0x0216a2a2)); */
1747 /* MAD_F_MLA(hi, lo, X[7], -MAD_F(0x09bd7ca0)); */
1748 /* MAD_F_MLA(hi, lo, X[10], MAD_F(0x0cb19346)); */
1749 /* MAD_F_MLA(hi, lo, X[16], MAD_F(0x0fdcf549)); */
1750 /* t3 = MAD_F_MLZ(hi, lo); */
1752 /* MAD_F_ML0(hi, lo, X[1], -MAD_F(0x0fdcf549)); */
1753 /* MAD_F_MLA(hi, lo, X[7], -MAD_F(0x0cb19346)); */
1754 /* MAD_F_MLA(hi, lo, X[10], -MAD_F(0x09bd7ca0)); */
1755 /* MAD_F_MLA(hi, lo, X[16], -MAD_F(0x0216a2a2)); */
1756 /* t5 = MAD_F_MLZ(hi, lo) - t6; */
1757 "msac.l %%d3, %%d5, %%acc0\n"
1758 "msac.l %%d1, %%d5, %%acc1\n"
1759 "msac.l %%d4, %%d5, ( 7*4, %[X]), %%d5, %%acc2\n"
1760 "mac.l %%d1, %%d5, %%acc0\n"
1761 "msac.l %%d3, %%d5, %%acc1\n"
1762 "msac.l %%d2, %%d5, (10*4, %[X]), %%d5, %%acc2\n"
1763 "msac.l %%d4, %%d5, %%acc0\n"
1764 "mac.l %%d2, %%d5, %%acc1\n"
1765 "msac.l %%d3, %%d5, (16*4, %[X]), %%d5, %%acc2\n"
1766 "mac.l %%d2, %%d5, %%acc0\n"
1767 "mac.l %%d4, %%d5, %%acc1\n"
1768 "msac.l %%d1, %%d5, ( 0*4, %[X]), %%d0, %%acc2\n"
1770 "movclr.l %%acc0, %%d7\n"
1771 "asl.l #3, %%d7\n"
1772 "add.l (6*4, %[t]), %%d7\n" /* t1 */
1774 "movclr.l %%acc1, %%d5\n"
1775 "asl.l #3, %%d5\n" /* t3 */
1777 "movclr.l %%acc2, %%d6\n"
1778 "asl.l #3, %%d6\n"
1779 "sub.l (6*4, %[t]), %%d6\n" /* t5 */
1780 "move.l %%d6, (5*4, %[t])\n"
1782 /* MAD_F_ML0(hi, lo, X[0], MAD_F(0x03768962)); */
1783 /* MAD_F_MLA(hi, lo, X[2], MAD_F(0x0e313245)); */
1784 /* MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0ffc19fd)); */
1785 /* MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0acf37ad)); */
1786 /* MAD_F_MLA(hi, lo, X[6], MAD_F(0x04cfb0e2)); */
1787 /* MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0898c779)); */
1788 /* MAD_F_MLA(hi, lo, X[9], MAD_F(0x0d7e8807)); */
1789 /* MAD_F_MLA(hi, lo, X[11], MAD_F(0x0f426cb5)); */
1790 /* MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0bcbe352)); */
1791 /* MAD_F_MLA(hi, lo, X[14], MAD_F(0x00b2aa3e)); */
1792 /* MAD_F_MLA(hi, lo, X[15], -MAD_F(0x07635284)); */
1793 /* MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0f9ee890)); */
1794 /* x[11] = -(x[6] = MAD_F_MLZ(hi, lo) + t1); */
1795 /* MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0f426cb5)); */
1796 /* MAD_F_MLA(hi, lo, X[2], -MAD_F(0x00b2aa3e)); */
1797 /* MAD_F_MLA(hi, lo, X[3], MAD_F(0x0898c779)); */
1798 /* MAD_F_MLA(hi, lo, X[5], MAD_F(0x0f9ee890)); */
1799 /* MAD_F_MLA(hi, lo, X[6], MAD_F(0x0acf37ad)); */
1800 /* MAD_F_MLA(hi, lo, X[8], -MAD_F(0x07635284)); */
1801 /* MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0e313245)); */
1802 /* MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0bcbe352)); */
1803 /* MAD_F_MLA(hi, lo, X[12], -MAD_F(0x03768962)); */
1804 /* MAD_F_MLA(hi, lo, X[14], MAD_F(0x0d7e8807)); */
1805 /* MAD_F_MLA(hi, lo, X[15], MAD_F(0x0ffc19fd)); */
1806 /* MAD_F_MLA(hi, lo, X[17], MAD_F(0x04cfb0e2)); */
1807 /* x[23] = x[30] = MAD_F_MLZ(hi, lo) + t1; */
1808 /* MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0bcbe352)); */
1809 /* MAD_F_MLA(hi, lo, X[2], MAD_F(0x0d7e8807)); */
1810 /* MAD_F_MLA(hi, lo, X[3], -MAD_F(0x07635284)); */
1811 /* MAD_F_MLA(hi, lo, X[5], MAD_F(0x04cfb0e2)); */
1812 /* MAD_F_MLA(hi, lo, X[6], MAD_F(0x0f9ee890)); */
1813 /* MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0ffc19fd)); */
1814 /* MAD_F_MLA(hi, lo, X[9], -MAD_F(0x00b2aa3e)); */
1815 /* MAD_F_MLA(hi, lo, X[11], MAD_F(0x03768962)); */
1816 /* MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0f426cb5)); */
1817 /* MAD_F_MLA(hi, lo, X[14], MAD_F(0x0e313245)); */
1818 /* MAD_F_MLA(hi, lo, X[15], MAD_F(0x0898c779)); */
1819 /* MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0acf37ad)); */
1820 /* x[18] = x[35] = MAD_F_MLZ(hi, lo) - t1; */
1821 "move.l #0x03768962, %%d1\n"
1822 "move.l #0x0f426cb5, %%d2\n"
1823 "move.l #0x0bcbe352, %%d3\n"
1824 "mac.l %%d1, %%d0, %%acc0\n"
1825 "msac.l %%d2, %%d0, %%acc1\n"
1826 "msac.l %%d3, %%d0, (11*4, %[X]), %%d0, %%acc2\n"
1827 "mac.l %%d2, %%d0, %%acc0\n"
1828 "msac.l %%d3, %%d0, %%acc1\n"
1829 "mac.l %%d1, %%d0, (12*4, %[X]), %%d0, %%acc2\n"
1830 "msac.l %%d3, %%d0, %%acc0\n"
1831 "msac.l %%d1, %%d0, %%acc1\n"
1832 "msac.l %%d2, %%d0, ( 2*4, %[X]), %%d0, %%acc2\n"
1833 "move.l #0x0e313245, %%d1\n"
1834 "move.l #0x00b2aa3e, %%d2\n"
1835 "move.l #0x0d7e8807, %%d3\n"
1836 "mac.l %%d1, %%d0, %%acc0\n"
1837 "msac.l %%d2, %%d0, %%acc1\n"
1838 "mac.l %%d3, %%d0, ( 9*4, %[X]), %%d0, %%acc2\n"
1839 "mac.l %%d3, %%d0, %%acc0\n"
1840 "msac.l %%d1, %%d0, %%acc1\n"
1841 "msac.l %%d2, %%d0, (14*4, %[X]), %%d0, %%acc2\n"
1842 "mac.l %%d2, %%d0, %%acc0\n"
1843 "mac.l %%d3, %%d0, %%acc1\n"
1844 "mac.l %%d1, %%d0, ( 3*4, %[X]), %%d0, %%acc2\n"
1845 "move.l #0x0ffc19fd, %%d1\n"
1846 "move.l #0x0898c779, %%d2\n"
1847 "move.l #0x07635284, %%d3\n"
1848 "msac.l %%d1, %%d0, %%acc0\n"
1849 "mac.l %%d2, %%d0, %%acc1\n"
1850 "msac.l %%d3, %%d0, ( 8*4, %[X]), %%d0, %%acc2\n"
1851 "msac.l %%d2, %%d0, %%acc0\n"
1852 "msac.l %%d3, %%d0, %%acc1\n"
1853 "msac.l %%d1, %%d0, (15*4, %[X]), %%d0, %%acc2\n"
1854 "msac.l %%d3, %%d0, %%acc0\n"
1855 "mac.l %%d1, %%d0, %%acc1\n"
1856 "mac.l %%d2, %%d0, ( 5*4, %[X]), %%d0, %%acc2\n"
1857 "move.l #0x0acf37ad, %%d1\n"
1858 "move.l #0x0f9ee890, %%d2\n"
1859 "move.l #0x04cfb0e2, %%d3\n"
1860 "msac.l %%d1, %%d0, %%acc0\n"
1861 "mac.l %%d2, %%d0, %%acc1\n"
1862 "mac.l %%d3, %%d0, ( 6*4, %[X]), %%d0, %%acc2\n"
1863 "mac.l %%d3, %%d0, %%acc0\n"
1864 "mac.l %%d1, %%d0, %%acc1\n"
1865 "mac.l %%d2, %%d0, (17*4, %[X]), %%d0, %%acc2\n"
1866 "msac.l %%d2, %%d0, %%acc0\n"
1867 "mac.l %%d3, %%d0, %%acc1\n"
1868 "msac.l %%d1, %%d0, ( 4*4, %[X]), %%d0, %%acc2\n"
1870 "movclr.l %%acc0, %%d6\n"
1871 "asl.l #3, %%d6\n"
1872 "add.l %%d7, %%d6\n"
1873 "move.l %%d6, (6*4, %[x])\n"
1874 "neg.l %%d6\n"
1875 "move.l %%d6, (11*4, %[x])\n"
1877 "movclr.l %%acc1, %%d6\n"
1878 "asl.l #3, %%d6\n"
1879 "add.l %%d7, %%d6\n"
1880 "move.l %%d6, (23*4, %[x])\n"
1881 "move.l %%d6, (30*4, %[x])\n"
1883 "movclr.l %%acc2, %%d6\n"
1884 "asl.l #3, %%d6\n"
1885 "sub.l %%d7, %%d6\n"
1886 "move.l %%d6, (18*4, %[x])\n"
1887 "move.l %%d6, (35*4, %[x])\n"
1889 /* MAD_F_ML0(hi, lo, X[4], MAD_F(0x061f78aa)); */
1890 /* MAD_F_MLA(hi, lo, X[13], -MAD_F(0x0ec835e8)); */
1891 /* t3 += (t7 = MAD_F_MLZ(hi, lo)); */
1892 /* t4 -= t7; */
1893 "move.l #0x061f78aa, %%d1\n"
1894 "mac.l %%d1, %%d0, (13*4, %[X]), %%d0, %%acc0\n"
1895 "move.l #0x0ec835e8, %%d1\n"
1896 "msac.l %%d1, %%d0, (1*4, %[X]), %%d0, %%acc0\n"
1897 "move.l %%acc0, %%d6\n"
1898 "asl.l #3, %%d6\n" /* t7 */
1899 "add.l %%d6, %%d5\n" /* t3 */
1900 "move.l (4*4, %[t]), %%d1\n"
1901 "sub.l %%d6, %%d1\n" /* t4 */
1902 "move.l %%d1, (4*4, %[t])\n"
1904 /* MAD_F_MLA(hi, lo, X[1], -MAD_F(0x0cb19346)); */
1905 /* MAD_F_MLA(hi, lo, X[7], MAD_F(0x0fdcf549)); */
1906 /* MAD_F_MLA(hi, lo, X[10], MAD_F(0x0216a2a2)); */
1907 /* MAD_F_MLA(hi, lo, X[16], -MAD_F(0x09bd7ca0)); */
1908 /* t2 = MAD_F_MLZ(hi, lo); */
1909 "move.l #0x0cb19346, %%d1\n"
1910 "msac.l %%d1, %%d0, ( 7*4, %[X]), %%d0, %%acc0\n"
1911 "move.l #0x0fdcf549, %%d1\n"
1912 "mac.l %%d1, %%d0, (10*4, %[X]), %%d0, %%acc0\n"
1913 "move.l #0x0216a2a2, %%d1\n"
1914 "mac.l %%d1, %%d0, (16*4, %[X]), %%d0, %%acc0\n"
1915 "move.l #0x09bd7ca0, %%d1\n"
1916 "msac.l %%d1, %%d0, ( %[X]), %%d0, %%acc0\n"
1917 "move.l %%acc0, %%d7\n"
1918 "asl.l #3, %%d7\n" /* t2 */
1920 /* MAD_F_MLA(hi, lo, X[0], MAD_F(0x04cfb0e2)); */
1921 /* MAD_F_MLA(hi, lo, X[2], MAD_F(0x0ffc19fd)); */
1922 /* MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0d7e8807)); */
1923 /* MAD_F_MLA(hi, lo, X[5], MAD_F(0x03768962)); */
1924 /* MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0bcbe352)); */
1925 /* MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0e313245)); */
1926 /* MAD_F_MLA(hi, lo, X[9], MAD_F(0x07635284)); */
1927 /* MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0acf37ad)); */
1928 /* MAD_F_MLA(hi, lo, X[12], MAD_F(0x0f9ee890)); */
1929 /* MAD_F_MLA(hi, lo, X[14], MAD_F(0x0898c779)); */
1930 /* MAD_F_MLA(hi, lo, X[15], MAD_F(0x00b2aa3e)); */
1931 /* MAD_F_MLA(hi, lo, X[17], MAD_F(0x0f426cb5)); */
1932 /* x[12] = -(x[5] = MAD_F_MLZ(hi, lo)); */
1933 /* MAD_F_ML0(hi, lo, X[0], MAD_F(0x0acf37ad)); */
1934 /* MAD_F_MLA(hi, lo, X[2], -MAD_F(0x0898c779)); */
1935 /* MAD_F_MLA(hi, lo, X[3], MAD_F(0x0e313245)); */
1936 /* MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0f426cb5)); */
1937 /* MAD_F_MLA(hi, lo, X[6], -MAD_F(0x03768962)); */
1938 /* MAD_F_MLA(hi, lo, X[8], MAD_F(0x00b2aa3e)); */
1939 /* MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0ffc19fd)); */
1940 /* MAD_F_MLA(hi, lo, X[11], MAD_F(0x0f9ee890)); */
1941 /* MAD_F_MLA(hi, lo, X[12], -MAD_F(0x04cfb0e2)); */
1942 /* MAD_F_MLA(hi, lo, X[14], MAD_F(0x07635284)); */
1943 /* MAD_F_MLA(hi, lo, X[15], MAD_F(0x0d7e8807)); */
1944 /* MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0bcbe352)); */
1945 /* x[17] = -(x[0] = MAD_F_MLZ(hi, lo) + t2); */
1946 /* MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0f9ee890)); */
1947 /* MAD_F_MLA(hi, lo, X[2], -MAD_F(0x07635284)); */
1948 /* MAD_F_MLA(hi, lo, X[3], -MAD_F(0x00b2aa3e)); */
1949 /* MAD_F_MLA(hi, lo, X[5], MAD_F(0x0bcbe352)); */
1950 /* MAD_F_MLA(hi, lo, X[6], MAD_F(0x0f426cb5)); */
1951 /* MAD_F_MLA(hi, lo, X[8], MAD_F(0x0d7e8807)); */
1952 /* MAD_F_MLA(hi, lo, X[9], MAD_F(0x0898c779)); */
1953 /* MAD_F_MLA(hi, lo, X[11], -MAD_F(0x04cfb0e2)); */
1954 /* MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0acf37ad)); */
1955 /* MAD_F_MLA(hi, lo, X[14], -MAD_F(0x0ffc19fd)); */
1956 /* MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0e313245)); */
1957 /* MAD_F_MLA(hi, lo, X[17], -MAD_F(0x03768962)); */
1958 /* x[24] = x[29] = MAD_F_MLZ(hi, lo) + t2; */
1959 "move.l #0x0acf37ad, %%d1\n"
1960 "move.l #0x0f9ee890, %%d2\n"
1961 "move.l #0x04cfb0e2, %%d3\n"
1962 "mac.l %%d3, %%d0, %%acc0\n"
1963 "mac.l %%d1, %%d0, %%acc1\n"
1964 "msac.l %%d2, %%d0, (11*4, %[X]), %%d0, %%acc2\n"
1965 "msac.l %%d1, %%d0, %%acc0\n"
1966 "mac.l %%d2, %%d0, %%acc1\n"
1967 "msac.l %%d3, %%d0, (12*4, %[X]), %%d0, %%acc2\n"
1968 "mac.l %%d2, %%d0, %%acc0\n"
1969 "msac.l %%d3, %%d0, %%acc1\n"
1970 "msac.l %%d1, %%d0, ( 2*4, %[X]), %%d0, %%acc2\n"
1971 "move.l #0x0ffc19fd, %%d1\n"
1972 "move.l #0x0898c779, %%d2\n"
1973 "move.l #0x07635284, %%d3\n"
1974 "mac.l %%d1, %%d0, %%acc0\n"
1975 "msac.l %%d2, %%d0, %%acc1\n"
1976 "msac.l %%d3, %%d0, ( 9*4, %[X]), %%d0, %%acc2\n"
1977 "mac.l %%d3, %%d0, %%acc0\n"
1978 "msac.l %%d1, %%d0, %%acc1\n"
1979 "mac.l %%d2, %%d0, (14*4, %[X]), %%d0, %%acc2\n"
1980 "mac.l %%d2, %%d0, %%acc0\n"
1981 "mac.l %%d3, %%d0, %%acc1\n"
1982 "msac.l %%d1, %%d0, ( 3*4, %[X]), %%d0, %%acc2\n"
1983 "move.l #0x0e313245, %%d1\n"
1984 "move.l #0x00b2aa3e, %%d2\n"
1985 "move.l #0x0d7e8807, %%d3\n"
1986 "msac.l %%d3, %%d0, %%acc0\n"
1987 "mac.l %%d1, %%d0, %%acc1\n"
1988 "msac.l %%d2, %%d0, ( 8*4, %[X]), %%d0, %%acc2\n"
1989 "msac.l %%d1, %%d0, %%acc0\n"
1990 "mac.l %%d2, %%d0, %%acc1\n"
1991 "mac.l %%d3, %%d0, (15*4, %[X]), %%d0, %%acc2\n"
1992 "mac.l %%d2, %%d0, %%acc0\n"
1993 "mac.l %%d3, %%d0, %%acc1\n"
1994 "msac.l %%d1, %%d0, ( 5*4, %[X]), %%d0, %%acc2\n"
1995 "move.l #0x03768962, %%d1\n"
1996 "move.l #0x0f426cb5, %%d2\n"
1997 "move.l #0x0bcbe352, %%d3\n"
1998 "mac.l %%d1, %%d0, %%acc0\n"
1999 "msac.l %%d2, %%d0, %%acc1\n"
2000 "mac.l %%d3, %%d0, ( 6*4, %[X]), %%d0, %%acc2\n"
2001 "msac.l %%d3, %%d0, %%acc0\n"
2002 "msac.l %%d1, %%d0, %%acc1\n"
2003 "mac.l %%d2, %%d0, (17*4, %[X]), %%d0, %%acc2\n"
2004 "mac.l %%d2, %%d0, %%acc0\n"
2005 "msac.l %%d3, %%d0, %%acc1\n"
2006 "msac.l %%d1, %%d0, ( %[X]), %%d0, %%acc2\n"
2008 "movclr.l %%acc0, %%d6\n"
2009 "asl.l #3, %%d6\n"
2010 "move.l %%d6, ( 5*4, %[x])\n"
2011 "neg.l %%d6\n"
2012 "move.l %%d6, (12*4, %[x])\n"
2014 "movclr.l %%acc1, %%d6\n"
2015 "asl.l #3, %%d6\n"
2016 "add.l %%d7, %%d6\n"
2017 "move.l %%d6, ( %[x])\n"
2018 "neg.l %%d6\n"
2019 "move.l %%d6, (17*4, %[x])\n"
2021 "movclr.l %%acc2, %%d6\n"
2022 "asl.l #3, %%d6\n"
2023 "add.l %%d7, %%d6\n"
2024 "move.l %%d6, (24*4, %[x])\n"
2025 "move.l %%d6, (29*4, %[x])\n"
2027 /* MAD_F_ML0(hi, lo, X[0], MAD_F(0x00b2aa3e)); */
2028 /* MAD_F_MLA(hi, lo, X[2], MAD_F(0x03768962)); */
2029 /* MAD_F_MLA(hi, lo, X[3], -MAD_F(0x04cfb0e2)); */
2030 /* MAD_F_MLA(hi, lo, X[5], -MAD_F(0x07635284)); */
2031 /* MAD_F_MLA(hi, lo, X[6], MAD_F(0x0898c779)); */
2032 /* MAD_F_MLA(hi, lo, X[8], MAD_F(0x0acf37ad)); */
2033 /* MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0bcbe352)); */
2034 /* MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0d7e8807)); */
2035 /* MAD_F_MLA(hi, lo, X[12], MAD_F(0x0e313245)); */
2036 /* MAD_F_MLA(hi, lo, X[14], MAD_F(0x0f426cb5)); */
2037 /* MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0f9ee890)); */
2038 /* MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0ffc19fd)); */
2039 /* x[9] = -(x[8] = MAD_F_MLZ(hi, lo) + t3); */
2041 /* MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0e313245)); */
2042 /* MAD_F_MLA(hi, lo, X[2], MAD_F(0x0bcbe352)); */
2043 /* MAD_F_MLA(hi, lo, X[3], MAD_F(0x0f9ee890)); */
2044 /* MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0898c779)); */
2045 /* MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0ffc19fd)); */
2046 /* MAD_F_MLA(hi, lo, X[8], MAD_F(0x04cfb0e2)); */
2047 /* MAD_F_MLA(hi, lo, X[9], MAD_F(0x0f426cb5)); */
2048 /* MAD_F_MLA(hi, lo, X[11], -MAD_F(0x00b2aa3e)); */
2049 /* MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0d7e8807)); */
2050 /* MAD_F_MLA(hi, lo, X[14], -MAD_F(0x03768962)); */
2051 /* MAD_F_MLA(hi, lo, X[15], MAD_F(0x0acf37ad)); */
2052 /* MAD_F_MLA(hi, lo, X[17], MAD_F(0x07635284)); */
2053 /* x[21] = x[32] = MAD_F_MLZ(hi, lo) + t3; */
2055 /* MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0d7e8807)); */
2056 /* MAD_F_MLA(hi, lo, X[2], MAD_F(0x0f426cb5)); */
2057 /* MAD_F_MLA(hi, lo, X[3], MAD_F(0x0acf37ad)); */
2058 /* MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0ffc19fd)); */
2059 /* MAD_F_MLA(hi, lo, X[6], -MAD_F(0x07635284)); */
2060 /* MAD_F_MLA(hi, lo, X[8], MAD_F(0x0f9ee890)); */
2061 /* MAD_F_MLA(hi, lo, X[9], MAD_F(0x03768962)); */
2062 /* MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0e313245)); */
2063 /* MAD_F_MLA(hi, lo, X[12], MAD_F(0x00b2aa3e)); */
2064 /* MAD_F_MLA(hi, lo, X[14], MAD_F(0x0bcbe352)); */
2065 /* MAD_F_MLA(hi, lo, X[15], -MAD_F(0x04cfb0e2)); */
2066 /* MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0898c779)); */
2067 /* x[20] = x[33] = MAD_F_MLZ(hi, lo) - t3; */
2068 "move.l #0x0e313245, %%d1\n"
2069 "move.l #0x00b2aa3e, %%d2\n"
2070 "move.l #0x0d7e8807, %%d3\n"
2071 "mac.l %%d2, %%d0, %%acc0\n"
2072 "msac.l %%d1, %%d0, %%acc1\n"
2073 "msac.l %%d3, %%d0, (11*4, %[X]), %%d0, %%acc2\n"
2074 "msac.l %%d3, %%d0, %%acc0\n"
2075 "msac.l %%d2, %%d0, %%acc1\n"
2076 "msac.l %%d1, %%d0, (12*4, %[X]), %%d0, %%acc2\n"
2077 "mac.l %%d1, %%d0, %%acc0\n"
2078 "msac.l %%d3, %%d0, %%acc1\n"
2079 "mac.l %%d2, %%d0, ( 2*4, %[X]), %%d0, %%acc2\n"
2080 "move.l #0x03768962, %%d1\n"
2081 "move.l #0x0f426cb5, %%d2\n"
2082 "move.l #0x0bcbe352, %%d3\n"
2083 "mac.l %%d1, %%d0, %%acc0\n"
2084 "mac.l %%d3, %%d0, %%acc1\n"
2085 "mac.l %%d2, %%d0, ( 9*4, %[X]), %%d0, %%acc2\n"
2086 "msac.l %%d3, %%d0, %%acc0\n"
2087 "mac.l %%d2, %%d0, %%acc1\n"
2088 "mac.l %%d1, %%d0, (14*4, %[X]), %%d0, %%acc2\n"
2089 "mac.l %%d2, %%d0, %%acc0\n"
2090 "msac.l %%d1, %%d0, %%acc1\n"
2091 "mac.l %%d3, %%d0, ( 3*4, %[X]), %%d0, %%acc2\n"
2092 "move.l #0x0acf37ad, %%d1\n"
2093 "move.l #0x0f9ee890, %%d2\n"
2094 "move.l #0x04cfb0e2, %%d3\n"
2095 "msac.l %%d3, %%d0, %%acc0\n"
2096 "mac.l %%d2, %%d0, %%acc1\n"
2097 "mac.l %%d1, %%d0, ( 8*4, %[X]), %%d0, %%acc2\n"
2098 "mac.l %%d1, %%d0, %%acc0\n"
2099 "mac.l %%d3, %%d0, %%acc1\n"
2100 "mac.l %%d2, %%d0, (15*4, %[X]), %%d0, %%acc2\n"
2101 "msac.l %%d2, %%d0, %%acc0\n"
2102 "mac.l %%d1, %%d0, %%acc1\n"
2103 "msac.l %%d3, %%d0, ( 5*4, %[X]), %%d0, %%acc2\n"
2104 "move.l #0x0ffc19fd, %%d1\n"
2105 "move.l #0x0898c779, %%d2\n"
2106 "move.l #0x07635284, %%d3\n"
2107 "msac.l %%d3, %%d0, %%acc0\n"
2108 "msac.l %%d2, %%d0, %%acc1\n"
2109 "msac.l %%d1, %%d0, ( 6*4, %[X]), %%d0, %%acc2\n"
2110 "mac.l %%d2, %%d0, %%acc0\n"
2111 "msac.l %%d1, %%d0, %%acc1\n"
2112 "msac.l %%d3, %%d0, (17*4, %[X]), %%d0, %%acc2\n"
2113 "msac.l %%d1, %%d0, %%acc0\n"
2114 "mac.l %%d3, %%d0, %%acc1\n"
2115 "msac.l %%d2, %%d0, (12*4, %[t]), %%d0, %%acc2\n"
2117 "movclr.l %%acc0, %%d6\n"
2118 "asl.l #3, %%d6\n"
2119 "add.l %%d5, %%d6\n"
2120 "move.l %%d6, (8*4, %[x])\n"
2121 "neg.l %%d6\n"
2122 "move.l %%d6, (9*4, %[x])\n"
2124 "movclr.l %%acc1, %%d6\n"
2125 "asl.l #3, %%d6\n"
2126 "add.l %%d5, %%d6\n"
2127 "move.l %%d6, (21*4, %[x])\n"
2128 "move.l %%d6, (32*4, %[x])\n"
2130 "movclr.l %%acc2, %%d6\n"
2131 "asl.l #3, %%d6\n"
2132 "sub.l %%d5, %%d6\n"
2133 "move.l %%d6, (20*4, %[x])\n"
2134 "move.l %%d6, (33*4, %[x])\n"
2136 /* MAD_F_ML0(hi, lo, t12, -MAD_F(0x0ec835e8)); */
2137 /* MAD_F_MLA(hi, lo, t13, MAD_F(0x061f78aa)); */
2138 /* x[22] = x[31] = MAD_F_MLZ(hi, lo) + t0; */
2139 "move.l #0x0ec835e8, %%d1\n"
2140 "move.l #0x061f78aa, %%d2\n"
2141 "msac.l %%d1, %%d0, (13*4, %[t]), %%d3, %%acc0\n"
2142 "mac.l %%d2, %%d3, ( 1*4, %[x]), %%d4, %%acc0\n"
2143 "movclr.l %%acc0, %%d6\n"
2144 "asl.l #3, %%d6\n"
2145 "add.l (0*4, %[t]), %%d6\n"
2146 "move.l %%d6, (22*4, %[x])\n"
2147 "move.l %%d6, (31*4, %[x])\n"
2149 /* MAD_F_ML0(hi, lo, t12, MAD_F(0x061f78aa)); */
2150 /* MAD_F_MLA(hi, lo, t13, MAD_F(0x0ec835e8)); */
2151 /* x[13] = -(x[4] = MAD_F_MLZ(hi, lo) + t4); */
2152 /* x[16] = -(x[1] = x[1] + t4); */
2153 /* x[25] = x[28] = x[25] + t4; */
2154 "mac.l %%d2, %%d0, (4*4, %[t]), %%d2, %%acc0\n"
2155 "mac.l %%d1, %%d3, ( %[X]), %%d0, %%acc0\n"
2156 "movclr.l %%acc0, %%d6\n"
2157 "asl.l #3, %%d6\n"
2158 "add.l %%d2, %%d6\n"
2159 "move.l %%d6, ( 4*4, %[x])\n"
2160 "neg.l %%d6\n"
2161 "move.l %%d6, (13*4, %[x])\n"
2163 "add.l %%d2, %%d4\n"
2164 "move.l %%d4, ( 1*4, %[x])\n"
2165 "neg.l %%d4\n"
2166 "move.l %%d4, (16*4, %[x])\n"
2168 "move.l (25*4, %[x]), %%d4\n"
2169 "add.l %%d2, %%d4\n"
2170 "move.l %%d4, (25*4, %[x])\n"
2171 "move.l %%d4, (28*4, %[x])\n"
2173 /* MAD_F_ML0(hi, lo, X[0], MAD_F(0x0898c779)); */
2174 /* MAD_F_MLA(hi, lo, X[2], MAD_F(0x04cfb0e2)); */
2175 /* MAD_F_MLA(hi, lo, X[3], MAD_F(0x0bcbe352)); */
2176 /* MAD_F_MLA(hi, lo, X[5], MAD_F(0x00b2aa3e)); */
2177 /* MAD_F_MLA(hi, lo, X[6], MAD_F(0x0e313245)); */
2178 /* MAD_F_MLA(hi, lo, X[8], -MAD_F(0x03768962)); */
2179 /* MAD_F_MLA(hi, lo, X[9], MAD_F(0x0f9ee890)); */
2180 /* MAD_F_MLA(hi, lo, X[11], -MAD_F(0x07635284)); */
2181 /* MAD_F_MLA(hi, lo, X[12], MAD_F(0x0ffc19fd)); */
2182 /* MAD_F_MLA(hi, lo, X[14], -MAD_F(0x0acf37ad)); */
2183 /* MAD_F_MLA(hi, lo, X[15], MAD_F(0x0f426cb5)); */
2184 /* MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0d7e8807)); */
2185 /* x[15] = -(x[2] = MAD_F_MLZ(hi, lo) + t5); */
2186 /* MAD_F_ML0(hi, lo, X[0], MAD_F(0x07635284)); */
2187 /* MAD_F_MLA(hi, lo, X[2], MAD_F(0x0acf37ad)); */
2188 /* MAD_F_MLA(hi, lo, X[3], MAD_F(0x03768962)); */
2189 /* MAD_F_MLA(hi, lo, X[5], MAD_F(0x0d7e8807)); */
2190 /* MAD_F_MLA(hi, lo, X[6], -MAD_F(0x00b2aa3e)); */
2191 /* MAD_F_MLA(hi, lo, X[8], MAD_F(0x0f426cb5)); */
2192 /* MAD_F_MLA(hi, lo, X[9], -MAD_F(0x04cfb0e2)); */
2193 /* MAD_F_MLA(hi, lo, X[11], MAD_F(0x0ffc19fd)); */
2194 /* MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0898c779)); */
2195 /* MAD_F_MLA(hi, lo, X[14], MAD_F(0x0f9ee890)); */
2196 /* MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0bcbe352)); */
2197 /* MAD_F_MLA(hi, lo, X[17], MAD_F(0x0e313245)); */
2198 /* x[14] = -(x[3] = MAD_F_MLZ(hi, lo) + t5); */
2199 /* MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0ffc19fd)); */
2200 /* MAD_F_MLA(hi, lo, X[2], -MAD_F(0x0f9ee890)); */
2201 /* MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0f426cb5)); */
2202 /* MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0e313245)); */
2203 /* MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0d7e8807)); */
2204 /* MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0bcbe352)); */
2205 /* MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0acf37ad)); */
2206 /* MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0898c779)); */
2207 /* MAD_F_MLA(hi, lo, X[12], -MAD_F(0x07635284)); */
2208 /* MAD_F_MLA(hi, lo, X[14], -MAD_F(0x04cfb0e2)); */
2209 /* MAD_F_MLA(hi, lo, X[15], -MAD_F(0x03768962)); */
2210 /* MAD_F_MLA(hi, lo, X[17], -MAD_F(0x00b2aa3e)); */
2211 /* x[26] = x[27] = MAD_F_MLZ(hi, lo) + t5; */
2212 "move.l #0x0ffc19fd, %%d1\n"
2213 "move.l #0x0898c779, %%d2\n"
2214 "move.l #0x07635284, %%d3\n"
2215 "mac.l %%d2, %%d0, %%acc0\n"
2216 "mac.l %%d3, %%d0, %%acc1\n"
2217 "msac.l %%d1, %%d0, (11*4, %[X]), %%d0, %%acc2\n"
2218 "msac.l %%d3, %%d0, %%acc0\n"
2219 "mac.l %%d1, %%d0, %%acc1\n"
2220 "msac.l %%d2, %%d0, (12*4, %[X]), %%d0, %%acc2\n"
2221 "mac.l %%d1, %%d0, %%acc0\n"
2222 "msac.l %%d2, %%d0, %%acc1\n"
2223 "msac.l %%d3, %%d0, ( 2*4, %[X]), %%d0, %%acc2\n"
2224 "move.l #0x0acf37ad, %%d1\n"
2225 "move.l #0x0f9ee890, %%d2\n"
2226 "move.l #0x04cfb0e2, %%d3\n"
2227 "mac.l %%d3, %%d0, %%acc0\n"
2228 "mac.l %%d1, %%d0, %%acc1\n"
2229 "msac.l %%d2, %%d0, ( 9*4, %[X]), %%d0, %%acc2\n"
2230 "mac.l %%d2, %%d0, %%acc0\n"
2231 "msac.l %%d3, %%d0, %%acc1\n"
2232 "msac.l %%d1, %%d0, (14*4, %[X]), %%d0, %%acc2\n"
2233 "msac.l %%d1, %%d0, %%acc0\n"
2234 "mac.l %%d2, %%d0, %%acc1\n"
2235 "msac.l %%d3, %%d0, ( 3*4, %[X]), %%d0, %%acc2\n"
2236 "move.l #0x03768962, %%d1\n"
2237 "move.l #0x0f426cb5, %%d2\n"
2238 "move.l #0x0bcbe352, %%d3\n"
2239 "mac.l %%d3, %%d0, %%acc0\n"
2240 "mac.l %%d1, %%d0, %%acc1\n"
2241 "msac.l %%d2, %%d0, ( 8*4, %[X]), %%d0, %%acc2\n"
2242 "msac.l %%d1, %%d0, %%acc0\n"
2243 "mac.l %%d2, %%d0, %%acc1\n"
2244 "msac.l %%d3, %%d0, (15*4, %[X]), %%d0, %%acc2\n"
2245 "mac.l %%d2, %%d0, %%acc0\n"
2246 "msac.l %%d3, %%d0, %%acc1\n"
2247 "msac.l %%d1, %%d0, ( 5*4, %[X]), %%d0, %%acc2\n"
2248 "move.l #0x0e313245, %%d1\n"
2249 "move.l #0x00b2aa3e, %%d2\n"
2250 "move.l #0x0d7e8807, %%d3\n"
2251 "mac.l %%d2, %%d0, %%acc0\n"
2252 "mac.l %%d3, %%d0, %%acc1\n"
2253 "msac.l %%d1, %%d0, ( 6*4, %[X]), %%d0, %%acc2\n"
2254 "mac.l %%d1, %%d0, %%acc0\n"
2255 "msac.l %%d2, %%d0, %%acc1\n"
2256 "msac.l %%d3, %%d0, (17*4, %[X]), %%d0, %%acc2\n"
2257 "msac.l %%d3, %%d0, %%acc0\n"
2258 "mac.l %%d1, %%d0, %%acc1\n"
2259 "msac.l %%d2, %%d0, ( 5*4, %[t]), %%d6, %%acc2\n"
2260 "movclr.l %%acc0, %%d7\n"
2261 "asl.l #3, %%d7\n"
2262 "add.l %%d6, %%d7\n"
2263 "move.l %%d7, (2*4, %[x])\n"
2264 "neg.l %%d7\n"
2265 "move.l %%d7, (15*4, %[x])\n"
2267 "movclr.l %%acc1, %%d7\n"
2268 "asl.l #3, %%d7\n"
2269 "add.l %%d6, %%d7\n"
2270 "move.l %%d7, (3*4, %[x])\n"
2271 "neg.l %%d7\n"
2272 "move.l %%d7, (14*4, %[x])\n"
2274 "movclr.l %%acc2, %%d7\n"
2275 "asl.l #3, %%d7\n"
2276 "add.l %%d6, %%d7\n"
2277 "move.l %%d7, (26*4, %[x])\n"
2278 "move.l %%d7, (27*4, %[x])\n"
2280 : : [X] "a" (X), [x] "a" (x), [t] "a" (t)
2281 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7");
2282 /* pfew */
2285 # else /* if defined(CPU_COLDFIRE) */
2287 static inline
2288 void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36])
2290 mad_fixed_t t0, t1, t2, t3, t4, t5, t6, t7;
2291 mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15;
2292 register mad_fixed64hi_t hi;
2293 register mad_fixed64lo_t lo;
2295 MAD_F_ML0(hi, lo, (t14 = X[1] - X[10]), -MAD_F(0x0ec835e8));
2296 MAD_F_MLA(hi, lo, (t15 = X[7] + X[16]), MAD_F(0x061f78aa));
2297 t4 = MAD_F_MLZ(hi, lo);
2299 MAD_F_ML0(hi, lo, X[4], MAD_F(0x0ec835e8));
2300 MAD_F_MLA(hi, lo, X[13], MAD_F(0x061f78aa));
2301 t6 = MAD_F_MLZ(hi, lo);
2303 MAD_F_MLA(hi, lo, t14, -MAD_F(0x061f78aa));
2304 MAD_F_MLA(hi, lo, t15, -MAD_F(0x0ec835e8));
2305 t0 = MAD_F_MLZ(hi, lo);
2307 MAD_F_MLA(hi, lo, (t8 =X[0]-X[11]-X[12]), MAD_F(0x0216a2a2));
2308 MAD_F_MLA(hi, lo, (t9 =X[2]-X[ 9]-X[14]), MAD_F(0x09bd7ca0));
2309 MAD_F_MLA(hi, lo, (t10=X[3]-X[ 8]-X[15]), -MAD_F(0x0cb19346));
2310 MAD_F_MLA(hi, lo, (t11=X[5]-X[ 6]-X[17]), -MAD_F(0x0fdcf549));
2311 x[10] = -(x[7] = MAD_F_MLZ(hi, lo));
2313 MAD_F_ML0(hi, lo, t8, -MAD_F(0x0cb19346));
2314 MAD_F_MLA(hi, lo, t9, MAD_F(0x0fdcf549));
2315 MAD_F_MLA(hi, lo, t10, MAD_F(0x0216a2a2));
2316 MAD_F_MLA(hi, lo, t11, -MAD_F(0x09bd7ca0));
2317 x[19] = x[34] = MAD_F_MLZ(hi, lo) - t0;
2319 MAD_F_ML0(hi, lo, t8, MAD_F(0x09bd7ca0));
2320 MAD_F_MLA(hi, lo, t9, -MAD_F(0x0216a2a2));
2321 MAD_F_MLA(hi, lo, t10, MAD_F(0x0fdcf549));
2322 MAD_F_MLA(hi, lo, t11, -MAD_F(0x0cb19346));
2323 x[ 1] = MAD_F_MLZ(hi, lo);
2325 MAD_F_ML0(hi, lo, t8, -MAD_F(0x0fdcf549));
2326 MAD_F_MLA(hi, lo, t9, -MAD_F(0x0cb19346));
2327 MAD_F_MLA(hi, lo, t10, -MAD_F(0x09bd7ca0));
2328 MAD_F_MLA(hi, lo, t11, -MAD_F(0x0216a2a2));
2329 x[25] = MAD_F_MLZ(hi, lo);
2331 t12 = t8 - t10;
2332 t13 = t9 + t11;
2334 MAD_F_ML0(hi, lo, X[1], -MAD_F(0x09bd7ca0));
2335 MAD_F_MLA(hi, lo, X[7], MAD_F(0x0216a2a2));
2336 MAD_F_MLA(hi, lo, X[10], -MAD_F(0x0fdcf549));
2337 MAD_F_MLA(hi, lo, X[16], MAD_F(0x0cb19346));
2338 t1 = MAD_F_MLZ(hi, lo) + t6;
2340 MAD_F_ML0(hi, lo, X[1], -MAD_F(0x0216a2a2));
2341 MAD_F_MLA(hi, lo, X[7], -MAD_F(0x09bd7ca0));
2342 MAD_F_MLA(hi, lo, X[10], MAD_F(0x0cb19346));
2343 MAD_F_MLA(hi, lo, X[16], MAD_F(0x0fdcf549));
2344 t3 = MAD_F_MLZ(hi, lo);
2346 MAD_F_ML0(hi, lo, X[1], -MAD_F(0x0fdcf549));
2347 MAD_F_MLA(hi, lo, X[7], -MAD_F(0x0cb19346));
2348 MAD_F_MLA(hi, lo, X[10], -MAD_F(0x09bd7ca0));
2349 MAD_F_MLA(hi, lo, X[16], -MAD_F(0x0216a2a2));
2350 t5 = MAD_F_MLZ(hi, lo) - t6;
2352 MAD_F_ML0(hi, lo, X[0], MAD_F(0x03768962));
2353 MAD_F_MLA(hi, lo, X[2], MAD_F(0x0e313245));
2354 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0ffc19fd));
2355 MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0acf37ad));
2356 MAD_F_MLA(hi, lo, X[6], MAD_F(0x04cfb0e2));
2357 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0898c779));
2358 MAD_F_MLA(hi, lo, X[9], MAD_F(0x0d7e8807));
2359 MAD_F_MLA(hi, lo, X[11], MAD_F(0x0f426cb5));
2360 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0bcbe352));
2361 MAD_F_MLA(hi, lo, X[14], MAD_F(0x00b2aa3e));
2362 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x07635284));
2363 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0f9ee890));
2364 x[11] = -(x[6] = MAD_F_MLZ(hi, lo) + t1);
2366 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0f426cb5));
2367 MAD_F_MLA(hi, lo, X[2], -MAD_F(0x00b2aa3e));
2368 MAD_F_MLA(hi, lo, X[3], MAD_F(0x0898c779));
2369 MAD_F_MLA(hi, lo, X[5], MAD_F(0x0f9ee890));
2370 MAD_F_MLA(hi, lo, X[6], MAD_F(0x0acf37ad));
2371 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x07635284));
2372 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0e313245));
2373 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0bcbe352));
2374 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x03768962));
2375 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0d7e8807));
2376 MAD_F_MLA(hi, lo, X[15], MAD_F(0x0ffc19fd));
2377 MAD_F_MLA(hi, lo, X[17], MAD_F(0x04cfb0e2));
2378 x[23] = x[30] = MAD_F_MLZ(hi, lo) + t1;
2380 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0bcbe352));
2381 MAD_F_MLA(hi, lo, X[2], MAD_F(0x0d7e8807));
2382 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x07635284));
2383 MAD_F_MLA(hi, lo, X[5], MAD_F(0x04cfb0e2));
2384 MAD_F_MLA(hi, lo, X[6], MAD_F(0x0f9ee890));
2385 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0ffc19fd));
2386 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x00b2aa3e));
2387 MAD_F_MLA(hi, lo, X[11], MAD_F(0x03768962));
2388 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0f426cb5));
2389 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0e313245));
2390 MAD_F_MLA(hi, lo, X[15], MAD_F(0x0898c779));
2391 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0acf37ad));
2392 x[18] = x[35] = MAD_F_MLZ(hi, lo) - t1;
2394 MAD_F_ML0(hi, lo, X[4], MAD_F(0x061f78aa));
2395 MAD_F_MLA(hi, lo, X[13], -MAD_F(0x0ec835e8));
2396 t3+= (t7 = MAD_F_MLZ(hi, lo));
2397 t4-= t7;
2399 MAD_F_MLA(hi, lo, X[1], -MAD_F(0x0cb19346));
2400 MAD_F_MLA(hi, lo, X[7], MAD_F(0x0fdcf549));
2401 MAD_F_MLA(hi, lo, X[10], MAD_F(0x0216a2a2));
2402 MAD_F_MLA(hi, lo, X[16], -MAD_F(0x09bd7ca0));
2403 t2 = MAD_F_MLZ(hi, lo);
2405 MAD_F_MLA(hi, lo, X[0], MAD_F(0x04cfb0e2));
2406 MAD_F_MLA(hi, lo, X[2], MAD_F(0x0ffc19fd));
2407 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0d7e8807));
2408 MAD_F_MLA(hi, lo, X[5], MAD_F(0x03768962));
2409 MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0bcbe352));
2410 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0e313245));
2411 MAD_F_MLA(hi, lo, X[9], MAD_F(0x07635284));
2412 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0acf37ad));
2413 MAD_F_MLA(hi, lo, X[12], MAD_F(0x0f9ee890));
2414 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0898c779));
2415 MAD_F_MLA(hi, lo, X[15], MAD_F(0x00b2aa3e));
2416 MAD_F_MLA(hi, lo, X[17], MAD_F(0x0f426cb5));
2417 x[12] = -(x[5] = MAD_F_MLZ(hi, lo));
2419 MAD_F_ML0(hi, lo, X[0], MAD_F(0x0acf37ad));
2420 MAD_F_MLA(hi, lo, X[2], -MAD_F(0x0898c779));
2421 MAD_F_MLA(hi, lo, X[3], MAD_F(0x0e313245));
2422 MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0f426cb5));
2423 MAD_F_MLA(hi, lo, X[6], -MAD_F(0x03768962));
2424 MAD_F_MLA(hi, lo, X[8], MAD_F(0x00b2aa3e));
2425 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0ffc19fd));
2426 MAD_F_MLA(hi, lo, X[11], MAD_F(0x0f9ee890));
2427 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x04cfb0e2));
2428 MAD_F_MLA(hi, lo, X[14], MAD_F(0x07635284));
2429 MAD_F_MLA(hi, lo, X[15], MAD_F(0x0d7e8807));
2430 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0bcbe352));
2431 x[17] = -(x[0] = MAD_F_MLZ(hi, lo) + t2);
2433 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0f9ee890));
2434 MAD_F_MLA(hi, lo, X[2], -MAD_F(0x07635284));
2435 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x00b2aa3e));
2436 MAD_F_MLA(hi, lo, X[5], MAD_F(0x0bcbe352));
2437 MAD_F_MLA(hi, lo, X[6], MAD_F(0x0f426cb5));
2438 MAD_F_MLA(hi, lo, X[8], MAD_F(0x0d7e8807));
2439 MAD_F_MLA(hi, lo, X[9], MAD_F(0x0898c779));
2440 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x04cfb0e2));
2441 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0acf37ad));
2442 MAD_F_MLA(hi, lo, X[14], -MAD_F(0x0ffc19fd));
2443 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0e313245));
2444 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x03768962));
2445 x[24] = x[29] = MAD_F_MLZ(hi, lo) + t2;
2447 MAD_F_ML0(hi, lo, X[0], MAD_F(0x00b2aa3e));
2448 MAD_F_MLA(hi, lo, X[2], MAD_F(0x03768962));
2449 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x04cfb0e2));
2450 MAD_F_MLA(hi, lo, X[5], -MAD_F(0x07635284));
2451 MAD_F_MLA(hi, lo, X[6], MAD_F(0x0898c779));
2452 MAD_F_MLA(hi, lo, X[8], MAD_F(0x0acf37ad));
2453 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0bcbe352));
2454 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0d7e8807));
2455 MAD_F_MLA(hi, lo, X[12], MAD_F(0x0e313245));
2456 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0f426cb5));
2457 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0f9ee890));
2458 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0ffc19fd));
2459 x[9] = -(x[8] = MAD_F_MLZ(hi, lo) + t3);
2461 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0e313245));
2462 MAD_F_MLA(hi, lo, X[2], MAD_F(0x0bcbe352));
2463 MAD_F_MLA(hi, lo, X[3], MAD_F(0x0f9ee890));
2464 MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0898c779));
2465 MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0ffc19fd));
2466 MAD_F_MLA(hi, lo, X[8], MAD_F(0x04cfb0e2));
2467 MAD_F_MLA(hi, lo, X[9], MAD_F(0x0f426cb5));
2468 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x00b2aa3e));
2469 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0d7e8807));
2470 MAD_F_MLA(hi, lo, X[14], -MAD_F(0x03768962));
2471 MAD_F_MLA(hi, lo, X[15], MAD_F(0x0acf37ad));
2472 MAD_F_MLA(hi, lo, X[17], MAD_F(0x07635284));
2473 x[21] = x[32] = MAD_F_MLZ(hi, lo) + t3;
2475 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0d7e8807));
2476 MAD_F_MLA(hi, lo, X[2], MAD_F(0x0f426cb5));
2477 MAD_F_MLA(hi, lo, X[3], MAD_F(0x0acf37ad));
2478 MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0ffc19fd));
2479 MAD_F_MLA(hi, lo, X[6], -MAD_F(0x07635284));
2480 MAD_F_MLA(hi, lo, X[8], MAD_F(0x0f9ee890));
2481 MAD_F_MLA(hi, lo, X[9], MAD_F(0x03768962));
2482 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0e313245));
2483 MAD_F_MLA(hi, lo, X[12], MAD_F(0x00b2aa3e));
2484 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0bcbe352));
2485 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x04cfb0e2));
2486 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0898c779));
2487 x[20] = x[33] = MAD_F_MLZ(hi, lo) - t3;
2489 MAD_F_ML0(hi, lo, t12, -MAD_F(0x0ec835e8));
2490 MAD_F_MLA(hi, lo, t13, MAD_F(0x061f78aa));
2491 x[22] = x[31] = MAD_F_MLZ(hi, lo) + t0;
2493 MAD_F_ML0(hi, lo, t12, MAD_F(0x061f78aa));
2494 MAD_F_MLA(hi, lo, t13, MAD_F(0x0ec835e8));
2495 x[13] = -(x[4] = MAD_F_MLZ(hi, lo) + t4);
2496 x[16] = -(x[1] = x[1] + t4);
2497 x[25] = x[28] = x[25] + t4;
2499 MAD_F_ML0(hi, lo, X[0], MAD_F(0x0898c779));
2500 MAD_F_MLA(hi, lo, X[2], MAD_F(0x04cfb0e2));
2501 MAD_F_MLA(hi, lo, X[3], MAD_F(0x0bcbe352));
2502 MAD_F_MLA(hi, lo, X[5], MAD_F(0x00b2aa3e));
2503 MAD_F_MLA(hi, lo, X[6], MAD_F(0x0e313245));
2504 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x03768962));
2505 MAD_F_MLA(hi, lo, X[9], MAD_F(0x0f9ee890));
2506 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x07635284));
2507 MAD_F_MLA(hi, lo, X[12], MAD_F(0x0ffc19fd));
2508 MAD_F_MLA(hi, lo, X[14], -MAD_F(0x0acf37ad));
2509 MAD_F_MLA(hi, lo, X[15], MAD_F(0x0f426cb5));
2510 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0d7e8807));
2511 x[15] = -(x[2] = MAD_F_MLZ(hi, lo) + t5);
2513 MAD_F_ML0(hi, lo, X[0], MAD_F(0x07635284));
2514 MAD_F_MLA(hi, lo, X[2], MAD_F(0x0acf37ad));
2515 MAD_F_MLA(hi, lo, X[3], MAD_F(0x03768962));
2516 MAD_F_MLA(hi, lo, X[5], MAD_F(0x0d7e8807));
2517 MAD_F_MLA(hi, lo, X[6], -MAD_F(0x00b2aa3e));
2518 MAD_F_MLA(hi, lo, X[8], MAD_F(0x0f426cb5));
2519 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x04cfb0e2));
2520 MAD_F_MLA(hi, lo, X[11], MAD_F(0x0ffc19fd));
2521 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0898c779));
2522 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0f9ee890));
2523 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0bcbe352));
2524 MAD_F_MLA(hi, lo, X[17], MAD_F(0x0e313245));
2525 x[14] = -(x[3] = MAD_F_MLZ(hi, lo) + t5);
2527 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0ffc19fd));
2528 MAD_F_MLA(hi, lo, X[2], -MAD_F(0x0f9ee890));
2529 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0f426cb5));
2530 MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0e313245));
2531 MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0d7e8807));
2532 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0bcbe352));
2533 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0acf37ad));
2534 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0898c779));
2535 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x07635284));
2536 MAD_F_MLA(hi, lo, X[14], -MAD_F(0x04cfb0e2));
2537 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x03768962));
2538 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x00b2aa3e));
2539 x[26] = x[27] = MAD_F_MLZ(hi, lo) + t5;
2541 # endif /* CPU_COLDFIRE */
2544 * NAME: III_imdct_l()
2545 * DESCRIPTION: perform IMDCT and windowing for long blocks
2547 static
2548 void III_imdct_l(mad_fixed_t const X[18], mad_fixed_t z[36],
2549 unsigned int block_type)
2551 unsigned int i;
2553 /* IMDCT */
2555 imdct36(X, z);
2557 /* windowing */
2559 switch (block_type) {
2560 case 0: /* normal window */
2561 # if 1
2562 /* loop unrolled implementation */
2563 for (i = 0; i < 36; i += 4) {
2564 z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
2565 z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
2566 z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
2567 z[i + 3] = mad_f_mul(z[i + 3], window_l[i + 3]);
2569 # else
2570 /* reference implementation */
2571 for (i = 0; i < 36; ++i) z[i] = mad_f_mul(z[i], window_l[i]);
2572 # endif
2573 break;
2575 case 1: /* start block */
2576 for (i = 0; i < 18; i += 3) {
2577 z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
2578 z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
2579 z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
2581 /* (i = 18; i < 24; ++i) z[i] unchanged */
2582 for (i = 24; i < 30; ++i) z[i] = mad_f_mul(z[i], window_s[i - 18]);
2583 for (i = 30; i < 36; ++i) z[i] = 0;
2584 break;
2586 case 3: /* stop block */
2587 for (i = 0; i < 6; ++i) z[i] = 0;
2588 for (i = 6; i < 12; ++i) z[i] = mad_f_mul(z[i], window_s[i - 6]);
2589 /* (i = 12; i < 18; ++i) z[i] unchanged */
2590 for (i = 18; i < 36; i += 3) {
2591 z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
2592 z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
2593 z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
2595 break;
2598 # endif /* FPM_ARM */
2601 * NAME: III_imdct_s()
2602 * DESCRIPTION: perform IMDCT and windowing for short blocks
2605 # if defined(CPU_COLDFIRE)
2606 void III_imdct_s(mad_fixed_t const X[18], mad_fixed_t z[36]);
2607 #else
2609 static
2610 void III_imdct_s(mad_fixed_t const X[18], mad_fixed_t z[36])
2612 mad_fixed_t y[36], *yptr;
2613 mad_fixed_t const *wptr;
2614 int w, i;
2615 register mad_fixed64hi_t hi;
2616 register mad_fixed64lo_t lo;
2618 /* IMDCT */
2620 yptr = &y[0];
2622 for (w = 0; w < 3; ++w) {
2623 register mad_fixed_t const (*s)[6];
2625 s = imdct_s;
2627 for (i = 0; i < 3; ++i) {
2628 MAD_F_ML0(hi, lo, X[0], (*s)[0]);
2629 MAD_F_MLA(hi, lo, X[1], (*s)[1]);
2630 MAD_F_MLA(hi, lo, X[2], (*s)[2]);
2631 MAD_F_MLA(hi, lo, X[3], (*s)[3]);
2632 MAD_F_MLA(hi, lo, X[4], (*s)[4]);
2633 MAD_F_MLA(hi, lo, X[5], (*s)[5]);
2635 yptr[i + 0] = MAD_F_MLZ(hi, lo);
2636 yptr[5 - i] = -yptr[i + 0];
2638 ++s;
2640 MAD_F_ML0(hi, lo, X[0], (*s)[0]);
2641 MAD_F_MLA(hi, lo, X[1], (*s)[1]);
2642 MAD_F_MLA(hi, lo, X[2], (*s)[2]);
2643 MAD_F_MLA(hi, lo, X[3], (*s)[3]);
2644 MAD_F_MLA(hi, lo, X[4], (*s)[4]);
2645 MAD_F_MLA(hi, lo, X[5], (*s)[5]);
2647 yptr[ i + 6] = MAD_F_MLZ(hi, lo);
2648 yptr[11 - i] = yptr[i + 6];
2650 ++s;
2653 yptr += 12;
2654 X += 6;
2657 /* windowing, overlapping and concatenation */
2659 yptr = &y[0];
2660 wptr = &window_s[0];
2662 for (i = 0; i < 6; ++i) {
2663 z[i + 0] = 0;
2664 z[i + 6] = mad_f_mul(yptr[ 0 + 0], wptr[0]);
2666 MAD_F_ML0(hi, lo, yptr[ 0 + 6], wptr[6]);
2667 MAD_F_MLA(hi, lo, yptr[12 + 0], wptr[0]);
2669 z[i + 12] = MAD_F_MLZ(hi, lo);
2671 MAD_F_ML0(hi, lo, yptr[12 + 6], wptr[6]);
2672 MAD_F_MLA(hi, lo, yptr[24 + 0], wptr[0]);
2674 z[i + 18] = MAD_F_MLZ(hi, lo);
2676 z[i + 24] = mad_f_mul(yptr[24 + 6], wptr[6]);
2677 z[i + 30] = 0;
2679 ++yptr;
2680 ++wptr;
2684 #endif
2686 #ifdef CPU_ARM
2687 void III_overlap(mad_fixed_t const output[36], mad_fixed_t overlap[18],
2688 mad_fixed_t sample[18][32], unsigned int sb);
2689 #else
2692 * NAME: III_overlap()
2693 * DESCRIPTION: perform overlap-add of windowed IMDCT outputs
2695 static
2696 void III_overlap(mad_fixed_t const output[36], mad_fixed_t overlap[18],
2697 mad_fixed_t sample[18][32], unsigned int sb)
2699 unsigned int i;
2700 for (i = 0; i < 18; ++i) {
2701 sample[i][sb] = output[i + 0] + overlap[i];
2702 overlap[i] = output[i + 18];
2705 #endif
2708 * NAME: III_overlap_z()
2709 * DESCRIPTION: perform "overlap-add" of zero IMDCT outputs
2711 static inline
2712 void III_overlap_z(mad_fixed_t overlap[18],
2713 mad_fixed_t sample[18][32], unsigned int sb)
2715 unsigned int i;
2716 for (i = 0; i < 18; ++i) {
2717 sample[i][sb] = overlap[i];
2718 overlap[i] = 0;
2723 * NAME: III_freqinver()
2724 * DESCRIPTION: perform subband frequency inversion for odd sample lines
2726 static
2727 void III_freqinver(mad_fixed_t sample[18][32], unsigned int sb)
2729 unsigned int i;
2730 for (i = 1; i < 18; i += 2)
2731 sample[i][sb] = -sample[i][sb];
2735 * NAME: III_decode()
2736 * DESCRIPTION: decode frame main_data
2738 static
2739 enum mad_error III_decode(struct mad_bitptr *ptr, struct mad_frame *frame,
2740 struct sideinfo *si, unsigned int nch)
2742 struct mad_header *header = &frame->header;
2743 unsigned int sfreqi, ngr, gr;
2746 unsigned int sfreq;
2748 sfreq = header->samplerate;
2749 if (header->flags & MAD_FLAG_MPEG_2_5_EXT)
2750 sfreq *= 2;
2752 /* 48000 => 0, 44100 => 1, 32000 => 2,
2753 24000 => 3, 22050 => 4, 16000 => 5 */
2754 sfreqi = ((sfreq >> 7) & 0x000f) +
2755 ((sfreq >> 15) & 0x0001) - 8;
2757 if (header->flags & MAD_FLAG_MPEG_2_5_EXT)
2758 sfreqi += 3;
2761 /* scalefactors, Huffman decoding, requantization */
2763 ngr = (header->flags & MAD_FLAG_LSF_EXT) ? 1 : 2;
2765 for (gr = 0; gr < ngr; ++gr) {
2766 struct granule *granule = &si->gr[gr];
2767 unsigned char const *sfbwidth[2];
2768 mad_fixed_t xr[2][576];
2769 unsigned int ch;
2770 enum mad_error error;
2772 for (ch = 0; ch < nch; ++ch) {
2773 struct channel *channel = &granule->ch[ch];
2774 unsigned int part2_length;
2776 sfbwidth[ch] = sfbwidth_table[sfreqi].l;
2777 if (channel->block_type == 2) {
2778 sfbwidth[ch] = (channel->flags & mixed_block_flag) ?
2779 sfbwidth_table[sfreqi].m : sfbwidth_table[sfreqi].s;
2782 if (header->flags & MAD_FLAG_LSF_EXT) {
2783 part2_length = III_scalefactors_lsf(ptr, channel,
2784 ch == 0 ? 0 : &si->gr[1].ch[1],
2785 header->mode_extension);
2787 else {
2788 part2_length = III_scalefactors(ptr, channel, &si->gr[0].ch[ch],
2789 gr == 0 ? 0 : si->scfsi[ch]);
2792 error = III_huffdecode(ptr, xr[ch], channel, sfbwidth[ch], part2_length);
2793 if (error)
2794 return error;
2797 /* joint stereo processing */
2799 if (header->mode == MAD_MODE_JOINT_STEREO && header->mode_extension) {
2800 error = III_stereo(xr, granule, header, sfbwidth[0]);
2801 if (error)
2802 return error;
2805 /* reordering, alias reduction, IMDCT, overlap-add, frequency inversion */
2807 for (ch = 0; ch < nch; ++ch) {
2808 struct channel const *channel = &granule->ch[ch];
2809 mad_fixed_t (*sample)[32] = &((*frame->sbsample)[ch][18 * gr]);
2810 unsigned int sb, l, i, sblimit;
2811 mad_fixed_t output[36];
2813 if (channel->block_type == 2) {
2814 III_reorder(xr[ch], channel, sfbwidth[ch]);
2816 # if !defined(OPT_STRICT)
2818 * According to ISO/IEC 11172-3, "Alias reduction is not applied for
2819 * granules with block_type == 2 (short block)." However, other
2820 * sources suggest alias reduction should indeed be performed on the
2821 * lower two subbands of mixed blocks. Most other implementations do
2822 * this, so by default we will too.
2824 if (channel->flags & mixed_block_flag)
2825 III_aliasreduce(xr[ch], 36);
2826 # endif
2828 else
2829 III_aliasreduce(xr[ch], 576);
2831 l = 0;
2833 /* subbands 0-1 */
2835 if (channel->block_type != 2 || (channel->flags & mixed_block_flag)) {
2836 unsigned int block_type;
2838 block_type = channel->block_type;
2839 if (channel->flags & mixed_block_flag)
2840 block_type = 0;
2842 /* long blocks */
2843 for (sb = 0; sb < 2; ++sb, l += 18) {
2844 III_imdct_l(&xr[ch][l], output, block_type);
2845 III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
2848 else {
2849 /* short blocks */
2850 for (sb = 0; sb < 2; ++sb, l += 18) {
2851 III_imdct_s(&xr[ch][l], output);
2852 III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
2856 III_freqinver(sample, 1);
2858 /* (nonzero) subbands 2-31 */
2861 i = 576;
2862 while (i > 36 && xr[ch][i - 1] == 0)
2863 --i;
2867 /* saves ~600k cycles */
2868 mad_fixed_t *p = &xr[ch][576];
2869 mad_fixed_t tmp = xr[ch][35];
2870 xr[ch][35] = 1;
2871 while (!*--p);
2872 xr[ch][35] = tmp;
2873 i = p - &xr[ch][0] + 1;
2875 sblimit = 32 - (576 - i) / 18;
2877 if (channel->block_type != 2) {
2878 /* long blocks */
2879 for (sb = 2; sb < sblimit; ++sb, l += 18) {
2880 III_imdct_l(&xr[ch][l], output, channel->block_type);
2881 III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
2883 if (sb & 1)
2884 III_freqinver(sample, sb);
2887 else {
2888 /* short blocks */
2889 for (sb = 2; sb < sblimit; ++sb, l += 18) {
2890 III_imdct_s(&xr[ch][l], output);
2891 III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
2893 if (sb & 1)
2894 III_freqinver(sample, sb);
2898 /* remaining (zero) subbands */
2900 for (sb = sblimit; sb < 32; ++sb) {
2901 III_overlap_z((*frame->overlap)[ch][sb], sample, sb);
2903 if (sb & 1)
2904 III_freqinver(sample, sb);
2909 return MAD_ERROR_NONE;
2913 * NAME: layer->III()
2914 * DESCRIPTION: decode a single Layer III frame
2916 int mad_layer_III(struct mad_stream *stream, struct mad_frame *frame)
2918 struct mad_header *header = &frame->header;
2919 unsigned int nch, priv_bitlen, next_md_begin = 0;
2920 unsigned int si_len, data_bitlen, md_len;
2921 unsigned int frame_space, frame_used, frame_free;
2922 struct mad_bitptr ptr;
2923 struct sideinfo si;
2924 enum mad_error error;
2925 int result = 0;
2927 #if 0 /* rockbox: do not allocate */
2928 /* allocate Layer III dynamic structures */
2929 /* rockbox: not used. Both pointers are linked to an array in rockbox'
2930 * apps/codecs/mpa.c before calling this. */
2931 if (stream->main_data == 0) {
2932 stream->main_data = malloc(MAD_BUFFER_MDLEN);
2933 if (stream->main_data == 0) {
2934 stream->error = MAD_ERROR_NOMEM;
2935 return -1;
2939 if (frame->overlap == 0) {
2940 frame->overlap = calloc(2 * 32 * 18, sizeof(mad_fixed_t));
2941 if (frame->overlap == 0) {
2942 stream->error = MAD_ERROR_NOMEM;
2943 return -1;
2946 #else
2947 /* rockbox: This should not happen. Return with error. */
2948 if ((stream->main_data == 0) || (frame->overlap == 0)) {
2949 stream->error = MAD_ERROR_NOMEM;
2950 return -1;
2952 #endif /* rockbox */
2954 nch = MAD_NCHANNELS(header);
2955 si_len = (header->flags & MAD_FLAG_LSF_EXT) ?
2956 (nch == 1 ? 9 : 17) : (nch == 1 ? 17 : 32);
2958 /* check frame sanity */
2960 if (stream->next_frame - mad_bit_nextbyte(&stream->ptr) <
2961 (signed int) si_len) {
2962 stream->error = MAD_ERROR_BADFRAMELEN;
2963 stream->md_len = 0;
2964 return -1;
2967 /* check CRC word */
2969 if (header->flags & MAD_FLAG_PROTECTION) {
2970 header->crc_check =
2971 mad_bit_crc(stream->ptr, si_len * CHAR_BIT, header->crc_check);
2973 if (header->crc_check != header->crc_target &&
2974 !(frame->options & MAD_OPTION_IGNORECRC)) {
2975 stream->error = MAD_ERROR_BADCRC;
2976 result = -1;
2980 /* decode frame side information */
2982 error = III_sideinfo(&stream->ptr, nch, header->flags & MAD_FLAG_LSF_EXT,
2983 &si, &data_bitlen, &priv_bitlen);
2984 if (error && result == 0) {
2985 stream->error = error;
2986 result = -1;
2989 header->flags |= priv_bitlen;
2990 header->private_bits |= si.private_bits;
2992 /* find main_data of next frame */
2995 struct mad_bitptr peek;
2996 unsigned long header;
2998 mad_bit_init(&peek, stream->next_frame);
3000 header = mad_bit_read(&peek, 32);
3001 if ((header & 0xffe60000L) /* syncword | layer */ == 0xffe20000L) {
3002 if (!(header & 0x00010000L)) /* protection_bit */
3003 mad_bit_skip(&peek, 16); /* crc_check */
3005 next_md_begin =
3006 mad_bit_read(&peek, (header & 0x00080000L) /* ID */ ? 9 : 8);
3009 mad_bit_finish(&peek);
3012 /* find main_data of this frame */
3014 frame_space = stream->next_frame - mad_bit_nextbyte(&stream->ptr);
3016 if (next_md_begin > si.main_data_begin + frame_space)
3017 next_md_begin = 0;
3019 md_len = si.main_data_begin + frame_space - next_md_begin;
3021 frame_used = 0;
3023 if (si.main_data_begin == 0) {
3024 ptr = stream->ptr;
3025 stream->md_len = 0;
3027 frame_used = md_len;
3029 else {
3030 if (si.main_data_begin > stream->md_len) {
3031 if (result == 0) {
3032 stream->error = MAD_ERROR_BADDATAPTR;
3033 result = -1;
3036 else {
3037 mad_bit_init(&ptr,
3038 *stream->main_data + stream->md_len - si.main_data_begin);
3040 if (md_len > si.main_data_begin) {
3041 assert(stream->md_len + md_len -
3042 si.main_data_begin <= MAD_BUFFER_MDLEN);
3044 memcpy(*stream->main_data + stream->md_len,
3045 mad_bit_nextbyte(&stream->ptr),
3046 frame_used = md_len - si.main_data_begin);
3047 stream->md_len += frame_used;
3052 frame_free = frame_space - frame_used;
3054 /* decode main_data */
3056 if (result == 0) {
3057 error = III_decode(&ptr, frame, &si, nch);
3058 if (error) {
3059 stream->error = error;
3060 result = -1;
3063 /* designate ancillary bits */
3065 stream->anc_ptr = ptr;
3066 stream->anc_bitlen = md_len * CHAR_BIT - data_bitlen;
3069 # if 0 && defined(DEBUG)
3070 fprintf(stderr,
3071 "main_data_begin:%u, md_len:%u, frame_free:%u, "
3072 "data_bitlen:%u, anc_bitlen: %u\n",
3073 si.main_data_begin, md_len, frame_free,
3074 data_bitlen, stream->anc_bitlen);
3075 # endif
3077 /* preload main_data buffer with up to 511 bytes for next frame(s) */
3079 if (frame_free >= next_md_begin) {
3080 memcpy(*stream->main_data,
3081 stream->next_frame - next_md_begin, next_md_begin);
3082 stream->md_len = next_md_begin;
3084 else {
3085 if (md_len < si.main_data_begin) {
3086 unsigned int extra;
3088 extra = si.main_data_begin - md_len;
3089 if (extra + frame_free > next_md_begin)
3090 extra = next_md_begin - frame_free;
3092 if (extra < stream->md_len) {
3093 memmove(*stream->main_data,
3094 *stream->main_data + stream->md_len - extra, extra);
3095 stream->md_len = extra;
3098 else
3099 stream->md_len = 0;
3101 memcpy(*stream->main_data + stream->md_len,
3102 stream->next_frame - frame_free, frame_free);
3103 stream->md_len += frame_free;
3106 return result;