~kamalmostafa/ubuntu/lucid/pdp/fix-504941-ftbfs

« back to all changes in this revision

Viewing changes to system/mmx/pixel_biquad_s16.s

  • Committer: Bazaar Package Importer
  • Author(s): Guenter Geiger (Debian/GNU)
  • Date: 2005-03-15 22:21:05 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050315222105-1q287rsihmd9j1tb
Tags: 1:0.12.4-2
* fixed the hardcoded depends
* added 3dp library

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#    Pure Data Packet mmx routine.
2
 
#    Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
3
 
4
 
#    This program is free software; you can redistribute it and/or modify
5
 
#    it under the terms of the GNU General Public License as published by
6
 
#    the Free Software Foundation; either version 2 of the License, or
7
 
#    (at your option) any later version.
8
 
9
 
#    This program is distributed in the hope that it will be useful,
10
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
#    GNU General Public License for more details.
13
 
14
 
#    You should have received a copy of the GNU General Public License
15
 
#    along with this program; if not, write to the Free Software
16
 
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
 
#
18
 
 
19
 
        
20
 
        # DIRECT FORM II BIQUAD
21
 
        #
22
 
        # y[k]  = b0 * x[k] + u1[k-1]
23
 
        # u1[k] = b1 * x[k] + u2[k-1] - a1 * y[k]
24
 
        # u2[k] = b2 * x[k]           - a2 * y[k]
25
 
        # MACRO:        df2 <reg>
26
 
        #
27
 
        # computes a direct form 2 biquad
28
 
        # does not use {mm0-mm3}\<inreg>
29
 
        #
30
 
        # input:        <reg>   == input
31
 
        #               %mm4    == state 1
32
 
        #               %mm5    == state 2
33
 
        #               (%esi)  == biquad coefs (-a1 -a2 b0 b1 b2) in s1.14
34
 
        # output:       <reg>   == output
35
 
        #               %mm4    == state 1
36
 
        #               %mm5    == state 2
37
 
 
38
 
        .macro df2 reg 
39
 
        movq \reg, %mm6                 # mm6 == x[k]
40
 
        movq \reg, %mm7                 # mm7 == x[k]
41
 
        pmulhw 16(%esi), %mm6           # mm6 == x[k] * b0
42
 
        pmulhw 24(%esi), %mm7           # mm7 == x[k] * b1
43
 
        paddw %mm4, %mm6                # mm6 == x[k] * b0 + u1[k-1] == y[k]
44
 
        paddw %mm5, %mm7                # mm7 == x[k] * b1 + u2[k-1]
45
 
        paddsw %mm6, %mm6               # compensate for mul = x*y/4 (coefs are s1.14 fixed point)
46
 
        paddsw %mm6, %mm6               # paddsw ensures saturation
47
 
        movq \reg, %mm5                 # mm5 == x[k]
48
 
        movq %mm6, %mm4                 # mm4 == y[k]
49
 
        movq %mm6, \reg                 # reg == y[k]   --------------------
50
 
        pmulhw 0(%esi), %mm4            # mm4 == y[k] * (-a1)
51
 
        pmulhw 8(%esi), %mm6            # mm6 == y[k] * (-a2)
52
 
        pmulhw 32(%esi), %mm5           # mm5 == x[k] * b2
53
 
        paddw %mm7, %mm4                # mm4 == u1[k]  --------------------
54
 
        paddw %mm6, %mm5                # mm5 == u2[k]  --------------------
55
 
        .endm
56
 
 
57
 
                
58
 
        # input in register:    
59
 
        # %mm0-mm3:     input 4x4 pixels {x0 x1 x2 x3}
60
 
        # %esi:         coef memory  (-a1, -a2, b0, b1, b2) in s1.14
61
 
        # %edi:         state memory (u1, u2)
62
 
        
63
 
        # return in register:    
64
 
        # %mm0-mm4:     4x4 pixels result
65
 
 
66
 
 
67
 
 
68
 
        
69
 
        .macro biquad_4x4_pixels        
70
 
        .align 16
71
 
        movq 0(%edi), %mm4              # get state
