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.

664 lines
40KB

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