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.

719 lines
42KB

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