FFmpeg
mpegaudiodsp_altivec.c
Go to the documentation of this file.
1 /*
2  * Altivec optimized MP3 decoding functions
3  * Copyright (c) 2010 Vitor Sessak
4  *
5  * This file is part of FFmpeg.
6  *
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.
11  *
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.
16  *
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
20  */
21 
22 #include <string.h>
23 
24 #include "config.h"
25 #include "libavutil/attributes.h"
26 #include "libavutil/cpu.h"
27 #include "libavutil/internal.h"
28 #include "libavutil/mem_internal.h"
29 #include "libavutil/ppc/cpu.h"
32 
33 #if HAVE_ALTIVEC
34 
35 #define MACS(rt, ra, rb) rt+=(ra)*(rb)
36 #define MLSS(rt, ra, rb) rt-=(ra)*(rb)
37 
38 #define SUM8(op, sum, w, p) \
39 { \
40  op(sum, (w)[0 * 64], (p)[0 * 64]); \
41  op(sum, (w)[1 * 64], (p)[1 * 64]); \
42  op(sum, (w)[2 * 64], (p)[2 * 64]); \
43  op(sum, (w)[3 * 64], (p)[3 * 64]); \
44  op(sum, (w)[4 * 64], (p)[4 * 64]); \
45  op(sum, (w)[5 * 64], (p)[5 * 64]); \
46  op(sum, (w)[6 * 64], (p)[6 * 64]); \
47  op(sum, (w)[7 * 64], (p)[7 * 64]); \
48 }
49 
50 static void apply_window(const float *buf, const float *win1,
51  const float *win2, float *sum1, float *sum2, int len)
52 {
53  const vector float *win1a = (const vector float *) win1;
54  const vector float *win2a = (const vector float *) win2;
55  const vector float *bufa = (const vector float *) buf;
56  vector float *sum1a = (vector float *) sum1;
57  vector float *sum2a = (vector float *) sum2;
58  vector float av_uninit(v0), av_uninit(v4);
59  vector float v1, v2, v3;
60 
61  len = len >> 2;
62 
63 #define MULT(a, b) \
64  { \
65  v1 = vec_ld(a, win1a); \
66  v2 = vec_ld(b, win2a); \
67  v3 = vec_ld(a, bufa); \
68  v0 = vec_madd(v3, v1, v0); \
69  v4 = vec_madd(v2, v3, v4); \
70  }
71 
72  while (len--) {
73  v0 = vec_xor(v0, v0);
74  v4 = vec_xor(v4, v4);
75 
76  MULT( 0, 0);
77  MULT( 256, 64);
78  MULT( 512, 128);
79  MULT( 768, 192);
80  MULT(1024, 256);
81  MULT(1280, 320);
82  MULT(1536, 384);
83  MULT(1792, 448);
84 
85  vec_st(v0, 0, sum1a);
86  vec_st(v4, 0, sum2a);
87  sum1a++;
88  sum2a++;
89  win1a++;
90  win2a++;
91  bufa++;
92  }
93 }
94 
95 static void apply_window_mp3(float *in, float *win, int *unused, float *out,
96  ptrdiff_t incr)
97 {
98  LOCAL_ALIGNED_16(float, suma, [17]);
99  LOCAL_ALIGNED_16(float, sumb, [17]);
100  LOCAL_ALIGNED_16(float, sumc, [17]);
101  LOCAL_ALIGNED_16(float, sumd, [17]);
102 
103  float sum;
104  int j;
105  float *out2 = out + 32 * incr;
106 
107  /* copy to avoid wrap */
108  memcpy(in + 512, in, 32 * sizeof(*in));
109 
110  apply_window(in + 16, win , win + 512, suma, sumc, 16);
111  apply_window(in + 32, win + 48, win + 640, sumb, sumd, 16);
112 
113  SUM8(MLSS, suma[0], win + 32, in + 48);
114 
115  sumc[ 0] = 0;
116  sumb[16] = 0;
117  sumd[16] = 0;
118 
119  out[0 ] = suma[ 0];
120  out += incr;
121  out2 -= incr;
122  for(j=1;j<16;j++) {
123  *out = suma[ j] - sumd[16-j];
124  *out2 = -sumb[16-j] - sumc[ j];
125  out += incr;
126  out2 -= incr;
127  }
128 
129  sum = 0;
130  SUM8(MLSS, sum, win + 16 + 32, in + 32);
131  *out = sum;
132 }
133 
134 #endif /* HAVE_ALTIVEC */
135 
137 {
138 #if HAVE_ALTIVEC
140  return;
141 
142  s->apply_window_float = apply_window_mp3;
143 #endif /* HAVE_ALTIVEC */
144 }
mem_internal.h
out
FILE * out
Definition: movenc.c:55
MPADSPContext
Definition: mpegaudiodsp.h:28
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:109
win
static float win(SuperEqualizerContext *s, float n, int N)
Definition: af_superequalizer.c:119
SUM8
#define SUM8(op, sum, w, p)
Definition: mpegaudiodsp_template.c:82
av_cold
#define av_cold
Definition: attributes.h:90
s
#define s(width, name)
Definition: cbs_vp9.c:198
LOCAL_ALIGNED_16
#define LOCAL_ALIGNED_16(t, v,...)
Definition: mem_internal.h:130
PPC_ALTIVEC
#define PPC_ALTIVEC(flags)
Definition: cpu.h:25
cpu.h
ff_mpadsp_init_ppc
av_cold void ff_mpadsp_init_ppc(MPADSPContext *s)
Definition: mpegaudiodsp_altivec.c:136
MLSS
#define MLSS(rt, ra, rb)
Definition: mpegaudiodsp_template.c:66
MULT
#define MULT(c, x, n)
Definition: xvididct.c:145
attributes.h
internal.h
apply_window
static void(*const apply_window[4])(AVFloatDSPContext *fdsp, SingleChannelElement *sce, const float *audio)
Definition: aacenc.c:466
len
int len
Definition: vorbis_enc_data.h:426
av_uninit
#define av_uninit(x)
Definition: attributes.h:154
mpegaudiodsp.h
util_altivec.h
cpu.h