72
 
        movq 8(%edi), %mm5
73
 
        df2 %mm0                        # compute 4 biquads
74
 
        df2 %mm1
75
 
        df2 %mm2
76
 
        df2 %mm3
77
 
        movq %mm4, 0(%edi)              # store state
78
 
        movq %mm5, 8(%edi)
79
 
        .endm
80
 
 
81
 
        
82
 
 
83
 
        # in order to use the 4 line parallel biquad routine on horizontal
84
 
        # lines, we need to reorder (rotate or transpose) the matrix, since
85
 
        # images are scanline encoded, and we want to work in parallell
86
 
        # on 4 lines.
87
 
        #
88
 
        # since the 4 lines are independent, it doesnt matter in which order
89
 
        # the the vector elements are present. 
90
 
        #
91
 
        # this allows us to use the same routine for left->right and right->left
92
 
        # processing.
93
 
        #       
94
 
        # some comments on the non-abelean group of square isometries consisting of
95
 
        # (I) identity
96
 
        # (H) horizontal axis mirror 
97
 
        # (V) vertical axis mirror
98
 
        # (T) transpose (diagonal axis mirror)
99
 
        # (A) antitranspose (antidiagonal axis mirror)
100
 
        # (R1) 90deg anticlockwize rotation
101
 
        # (R2) 180deg rotation
102
 
        # (R3) 90deg clockwize rotation
103
 
        #
104
 
        #       
105
 
        # we basicly have two options: (R1,R3) or (T,A)
106
 
        # we opt for T and A because they are self inverting, which improves locality
107
 
        #
108
 
        # use antitranspose for right to left an transpose
109
 
        # for left to right (little endian)
110
 
 
111
 
 
112
 
        # antitranspose 4x4
113
 
 
114
 
        # input
115
 
        # %mm3 == {d0 d1 d2 d3}
116
 
        # %mm2 == {c0 c1 c2 c3} 
117
 
        # %mm1 == {b0 b1 b2 b3} 
118
 
        # %mm0 == {a0 a1 a2 a3}
119
 
 
120
 
        # output
121
 
        # %mm3 == {a3 b3 c3 d3}
122
 
        # %mm2 == {a2 b2 c2 d2}
123
 
        # %mm1 == {a1 b1 c1 d1}
124
 
        # %mm0 == {a0 b0 c0 d0}
125
 
 
126
 
        
127
 
        .macro antitranspose_4x4:       
128
 
        movq %mm3, %mm4
129
 
        punpcklwd %mm1, %mm4    # mm4 <- {b2 d2 b3 d3}
130
 
        movq %mm3, %mm5 
131
 
        punpckhwd %mm1, %mm5    # mm5 <- {b0 d0 b1 d1}
132
 
                        
133
 
        movq %mm2, %mm6
134
 
        punpcklwd %mm0, %mm6    # mm6 <- {a2 c2 a3 c3}
135
 
        movq %mm2, %mm7 
136
 
        punpckhwd %mm0, %mm7    # mm7 <- {a0 c0 a1 c1}
137
 
 
138
 
        movq %mm4, %mm3
139
 
        punpcklwd %mm6, %mm3    # mm3 <- {a3 b3 c3 d3}
140
 
        movq %mm4, %mm2
141
 
        punpckhwd %mm6, %mm2    # mm2 <- {a2 b2 c2 d2}
142
 
                
143
 
        movq %mm5, %mm1
144
 
        punpcklwd %mm7, %mm1    # mm1 <- {a1 b1 c1 d1}
145
 
        movq %mm5, %mm0
146
 
        punpckhwd %mm7, %mm0    # mm0 <- {a0 b0 c0 d0}
147
 
        
148
 
        .endm
149
 
        
150
 
 
151
 
        # transpose 4x4
152
 
 
153
 
        # input
154
 
        # %mm3 == {d3 d2 d1 d0}
155
 
        # %mm2 == {c3 c2 c1 c0} 
156
 
        # %mm1 == {b3 b2 b1 b0} 
157
 
        # %mm0 == {a3 a2 a1 a0}
158
 
 
159
 
        # output
