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.

734 lines
43KB

  1. /*
  2. * Copyright (c) 2000, 2001 Fabrice Bellard
  3. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "config.h"
  22. #include "libavutil/attributes.h"
  23. #include "libavutil/cpu.h"
  24. #include "libavutil/x86/asm.h"
  25. #include "libavutil/x86/cpu.h"
  26. #include "libavcodec/dsputil.h"
  27. #include "libavcodec/simple_idct.h"
  28. #include "dsputil_x86.h"
  29. #include "idct_xvid.h"
  30. void ff_put_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
  31. int dstStride, int src1Stride, int h);
  32. void ff_put_no_rnd_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1,
  33. uint8_t *src2, int dstStride,
  34. int src1Stride, int h);
  35. void ff_avg_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
  36. int dstStride, int src1Stride, int h);
  37. void ff_put_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
  38. int dstStride, int src1Stride, int h);
  39. void ff_avg_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
  40. int dstStride, int src1Stride, int h);
  41. void ff_put_no_rnd_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
  42. int dstStride, int src1Stride, int h);
  43. void ff_put_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  44. int dstStride, int srcStride, int h);
  45. void ff_avg_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  46. int dstStride, int srcStride, int h);
  47. void ff_put_no_rnd_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  48. int dstStride, int srcStride,
  49. int h);
  50. void ff_put_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  51. int dstStride, int srcStride, int h);
  52. void ff_avg_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  53. int dstStride, int srcStride, int h);
  54. void ff_put_no_rnd_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  55. int dstStride, int srcStride,
  56. int h);
  57. void ff_put_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  58. int dstStride, int srcStride);
  59. void ff_avg_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  60. int dstStride, int srcStride);
  61. void ff_put_no_rnd_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  62. int dstStride, int srcStride);
  63. void ff_put_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  64. int dstStride, int srcStride);
  65. void ff_avg_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  66. int dstStride, int srcStride);
  67. void ff_put_no_rnd_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  68. int dstStride, int srcStride);
  69. #define ff_put_no_rnd_pixels16_mmxext ff_put_pixels16_mmxext
  70. #define ff_put_no_rnd_pixels8_mmxext ff_put_pixels8_mmxext
  71. void ff_h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale);
  72. void ff_h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale);
  73. int32_t ff_scalarproduct_int16_mmxext(const int16_t *v1, const int16_t *v2,
  74. int order);
  75. int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2,
  76. int order);
  77. int32_t ff_scalarproduct_and_madd_int16_mmxext(int16_t *v1, const int16_t *v2,
  78. const int16_t *v3,
  79. int order, int mul);
  80. int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, const int16_t *v2,
  81. const int16_t *v3,
  82. int order, int mul);
  83. int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, const int16_t *v2,
  84. const int16_t *v3,
  85. int order, int mul);
  86. void ff_apply_window_int16_round_mmxext(int16_t *output, const int16_t *input,
  87. const int16_t *window, unsigned int len);
  88. void ff_apply_window_int16_round_sse2(int16_t *output, const int16_t *input,
  89. const int16_t *window, unsigned int len);
  90. void ff_apply_window_int16_mmxext(int16_t *output, const int16_t *input,
  91. const int16_t *window, unsigned int len);
  92. void ff_apply_window_int16_sse2(int16_t *output, const int16_t *input,
  93. const int16_t *window, unsigned int len);
  94. void ff_apply_window_int16_ssse3(int16_t *output, const int16_t *input,
  95. const int16_t *window, unsigned int len);
  96. void ff_apply_window_int16_ssse3_atom(int16_t *output, const int16_t *input,
  97. const int16_t *window, unsigned int len);
  98. void ff_bswap32_buf_ssse3(uint32_t *dst, const uint32_t *src, int w);
  99. void ff_bswap32_buf_sse2(uint32_t *dst, const uint32_t *src, int w);
  100. void ff_add_hfyu_median_prediction_mmxext(uint8_t *dst, const uint8_t *top,
  101. const uint8_t *diff, int w,
  102. int *left, int *left_top);
  103. int ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src,
  104. int w, int left);
  105. int ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src,
  106. int w, int left);
  107. void ff_vector_clip_int32_mmx (int32_t *dst, const int32_t *src,
  108. int32_t min, int32_t max, unsigned int len);
  109. void ff_vector_clip_int32_sse2 (int32_t *dst, const int32_t *src,
  110. int32_t min, int32_t max, unsigned int len);
  111. void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src,
  112. int32_t min, int32_t max, unsigned int len);
  113. void ff_vector_clip_int32_sse4 (int32_t *dst, const int32_t *src,
  114. int32_t min, int32_t max, unsigned int len);
  115. #if HAVE_YASM
  116. PIXELS16(static, ff_avg, , , _mmxext)
  117. PIXELS16(static, ff_put, , , _mmxext)
  118. #define QPEL_OP(OPNAME, RND, MMX) \
  119. static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
  120. ptrdiff_t stride) \
  121. { \
  122. ff_ ## OPNAME ## pixels8_ ## MMX(dst, src, stride, 8); \
  123. } \
  124. \
  125. static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
  126. ptrdiff_t stride) \
  127. { \
  128. uint64_t temp[8]; \
  129. uint8_t * const half = (uint8_t*)temp; \
  130. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
  131. stride, 8); \
  132. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
  133. stride, stride, 8); \
  134. } \
  135. \
  136. static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
  137. ptrdiff_t stride) \
  138. { \
  139. ff_ ## OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, \
  140. stride, 8); \
  141. } \
  142. \
  143. static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
  144. ptrdiff_t stride) \
  145. { \
  146. uint64_t temp[8]; \
  147. uint8_t * const half = (uint8_t*)temp; \
  148. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
  149. stride, 8); \
  150. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + 1, half, stride, \
  151. stride, 8); \
  152. } \
  153. \
  154. static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
  155. ptrdiff_t stride) \
  156. { \
  157. uint64_t temp[8]; \
  158. uint8_t * const half = (uint8_t*)temp; \
  159. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, \
  160. 8, stride); \
  161. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
  162. stride, stride, 8); \
  163. } \
  164. \
  165. static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
  166. ptrdiff_t stride) \
  167. { \
  168. ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, \
  169. stride, stride); \
  170. } \
  171. \
  172. static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
  173. ptrdiff_t stride) \
  174. { \
  175. uint64_t temp[8]; \
  176. uint8_t * const half = (uint8_t*)temp; \
  177. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, \
  178. 8, stride); \
  179. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + stride, half, stride,\
  180. stride, 8); \
  181. } \
  182. \
  183. static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
  184. ptrdiff_t stride) \
  185. { \
  186. uint64_t half[8 + 9]; \
  187. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  188. uint8_t * const halfHV = ((uint8_t*)half); \
  189. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  190. stride, 9); \
  191. ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, \
  192. stride, 9); \
  193. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  194. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
  195. stride, 8, 8); \
  196. } \
  197. \
  198. static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
  199. ptrdiff_t stride) \
  200. { \
  201. uint64_t half[8 + 9]; \
  202. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  203. uint8_t * const halfHV = ((uint8_t*)half); \
  204. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  205. stride, 9); \
  206. ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
  207. stride, 9); \
  208. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  209. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
  210. stride, 8, 8); \
  211. } \
  212. \
  213. static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
  214. ptrdiff_t stride) \
  215. { \
  216. uint64_t half[8 + 9]; \
  217. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  218. uint8_t * const halfHV = ((uint8_t*)half); \
  219. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  220. stride, 9); \
  221. ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, \
  222. stride, 9); \
  223. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  224. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
  225. stride, 8, 8); \
  226. } \
  227. \
  228. static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
  229. ptrdiff_t stride) \
  230. { \
  231. uint64_t half[8 + 9]; \
  232. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  233. uint8_t * const halfHV = ((uint8_t*)half); \
  234. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  235. stride, 9); \
  236. ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
  237. stride, 9); \
  238. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  239. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
  240. stride, 8, 8); \
  241. } \
  242. \
  243. static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
  244. ptrdiff_t stride) \
  245. { \
  246. uint64_t half[8 + 9]; \
  247. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  248. uint8_t * const halfHV = ((uint8_t*)half); \
  249. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  250. stride, 9); \
  251. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  252. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
  253. stride, 8, 8); \
  254. } \
  255. \
  256. static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
  257. ptrdiff_t stride) \
  258. { \
  259. uint64_t half[8 + 9]; \
  260. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  261. uint8_t * const halfHV = ((uint8_t*)half); \
  262. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  263. stride, 9); \
  264. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  265. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
  266. stride, 8, 8); \
  267. } \
  268. \
  269. static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
  270. ptrdiff_t stride) \
  271. { \
  272. uint64_t half[8 + 9]; \
  273. uint8_t * const halfH = ((uint8_t*)half); \
  274. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  275. stride, 9); \
  276. ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, \
  277. 8, stride, 9); \
  278. ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
  279. stride, 8); \
  280. } \
  281. \
  282. static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
  283. ptrdiff_t stride) \
  284. { \
  285. uint64_t half[8 + 9]; \
  286. uint8_t * const halfH = ((uint8_t*)half); \
  287. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  288. stride, 9); \
  289. ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
  290. stride, 9); \
  291. ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
  292. stride, 8); \
  293. } \
  294. \
  295. static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
  296. ptrdiff_t stride) \
  297. { \
  298. uint64_t half[9]; \
  299. uint8_t * const halfH = ((uint8_t*)half); \
  300. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  301. stride, 9); \
  302. ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
  303. stride, 8); \
  304. } \
  305. \
  306. static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
  307. ptrdiff_t stride) \
  308. { \
  309. ff_ ## OPNAME ## pixels16_ ## MMX(dst, src, stride, 16); \
  310. } \
  311. \
  312. static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
  313. ptrdiff_t stride) \
  314. { \
  315. uint64_t temp[32]; \
  316. uint8_t * const half = (uint8_t*)temp; \
  317. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
  318. stride, 16); \
  319. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
  320. stride, 16); \
  321. } \
  322. \
  323. static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
  324. ptrdiff_t stride) \
  325. { \
  326. ff_ ## OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, \
  327. stride, stride, 16);\
  328. } \
  329. \
  330. static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
  331. ptrdiff_t stride) \
  332. { \
  333. uint64_t temp[32]; \
  334. uint8_t * const half = (uint8_t*)temp; \
  335. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
  336. stride, 16); \
  337. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src + 1, half, \
  338. stride, stride, 16); \
  339. } \
  340. \
  341. static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
  342. ptrdiff_t stride) \
  343. { \
  344. uint64_t temp[32]; \
  345. uint8_t * const half = (uint8_t*)temp; \
  346. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
  347. stride); \
  348. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
  349. stride, 16); \
  350. } \
  351. \
  352. static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
  353. ptrdiff_t stride) \
  354. { \
  355. ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, \
  356. stride, stride); \
  357. } \
  358. \
  359. static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
  360. ptrdiff_t stride) \
  361. { \
  362. uint64_t temp[32]; \
  363. uint8_t * const half = (uint8_t*)temp; \
  364. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
  365. stride); \
  366. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, \
  367. stride, stride, 16); \
  368. } \
  369. \
  370. static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
  371. ptrdiff_t stride) \
  372. { \
  373. uint64_t half[16 * 2 + 17 * 2]; \
  374. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  375. uint8_t * const halfHV = ((uint8_t*)half); \
  376. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  377. stride, 17); \
  378. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
  379. stride, 17); \
  380. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  381. 16, 16); \
  382. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
  383. stride, 16, 16); \
  384. } \
  385. \
  386. static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
  387. ptrdiff_t stride) \
  388. { \
  389. uint64_t half[16 * 2 + 17 * 2]; \
  390. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  391. uint8_t * const halfHV = ((uint8_t*)half); \
  392. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  393. stride, 17); \
  394. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
  395. stride, 17); \
  396. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  397. 16, 16); \
  398. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
  399. stride, 16, 16); \
  400. } \
  401. \
  402. static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
  403. ptrdiff_t stride) \
  404. { \
  405. uint64_t half[16 * 2 + 17 * 2]; \
  406. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  407. uint8_t * const halfHV = ((uint8_t*)half); \
  408. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  409. stride, 17); \
  410. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
  411. stride, 17); \
  412. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  413. 16, 16); \
  414. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
  415. stride, 16, 16); \
  416. } \
  417. \
  418. static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
  419. ptrdiff_t stride) \
  420. { \
  421. uint64_t half[16 * 2 + 17 * 2]; \
  422. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  423. uint8_t * const halfHV = ((uint8_t*)half); \
  424. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  425. stride, 17); \
  426. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
  427. stride, 17); \
  428. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  429. 16, 16); \
  430. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
  431. stride, 16, 16); \
  432. } \
  433. \
  434. static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
  435. ptrdiff_t stride) \
  436. { \
  437. uint64_t half[16 * 2 + 17 * 2]; \
  438. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  439. uint8_t * const halfHV = ((uint8_t*)half); \
  440. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  441. stride, 17); \
  442. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  443. 16, 16); \
  444. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
  445. stride, 16, 16); \
  446. } \
  447. \
  448. static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
  449. ptrdiff_t stride) \
  450. { \
  451. uint64_t half[16 * 2 + 17 * 2]; \
  452. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  453. uint8_t * const halfHV = ((uint8_t*)half); \
  454. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  455. stride, 17); \
  456. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  457. 16, 16); \
  458. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
  459. stride, 16, 16); \
  460. } \
  461. \
  462. static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
  463. ptrdiff_t stride) \
  464. { \
  465. uint64_t half[17 * 2]; \
  466. uint8_t * const halfH = ((uint8_t*)half); \
  467. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  468. stride, 17); \
  469. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
  470. stride, 17); \
  471. ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
  472. stride, 16); \
  473. } \
  474. \
  475. static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
  476. ptrdiff_t stride) \
  477. { \
  478. uint64_t half[17 * 2]; \
  479. uint8_t * const halfH = ((uint8_t*)half); \
  480. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  481. stride, 17); \
  482. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
  483. stride, 17); \
  484. ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
  485. stride, 16); \
  486. } \
  487. \
  488. static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
  489. ptrdiff_t stride) \
  490. { \
  491. uint64_t half[17 * 2]; \
  492. uint8_t * const halfH = ((uint8_t*)half); \
  493. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  494. stride, 17); \
  495. ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
  496. stride, 16); \
  497. }
  498. QPEL_OP(put_, _, mmxext)
  499. QPEL_OP(avg_, _, mmxext)
  500. QPEL_OP(put_no_rnd_, _no_rnd_, mmxext)
  501. #endif /* HAVE_YASM */
  502. #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \
  503. do { \
  504. c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
  505. c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
  506. c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
  507. c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
  508. c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
  509. c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
  510. c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
  511. c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
  512. c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
  513. c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
  514. c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
  515. c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
  516. c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
  517. c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
  518. c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
  519. c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \
  520. } while (0)
  521. static av_cold void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx,
  522. int cpu_flags)
  523. {
  524. #if HAVE_MMX_INLINE
  525. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  526. c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
  527. c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
  528. c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
  529. if (!high_bit_depth) {
  530. c->clear_block = ff_clear_block_mmx;
  531. c->clear_blocks = ff_clear_blocks_mmx;
  532. c->draw_edges = ff_draw_edges_mmx;
  533. }
  534. #if CONFIG_VIDEODSP && (ARCH_X86_32 || !HAVE_YASM)
  535. c->gmc = ff_gmc_mmx;
  536. #endif
  537. c->add_bytes = ff_add_bytes_mmx;
  538. #endif /* HAVE_MMX_INLINE */
  539. #if HAVE_MMX_EXTERNAL
  540. if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  541. c->h263_v_loop_filter = ff_h263_v_loop_filter_mmx;
  542. c->h263_h_loop_filter = ff_h263_h_loop_filter_mmx;
  543. }
  544. c->vector_clip_int32 = ff_vector_clip_int32_mmx;
  545. #endif /* HAVE_MMX_EXTERNAL */
  546. }
  547. static av_cold void dsputil_init_mmxext(DSPContext *c, AVCodecContext *avctx,
  548. int cpu_flags)
  549. {
  550. #if HAVE_MMXEXT_INLINE
  551. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  552. if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX && avctx->lowres == 0) {
  553. c->idct_put = ff_idct_xvid_mmxext_put;
  554. c->idct_add = ff_idct_xvid_mmxext_add;
  555. c->idct = ff_idct_xvid_mmxext;
  556. }
  557. #endif /* HAVE_MMXEXT_INLINE */
  558. #if HAVE_MMXEXT_EXTERNAL
  559. SET_QPEL_FUNCS(avg_qpel, 0, 16, mmxext, );
  560. SET_QPEL_FUNCS(avg_qpel, 1, 8, mmxext, );
  561. SET_QPEL_FUNCS(put_qpel, 0, 16, mmxext, );
  562. SET_QPEL_FUNCS(put_qpel, 1, 8, mmxext, );
  563. SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmxext, );
  564. SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmxext, );
  565. /* slower than cmov version on AMD */
  566. if (!(cpu_flags & AV_CPU_FLAG_3DNOW))
  567. c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmxext;
  568. c->scalarproduct_int16 = ff_scalarproduct_int16_mmxext;
  569. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmxext;
  570. if (avctx->flags & CODEC_FLAG_BITEXACT) {
  571. c->apply_window_int16 = ff_apply_window_int16_mmxext;
  572. } else {
  573. c->apply_window_int16 = ff_apply_window_int16_round_mmxext;
  574. }
  575. #endif /* HAVE_MMXEXT_EXTERNAL */
  576. }
  577. static av_cold void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx,
  578. int cpu_flags)
  579. {
  580. #if HAVE_SSE_INLINE
  581. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  582. if (!high_bit_depth) {
  583. if (!(CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1)) {
  584. /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
  585. c->clear_block = ff_clear_block_sse;
  586. c->clear_blocks = ff_clear_blocks_sse;
  587. }
  588. }
  589. c->vector_clipf = ff_vector_clipf_sse;
  590. #endif /* HAVE_SSE_INLINE */
  591. #if HAVE_YASM
  592. #if HAVE_INLINE_ASM && CONFIG_VIDEODSP
  593. c->gmc = ff_gmc_sse;
  594. #endif
  595. #endif /* HAVE_YASM */
  596. }
  597. static av_cold void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
  598. int cpu_flags)
  599. {
  600. #if HAVE_SSE2_INLINE
  601. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  602. if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX && avctx->lowres == 0) {
  603. c->idct_put = ff_idct_xvid_sse2_put;
  604. c->idct_add = ff_idct_xvid_sse2_add;
  605. c->idct = ff_idct_xvid_sse2;
  606. c->idct_permutation_type = FF_SSE2_IDCT_PERM;
  607. }
  608. #endif /* HAVE_SSE2_INLINE */
  609. #if HAVE_SSE2_EXTERNAL
  610. c->scalarproduct_int16 = ff_scalarproduct_int16_sse2;
  611. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2;
  612. if (cpu_flags & AV_CPU_FLAG_ATOM) {
  613. c->vector_clip_int32 = ff_vector_clip_int32_int_sse2;
  614. } else {
  615. c->vector_clip_int32 = ff_vector_clip_int32_sse2;
  616. }
  617. if (avctx->flags & CODEC_FLAG_BITEXACT) {
  618. c->apply_window_int16 = ff_apply_window_int16_sse2;
  619. } else if (!(cpu_flags & AV_CPU_FLAG_SSE2SLOW)) {
  620. c->apply_window_int16 = ff_apply_window_int16_round_sse2;
  621. }
  622. c->bswap_buf = ff_bswap32_buf_sse2;
  623. #endif /* HAVE_SSE2_EXTERNAL */
  624. }
  625. static av_cold void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
  626. int cpu_flags)
  627. {
  628. #if HAVE_SSSE3_EXTERNAL
  629. c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
  630. if (cpu_flags & AV_CPU_FLAG_SSE4) // not really SSE4, just slow on Conroe
  631. c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
  632. if (cpu_flags & AV_CPU_FLAG_ATOM)
  633. c->apply_window_int16 = ff_apply_window_int16_ssse3_atom;
  634. else
  635. c->apply_window_int16 = ff_apply_window_int16_ssse3;
  636. if (!(cpu_flags & (AV_CPU_FLAG_SSE42 | AV_CPU_FLAG_3DNOW))) // cachesplit
  637. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3;
  638. c->bswap_buf = ff_bswap32_buf_ssse3;
  639. #endif /* HAVE_SSSE3_EXTERNAL */
  640. }
  641. static av_cold void dsputil_init_sse4(DSPContext *c, AVCodecContext *avctx,
  642. int cpu_flags)
  643. {
  644. #if HAVE_SSE4_EXTERNAL
  645. c->vector_clip_int32 = ff_vector_clip_int32_sse4;
  646. #endif /* HAVE_SSE4_EXTERNAL */
  647. }
  648. av_cold void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx)
  649. {
  650. int cpu_flags = av_get_cpu_flags();
  651. #if HAVE_7REGS && HAVE_INLINE_ASM
  652. if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_CMOV)
  653. c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_cmov;
  654. #endif
  655. if (X86_MMX(cpu_flags)) {
  656. #if HAVE_INLINE_ASM
  657. const int idct_algo = avctx->idct_algo;
  658. if (avctx->lowres == 0 && avctx->bits_per_raw_sample <= 8) {
  659. if (idct_algo == FF_IDCT_AUTO || idct_algo == FF_IDCT_SIMPLEMMX) {
  660. c->idct_put = ff_simple_idct_put_mmx;
  661. c->idct_add = ff_simple_idct_add_mmx;
  662. c->idct = ff_simple_idct_mmx;
  663. c->idct_permutation_type = FF_SIMPLE_IDCT_PERM;
  664. } else if (idct_algo == FF_IDCT_XVIDMMX) {
  665. c->idct_put = ff_idct_xvid_mmx_put;
  666. c->idct_add = ff_idct_xvid_mmx_add;
  667. c->idct = ff_idct_xvid_mmx;
  668. }
  669. }
  670. #endif /* HAVE_INLINE_ASM */
  671. dsputil_init_mmx(c, avctx, cpu_flags);
  672. }
  673. if (X86_MMXEXT(cpu_flags))
  674. dsputil_init_mmxext(c, avctx, cpu_flags);
  675. if (X86_SSE(cpu_flags))
  676. dsputil_init_sse(c, avctx, cpu_flags);
  677. if (X86_SSE2(cpu_flags))
  678. dsputil_init_sse2(c, avctx, cpu_flags);
  679. if (EXTERNAL_SSSE3(cpu_flags))
  680. dsputil_init_ssse3(c, avctx, cpu_flags);
  681. if (EXTERNAL_SSE4(cpu_flags))
  682. dsputil_init_sse4(c, avctx, cpu_flags);
  683. if (CONFIG_ENCODERS)
  684. ff_dsputilenc_init_mmx(c, avctx);
  685. }