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, mmx2)
00037 IDCT_ADD_FUNC(_dc, 10, mmx2)
00038 IDCT_ADD_FUNC(8_dc, 8, mmx2)
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, mmx2)
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, mmx2)
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, mmx2)
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, mmx2)
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_mmx2(int16_t bS[2][4][4], uint8_t nnz[40],
00088 int8_t ref[2][40], int16_t mv[2][40][2],
00089 int bidir, int edges, int step,
00090 int mask_mv0, int mask_mv1, int field);
00091
00092 #define LF_FUNC(DIR, TYPE, DEPTH, OPT) \
00093 void ff_deblock_ ## DIR ## _ ## TYPE ## _ ## DEPTH ## _ ## OPT(uint8_t *pix, \
00094 int stride, \
00095 int alpha, \
00096 int beta, \
00097 int8_t *tc0);
00098 #define LF_IFUNC(DIR, TYPE, DEPTH, OPT) \
00099 void ff_deblock_ ## DIR ## _ ## TYPE ## _ ## DEPTH ## _ ## OPT(uint8_t *pix, \
00100 int stride, \
00101 int alpha, \
00102 int beta);
00103
00104 #define LF_FUNCS(type, depth) \
00105 LF_FUNC(h, chroma, depth, mmx2) \
00106 LF_IFUNC(h, chroma_intra, depth, mmx2) \
00107 LF_FUNC(v, chroma, depth, mmx2) \
00108 LF_IFUNC(v, chroma_intra, depth, mmx2) \
00109 LF_FUNC(h, luma, depth, mmx2) \
00110 LF_IFUNC(h, luma_intra, depth, mmx2) \
00111 LF_FUNC(h, luma, depth, sse2) \
00112 LF_IFUNC(h, luma_intra, depth, sse2) \
00113 LF_FUNC(v, luma, depth, sse2) \
00114 LF_IFUNC(v, luma_intra, depth, sse2) \
00115 LF_FUNC(h, chroma, depth, sse2) \
00116 LF_IFUNC(h, chroma_intra, depth, sse2) \
00117 LF_FUNC(v, chroma, depth, sse2) \
00118 LF_IFUNC(v, chroma_intra, depth, sse2) \
00119 LF_FUNC(h, luma, depth, avx) \
00120 LF_IFUNC(h, luma_intra, depth, avx) \
00121 LF_FUNC(v, luma, depth, avx) \
00122 LF_IFUNC(v, luma_intra, depth, avx) \
00123 LF_FUNC(h, chroma, depth, avx) \
00124 LF_IFUNC(h, chroma_intra, depth, avx) \
00125 LF_FUNC(v, chroma, depth, avx) \
00126 LF_IFUNC(v, chroma_intra, depth, avx)
00127
00128 LF_FUNCS(uint8_t, 8)
00129 LF_FUNCS(uint16_t, 10)
00130
00131 #if ARCH_X86_32 && HAVE_YASM
00132 LF_FUNC(v8, luma, 8, mmx2)
00133 static void ff_deblock_v_luma_8_mmx2(uint8_t *pix, int stride, int alpha,
00134 int beta, int8_t *tc0)
00135 {
00136 if ((tc0[0] & tc0[1]) >= 0)
00137 ff_deblock_v8_luma_8_mmx2(pix + 0, stride, alpha, beta, tc0);
00138 if ((tc0[2] & tc0[3]) >= 0)
00139 ff_deblock_v8_luma_8_mmx2(pix + 8, stride, alpha, beta, tc0 + 2);
00140 }
00141
00142 LF_IFUNC(v8, luma_intra, 8, mmx2)
00143 static void ff_deblock_v_luma_intra_8_mmx2(uint8_t *pix, int stride,
00144 int alpha, int beta)
00145 {
00146 ff_deblock_v8_luma_intra_8_mmx2(pix + 0, stride, alpha, beta);
00147 ff_deblock_v8_luma_intra_8_mmx2(pix + 8, stride, alpha, beta);
00148 }
00149 #endif
00150
00151 LF_FUNC(v, luma, 10, mmx2)
00152 LF_IFUNC(v, luma_intra, 10, mmx2)
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, mmx2) \
00170 H264_BIWEIGHT(W, mmx2)
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_mmx2;
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_mmx2;
00236 c->h264_idct8_dc_add = ff_h264_idct8_dc_add_8_mmx2;
00237 c->h264_idct_add16 = ff_h264_idct_add16_8_mmx2;
00238 c->h264_idct8_add4 = ff_h264_idct8_add4_8_mmx2;
00239 if (chroma_format_idc == 1)
00240 c->h264_idct_add8 = ff_h264_idct_add8_8_mmx2;
00241 c->h264_idct_add16intra = ff_h264_idct_add16intra_8_mmx2;
00242
00243 c->h264_v_loop_filter_chroma = ff_deblock_v_chroma_8_mmx2;
00244 c->h264_v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_8_mmx2;
00245 if (chroma_format_idc == 1) {
00246 c->h264_h_loop_filter_chroma = ff_deblock_h_chroma_8_mmx2;
00247 c->h264_h_loop_filter_chroma_intra = ff_deblock_h_chroma_intra_8_mmx2;
00248 }
00249 #if ARCH_X86_32
00250 c->h264_v_loop_filter_luma = ff_deblock_v_luma_8_mmx2;
00251 c->h264_h_loop_filter_luma = ff_deblock_h_luma_8_mmx2;
00252 c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_mmx2;
00253 c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_mmx2;
00254 #endif
00255 c->weight_h264_pixels_tab[0] = ff_h264_weight_16_mmx2;
00256 c->weight_h264_pixels_tab[1] = ff_h264_weight_8_mmx2;
00257 c->weight_h264_pixels_tab[2] = ff_h264_weight_4_mmx2;
00258
00259 c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16_mmx2;
00260 c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_mmx2;
00261 c->biweight_h264_pixels_tab[2] = ff_h264_biweight_4_mmx2;
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 #if HAVE_ALIGNED_STACK
00280 c->h264_v_loop_filter_luma = ff_deblock_v_luma_8_sse2;
00281 c->h264_h_loop_filter_luma = ff_deblock_h_luma_8_sse2;
00282 c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_sse2;
00283 c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_sse2;
00284 #endif
00285 }
00286 if (EXTERNAL_SSSE3(mm_flags)) {
00287 c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16_ssse3;
00288 c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_ssse3;
00289 }
00290 if (EXTERNAL_AVX(mm_flags) && HAVE_ALIGNED_STACK) {
00291 c->h264_v_loop_filter_luma = ff_deblock_v_luma_8_avx;
00292 c->h264_h_loop_filter_luma = ff_deblock_h_luma_8_avx;
00293 c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_avx;
00294 c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_avx;
00295 }
00296 }
00297 }
00298 } else if (bit_depth == 10) {
00299 if (EXTERNAL_MMX(mm_flags)) {
00300 if (EXTERNAL_MMXEXT(mm_flags)) {
00301 #if ARCH_X86_32
00302 c->h264_v_loop_filter_chroma = ff_deblock_v_chroma_10_mmx2;
00303 c->h264_v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_mmx2;
00304 c->h264_v_loop_filter_luma = ff_deblock_v_luma_10_mmx2;
00305 c->h264_h_loop_filter_luma = ff_deblock_h_luma_10_mmx2;
00306 c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_mmx2;
00307 c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_mmx2;
00308 #endif
00309 c->h264_idct_dc_add = ff_h264_idct_dc_add_10_mmx2;
00310 if (EXTERNAL_SSE2(mm_flags)) {
00311 c->h264_idct_add = ff_h264_idct_add_10_sse2;
00312 c->h264_idct8_dc_add = ff_h264_idct8_dc_add_10_sse2;
00313
00314 c->h264_idct_add16 = ff_h264_idct_add16_10_sse2;
00315 if (chroma_format_idc == 1)
00316 c->h264_idct_add8 = ff_h264_idct_add8_10_sse2;
00317 c->h264_idct_add16intra = ff_h264_idct_add16intra_10_sse2;
00318 #if HAVE_ALIGNED_STACK
00319 c->h264_idct8_add = ff_h264_idct8_add_10_sse2;
00320 c->h264_idct8_add4 = ff_h264_idct8_add4_10_sse2;
00321 #endif
00322
00323 c->weight_h264_pixels_tab[0] = ff_h264_weight_16_10_sse2;
00324 c->weight_h264_pixels_tab[1] = ff_h264_weight_8_10_sse2;
00325 c->weight_h264_pixels_tab[2] = ff_h264_weight_4_10_sse2;
00326
00327 c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16_10_sse2;
00328 c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_10_sse2;
00329 c->biweight_h264_pixels_tab[2] = ff_h264_biweight_4_10_sse2;
00330
00331 c->h264_v_loop_filter_chroma = ff_deblock_v_chroma_10_sse2;
00332 c->h264_v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_sse2;
00333 #if HAVE_ALIGNED_STACK
00334 c->h264_v_loop_filter_luma = ff_deblock_v_luma_10_sse2;
00335 c->h264_h_loop_filter_luma = ff_deblock_h_luma_10_sse2;
00336 c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_sse2;
00337 c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_sse2;
00338 #endif
00339 }
00340 if (EXTERNAL_SSE4(mm_flags)) {
00341 c->weight_h264_pixels_tab[0] = ff_h264_weight_16_10_sse4;
00342 c->weight_h264_pixels_tab[1] = ff_h264_weight_8_10_sse4;
00343 c->weight_h264_pixels_tab[2] = ff_h264_weight_4_10_sse4;
00344
00345 c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16_10_sse4;
00346 c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_10_sse4;
00347 c->biweight_h264_pixels_tab[2] = ff_h264_biweight_4_10_sse4;
00348 }
00349 if (EXTERNAL_AVX(mm_flags)) {
00350 c->h264_idct_dc_add =
00351 c->h264_idct_add = ff_h264_idct_add_10_avx;
00352 c->h264_idct8_dc_add = ff_h264_idct8_dc_add_10_avx;
00353
00354 c->h264_idct_add16 = ff_h264_idct_add16_10_avx;
00355 if (chroma_format_idc == 1)
00356 c->h264_idct_add8 = ff_h264_idct_add8_10_avx;
00357 c->h264_idct_add16intra = ff_h264_idct_add16intra_10_avx;
00358 #if HAVE_ALIGNED_STACK
00359 c->h264_idct8_add = ff_h264_idct8_add_10_avx;
00360 c->h264_idct8_add4 = ff_h264_idct8_add4_10_avx;
00361 #endif
00362
00363 c->h264_v_loop_filter_chroma = ff_deblock_v_chroma_10_avx;
00364 c->h264_v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_avx;
00365 #if HAVE_ALIGNED_STACK
00366 c->h264_v_loop_filter_luma = ff_deblock_v_luma_10_avx;
00367 c->h264_h_loop_filter_luma = ff_deblock_h_luma_10_avx;
00368 c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_avx;
00369 c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_avx;
00370 #endif
00371 }
00372 }
00373 }
00374 }
00375 #endif
00376 }