160
 
        # %mm3 == {d3 c3 b3 a3}
161
 
        # %mm2 == {d2 c2 b2 a2}
162
 
        # %mm1 == {d1 c1 b1 a1}
163
 
        # %mm0 == {d0 c0 b0 a0}
164
 
 
165
 
        
166
 
        .macro transpose_4x4:   
167
 
        movq %mm0, %mm4
168
 
        punpcklwd %mm2, %mm4    # mm4 <- {c1 a1 c0 a0}
169
 
        movq %mm0, %mm5 
170
 
        punpckhwd %mm2, %mm5    # mm5 <- {c3 a3 c2 a2}
171
 
                
172
 
        movq %mm1, %mm6
173
 
        punpcklwd %mm3, %mm6    # mm6 <- {d1 b1 d0 b0}
174
 
        movq %mm1, %mm7 
175
 
        punpckhwd %mm3, %mm7    # mm7 <- {d3 b3 d2 b2}
176
 
 
177
 
        movq %mm4, %mm0
178
 
        punpcklwd %mm6, %mm0    # mm0 <- {d0 c0 b0 a0}
179
 
        movq %mm4, %mm1
180
 
        punpckhwd %mm6, %mm1    # mm1 <- {d1 c1 b1 a1}
181
 
                
182
 
        movq %mm5, %mm2
183
 
        punpcklwd %mm7, %mm2    # mm2 <- {d2 c2 b2 a2}
184
 
        movq %mm5, %mm3
185
 
        punpckhwd %mm7, %mm3    # mm3 <- {d3 c3 b3 a3}
186
 
 
187
 
        .endm
188
 
        
189
 
.globl pixel_biquad_vertb_s16
190
 
.type  pixel_biquad_vertb_s16,@function
191
 
 
192
 
 
193
 
# pixel_biquad_vertbr_s16(char *pixel_array, int nb_rows, int linewidth, short int coef[20], short int state[8])
194
 
 
195
 
        
196
 
pixel_biquad_vertb_s16: 
197
 
 
198
 
                
199
 
        pushl %ebp
200
 
        movl %esp, %ebp
201
 
        push %ebx
202
 
        push %esi
203
 
        push %edi
204
 
 
205
 
        movl 8(%ebp),  %ebx     # pixel array offset
206
 
        movl 12(%ebp), %ecx     # nb of 4x4 pixblocks
207
 
        movl 16(%ebp), %edx     # line with
208
 
 
209
 
        movl 20(%ebp), %esi     # coefs
210
 
        movl 24(%ebp), %edi     # state
211
 
 
212
 
        shll $1, %edx           # short int addressing  
213
 
        movl %edx, %eax
214
 
        shll $1, %eax
215
 
        addl %edx, %eax         # eax = 3 * edx
216
 
        
217
 
        .align 16
218
 
        .biquad_vertb_line_loop:
219
 
        movq (%ebx), %mm0       
220
 
        movq (%ebx,%edx,1), %mm1        
221
 
        movq (%ebx,%edx,2), %mm2        
222
 
        movq (%ebx,%eax,1), %mm3
223
 
        biquad_4x4_pixels
224
 
        movq %mm0, (%ebx)       
225
 
        movq %mm1, (%ebx,%edx,1)        
226
 
        movq %mm2, (%ebx,%edx,2)        
227
 
        movq %mm3, (%ebx,%eax,1)
228
 
        addl %edx, %ebx
229
 
        addl %eax, %ebx
230
 
        decl %ecx
231
 
        jnz .biquad_vertb_line_loop
232
 
                
233
 
        emms
234
 
        
235
 
        pop %edi
236
 
        pop %esi
237
 
        pop %ebx
238
 
        leave
239
 
        ret
240
 
.globl pixel_biquad_verbt_s16
241
 
.type  pixel_biquad_verbt_s16,@function
242
 
 
243
 
 
244
 
# pixel_biquad_vertbt_s16(char *pixel_array, int nb_rows, int linewidth, short int coef[20], short int state[8])
245
 
 
246
 
        
247
 
