summaryrefslogtreecommitdiff
path: root/ac3dec/downmix_kni.S
blob: 7df8c060f52eaeea206446d8dd8ea23f968dbe11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
/* 
 *  downmix_kni.S
 *
 *  Copyright (C) Yuqing Deng <Yuqing_Deng@brown.edu> - October 2000
 *
 *
 *  downmix_kni.S is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  downmix_kni.S is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#ifdef __i386__

.section .rodata
	.align 4
sqrt2:	.float 0f0.7071068
	.p2align 5,0,
	
	.section .text
	
	.align 4
	.global downmix_3f_2r_to_2ch_kni
	.type downmix_3f_2r_to_2ch_kni, @function

downmix_3f_2r_to_2ch_kni:
	pushl	%ebp
	movl  	%esp, %ebp
	
	pushl	%eax
	pushl	%ebx
	pushl	%ecx

	movl 	8(%ebp), %eax /* samples[] */
	movl	12(%ebp), %ebx /* &dm_par */
	movl	$64, %ecx		/* loop counter */

	movss	(%ebx), %xmm5	/* unit */
	shufps	$0, %xmm5, %xmm5	/* unit | unit | unit | unit */

	movss	4(%ebx), %xmm6		/* clev */
	shufps	$0, %xmm6, %xmm6	/* clev | clev | clev | clev */

	movss	8(%ebx), %xmm7		/* slev */
	shufps	$0, %xmm7, %xmm7	/* slev | slev | slev | slev */

.loop:	
	movaps	(%eax), %xmm0 /*  left */
	movaps	2048(%eax), %xmm1 /* right */
	movaps 	1024(%eax), %xmm2	/* center */
	mulps	%xmm5, %xmm0
	mulps	%xmm5, %xmm1
	
	mulps	%xmm6, %xmm2
	movaps	3072(%eax), %xmm3	/* leftsur */
	movaps	4096(%eax), %xmm4	/* rithgsur */
	addps	%xmm2, %xmm0
	addps 	%xmm2, %xmm1

	mulps	%xmm7, %xmm3
	mulps	%xmm7, %xmm4
	addps	%xmm3, %xmm0
	addps	%xmm4, %xmm1

	movaps	%xmm0, (%eax)
	movaps	%xmm1, 1024(%eax)

	addl	$16, %eax
	decl 	%ecx
	jnz	.loop

	popl	%ecx
	popl	%ebx
	popl 	%eax

	leave
	ret
	.p2align 4,,7

	.global downmix_2f_2r_to_2ch_kni
	.type downmix_2f_2r_to_2ch_kni, @function

downmix_2f_2r_to_2ch_kni:
	pushl %ebp
	movl  %esp, %ebp

	pushl %eax
	pushl %ebx
	pushl %ecx

	movl 8(%ebp), %eax /* samples[] */
	movl 12(%ebp), %ebx /* &dm_par */
	movl $64, %ecx	/* loop counter */

	movss (%ebx), %xmm5	/* unit */
	shufps $0, %xmm5, %xmm5 /* unit | unit | unit | unit */

	movss	8(%ebx), %xmm7		/* slev */
	shufps	$0, %xmm7, %xmm7	/* slev | slev | slev | slev */

.loop3:	
	movaps	(%eax), %xmm0 /*  left */
	movaps	1024(%eax), %xmm1 /* right */
	movaps 	2048(%eax), %xmm3	/* leftsur */
	mulps	%xmm5, %xmm0
	mulps	%xmm5, %xmm1
	
	movaps	3072(%eax), %xmm4	/* rightsur */

	mulps	%xmm7, %xmm3
	mulps	%xmm7, %xmm4
	addps	%xmm3, %xmm0
	addps	%xmm4, %xmm1

	movaps	%xmm0, (%eax)
	movaps	%xmm1, 1024(%eax)

	addl	$16, %eax
	decl 	%ecx
	jnz	.loop3

	popl	%ecx
	popl	%ebx
	popl 	%eax

	leave
	ret
	.p2align 4,,7
	
	.global downmix_3f_1r_to_2ch_kni
	.type downmix_3f_1r_to_2ch_kni, @function

