You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

554 lines
22KB

  1. /*
  2. * DSP utils
  3. * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of Libav.
  7. *
  8. * Libav is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * Libav is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with Libav; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * DSP utils.
  25. * note, many functions in here may use MMX which trashes the FPU state, it is
  26. * absolutely necessary to call emms_c() between dsp & float/double code
  27. */
  28. #ifndef AVCODEC_DSPUTIL_H
  29. #define AVCODEC_DSPUTIL_H
  30. #include "libavutil/intreadwrite.h"
  31. #include "avcodec.h"
  32. //#define DEBUG
  33. /* dct code */
  34. void ff_fdct_ifast(int16_t *data);
  35. void ff_fdct_ifast248(int16_t *data);
  36. void ff_jpeg_fdct_islow_8(int16_t *data);
  37. void ff_jpeg_fdct_islow_10(int16_t *data);
  38. void ff_fdct248_islow_8(int16_t *data);
  39. void ff_fdct248_islow_10(int16_t *data);
  40. void ff_j_rev_dct(int16_t *data);
  41. void ff_fdct_mmx(int16_t *block);
  42. void ff_fdct_mmxext(int16_t *block);
  43. void ff_fdct_sse2(int16_t *block);
  44. #define H264_IDCT(depth) \
  45. void ff_h264_idct8_add_ ## depth ## _c(uint8_t *dst, int16_t *block, int stride);\
  46. void ff_h264_idct_add_ ## depth ## _c(uint8_t *dst, int16_t *block, int stride);\
  47. void ff_h264_idct8_dc_add_ ## depth ## _c(uint8_t *dst, int16_t *block, int stride);\
  48. void ff_h264_idct_dc_add_ ## depth ## _c(uint8_t *dst, int16_t *block, int stride);\
  49. void ff_h264_idct_add16_ ## depth ## _c(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[6*8]);\
  50. void ff_h264_idct_add16intra_ ## depth ## _c(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[6*8]);\
  51. void ff_h264_idct8_add4_ ## depth ## _c(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[6*8]);\
  52. void ff_h264_idct_add8_422_ ## depth ## _c(uint8_t **dest, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[6*8]);\
  53. void ff_h264_idct_add8_ ## depth ## _c(uint8_t **dest, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[6*8]);\
  54. void ff_h264_luma_dc_dequant_idct_ ## depth ## _c(int16_t *output, int16_t *input, int qmul);\
  55. void ff_h264_chroma422_dc_dequant_idct_ ## depth ## _c(int16_t *block, int qmul);\
  56. void ff_h264_chroma_dc_dequant_idct_ ## depth ## _c(int16_t *block, int qmul);
  57. H264_IDCT( 8)
  58. H264_IDCT( 9)
  59. H264_IDCT(10)
  60. void ff_svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp);
  61. void ff_svq3_add_idct_c(uint8_t *dst, int16_t *block, int stride, int qp, int dc);
  62. /* encoding scans */
  63. extern const uint8_t ff_alternate_horizontal_scan[64];
  64. extern const uint8_t ff_alternate_vertical_scan[64];
  65. extern const uint8_t ff_zigzag_direct[64];
  66. extern const uint8_t ff_zigzag248_direct[64];
  67. /* pixel operations */
  68. #define MAX_NEG_CROP 1024
  69. /* temporary */
  70. extern uint32_t ff_squareTbl[512];
  71. extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP];
  72. #define PUTAVG_PIXELS(depth)\
  73. void ff_put_pixels8x8_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);\
  74. void ff_avg_pixels8x8_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);\
  75. void ff_put_pixels16x16_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);\
  76. void ff_avg_pixels16x16_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);
  77. PUTAVG_PIXELS( 8)
  78. PUTAVG_PIXELS( 9)
  79. PUTAVG_PIXELS(10)
  80. #define ff_put_pixels8x8_c ff_put_pixels8x8_8_c
  81. #define ff_avg_pixels8x8_c ff_avg_pixels8x8_8_c
  82. #define ff_put_pixels16x16_c ff_put_pixels16x16_8_c
  83. #define ff_avg_pixels16x16_c ff_avg_pixels16x16_8_c
  84. /* RV40 functions */
  85. void ff_put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride);
  86. void ff_avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride);
  87. void ff_put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride);
  88. void ff_avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride);
  89. /* 1/2^n downscaling functions from imgconvert.c */
  90. void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
  91. void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
  92. void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
  93. void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  94. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
  95. /* minimum alignment rules ;)
  96. If you notice errors in the align stuff, need more alignment for some ASM code
  97. for some CPU or need to use a function with less aligned data then send a mail
  98. to the libav-devel mailing list, ...
  99. !warning These alignments might not match reality, (missing attribute((align))
  100. stuff somewhere possible).
  101. I (Michael) did not check them, these are just the alignments which I think
  102. could be reached easily ...
  103. !future video codecs might need functions with less strict alignment
  104. */
  105. /*
  106. void get_pixels_c(int16_t *block, const uint8_t *pixels, int line_size);
  107. void diff_pixels_c(int16_t *block, const uint8_t *s1, const uint8_t *s2, int stride);
  108. void put_pixels_clamped_c(const int16_t *block, uint8_t *pixels, int line_size);
  109. void add_pixels_clamped_c(const int16_t *block, uint8_t *pixels, int line_size);
  110. void clear_blocks_c(int16_t *blocks);
  111. */
  112. /* add and put pixel (decoding) */
  113. // blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
  114. //h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller than 4
  115. typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, ptrdiff_t line_size, int h);
  116. typedef void (*tpel_mc_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int w, int h);
  117. typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
  118. typedef void (*op_fill_func)(uint8_t *block/*align width (8 or 16)*/, uint8_t value, int line_size, int h);
  119. #define DEF_OLD_QPEL(name)\
  120. void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
  121. void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
  122. void ff_avg_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
  123. DEF_OLD_QPEL(qpel16_mc11_old_c)
  124. DEF_OLD_QPEL(qpel16_mc31_old_c)
  125. DEF_OLD_QPEL(qpel16_mc12_old_c)
  126. DEF_OLD_QPEL(qpel16_mc32_old_c)
  127. DEF_OLD_QPEL(qpel16_mc13_old_c)
  128. DEF_OLD_QPEL(qpel16_mc33_old_c)
  129. DEF_OLD_QPEL(qpel8_mc11_old_c)
  130. DEF_OLD_QPEL(qpel8_mc31_old_c)
  131. DEF_OLD_QPEL(qpel8_mc12_old_c)
  132. DEF_OLD_QPEL(qpel8_mc32_old_c)
  133. DEF_OLD_QPEL(qpel8_mc13_old_c)
  134. DEF_OLD_QPEL(qpel8_mc33_old_c)
  135. #define CALL_2X_PIXELS(a, b, n)\
  136. static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  137. b(block , pixels , line_size, h);\
  138. b(block+n, pixels+n, line_size, h);\
  139. }
  140. /* motion estimation */
  141. // h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller than 2
  142. // although currently h<4 is not used as functions with width <8 are neither used nor implemented
  143. typedef int (*me_cmp_func)(void /*MpegEncContext*/ *s, uint8_t *blk1/*align width (8 or 16)*/, uint8_t *blk2/*align 1*/, int line_size, int h)/* __attribute__ ((const))*/;
  144. /**
  145. * Scantable.
  146. */
  147. typedef struct ScanTable{
  148. const uint8_t *scantable;
  149. uint8_t permutated[64];
  150. uint8_t raster_end[64];
  151. } ScanTable;
  152. void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable);
  153. void ff_init_scantable_permutation(uint8_t *idct_permutation,
  154. int idct_permutation_type);
  155. /**
  156. * DSPContext.
  157. */
  158. typedef struct DSPContext {
  159. /**
  160. * Size of DCT coefficients.
  161. */
  162. int dct_bits;
  163. /* pixel ops : interface with DCT */
  164. void (*get_pixels)(int16_t *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
  165. void (*diff_pixels)(int16_t *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
  166. void (*put_pixels_clamped)(const int16_t *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
  167. void (*put_signed_pixels_clamped)(const int16_t *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
  168. void (*add_pixels_clamped)(const int16_t *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
  169. void (*add_pixels8)(uint8_t *pixels, int16_t *block, int line_size);
  170. void (*add_pixels4)(uint8_t *pixels, int16_t *block, int line_size);
  171. int (*sum_abs_dctelem)(int16_t *block/*align 16*/);
  172. /**
  173. * translational global motion compensation.
  174. */
  175. void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder);
  176. /**
  177. * global motion compensation.
  178. */
  179. void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy,
  180. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
  181. void (*clear_block)(int16_t *block/*align 16*/);
  182. void (*clear_blocks)(int16_t *blocks/*align 16*/);
  183. int (*pix_sum)(uint8_t * pix, int line_size);
  184. int (*pix_norm1)(uint8_t * pix, int line_size);
  185. // 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4
  186. me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
  187. me_cmp_func sse[6];
  188. me_cmp_func hadamard8_diff[6];
  189. me_cmp_func dct_sad[6];
  190. me_cmp_func quant_psnr[6];
  191. me_cmp_func bit[6];
  192. me_cmp_func rd[6];
  193. me_cmp_func vsad[6];
  194. me_cmp_func vsse[6];
  195. me_cmp_func nsse[6];
  196. me_cmp_func dct_max[6];
  197. me_cmp_func dct264_sad[6];
  198. me_cmp_func me_pre_cmp[6];
  199. me_cmp_func me_cmp[6];
  200. me_cmp_func me_sub_cmp[6];
  201. me_cmp_func mb_cmp[6];
  202. me_cmp_func ildct_cmp[6]; //only width 16 used
  203. me_cmp_func frame_skip_cmp[6]; //only width 8 used
  204. int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2,
  205. int size);
  206. /**
  207. * Halfpel motion compensation with rounding (a+b+1)>>1.
  208. * this is an array[4][4] of motion compensation functions for 4
  209. * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
  210. * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
  211. * @param block destination where the result is stored
  212. * @param pixels source
  213. * @param line_size number of bytes in a horizontal line of block
  214. * @param h height
  215. */
  216. op_pixels_func put_pixels_tab[4][4];
  217. /**
  218. * Halfpel motion compensation with rounding (a+b+1)>>1.
  219. * This is an array[4][4] of motion compensation functions for 4
  220. * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
  221. * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
  222. * @param block destination into which the result is averaged (a+b+1)>>1
  223. * @param pixels source
  224. * @param line_size number of bytes in a horizontal line of block
  225. * @param h height
  226. */
  227. op_pixels_func avg_pixels_tab[4][4];
  228. /**
  229. * Halfpel motion compensation with no rounding (a+b)>>1.
  230. * this is an array[2][4] of motion compensation functions for 2
  231. * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
  232. * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
  233. * @param block destination where the result is stored
  234. * @param pixels source
  235. * @param line_size number of bytes in a horizontal line of block
  236. * @param h height
  237. */
  238. op_pixels_func put_no_rnd_pixels_tab[2][4];
  239. /**
  240. * Halfpel motion compensation with no rounding (a+b)>>1.
  241. * this is an array[4] of motion compensation functions for 1
  242. * horizontal blocksize (16) and the 4 halfpel positions<br>
  243. * *pixels_tab[0][ xhalfpel + 2*yhalfpel ]
  244. * @param block destination into which the result is averaged (a+b)>>1
  245. * @param pixels source
  246. * @param line_size number of bytes in a horizontal line of block
  247. * @param h height
  248. */
  249. op_pixels_func avg_no_rnd_pixels_tab[4];
  250. /**
  251. * Thirdpel motion compensation with rounding (a+b+1)>>1.
  252. * this is an array[12] of motion compensation functions for the 9 thirdpe
  253. * positions<br>
  254. * *pixels_tab[ xthirdpel + 4*ythirdpel ]
  255. * @param block destination where the result is stored
  256. * @param pixels source
  257. * @param line_size number of bytes in a horizontal line of block
  258. * @param h height
  259. */
  260. tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
  261. tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
  262. qpel_mc_func put_qpel_pixels_tab[2][16];
  263. qpel_mc_func avg_qpel_pixels_tab[2][16];
  264. qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
  265. qpel_mc_func put_mspel_pixels_tab[8];
  266. me_cmp_func pix_abs[2][4];
  267. /* huffyuv specific */
  268. void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
  269. void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w);
  270. /**
  271. * subtract huffyuv's variant of median prediction
  272. * note, this might read from src1[-1], src2[-1]
  273. */
  274. void (*sub_hfyu_median_prediction)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top);
  275. void (*add_hfyu_median_prediction)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top);
  276. int (*add_hfyu_left_prediction)(uint8_t *dst, const uint8_t *src, int w, int left);
  277. void (*add_hfyu_left_prediction_bgr32)(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha);
  278. void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
  279. void (*bswap16_buf)(uint16_t *dst, const uint16_t *src, int len);
  280. void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
  281. void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
  282. void (*h261_loop_filter)(uint8_t *src, int stride);
  283. /* assume len is a multiple of 8, and arrays are 16-byte aligned */
  284. void (*vector_clipf)(float *dst /* align 16 */, const float *src /* align 16 */, float min, float max, int len /* align 16 */);
  285. /* (I)DCT */
  286. void (*fdct)(int16_t *block/* align 16*/);
  287. void (*fdct248)(int16_t *block/* align 16*/);
  288. /* IDCT really*/
  289. void (*idct)(int16_t *block/* align 16*/);
  290. /**
  291. * block -> idct -> clip to unsigned 8 bit -> dest.
  292. * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
  293. * @param line_size size in bytes of a horizontal line of dest
  294. */
  295. void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, int16_t *block/*align 16*/);
  296. /**
  297. * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
  298. * @param line_size size in bytes of a horizontal line of dest
  299. */
  300. void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, int16_t *block/*align 16*/);
  301. /**
  302. * idct input permutation.
  303. * several optimized IDCTs need a permutated input (relative to the normal order of the reference
  304. * IDCT)
  305. * this permutation must be performed before the idct_put/add, note, normally this can be merged
  306. * with the zigzag/alternate scan<br>
  307. * an example to avoid confusion:
  308. * - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...)
  309. * - (x -> reference dct -> reference idct -> x)
  310. * - (x -> reference dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x)
  311. * - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...)
  312. */
  313. uint8_t idct_permutation[64];
  314. int idct_permutation_type;
  315. #define FF_NO_IDCT_PERM 1
  316. #define FF_LIBMPEG2_IDCT_PERM 2
  317. #define FF_SIMPLE_IDCT_PERM 3
  318. #define FF_TRANSPOSE_IDCT_PERM 4
  319. #define FF_PARTTRANS_IDCT_PERM 5
  320. #define FF_SSE2_IDCT_PERM 6
  321. int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale);
  322. void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
  323. #define BASIS_SHIFT 16
  324. #define RECON_SHIFT 6
  325. void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w, int h, int sides);
  326. #define EDGE_WIDTH 16
  327. #define EDGE_TOP 1
  328. #define EDGE_BOTTOM 2
  329. void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
  330. /**
  331. * Calculate scalar product of two vectors.
  332. * @param len length of vectors, should be multiple of 16
  333. */
  334. int32_t (*scalarproduct_int16)(const int16_t *v1, const int16_t *v2/*align 16*/, int len);
  335. /* ape functions */
  336. /**
  337. * Calculate scalar product of v1 and v2,
  338. * and v1[i] += v3[i] * mul
  339. * @param len length of vectors, should be multiple of 16
  340. */
  341. int32_t (*scalarproduct_and_madd_int16)(int16_t *v1/*align 16*/, const int16_t *v2, const int16_t *v3, int len, int mul);
  342. /**
  343. * Apply symmetric window in 16-bit fixed-point.
  344. * @param output destination array
  345. * constraints: 16-byte aligned
  346. * @param input source array
  347. * constraints: 16-byte aligned
  348. * @param window window array
  349. * constraints: 16-byte aligned, at least len/2 elements
  350. * @param len full window length
  351. * constraints: multiple of ? greater than zero
  352. */
  353. void (*apply_window_int16)(int16_t *output, const int16_t *input,
  354. const int16_t *window, unsigned int len);
  355. /**
  356. * Clip each element in an array of int32_t to a given minimum and maximum value.
  357. * @param dst destination array
  358. * constraints: 16-byte aligned
  359. * @param src source array
  360. * constraints: 16-byte aligned
  361. * @param min minimum value
  362. * constraints: must be in the range [-(1 << 24), 1 << 24]
  363. * @param max maximum value
  364. * constraints: must be in the range [-(1 << 24), 1 << 24]
  365. * @param len number of elements in the array
  366. * constraints: multiple of 32 greater than zero
  367. */
  368. void (*vector_clip_int32)(int32_t *dst, const int32_t *src, int32_t min,
  369. int32_t max, unsigned int len);
  370. op_fill_func fill_block_tab[2];
  371. } DSPContext;
  372. void ff_dsputil_static_init(void);
  373. void ff_dsputil_init(DSPContext* p, AVCodecContext *avctx);
  374. int ff_check_alignment(void);
  375. void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type);
  376. #define BYTE_VEC32(c) ((c)*0x01010101UL)
  377. #define BYTE_VEC64(c) ((c)*0x0001000100010001UL)
  378. static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
  379. {
  380. return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
  381. }
  382. static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
  383. {
  384. return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
  385. }
  386. static inline uint64_t rnd_avg64(uint64_t a, uint64_t b)
  387. {
  388. return (a | b) - (((a ^ b) & ~BYTE_VEC64(0x01)) >> 1);
  389. }
  390. static inline uint64_t no_rnd_avg64(uint64_t a, uint64_t b)
  391. {
  392. return (a & b) + (((a ^ b) & ~BYTE_VEC64(0x01)) >> 1);
  393. }
  394. void ff_dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
  395. void ff_dsputil_init_arm(DSPContext* c, AVCodecContext *avctx);
  396. void ff_dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx);
  397. void ff_dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx);
  398. void ff_dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx);
  399. void ff_dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
  400. void ff_dsputil_init_vis(DSPContext* c, AVCodecContext *avctx);
  401. #if (ARCH_ARM && HAVE_NEON) || ARCH_PPC || HAVE_MMX
  402. # define STRIDE_ALIGN 16
  403. #else
  404. # define STRIDE_ALIGN 8
  405. #endif
  406. // Some broken preprocessors need a second expansion
  407. // to be forced to tokenize __VA_ARGS__
  408. #define E(x) x
  409. #define LOCAL_ALIGNED_A(a, t, v, s, o, ...) \
  410. uint8_t la_##v[sizeof(t s o) + (a)]; \
  411. t (*v) o = (void *)FFALIGN((uintptr_t)la_##v, a)
  412. #define LOCAL_ALIGNED_D(a, t, v, s, o, ...) \
  413. DECLARE_ALIGNED(a, t, la_##v) s o; \
  414. t (*v) o = la_##v
  415. #define LOCAL_ALIGNED(a, t, v, ...) E(LOCAL_ALIGNED_A(a, t, v, __VA_ARGS__,,))
  416. #if HAVE_LOCAL_ALIGNED_8
  417. # define LOCAL_ALIGNED_8(t, v, ...) E(LOCAL_ALIGNED_D(8, t, v, __VA_ARGS__,,))
  418. #else
  419. # define LOCAL_ALIGNED_8(t, v, ...) LOCAL_ALIGNED(8, t, v, __VA_ARGS__)
  420. #endif
  421. #if HAVE_LOCAL_ALIGNED_16
  422. # define LOCAL_ALIGNED_16(t, v, ...) E(LOCAL_ALIGNED_D(16, t, v, __VA_ARGS__,,))
  423. #else
  424. # define LOCAL_ALIGNED_16(t, v, ...) LOCAL_ALIGNED(16, t, v, __VA_ARGS__)
  425. #endif
  426. #define WRAPPER8_16_SQ(name8, name16)\
  427. static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
  428. int score=0;\
  429. score +=name8(s, dst , src , stride, 8);\
  430. score +=name8(s, dst+8 , src+8 , stride, 8);\
  431. if(h==16){\
  432. dst += 8*stride;\
  433. src += 8*stride;\
  434. score +=name8(s, dst , src , stride, 8);\
  435. score +=name8(s, dst+8 , src+8 , stride, 8);\
  436. }\
  437. return score;\
  438. }
  439. static inline void copy_block8(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
  440. {
  441. int i;
  442. for(i=0; i<h; i++)
  443. {
  444. AV_COPY64U(dst, src);
  445. dst+=dstStride;
  446. src+=srcStride;
  447. }
  448. }
  449. static inline void copy_block9(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
  450. {
  451. int i;
  452. for(i=0; i<h; i++)
  453. {
  454. AV_COPY64U(dst, src);
  455. dst[8]= src[8];
  456. dst+=dstStride;
  457. src+=srcStride;
  458. }
  459. }
  460. static inline void copy_block17(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
  461. {
  462. int i;
  463. for(i=0; i<h; i++)
  464. {
  465. AV_COPY128U(dst, src);
  466. dst[16]= src[16];
  467. dst+=dstStride;
  468. src+=srcStride;
  469. }
  470. }
  471. #endif /* AVCODEC_DSPUTIL_H */