some bugfixes and rescale filter
[melted] / src / modules / gtk2 / scale_line_22_33_mmx.S
1         .file   "scale_line_22_33_mmx.S"
2         .version        "01.01"
3 gcc2_compiled.:
4 .text
5         .align 16
6
7 #if !defined(__MINGW32__) && !defined(__CYGWIN__)       
8         
9 .globl pixops_scale_line_22_33_mmx
10         .type    pixops_scale_line_22_33_mmx,@function
11 pixops_scale_line_22_33_mmx:
12         
13 #else
14         
15 .globl _pixops_scale_line_22_33_mmx
16 _pixops_scale_line_22_33_mmx:
17         
18 #endif
19 /*
20  * Arguments
21  *              
22  * weights:      8(%ebp)
23  * p:           12(%ebp)        %esi
24  * q1:          16(%ebp)        
25  * q2:          20(%ebp)        
26  * xstep:       24(%ebp)        
27  * p_end:       28(%ebp)
28  * xinit:       32(%ebp)
29  *      
30 */
31
32 /*
33  * Function call entry
34  */
35         pushl %ebp
36         movl %esp,%ebp
37         subl $28,%esp
38         pushl %edi
39         pushl %esi
40         pushl %ebx
41 /* Locals:      
42  * int x                      %ebx
43  * int x_scaled             -24(%ebp)
44  */
45
46 /*
47  * Setup
48  */
49 /* Initialize variables */      
50         movl 32(%ebp),%ebx
51         movl 32(%ebp),%edx
52         sarl $16,%edx
53         movl 12(%ebp),%esi
54
55         cmpl 28(%ebp),%esi
56         jnb  .out
57
58 /* For the body of this loop, %mm01, %mm1, %mm2, %mm3 hold the 4 adjoining
59  * points we are interpolating between, as:
60  *
61  *  000000BB00GG00RR
62  */     
63         
64 /* Load initial values into %mm1, %mm3 */
65         leal (%edx,%edx,2),%edx  # Multiply by 3
66
67         movl 16(%ebp),%edi
68         pxor %mm4, %mm4
69         movzbl 2(%edi,%edx),%ecx
70         shll $16,%ecx
71         movzwl (%edi,%edx),%eax
72         orl %eax,%ecx
73         movd %ecx, %mm1
74         punpcklbw %mm4, %mm1
75
76         movl 20(%ebp),%edi
77         movzbl 2(%edi,%edx),%ecx
78         shll $16,%ecx
79         movzwl (%edi,%edx),%eax
80         orl %eax,%ecx
81         movd %ecx, %mm3
82         punpcklbw %mm4, %mm3
83
84         addl $65536,%ebx
85         movl %ebx,%edx
86         sarl $16,%edx
87
88         jmp .newx
89         .p2align 4,,7
90 .loop:
91 /* short *pixel_weights = weights + ((x >> (SCALE_SHIFT - SUBSAMPLE_BITS)) & SUBSAMPLE_MASK) * n_x * n_y
92  *                                             16             4                  0xf            2     2
93  */
94         movl %ebx,%eax
95         andl $0xf000,%eax
96         shrl $7,%eax
97
98 /* At this point, %edi holds weights. Load the 4 weights into %mm4,%mm5,%mm6,%mm7, multiply and
99  * accumulate.
100  */
101         movq (%edi,%eax),%mm4
102         pmullw %mm0,%mm4
103         movq 8(%edi,%eax),%mm5
104         pmullw %mm1,%mm5
105         movq 16(%edi,%eax),%mm6
106         movq 24(%edi,%eax),%mm7
107         pmullw %mm2,%mm6
108         pmullw %mm3,%mm7
109         paddw %mm4, %mm5
110         paddw %mm6, %mm7
111         paddw %mm5, %mm7
112
113 /* %mm7 holds the accumulated sum. Compute (C + 0x80) / 256
114  */
115         pxor %mm4, %mm4
116         movl $8421504, %eax  # 0x00808080
117         movd %eax, %mm6  
118         punpcklbw %mm4, %mm6
119         paddw %mm6, %mm7
120         psrlw $8, %mm7
121
122 /* Pack into %eax and store result
123  */     
124         packuswb %mm7, %mm7
125         movd %mm7, %eax
126         
127         movb %al, (%esi)
128         shrl $8, %eax
129         movw %ax, 1(%esi)
130         addl $3, %esi
131                 
132         cmpl %esi,28(%ebp)
133         je   .out
134
135 /* x += x_step; */
136         addl 24(%ebp),%ebx
137 /* x_scaled = x >> 16; */
138         movl %ebx,%edx
139         sarl $16,%edx
140
141         cmpl %edx,-24(%ebp)
142         je   .loop
143
144 .newx:
145         movl %edx,-24(%ebp)
146 /*
147  * Load the two new values into %mm1, %mm3, move old values into %mm0, %mm2
148  */
149         movq %mm1, %mm0
150         movq %mm3, %mm2
151         
152         leal (%edx,%edx,2),%edx  # Multiply by 3
153
154         movl 16(%ebp),%edi
155         movzbl 2(%edi,%edx),%ecx
156         shll $16,%ecx
157         movzwl (%edi,%edx),%eax
158         orl %eax,%ecx
159         movd %ecx, %mm1
160         punpcklbw %mm4, %mm1
161
162         movl 20(%ebp),%edi
163         movzbl 2(%edi,%edx),%ecx
164         shll $16,%ecx
165         movzwl (%edi,%edx),%eax
166         orl %eax,%ecx
167         movd %ecx, %mm3
168         punpcklbw %mm4, %mm3
169         
170         movl 8(%ebp),%edi
171         
172         jmp .loop
173
174 .out:
175         movl %esi,%eax
176         emms
177         leal -40(%ebp),%esp
178         popl %ebx
179         popl %esi
180         popl %edi
181         movl %ebp,%esp
182         popl %ebp
183         ret