added very preliminary mmx for composite.
[melted] / src / modules / core / composite_line_yuv_mmx.S
1         .file "composite_line_yuv_mmx"
2         .version "01.01"
3         
4 gcc2_compiled.:
5 .data
6
7 .text
8         .align 16
9
10 #if !defined(__MINGW32__) && !defined(__CYGWIN__)
11 .globl composite_line_yuv_mmx
12         .type    composite_line_yuv_mmx,@function
13 composite_line_yuv_mmx:
14 #else
15 .globl _composite_line_yuv_mmx
16 _composite_line_yuv_mmx:
17 #endif
18
19 /*
20  * Arguments
21  *              
22  * dest:             8(%ebp)            %esi
23  * src:         12(%ebp)
24  * width_src:   16(%ebp)        
25  * alpha:       20(%ebp)        
26  * weight:      24(%ebp)        
27  * luma:        28(%ebp)
28  * softness:    32(%ebp)
29  */
30
31 /*
32  * Function call entry
33  */
34         pushl %ebp
35         movl %esp,%ebp
36         subl $28,%esp
37         pushl %edi
38         pushl %esi
39         pushl %ebx
40
41 /* Initialise */
42         movl 8(%ebp), %esi            # get dest
43         movl $0, %edx                     # j = 0
44         
45 .loop:
46
47         movl $0xff, %ecx           # a = 255
48         cmpl $0, 20(%ebp)         # if alpha == NULL
49         je .noalpha
50         movl 20(%ebp), %edi       # a = alpha[ j ]
51         movb (%edi,%edx), %cl
52 .noalpha:
53
54         movl 24(%ebp), %eax       # mix = weight
55         cmpl $0, 28(%ebp)         # if luma == NULL
56         je .noluma
57         movl 28(%ebp), %edi       # mix = ...
58         movl %edx, %ebx
59         #sall $1, %ebx
60         movw (%edi,%ebx), %ax # luma[ j*2 ]
61         cmpw %cx, %ax
62         jl .luma0
63         movl %eax, %ebx
64         addl 32(%ebp), %ebx       # + softness
65         cmpw %bx, %cx
66         jge .luma1
67         /* TODO: linear interpolate between edges eax and ebx */
68         jmp .noluma
69 .luma0:
70         movl $0, %eax
71         jmp .noluma
72 .luma1:
73         movl $0xffff, %eax
74 .noluma:
75         shrl $8, %eax
76
77         movl %edx, %ebx           # edx will be destroyed by mulw
78         mull %ecx                  # mix = mix * a...
79         movl %ebx, %edx           # restore edx
80         shrl $8, %eax             # >>8
81         andl $0xff, %eax
82         
83 /* put alpha and (1-alpha) into mm0 */
84 /* 0 aa 0 1-a 0 aa 0 1-a */
85
86         /* duplicate word */
87         movl %eax, %ecx
88         shll $16, %ecx
89         orl %eax, %ecx
90         
91         movd %ecx, %mm1
92         
93         /* (1 << 16) - mix */
94         movl $0x000000ff, %ecx
95         subl %eax, %ecx
96         andl $0xff, %ecx
97         
98         /* duplicate word */
99         movl %ecx, %eax
100         shll $16, %eax
101         orl %eax, %ecx
102         
103         movd %ecx, %mm0
104         
105         /* unpack words into double words */
106         punpcklwd %mm1, %mm0
107         
108 /* put src yuv and dest yuv into mm1 */
109 /* 0 UVs 0 UVd 0 Ys 0 Yd */
110
111         movl 12(%ebp), %edi       # get src
112         movb (%edi), %cl
113         shll $8, %ecx
114         movb 1(%edi), %al
115         shll $24, %eax
116         orl %eax, %ecx
117         
118         movb (%esi), %al         # get dest
119         orl %eax, %ecx
120         movb 1(%esi), %al
121         shll $16, %eax
122         orl %eax, %ecx
123         
124         movd %ecx, %mm1
125         punpcklbw %mm4, %mm1
126         
127 /* alpha composite */
128         pmaddwd %mm1, %mm0
129         psrld $8, %mm0
130
131 /* store result */
132         movd %mm0, %eax
133         movb %al, (%esi)
134         pextrw $2, %mm0, %eax
135                 movl $128, %eax
136         movb %al, 1(%esi)
137
138 /* for..next */
139         addl $1, %edx             # j++
140         cmpl %edx, 16(%ebp)       # if ( j == width_src )
141         je .out
142         
143         addl $2, %esi
144         addl $2, 12(%ebp)
145         
146         jmp .loop
147
148 .out:
149         emms
150         leal -40(%ebp),%esp
151         popl %ebx
152         popl %esi
153         popl %edi
154         movl %ebp,%esp
155         popl %ebp
156         ret
157
158
159 /********************************************/
160
161 .align 8
162 #if !defined(__MINGW32__) && !defined(__CYGWIN__)       
163 .globl composite_have_mmx
164         .type    composite_have_mmx,@function
165 composite_have_mmx:
166 #else
167 .globl _composite_have_mmx
168 _composite_have_mmx:
169 #endif
170         
171         push    %ebx
172
173 # Check if bit 21 in flags word is writeable
174
175         pushfl  
176         popl    %eax
177         movl    %eax,%ebx
178         xorl    $0x00200000, %eax
179         pushl   %eax
180         popfl
181         pushfl
182         popl    %eax
183
184         cmpl    %eax, %ebx
185
186         je .notfound
187
188 # OK, we have CPUID
189
190         movl    $1, %eax
191         cpuid
192         
193         test    $0x00800000, %edx
194         jz      .notfound
195
196         movl    $1, %eax
197         jmp     .out2
198
199 .notfound:
200         movl    $0, %eax
201 .out2:  
202         popl    %ebx
203         ret