~ubuntu-branches/ubuntu/karmic/asterisk/karmic

« back to all changes in this revision

Viewing changes to codecs/mp3/src/x86gas.s

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2002-04-27 21:19:32 UTC
  • Revision ID: james.westby@ubuntu.com-20020427211932-kqaertc4bg7ss5mc
Tags: upstream-0.1.11
ImportĀ upstreamĀ versionĀ 0.1.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#       
 
2
#       FreeAmp - The Free MP3 Player
 
3
#
 
4
#       Based on MP3 decoder originally Copyright (C) 1995-1997
 
5
#       Xing Technology Corp.  http://www.xingtech.com
 
6
#
 
7
#       Copyright (C) 1999 Mark H. Weaver <mhw@netris.org>
 
8
#
 
9
#       This program is free software; you can redistribute it and/or modify
 
10
#       it under the terms of the GNU General Public License as published by
 
11
#       the Free Software Foundation; either version 2 of the License, or
 
12
#       (at your option) any later version.
 
13
#
 
14
#       This program is distributed in the hope that it will be useful,
 
15
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
#       GNU General Public License for more details.
 
18
#
 
19
#       You should have received a copy of the GNU General Public License
 
20
#       along with this program; if not, write to the Free Software
 
21
#       Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
22
#       
 
23
#       $Id: x86gas.s,v 1.1 1999/12/07 05:46:02 markster Exp $
 
24
#
 
25
 
 
26
#%% extern wincoef,dword
 
27
#%% extern coef32,dword
 
28
#%% ! extern float wincoef[264];
 
29
#%% ! extern float coef32[31];
 
30
 
 
31
.equ L_tmp,     0
 
32
#%!.equ L_pcm,  4
 
33
#%% if-not-inline
 
34
.equ L_vbuf,    24
 
35
.equ L_vb_ptr,  28
 
36
.equ L_pcm,     32
 
37
 
 
38
.globl window_dual
 
39
        .align 16
 
40
#%% end-not-inline
 
41
#%% ! void window_dual(float *vbuf, int vb_ptr, short *pcm)
 
42
#%% ! {
 
43
window_dual:    #%% proc
 
44
#%% if-not-inline
 
45
        pushl %ebp
 
46
        pushl %edi
 
47
        pushl %esi
 
48
        pushl %ebx
 
49
        subl $4,%esp
 
50
 
 
51
        movl L_vb_ptr(%esp),%esi
 
52
        movl L_vbuf(%esp),%edi
 
53
#%% end-not-inline
 
54
 
 
55
#%!     movl vb_ptr,%esi
 
56
#%!     movl vbuf,%edi
 
57
#%!     movl pcm,%ecx
 
58
#%!     pushl %ebp
 
59
#%!     subl $8,%esp
 
60
#%!     movl %ecx,L_pcm(%esp)
 
61
 
 
62
        movl $511,%ebp          # ebp = 511
 
63
        leal wincoef,%ecx       # coef = wincoef
 
64
        addl $16,%esi           # si = vb_ptr + 16
 
65
        movl %esi,%ebx
 
66
        addl $32,%ebx
 
67
        andl %ebp,%ebx          # bx = (si + 32) & 511
 
68
 
 
69
# First 16
 
70
        movb $16,%dh            # i = 16
 
71
        .align 4
 
72
.FirstOuter:
 
73
        fldz                    # sum = 0.0
 
74
        movb $2,%dl             # j = 2
 
75
        .align 4
 
76
.FirstInner:
 
77
.rept 4         # Unrolled loop
 
78
        flds (%ecx)             # Push *coef
 
79
        fmuls (%edi,%esi,4)     # Multiply by vbuf[si]
 
80
        addl $64,%esi           # si += 64
 
81
        addl $4,%ecx            # Advance coef pointer
 
82
        andl %ebp,%esi          # si &= 511
 
83
        faddp %st,%st(1)        # Add to sum
 
84
        
 
85
        flds (%ecx)             # Push *coef
 
86
        fmuls (%edi,%ebx,4)     # Multiply by vbuf[bx]
 
87
        addl $64,%ebx           # bx += 64
 
88
        addl $4,%ecx            # Advance coef pointer
 
89
        andl %ebp,%ebx          # bx &= 511
 
90
        fsubrp %st,%st(1)       # Subtract from sum
 
91
.endr
 
92
 
 
93
        decb %dl                # --j
 
94
        jg .FirstInner          # Jump back if j > 0
 
95
 
 
96
        fistpl L_tmp(%esp)      # tmp = (long) round (sum)
 
97
        incl %esi               # si++
 