pixel_biquad_verbt_s16: 
248
 
 
249
 
                
250
 
        pushl %ebp
251
 
        movl %esp, %ebp
252
 
        push %ebx
253
 
        push %esi
254
 
        push %edi
255
 
 
256
 
        movl 8(%ebp),  %ebx     # pixel array offset
257
 
        movl 12(%ebp), %ecx     # nb of 4x4 pixblocks
258
 
        movl 16(%ebp), %eax     # line with
259
 
 
260
 
        shll $3, %eax           # 4 line byte spacing
261
 
        decl %ecx
262
 
        mul %ecx
263
 
        incl %ecx
264
 
        addl %eax, %ebx         # ebx points to last pixblock
265
 
 
266
 
        movl 16(%ebp), %edx     # line with
267
 
 
268
 
        movl 20(%ebp), %esi     # coefs
269
 
        movl 24(%ebp), %edi     # state
270
 
 
271
 
        shll $1, %edx           # short int addressing  
272
 
        movl %edx, %eax
273
 
        shll $1, %eax
274
 
        addl %edx, %eax         # eax = 3 * edx
275
 
        
276
 
        .align 16
277
 
        .biquad_verbt_line_loop:
278
 
        movq (%ebx), %mm3       
279
 
        movq (%ebx,%edx,1), %mm2        
280
 
        movq (%ebx,%edx,2), %mm1        
281
 
        movq (%ebx,%eax,1), %mm0
282
 
        biquad_4x4_pixels
283
 
        movq %mm3, (%ebx)       
284
 
        movq %mm2, (%ebx,%edx,1)        
285
 
        movq %mm1, (%ebx,%edx,2)        
286
 
        movq %mm0, (%ebx,%eax,1)
287
 
        subl %edx, %ebx
288
 
        subl %eax, %ebx
289
 
        decl %ecx
290
 
        jnz .biquad_verbt_line_loop
291
 
                
292
 
        emms
293
 
        
294
 
        pop %edi
295
 
        pop %esi
296
 
        pop %ebx
297
 
        leave
298
 
        ret
299
 
 
300
 
.globl pixel_biquad_horlr_s16
301
 
.type  pixel_biquad_horlr_s16,@function
302
 
# pixel_biquad_hor_s16(char *pixel_array, int nb_rows, int linewidth, short int coef[20], short int state[8])
303
 
 
304
 
pixel_biquad_horlr_s16: 
305
 
 
306
 
                
307
 
        pushl %ebp
308
 
        movl %esp, %ebp
309
 
        push %ebx
310
 
        push %esi
311
 
        push %edi
312
 
 
313
 
        movl 8(%ebp),  %ebx     # pixel array offset
314
 
        movl 12(%ebp), %ecx     # nb of 4x4 pixblocks
315
 
        movl 16(%ebp), %edx     # line with
316
 
 
317
 
        movl 20(%ebp), %esi     # coefs
318
 
        movl 24(%ebp), %edi     # state
319
 
 
320
 
        shll $1, %edx           # short int addressing
321
 
        movl %edx, %eax
322
 
        shll $1, %eax
323
 
        addl %edx, %eax         # eax = 3 * edx
324
 
        
325
 
        .align 16
326
 
        .biquad_horlr_line_loop:
327
 
        movq (%ebx), %mm0       
328
 
        movq (%ebx,%edx,1), %mm1        
329
 
        movq (%ebx,%edx,2), %mm2        
330
 
        movq (%ebx,%eax,1), %mm3
331
 
        transpose_4x4   
332
 
        biquad_4x4_pixels
333
 
        transpose_4x4   
334
 
        movq %mm0, (%ebx)       
335
 
        movq %mm1, (%ebx,%edx,1)        
336
 
        movq %mm2, (%ebx,%edx,2)        
337
 
        movq %mm3, (%ebx,%eax,1)
338
 
        addl $8, %ebx
339
 
        decl %ecx
340
 
        jnz .biquad_horlr_line_loop
341
 
                
342
 
        emms
343
 
        
344
 
        pop %edi
345
 
        pop %esi
346
 
        pop %ebx
347
 
        leave
348
 
        ret
