History

Add float_interleave() to FmtConvertContext with x86-optimized versions.

Partially based on patches by clsid2 in ffdshow-tryout. ff_float_interleave6() x86 improvements by Loren Merrit.

Justin Ruggles committed 15 years ago

Commit 32f8fb81 parent f907ad94 files · +200 −0Browse files

Unified · Split

4 files
  1. libavcodec/fmtconvert.c +20 −0
  2. libavcodec/fmtconvert.h +9 −0
  3. libavcodec/x86/fmtconvert.asm +141 −0
  4. libavcodec/x86/fmtconvert_mmx.c +30 −0
libavcodec/fmtconvert.c+20−0
@@ -56,11 +56,31 @@ static void float_to_int16_interleave_c(int16_t *dst, const float **src, · 55 unmodified lines
5656 }
5757 }
5858
59+void ff_float_interleave_c(float *dst, const float **src, unsigned int len,
60+ int channels)
61+{
62+ int j, c;
63+ unsigned int i;
64+ if (channels == 2) {
65+ for (i = 0; i < len; i++) {
66+ dst[2*i] = src[0][i];
67+ dst[2*i+1] = src[1][i];
68+ }
69+ } else if (channels == 1 && len < INT_MAX / sizeof(float)) {
70+ memcpy(dst, src[0], len * sizeof(float));
71+ } else {
72+ for (c = 0; c < channels; c++)
73+ for (i = 0, j = c; i < len; i++, j += channels)
74+ dst[j] = src[c][i];
75+ }
76+}
77+
5978 av_cold void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx)
6079 {
6180 c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_c;
6281 c->float_to_int16 = float_to_int16_c;
6382 c->float_to_int16_interleave = float_to_int16_interleave_c;
83+ c->float_interleave = ff_float_interleave_c;
6484
6585 if (ARCH_ARM) ff_fmt_convert_init_arm(c, avctx);
6686 if (HAVE_ALTIVEC) ff_fmt_convert_init_altivec(c, avctx);
libavcodec/fmtconvert.h+9−0
@@ -68,8 +68,17 @@ typedef struct FmtConvertContext { · 67 unmodified lines
6868 */
6969 void (*float_to_int16_interleave)(int16_t *dst, const float **src,
7070 long len, int channels);
71+
72+ /**
73+ * Convert an array of interleaved float to multiple arrays of float.
74+ */
75+ void (*float_interleave)(float *dst, const float **src, unsigned int len,
76+ int channels);
7177 } FmtConvertContext;
7278
79+void ff_float_interleave_c(float *dst, const float **src, unsigned int len,
80+ int channels);
81+
7382 void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx);
7483
7584 void ff_fmt_convert_init_arm(FmtConvertContext *c, AVCodecContext *avctx);
libavcodec/x86/fmtconvert.asm+141−0
@@ -20,6 +20,7 @@ · 19 unmodified lines
2020 ;******************************************************************************
2121
2222 %include "x86inc.asm"
23+%include "x86util.asm"
2324
2425 section .text align=16
2526
@@ -89,3 +90,143 @@ FLOAT_TO_INT16_INTERLEAVE6 3dnow · 63 unmodified lines
8990 %undef pswapd
9091 FLOAT_TO_INT16_INTERLEAVE6 3dn2
9192 %undef cvtps2pi
93+
94+;-----------------------------------------------------------------------------
95+; void ff_float_interleave6(float *dst, const float **src, unsigned int len);
96+;-----------------------------------------------------------------------------
97+
98+%macro BUTTERFLYPS 3
99+ movaps m%3, m%1
100+ unpcklps m%1, m%2
101+ unpckhps m%3, m%2
102+ SWAP %2, %3
103+%endmacro
104+
105+%macro FLOAT_INTERLEAVE6 2
106+cglobal float_interleave6_%1, 2,7,%2, dst, src, src1, src2, src3, src4, src5
107+%ifdef ARCH_X86_64
108+ %define lend r10d
109+ mov lend, r2d
110+%else
111+ %define lend dword r2m
112+%endif
113+ mov src1q, [srcq+1*gprsize]
114+ mov src2q, [srcq+2*gprsize]
115+ mov src3q, [srcq+3*gprsize]
116+ mov src4q, [srcq+4*gprsize]
117+ mov src5q, [srcq+5*gprsize]
118+ mov srcq, [srcq]
119+ sub src1q, srcq
120+ sub src2q, srcq
121+ sub src3q, srcq
122+ sub src4q, srcq
123+ sub src5q, srcq
124+.loop:
125+%ifidn %1, sse
126+ movaps m0, [srcq]
127+ movaps m1, [srcq+src1q]
128+ movaps m2, [srcq+src2q]
129+ movaps m3, [srcq+src3q]
130+ movaps m4, [srcq+src4q]
131+ movaps m5, [srcq+src5q]
132+
133+ BUTTERFLYPS 0, 1, 6
134+ BUTTERFLYPS 2, 3, 6
135+ BUTTERFLYPS 4, 5, 6
136+
137+ movaps m6, m4
138+ shufps m4, m0, 0xe4
139+ movlhps m0, m2
140+ movhlps m6, m2
141+ movaps [dstq ], m0
142+ movaps [dstq+16], m4
143+ movaps [dstq+32], m6
144+
145+ movaps m6, m5
146+ shufps m5, m1, 0xe4
147+ movlhps m1, m3
148+ movhlps m6, m3
149+ movaps [dstq+48], m1
150+ movaps [dstq+64], m5
151+ movaps [dstq+80], m6
152+%else ; mmx
153+ movq m0, [srcq]
154+ movq m1, [srcq+src1q]
155+ movq m2, [srcq+src2q]
156+ movq m3, [srcq+src3q]
157+ movq m4, [srcq+src4q]
158+ movq m5, [srcq+src5q]
159+
160+ SBUTTERFLY dq, 0, 1, 6
161+ SBUTTERFLY dq, 2, 3, 6
162+ SBUTTERFLY dq, 4, 5, 6
163+ movq [dstq ], m0
164+ movq [dstq+ 8], m2
165+ movq [dstq+16], m4
166+ movq [dstq+24], m1
167+ movq [dstq+32], m3
168+ movq [dstq+40], m5
169+%endif
170+ add srcq, mmsize
171+ add dstq, mmsize*6
172+ sub lend, mmsize/4
173+ jg .loop
174+%ifidn %1, mmx
175+ emms
176+%endif
177+ REP_RET
178+%endmacro
179+
180+INIT_MMX
181+FLOAT_INTERLEAVE6 mmx, 0
182+INIT_XMM
183+FLOAT_INTERLEAVE6 sse, 7
184+
185+;-----------------------------------------------------------------------------
186+; void ff_float_interleave2(float *dst, const float **src, unsigned int len);
187+;-----------------------------------------------------------------------------
188+
189+%macro FLOAT_INTERLEAVE2 2
190+cglobal float_interleave2_%1, 3,4,%2, dst, src, len, src1
191+ mov src1q, [srcq+gprsize]
192+ mov srcq, [srcq ]
193+ sub src1q, srcq
194+.loop
195+ MOVPS m0, [srcq ]
196+ MOVPS m1, [srcq+src1q ]
197+ MOVPS m3, [srcq +mmsize]
198+ MOVPS m4, [srcq+src1q+mmsize]
199+
200+ MOVPS m2, m0
201+ PUNPCKLDQ m0, m1
202+ PUNPCKHDQ m2, m1
203+
204+ MOVPS m1, m3
205+ PUNPCKLDQ m3, m4
206+ PUNPCKHDQ m1, m4
207+
208+ MOVPS [dstq ], m0
209+ MOVPS [dstq+1*mmsize], m2
210+ MOVPS [dstq+2*mmsize], m3
211+ MOVPS [dstq+3*mmsize], m1
212+
213+ add srcq, mmsize*2
214+ add dstq, mmsize*4
215+ sub lend, mmsize/2
216+ jg .loop
217+%ifidn %1, mmx
218+ emms
219+%endif
220+ REP_RET
221+%endmacro
222+
223+INIT_MMX
224+%define MOVPS movq
225+%define PUNPCKLDQ punpckldq
226+%define PUNPCKHDQ punpckhdq
227+FLOAT_INTERLEAVE2 mmx, 0
228+INIT_XMM
229+%define MOVPS movaps
230+%define PUNPCKLDQ unpcklps
231+%define PUNPCKHDQ unpckhps
232+FLOAT_INTERLEAVE2 sse, 5
libavcodec/x86/fmtconvert_mmx.c+30−0
@@ -235,11 +235,40 @@ static void float_to_int16_interleave_3dn2(int16_t *dst, const float **src, long · 234 unmodified lines
235235 float_to_int16_interleave_3dnow(dst, src, len, channels);
236236 }
237237
238+void ff_float_interleave2_mmx(float *dst, const float **src, unsigned int len);
239+void ff_float_interleave2_sse(float *dst, const float **src, unsigned int len);
240+
241+void ff_float_interleave6_mmx(float *dst, const float **src, unsigned int len);
242+void ff_float_interleave6_sse(float *dst, const float **src, unsigned int len);
243+
244+static void float_interleave_mmx(float *dst, const float **src,
245+ unsigned int len, int channels)
246+{
247+ if (channels == 2) {
248+ ff_float_interleave2_mmx(dst, src, len);
249+ } else if (channels == 6)
250+ ff_float_interleave6_mmx(dst, src, len);
251+ else
252+ ff_float_interleave_c(dst, src, len, channels);
253+}
254+
255+static void float_interleave_sse(float *dst, const float **src,
256+ unsigned int len, int channels)
257+{
258+ if (channels == 2) {
259+ ff_float_interleave2_sse(dst, src, len);
260+ } else if (channels == 6)
261+ ff_float_interleave6_sse(dst, src, len);
262+ else
263+ ff_float_interleave_c(dst, src, len, channels);
264+}
265+
238266 void ff_fmt_convert_init_x86(FmtConvertContext *c, AVCodecContext *avctx)
239267 {
240268 int mm_flags = av_get_cpu_flags();
241269
242270 if (mm_flags & AV_CPU_FLAG_MMX) {
271+ c->float_interleave = float_interleave_mmx;
243272
244273 if(mm_flags & AV_CPU_FLAG_3DNOW){
245274 if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
@@ -256,6 +285,7 @@ void ff_fmt_convert_init_x86(FmtConvertContext *c, AVCodecContext *avctx) · 10 unmodified lines
256285 c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse;
257286 c->float_to_int16 = float_to_int16_sse;
258287 c->float_to_int16_interleave = float_to_int16_interleave_sse;
288+ c->float_interleave = float_interleave_sse;
259289 }
260290 if(mm_flags & AV_CPU_FLAG_SSE2){
261291 c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse2;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t