98
        movl L_tmp(%esp),%eax
 
99
        decl %ebx               # bx--
 
100
        movl %eax,%ebp
 
101
        sarl $15,%eax
 
102
        incl %eax
 
103
        sarl $1,%eax
 
104
        jz .FirstInRange        # Jump if in range
 
105
 
 
106
        sarl $16,%eax           # Out of range
 
107
        movl $32767,%ebp
 
108
        xorl %eax,%ebp
 
109
.FirstInRange:
 
110
        movl L_pcm(%esp),%eax
 
111
        movw %bp,(%eax)         # Store sample in *pcm
 
112
        addl $4,%eax            # Increment pcm
 
113
        movl $511,%ebp          # Reload ebp with 511
 
114
        movl %eax,L_pcm(%esp)
 
115
 
 
116
        decb %dh                # --i
 
117
        jg .FirstOuter          # Jump back if i > 0
 
118
 
 
119
 
 
120
# Special case
 
121
        fldz                    # sum = 0.0
 
122
        movb $4,%dl             # j = 4
 
123
        .align 4
 
124
.SpecialInner:
 
125
.rept 2         # Unrolled loop
 
126
        flds (%ecx)             # Push *coef
 
127
        fmuls (%edi,%ebx,4)     # Multiply by vbuf[bx]
 
128
        addl $64,%ebx           # bx += 64
 
129
        addl $4,%ecx            # Increment coef pointer
 
130
        andl %ebp,%ebx          # bx &= 511
 
131
        faddp %st,%st(1)        # Add to sum
 
132
.endr
 
133
        
 
134
        decb %dl                # --j
 
135
        jg .SpecialInner        # Jump back if j > 0
 
136
 
 
137
        fistpl L_tmp(%esp)      # tmp = (long) round (sum)
 
138
        decl %esi               # si--
 
139
        movl L_tmp(%esp),%eax
 
140
        incl %ebx               # bx++
 
141
        movl %eax,%ebp
 
142
        sarl $15,%eax
 
143
        incl %eax
 
144
        sarl $1,%eax
 
145
        jz .SpecialInRange      # Jump if within range
 
146
 
 
147
        sarl $16,%eax           # Out of range
 
148
        movl $32767,%ebp
 
149
        xorl %eax,%ebp
 
150
.SpecialInRange:
 
151
        movl L_pcm(%esp),%eax
 
152
        subl $36,%ecx           # Readjust coef pointer for last round
 
153
        movw %bp,(%eax)         # Store sample in *pcm
 
154
        addl $4,%eax            # Increment pcm
 
155
        movl $511,%ebp          # Reload ebp with 511
 
156
        movl %eax,L_pcm(%esp)
 
157
 
 
158
 
 
159
# Last 15
 
160
        movb $15,%dh            # i = 15
 
161
        .align 4
 
162
.LastOuter:
 
163
        fldz                    # sum = 0.0
 
164
        movb $2,%dl             # j = 2
 
165
        .align 4
 
166
.LastInner:
 
167
.rept 4         # Unrolled loop
 
168
        flds (%ecx)             # Push *coef
 
169
        fmuls (%edi,%esi,4)     # Multiply by vbuf[si]
 
170
        addl $64,%esi           # si += 64
 
171
        subl $4,%ecx            # Back up coef pointer
 
172
        andl %ebp,%esi          # si &= 511
 
173
        faddp %st,%st(1)        # Add to sum
 
174
        
 
175
        flds (%ecx)             # Push *coef
 
176
        fmuls (%edi,%ebx,4)     # Multiply by vbuf[bx]
 
177
        addl $64,%ebx           # bx += 64
 
178
        subl $4,%ecx            # Back up coef pointer
 
179
        andl %ebp,%ebx          # bx &= 511
 
180
        faddp %st,%st(1)        # Add to sum
 
181
.endr
 
182
 
 
183
        decb %dl                # --j
 
184
        jg .LastInner           # Jump back if j > 0
 
185
 
 
186
        fistpl L_tmp(%esp)      # tmp = (long) round (sum)
 
187
        decl %esi               # si--
 
188
        movl L_tmp(%esp),%eax
 
189
        incl %ebx               # bx++
 
190
        movl %eax,%ebp
 
191
        sarl $15,%eax
 
192
        incl %eax
 
193
        sarl $1,%eax
 
194
        jz .LastInRange         # Jump if in range
 
195
 
 
196
        sarl $16,%eax           # Out of range
 
197
        movl $32767,%ebp
 
198
        xorl %eax,%ebp
 
199
.LastInRange:
 
