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