gst Factor out endian-order RGB formats
[platform/upstream/gst-plugins-good.git] / gst / goom / filters_mmx.s
1 ; Goom Project
2 ; Copyright (C) <2001> Jean-Christophe Hoelt <jeko@free.fr>
3 ;
4 ; This library is free software; you can redistribute it and/or
5 ; modify it under the terms of the GNU Library General Public
6 ; License as published by the Free Software Foundation; either
7 ; version 2 of the License, or (at your option) any later version.
8 ;
9 ; This library 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 GNU
12 ; Library General Public License for more details.
13 ;
14 ; You should have received a copy of the GNU Library General Public
15 ; License along with this library; if not, write to the
16 ; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 ; Boston, MA 02110-1301, USA.
18 ;
19 ;//
20 ;// history
21 ;// 07/01/2001 : Changing FEMMS to EMMS : slower... but run on intel machines
22 ;//     03/01/2001 : WIDTH and HEIGHT are now variable
23 ;//     28/12/2000 : adding comments to the code, suppress some useless lines
24 ;//     27/12/2000 : reducing memory access... improving performance by 20%
25 ;//             coefficients are now on 1 byte
26 ;//     22/12/2000 : Changing data structure
27 ;//     16/12/2000 : AT&T version
28 ;//     14/12/2000 : unrolling loop
29 ;//     12/12/2000 : 64 bits memory access
30
31
32 .data
33
34 chaine:
35         .string "pos = %d\n\0"
36         .long 0x0
37                 
38 thezero:
39         .long 0x00000000
40         .long 0x00000000
41
42 .text
43
44 .globl mmx_zoom         ;// name of the function to call by C program
45 /* .extern coeffs               ;// the transformation buffer */
46 .extern expix1,expix2 ;// the source and destination buffer
47 .extern mmx_zoom_size, zoom_width ;// size of the buffers
48
49 .extern brutS,brutD,buffratio,precalCoef,prevX,prevY
50
51 #define PERTEMASK 15
52 /* faire : a / sqrtperte <=> a >> PERTEDEC*/
53 #define PERTEDEC 4
54
55 .align 16
56 mmx_zoom:
57
58                 pushl %ebp
59                 movl %esp,%ebp
60                 subl $12,%esp
61
62                 movl prevX,%eax
63                 decl %eax
64                 sarl $4,%eax
65                 movl %eax,-4(%ebp)
66
67                 movl prevY,%eax
68                 decl %eax
69                 sarl $4,%eax
70                 movl %eax,-8(%ebp)
71
72 ;// initialisation du mm7 � zero
73                 movq (thezero), %mm7
74
75 movl mmx_zoom_size, %ecx
76 decl %ecx
77
78 .while:
79         ;// esi <- nouvelle position
80         movl brutS, %eax
81         leal (%eax, %ecx, 8),%eax
82
83         movl (%eax),%edx /* = brutS.px (brutSmypos) */
84         movl 4(%eax),%eax /* = brutS.py */
85
86         movl brutD,%ebx
87         leal (%ebx, %ecx, 8),%ebx
88         movl (%ebx),%esi
89         subl %edx, %esi
90         imull buffratio,%esi
91         sarl $16,%esi
92         addl %edx,%esi /* esi = px */
93
94         /* eax contient deja brutS.py = le nouveau brutSmypos*/
95         /* ebx pointe sur brutD[myPos] */
96         movl 4(%ebx),%edi
97         subl %eax,%edi
98         imull buffratio,%edi
99         sarl $16,%edi
100         addl %eax,%edi /* edi = py */
101
102 /*              pushl %eax
103                 pushl %ebx*/
104 /*              popl %ebx
105                 popl %eax*/
106                 
107         movl %esi,%eax
108         andl $15,%eax /* eax = coefh */
109         movl %edi,%ebx
110         andl $15,%ebx /* ebx = coefv */
111
112         leal 0(,%ebx,4),%ebx
113         sall $6,%eax
114         addl %ebx,%eax
115         movl $precalCoef,%ebx
116 /*      movd (%eax,%ebx),%mm6*/ /* mm6 = coeffs */
117
118         cmpl -8(%ebp),%edi
119         jge .then1
120         cmpl -4(%ebp),%esi
121         jge .then1
122
123         sarl $4,%esi
124         sarl $4,%edi
125         imull zoom_width,%edi
126         leal (%esi,%edi),%esi
127         jmp .finsi1
128
129 .then1:
130         movl $0,%esi
131 .finsi1:
132
133         /** apres ce calcul, %esi = pos, %mm6 = coeffs **/
134 /*      pushl %esi
135         pushl $chaine
136         call printf
137         addl $8,%esp*/
138
139         movl expix1,%eax
140
141         ;// recuperation des deux premiers pixels dans mm0 et mm1
142 /*      movq (%eax,%esi,4), %mm0                /* b1-v1-r1-a1-b2-v2-r2-a2 */
143         movq %mm0, %mm1                         /* b1-v1-r1-a1-b2-v2-r2-a2 */
144
145         ;// depackage du premier pixel
146         punpcklbw %mm7, %mm0    /* 00-b2-00-v2-00-r2-00-a2 */
147
148         movq %mm6, %mm5                 /* ??-??-??-??-c4-c3-c2-c1 */
149         ;// depackage du 2ieme pixel
150         punpckhbw %mm7, %mm1    /* 00-b1-00-v1-00-r1-00-a1 */
151
152         ;// extraction des coefficients...
153         punpcklbw %mm5, %mm6    /* c4-c4-c3-c3-c2-c2-c1-c1 */
154         movq %mm6, %mm4                 /* c4-c4-c3-c3-c2-c2-c1-c1 */
155         movq %mm6, %mm5                 /* c4-c4-c3-c3-c2-c2-c1-c1 */
156
157         punpcklbw %mm5, %mm6    /* c2-c2-c2-c2-c1-c1-c1-c1 */
158         punpckhbw %mm5, %mm4    /* c4-c4-c4-c4-c3-c3-c3-c3 */
159
160         movq %mm6, %mm3                 /* c2-c2-c2-c2-c1-c1-c1-c1 */
161         punpcklbw %mm7, %mm6    /* 00-c1-00-c1-00-c1-00-c1 */
162         punpckhbw %mm7, %mm3    /* 00-c2-00-c2-00-c2-00-c2 */
163         
164         ;// multiplication des pixels par les coefficients
165         pmullw %mm6, %mm0               /* c1*b2-c1*v2-c1*r2-c1*a2 */
166         pmullw %mm3, %mm1               /* c2*b1-c2*v1-c2*r1-c2*a1 */
167         paddw %mm1, %mm0
168         
169         ;// ...extraction des 2 derniers coefficients
170         movq %mm4, %mm5                 /* c4-c4-c4-c4-c3-c3-c3-c3 */
171         punpcklbw %mm7, %mm4    /* 00-c3-00-c3-00-c3-00-c3 */
172         punpckhbw %mm7, %mm5    /* 00-c4-00-c4-00-c4-00-c4 */
173
174         /* ajouter la longueur de ligne a esi */
175         addl prevX,%esi
176                 
177         ;// recuperation des 2 derniers pixels
178 /*      movq (%eax,%esi,4), %mm1*/
179         movq %mm1, %mm2
180         
181         ;// depackage des pixels
182         punpcklbw %mm7, %mm1
183         punpckhbw %mm7, %mm2
184         
185         ;// multiplication pas les coeffs
186         pmullw %mm4, %mm1
187         pmullw %mm5, %mm2
188         
189         ;// ajout des valeurs obtenues � la valeur finale
190         paddw %mm1, %mm0
191         paddw %mm2, %mm0
192
193         ;// division par 256 = 16+16+16+16, puis repackage du pixel final
194         psrlw $8, %mm0
195         packuswb %mm7, %mm0
196         
197         ;// passage au suivant
198
199         ;// enregistrement du resultat
200         movl expix2,%eax
201 /*      movd %mm0,(%eax,%ecx,4)*/
202
203         decl %ecx
204         ;// test de fin du tantque
205         cmpl $0, %ecx                           ;// 400x300
206
207         jz .fin_while
208         jmp .while
209
210 .fin_while:
211         emms
212
213         movl %ebp,%esp
214         popl %ebp
215
216         ret                  ;//The End