200
        movl L_pcm(%esp),%eax
 
201
        movw %bp,(%eax)         # Store sample in *pcm
 
202
        addl $4,%eax            # Increment pcm
 
203
        movl $511,%ebp          # Reload ebp with 511
 
204
        movl %eax,L_pcm(%esp)
 
205
 
 
206
        decb %dh                # --i
 
207
        jg .LastOuter           # Jump back if i > 0
 
208
 
 
209
#%!     addl $8,%esp
 
210
#%!     popl %ebp
 
211
 
 
212
#%% if-not-inline
 
213
# Restore regs and return
 
214
        addl $4,%esp    
 
215
        popl %ebx
 
216
        popl %esi
 
217
        popl %edi
 
218
        popl %ebp
 
219
        ret
 
220
#%% end-not-inline
 
221
#%% endp
 
222
#%% ! }
 
223
 
 
224
#---------------------------------------------------------------------------
 
225
 
 
226
.equ L_mi,      0
 
227
.equ L_m,       4
 
228
.equ L_dummy,   8
 
229
#%!.equ L_in,   12
 
230
#%!.equ L_out,  16
 
231
#%!.equ L_buf,  20      # Temporary buffer
 
232
#%!.equ L_locals, 148   # Bytes used for locals
 
233
#%% if-not-inline
 
234
.equ L_buf,     12      # Temporary buffer
 
235
.equ L_in,      160
 
236
.equ L_out,     164
 
237
.equ L_locals,  140     # Bytes used for locals
 
238
 
 
239
.globl asm_fdct32
 
240
        .align 16
 
241
#%% end-not-inline
 
242
#%% ! void asm_fdct32(float in[], float out[])
 
243
#%% ! {
 
244
asm_fdct32:     #%% proc
 
245
#%% if-not-inline
 
246
        pushl %ebp
 
247
        pushl %edi
 
248
        pushl %esi
 
249
        pushl %ebx
 
250
        subl $L_locals,%esp
 
251
 
 
252
        movl L_in(%esp),%edi    # edi = x
 
253
        movl L_out(%esp),%esi   # esi = f
 
254
#%% end-not-inline
 
255
 
 
256
#%!     movl in,%edi            # edi = x
 
257
#%!     movl out,%esi           # esi = f
 
258
#%!     pushl %ebp
 
259
#%!     subl $L_locals,%esp
 
260
 
 
261
        leal coef32-128,%ecx    # coef = coef32 - (32 * 4)
 
262
        movl $1,4(%esp)         # m = 1
 
263
        movl $16,%ebp           # n = 32 / 2
 
264
        
 
265
        leal L_buf(%esp),%ebx
 
266
        movl %ebx,L_out(%esp)   # From now on, use temp buf instead of orig x
 
267
        jmp .ForwardLoopStart
 
268
 
 
269
        .align 4
 
270
.ForwardOuterLoop:
 
271
        movl L_in(%esp),%edi    # edi = x
 
272
        movl L_out(%esp),%esi   # esi = f
 
273
        movl %edi,L_out(%esp)   # Exchange mem versions of f/x for next iter
 
274
.ForwardLoopStart:
 
275
        movl %esi,L_in(%esp)
 
276
        movl L_m(%esp),%ebx     # ebx = m (temporarily)
 
277
        movl %ebx,L_mi(%esp)    # mi = m
 
278
        sall $1,%ebx            # Double m for next iter
 
279
        leal (%ecx,%ebp,8),%ecx # coef += n * 8
 
280
        movl %ebx,L_m(%esp)     # Store doubled m
 
281
        leal (%esi,%ebp,4),%ebx # ebx = f2 = f + n * 4
 
282
        sall $3,%ebp            # n *= 8
 
283
 
 
284
        .align 4
 
285
.ForwardMiddleLoop:
 
286
        movl %ebp,%eax          # q = n
 
287
        xorl %edx,%edx          # p = 0
 
288
        test $8,%eax
 
289
        jnz .ForwardInnerLoop1
 
290
 
 
291
        .align 4
 
292
.ForwardInnerLoop:
 
293
        subl $4,%eax            # q -= 4
 
294
        flds (%edi,%eax)        # push x[q]
 
295
        flds (%edi,%edx)        # push x[p]
 
296
        fld %st(1)              # Duplicate top two stack entries
 
297
        fld %st(1)
 
298
        faddp %st,%st(1)
 
299
        fstps (%esi,%edx)       # f[p] = x[p] + x[q]
 
300
        fsubp %st,%st(1)
 
301
        fmuls (%ecx,%edx)
 
