00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #undef MMREG_WIDTH
00024 #undef MM
00025 #undef MOVQ
00026 #undef SPREADW
00027 #undef PMAXW
00028 #undef PMAX
00029 #undef SAVE_SIGN
00030 #undef RESTORE_SIGN
00031
00032 #if HAVE_SSE2
00033 #define MMREG_WIDTH "16"
00034 #define MM "%%xmm"
00035 #define MOVQ "movdqa"
00036 #define SPREADW(a) \
00037 "pshuflw $0, "a", "a" \n\t"\
00038 "punpcklwd "a", "a" \n\t"
00039 #define PMAXW(a,b) "pmaxsw "a", "b" \n\t"
00040 #define PMAX(a,b) \
00041 "movhlps "a", "b" \n\t"\
00042 PMAXW(b, a)\
00043 "pshuflw $0x0E, "a", "b" \n\t"\
00044 PMAXW(b, a)\
00045 "pshuflw $0x01, "a", "b" \n\t"\
00046 PMAXW(b, a)
00047 #else
00048 #define MMREG_WIDTH "8"
00049 #define MM "%%mm"
00050 #define MOVQ "movq"
00051 #if HAVE_MMX2
00052 #define SPREADW(a) "pshufw $0, "a", "a" \n\t"
00053 #define PMAXW(a,b) "pmaxsw "a", "b" \n\t"
00054 #define PMAX(a,b) \
00055 "pshufw $0x0E, "a", "b" \n\t"\
00056 PMAXW(b, a)\
00057 "pshufw $0x01, "a", "b" \n\t"\
00058 PMAXW(b, a)
00059 #else
00060 #define SPREADW(a) \
00061 "punpcklwd "a", "a" \n\t"\
00062 "punpcklwd "a", "a" \n\t"
00063 #define PMAXW(a,b) \
00064 "psubusw "a", "b" \n\t"\
00065 "paddw "a", "b" \n\t"
00066 #define PMAX(a,b) \
00067 "movq "a", "b" \n\t"\
00068 "psrlq $32, "a" \n\t"\
00069 PMAXW(b, a)\
00070 "movq "a", "b" \n\t"\
00071 "psrlq $16, "a" \n\t"\
00072 PMAXW(b, a)
00073
00074 #endif
00075 #endif
00076
00077 #if HAVE_SSSE3
00078 #define SAVE_SIGN(a,b) \
00079 "movdqa "b", "a" \n\t"\
00080 "pabsw "b", "b" \n\t"
00081 #define RESTORE_SIGN(a,b) \
00082 "psignw "a", "b" \n\t"
00083 #else
00084 #define SAVE_SIGN(a,b) \
00085 "pxor "a", "a" \n\t"\
00086 "pcmpgtw "b", "a" \n\t" \
00087 "pxor "a", "b" \n\t"\
00088 "psubw "a", "b" \n\t"
00089 #define RESTORE_SIGN(a,b) \
00090 "pxor "a", "b" \n\t"\
00091 "psubw "a", "b" \n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
00092 #endif
00093
00094 static int RENAME(dct_quantize)(MpegEncContext *s,
00095 DCTELEM *block, int n,
00096 int qscale, int *overflow)
00097 {
00098 x86_reg last_non_zero_p1;
00099 int level=0, q;
00100 const uint16_t *qmat, *bias;
00101 LOCAL_ALIGNED_16(int16_t, temp_block, [64]);
00102
00103 assert((7&(int)(&temp_block[0])) == 0);
00104
00105
00106 RENAMEl(ff_fdct) (block);
00107
00108 if(s->dct_error_sum)
00109 s->denoise_dct(s, block);
00110
00111 if (s->mb_intra) {
00112 int dummy;
00113 if (n < 4){
00114 q = s->y_dc_scale;
00115 bias = s->q_intra_matrix16[qscale][1];
00116 qmat = s->q_intra_matrix16[qscale][0];
00117 }else{
00118 q = s->c_dc_scale;
00119 bias = s->q_chroma_intra_matrix16[qscale][1];
00120 qmat = s->q_chroma_intra_matrix16[qscale][0];
00121 }
00122
00123 if (!s->h263_aic) {
00124 __asm__ volatile (
00125 "mul %%ecx \n\t"
00126 : "=d" (level), "=a"(dummy)
00127 : "a" ((block[0]>>2) + q), "c" (ff_inverse[q<<1])
00128 );
00129 } else
00130
00131 level = (block[0] + 4)>>3;
00132
00133 block[0]=0;
00134
00135 last_non_zero_p1 = 1;
00136 } else {
00137 last_non_zero_p1 = 0;
00138 bias = s->q_inter_matrix16[qscale][1];
00139 qmat = s->q_inter_matrix16[qscale][0];
00140 }
00141
00142 if((s->out_format == FMT_H263 || s->out_format == FMT_H261) && s->mpeg_quant==0){
00143
00144 __asm__ volatile(
00145 "movd %%"REG_a", "MM"3 \n\t"
00146 SPREADW(MM"3")
00147 "pxor "MM"7, "MM"7 \n\t"
00148 "pxor "MM"4, "MM"4 \n\t"
00149 MOVQ" (%2), "MM"5 \n\t"
00150 "pxor "MM"6, "MM"6 \n\t"
00151 "psubw (%3), "MM"6 \n\t"
00152 "mov $-128, %%"REG_a" \n\t"
00153 ".p2align 4 \n\t"
00154 "1: \n\t"
00155 MOVQ" (%1, %%"REG_a"), "MM"0 \n\t"
00156 SAVE_SIGN(MM"1", MM"0")
00157 "psubusw "MM"6, "MM"0 \n\t"
00158 "pmulhw "MM"5, "MM"0 \n\t"
00159 "por "MM"0, "MM"4 \n\t"
00160 RESTORE_SIGN(MM"1", MM"0")
00161 MOVQ" "MM"0, (%5, %%"REG_a") \n\t"
00162 "pcmpeqw "MM"7, "MM"0 \n\t"
00163 MOVQ" (%4, %%"REG_a"), "MM"1 \n\t"
00164 MOVQ" "MM"7, (%1, %%"REG_a") \n\t"
00165 "pandn "MM"1, "MM"0 \n\t"
00166 PMAXW(MM"0", MM"3")
00167 "add $"MMREG_WIDTH", %%"REG_a" \n\t"
00168 " js 1b \n\t"
00169 PMAX(MM"3", MM"0")
00170 "movd "MM"3, %%"REG_a" \n\t"
00171 "movzb %%al, %%"REG_a" \n\t"
00172 : "+a" (last_non_zero_p1)
00173 : "r" (block+64), "r" (qmat), "r" (bias),
00174 "r" (ff_inv_zigzag_direct16+64), "r" (temp_block+64)
00175 XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3",
00176 "%xmm4", "%xmm5", "%xmm6", "%xmm7")
00177 );
00178 }else{
00179 __asm__ volatile(
00180 "movd %%"REG_a", "MM"3 \n\t"
00181 SPREADW(MM"3")
00182 "pxor "MM"7, "MM"7 \n\t"
00183 "pxor "MM"4, "MM"4 \n\t"
00184 "mov $-128, %%"REG_a" \n\t"
00185 ".p2align 4 \n\t"
00186 "1: \n\t"
00187 MOVQ" (%1, %%"REG_a"), "MM"0 \n\t"
00188 SAVE_SIGN(MM"1", MM"0")
00189 MOVQ" (%3, %%"REG_a"), "MM"6 \n\t"
00190 "paddusw "MM"6, "MM"0 \n\t"
00191 MOVQ" (%2, %%"REG_a"), "MM"5 \n\t"
00192 "pmulhw "MM"5, "MM"0 \n\t"
00193 "por "MM"0, "MM"4 \n\t"
00194 RESTORE_SIGN(MM"1", MM"0")
00195 MOVQ" "MM"0, (%5, %%"REG_a") \n\t"
00196 "pcmpeqw "MM"7, "MM"0 \n\t"
00197 MOVQ" (%4, %%"REG_a"), "MM"1 \n\t"
00198 MOVQ" "MM"7, (%1, %%"REG_a") \n\t"
00199 "pandn "MM"1, "MM"0 \n\t"
00200 PMAXW(MM"0", MM"3")
00201 "add $"MMREG_WIDTH", %%"REG_a" \n\t"
00202 " js 1b \n\t"
00203 PMAX(MM"3", MM"0")
00204 "movd "MM"3, %%"REG_a" \n\t"
00205 "movzb %%al, %%"REG_a" \n\t"
00206 : "+a" (last_non_zero_p1)
00207 : "r" (block+64), "r" (qmat+64), "r" (bias+64),
00208 "r" (ff_inv_zigzag_direct16+64), "r" (temp_block+64)
00209 XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3",
00210 "%xmm4", "%xmm5", "%xmm6", "%xmm7")
00211 );
00212 }
00213 __asm__ volatile(
00214 "movd %1, "MM"1 \n\t"
00215 SPREADW(MM"1")
00216 "psubusw "MM"1, "MM"4 \n\t"
00217 "packuswb "MM"4, "MM"4 \n\t"
00218 #if HAVE_SSE2
00219 "packuswb "MM"4, "MM"4 \n\t"
00220 #endif
00221 "movd "MM"4, %0 \n\t"
00222 : "=g" (*overflow)
00223 : "g" (s->max_qcoeff)
00224 );
00225
00226 if(s->mb_intra) block[0]= level;
00227 else block[0]= temp_block[0];
00228
00229 if(s->dsp.idct_permutation_type == FF_SIMPLE_IDCT_PERM){
00230 if(last_non_zero_p1 <= 1) goto end;
00231 block[0x08] = temp_block[0x01]; block[0x10] = temp_block[0x08];
00232 block[0x20] = temp_block[0x10];
00233 if(last_non_zero_p1 <= 4) goto end;
00234 block[0x18] = temp_block[0x09]; block[0x04] = temp_block[0x02];
00235 block[0x09] = temp_block[0x03];
00236 if(last_non_zero_p1 <= 7) goto end;
00237 block[0x14] = temp_block[0x0A]; block[0x28] = temp_block[0x11];
00238 block[0x12] = temp_block[0x18]; block[0x02] = temp_block[0x20];
00239 if(last_non_zero_p1 <= 11) goto end;
00240 block[0x1A] = temp_block[0x19]; block[0x24] = temp_block[0x12];
00241 block[0x19] = temp_block[0x0B]; block[0x01] = temp_block[0x04];
00242 block[0x0C] = temp_block[0x05];
00243 if(last_non_zero_p1 <= 16) goto end;
00244 block[0x11] = temp_block[0x0C]; block[0x29] = temp_block[0x13];
00245 block[0x16] = temp_block[0x1A]; block[0x0A] = temp_block[0x21];
00246 block[0x30] = temp_block[0x28]; block[0x22] = temp_block[0x30];
00247 block[0x38] = temp_block[0x29]; block[0x06] = temp_block[0x22];
00248 if(last_non_zero_p1 <= 24) goto end;
00249 block[0x1B] = temp_block[0x1B]; block[0x21] = temp_block[0x14];
00250 block[0x1C] = temp_block[0x0D]; block[0x05] = temp_block[0x06];
00251 block[0x0D] = temp_block[0x07]; block[0x15] = temp_block[0x0E];
00252 block[0x2C] = temp_block[0x15]; block[0x13] = temp_block[0x1C];
00253 if(last_non_zero_p1 <= 32) goto end;
00254 block[0x0B] = temp_block[0x23]; block[0x34] = temp_block[0x2A];
00255 block[0x2A] = temp_block[0x31]; block[0x32] = temp_block[0x38];
00256 block[0x3A] = temp_block[0x39]; block[0x26] = temp_block[0x32];
00257 block[0x39] = temp_block[0x2B]; block[0x03] = temp_block[0x24];
00258 if(last_non_zero_p1 <= 40) goto end;
00259 block[0x1E] = temp_block[0x1D]; block[0x25] = temp_block[0x16];
00260 block[0x1D] = temp_block[0x0F]; block[0x2D] = temp_block[0x17];
00261 block[0x17] = temp_block[0x1E]; block[0x0E] = temp_block[0x25];
00262 block[0x31] = temp_block[0x2C]; block[0x2B] = temp_block[0x33];
00263 if(last_non_zero_p1 <= 48) goto end;
00264 block[0x36] = temp_block[0x3A]; block[0x3B] = temp_block[0x3B];
00265 block[0x23] = temp_block[0x34]; block[0x3C] = temp_block[0x2D];
00266 block[0x07] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
00267 block[0x0F] = temp_block[0x27]; block[0x35] = temp_block[0x2E];
00268 if(last_non_zero_p1 <= 56) goto end;
00269 block[0x2E] = temp_block[0x35]; block[0x33] = temp_block[0x3C];
00270 block[0x3E] = temp_block[0x3D]; block[0x27] = temp_block[0x36];
00271 block[0x3D] = temp_block[0x2F]; block[0x2F] = temp_block[0x37];
00272 block[0x37] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
00273 }else if(s->dsp.idct_permutation_type == FF_LIBMPEG2_IDCT_PERM){
00274 if(last_non_zero_p1 <= 1) goto end;
00275 block[0x04] = temp_block[0x01];
00276 block[0x08] = temp_block[0x08]; block[0x10] = temp_block[0x10];
00277 if(last_non_zero_p1 <= 4) goto end;
00278 block[0x0C] = temp_block[0x09]; block[0x01] = temp_block[0x02];
00279 block[0x05] = temp_block[0x03];
00280 if(last_non_zero_p1 <= 7) goto end;
00281 block[0x09] = temp_block[0x0A]; block[0x14] = temp_block[0x11];
00282 block[0x18] = temp_block[0x18]; block[0x20] = temp_block[0x20];
00283 if(last_non_zero_p1 <= 11) goto end;
00284 block[0x1C] = temp_block[0x19];
00285 block[0x11] = temp_block[0x12]; block[0x0D] = temp_block[0x0B];
00286 block[0x02] = temp_block[0x04]; block[0x06] = temp_block[0x05];
00287 if(last_non_zero_p1 <= 16) goto end;
00288 block[0x0A] = temp_block[0x0C]; block[0x15] = temp_block[0x13];
00289 block[0x19] = temp_block[0x1A]; block[0x24] = temp_block[0x21];
00290 block[0x28] = temp_block[0x28]; block[0x30] = temp_block[0x30];
00291 block[0x2C] = temp_block[0x29]; block[0x21] = temp_block[0x22];
00292 if(last_non_zero_p1 <= 24) goto end;
00293 block[0x1D] = temp_block[0x1B]; block[0x12] = temp_block[0x14];
00294 block[0x0E] = temp_block[0x0D]; block[0x03] = temp_block[0x06];
00295 block[0x07] = temp_block[0x07]; block[0x0B] = temp_block[0x0E];
00296 block[0x16] = temp_block[0x15]; block[0x1A] = temp_block[0x1C];
00297 if(last_non_zero_p1 <= 32) goto end;
00298 block[0x25] = temp_block[0x23]; block[0x29] = temp_block[0x2A];
00299 block[0x34] = temp_block[0x31]; block[0x38] = temp_block[0x38];
00300 block[0x3C] = temp_block[0x39]; block[0x31] = temp_block[0x32];
00301 block[0x2D] = temp_block[0x2B]; block[0x22] = temp_block[0x24];
00302 if(last_non_zero_p1 <= 40) goto end;
00303 block[0x1E] = temp_block[0x1D]; block[0x13] = temp_block[0x16];
00304 block[0x0F] = temp_block[0x0F]; block[0x17] = temp_block[0x17];
00305 block[0x1B] = temp_block[0x1E]; block[0x26] = temp_block[0x25];
00306 block[0x2A] = temp_block[0x2C]; block[0x35] = temp_block[0x33];
00307 if(last_non_zero_p1 <= 48) goto end;
00308 block[0x39] = temp_block[0x3A]; block[0x3D] = temp_block[0x3B];
00309 block[0x32] = temp_block[0x34]; block[0x2E] = temp_block[0x2D];
00310 block[0x23] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
00311 block[0x27] = temp_block[0x27]; block[0x2B] = temp_block[0x2E];
00312 if(last_non_zero_p1 <= 56) goto end;
00313 block[0x36] = temp_block[0x35]; block[0x3A] = temp_block[0x3C];
00314 block[0x3E] = temp_block[0x3D]; block[0x33] = temp_block[0x36];
00315 block[0x2F] = temp_block[0x2F]; block[0x37] = temp_block[0x37];
00316 block[0x3B] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
00317 }else{
00318 if(last_non_zero_p1 <= 1) goto end;
00319 block[0x01] = temp_block[0x01];
00320 block[0x08] = temp_block[0x08]; block[0x10] = temp_block[0x10];
00321 if(last_non_zero_p1 <= 4) goto end;
00322 block[0x09] = temp_block[0x09]; block[0x02] = temp_block[0x02];
00323 block[0x03] = temp_block[0x03];
00324 if(last_non_zero_p1 <= 7) goto end;
00325 block[0x0A] = temp_block[0x0A]; block[0x11] = temp_block[0x11];
00326 block[0x18] = temp_block[0x18]; block[0x20] = temp_block[0x20];
00327 if(last_non_zero_p1 <= 11) goto end;
00328 block[0x19] = temp_block[0x19];
00329 block[0x12] = temp_block[0x12]; block[0x0B] = temp_block[0x0B];
00330 block[0x04] = temp_block[0x04]; block[0x05] = temp_block[0x05];
00331 if(last_non_zero_p1 <= 16) goto end;
00332 block[0x0C] = temp_block[0x0C]; block[0x13] = temp_block[0x13];
00333 block[0x1A] = temp_block[0x1A]; block[0x21] = temp_block[0x21];
00334 block[0x28] = temp_block[0x28]; block[0x30] = temp_block[0x30];
00335 block[0x29] = temp_block[0x29]; block[0x22] = temp_block[0x22];
00336 if(last_non_zero_p1 <= 24) goto end;
00337 block[0x1B] = temp_block[0x1B]; block[0x14] = temp_block[0x14];
00338 block[0x0D] = temp_block[0x0D]; block[0x06] = temp_block[0x06];
00339 block[0x07] = temp_block[0x07]; block[0x0E] = temp_block[0x0E];
00340 block[0x15] = temp_block[0x15]; block[0x1C] = temp_block[0x1C];
00341 if(last_non_zero_p1 <= 32) goto end;
00342 block[0x23] = temp_block[0x23]; block[0x2A] = temp_block[0x2A];
00343 block[0x31] = temp_block[0x31]; block[0x38] = temp_block[0x38];
00344 block[0x39] = temp_block[0x39]; block[0x32] = temp_block[0x32];
00345 block[0x2B] = temp_block[0x2B]; block[0x24] = temp_block[0x24];
00346 if(last_non_zero_p1 <= 40) goto end;
00347 block[0x1D] = temp_block[0x1D]; block[0x16] = temp_block[0x16];
00348 block[0x0F] = temp_block[0x0F]; block[0x17] = temp_block[0x17];
00349 block[0x1E] = temp_block[0x1E]; block[0x25] = temp_block[0x25];
00350 block[0x2C] = temp_block[0x2C]; block[0x33] = temp_block[0x33];
00351 if(last_non_zero_p1 <= 48) goto end;
00352 block[0x3A] = temp_block[0x3A]; block[0x3B] = temp_block[0x3B];
00353 block[0x34] = temp_block[0x34]; block[0x2D] = temp_block[0x2D];
00354 block[0x26] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
00355 block[0x27] = temp_block[0x27]; block[0x2E] = temp_block[0x2E];
00356 if(last_non_zero_p1 <= 56) goto end;
00357 block[0x35] = temp_block[0x35]; block[0x3C] = temp_block[0x3C];
00358 block[0x3D] = temp_block[0x3D]; block[0x36] = temp_block[0x36];
00359 block[0x2F] = temp_block[0x2F]; block[0x37] = temp_block[0x37];
00360 block[0x3E] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
00361 }
00362 end:
00363
00364
00365
00366
00367
00368
00369
00370
00371 return last_non_zero_p1 - 1;
00372 }