summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/codecs/libmad/Makefile3
-rw-r--r--apps/codecs/libmad/fixed.h23
-rw-r--r--apps/codecs/libmad/global.h6
-rw-r--r--apps/codecs/libmad/synth.c53
4 files changed, 65 insertions, 20 deletions
diff --git a/apps/codecs/libmad/Makefile b/apps/codecs/libmad/Makefile
index e3ba245513..a6f310195c 100644
--- a/apps/codecs/libmad/Makefile
+++ b/apps/codecs/libmad/Makefile
@@ -14,7 +14,8 @@ ifdef APPEXTRA
14INCLUDES += -I$(APPSDIR)/$(APPEXTRA) 14INCLUDES += -I$(APPSDIR)/$(APPEXTRA)
15endif 15endif
16 16
17MADOPTS = -DFPM_DEFAULT -DNDEBUG -O2 17# NOTE: FPM_ define has been moved to global.h
18MADOPTS = -DNDEBUG -O2
18CFLAGS = $(GCCOPTS) $(MADOPTS)\ 19CFLAGS = $(GCCOPTS) $(MADOPTS)\
19$(INCLUDES) $(TARGET) $(EXTRA_DEFINES) -DMEM=${MEMORYSIZE} 20$(INCLUDES) $(TARGET) $(EXTRA_DEFINES) -DMEM=${MEMORYSIZE}
20 21
diff --git a/apps/codecs/libmad/fixed.h b/apps/codecs/libmad/fixed.h
index baa7dc59c8..7ccf1cb4ed 100644
--- a/apps/codecs/libmad/fixed.h
+++ b/apps/codecs/libmad/fixed.h
@@ -420,6 +420,29 @@ mad_fixed_t mad_f_mul_inline(mad_fixed_t x, mad_fixed_t y)
420 420
421# define MAD_F_SCALEBITS MAD_F_FRACBITS 421# define MAD_F_SCALEBITS MAD_F_FRACBITS
422 422
423# elif defined(FPM_COLDFIRE_EMAC)
424
425/* mad_f_mul using the Coldfire MCF5249 EMAC unit. Loses 3 bits of accuracy.
426 Note that we don't define any of the libmad accumulator macros, as
427 any functions that use these should have the relevant sections rewritten
428 in assembler to utilise the EMAC accumulators properly.
429 Assumes the default +/- 3.28 fixed point format
430 */
431#define mad_f_mul(x, y) \
432({ \
433 mad_fixed64hi_t hi; \
434 asm volatile("mac.l %[a], %[b], %%acc0\n\t" \
435 "movclr.l %%acc0, %[hi]\n\t" \
436 "asl.l #3, %[hi]" \
437 : [hi] "=d" (hi) \
438 : [a] "r" ((x)), [b] "r" ((y))); \
439 hi; \
440})
441/* Define dummy mad_f_scale64 to prevent libmad from defining MAD_F_SCALEBITS
442 below. Having MAD_F_SCALEBITS defined screws up the PRESHIFT macro in synth.h
443 */
444#define mad_f_scale64(hi, lo) (lo)
445
423/* --- Default ------------------------------------------------------------- */ 446/* --- Default ------------------------------------------------------------- */
424 447
425# elif defined(FPM_DEFAULT) 448# elif defined(FPM_DEFAULT)
diff --git a/apps/codecs/libmad/global.h b/apps/codecs/libmad/global.h
index 8669bf9044..bba9f062bf 100644
--- a/apps/codecs/libmad/global.h
+++ b/apps/codecs/libmad/global.h
@@ -24,6 +24,12 @@
24# ifndef LIBMAD_GLOBAL_H 24# ifndef LIBMAD_GLOBAL_H
25# define LIBMAD_GLOBAL_H 25# define LIBMAD_GLOBAL_H
26 26
27#if CONFIG_CPU==MCF5249 && !defined(SIMULATOR)
28#define FPM_COLDFIRE_EMAC
29#else
30#define FPM_DEFAULT
31#endif
32
27/* conditional debugging */ 33/* conditional debugging */
28 34
29# if defined(DEBUG) && defined(NDEBUG) 35# if defined(DEBUG) && defined(NDEBUG)
diff --git a/apps/codecs/libmad/synth.c b/apps/codecs/libmad/synth.c
index 166e3d9f3a..bdec4258fb 100644
--- a/apps/codecs/libmad/synth.c
+++ b/apps/codecs/libmad/synth.c
@@ -102,7 +102,21 @@ void mad_synth_mute(struct mad_synth *synth)
102 102
103/* possible DCT speed optimization */ 103/* possible DCT speed optimization */
104 104
105# if defined(OPT_SPEED) && defined(MAD_F_MLX) 105/* This is a Coldfire version of the OPT_SPEED optimisation below, but in the
106 case of Coldfire it doesn't lose any more precision than we would ordinarily
107 lose, */
108# ifdef FPM_COLDFIRE_EMAC
109# define OPT_DCTO
110# define MUL(x, y) \
111 ({ \
112 mad_fixed64hi_t hi; \
113 asm volatile("mac.l %[a], %[b], %%acc0\n\t" \
114 "movclr.l %%acc0, %[hi]" \
115 : [hi] "=r" (hi) \
116 : [a] "r" ((x)), [b] "r" ((y))); \
117 hi; \
118 })
119# elif defined(OPT_SPEED) && defined(MAD_F_MLX)
106# define OPT_DCTO 120# define OPT_DCTO
107# define MUL(x, y) \ 121# define MUL(x, y) \
108 ({ mad_fixed64hi_t hi; \ 122 ({ mad_fixed64hi_t hi; \
@@ -555,8 +569,8 @@ void synth_full(struct mad_synth *, struct mad_frame const *,
555 * DESCRIPTION: perform full frequency PCM synthesis 569 * DESCRIPTION: perform full frequency PCM synthesis
556 */ 570 */
557 571
558/* optimised version of synth full, requires OPT_SSO at the moment */ 572/* optimised version of synth_full */
559# if CONFIG_CPU==MCF5249 && defined(OPT_SSO) && !defined(SIMULATOR) 573# ifdef FPM_COLDFIRE_EMAC
560static 574static
561void synth_full(struct mad_synth *synth, struct mad_frame const *frame, 575void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
562 unsigned int nch, unsigned int ns) 576 unsigned int nch, unsigned int ns)
@@ -566,10 +580,9 @@ void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
566 mad_fixed_t const (*sbsample)[36][32]; 580 mad_fixed_t const (*sbsample)[36][32];
567 mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8]; 581 mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
568 mad_fixed_t const (*Dptr)[32]; 582 mad_fixed_t const (*Dptr)[32];
569 mad_fixed64hi_t hi = 0; 583 mad_fixed64hi_t hi;
570 mad_fixed64lo_t lo;
571 584
572 asm volatile("move.l #0, %macsr"); /* need integer mode */ 585 asm volatile("move.l #0x20, %macsr"); /* fractional mode */
573 586
574 for (ch = 0; ch < nch; ++ch) { 587 for (ch = 0; ch < nch; ++ch) {
575 sbsample = &frame->sbsample[ch]; 588 sbsample = &frame->sbsample[ch];
@@ -613,10 +626,12 @@ void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
613 "mac.l %%d5, %%a5, 16(%4), %%a5, %%acc0\n\t" 626 "mac.l %%d5, %%a5, 16(%4), %%a5, %%acc0\n\t"
614 "mac.l %%d6, %%a5, 8(%4), %%a5, %%acc0\n\t" 627 "mac.l %%d6, %%a5, 8(%4), %%a5, %%acc0\n\t"
615 "mac.l %%d7, %%a5, %%acc0\n\t" 628 "mac.l %%d7, %%a5, %%acc0\n\t"
616 "movclr.l %%acc0, %0" 629 "movclr.l %%acc0, %0\n\t"
617 : "=ad" (lo) : "a" (*fx), "a" (*Dptr + po), "a" (*fe), "a" (*Dptr + pe) : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5"); 630 : "=r" (hi)
631 : "a" (*fx), "a" (*Dptr + po), "a" (*fe), "a" (*Dptr + pe)
632 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5");
618 633
619 *pcm1++ = SHIFT(MLZ(hi, lo)); 634 *pcm1++ = hi << 3; /* shift result to libmad's fixed point format */
620 635
621 pcm2 = pcm1 + 30; 636 pcm2 = pcm1 + 30;
622 637
@@ -646,13 +661,13 @@ void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
646 "mac.l %%d2, %%a5, 56(%4), %%a5, %%acc0\n\t" 661 "mac.l %%d2, %%a5, 56(%4), %%a5, %%acc0\n\t"
647 "mac.l %%d1, %%a5, (%4), %%a5, %%acc0\n\t" 662 "mac.l %%d1, %%a5, (%4), %%a5, %%acc0\n\t"
648 "mac.l %%d0, %%a5, %%acc0\n\t" 663 "mac.l %%d0, %%a5, %%acc0\n\t"
649 "movclr.l %%acc0, %0" 664 "movclr.l %%acc0, %0\n\t"
650 : "=ad" (lo) 665 : "=r" (hi)
651 : "a" (*fo), "a" (*Dptr + po), "a" (*fe), "a" (*Dptr + pe) 666 : "a" (*fo), "a" (*Dptr + po), "a" (*fe), "a" (*Dptr + pe)
652 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5"); 667 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5");
653 668
654 *pcm1++ = SHIFT(MLZ(hi, lo)); 669 *pcm1++ = hi << 3;
655 670
656 asm volatile( 671 asm volatile(
657 "movem.l (%1), %%d0-%%d7\n\t" 672 "movem.l (%1), %%d0-%%d7\n\t"
658 "move.l 60(%2), %%a5\n\t" 673 "move.l 60(%2), %%a5\n\t"
@@ -674,12 +689,12 @@ void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
674 "mac.l %%d2, %%a5, 68(%4), %%a5, %%acc0\n\t" 689 "mac.l %%d2, %%a5, 68(%4), %%a5, %%acc0\n\t"
675 "mac.l %%d1, %%a5, 60(%4), %%a5, %%acc0\n\t" 690 "mac.l %%d1, %%a5, 60(%4), %%a5, %%acc0\n\t"
676 "mac.l %%d0, %%a5, %%acc0\n\t" 691 "mac.l %%d0, %%a5, %%acc0\n\t"
677 "movclr.l %%acc0, %0" 692 "movclr.l %%acc0, %0\n\t"
678 : "=ad" (lo) 693 : "=r" (hi)
679 : "a" (*fe), "a" (*Dptr - pe), "a" (*fo), "a" (*Dptr - po) 694 : "a" (*fe), "a" (*Dptr - pe), "a" (*fo), "a" (*Dptr - po)
680 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5"); 695 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5");
681 696
682 *pcm2-- = SHIFT(MLZ(hi, lo)); 697 *pcm2-- = hi << 3;
683 698
684 ++fo; 699 ++fo;
685 } 700 }
@@ -696,11 +711,11 @@ void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
696 "mac.l %%d5, %%a5, 16(%2), %%a5, %%acc0\n\t" 711 "mac.l %%d5, %%a5, 16(%2), %%a5, %%acc0\n\t"
697 "mac.l %%d6, %%a5, 8(%2), %%a5, %%acc0\n\t" 712 "mac.l %%d6, %%a5, 8(%2), %%a5, %%acc0\n\t"
698 "mac.l %%d7, %%a5, %%acc0\n\t" 713 "mac.l %%d7, %%a5, %%acc0\n\t"
699 "movclr.l %%acc0, %0" 714 "movclr.l %%acc0, %0\n\t"
700 : "=ad" (lo) : "a" (*fo), "a" (*Dptr + po) 715 : "=r" (hi) : "a" (*fo), "a" (*Dptr + po)
701 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5"); 716 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5");
702 717
703 *pcm1 = SHIFT(-MLZ(hi, lo)); 718 *pcm1 = -(hi << 3);
704 pcm1 += 16; 719 pcm1 += 16;
705 720
706 phase = (phase + 1) % 16; 721 phase = (phase + 1) % 16;