downmix_3f_1r_to_2ch_kni:
	pushl	%ebp
	movl  	%esp, %ebp
	
	pushl	%eax
	pushl	%ebx
	pushl	%ecx

	movl 	8(%ebp), %eax /* samples[] */
	movl	12(%ebp), %ebx /* &dm_par */
	movl	$64, %ecx		/* loop counter */

	movss	(%ebx), %xmm5	/* unit */
	shufps	$0, %xmm5, %xmm5	/* unit | unit | unit | unit */

	movss	4(%ebx), %xmm6		/* clev */
	shufps	$0, %xmm6, %xmm6	/* clev | clev | clev | clev */

	movss	8(%ebx), %xmm7		/* slev */
	shufps	$0, %xmm7, %xmm7	/* slev | slev | slev | slev */

.loop4:	
	movaps	(%eax), %xmm0 /*  left */
	movaps	2048(%eax), %xmm1 /* right */
	movaps 	1024(%eax), %xmm2	/* center */
	mulps	%xmm5, %xmm0
	mulps	%xmm5, %xmm1
	
	mulps	%xmm6, %xmm2
	movaps	3072(%eax), %xmm3	/* sur */

	addps	%xmm2, %xmm0
	mulps	%xmm7, %xmm3
	
	addps 	%xmm2, %xmm1

	subps	%xmm3, %xmm0
	addps	%xmm3, %xmm1

	movaps	%xmm0, (%eax)
	movaps	%xmm1, 1024(%eax)

	addl	$16, %eax
	decl 	%ecx
	jnz	.loop4

	popl	%ecx
	popl	%ebx
	popl 	%eax

	leave
	ret
	.p2align 4,,7
		
	.global downmix_2f_1r_to_2ch_kni
	.type downmix_2f_1r_to_2ch_kni, @function

downmix_2f_1r_to_2ch_kni:
	pushl	%ebp
	movl  	%esp, %ebp
	
	pushl	%eax
	pushl	%ebx
	pushl	%ecx

	movl 	8(%ebp), %eax /* samples[] */
	movl	12(%ebp), %ebx /* &dm_par */
	movl	$64, %ecx		/* loop counter */

	movss	(%ebx), %xmm5	/* unit */
	shufps	$0, %xmm5, %xmm5	/* unit | unit | unit | unit */

	movss	8(%ebx), %xmm7		/* slev */
	shufps	$0, %xmm7, %xmm7	/* slev | slev | slev | slev */

.loop5:	
	movaps	(%eax), %xmm0 /*  left */
	movaps	1024(%eax), %xmm1 /* right */
	
	mulps	%xmm5, %xmm0
	mulps	%xmm5, %xmm1
	
	movaps	2048(%eax), %xmm3	/* sur */

	mulps	%xmm7, %xmm3
	
	subps	%xmm3, %xmm0
	addps	%xmm3, %xmm1

	movaps	%xmm0, (%eax)
	movaps	%xmm1, 1024(%eax)

	addl	$16, %eax
	decl 	%ecx
	jnz	.loop5

	popl	%ecx
	popl	%ebx
	popl 	%eax

	leave
	ret
	.p2align 4,,7
	
	.global downmix_3f_0r_to_2ch_kni
	.type downmix_3f_0r_to_2ch_kni, @function

downmix_3f_0r_to_2ch_kni:
	pushl	%ebp
	movl  	%esp, %ebp
	
	pushl	%eax
	pushl	%ebx
	pushl	%ecx

	movl 	8(%ebp), %eax /* samples[] */
	movl	12(%ebp), %ebx /* &dm_par */
	movl	$64, %ecx		/* loop counter */

	movss	(%ebx), %xmm5	/* unit */
	shufps	$0, %xmm5, %xmm5	/* unit | unit | unit | unit */

	movss	4(%ebx), %xmm6		/* clev */
	shufps	$0, %xmm6, %xmm6	/* clev | clev | clev | clev */


