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.

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