1
# Pure Data Packet mmx routine.
2
# Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
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.
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.
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.
20
# DIRECT FORM II BIQUAD
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]
27
# computes a direct form 2 biquad
28
# does not use {mm0-mm3}\<inreg>
30
# input: <reg> == input
33
# (%esi) == biquad coefs (-a1 -a2 b0 b1 b2) in s1.14
34
# output: <reg> == output
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] --------------------
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)
64
# %mm0-mm4: 4x4 pixels result
69
.macro biquad_4x4_pixels
71
movq 0(%edi), %mm4 # get state
73
df2 %mm0 # compute 4 biquads
77
movq %mm4, 0(%edi) # store state
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
88
# since the 4 lines are independent, it doesnt matter in which order
89
# the the vector elements are present.
91
# this allows us to use the same routine for left->right and right->left
94
# some comments on the non-abelean group of square isometries consisting of
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
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
108
# use antitranspose for right to left an transpose
109
# for left to right (little endian)
115
# %mm3 == {d0 d1 d2 d3}
116
# %mm2 == {c0 c1 c2 c3}
117
# %mm1 == {b0 b1 b2 b3}
118
# %mm0 == {a0 a1 a2 a3}
121
# %mm3 == {a3 b3 c3 d3}
122
# %mm2 == {a2 b2 c2 d2}
123
# %mm1 == {a1 b1 c1 d1}
124
# %mm0 == {a0 b0 c0 d0}
127
.macro antitranspose_4x4:
129
punpcklwd %mm1, %mm4 # mm4 <- {b2 d2 b3 d3}
131
punpckhwd %mm1, %mm5 # mm5 <- {b0 d0 b1 d1}
134
punpcklwd %mm0, %mm6 # mm6 <- {a2 c2 a3 c3}
136
punpckhwd %mm0, %mm7 # mm7 <- {a0 c0 a1 c1}
139
punpcklwd %mm6, %mm3 # mm3 <- {a3 b3 c3 d3}
141
punpckhwd %mm6, %mm2 # mm2 <- {a2 b2 c2 d2}
144
punpcklwd %mm7, %mm1 # mm1 <- {a1 b1 c1 d1}
146
punpckhwd %mm7, %mm0 # mm0 <- {a0 b0 c0 d0}
154
# %mm3 == {d3 d2 d1 d0}
155
# %mm2 == {c3 c2 c1 c0}
156
# %mm1 == {b3 b2 b1 b0}
157
# %mm0 == {a3 a2 a1 a0}
160
# %mm3 == {d3 c3 b3 a3}
161
# %mm2 == {d2 c2 b2 a2}
162
# %mm1 == {d1 c1 b1 a1}
163
# %mm0 == {d0 c0 b0 a0}
166
.macro transpose_4x4:
168
punpcklwd %mm2, %mm4 # mm4 <- {c1 a1 c0 a0}
170
punpckhwd %mm2, %mm5 # mm5 <- {c3 a3 c2 a2}
173
punpcklwd %mm3, %mm6 # mm6 <- {d1 b1 d0 b0}
175
punpckhwd %mm3, %mm7 # mm7 <- {d3 b3 d2 b2}
178
punpcklwd %mm6, %mm0 # mm0 <- {d0 c0 b0 a0}
180
punpckhwd %mm6, %mm1 # mm1 <- {d1 c1 b1 a1}
183
punpcklwd %mm7, %mm2 # mm2 <- {d2 c2 b2 a2}
185
punpckhwd %mm7, %mm3 # mm3 <- {d3 c3 b3 a3}
189
.globl pixel_biquad_vertb_s16
190
.type pixel_biquad_vertb_s16,@function
193
# pixel_biquad_vertbr_s16(char *pixel_array, int nb_rows, int linewidth, short int coef[20], short int state[8])
196
pixel_biquad_vertb_s16:
205
movl 8(%ebp), %ebx # pixel array offset
206
movl 12(%ebp), %ecx # nb of 4x4 pixblocks
207
movl 16(%ebp), %edx # line with
209
movl 20(%ebp), %esi # coefs
210
movl 24(%ebp), %edi # state
212
shll $1, %edx # short int addressing
215
addl %edx, %eax # eax = 3 * edx
218
.biquad_vertb_line_loop:
220
movq (%ebx,%edx,1), %mm1
221
movq (%ebx,%edx,2), %mm2
222
movq (%ebx,%eax,1), %mm3
225
movq %mm1, (%ebx,%edx,1)
226
movq %mm2, (%ebx,%edx,2)
227
movq %mm3, (%ebx,%eax,1)
231
jnz .biquad_vertb_line_loop
240
.globl pixel_biquad_verbt_s16
241
.type pixel_biquad_verbt_s16,@function
244
# pixel_biquad_vertbt_s16(char *pixel_array, int nb_rows, int linewidth, short int coef[20], short int state[8])
247
pixel_biquad_verbt_s16:
256
movl 8(%ebp), %ebx # pixel array offset
257
movl 12(%ebp), %ecx # nb of 4x4 pixblocks
258
movl 16(%ebp), %eax # line with
260
shll $3, %eax # 4 line byte spacing
264
addl %eax, %ebx # ebx points to last pixblock
266
movl 16(%ebp), %edx # line with
268
movl 20(%ebp), %esi # coefs
269
movl 24(%ebp), %edi # state
271
shll $1, %edx # short int addressing
274
addl %edx, %eax # eax = 3 * edx
277
.biquad_verbt_line_loop:
279
movq (%ebx,%edx,1), %mm2
280
movq (%ebx,%edx,2), %mm1
281
movq (%ebx,%eax,1), %mm0
284
movq %mm2, (%ebx,%edx,1)
285
movq %mm1, (%ebx,%edx,2)
286
movq %mm0, (%ebx,%eax,1)
290
jnz .biquad_verbt_line_loop
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])
304
pixel_biquad_horlr_s16:
313
movl 8(%ebp), %ebx # pixel array offset
314
movl 12(%ebp), %ecx # nb of 4x4 pixblocks
315
movl 16(%ebp), %edx # line with
317
movl 20(%ebp), %esi # coefs
318
movl 24(%ebp), %edi # state
320
shll $1, %edx # short int addressing
323
addl %edx, %eax # eax = 3 * edx
326
.biquad_horlr_line_loop:
328
movq (%ebx,%edx,1), %mm1
329
movq (%ebx,%edx,2), %mm2
330
movq (%ebx,%eax,1), %mm3
335
movq %mm1, (%ebx,%edx,1)
336
movq %mm2, (%ebx,%edx,2)
337
movq %mm3, (%ebx,%eax,1)
340
jnz .biquad_horlr_line_loop
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])
355
pixel_biquad_horrl_s16:
363
movl 8(%ebp), %ebx # pixel array offset
364
movl 12(%ebp), %ecx # nb of 4x4 pixblocks
365
movl 16(%ebp), %edx # line with
371
addl %eax, %ebx # ebx points to last pixblock
374
movl 20(%ebp), %esi # coefs
375
movl 24(%ebp), %edi # state
377
shll $1, %edx # short int addressing
380
addl %edx, %eax # eax = 3 * edx
383
.biquad_horrl_line_loop:
385
movq (%ebx,%edx,1), %mm1
386
movq (%ebx,%edx,2), %mm2
387
movq (%ebx,%eax,1), %mm3
392
movq %mm1, (%ebx,%edx,1)
393
movq %mm2, (%ebx,%edx,2)
394
movq %mm3, (%ebx,%eax,1)
397
jnz .biquad_horrl_line_loop
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)
412
pixel_biquad_time_s16:
420
movl 8(%ebp), %ebx # pixel array offset
421
movl 12(%ebp), %edx # state 1 array
422
movl 16(%ebp), %edi # state 2 array
424
movl 20(%ebp), %esi # coefs
425
movl 24(%ebp), %ecx # nb of 4 pixel vectors
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
441
jnz .biquad_time_loop