.loop6:	
	movaps	(%eax), %xmm0 /*  left */
	movaps	2048(%eax), %xmm1 /* right */
	movaps 	1024(%eax), %xmm2	/* center */
	mulps	%xmm5, %xmm0
	mulps	%xmm5, %xmm1
	
	mulps	%xmm6, %xmm2

	addps	%xmm2, %xmm0
	
	addps 	%xmm2, %xmm1

	movaps	%xmm0, (%eax)
	movaps	%xmm1, 1024(%eax)

	addl	$16, %eax
	decl 	%ecx
	jnz	.loop6

	popl	%ecx
	popl	%ebx
	popl 	%eax

	leave
	ret
	.p2align 4,,7
	
	.global stream_sample_2ch_to_s16_kni
	.type stream_sample_2ch_to_s16_kni, @function

stream_sample_2ch_to_s16_kni:
	pushl %ebp
	movl  %esp, %ebp

	pushl %eax
	pushl %ebx
	pushl %edx
	pushl %ecx

	movl 8(%ebp), %eax	/* s16_samples */
	movl 12(%ebp), %ebx	/* left */
	movl 16(%ebp), %edx	/* right */
	movl $64, %ecx

.loop1:
	movaps (%ebx), %xmm0	/* l3 | l2 | l1 | l0 */
	movaps (%edx), %xmm1	/* r3 | r2 | r1 | r0 */
	movhlps %xmm0, %xmm2	/* l3 | l2 */
	movhlps %xmm1, %xmm3	/* r3 | r2 */
	unpcklps %xmm1, %xmm0	/* r1 | l1 | r0 | l0 */
	unpcklps %xmm3, %xmm2	/* r3 | l3 | r2 | l2 */

	cvtps2pi %xmm0, %mm0	/* r0 l0 --> mm0, int_32 */
	movhlps %xmm0, %xmm0	
	cvtps2pi %xmm0, %mm1	/* r1 l1 --> mm1, int_32 */

	cvtps2pi %xmm2, %mm2	/* r2 l2 --> mm2, int_32 */
	movhlps %xmm2, %xmm2
	cvtps2pi %xmm2, %mm3	/* r3 l3 --> mm3, int_32 */
	packssdw %mm1, %mm0	/* r1 l1 r0 l0 --> mm0, int_16 */
	packssdw %mm3, %mm2	/* r3 l3 r2 l2 --> mm2, int_16 */

	movq %mm0, (%eax)
	movq %mm2, 8(%eax)
	addl $16, %eax
	addl $16, %ebx
	addl $16, %edx

	decl %ecx
	jnz .loop1

	popl %ecx
	popl %edx
	popl %ebx
	popl %eax

	emms

	leave
	ret
	.p2align 4,,7
	
	.global stream_sample_1ch_to_s16_kni
	.type stream_sample_1ch_to_s16_kni, @function

stream_sample_1ch_to_s16_kni:
	pushl %ebp
	movl  %esp, %ebp

	pushl %eax
	pushl %ebx
	pushl %ecx

	movl $sqrt2, %eax
	movss (%eax), %xmm7
	movl 8(%ebp), %eax	/* s16_samples */
	movl 12(%ebp), %ebx	/* left */
	shufps $0, %xmm7, %xmm7
	movl $64, %ecx

.loop2:
	movaps (%ebx), %xmm0	/* c3 | c2 | c1 | c0 */
	mulps %xmm7, %xmm0
	movhlps %xmm0, %xmm2	/* c3 | c2 */

	cvtps2pi %xmm0, %mm0	/* c1 c0 --> mm0, int_32 */
	cvtps2pi %xmm2, %mm1	/* c3 c2 --> mm1, int_32 */

	packssdw %mm0, %mm0	/* c1 c1 c0 c0 --> mm0, int_16 */
	packssdw %mm1, %mm1	/* c3 c3 c2 c2 --> mm1, int_16 */

	movq %mm0, (%eax)
	movq %mm1, 8(%eax)
	addl $16, %eax
	addl $16, %ebx

	decl %ecx
	jnz .loop2

	popl %ecx
	popl %ebx
	popl %eax
	
	emms
	leave
	ret 
#endif