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 DECLARE_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 else
00116 q = s->c_dc_scale;
00117
00118 if (!s->h263_aic) {
00119 __asm__ volatile (
00120 "mul %%ecx \n\t"
00121 : "=d" (level), "=a"(dummy)
00122 : "a" ((block[0]>>2) + q), "c" (ff_inverse[q<<1])
00123 );
00124 } else
00125
00126 level = (block[0] + 4)>>3;
00127
00128 block[0]=0;
00129
00130 last_non_zero_p1 = 1;
00131 bias = s->q_intra_matrix16[qscale][1];
00132 qmat = s->q_intra_matrix16[qscale][0];
00133 } else {
00134 last_non_zero_p1 = 0;
00135 bias = s->q_inter_matrix16[qscale][1];
00136 qmat = s->q_inter_matrix16[qscale][0];
00137 }
00138
00139 if((s->out_format == FMT_H263 || s->out_format == FMT_H261) && s->mpeg_quant==0){
00140
00141 __asm__ volatile(
00142 "movd %%"REG_a", "MM"3 \n\t"
00143 SPREADW(MM"3")
00144 "pxor "MM"7, "MM"7 \n\t"
00145 "pxor "MM"4, "MM"4 \n\t"
00146 MOVQ" (%2), "MM"5 \n\t"
00147 "pxor "MM"6, "MM"6 \n\t"
00148 "psubw (%3), "MM"6 \n\t"
00149 "mov $-128, %%"REG_a" \n\t"
00150 ".p2align 4 \n\t"
00151 "1: \n\t"
00152 MOVQ" (%1, %%"REG_a"), "MM"0 \n\t"
00153 SAVE_SIGN(MM"1", MM"0")
00154 "psubusw "MM"6, "MM"0 \n\t"
00155 "pmulhw "MM"5, "MM"0 \n\t"
00156 "por "MM"0, "MM"4 \n\t"
00157 RESTORE_SIGN(MM"1", MM"0")
00158 MOVQ" "MM"0, (%5, %%"REG_a") \n\t"
00159 "pcmpeqw "MM"7, "MM"0 \n\t"
00160 MOVQ" (%4, %%"REG_a"), "MM"1 \n\t"
00161 MOVQ" "MM"7, (%1, %%"REG_a") \n\t"
00162 "pandn "MM"1, "MM"0 \n\t"
00163 PMAXW(MM"0", MM"3")
00164 "add $"MMREG_WIDTH", %%"REG_a" \n\t"
00165 " js 1b \n\t"
00166 PMAX(MM"3", MM"0")
00167 "movd "MM"3, %%"REG_a" \n\t"
00168 "movzb %%al, %%"REG_a" \n\t"
00169 : "+a" (last_non_zero_p1)
00170 : "r" (block+64), "r" (qmat), "r" (bias),
00171 "r" (inv_zigzag_direct16+64), "r" (temp_block+64)
00172 XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3",
00173 "%xmm4", "%xmm5", "%xmm6", "%xmm7")
00174 );
00175 }else{
00176 __asm__ volatile(
00177 "movd %%"REG_a", "MM"3 \n\t"
00178 SPREADW(MM"3")
00179 "pxor "MM"7, "MM"7 \n\t"
00180 "pxor "MM"4, "MM"4 \n\t"
00181 "mov $-128, %%"REG_a" \n\t"
00182 ".p2align 4 \n\t"
00183 "1: \n\t"
00184 MOVQ" (%1, %%"REG_a"), "MM"0 \n\t"
00185 SAVE_SIGN(MM"1", MM"0")
00186 MOVQ" (%3, %%"REG_a"), "MM"6 \n\t"
00187 "paddusw "MM"6, "MM"0 \n\t"
00188 MOVQ" (%2, %%"REG_a"), "MM"5 \n\t"
00189 "pmulhw "MM"5, "MM"0 \n\t"
00190 "por "MM"0, "MM"4 \n\t"
00191 RESTORE_SIGN(MM"1", MM"0")
00192 MOVQ" "MM"0, (%5, %%"REG_a") \n\t"
00193 "pcmpeqw "MM"7, "MM"0 \n\t"
00194 MOVQ" (%4, %%"REG_a"), "MM"1 \n\t"
00195 MOVQ" "MM"7, (%1, %%"REG_a") \n\t"
00196 "pandn "MM"1, "MM"0 \n\t"
00197 PMAXW(MM"0", MM"3")
00198 "add $"MMREG_WIDTH", %%"REG_a" \n\t"
00199 " js 1b \n\t"
00200 PMAX(MM"3", MM"0")
00201 "movd "MM"3, %%"REG_a" \n\t"
00202 "movzb %%al, %%"REG_a" \n\t"
00203 : "+a" (last_non_zero_p1)
00204 : "r" (block+64), "r" (qmat+64), "r" (bias+64),
00205 "r" (inv_zigzag_direct16+64), "r" (temp_block+64)
00206 XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3",
00207 "%xmm4", "%xmm5", "%xmm6", "%xmm7")
00208 );
00209 }
00210 __asm__ volatile(
00211 "movd %1, "MM"1 \n\t"
00212 SPREADW(MM"1")
00213 "psubusw "MM"1, "MM"4 \n\t"
00214 "packuswb "MM"4, "MM"4 \n\t"
00215 #if HAVE_SSE2
00216 "packuswb "MM"4, "MM"4 \n\t"
00217 #endif
00218 "movd "MM"4, %0 \n\t"
00219 : "=g" (*overflow)
00220 : "g" (s->max_qcoeff)
00221 );
00222
00223 if(s->mb_intra) block[0]= level;
00224 else block[0]= temp_block[0];
00225
00226 if(s->dsp.idct_permutation_type == FF_SIMPLE_IDCT_PERM){
00227 if(last_non_zero_p1 <= 1) goto end;
00228 block[0x08] = temp_block[0x01]; block[0x10] = temp_block[0x08];
00229 block[0x20] = temp_block[0x10];
00230 if(last_non_zero_p1 <= 4) goto end;
00231 block[0x18] = temp_block[0x09]; block[0x04] = temp_block[0x02];
00232 block[0x09] = temp_block[0x03];
00233 if(last_non_zero_p1 <= 7) goto end;
00234 block[0x14] = temp_block[0x0A]; block[0x28] = temp_block[0x11];
00235 block[0x12] = temp_block[0x18]; block[0x02] = temp_block[0x20];
00236 if(last_non_zero_p1 <= 11) goto end;
00237 block[0x1A] = temp_block[0x19]; block[0x24] = temp_block[0x12];
00238 block[0x19] = temp_block[0x0B]; block[0x01] = temp_block[0x04];
00239 block[0x0C] = temp_block[0x05];
00240 if(last_non_zero_p1 <= 16) goto end;
00241 block[0x11] = temp_block[0x0C]; block[0x29] = temp_block[0x13];
00242 block[0x16] = temp_block[0x1A]; block[0x0A] = temp_block[0x21];
00243 block[0x30] = temp_block[0x28]; block[0x22] = temp_block[0x30];
00244 block[0x38] = temp_block[0x29]; block[0x06] = temp_block[0x22];
00245 if(last_non_zero_p1 <= 24) goto end;
00246 block[0x1B] = temp_block[0x1B]; block[0x21] = temp_block[0x14];
00247 block[0x1C] = temp_block[0x0D]; block[0x05] = temp_block[0x06];
00248 block[0x0D] = temp_block[0x07]; block[0x15] = temp_block[0x0E];
00249 block[0x2C] = temp_block[0x15]; block[0x13] = temp_block[0x1C];
00250 if(last_non_zero_p1 <= 32) goto end;
00251 block[0x0B] = temp_block[0x23]; block[0x34] = temp_block[0x2A];
00252 block[0x2A] = temp_block[0x31]; block[0x32] = temp_block[0x38];
00253 block[0x3A] = temp_block[0x39]; block[0x26] = temp_block[0x32];
00254 block[0x39] = temp_block[0x2B]; block[0x03] = temp_block[0x24];
00255 if(last_non_zero_p1 <= 40) goto end;
00256 block[0x1E] = temp_block[0x1D]; block[0x25] = temp_block[0x16];
00257 block[0x1D] = temp_block[0x0F]; block[0x2D] = temp_block[0x17];
00258 block[0x17] = temp_block[0x1E]; block[0x0E] = temp_block[0x25];
00259 block[0x31] = temp_block[0x2C]; block[0x2B] = temp_block[0x33];
00260 if(last_non_zero_p1 <= 48) goto end;
00261 block[0x36] = temp_block[0x3A]; block[0x3B] = temp_block[0x3B];
00262 block[0x23] = temp_block[0x34]; block[0x3C] = temp_block[0x2D];
00263 block[0x07] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
00264 block[0x0F] = temp_block[0x27]; block[0x35] = temp_block[0x2E];
00265 if(last_non_zero_p1 <= 56) goto end;
00266 block[0x2E] = temp_block[0x35]; block[0x33] = temp_block[0x3C];
00267 block[0x3E] = temp_block[0x3D]; block[0x27] = temp_block[0x36];
00268 block[0x3D] = temp_block[0x2F]; block[0x2F] = temp_block[0x37];
00269 block[0x37] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
00270 }else if(s->dsp.idct_permutation_type == FF_LIBMPEG2_IDCT_PERM){
00271 if(last_non_zero_p1 <= 1) goto end;
00272 block[0x04] = temp_block[0x01];
00273 block[0x08] = temp_block[0x08]; block[0x10] = temp_block[0x10];
00274 if(last_non_zero_p1 <= 4) goto end;
00275 block[0x0C] = temp_block[0x09]; block[0x01] = temp_block[0x02];
00276 block[0x05] = temp_block[0x03];
00277 if(last_non_zero_p1 <= 7) goto end;
00278 block[0x09] = temp_block[0x0A]; block[0x14] = temp_block[0x11];
00279 block[0x18] = temp_block[0x18]; block[0x20] = temp_block[0x20];
00280 if(last_non_zero_p1 <= 11) goto end;
00281 block[0x1C] = temp_block[0x19];
00282 block[0x11] = temp_block[0x12]; block[0x0D] = temp_block[0x0B];
00283 block[0x02] = temp_block[0x04]; block[0x06] = temp_block[0x05];
00284 if(last_non_zero_p1 <= 16) goto end;
00285 block[0x0A] = temp_block[0x0C]; block[0x15] = temp_block[0x13];
00286 block[0x19] = temp_block[0x1A]; block[0x24] = temp_block[0x21];
00287 block[0x28] = temp_block[0x28]; block[0x30] = temp_block[0x30];
00288 block[0x2C] = temp_block[0x29]; block[0x21] = temp_block[0x22];
00289 if(last_non_zero_p1 <= 24) goto end;
00290 block[0x1D] = temp_block[0x1B]; block[0x12] = temp_block[0x14];
00291 block[0x0E] = temp_block[0x0D]; block[0x03] = temp_block[0x06];
00292 block[0x07] = temp_block[0x07]; block[0x0B] = temp_block[0x0E];
00293 block[0x16] = temp_block[0x15]; block[0x1A] = temp_block[0x1C];
00294 if(last_non_zero_p1 <= 32) goto end;
00295 block[0x25] = temp_block[0x23]; block[0x29] = temp_block[0x2A];
00296 block[0x34] = temp_block[0x31]; block[0x38] = temp_block[0x38];
00297 block[0x3C] = temp_block[0x39]; block[0x31] = temp_block[0x32];
00298 block[0x2D] = temp_block[0x2B]; block[0x22] = temp_block[0x24];
00299 if(last_non_zero_p1 <= 40) goto end;
00300 block[0x1E] = temp_block[0x1D]; block[0x13] = temp_block[0x16];
00301 block[0x0F] = temp_block[0x0F]; block[0x17] = temp_block[0x17];
00302 block[0x1B] = temp_block[0x1E]; block[0x26] = temp_block[0x25];
00303 block[0x2A] = temp_block[0x2C]; block[0x35] = temp_block[0x33];
00304 if(last_non_zero_p1 <= 48) goto end;
00305 block[0x39] = temp_block[0x3A]; block[0x3D] = temp_block[0x3B];
00306 block[0x32] = temp_block[0x34]; block[0x2E] = temp_block[0x2D];
00307 block[0x23] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
00308 block[0x27] = temp_block[0x27]; block[0x2B] = temp_block[0x2E];
00309 if(last_non_zero_p1 <= 56) goto end;
00310 block[0x36] = temp_block[0x35]; block[0x3A] = temp_block[0x3C];
00311 block[0x3E] = temp_block[0x3D]; block[0x33] = temp_block[0x36];
00312 block[0x2F] = temp_block[0x2F]; block[0x37] = temp_block[0x37];
00313 block[0x3B] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
00314 }else{
00315 if(last_non_zero_p1 <= 1) goto end;
00316 block[0x01] = temp_block[0x01];
00317 block[0x08] = temp_block[0x08]; block[0x10] = temp_block[0x10];
00318 if(last_non_zero_p1 <= 4) goto end;
00319 block[0x09] = temp_block[0x09]; block[0x02] = temp_block[0x02];
00320 block[0x03] = temp_block[0x03];
00321 if(last_non_zero_p1 <= 7) goto end;
00322 block[0x0A] = temp_block[0x0A]; block[0x11] = temp_block[0x11];
00323 block[0x18] = temp_block[0x18]; block[0x20] = temp_block[0x20];
00324 if(last_non_zero_p1 <= 11) goto end;
00325 block[0x19] = temp_block[0x19];
00326 block[0x12] = temp_block[0x12]; block[0x0B] = temp_block[0x0B];
00327 block[0x04] = temp_block[0x04]; block[0x05] = temp_block[0x05];
00328 if(last_non_zero_p1 <= 16) goto end;
00329 block[0x0C] = temp_block[0x0C]; block[0x13] = temp_block[0x13];
00330 block[0x1A] = temp_block[0x1A]; block[0x21] = temp_block[0x21];
00331 block[0x28] = temp_block[0x28]; block[0x30] = temp_block[0x30];
00332 block[0x29] = temp_block[0x29]; block[0x22] = temp_block[0x22];
00333 if(last_non_zero_p1 <= 24) goto end;
00334 block[0x1B] = temp_block[0x1B]; block[0x14] = temp_block[0x14];
00335 block[0x0D] = temp_block[0x0D]; block[0x06] = temp_block[0x06];
00336 block[0x07] = temp_block[0x07]; block[0x0E] = temp_block[0x0E];
00337 block[0x15] = temp_block[0x15]; block[0x1C] = temp_block[0x1C];
00338 if(last_non_zero_p1 <= 32) goto end;
00339 block[0x23] = temp_block[0x23]; block[0x2A] = temp_block[0x2A];
00340 block[0x31] = temp_block[0x31]; block[0x38] = temp_block[0x38];
00341 block[0x39] = temp_block[0x39]; block[0x32] = temp_block[0x32];
00342 block[0x2B] = temp_block[0x2B]; block[0x24] = temp_block[0x24];
00343 if(last_non_zero_p1 <= 40) goto end;
00344 block[0x1D] = temp_block[0x1D]; block[0x16] = temp_block[0x16];
00345 block[0x0F] = temp_block[0x0F]; block[0x17] = temp_block[0x17];
00346 block[0x1E] = temp_block[0x1E]; block[0x25] = temp_block[0x25];
00347 block[0x2C] = temp_block[0x2C]; block[0x33] = temp_block[0x33];
00348 if(last_non_zero_p1 <= 48) goto end;
00349 block[0x3A] = temp_block[0x3A]; block[0x3B] = temp_block[0x3B];
00350 block[0x34] = temp_block[0x34]; block[0x2D] = temp_block[0x2D];
00351 block[0x26] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
00352 block[0x27] = temp_block[0x27]; block[0x2E] = temp_block[0x2E];
00353 if(last_non_zero_p1 <= 56) goto end;
00354 block[0x35] = temp_block[0x35]; block[0x3C] = temp_block[0x3C];
00355 block[0x3D] = temp_block[0x3D]; block[0x36] = temp_block[0x36];
00356 block[0x2F] = temp_block[0x2F]; block[0x37] = temp_block[0x37];
00357 block[0x3E] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
00358 }
00359 end:
00360
00361
00362
00363
00364
00365
00366
00367
00368 return last_non_zero_p1 - 1;
00369 }