Debian Codegraph @

src/libmpg123/synth_i586_dither.S

raw
1 /*
2 decode_i586_dither: asm synth with dither noise
3
4 copyright ?-2007 by the mpg123 project - free software under the terms of the LGPL 2.1
5 see COPYING and AUTHORS files in distribution or http://mpg123.org
6 initially written by Stefan Bieschewski as decode_i586.s without dither
7
8 This version uses "circular" 64k dither noise.
9 (Patch by Adrian <[email protected]>)
10
11 Thomas learned something about assembler and the stack while making this one thread safe (removing static data).
12 */
13
14 #include "mangle.h"
15
16 RODATA
17 ALIGN8
18 .LC0:
19 .long 0x0,0x40dfffc0
20 ALIGN8
21 .LC1:
22 .long 0x0,0xc0e00000
23 ALIGN8
24 .text
25 /* int synth_1to1_i586_asm_dither(real *bandPtr, int channel, unsigned char *out, unsigned char *buffs, int bo_and_ditherindex[2], real *decwin, real* dithernoise); */
26 .globl ASM_NAME(INT123_synth_1to1_i586_asm_dither)
27 ASM_NAME(INT123_synth_1to1_i586_asm_dither):
28 subl $16,%esp
29 pushl %ebp
30 pushl %edi
31 pushl %esi
32 pushl %ebx
33 /* stack: 0(%esp)=%ebx 4=esi 8=edi 12=ebp 16,20,24,28=local 32=back 36=bandptr 40=channel 44=out 48=buffs 52=bo 56=decwin 60=dithernoise */
34 #define BANDPTR 36(%esp)
35 #define CHANNEL 40(%esp)
36 #define OUT 44(%esp)
37 #define BUFFS 48(%esp)
38 #define BO 52(%esp)
39 #define DECWIN 56(%esp)
40 #define DITHERNOISE 60(%esp)
41 /*#define DITHERNOISE $(ASM_NAME(INT123_dithernoise))*/
42 #define LOC0 16(%esp)
43 #define LOC1 20(%esp)
44 #define LOC2 24(%esp)
45 #define DITHERINDEX 28(%esp)
46 /* During application of the dithering, we need the shifted locations because there's an additional value on the stack. */
47 #define DITHERNOISE2 64(%esp)
48 #define DITHERINDEX2 32(%esp)
49
50 movl BANDPTR,%eax
51 movl OUT,%esi
52 movl BO, %ebx
53 movl (%ebx),%ebp /* get bo value */
54 movl 4(%ebx),%edi; /* get the ditherindex behind bo */
55 movl %edi,DITHERINDEX
56 xorl %edi,%edi
57 cmpl %edi,CHANNEL
58 jne .L48
59 decl %ebp
60 andl $15,%ebp
61 movl %ebp,(%ebx) /* save bo back */
62 movl BUFFS,%ecx
63 jmp .L49
64 .L48:
65 /* In stereo mode , "rewind" dither pointer 32 samples , so 2nd channel */
66 /* has same dither values. Tested OK for mono and stereo MP2 and MP3 */
67 subl $128,DITHERINDEX /* better move to %edi for the two calculations? */
68 andl $0x0003fffc,DITHERINDEX
69 addl $2,%esi
70 movl BUFFS,%ecx
71 addl $2176,%ecx
72 .L49:
73 /* now the call of dct64 is prepared, stuff pushed to the stack, but soon after it's removed again */
74 testl $1,%ebp
75 je .L50
76 movl %ecx,%ebx
77 movl %ebp,LOC0
78 pushl %eax
79 movl LOC1,%edx
80 leal (%ebx,%edx,4),%eax
81 pushl %eax
82 movl LOC2,%eax
83 incl %eax
84 andl $15,%eax
85 leal 1088(,%eax,4),%eax
86 addl %ebx,%eax
87 jmp .L74
88 .L50:
89 leal 1088(%ecx),%ebx
90 leal 1(%ebp),%edx
91 movl %edx,LOC0
92 pushl %eax
93 leal 1092(%ecx,%ebp,4),%eax
94 pushl %eax
95 leal (%ecx,%ebp,4),%eax
96 .L74:
97 pushl %eax
98 call FUNC(INT123_dct64_i386)
99 addl $12,%esp
100 /* Now removed the parameters.
101 stack: 0(%esp)=%ebx 4=esi 8=edi 12=ebp 16,20,24,28=local 32=back 36=bandptr 40=channel 44=out 48=buffs 52=bo 56=decwin 60=dithernoise */
102 movl LOC0,%edx
103 leal 0(,%edx,4),%edx
104 /* movl ASM_VALUE(decwin)+64,%eax */
105 movl DECWIN,%eax
106 addl $64,%eax
107 movl %eax,%ecx
108 subl %edx,%ecx
109 movl $16,%ebp
110 .L55:
111 flds (%ecx)
112 fmuls (%ebx)
113 flds 4(%ecx)
114 fmuls 4(%ebx)
115 fxch %st(1)
116 flds 8(%ecx)
117 fmuls 8(%ebx)
118 fxch %st(2)
119 fsubrp %st,%st(1)
120 flds 12(%ecx)
121 fmuls 12(%ebx)
122 fxch %st(2)
123 faddp %st,%st(1)
124 flds 16(%ecx)
125 fmuls 16(%ebx)
126 fxch %st(2)
127 fsubrp %st,%st(1)
128 flds 20(%ecx)
129 fmuls 20(%ebx)
130 fxch %st(2)
131 faddp %st,%st(1)
132 flds 24(%ecx)
133 fmuls 24(%ebx)
134 fxch %st(2)
135 fsubrp %st,%st(1)
136 flds 28(%ecx)
137 fmuls 28(%ebx)
138 fxch %st(2)
139 faddp %st,%st(1)
140 flds 32(%ecx)
141 fmuls 32(%ebx)
142 fxch %st(2)
143 fsubrp %st,%st(1)
144 flds 36(%ecx)
145 fmuls 36(%ebx)
146 fxch %st(2)
147 faddp %st,%st(1)
148 flds 40(%ecx)
149 fmuls 40(%ebx)
150 fxch %st(2)
151 fsubrp %st,%st(1)
152 flds 44(%ecx)
153 fmuls 44(%ebx)
154 fxch %st(2)
155 faddp %st,%st(1)
156 flds 48(%ecx)
157 fmuls 48(%ebx)
158 fxch %st(2)
159 fsubrp %st,%st(1)
160 flds 52(%ecx)
161 fmuls 52(%ebx)
162 fxch %st(2)
163 faddp %st,%st(1)
164 flds 56(%ecx)
165 fmuls 56(%ebx)
166 fxch %st(2)
167 fsubrp %st,%st(1)
168 flds 60(%ecx)
169 fmuls 60(%ebx)
170 fxch %st(2)
171 subl $4,%esp
172 faddp %st,%st(1)
173 fxch %st(1)
174 fsubrp %st,%st(1)
175
176 addl $4,DITHERINDEX2
177 andl $0x0003fffc,DITHERINDEX2
178 movl DITHERNOISE2,%edi
179 addl DITHERINDEX2,%edi
180
181 fadds (%edi)
182
183 /* fistpl and popl as a unit keep the stack unchanged */
184 fistpl (%esp)
185 popl %eax
186 cmpl $32767,%eax
187 jg 1f
188 cmpl $-32768,%eax
189 jl 2f
190 movw %ax,(%esi)
191 jmp 4f
192 1: movw $32767,(%esi)
193 jmp 3f
194 2: movw $-32768,(%esi)
195 3:
196 /* incl %edi */
197 4:
198 .L54:
199 addl $64,%ebx
200 subl $-128,%ecx
201 addl $4,%esi
202 decl %ebp
203 jnz .L55
204 flds (%ecx)
205 fmuls (%ebx)
206 flds 8(%ecx)
207 fmuls 8(%ebx)
208 flds 16(%ecx)
209 fmuls 16(%ebx)
210 fxch %st(2)
211 faddp %st,%st(1)
212 flds 24(%ecx)
213 fmuls 24(%ebx)
214 fxch %st(2)
215 faddp %st,%st(1)
216 flds 32(%ecx)
217 fmuls 32(%ebx)
218 fxch %st(2)
219 faddp %st,%st(1)
220 flds 40(%ecx)
221 fmuls 40(%ebx)
222 fxch %st(2)
223 faddp %st,%st(1)
224 flds 48(%ecx)
225 fmuls 48(%ebx)
226 fxch %st(2)
227 faddp %st,%st(1)
228 flds 56(%ecx)
229 fmuls 56(%ebx)
230 fxch %st(2)
231 subl $4,%esp
232 faddp %st,%st(1)
233 fxch %st(1)
234 faddp %st,%st(1)
235
236 addl $4,DITHERINDEX2
237 andl $0x0003fffc,DITHERINDEX2
238 movl DITHERNOISE2,%edi
239 addl DITHERINDEX2,%edi
240
241 fadds (%edi)
242 /* fistpl and popl as a unit keep the stack unchanged */
243 fistpl (%esp)
244 popl %eax
245 cmpl $32767,%eax
246 jg 1f
247 cmpl $-32768,%eax
248 jl 2f
249 movw %ax,(%esi)
250 jmp 4f
251 1: movw $32767,(%esi)
252 jmp 3f
253 2: movw $-32768,(%esi)
254 3:
255 /* incl %edi */
256 4:
257 .L62:
258 addl $-64,%ebx
259 addl $4,%esi
260 movl LOC0,%edx
261 leal -128(%ecx,%edx,8),%ecx
262 movl $15,%ebp
263 .L68:
264 flds -4(%ecx)
265 fchs
266 fmuls (%ebx)
267 flds -8(%ecx)
268 fmuls 4(%ebx)
269 fxch %st(1)
270 flds -12(%ecx)
271 fmuls 8(%ebx)
272 fxch %st(2)
273 fsubrp %st,%st(1)
274 flds -16(%ecx)
275 fmuls 12(%ebx)
276 fxch %st(2)
277 fsubrp %st,%st(1)
278 flds -20(%ecx)
279 fmuls 16(%ebx)
280 fxch %st(2)
281 fsubrp %st,%st(1)
282 flds -24(%ecx)
283 fmuls 20(%ebx)
284 fxch %st(2)
285 fsubrp %st,%st(1)
286 flds -28(%ecx)
287 fmuls 24(%ebx)
288 fxch %st(2)
289 fsubrp %st,%st(1)
290 flds -32(%ecx)
291 fmuls 28(%ebx)
292 fxch %st(2)
293 fsubrp %st,%st(1)
294 flds -36(%ecx)
295 fmuls 32(%ebx)
296 fxch %st(2)
297 fsubrp %st,%st(1)
298 flds -40(%ecx)
299 fmuls 36(%ebx)
300 fxch %st(2)
301 fsubrp %st,%st(1)
302 flds -44(%ecx)
303 fmuls 40(%ebx)
304 fxch %st(2)
305 fsubrp %st,%st(1)
306 flds -48(%ecx)
307 fmuls 44(%ebx)
308 fxch %st(2)
309 fsubrp %st,%st(1)
310 flds -52(%ecx)
311 fmuls 48(%ebx)
312 fxch %st(2)
313 fsubrp %st,%st(1)
314 flds -56(%ecx)
315 fmuls 52(%ebx)
316 fxch %st(2)
317 fsubrp %st,%st(1)
318 flds -60(%ecx)
319 fmuls 56(%ebx)
320 fxch %st(2)
321 fsubrp %st,%st(1)
322 flds (%ecx)
323 fmuls 60(%ebx)
324 fxch %st(2)
325 subl $4,%esp
326 fsubrp %st,%st(1)
327 fxch %st(1)
328 fsubrp %st,%st(1)
329
330 addl $4,DITHERINDEX2
331 andl $0x0003fffc,DITHERINDEX2
332 movl DITHERNOISE2,%edi
333 addl DITHERINDEX2,%edi
334
335 fadds (%edi)
336 /* fistpl and popl as a unit keep the stack unchanged */
337 fistpl (%esp)
338 popl %eax
339 cmpl $32767,%eax
340 jg 1f
341 cmpl $-32768,%eax
342 jl 2f
343 movw %ax,(%esi)
344 jmp 4f
345 1: movw $32767,(%esi)
346 jmp 3f
347 2: movw $-32768,(%esi)
348 3:
349 /* incl %edi */
350 4:
351 .L67:
352 addl $-64,%ebx
353 addl $-128,%ecx
354 addl $4,%esi
355 decl %ebp
356 jnz .L68
357 /* return ipv edi 0 in eax */
358 movl $0,%eax
359 /* save ditherindex */
360 movl BO,%ebx
361 movl DITHERINDEX,%esi
362 movl %esi,4(%ebx);
363 /* stack: 0=ebx 4=esi 8=edi 12=ebp 16,20,24,28=local 32=back 36=bandptr 40=channel 44=out 48=buffs 52=bo */
364 popl %ebx
365 popl %esi
366 popl %edi
367 popl %ebp
368 addl $16,%esp
369 /* The stack must be now: 0=back 4=bandptr 8=channel 12=out 16=buffs 20=bo */
370 ret
371
372 #if defined(PIC) && defined(__APPLE__)
373 .section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5
374 FUNC(INT123_dct64_i386):
375 .indirect_symbol ASM_NAME(INT123_dct64_i386)
376 hlt ; hlt ; hlt ; hlt ; hlt
377 #endif
378
379 NONEXEC_STACK