349
 
 
350
 
 
351
 
.globl pixel_biquad_horrl_s16
352
 
.type  pixel_biquad_horrl_s16,@function
353
 
# pixel_biquad_horrl_s16(char *pixel_array, int nb_rows, int linewidth, short int coef[20], short int state[8])
354
 
 
355
 
pixel_biquad_horrl_s16: 
356
 
 
357
 
        pushl %ebp
358
 
        movl %esp, %ebp
359
 
        push %ebx
360
 
        push %esi
361
 
        push %edi
362
 
 
363
 
        movl 8(%ebp),  %ebx     # pixel array offset
364
 
        movl 12(%ebp), %ecx     # nb of 4x4 pixblocks
365
 
        movl 16(%ebp), %edx     # line with
366
 
 
367
 
 
368
 
        movl %ecx, %eax
369
 
        decl %eax
370
 
        shll $3, %eax
371
 
        addl %eax, %ebx         # ebx points to last pixblock
372
 
 
373
 
        
374
 
        movl 20(%ebp), %esi     # coefs
375
 
        movl 24(%ebp), %edi     # state
376
 
 
377
 
        shll $1, %edx           # short int addressing
378
 
        movl %edx, %eax
379
 
        shll $1, %eax
380
 
        addl %edx, %eax         # eax = 3 * edx
381
 
        
382
 
        .align 16
383
 
        .biquad_horrl_line_loop:
384
 
        movq (%ebx), %mm0       
385
 
        movq (%ebx,%edx,1), %mm1        
386
 
        movq (%ebx,%edx,2), %mm2        
387
 
        movq (%ebx,%eax,1), %mm3
388
 
        antitranspose_4x4       
389
 
        biquad_4x4_pixels
390
 
        antitranspose_4x4       
391
 
        movq %mm0, (%ebx)       
392
 
        movq %mm1, (%ebx,%edx,1)        
393
 
        movq %mm2, (%ebx,%edx,2)        
394
 
        movq %mm3, (%ebx,%eax,1)
395
 
        subl $8, %ebx
396
 
        decl %ecx
397
 
        jnz .biquad_horrl_line_loop
398
 
                
399
 
        emms
400
 
        
401
 
        pop %edi
402
 
        pop %esi
403
 
        pop %ebx
404
 
        leave
405
 
        ret
406
 
 
407
 
 
408
 
.globl pixel_biquad_time_s16
409
 
.type  pixel_biquad_time_s16,@function
410
 
# pixel_biquad_time_s16(short int *pixel_array, short int *s1, short int *s2, short int *coefs, int nb_4_pix_vectors)
411
 
 
412
 
pixel_biquad_time_s16: 
413
 
 
414
 
        pushl %ebp
415
 
        movl %esp, %ebp
416
 
        push %ebx
417
 
        push %esi
418
 
        push %edi
419
 
 
420
 
        movl 8(%ebp),  %ebx     # pixel array offset
421
 
        movl 12(%ebp), %edx     # state 1 array
422
 
        movl 16(%ebp), %edi     # state 2 array
423
 
 
424
 
        movl 20(%ebp), %esi     # coefs
425
 
        movl 24(%ebp), %ecx     # nb of 4 pixel vectors
426
 
 
427
 
 
428
 
        .align 16
429
 
        .biquad_time_loop:
430
 
        movq (%ebx), %mm0       # get input
431
 
        movq (%edx), %mm4       # get state 1
432
 
        movq (%edi), %mm5       # get state 2
433
 
        df2 %mm0                # compute direct form 2
434
 
        movq %mm0, (%ebx)       # write output
435
 
        movq %mm5, (%edi)       # write state 2
436
 
        movq %mm4, (%edx)       # write state 1
437
 
        addl $8, %ebx
438
 
        addl $8, %edi
439
 
        addl $8, %edx
440
 
        decl %ecx
441
 
        jnz .biquad_time_loop
442
 
                
443
 
        emms
444
 
        
445
 
        pop %edi
446
 
        pop %esi
447
 
        pop %ebx
448
 
        leave
449
 
        ret
450
 
 
451