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