Mercurial > libavcodec.hg
annotate i386/mpegvideo_mmx_template.c @ 376:ba9c3b8088c0 libavcodec
- pict_type exported to AVCodecContext
- Added real_pict_num to AVCodecContext, it represent the number of the
previous encoded frame, usefull when coding with B frames.
- Warning fix in motion_est.c
author | pulento |
---|---|
date | Sat, 11 May 2002 23:42:16 +0000 |
parents | 6ebbecc10063 |
children | 718a22dc121f |
rev | line source |
---|---|
220 | 1 /* |
2 Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at> | |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 */ | |
18 | |
19 #undef SPREADW | |
20 #undef PMAXW | |
21 #ifdef HAVE_MMX2 | |
22 #define SPREADW(a) "pshufw $0, " #a ", " #a " \n\t" | |
23 #define PMAXW(a,b) "pmaxsw " #a ", " #b " \n\t" | |
24 | |
25 #else | |
26 #define SPREADW(a) \ | |
27 "punpcklwd " #a ", " #a " \n\t"\ | |
28 "punpcklwd " #a ", " #a " \n\t" | |
29 #define PMAXW(a,b) \ | |
30 "psubusw " #a ", " #b " \n\t"\ | |
31 "paddw " #a ", " #b " \n\t" | |
32 #endif | |
33 | |
34 static int RENAME(dct_quantize)(MpegEncContext *s, | |
35 DCTELEM *block, int n, | |
344 | 36 int qscale, int *overflow) |
220 | 37 { |
344 | 38 int level=0, last_non_zero_p1, q; //=0 is cuz gcc says uninitalized ... |
39 const UINT16 *qmat, *bias; | |
220 | 40 static __align8 INT16 temp_block[64]; |
41 | |
42 av_fdct (block); | |
344 | 43 |
220 | 44 if (s->mb_intra) { |
45 int dummy; | |
46 if (n < 4) | |
47 q = s->y_dc_scale; | |
48 else | |
49 q = s->c_dc_scale; | |
50 /* note: block[0] is assumed to be positive */ | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
344
diff
changeset
|
51 if (!s->h263_aic) { |
220 | 52 #if 1 |
344 | 53 asm volatile ( |
54 "xorl %%edx, %%edx \n\t" | |
55 "mul %%ecx \n\t" | |
56 : "=d" (level), "=a"(dummy) | |
57 : "a" (block[0] + (q >> 1)), "c" (inverse[q]) | |
58 ); | |
220 | 59 #else |
344 | 60 asm volatile ( |
61 "xorl %%edx, %%edx \n\t" | |
62 "divw %%cx \n\t" | |
63 "movzwl %%ax, %%eax \n\t" | |
64 : "=a" (level) | |
65 : "a" (block[0] + (q >> 1)), "c" (q) | |
66 : "%edx" | |
67 ); | |
220 | 68 #endif |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
344
diff
changeset
|
69 } else |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
344
diff
changeset
|
70 /* For AIC we skip quant/dequant of INTRADC */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
344
diff
changeset
|
71 level = block[0]; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
344
diff
changeset
|
72 |
344 | 73 block[0]=0; //avoid fake overflow |
220 | 74 // temp_block[0] = (block[0] + (q >> 1)) / q; |
75 last_non_zero_p1 = 1; | |
344 | 76 bias = s->q_intra_matrix16_bias[qscale]; |
77 qmat = s->q_intra_matrix16[qscale]; | |
220 | 78 } else { |
79 last_non_zero_p1 = 0; | |
344 | 80 bias = s->q_inter_matrix16_bias[qscale]; |
81 qmat = s->q_inter_matrix16[qscale]; | |
220 | 82 } |
83 | |
344 | 84 if(s->out_format == FMT_H263){ |
85 | |
86 asm volatile( | |
87 "movd %%eax, %%mm3 \n\t" // last_non_zero_p1 | |
88 SPREADW(%%mm3) | |
89 "pxor %%mm7, %%mm7 \n\t" // 0 | |
90 "pxor %%mm4, %%mm4 \n\t" // 0 | |
91 "movq (%2), %%mm5 \n\t" // qmat[0] | |
92 "pxor %%mm6, %%mm6 \n\t" | |
93 "psubw (%3), %%mm6 \n\t" // -bias[0] | |
94 "movl $-128, %%eax \n\t" | |
95 ".balign 16 \n\t" | |
96 "1: \n\t" | |
97 "pxor %%mm1, %%mm1 \n\t" // 0 | |
98 "movq (%1, %%eax), %%mm0 \n\t" // block[i] | |
99 "pcmpgtw %%mm0, %%mm1 \n\t" // block[i] <= 0 ? 0xFF : 0x00 | |
100 "pxor %%mm1, %%mm0 \n\t" | |
101 "psubw %%mm1, %%mm0 \n\t" // ABS(block[i]) | |
102 "psubusw %%mm6, %%mm0 \n\t" // ABS(block[i]) + bias[0] | |
103 "pmulhw %%mm5, %%mm0 \n\t" // (ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16 | |
104 "por %%mm0, %%mm4 \n\t" | |
105 "pxor %%mm1, %%mm0 \n\t" | |
106 "psubw %%mm1, %%mm0 \n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i]) | |
107 "movq %%mm0, (%5, %%eax) \n\t" | |
108 "pcmpeqw %%mm7, %%mm0 \n\t" // out==0 ? 0xFF : 0x00 | |
109 "movq (%4, %%eax), %%mm1 \n\t" | |
110 "movq %%mm7, (%1, %%eax) \n\t" // 0 | |
111 "pandn %%mm1, %%mm0 \n\t" | |
112 PMAXW(%%mm0, %%mm3) | |
113 "addl $8, %%eax \n\t" | |
114 " js 1b \n\t" | |
115 "movq %%mm3, %%mm0 \n\t" | |
116 "psrlq $32, %%mm3 \n\t" | |
117 PMAXW(%%mm0, %%mm3) | |
118 "movq %%mm3, %%mm0 \n\t" | |
119 "psrlq $16, %%mm3 \n\t" | |
120 PMAXW(%%mm0, %%mm3) | |
121 "movd %%mm3, %%eax \n\t" | |
122 "movzbl %%al, %%eax \n\t" // last_non_zero_p1 | |
123 : "+a" (last_non_zero_p1) | |
124 : "r" (block+64), "r" (qmat), "r" (bias), | |
125 "r" (inv_zigzag_direct16+64), "r" (temp_block+64) | |
126 ); | |
127 // note the asm is split cuz gcc doesnt like that many operands ... | |
128 asm volatile( | |
129 "movd %1, %%mm1 \n\t" // max_qcoeff | |
130 SPREADW(%%mm1) | |
131 "psubusw %%mm1, %%mm4 \n\t" | |
132 "packuswb %%mm4, %%mm4 \n\t" | |
133 "movd %%mm4, %0 \n\t" // *overflow | |
134 : "=g" (*overflow) | |
135 : "g" (s->max_qcoeff) | |
136 ); | |
137 }else{ // FMT_H263 | |
138 asm volatile( | |
139 "movd %%eax, %%mm3 \n\t" // last_non_zero_p1 | |
140 SPREADW(%%mm3) | |
141 "pxor %%mm7, %%mm7 \n\t" // 0 | |
142 "pxor %%mm4, %%mm4 \n\t" // 0 | |
143 "movl $-128, %%eax \n\t" | |
144 ".balign 16 \n\t" | |
145 "1: \n\t" | |
146 "pxor %%mm1, %%mm1 \n\t" // 0 | |
147 "movq (%1, %%eax), %%mm0 \n\t" // block[i] | |
148 "pcmpgtw %%mm0, %%mm1 \n\t" // block[i] <= 0 ? 0xFF : 0x00 | |
149 "pxor %%mm1, %%mm0 \n\t" | |
150 "psubw %%mm1, %%mm0 \n\t" // ABS(block[i]) | |
151 "movq (%3, %%eax), %%mm6 \n\t" // bias[0] | |
152 "paddusw %%mm6, %%mm0 \n\t" // ABS(block[i]) + bias[0] | |
153 "movq (%2, %%eax), %%mm5 \n\t" // qmat[i] | |
154 "pmulhw %%mm5, %%mm0 \n\t" // (ABS(block[i])*qmat[0] + bias[0]*qmat[0])>>16 | |
155 "por %%mm0, %%mm4 \n\t" | |
156 "pxor %%mm1, %%mm0 \n\t" | |
157 "psubw %%mm1, %%mm0 \n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i]) | |
158 "movq %%mm0, (%5, %%eax) \n\t" | |
159 "pcmpeqw %%mm7, %%mm0 \n\t" // out==0 ? 0xFF : 0x00 | |
160 "movq (%4, %%eax), %%mm1 \n\t" | |
161 "movq %%mm7, (%1, %%eax) \n\t" // 0 | |
162 "pandn %%mm1, %%mm0 \n\t" | |
163 PMAXW(%%mm0, %%mm3) | |
164 "addl $8, %%eax \n\t" | |
165 " js 1b \n\t" | |
166 "movq %%mm3, %%mm0 \n\t" | |
167 "psrlq $32, %%mm3 \n\t" | |
168 PMAXW(%%mm0, %%mm3) | |
169 "movq %%mm3, %%mm0 \n\t" | |
170 "psrlq $16, %%mm3 \n\t" | |
171 PMAXW(%%mm0, %%mm3) | |
172 "movd %%mm3, %%eax \n\t" | |
173 "movzbl %%al, %%eax \n\t" // last_non_zero_p1 | |
174 : "+a" (last_non_zero_p1) | |
175 : "r" (block+64), "r" (qmat+64), "r" (bias+64), | |
176 "r" (inv_zigzag_direct16+64), "r" (temp_block+64) | |
177 ); | |
178 // note the asm is split cuz gcc doesnt like that many operands ... | |
179 asm volatile( | |
180 "movd %1, %%mm1 \n\t" // max_qcoeff | |
181 SPREADW(%%mm1) | |
182 "psubusw %%mm1, %%mm4 \n\t" | |
183 "packuswb %%mm4, %%mm4 \n\t" | |
184 "movd %%mm4, %0 \n\t" // *overflow | |
185 : "=g" (*overflow) | |
186 : "g" (s->max_qcoeff) | |
187 ); | |
188 } | |
189 | |
190 if(s->mb_intra) temp_block[0]= level; //FIXME move afer permute | |
220 | 191 // last_non_zero_p1=64; |
192 /* permute for IDCT */ | |
193 asm volatile( | |
344 | 194 "movl %0, %%eax \n\t" |
220 | 195 "pushl %%ebp \n\t" |
196 "movl %%esp, " MANGLE(esp_temp) "\n\t" | |
197 "1: \n\t" | |
198 "movzbl (%1, %%eax), %%ebx \n\t" | |
199 "movzbl 1(%1, %%eax), %%ebp \n\t" | |
200 "movw (%2, %%ebx, 2), %%cx \n\t" | |
201 "movw (%2, %%ebp, 2), %%sp \n\t" | |
202 "movzbl " MANGLE(permutation) "(%%ebx), %%ebx\n\t" | |
203 "movzbl " MANGLE(permutation) "(%%ebp), %%ebp\n\t" | |
204 "movw %%cx, (%3, %%ebx, 2) \n\t" | |
205 "movw %%sp, (%3, %%ebp, 2) \n\t" | |
206 "addl $2, %%eax \n\t" | |
207 " js 1b \n\t" | |
208 "movl " MANGLE(esp_temp) ", %%esp\n\t" | |
209 "popl %%ebp \n\t" | |
210 : | |
211 : "g" (-last_non_zero_p1), "d" (zigzag_direct_noperm+last_non_zero_p1), "S" (temp_block), "D" (block) | |
212 : "%eax", "%ebx", "%ecx" | |
213 ); | |
214 /* | |
215 for(i=0; i<last_non_zero_p1; i++) | |
216 { | |
217 int j= zigzag_direct_noperm[i]; | |
218 block[block_permute_op(j)]= temp_block[j]; | |
219 } | |
220 */ | |
221 //block_permute(block); | |
344 | 222 |
220 | 223 return last_non_zero_p1 - 1; |
224 } |