302
        fstps (%ebx,%edx)       # f2[p] = coef[p] * (x[p] - x[q])
 
303
        addl $4,%edx            # p += 4
 
304
 
 
305
.ForwardInnerLoop1:
 
306
        subl $4,%eax            # q -= 4
 
307
        flds (%edi,%eax)        # push x[q]
 
308
        flds (%edi,%edx)        # push x[p]
 
309
        fld %st(1)              # Duplicate top two stack entries
 
310
        fld %st(1)
 
311
        faddp %st,%st(1)
 
312
        fstps (%esi,%edx)       # f[p] = x[p] + x[q]
 
313
        fsubp %st,%st(1)
 
314
        fmuls (%ecx,%edx)
 
315
        fstps (%ebx,%edx)       # f2[p] = coef[p] * (x[p] - x[q])
 
316
        addl $4,%edx            # p += 4
 
317
 
 
318
        cmpl %eax,%edx
 
319
        jb .ForwardInnerLoop    # Jump back if (p < q)
 
320
 
 
321
        addl %ebp,%esi          # f += n
 
322
        addl %ebp,%ebx          # f2 += n
 
323
        addl %ebp,%edi          # x += n
 
324
        decl L_mi(%esp)         # mi--
 
325
        jg .ForwardMiddleLoop   # Jump back if mi > 0
 
326
 
 
327
        sarl $4,%ebp            # n /= 16
 
328
        jg .ForwardOuterLoop    # Jump back if n > 0
 
329
 
 
330
 
 
331
# Setup back loop
 
332
        movl $8,%ebx            # ebx = m = 8 (temporarily)
 
333
        movl %ebx,%ebp          # n = 4 * 2
 
334
 
 
335
        .align 4
 
336
.BackOuterLoop:
 
337
        movl L_out(%esp),%esi   # esi = f
 
338
        movl %ebx,L_mi(%esp)    # mi = m
 
339
        movl L_in(%esp),%edi    # edi = x
 
340
        movl %ebx,L_m(%esp)     # Store m
 
341
        movl %esi,L_in(%esp)    # Exchange mem versions of f/x for next iter
 
342
        movl %edi,%ebx
 
343
        movl %edi,L_out(%esp)
 
344
        subl %ebp,%ebx          # ebx = x2 = x - n
 
345
        sall $1,%ebp            # n *= 2
 
346
 
 
347
        .align 4
 
348
.BackMiddleLoop:
 
349
        movl -4(%ebx,%ebp),%ecx
 
350
        movl %ecx,-8(%esi,%ebp) # f[n - 8] = x2[n - 4]
 
351
        flds -4(%edi,%ebp)      # push x[n - 4]
 
352
        fsts -4(%esi,%ebp)      # f[n - 4] = x[n - 4], without popping
 
353
        leal -8(%ebp),%eax      # q = n - 8
 
354
        leal -16(%ebp),%edx     # p = n - 16
 
355
 
 
356
        .align 4
 
357
.BackInnerLoop:
 
358
        movl (%ebx,%eax),%ecx
 
359
        movl %ecx,(%esi,%edx)   # f[p] = x2[q]
 
360
        flds (%edi,%eax)        # push x[q]
 
361
        fadd %st,%st(1)
 
362
        fxch
 
363
        fstps 4(%esi,%edx)      # f[p + 4] = x[q] + x[q + 4]
 
364
        subl $4,%eax            # q -= 4
 
365
        subl $8,%edx            # p -= 8
 
366
        jge .BackInnerLoop      # Jump back if p >= 0
 
367
 
 
368
        fstps L_dummy(%esp)     # Pop (XXX is there a better way to do this?)
 
369
        addl %ebp,%esi          # f += n
 
370
        addl %ebp,%ebx          # x2 += n
 
371
        addl %ebp,%edi          # x += n
 
372
        decl L_mi(%esp)         # mi--
 
373
        jg .BackMiddleLoop      # Jump back if mi > 0
 
374
 
 
375
        movl L_m(%esp),%ebx     # ebx = m (temporarily)
 
376
        sarl $1,%ebx            # Halve m for next iter
 
377
        jg .BackOuterLoop       # Jump back if m > 0
 
378
 
 
379
#%!     addl $L_locals,%esp
 
380
#%!     popl %ebp
 
381
 
 
382
#%% if-not-inline
 
383
# Restore regs and return
 
384
        addl $L_locals,%esp
 
385
        popl %ebx
 
386
        popl %esi
 
387
        popl %edi
 
388
        popl %ebp
 
389
        ret
 
390
#%% end-not-inline
 
391
#%% endp
 
392
#%% ! }
 
393