2 * Altivec optimized MP3 decoding functions
3 * Copyright (c) 2010 Vitor Sessak
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "libavutil/attributes.h"
24 #include "libavutil/cpu.h"
25 #include "libavutil/internal.h"
26 #include "libavutil/ppc/cpu.h"
27 #include "libavutil/ppc/util_altivec.h"
28 #include "libavcodec/mpegaudiodsp.h"
32 #define MACS(rt, ra, rb) rt+=(ra)*(rb)
33 #define MLSS(rt, ra, rb) rt-=(ra)*(rb)
35 #define SUM8(op, sum, w, p) \
37 op(sum, (w)[0 * 64], (p)[0 * 64]); \
38 op(sum, (w)[1 * 64], (p)[1 * 64]); \
39 op(sum, (w)[2 * 64], (p)[2 * 64]); \
40 op(sum, (w)[3 * 64], (p)[3 * 64]); \
41 op(sum, (w)[4 * 64], (p)[4 * 64]); \
42 op(sum, (w)[5 * 64], (p)[5 * 64]); \
43 op(sum, (w)[6 * 64], (p)[6 * 64]); \
44 op(sum, (w)[7 * 64], (p)[7 * 64]); \
47 static void apply_window(const float *buf, const float *win1,
48 const float *win2, float *sum1, float *sum2, int len)
50 const vector float *win1a = (const vector float *) win1;
51 const vector float *win2a = (const vector float *) win2;
52 const vector float *bufa = (const vector float *) buf;
53 vector float *sum1a = (vector float *) sum1;
54 vector float *sum2a = (vector float *) sum2;
55 vector float av_uninit(v0), av_uninit(v4);
56 vector float v1, v2, v3;
62 v1 = vec_ld(a, win1a); \
63 v2 = vec_ld(b, win2a); \
64 v3 = vec_ld(a, bufa); \
65 v0 = vec_madd(v3, v1, v0); \
66 v4 = vec_madd(v2, v3, v4); \
92 static void apply_window_mp3(float *in, float *win, int *unused, float *out,
95 LOCAL_ALIGNED_16(float, suma, [17]);
96 LOCAL_ALIGNED_16(float, sumb, [17]);
97 LOCAL_ALIGNED_16(float, sumc, [17]);
98 LOCAL_ALIGNED_16(float, sumd, [17]);
102 float *out2 = out + 32 * incr;
104 /* copy to avoid wrap */
105 memcpy(in + 512, in, 32 * sizeof(*in));
107 apply_window(in + 16, win , win + 512, suma, sumc, 16);
108 apply_window(in + 32, win + 48, win + 640, sumb, sumd, 16);
110 SUM8(MLSS, suma[0], win + 32, in + 48);
120 *out = suma[ j] - sumd[16-j];
121 *out2 = -sumb[16-j] - sumc[ j];
127 SUM8(MLSS, sum, win + 16 + 32, in + 32);
131 #endif /* HAVE_ALTIVEC */
133 av_cold void ff_mpadsp_init_ppc(MPADSPContext *s)
136 if (!PPC_ALTIVEC(av_get_cpu_flags()))
139 s->apply_window_float = apply_window_mp3;
140 #endif /* HAVE_ALTIVEC */