36
36
/* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg
38
38
#ifdef CONFIG_MPEGAUDIO_HP
39
#define USE_HIGHPRECISION
39
# define USE_HIGHPRECISION
42
42
#include "mpegaudio.h"
44
44
#define FRAC_ONE (1 << FRAC_BITS)
46
#define MULL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS)
47
#define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
47
# define MULL(ra, rb) \
48
({ int rt, dummy; asm (\
50
"shrdl %4, %%edx, %%eax \n\t"\
51
: "=a"(rt), "=d"(dummy)\
52
: "a" (ra), "rm" (rb), "i"(FRAC_BITS));\
54
# define MUL64(ra, rb) \
55
({ int64_t rt; asm ("imull %2\n\t" : "=A"(rt) : "a" (ra), "g" (rb)); rt; })
56
# define MULH(ra, rb) \
57
({ int rt, dummy; asm ("imull %3\n\t" : "=d"(rt), "=a"(dummy): "a" (ra), "rm" (rb)); rt; })
58
#elif defined(ARCH_ARMV4L)
61
asm("smull %0, %1, %2, %3 \n\t"\
62
"mov %0, %0, lsr #%4\n\t"\
63
"add %1, %0, %1, lsl #%5\n\t"\
65
: "r"(b), "r"(a), "i"(FRAC_BITS), "i"(32-FRAC_BITS));\
67
# define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
68
# define MULH(a, b) ({ int lo, hi; asm ("smull %0, %1, %2, %3" : "=r"(lo), "=r"(hi) : "r"(b),"r"(a)); hi; })
70
# define MULL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS)
71
# define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
72
//#define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32) //gcc 3.4 creates an incredibly bloated mess out of this
73
static always_inline int MULH(int a, int b){
74
return ((int64_t)(a) * (int64_t)(b))>>32;
48
77
#define FIX(a) ((int)((a) * FRAC_ONE))
49
78
/* WARNING: only correct for posititive numbers */
50
79
#define FIXR(a) ((int)((a) * FRAC_ONE + 0.5))
51
80
#define FRAC_RND(a) (((a) + (FRAC_ONE/2)) >> FRAC_BITS)
53
82
#define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5))
54
//#define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32) //gcc 3.4 creates an incredibly bloated mess out of this
55
static always_inline int MULH(int a, int b){
56
return ((int64_t)(a) * (int64_t)(b))>>32;
514
539
/* cos(i*pi/64) */
516
#define COS0_0 FIXR(0.50060299823519630134)
517
#define COS0_1 FIXR(0.50547095989754365998)
518
#define COS0_2 FIXR(0.51544730992262454697)
519
#define COS0_3 FIXR(0.53104259108978417447)
520
#define COS0_4 FIXR(0.55310389603444452782)
521
#define COS0_5 FIXR(0.58293496820613387367)
522
#define COS0_6 FIXR(0.62250412303566481615)
523
#define COS0_7 FIXR(0.67480834145500574602)
524
#define COS0_8 FIXR(0.74453627100229844977)
525
#define COS0_9 FIXR(0.83934964541552703873)
526
#define COS0_10 FIXR(0.97256823786196069369)
527
#define COS0_11 FIXR(1.16943993343288495515)
528
#define COS0_12 FIXR(1.48416461631416627724)
529
#define COS0_13 FIXR(2.05778100995341155085)
530
#define COS0_14 FIXR(3.40760841846871878570)
531
#define COS0_15 FIXR(10.19000812354805681150)
533
#define COS1_0 FIXR(0.50241928618815570551)
534
#define COS1_1 FIXR(0.52249861493968888062)
535
#define COS1_2 FIXR(0.56694403481635770368)
536
#define COS1_3 FIXR(0.64682178335999012954)
537
#define COS1_4 FIXR(0.78815462345125022473)
538
#define COS1_5 FIXR(1.06067768599034747134)
539
#define COS1_6 FIXR(1.72244709823833392782)
540
#define COS1_7 FIXR(5.10114861868916385802)
542
#define COS2_0 FIXR(0.50979557910415916894)
543
#define COS2_1 FIXR(0.60134488693504528054)
544
#define COS2_2 FIXR(0.89997622313641570463)
545
#define COS2_3 FIXR(2.56291544774150617881)
547
#define COS3_0 FIXR(0.54119610014619698439)
548
#define COS3_1 FIXR(1.30656296487637652785)
550
#define COS4_0 FIXR(0.70710678118654752439)
541
#define COS0_0 FIXHR(0.50060299823519630134/2)
542
#define COS0_1 FIXHR(0.50547095989754365998/2)
543
#define COS0_2 FIXHR(0.51544730992262454697/2)
544
#define COS0_3 FIXHR(0.53104259108978417447/2)
545
#define COS0_4 FIXHR(0.55310389603444452782/2)
546
#define COS0_5 FIXHR(0.58293496820613387367/2)
547
#define COS0_6 FIXHR(0.62250412303566481615/2)
548
#define COS0_7 FIXHR(0.67480834145500574602/2)
549
#define COS0_8 FIXHR(0.74453627100229844977/2)
550
#define COS0_9 FIXHR(0.83934964541552703873/2)
551
#define COS0_10 FIXHR(0.97256823786196069369/2)
552
#define COS0_11 FIXHR(1.16943993343288495515/4)
553
#define COS0_12 FIXHR(1.48416461631416627724/4)
554
#define COS0_13 FIXHR(2.05778100995341155085/8)
555
#define COS0_14 FIXHR(3.40760841846871878570/8)
556
#define COS0_15 FIXHR(10.19000812354805681150/32)
558
#define COS1_0 FIXHR(0.50241928618815570551/2)
559
#define COS1_1 FIXHR(0.52249861493968888062/2)
560
#define COS1_2 FIXHR(0.56694403481635770368/2)
561
#define COS1_3 FIXHR(0.64682178335999012954/2)
562
#define COS1_4 FIXHR(0.78815462345125022473/2)
563
#define COS1_5 FIXHR(1.06067768599034747134/4)
564
#define COS1_6 FIXHR(1.72244709823833392782/4)
565
#define COS1_7 FIXHR(5.10114861868916385802/16)
567
#define COS2_0 FIXHR(0.50979557910415916894/2)
568
#define COS2_1 FIXHR(0.60134488693504528054/2)
569
#define COS2_2 FIXHR(0.89997622313641570463/2)
570
#define COS2_3 FIXHR(2.56291544774150617881/8)
572
#define COS3_0 FIXHR(0.54119610014619698439/2)
573
#define COS3_1 FIXHR(1.30656296487637652785/4)
575
#define COS4_0 FIXHR(0.70710678118654752439/2)
552
577
/* butterfly operator */
578
#define BF(a, b, c, s)\
555
580
tmp0 = tab[a] + tab[b];\
556
581
tmp1 = tab[a] - tab[b];\
558
tab[b] = MULL(tmp1, c);\
583
tab[b] = MULH(tmp1<<(s), c);\
561
586
#define BF1(a, b, c, d)\
588
BF(a, b, COS4_0, 1);\
589
BF(c, d,-COS4_0, 1);\
565
590
tab[c] += tab[d];\
568
593
#define BF2(a, b, c, d)\
595
BF(a, b, COS4_0, 1);\
596
BF(c, d,-COS4_0, 1);\
572
597
tab[c] += tab[d];\
573
598
tab[a] += tab[c];\
574
599
tab[c] += tab[b];\
745
#if defined(ARCH_POWERPC_405)
747
/* signed 16x16 -> 32 multiply add accumulate */
748
#define MACS(rt, ra, rb) \
749
asm ("maclhw %0, %2, %3" : "=r" (rt) : "0" (rt), "r" (ra), "r" (rb));
751
/* signed 16x16 -> 32 multiply */
752
#define MULS(ra, rb) \
753
({ int __rt; asm ("mullhw %0, %1, %2" : "=r" (__rt) : "r" (ra), "r" (rb)); __rt; })
757
/* signed 16x16 -> 32 multiply add accumulate */
758
#define MACS(rt, ra, rb) rt += (ra) * (rb)
760
/* signed 16x16 -> 32 multiply */
761
#define MULS(ra, rb) ((ra) * (rb))
778
# if defined(ARCH_POWERPC_405)
779
/* signed 16x16 -> 32 multiply add accumulate */
780
# define MACS(rt, ra, rb) \
781
asm ("maclhw %0, %2, %3" : "=r" (rt) : "0" (rt), "r" (ra), "r" (rb));
783
/* signed 16x16 -> 32 multiply */
784
# define MULS(ra, rb) \
785
({ int __rt; asm ("mullhw %0, %1, %2" : "=r" (__rt) : "r" (ra), "r" (rb)); __rt; })
787
/* signed 16x16 -> 32 multiply add accumulate */
788
# define MACS(rt, ra, rb) rt += (ra) * (rb)
790
/* signed 16x16 -> 32 multiply */
791
# define MULS(ra, rb) ((ra) * (rb))
767
795
static inline int round_sample(int64_t *sum)
934
961
FIXR(5.73685662283492756461),
964
/* 0.5 / cos(pi*(2*i+1)/36) */
965
static const int icos36h[9] = {
966
FIXHR(0.50190991877167369479/2),
967
FIXHR(0.51763809020504152469/2), //0
968
FIXHR(0.55168895948124587824/2),
969
FIXHR(0.61038729438072803416/2),
970
FIXHR(0.70710678118654752439/2), //1
971
FIXHR(0.87172339781054900991/2),
972
FIXHR(1.18310079157624925896/4),
973
FIXHR(1.93185165257813657349/4), //2
974
// FIXHR(5.73685662283492756461),
937
977
/* 12 points IMDCT. We compute it "by hand" by factorizing obvious
939
979
static void imdct12(int *out, int *in)