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.

691 lines
41KB

  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/internal.h"
  22. #include "libavutil/x86/asm.h"
  23. #include "libavutil/x86/cpu.h"
  24. #include "libavcodec/dsputil.h"
  25. #include "libavcodec/simple_idct.h"
  26. #include "libavcodec/version.h"
  27. #include "dsputil_x86.h"
  28. #include "idct_xvid.h"
  29. void ff_put_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
  30. int dstStride, int src1Stride, int h);
  31. void ff_put_no_rnd_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1,
  32. uint8_t *src2, int dstStride,
  33. int src1Stride, int h);
  34. void ff_avg_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
  35. int dstStride, int src1Stride, int h);
  36. void ff_put_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
  37. int dstStride, int src1Stride, int h);
  38. void ff_avg_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
  39. int dstStride, int src1Stride, int h);
  40. void ff_put_no_rnd_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
  41. int dstStride, int src1Stride, int h);
  42. void ff_put_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  43. int dstStride, int srcStride, int h);
  44. void ff_avg_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  45. int dstStride, int srcStride, int h);
  46. void ff_put_no_rnd_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  47. int dstStride, int srcStride,
  48. int h);
  49. void ff_put_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  50. int dstStride, int srcStride, int h);
  51. void ff_avg_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  52. int dstStride, int srcStride, int h);
  53. void ff_put_no_rnd_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  54. int dstStride, int srcStride,
  55. int h);
  56. void ff_put_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  57. int dstStride, int srcStride);
  58. void ff_avg_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  59. int dstStride, int srcStride);
  60. void ff_put_no_rnd_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  61. int dstStride, int srcStride);
  62. void ff_put_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  63. int dstStride, int srcStride);
  64. void ff_avg_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  65. int dstStride, int srcStride);
  66. void ff_put_no_rnd_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  67. int dstStride, int srcStride);
  68. #define ff_put_no_rnd_pixels16_mmxext ff_put_pixels16_mmxext
  69. #define ff_put_no_rnd_pixels8_mmxext ff_put_pixels8_mmxext
  70. int32_t ff_scalarproduct_int16_mmxext(const int16_t *v1, const int16_t *v2,
  71. int order);
  72. int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2,
  73. int order);
  74. int32_t ff_scalarproduct_and_madd_int16_mmxext(int16_t *v1, const int16_t *v2,
  75. const int16_t *v3,
  76. int order, int mul);
  77. int32_t ff_scalarproduct_and_madd_int16_sse2(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_ssse3(int16_t *v1, const int16_t *v2,
  81. const int16_t *v3,
  82. int order, int mul);
  83. void ff_bswap32_buf_ssse3(uint32_t *dst, const uint32_t *src, int w);
  84. void ff_bswap32_buf_sse2(uint32_t *dst, const uint32_t *src, int w);
  85. void ff_add_hfyu_median_prediction_mmxext(uint8_t *dst, const uint8_t *top,
  86. const uint8_t *diff, int w,
  87. int *left, int *left_top);
  88. int ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src,
  89. int w, int left);
  90. int ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src,
  91. int w, int left);
  92. void ff_vector_clip_int32_mmx (int32_t *dst, const int32_t *src,
  93. int32_t min, int32_t max, unsigned int len);
  94. void ff_vector_clip_int32_sse2 (int32_t *dst, const int32_t *src,
  95. int32_t min, int32_t max, unsigned int len);
  96. void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src,
  97. int32_t min, int32_t max, unsigned int len);
  98. void ff_vector_clip_int32_sse4 (int32_t *dst, const int32_t *src,
  99. int32_t min, int32_t max, unsigned int len);
  100. #if HAVE_YASM
  101. PIXELS16(static, ff_avg, , , _mmxext)
  102. PIXELS16(static, ff_put, , , _mmxext)
  103. #define QPEL_OP(OPNAME, RND, MMX) \
  104. static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
  105. ptrdiff_t stride) \
  106. { \
  107. ff_ ## OPNAME ## pixels8_ ## MMX(dst, src, stride, 8); \
  108. } \
  109. \
  110. static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
  111. ptrdiff_t stride) \
  112. { \
  113. uint64_t temp[8]; \
  114. uint8_t * const half = (uint8_t*)temp; \
  115. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
  116. stride, 8); \
  117. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
  118. stride, stride, 8); \
  119. } \
  120. \
  121. static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
  122. ptrdiff_t stride) \
  123. { \
  124. ff_ ## OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, \
  125. stride, 8); \
  126. } \
  127. \
  128. static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
  129. ptrdiff_t stride) \
  130. { \
  131. uint64_t temp[8]; \
  132. uint8_t * const half = (uint8_t*)temp; \
  133. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
  134. stride, 8); \
  135. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + 1, half, stride, \
  136. stride, 8); \
  137. } \
  138. \
  139. static void OPNAME ## qpel8_mc01_ ## 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_v_lowpass_ ## MMX(half, src, \
  145. 8, stride); \
  146. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
  147. stride, stride, 8); \
  148. } \
  149. \
  150. static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
  151. ptrdiff_t stride) \
  152. { \
  153. ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, \
  154. stride, stride); \
  155. } \
  156. \
  157. static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
  158. ptrdiff_t stride) \
  159. { \
  160. uint64_t temp[8]; \
  161. uint8_t * const half = (uint8_t*)temp; \
  162. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, \
  163. 8, stride); \
  164. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + stride, half, stride,\
  165. stride, 8); \
  166. } \
  167. \
  168. static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
  169. ptrdiff_t stride) \
  170. { \
  171. uint64_t half[8 + 9]; \
  172. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  173. uint8_t * const halfHV = ((uint8_t*)half); \
  174. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  175. stride, 9); \
  176. ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, \
  177. stride, 9); \
  178. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  179. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
  180. stride, 8, 8); \
  181. } \
  182. \
  183. static void OPNAME ## qpel8_mc31_ ## 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 + 1, 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_mc13_ ## 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, 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 + 8, halfHV, \
  210. stride, 8, 8); \
  211. } \
  212. \
  213. static void OPNAME ## qpel8_mc33_ ## 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 + 1, 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_mc21_ ## 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 ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  237. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
  238. stride, 8, 8); \
  239. } \
  240. \
  241. static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
  242. ptrdiff_t stride) \
  243. { \
  244. uint64_t half[8 + 9]; \
  245. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  246. uint8_t * const halfHV = ((uint8_t*)half); \
  247. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  248. stride, 9); \
  249. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  250. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
  251. stride, 8, 8); \
  252. } \
  253. \
  254. static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
  255. ptrdiff_t stride) \
  256. { \
  257. uint64_t half[8 + 9]; \
  258. uint8_t * const halfH = ((uint8_t*)half); \
  259. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  260. stride, 9); \
  261. ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, \
  262. 8, stride, 9); \
  263. ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
  264. stride, 8); \
  265. } \
  266. \
  267. static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
  268. ptrdiff_t stride) \
  269. { \
  270. uint64_t half[8 + 9]; \
  271. uint8_t * const halfH = ((uint8_t*)half); \
  272. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  273. stride, 9); \
  274. ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
  275. stride, 9); \
  276. ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
  277. stride, 8); \
  278. } \
  279. \
  280. static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
  281. ptrdiff_t stride) \
  282. { \
  283. uint64_t half[9]; \
  284. uint8_t * const halfH = ((uint8_t*)half); \
  285. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  286. stride, 9); \
  287. ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
  288. stride, 8); \
  289. } \
  290. \
  291. static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
  292. ptrdiff_t stride) \
  293. { \
  294. ff_ ## OPNAME ## pixels16_ ## MMX(dst, src, stride, 16); \
  295. } \
  296. \
  297. static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
  298. ptrdiff_t stride) \
  299. { \
  300. uint64_t temp[32]; \
  301. uint8_t * const half = (uint8_t*)temp; \
  302. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
  303. stride, 16); \
  304. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
  305. stride, 16); \
  306. } \
  307. \
  308. static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
  309. ptrdiff_t stride) \
  310. { \
  311. ff_ ## OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, \
  312. stride, stride, 16);\
  313. } \
  314. \
  315. static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
  316. ptrdiff_t stride) \
  317. { \
  318. uint64_t temp[32]; \
  319. uint8_t * const half = (uint8_t*)temp; \
  320. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
  321. stride, 16); \
  322. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src + 1, half, \
  323. stride, stride, 16); \
  324. } \
  325. \
  326. static void OPNAME ## qpel16_mc01_ ## 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_v_lowpass_ ## MMX(half, src, 16, \
  332. stride); \
  333. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
  334. stride, 16); \
  335. } \
  336. \
  337. static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
  338. ptrdiff_t stride) \
  339. { \
  340. ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, \
  341. stride, stride); \
  342. } \
  343. \
  344. static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
  345. ptrdiff_t stride) \
  346. { \
  347. uint64_t temp[32]; \
  348. uint8_t * const half = (uint8_t*)temp; \
  349. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
  350. stride); \
  351. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, \
  352. stride, stride, 16); \
  353. } \
  354. \
  355. static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
  356. ptrdiff_t stride) \
  357. { \
  358. uint64_t half[16 * 2 + 17 * 2]; \
  359. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  360. uint8_t * const halfHV = ((uint8_t*)half); \
  361. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  362. stride, 17); \
  363. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
  364. stride, 17); \
  365. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  366. 16, 16); \
  367. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
  368. stride, 16, 16); \
  369. } \
  370. \
  371. static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
  372. ptrdiff_t stride) \
  373. { \
  374. uint64_t half[16 * 2 + 17 * 2]; \
  375. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  376. uint8_t * const halfHV = ((uint8_t*)half); \
  377. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  378. stride, 17); \
  379. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
  380. stride, 17); \
  381. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  382. 16, 16); \
  383. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
  384. stride, 16, 16); \
  385. } \
  386. \
  387. static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
  388. ptrdiff_t stride) \
  389. { \
  390. uint64_t half[16 * 2 + 17 * 2]; \
  391. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  392. uint8_t * const halfHV = ((uint8_t*)half); \
  393. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  394. stride, 17); \
  395. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
  396. stride, 17); \
  397. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  398. 16, 16); \
  399. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
  400. stride, 16, 16); \
  401. } \
  402. \
  403. static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
  404. ptrdiff_t stride) \
  405. { \
  406. uint64_t half[16 * 2 + 17 * 2]; \
  407. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  408. uint8_t * const halfHV = ((uint8_t*)half); \
  409. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  410. stride, 17); \
  411. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
  412. stride, 17); \
  413. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  414. 16, 16); \
  415. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
  416. stride, 16, 16); \
  417. } \
  418. \
  419. static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
  420. ptrdiff_t stride) \
  421. { \
  422. uint64_t half[16 * 2 + 17 * 2]; \
  423. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  424. uint8_t * const halfHV = ((uint8_t*)half); \
  425. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  426. stride, 17); \
  427. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  428. 16, 16); \
  429. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
  430. stride, 16, 16); \
  431. } \
  432. \
  433. static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
  434. ptrdiff_t stride) \
  435. { \
  436. uint64_t half[16 * 2 + 17 * 2]; \
  437. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  438. uint8_t * const halfHV = ((uint8_t*)half); \
  439. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  440. stride, 17); \
  441. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  442. 16, 16); \
  443. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
  444. stride, 16, 16); \
  445. } \
  446. \
  447. static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
  448. ptrdiff_t stride) \
  449. { \
  450. uint64_t half[17 * 2]; \
  451. uint8_t * const halfH = ((uint8_t*)half); \
  452. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  453. stride, 17); \
  454. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
  455. stride, 17); \
  456. ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
  457. stride, 16); \
  458. } \
  459. \
  460. static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
  461. ptrdiff_t stride) \
  462. { \
  463. uint64_t half[17 * 2]; \
  464. uint8_t * const halfH = ((uint8_t*)half); \
  465. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  466. stride, 17); \
  467. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
  468. stride, 17); \
  469. ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
  470. stride, 16); \
  471. } \
  472. \
  473. static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
  474. ptrdiff_t stride) \
  475. { \
  476. uint64_t half[17 * 2]; \
  477. uint8_t * const halfH = ((uint8_t*)half); \
  478. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  479. stride, 17); \
  480. ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
  481. stride, 16); \
  482. }
  483. QPEL_OP(put_, _, mmxext)
  484. QPEL_OP(avg_, _, mmxext)
  485. QPEL_OP(put_no_rnd_, _no_rnd_, mmxext)
  486. #endif /* HAVE_YASM */
  487. #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \
  488. do { \
  489. c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
  490. c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
  491. c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
  492. c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
  493. c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
  494. c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
  495. c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
  496. c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
  497. c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
  498. c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
  499. c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
  500. c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
  501. c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
  502. c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
  503. c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
  504. c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \
  505. } while (0)
  506. static av_cold void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx,
  507. int cpu_flags)
  508. {
  509. #if HAVE_MMX_INLINE
  510. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  511. c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
  512. c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
  513. c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
  514. if (!high_bit_depth) {
  515. c->clear_block = ff_clear_block_mmx;
  516. c->clear_blocks = ff_clear_blocks_mmx;
  517. c->draw_edges = ff_draw_edges_mmx;
  518. switch (avctx->idct_algo) {
  519. case FF_IDCT_AUTO:
  520. case FF_IDCT_SIMPLEMMX:
  521. c->idct_put = ff_simple_idct_put_mmx;
  522. c->idct_add = ff_simple_idct_add_mmx;
  523. c->idct = ff_simple_idct_mmx;
  524. c->idct_permutation_type = FF_SIMPLE_IDCT_PERM;
  525. break;
  526. case FF_IDCT_XVIDMMX:
  527. c->idct_put = ff_idct_xvid_mmx_put;
  528. c->idct_add = ff_idct_xvid_mmx_add;
  529. c->idct = ff_idct_xvid_mmx;
  530. break;
  531. }
  532. }
  533. c->gmc = ff_gmc_mmx;
  534. c->add_bytes = ff_add_bytes_mmx;
  535. #endif /* HAVE_MMX_INLINE */
  536. #if HAVE_MMX_EXTERNAL
  537. c->vector_clip_int32 = ff_vector_clip_int32_mmx;
  538. #endif /* HAVE_MMX_EXTERNAL */
  539. }
  540. static av_cold void dsputil_init_mmxext(DSPContext *c, AVCodecContext *avctx,
  541. int cpu_flags)
  542. {
  543. #if HAVE_MMXEXT_INLINE
  544. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  545. if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX) {
  546. c->idct_put = ff_idct_xvid_mmxext_put;
  547. c->idct_add = ff_idct_xvid_mmxext_add;
  548. c->idct = ff_idct_xvid_mmxext;
  549. }
  550. #endif /* HAVE_MMXEXT_INLINE */
  551. #if HAVE_MMXEXT_EXTERNAL
  552. SET_QPEL_FUNCS(avg_qpel, 0, 16, mmxext, );
  553. SET_QPEL_FUNCS(avg_qpel, 1, 8, mmxext, );
  554. SET_QPEL_FUNCS(put_qpel, 0, 16, mmxext, );
  555. SET_QPEL_FUNCS(put_qpel, 1, 8, mmxext, );
  556. SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmxext, );
  557. SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmxext, );
  558. /* slower than cmov version on AMD */
  559. if (!(cpu_flags & AV_CPU_FLAG_3DNOW))
  560. c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmxext;
  561. c->scalarproduct_int16 = ff_scalarproduct_int16_mmxext;
  562. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmxext;
  563. #endif /* HAVE_MMXEXT_EXTERNAL */
  564. }
  565. static av_cold void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx,
  566. int cpu_flags)
  567. {
  568. #if HAVE_SSE_INLINE
  569. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  570. c->vector_clipf = ff_vector_clipf_sse;
  571. #if FF_API_XVMC
  572. FF_DISABLE_DEPRECATION_WARNINGS
  573. /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
  574. if (CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1)
  575. return;
  576. FF_ENABLE_DEPRECATION_WARNINGS
  577. #endif /* FF_API_XVMC */
  578. if (!high_bit_depth) {
  579. c->clear_block = ff_clear_block_sse;
  580. c->clear_blocks = ff_clear_blocks_sse;
  581. }
  582. #endif /* HAVE_SSE_INLINE */
  583. }
  584. static av_cold void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
  585. int cpu_flags)
  586. {
  587. #if HAVE_SSE2_INLINE
  588. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  589. if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX) {
  590. c->idct_put = ff_idct_xvid_sse2_put;
  591. c->idct_add = ff_idct_xvid_sse2_add;
  592. c->idct = ff_idct_xvid_sse2;
  593. c->idct_permutation_type = FF_SSE2_IDCT_PERM;
  594. }
  595. #endif /* HAVE_SSE2_INLINE */
  596. #if HAVE_SSE2_EXTERNAL
  597. c->scalarproduct_int16 = ff_scalarproduct_int16_sse2;
  598. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2;
  599. if (cpu_flags & AV_CPU_FLAG_ATOM) {
  600. c->vector_clip_int32 = ff_vector_clip_int32_int_sse2;
  601. } else {
  602. c->vector_clip_int32 = ff_vector_clip_int32_sse2;
  603. }
  604. c->bswap_buf = ff_bswap32_buf_sse2;
  605. #endif /* HAVE_SSE2_EXTERNAL */
  606. }
  607. static av_cold void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
  608. int cpu_flags)
  609. {
  610. #if HAVE_SSSE3_EXTERNAL
  611. c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
  612. if (cpu_flags & AV_CPU_FLAG_SSE4) // not really SSE4, just slow on Conroe
  613. c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
  614. if (!(cpu_flags & (AV_CPU_FLAG_SSE42 | AV_CPU_FLAG_3DNOW))) // cachesplit
  615. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3;
  616. c->bswap_buf = ff_bswap32_buf_ssse3;
  617. #endif /* HAVE_SSSE3_EXTERNAL */
  618. }
  619. static av_cold void dsputil_init_sse4(DSPContext *c, AVCodecContext *avctx,
  620. int cpu_flags)
  621. {
  622. #if HAVE_SSE4_EXTERNAL
  623. c->vector_clip_int32 = ff_vector_clip_int32_sse4;
  624. #endif /* HAVE_SSE4_EXTERNAL */
  625. }
  626. av_cold void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx)
  627. {
  628. int cpu_flags = av_get_cpu_flags();
  629. #if HAVE_7REGS && HAVE_INLINE_ASM
  630. if (cpu_flags & AV_CPU_FLAG_CMOV)
  631. c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_cmov;
  632. #endif
  633. if (X86_MMX(cpu_flags))
  634. dsputil_init_mmx(c, avctx, cpu_flags);
  635. if (X86_MMXEXT(cpu_flags))
  636. dsputil_init_mmxext(c, avctx, cpu_flags);
  637. if (X86_SSE(cpu_flags))
  638. dsputil_init_sse(c, avctx, cpu_flags);
  639. if (X86_SSE2(cpu_flags))
  640. dsputil_init_sse2(c, avctx, cpu_flags);
  641. if (EXTERNAL_SSSE3(cpu_flags))
  642. dsputil_init_ssse3(c, avctx, cpu_flags);
  643. if (EXTERNAL_SSE4(cpu_flags))
  644. dsputil_init_sse4(c, avctx, cpu_flags);
  645. if (CONFIG_ENCODERS)
  646. ff_dsputilenc_init_mmx(c, avctx);
  647. }