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.

699 lines
41KB

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