00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "libavutil/cpu.h"
00022 #include "libavutil/x86/asm.h"
00023 #include "libavutil/x86/cpu.h"
00024 #include "libavcodec/h264dsp.h"
00025 #include "dsputil_mmx.h"
00026
00027
00028
00029 #define IDCT_ADD_FUNC(NUM, DEPTH, OPT) \
00030 void ff_h264_idct ## NUM ## _add_ ## DEPTH ## _ ## OPT(uint8_t *dst, \
00031 int16_t *block, \
00032 int stride);
00033
00034 IDCT_ADD_FUNC(, 8, mmx)
00035 IDCT_ADD_FUNC(, 10, sse2)
00036 IDCT_ADD_FUNC(_dc, 8, mmxext)
00037 IDCT_ADD_FUNC(_dc, 10, mmxext)
00038 IDCT_ADD_FUNC(8_dc, 8, mmxext)
00039 IDCT_ADD_FUNC(8_dc, 10, sse2)
00040 IDCT_ADD_FUNC(8, 8, mmx)
00041 IDCT_ADD_FUNC(8, 8, sse2)
00042 IDCT_ADD_FUNC(8, 10, sse2)
00043 IDCT_ADD_FUNC(, 10, avx)
00044 IDCT_ADD_FUNC(8_dc, 10, avx)
00045 IDCT_ADD_FUNC(8, 10, avx)
00046
00047
00048 #define IDCT_ADD_REP_FUNC(NUM, REP, DEPTH, OPT) \
00049 void ff_h264_idct ## NUM ## _add ## REP ## _ ## DEPTH ## _ ## OPT \
00050 (uint8_t *dst, const int *block_offset, \
00051 DCTELEM *block, int stride, const uint8_t nnzc[6 * 8]);
00052
00053 IDCT_ADD_REP_FUNC(8, 4, 8, mmx)
00054 IDCT_ADD_REP_FUNC(8, 4, 8, mmxext)
00055 IDCT_ADD_REP_FUNC(8, 4, 8, sse2)
00056 IDCT_ADD_REP_FUNC(8, 4, 10, sse2)
00057 IDCT_ADD_REP_FUNC(8, 4, 10, avx)
00058 IDCT_ADD_REP_FUNC(, 16, 8, mmx)
00059 IDCT_ADD_REP_FUNC(, 16, 8, mmxext)
00060 IDCT_ADD_REP_FUNC(, 16, 8, sse2)
00061 IDCT_ADD_REP_FUNC(, 16, 10, sse2)
00062 IDCT_ADD_REP_FUNC(, 16intra, 8, mmx)
00063 IDCT_ADD_REP_FUNC(, 16intra, 8, mmxext)
00064 IDCT_ADD_REP_FUNC(, 16intra, 8, sse2)
00065 IDCT_ADD_REP_FUNC(, 16intra, 10, sse2)
00066 IDCT_ADD_REP_FUNC(, 16, 10, avx)
00067 IDCT_ADD_REP_FUNC(, 16intra, 10, avx)
00068
00069
00070 #define IDCT_ADD_REP_FUNC2(NUM, REP, DEPTH, OPT) \
00071 void ff_h264_idct ## NUM ## _add ## REP ## _ ## DEPTH ## _ ## OPT \
00072 (uint8_t **dst, const int *block_offset, \
00073 DCTELEM *block, int stride, const uint8_t nnzc[6 * 8]);
00074
00075 IDCT_ADD_REP_FUNC2(, 8, 8, mmx)
00076 IDCT_ADD_REP_FUNC2(, 8, 8, mmxext)
00077 IDCT_ADD_REP_FUNC2(, 8, 8, sse2)
00078 IDCT_ADD_REP_FUNC2(, 8, 10, sse2)
00079 IDCT_ADD_REP_FUNC2(, 8, 10, avx)
00080
00081 void ff_h264_luma_dc_dequant_idct_mmx(DCTELEM *output, DCTELEM *input, int qmul);
00082 void ff_h264_luma_dc_dequant_idct_sse2(DCTELEM *output, DCTELEM *input, int qmul);
00083
00084
00085
00086
00087 void ff_h264_loop_filter_strength_mmxext(int16_t bS[2][4][4], uint8_t nnz[40],
00088 int8_t ref[2][40],
00089 int16_t mv[2][40][2],
00090 int bidir, int edges, int step,
00091 int mask_mv0, int mask_mv1, int field);
00092
00093 #define LF_FUNC(DIR, TYPE, DEPTH, OPT) \
00094 void ff_deblock_ ## DIR ## _ ## TYPE ## _ ## DEPTH ## _ ## OPT(uint8_t *pix, \
00095 int stride, \
00096 int alpha, \
00097 int beta, \
00098 int8_t *tc0);
00099 #define LF_IFUNC(DIR, TYPE, DEPTH, OPT) \
00100 void ff_deblock_ ## DIR ## _ ## TYPE ## _ ## DEPTH ## _ ## OPT(uint8_t *pix, \
00101 int stride, \
00102 int alpha, \
00103 int beta);
00104
00105 #define LF_FUNCS(type, depth) \
00106 LF_FUNC(h, chroma, depth, mmxext) \
00107 LF_IFUNC(h, chroma_intra, depth, mmxext) \
00108 LF_FUNC(v, chroma, depth, mmxext) \
00109 LF_IFUNC(v, chroma_intra, depth, mmxext) \
00110 LF_FUNC(h, luma, depth, mmxext) \
00111 LF_IFUNC(h, luma_intra, depth, mmxext) \
00112 LF_FUNC(h, luma, depth, sse2) \
00113 LF_IFUNC(h, luma_intra, depth, sse2) \
00114 LF_FUNC(v, luma, depth, sse2) \
00115 LF_IFUNC(v, luma_intra, depth, sse2) \
00116 LF_FUNC(h, chroma, depth, sse2) \
00117 LF_IFUNC(h, chroma_intra, depth, sse2) \
00118 LF_FUNC(v, chroma, depth, sse2) \
00119 LF_IFUNC(v, chroma_intra, depth, sse2) \
00120 LF_FUNC(h, luma, depth, avx) \
00121 LF_IFUNC(h, luma_intra, depth, avx) \
00122 LF_FUNC(v, luma, depth, avx) \
00123 LF_IFUNC(v, luma_intra, depth, avx) \
00124 LF_FUNC(h, chroma, depth, avx) \
00125 LF_IFUNC(h, chroma_intra, depth, avx) \
00126 LF_FUNC(v, chroma, depth, avx) \
00127 LF_IFUNC(v, chroma_intra, depth, avx)
00128
00129 LF_FUNCS(uint8_t, 8)
00130 LF_FUNCS(uint16_t, 10)
00131
00132 #if ARCH_X86_32 && HAVE_MMXEXT_EXTERNAL
00133 LF_FUNC(v8, luma, 8, mmxext)
00134 static void ff_deblock_v_luma_8_mmxext(uint8_t *pix, int stride, int alpha,
00135 int beta, int8_t *tc0)
00136 {
00137 if ((tc0[0] & tc0[1]) >= 0)
00138 ff_deblock_v8_luma_8_mmxext(pix + 0, stride, alpha, beta, tc0);
00139 if ((tc0[2] & tc0[3]) >= 0)
00140 ff_deblock_v8_luma_8_mmxext(pix + 8, stride, alpha, beta, tc0 + 2);
00141 }
00142 LF_IFUNC(v8, luma_intra, 8, mmxext)
00143 static void ff_deblock_v_luma_intra_8_mmxext(uint8_t *pix, int stride,
00144 int alpha, int beta)
00145 {
00146 ff_deblock_v8_luma_intra_8_mmxext(pix + 0, stride, alpha, beta);
00147 ff_deblock_v8_luma_intra_8_mmxext(pix + 8, stride, alpha, beta);
00148 }
00149 #endif
00150
00151 LF_FUNC(v, luma, 10, mmxext)
00152 LF_IFUNC(v, luma_intra, 10, mmxext)
00153
00154
00155
00156
00157 #define H264_WEIGHT(W, OPT) \
00158 void ff_h264_weight_ ## W ## _ ## OPT(uint8_t *dst, int stride, \
00159 int height, int log2_denom, \
00160 int weight, int offset);
00161
00162 #define H264_BIWEIGHT(W, OPT) \
00163 void ff_h264_biweight_ ## W ## _ ## OPT(uint8_t *dst, uint8_t *src, \
00164 int stride, int height, \
00165 int log2_denom, int weightd, \
00166 int weights, int offset);
00167
00168 #define H264_BIWEIGHT_MMX(W) \
00169 H264_WEIGHT(W, mmxext) \
00170 H264_BIWEIGHT(W, mmxext)
00171
00172 #define H264_BIWEIGHT_MMX_SSE(W) \
00173 H264_BIWEIGHT_MMX(W) \
00174 H264_WEIGHT(W, sse2) \
00175 H264_BIWEIGHT(W, sse2) \
00176 H264_BIWEIGHT(W, ssse3)
00177
00178 H264_BIWEIGHT_MMX_SSE(16)
00179 H264_BIWEIGHT_MMX_SSE(8)
00180 H264_BIWEIGHT_MMX(4)
00181
00182 #define H264_WEIGHT_10(W, DEPTH, OPT) \
00183 void ff_h264_weight_ ## W ## _ ## DEPTH ## _ ## OPT(uint8_t *dst, \
00184 int stride, \
00185 int height, \
00186 int log2_denom, \
00187 int weight, \
00188 int offset);
00189
00190 #define H264_BIWEIGHT_10(W, DEPTH, OPT) \
00191 void ff_h264_biweight_ ## W ## _ ## DEPTH ## _ ## OPT(uint8_t *dst, \
00192 uint8_t *src, \
00193 int stride, \
00194 int height, \
00195 int log2_denom, \
00196 int weightd, \
00197 int weights, \
00198 int offset);
00199
00200 #define H264_BIWEIGHT_10_SSE(W, DEPTH) \
00201 H264_WEIGHT_10(W, DEPTH, sse2) \
00202 H264_WEIGHT_10(W, DEPTH, sse4) \
00203 H264_BIWEIGHT_10(W, DEPTH, sse2) \
00204 H264_BIWEIGHT_10(W, DEPTH, sse4)
00205
00206 H264_BIWEIGHT_10_SSE(16, 10)
00207 H264_BIWEIGHT_10_SSE(8, 10)
00208 H264_BIWEIGHT_10_SSE(4, 10)
00209
00210 void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth,
00211 const int chroma_format_idc)
00212 {
00213 #if HAVE_YASM
00214 int mm_flags = av_get_cpu_flags();
00215
00216 if (chroma_format_idc == 1 && EXTERNAL_MMXEXT(mm_flags))
00217 c->h264_loop_filter_strength = ff_h264_loop_filter_strength_mmxext;
00218
00219 if (bit_depth == 8) {
00220 if (EXTERNAL_MMX(mm_flags)) {
00221 c->h264_idct_dc_add =
00222 c->h264_idct_add = ff_h264_idct_add_8_mmx;
00223 c->h264_idct8_dc_add =
00224 c->h264_idct8_add = ff_h264_idct8_add_8_mmx;
00225
00226 c->h264_idct_add16 = ff_h264_idct_add16_8_mmx;
00227 c->h264_idct8_add4 = ff_h264_idct8_add4_8_mmx;
00228 if (chroma_format_idc == 1)
00229 c->h264_idct_add8 = ff_h264_idct_add8_8_mmx;
00230 c->h264_idct_add16intra = ff_h264_idct_add16intra_8_mmx;
00231 if (mm_flags & AV_CPU_FLAG_CMOV)
00232 c->h264_luma_dc_dequant_idct = ff_h264_luma_dc_dequant_idct_mmx;
00233
00234 if (EXTERNAL_MMXEXT(mm_flags)) {
00235 c->h264_idct_dc_add = ff_h264_idct_dc_add_8_mmxext;
00236 c->h264_idct8_dc_add = ff_h264_idct8_dc_add_8_mmxext;
00237 c->h264_idct_add16 = ff_h264_idct_add16_8_mmxext;
00238 c->h264_idct8_add4 = ff_h264_idct8_add4_8_mmxext;
00239 if (chroma_format_idc == 1)
00240 c->h264_idct_add8 = ff_h264_idct_add8_8_mmxext;
00241 c->h264_idct_add16intra = ff_h264_idct_add16intra_8_mmxext;
00242
00243 c->h264_v_loop_filter_chroma = ff_deblock_v_chroma_8_mmxext;
00244 c->h264_v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_8_mmxext;
00245 if (chroma_format_idc == 1) {
00246 c->h264_h_loop_filter_chroma = ff_deblock_h_chroma_8_mmxext;
00247 c->h264_h_loop_filter_chroma_intra = ff_deblock_h_chroma_intra_8_mmxext;
00248 }
00249 #if ARCH_X86_32 && HAVE_MMXEXT_EXTERNAL
00250 c->h264_v_loop_filter_luma = ff_deblock_v_luma_8_mmxext;
00251 c->h264_h_loop_filter_luma = ff_deblock_h_luma_8_mmxext;
00252 c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_mmxext;
00253 c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_mmxext;
00254 #endif
00255 c->weight_h264_pixels_tab[0] = ff_h264_weight_16_mmxext;
00256 c->weight_h264_pixels_tab[1] = ff_h264_weight_8_mmxext;
00257 c->weight_h264_pixels_tab[2] = ff_h264_weight_4_mmxext;
00258
00259 c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16_mmxext;
00260 c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_mmxext;
00261 c->biweight_h264_pixels_tab[2] = ff_h264_biweight_4_mmxext;
00262
00263 if (EXTERNAL_SSE2(mm_flags)) {
00264 c->h264_idct8_add = ff_h264_idct8_add_8_sse2;
00265
00266 c->h264_idct_add16 = ff_h264_idct_add16_8_sse2;
00267 c->h264_idct8_add4 = ff_h264_idct8_add4_8_sse2;
00268 if (chroma_format_idc == 1)
00269 c->h264_idct_add8 = ff_h264_idct_add8_8_sse2;
00270 c->h264_idct_add16intra = ff_h264_idct_add16intra_8_sse2;
00271 c->h264_luma_dc_dequant_idct = ff_h264_luma_dc_dequant_idct_sse2;
00272
00273 c->weight_h264_pixels_tab[0] = ff_h264_weight_16_sse2;
00274 c->weight_h264_pixels_tab[1] = ff_h264_weight_8_sse2;
00275
00276 c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16_sse2;
00277 c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_sse2;
00278
00279 c->h264_v_loop_filter_luma = ff_deblock_v_luma_8_sse2;
00280 c->h264_h_loop_filter_luma = ff_deblock_h_luma_8_sse2;
00281 c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_sse2;
00282 c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_sse2;
00283 }
00284 if (EXTERNAL_SSSE3(mm_flags)) {
00285 c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16_ssse3;
00286 c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_ssse3;
00287 }
00288 if (EXTERNAL_AVX(mm_flags)) {
00289 c->h264_v_loop_filter_luma = ff_deblock_v_luma_8_avx;
00290 c->h264_h_loop_filter_luma = ff_deblock_h_luma_8_avx;
00291 c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_avx;
00292 c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_avx;
00293 }
00294 }
00295 }
00296 } else if (bit_depth == 10) {
00297 if (EXTERNAL_MMX(mm_flags)) {
00298 if (EXTERNAL_MMXEXT(mm_flags)) {
00299 #if ARCH_X86_32
00300 c->h264_v_loop_filter_chroma = ff_deblock_v_chroma_10_mmxext;
00301 c->h264_v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_mmxext;
00302 c->h264_v_loop_filter_luma = ff_deblock_v_luma_10_mmxext;
00303 c->h264_h_loop_filter_luma = ff_deblock_h_luma_10_mmxext;
00304 c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_mmxext;
00305 c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_mmxext;
00306 #endif
00307 c->h264_idct_dc_add = ff_h264_idct_dc_add_10_mmxext;
00308 if (EXTERNAL_SSE2(mm_flags)) {
00309 c->h264_idct_add = ff_h264_idct_add_10_sse2;
00310 c->h264_idct8_dc_add = ff_h264_idct8_dc_add_10_sse2;
00311
00312 c->h264_idct_add16 = ff_h264_idct_add16_10_sse2;
00313 if (chroma_format_idc == 1)
00314 c->h264_idct_add8 = ff_h264_idct_add8_10_sse2;
00315 c->h264_idct_add16intra = ff_h264_idct_add16intra_10_sse2;
00316 #if HAVE_ALIGNED_STACK
00317 c->h264_idct8_add = ff_h264_idct8_add_10_sse2;
00318 c->h264_idct8_add4 = ff_h264_idct8_add4_10_sse2;
00319 #endif
00320
00321 c->weight_h264_pixels_tab[0] = ff_h264_weight_16_10_sse2;
00322 c->weight_h264_pixels_tab[1] = ff_h264_weight_8_10_sse2;
00323 c->weight_h264_pixels_tab[2] = ff_h264_weight_4_10_sse2;
00324
00325 c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16_10_sse2;
00326 c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_10_sse2;
00327 c->biweight_h264_pixels_tab[2] = ff_h264_biweight_4_10_sse2;
00328
00329 c->h264_v_loop_filter_chroma = ff_deblock_v_chroma_10_sse2;
00330 c->h264_v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_sse2;
00331 #if HAVE_ALIGNED_STACK
00332 c->h264_v_loop_filter_luma = ff_deblock_v_luma_10_sse2;
00333 c->h264_h_loop_filter_luma = ff_deblock_h_luma_10_sse2;
00334 c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_sse2;
00335 c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_sse2;
00336 #endif
00337 }
00338 if (EXTERNAL_SSE4(mm_flags)) {
00339 c->weight_h264_pixels_tab[0] = ff_h264_weight_16_10_sse4;
00340 c->weight_h264_pixels_tab[1] = ff_h264_weight_8_10_sse4;
00341 c->weight_h264_pixels_tab[2] = ff_h264_weight_4_10_sse4;
00342
00343 c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16_10_sse4;
00344 c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_10_sse4;
00345 c->biweight_h264_pixels_tab[2] = ff_h264_biweight_4_10_sse4;
00346 }
00347 if (EXTERNAL_AVX(mm_flags)) {
00348 c->h264_idct_dc_add =
00349 c->h264_idct_add = ff_h264_idct_add_10_avx;
00350 c->h264_idct8_dc_add = ff_h264_idct8_dc_add_10_avx;
00351
00352 c->h264_idct_add16 = ff_h264_idct_add16_10_avx;
00353 if (chroma_format_idc == 1)
00354 c->h264_idct_add8 = ff_h264_idct_add8_10_avx;
00355 c->h264_idct_add16intra = ff_h264_idct_add16intra_10_avx;
00356 #if HAVE_ALIGNED_STACK
00357 c->h264_idct8_add = ff_h264_idct8_add_10_avx;
00358 c->h264_idct8_add4 = ff_h264_idct8_add4_10_avx;
00359 #endif
00360
00361 c->h264_v_loop_filter_chroma = ff_deblock_v_chroma_10_avx;
00362 c->h264_v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_avx;
00363 #if HAVE_ALIGNED_STACK
00364 c->h264_v_loop_filter_luma = ff_deblock_v_luma_10_avx;
00365 c->h264_h_loop_filter_luma = ff_deblock_h_luma_10_avx;
00366 c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_avx;
00367 c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_avx;
00368 #endif
00369 }
00370 }
00371 }
00372 }
00373 #endif
00374 }