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.

825 lines
36KB

  1. /*
  2. * VC-1 and WMV3 - DSP functions MMX-optimized
  3. * Copyright (c) 2007 Christophe GISQUET <christophe.gisquet@free.fr>
  4. *
  5. * Permission is hereby granted, free of charge, to any person
  6. * obtaining a copy of this software and associated documentation
  7. * files (the "Software"), to deal in the Software without
  8. * restriction, including without limitation the rights to use,
  9. * copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following
  12. * conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  19. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  21. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  22. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  23. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  24. * OTHER DEALINGS IN THE SOFTWARE.
  25. */
  26. #include "libavutil/cpu.h"
  27. #include "libavutil/x86_cpu.h"
  28. #include "libavcodec/dsputil.h"
  29. #include "dsputil_mmx.h"
  30. #include "libavcodec/vc1dsp.h"
  31. #if HAVE_INLINE_ASM
  32. #define OP_PUT(S,D)
  33. #define OP_AVG(S,D) "pavgb " #S ", " #D " \n\t"
  34. /** Add rounder from mm7 to mm3 and pack result at destination */
  35. #define NORMALIZE_MMX(SHIFT) \
  36. "paddw %%mm7, %%mm3 \n\t" /* +bias-r */ \
  37. "paddw %%mm7, %%mm4 \n\t" /* +bias-r */ \
  38. "psraw "SHIFT", %%mm3 \n\t" \
  39. "psraw "SHIFT", %%mm4 \n\t"
  40. #define TRANSFER_DO_PACK(OP) \
  41. "packuswb %%mm4, %%mm3 \n\t" \
  42. OP((%2), %%mm3) \
  43. "movq %%mm3, (%2) \n\t"
  44. #define TRANSFER_DONT_PACK(OP) \
  45. OP(0(%2), %%mm3) \
  46. OP(8(%2), %%mm4) \
  47. "movq %%mm3, 0(%2) \n\t" \
  48. "movq %%mm4, 8(%2) \n\t"
  49. /** @see MSPEL_FILTER13_CORE for use as UNPACK macro */
  50. #define DO_UNPACK(reg) "punpcklbw %%mm0, " reg "\n\t"
  51. #define DONT_UNPACK(reg)
  52. /** Compute the rounder 32-r or 8-r and unpacks it to mm7 */
  53. #define LOAD_ROUNDER_MMX(ROUND) \
  54. "movd "ROUND", %%mm7 \n\t" \
  55. "punpcklwd %%mm7, %%mm7 \n\t" \
  56. "punpckldq %%mm7, %%mm7 \n\t"
  57. #define SHIFT2_LINE(OFF, R0,R1,R2,R3) \
  58. "paddw %%mm"#R2", %%mm"#R1" \n\t" \
  59. "movd (%0,%3), %%mm"#R0" \n\t" \
  60. "pmullw %%mm6, %%mm"#R1" \n\t" \
  61. "punpcklbw %%mm0, %%mm"#R0" \n\t" \
  62. "movd (%0,%2), %%mm"#R3" \n\t" \
  63. "psubw %%mm"#R0", %%mm"#R1" \n\t" \
  64. "punpcklbw %%mm0, %%mm"#R3" \n\t" \
  65. "paddw %%mm7, %%mm"#R1" \n\t" \
  66. "psubw %%mm"#R3", %%mm"#R1" \n\t" \
  67. "psraw %4, %%mm"#R1" \n\t" \
  68. "movq %%mm"#R1", "#OFF"(%1) \n\t" \
  69. "add %2, %0 \n\t"
  70. /** Sacrifying mm6 allows to pipeline loads from src */
  71. static void vc1_put_ver_16b_shift2_mmx(int16_t *dst,
  72. const uint8_t *src, x86_reg stride,
  73. int rnd, int64_t shift)
  74. {
  75. __asm__ volatile(
  76. "mov $3, %%"REG_c" \n\t"
  77. LOAD_ROUNDER_MMX("%5")
  78. "movq "MANGLE(ff_pw_9)", %%mm6 \n\t"
  79. "1: \n\t"
  80. "movd (%0), %%mm2 \n\t"
  81. "add %2, %0 \n\t"
  82. "movd (%0), %%mm3 \n\t"
  83. "punpcklbw %%mm0, %%mm2 \n\t"
  84. "punpcklbw %%mm0, %%mm3 \n\t"
  85. SHIFT2_LINE( 0, 1, 2, 3, 4)
  86. SHIFT2_LINE( 24, 2, 3, 4, 1)
  87. SHIFT2_LINE( 48, 3, 4, 1, 2)
  88. SHIFT2_LINE( 72, 4, 1, 2, 3)
  89. SHIFT2_LINE( 96, 1, 2, 3, 4)
  90. SHIFT2_LINE(120, 2, 3, 4, 1)
  91. SHIFT2_LINE(144, 3, 4, 1, 2)
  92. SHIFT2_LINE(168, 4, 1, 2, 3)
  93. "sub %6, %0 \n\t"
  94. "add $8, %1 \n\t"
  95. "dec %%"REG_c" \n\t"
  96. "jnz 1b \n\t"
  97. : "+r"(src), "+r"(dst)
  98. : "r"(stride), "r"(-2*stride),
  99. "m"(shift), "m"(rnd), "r"(9*stride-4)
  100. : "%"REG_c, "memory"
  101. );
  102. }
  103. /**
  104. * Data is already unpacked, so some operations can directly be made from
  105. * memory.
  106. */
  107. #define VC1_HOR_16b_SHIFT2(OP, OPNAME)\
  108. static void OPNAME ## vc1_hor_16b_shift2_mmx(uint8_t *dst, x86_reg stride,\
  109. const int16_t *src, int rnd)\
  110. {\
  111. int h = 8;\
  112. \
  113. src -= 1;\
  114. rnd -= (-1+9+9-1)*1024; /* Add -1024 bias */\
  115. __asm__ volatile(\
  116. LOAD_ROUNDER_MMX("%4")\
  117. "movq "MANGLE(ff_pw_128)", %%mm6\n\t"\
  118. "movq "MANGLE(ff_pw_9)", %%mm5 \n\t"\
  119. "1: \n\t"\
  120. "movq 2*0+0(%1), %%mm1 \n\t"\
  121. "movq 2*0+8(%1), %%mm2 \n\t"\
  122. "movq 2*1+0(%1), %%mm3 \n\t"\
  123. "movq 2*1+8(%1), %%mm4 \n\t"\
  124. "paddw 2*3+0(%1), %%mm1 \n\t"\
  125. "paddw 2*3+8(%1), %%mm2 \n\t"\
  126. "paddw 2*2+0(%1), %%mm3 \n\t"\
  127. "paddw 2*2+8(%1), %%mm4 \n\t"\
  128. "pmullw %%mm5, %%mm3 \n\t"\
  129. "pmullw %%mm5, %%mm4 \n\t"\
  130. "psubw %%mm1, %%mm3 \n\t"\
  131. "psubw %%mm2, %%mm4 \n\t"\
  132. NORMALIZE_MMX("$7")\
  133. /* Remove bias */\
  134. "paddw %%mm6, %%mm3 \n\t"\
  135. "paddw %%mm6, %%mm4 \n\t"\
  136. TRANSFER_DO_PACK(OP)\
  137. "add $24, %1 \n\t"\
  138. "add %3, %2 \n\t"\
  139. "decl %0 \n\t"\
  140. "jnz 1b \n\t"\
  141. : "+r"(h), "+r" (src), "+r" (dst)\
  142. : "r"(stride), "m"(rnd)\
  143. : "memory"\
  144. );\
  145. }
  146. VC1_HOR_16b_SHIFT2(OP_PUT, put_)
  147. VC1_HOR_16b_SHIFT2(OP_AVG, avg_)
  148. /**
  149. * Purely vertical or horizontal 1/2 shift interpolation.
  150. * Sacrify mm6 for *9 factor.
  151. */
  152. #define VC1_SHIFT2(OP, OPNAME)\
  153. static void OPNAME ## vc1_shift2_mmx(uint8_t *dst, const uint8_t *src,\
  154. x86_reg stride, int rnd, x86_reg offset)\
  155. {\
  156. rnd = 8-rnd;\
  157. __asm__ volatile(\
  158. "mov $8, %%"REG_c" \n\t"\
  159. LOAD_ROUNDER_MMX("%5")\
  160. "movq "MANGLE(ff_pw_9)", %%mm6\n\t"\
  161. "1: \n\t"\
  162. "movd 0(%0 ), %%mm3 \n\t"\
  163. "movd 4(%0 ), %%mm4 \n\t"\
  164. "movd 0(%0,%2), %%mm1 \n\t"\
  165. "movd 4(%0,%2), %%mm2 \n\t"\
  166. "add %2, %0 \n\t"\
  167. "punpcklbw %%mm0, %%mm3 \n\t"\
  168. "punpcklbw %%mm0, %%mm4 \n\t"\
  169. "punpcklbw %%mm0, %%mm1 \n\t"\
  170. "punpcklbw %%mm0, %%mm2 \n\t"\
  171. "paddw %%mm1, %%mm3 \n\t"\
  172. "paddw %%mm2, %%mm4 \n\t"\
  173. "movd 0(%0,%3), %%mm1 \n\t"\
  174. "movd 4(%0,%3), %%mm2 \n\t"\
  175. "pmullw %%mm6, %%mm3 \n\t" /* 0,9,9,0*/\
  176. "pmullw %%mm6, %%mm4 \n\t" /* 0,9,9,0*/\
  177. "punpcklbw %%mm0, %%mm1 \n\t"\
  178. "punpcklbw %%mm0, %%mm2 \n\t"\
  179. "psubw %%mm1, %%mm3 \n\t" /*-1,9,9,0*/\
  180. "psubw %%mm2, %%mm4 \n\t" /*-1,9,9,0*/\
  181. "movd 0(%0,%2), %%mm1 \n\t"\
  182. "movd 4(%0,%2), %%mm2 \n\t"\
  183. "punpcklbw %%mm0, %%mm1 \n\t"\
  184. "punpcklbw %%mm0, %%mm2 \n\t"\
  185. "psubw %%mm1, %%mm3 \n\t" /*-1,9,9,-1*/\
  186. "psubw %%mm2, %%mm4 \n\t" /*-1,9,9,-1*/\
  187. NORMALIZE_MMX("$4")\
  188. "packuswb %%mm4, %%mm3 \n\t"\
  189. OP((%1), %%mm3)\
  190. "movq %%mm3, (%1) \n\t"\
  191. "add %6, %0 \n\t"\
  192. "add %4, %1 \n\t"\
  193. "dec %%"REG_c" \n\t"\
  194. "jnz 1b \n\t"\
  195. : "+r"(src), "+r"(dst)\
  196. : "r"(offset), "r"(-2*offset), "g"(stride), "m"(rnd),\
  197. "g"(stride-offset)\
  198. : "%"REG_c, "memory"\
  199. );\
  200. }
  201. VC1_SHIFT2(OP_PUT, put_)
  202. VC1_SHIFT2(OP_AVG, avg_)
  203. /**
  204. * Core of the 1/4 and 3/4 shift bicubic interpolation.
  205. *
  206. * @param UNPACK Macro unpacking arguments from 8 to 16bits (can be empty).
  207. * @param MOVQ "movd 1" or "movq 2", if data read is already unpacked.
  208. * @param A1 Address of 1st tap (beware of unpacked/packed).
  209. * @param A2 Address of 2nd tap
  210. * @param A3 Address of 3rd tap
  211. * @param A4 Address of 4th tap
  212. */
  213. #define MSPEL_FILTER13_CORE(UNPACK, MOVQ, A1, A2, A3, A4) \
  214. MOVQ "*0+"A1", %%mm1 \n\t" \
  215. MOVQ "*4+"A1", %%mm2 \n\t" \
  216. UNPACK("%%mm1") \
  217. UNPACK("%%mm2") \
  218. "pmullw "MANGLE(ff_pw_3)", %%mm1\n\t" \
  219. "pmullw "MANGLE(ff_pw_3)", %%mm2\n\t" \
  220. MOVQ "*0+"A2", %%mm3 \n\t" \
  221. MOVQ "*4+"A2", %%mm4 \n\t" \
  222. UNPACK("%%mm3") \
  223. UNPACK("%%mm4") \
  224. "pmullw %%mm6, %%mm3 \n\t" /* *18 */ \
  225. "pmullw %%mm6, %%mm4 \n\t" /* *18 */ \
  226. "psubw %%mm1, %%mm3 \n\t" /* 18,-3 */ \
  227. "psubw %%mm2, %%mm4 \n\t" /* 18,-3 */ \
  228. MOVQ "*0+"A4", %%mm1 \n\t" \
  229. MOVQ "*4+"A4", %%mm2 \n\t" \
  230. UNPACK("%%mm1") \
  231. UNPACK("%%mm2") \
  232. "psllw $2, %%mm1 \n\t" /* 4* */ \
  233. "psllw $2, %%mm2 \n\t" /* 4* */ \
  234. "psubw %%mm1, %%mm3 \n\t" /* -4,18,-3 */ \
  235. "psubw %%mm2, %%mm4 \n\t" /* -4,18,-3 */ \
  236. MOVQ "*0+"A3", %%mm1 \n\t" \
  237. MOVQ "*4+"A3", %%mm2 \n\t" \
  238. UNPACK("%%mm1") \
  239. UNPACK("%%mm2") \
  240. "pmullw %%mm5, %%mm1 \n\t" /* *53 */ \
  241. "pmullw %%mm5, %%mm2 \n\t" /* *53 */ \
  242. "paddw %%mm1, %%mm3 \n\t" /* 4,53,18,-3 */ \
  243. "paddw %%mm2, %%mm4 \n\t" /* 4,53,18,-3 */
  244. /**
  245. * Macro to build the vertical 16bits version of vc1_put_shift[13].
  246. * Here, offset=src_stride. Parameters passed A1 to A4 must use
  247. * %3 (src_stride) and %4 (3*src_stride).
  248. *
  249. * @param NAME Either 1 or 3
  250. * @see MSPEL_FILTER13_CORE for information on A1->A4
  251. */
  252. #define MSPEL_FILTER13_VER_16B(NAME, A1, A2, A3, A4) \
  253. static void \
  254. vc1_put_ver_16b_ ## NAME ## _mmx(int16_t *dst, const uint8_t *src, \
  255. x86_reg src_stride, \
  256. int rnd, int64_t shift) \
  257. { \
  258. int h = 8; \
  259. src -= src_stride; \
  260. __asm__ volatile( \
  261. LOAD_ROUNDER_MMX("%5") \
  262. "movq "MANGLE(ff_pw_53)", %%mm5\n\t" \
  263. "movq "MANGLE(ff_pw_18)", %%mm6\n\t" \
  264. ".p2align 3 \n\t" \
  265. "1: \n\t" \
  266. MSPEL_FILTER13_CORE(DO_UNPACK, "movd 1", A1, A2, A3, A4) \
  267. NORMALIZE_MMX("%6") \
  268. TRANSFER_DONT_PACK(OP_PUT) \
  269. /* Last 3 (in fact 4) bytes on the line */ \
  270. "movd 8+"A1", %%mm1 \n\t" \
  271. DO_UNPACK("%%mm1") \
  272. "movq %%mm1, %%mm3 \n\t" \
  273. "paddw %%mm1, %%mm1 \n\t" \
  274. "paddw %%mm3, %%mm1 \n\t" /* 3* */ \
  275. "movd 8+"A2", %%mm3 \n\t" \
  276. DO_UNPACK("%%mm3") \
  277. "pmullw %%mm6, %%mm3 \n\t" /* *18 */ \
  278. "psubw %%mm1, %%mm3 \n\t" /*18,-3 */ \
  279. "movd 8+"A3", %%mm1 \n\t" \
  280. DO_UNPACK("%%mm1") \
  281. "pmullw %%mm5, %%mm1 \n\t" /* *53 */ \
  282. "paddw %%mm1, %%mm3 \n\t" /*53,18,-3 */ \
  283. "movd 8+"A4", %%mm1 \n\t" \
  284. DO_UNPACK("%%mm1") \
  285. "psllw $2, %%mm1 \n\t" /* 4* */ \
  286. "psubw %%mm1, %%mm3 \n\t" \
  287. "paddw %%mm7, %%mm3 \n\t" \
  288. "psraw %6, %%mm3 \n\t" \
  289. "movq %%mm3, 16(%2) \n\t" \
  290. "add %3, %1 \n\t" \
  291. "add $24, %2 \n\t" \
  292. "decl %0 \n\t" \
  293. "jnz 1b \n\t" \
  294. : "+r"(h), "+r" (src), "+r" (dst) \
  295. : "r"(src_stride), "r"(3*src_stride), \
  296. "m"(rnd), "m"(shift) \
  297. : "memory" \
  298. ); \
  299. }
  300. /**
  301. * Macro to build the horizontal 16bits version of vc1_put_shift[13].
  302. * Here, offset=16bits, so parameters passed A1 to A4 should be simple.
  303. *
  304. * @param NAME Either 1 or 3
  305. * @see MSPEL_FILTER13_CORE for information on A1->A4
  306. */
  307. #define MSPEL_FILTER13_HOR_16B(NAME, A1, A2, A3, A4, OP, OPNAME) \
  308. static void \
  309. OPNAME ## vc1_hor_16b_ ## NAME ## _mmx(uint8_t *dst, x86_reg stride, \
  310. const int16_t *src, int rnd) \
  311. { \
  312. int h = 8; \
  313. src -= 1; \
  314. rnd -= (-4+58+13-3)*256; /* Add -256 bias */ \
  315. __asm__ volatile( \
  316. LOAD_ROUNDER_MMX("%4") \
  317. "movq "MANGLE(ff_pw_18)", %%mm6 \n\t" \
  318. "movq "MANGLE(ff_pw_53)", %%mm5 \n\t" \
  319. ".p2align 3 \n\t" \
  320. "1: \n\t" \
  321. MSPEL_FILTER13_CORE(DONT_UNPACK, "movq 2", A1, A2, A3, A4) \
  322. NORMALIZE_MMX("$7") \
  323. /* Remove bias */ \
  324. "paddw "MANGLE(ff_pw_128)", %%mm3 \n\t" \
  325. "paddw "MANGLE(ff_pw_128)", %%mm4 \n\t" \
  326. TRANSFER_DO_PACK(OP) \
  327. "add $24, %1 \n\t" \
  328. "add %3, %2 \n\t" \
  329. "decl %0 \n\t" \
  330. "jnz 1b \n\t" \
  331. : "+r"(h), "+r" (src), "+r" (dst) \
  332. : "r"(stride), "m"(rnd) \
  333. : "memory" \
  334. ); \
  335. }
  336. /**
  337. * Macro to build the 8bits, any direction, version of vc1_put_shift[13].
  338. * Here, offset=src_stride. Parameters passed A1 to A4 must use
  339. * %3 (offset) and %4 (3*offset).
  340. *
  341. * @param NAME Either 1 or 3
  342. * @see MSPEL_FILTER13_CORE for information on A1->A4
  343. */
  344. #define MSPEL_FILTER13_8B(NAME, A1, A2, A3, A4, OP, OPNAME) \
  345. static void \
  346. OPNAME ## vc1_## NAME ## _mmx(uint8_t *dst, const uint8_t *src, \
  347. x86_reg stride, int rnd, x86_reg offset) \
  348. { \
  349. int h = 8; \
  350. src -= offset; \
  351. rnd = 32-rnd; \
  352. __asm__ volatile ( \
  353. LOAD_ROUNDER_MMX("%6") \
  354. "movq "MANGLE(ff_pw_53)", %%mm5 \n\t" \
  355. "movq "MANGLE(ff_pw_18)", %%mm6 \n\t" \
  356. ".p2align 3 \n\t" \
  357. "1: \n\t" \
  358. MSPEL_FILTER13_CORE(DO_UNPACK, "movd 1", A1, A2, A3, A4) \
  359. NORMALIZE_MMX("$6") \
  360. TRANSFER_DO_PACK(OP) \
  361. "add %5, %1 \n\t" \
  362. "add %5, %2 \n\t" \
  363. "decl %0 \n\t" \
  364. "jnz 1b \n\t" \
  365. : "+r"(h), "+r" (src), "+r" (dst) \
  366. : "r"(offset), "r"(3*offset), "g"(stride), "m"(rnd) \
  367. : "memory" \
  368. ); \
  369. }
  370. /** 1/4 shift bicubic interpolation */
  371. MSPEL_FILTER13_8B (shift1, "0(%1,%4 )", "0(%1,%3,2)", "0(%1,%3 )", "0(%1 )", OP_PUT, put_)
  372. MSPEL_FILTER13_8B (shift1, "0(%1,%4 )", "0(%1,%3,2)", "0(%1,%3 )", "0(%1 )", OP_AVG, avg_)
  373. MSPEL_FILTER13_VER_16B(shift1, "0(%1,%4 )", "0(%1,%3,2)", "0(%1,%3 )", "0(%1 )")
  374. MSPEL_FILTER13_HOR_16B(shift1, "2*3(%1)", "2*2(%1)", "2*1(%1)", "2*0(%1)", OP_PUT, put_)
  375. MSPEL_FILTER13_HOR_16B(shift1, "2*3(%1)", "2*2(%1)", "2*1(%1)", "2*0(%1)", OP_AVG, avg_)
  376. /** 3/4 shift bicubic interpolation */
  377. MSPEL_FILTER13_8B (shift3, "0(%1 )", "0(%1,%3 )", "0(%1,%3,2)", "0(%1,%4 )", OP_PUT, put_)
  378. MSPEL_FILTER13_8B (shift3, "0(%1 )", "0(%1,%3 )", "0(%1,%3,2)", "0(%1,%4 )", OP_AVG, avg_)
  379. MSPEL_FILTER13_VER_16B(shift3, "0(%1 )", "0(%1,%3 )", "0(%1,%3,2)", "0(%1,%4 )")
  380. MSPEL_FILTER13_HOR_16B(shift3, "2*0(%1)", "2*1(%1)", "2*2(%1)", "2*3(%1)", OP_PUT, put_)
  381. MSPEL_FILTER13_HOR_16B(shift3, "2*0(%1)", "2*1(%1)", "2*2(%1)", "2*3(%1)", OP_AVG, avg_)
  382. typedef void (*vc1_mspel_mc_filter_ver_16bits)(int16_t *dst, const uint8_t *src, x86_reg src_stride, int rnd, int64_t shift);
  383. typedef void (*vc1_mspel_mc_filter_hor_16bits)(uint8_t *dst, x86_reg dst_stride, const int16_t *src, int rnd);
  384. typedef void (*vc1_mspel_mc_filter_8bits)(uint8_t *dst, const uint8_t *src, x86_reg stride, int rnd, x86_reg offset);
  385. /**
  386. * Interpolate fractional pel values by applying proper vertical then
  387. * horizontal filter.
  388. *
  389. * @param dst Destination buffer for interpolated pels.
  390. * @param src Source buffer.
  391. * @param stride Stride for both src and dst buffers.
  392. * @param hmode Horizontal filter (expressed in quarter pixels shift).
  393. * @param hmode Vertical filter.
  394. * @param rnd Rounding bias.
  395. */
  396. #define VC1_MSPEL_MC(OP)\
  397. static void OP ## vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride,\
  398. int hmode, int vmode, int rnd)\
  399. {\
  400. static const vc1_mspel_mc_filter_ver_16bits vc1_put_shift_ver_16bits[] =\
  401. { NULL, vc1_put_ver_16b_shift1_mmx, vc1_put_ver_16b_shift2_mmx, vc1_put_ver_16b_shift3_mmx };\
  402. static const vc1_mspel_mc_filter_hor_16bits vc1_put_shift_hor_16bits[] =\
  403. { NULL, OP ## vc1_hor_16b_shift1_mmx, OP ## vc1_hor_16b_shift2_mmx, OP ## vc1_hor_16b_shift3_mmx };\
  404. static const vc1_mspel_mc_filter_8bits vc1_put_shift_8bits[] =\
  405. { NULL, OP ## vc1_shift1_mmx, OP ## vc1_shift2_mmx, OP ## vc1_shift3_mmx };\
  406. \
  407. __asm__ volatile(\
  408. "pxor %%mm0, %%mm0 \n\t"\
  409. ::: "memory"\
  410. );\
  411. \
  412. if (vmode) { /* Vertical filter to apply */\
  413. if (hmode) { /* Horizontal filter to apply, output to tmp */\
  414. static const int shift_value[] = { 0, 5, 1, 5 };\
  415. int shift = (shift_value[hmode]+shift_value[vmode])>>1;\
  416. int r;\
  417. DECLARE_ALIGNED(16, int16_t, tmp)[12*8];\
  418. \
  419. r = (1<<(shift-1)) + rnd-1;\
  420. vc1_put_shift_ver_16bits[vmode](tmp, src-1, stride, r, shift);\
  421. \
  422. vc1_put_shift_hor_16bits[hmode](dst, stride, tmp+1, 64-rnd);\
  423. return;\
  424. }\
  425. else { /* No horizontal filter, output 8 lines to dst */\
  426. vc1_put_shift_8bits[vmode](dst, src, stride, 1-rnd, stride);\
  427. return;\
  428. }\
  429. }\
  430. \
  431. /* Horizontal mode with no vertical mode */\
  432. vc1_put_shift_8bits[hmode](dst, src, stride, rnd, 1);\
  433. }
  434. VC1_MSPEL_MC(put_)
  435. VC1_MSPEL_MC(avg_)
  436. /** Macro to ease bicubic filter interpolation functions declarations */
  437. #define DECLARE_FUNCTION(a, b) \
  438. static void put_vc1_mspel_mc ## a ## b ## _mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd) { \
  439. put_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
  440. }\
  441. static void avg_vc1_mspel_mc ## a ## b ## _mmx2(uint8_t *dst, const uint8_t *src, int stride, int rnd) { \
  442. avg_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
  443. }
  444. DECLARE_FUNCTION(0, 1)
  445. DECLARE_FUNCTION(0, 2)
  446. DECLARE_FUNCTION(0, 3)
  447. DECLARE_FUNCTION(1, 0)
  448. DECLARE_FUNCTION(1, 1)
  449. DECLARE_FUNCTION(1, 2)
  450. DECLARE_FUNCTION(1, 3)
  451. DECLARE_FUNCTION(2, 0)
  452. DECLARE_FUNCTION(2, 1)
  453. DECLARE_FUNCTION(2, 2)
  454. DECLARE_FUNCTION(2, 3)
  455. DECLARE_FUNCTION(3, 0)
  456. DECLARE_FUNCTION(3, 1)
  457. DECLARE_FUNCTION(3, 2)
  458. DECLARE_FUNCTION(3, 3)
  459. static void vc1_inv_trans_4x4_dc_mmx2(uint8_t *dest, int linesize, DCTELEM *block)
  460. {
  461. int dc = block[0];
  462. dc = (17 * dc + 4) >> 3;
  463. dc = (17 * dc + 64) >> 7;
  464. __asm__ volatile(
  465. "movd %0, %%mm0 \n\t"
  466. "pshufw $0, %%mm0, %%mm0 \n\t"
  467. "pxor %%mm1, %%mm1 \n\t"
  468. "psubw %%mm0, %%mm1 \n\t"
  469. "packuswb %%mm0, %%mm0 \n\t"
  470. "packuswb %%mm1, %%mm1 \n\t"
  471. ::"r"(dc)
  472. );
  473. __asm__ volatile(
  474. "movd %0, %%mm2 \n\t"
  475. "movd %1, %%mm3 \n\t"
  476. "movd %2, %%mm4 \n\t"
  477. "movd %3, %%mm5 \n\t"
  478. "paddusb %%mm0, %%mm2 \n\t"
  479. "paddusb %%mm0, %%mm3 \n\t"
  480. "paddusb %%mm0, %%mm4 \n\t"
  481. "paddusb %%mm0, %%mm5 \n\t"
  482. "psubusb %%mm1, %%mm2 \n\t"
  483. "psubusb %%mm1, %%mm3 \n\t"
  484. "psubusb %%mm1, %%mm4 \n\t"
  485. "psubusb %%mm1, %%mm5 \n\t"
  486. "movd %%mm2, %0 \n\t"
  487. "movd %%mm3, %1 \n\t"
  488. "movd %%mm4, %2 \n\t"
  489. "movd %%mm5, %3 \n\t"
  490. :"+m"(*(uint32_t*)(dest+0*linesize)),
  491. "+m"(*(uint32_t*)(dest+1*linesize)),
  492. "+m"(*(uint32_t*)(dest+2*linesize)),
  493. "+m"(*(uint32_t*)(dest+3*linesize))
  494. );
  495. }
  496. static void vc1_inv_trans_4x8_dc_mmx2(uint8_t *dest, int linesize, DCTELEM *block)
  497. {
  498. int dc = block[0];
  499. dc = (17 * dc + 4) >> 3;
  500. dc = (12 * dc + 64) >> 7;
  501. __asm__ volatile(
  502. "movd %0, %%mm0 \n\t"
  503. "pshufw $0, %%mm0, %%mm0 \n\t"
  504. "pxor %%mm1, %%mm1 \n\t"
  505. "psubw %%mm0, %%mm1 \n\t"
  506. "packuswb %%mm0, %%mm0 \n\t"
  507. "packuswb %%mm1, %%mm1 \n\t"
  508. ::"r"(dc)
  509. );
  510. __asm__ volatile(
  511. "movd %0, %%mm2 \n\t"
  512. "movd %1, %%mm3 \n\t"
  513. "movd %2, %%mm4 \n\t"
  514. "movd %3, %%mm5 \n\t"
  515. "paddusb %%mm0, %%mm2 \n\t"
  516. "paddusb %%mm0, %%mm3 \n\t"
  517. "paddusb %%mm0, %%mm4 \n\t"
  518. "paddusb %%mm0, %%mm5 \n\t"
  519. "psubusb %%mm1, %%mm2 \n\t"
  520. "psubusb %%mm1, %%mm3 \n\t"
  521. "psubusb %%mm1, %%mm4 \n\t"
  522. "psubusb %%mm1, %%mm5 \n\t"
  523. "movd %%mm2, %0 \n\t"
  524. "movd %%mm3, %1 \n\t"
  525. "movd %%mm4, %2 \n\t"
  526. "movd %%mm5, %3 \n\t"
  527. :"+m"(*(uint32_t*)(dest+0*linesize)),
  528. "+m"(*(uint32_t*)(dest+1*linesize)),
  529. "+m"(*(uint32_t*)(dest+2*linesize)),
  530. "+m"(*(uint32_t*)(dest+3*linesize))
  531. );
  532. dest += 4*linesize;
  533. __asm__ volatile(
  534. "movd %0, %%mm2 \n\t"
  535. "movd %1, %%mm3 \n\t"
  536. "movd %2, %%mm4 \n\t"
  537. "movd %3, %%mm5 \n\t"
  538. "paddusb %%mm0, %%mm2 \n\t"
  539. "paddusb %%mm0, %%mm3 \n\t"
  540. "paddusb %%mm0, %%mm4 \n\t"
  541. "paddusb %%mm0, %%mm5 \n\t"
  542. "psubusb %%mm1, %%mm2 \n\t"
  543. "psubusb %%mm1, %%mm3 \n\t"
  544. "psubusb %%mm1, %%mm4 \n\t"
  545. "psubusb %%mm1, %%mm5 \n\t"
  546. "movd %%mm2, %0 \n\t"
  547. "movd %%mm3, %1 \n\t"
  548. "movd %%mm4, %2 \n\t"
  549. "movd %%mm5, %3 \n\t"
  550. :"+m"(*(uint32_t*)(dest+0*linesize)),
  551. "+m"(*(uint32_t*)(dest+1*linesize)),
  552. "+m"(*(uint32_t*)(dest+2*linesize)),
  553. "+m"(*(uint32_t*)(dest+3*linesize))
  554. );
  555. }
  556. static void vc1_inv_trans_8x4_dc_mmx2(uint8_t *dest, int linesize, DCTELEM *block)
  557. {
  558. int dc = block[0];
  559. dc = ( 3 * dc + 1) >> 1;
  560. dc = (17 * dc + 64) >> 7;
  561. __asm__ volatile(
  562. "movd %0, %%mm0 \n\t"
  563. "pshufw $0, %%mm0, %%mm0 \n\t"
  564. "pxor %%mm1, %%mm1 \n\t"
  565. "psubw %%mm0, %%mm1 \n\t"
  566. "packuswb %%mm0, %%mm0 \n\t"
  567. "packuswb %%mm1, %%mm1 \n\t"
  568. ::"r"(dc)
  569. );
  570. __asm__ volatile(
  571. "movq %0, %%mm2 \n\t"
  572. "movq %1, %%mm3 \n\t"
  573. "movq %2, %%mm4 \n\t"
  574. "movq %3, %%mm5 \n\t"
  575. "paddusb %%mm0, %%mm2 \n\t"
  576. "paddusb %%mm0, %%mm3 \n\t"
  577. "paddusb %%mm0, %%mm4 \n\t"
  578. "paddusb %%mm0, %%mm5 \n\t"
  579. "psubusb %%mm1, %%mm2 \n\t"
  580. "psubusb %%mm1, %%mm3 \n\t"
  581. "psubusb %%mm1, %%mm4 \n\t"
  582. "psubusb %%mm1, %%mm5 \n\t"
  583. "movq %%mm2, %0 \n\t"
  584. "movq %%mm3, %1 \n\t"
  585. "movq %%mm4, %2 \n\t"
  586. "movq %%mm5, %3 \n\t"
  587. :"+m"(*(uint32_t*)(dest+0*linesize)),
  588. "+m"(*(uint32_t*)(dest+1*linesize)),
  589. "+m"(*(uint32_t*)(dest+2*linesize)),
  590. "+m"(*(uint32_t*)(dest+3*linesize))
  591. );
  592. }
  593. static void vc1_inv_trans_8x8_dc_mmx2(uint8_t *dest, int linesize, DCTELEM *block)
  594. {
  595. int dc = block[0];
  596. dc = (3 * dc + 1) >> 1;
  597. dc = (3 * dc + 16) >> 5;
  598. __asm__ volatile(
  599. "movd %0, %%mm0 \n\t"
  600. "pshufw $0, %%mm0, %%mm0 \n\t"
  601. "pxor %%mm1, %%mm1 \n\t"
  602. "psubw %%mm0, %%mm1 \n\t"
  603. "packuswb %%mm0, %%mm0 \n\t"
  604. "packuswb %%mm1, %%mm1 \n\t"
  605. ::"r"(dc)
  606. );
  607. __asm__ volatile(
  608. "movq %0, %%mm2 \n\t"
  609. "movq %1, %%mm3 \n\t"
  610. "movq %2, %%mm4 \n\t"
  611. "movq %3, %%mm5 \n\t"
  612. "paddusb %%mm0, %%mm2 \n\t"
  613. "paddusb %%mm0, %%mm3 \n\t"
  614. "paddusb %%mm0, %%mm4 \n\t"
  615. "paddusb %%mm0, %%mm5 \n\t"
  616. "psubusb %%mm1, %%mm2 \n\t"
  617. "psubusb %%mm1, %%mm3 \n\t"
  618. "psubusb %%mm1, %%mm4 \n\t"
  619. "psubusb %%mm1, %%mm5 \n\t"
  620. "movq %%mm2, %0 \n\t"
  621. "movq %%mm3, %1 \n\t"
  622. "movq %%mm4, %2 \n\t"
  623. "movq %%mm5, %3 \n\t"
  624. :"+m"(*(uint32_t*)(dest+0*linesize)),
  625. "+m"(*(uint32_t*)(dest+1*linesize)),
  626. "+m"(*(uint32_t*)(dest+2*linesize)),
  627. "+m"(*(uint32_t*)(dest+3*linesize))
  628. );
  629. dest += 4*linesize;
  630. __asm__ volatile(
  631. "movq %0, %%mm2 \n\t"
  632. "movq %1, %%mm3 \n\t"
  633. "movq %2, %%mm4 \n\t"
  634. "movq %3, %%mm5 \n\t"
  635. "paddusb %%mm0, %%mm2 \n\t"
  636. "paddusb %%mm0, %%mm3 \n\t"
  637. "paddusb %%mm0, %%mm4 \n\t"
  638. "paddusb %%mm0, %%mm5 \n\t"
  639. "psubusb %%mm1, %%mm2 \n\t"
  640. "psubusb %%mm1, %%mm3 \n\t"
  641. "psubusb %%mm1, %%mm4 \n\t"
  642. "psubusb %%mm1, %%mm5 \n\t"
  643. "movq %%mm2, %0 \n\t"
  644. "movq %%mm3, %1 \n\t"
  645. "movq %%mm4, %2 \n\t"
  646. "movq %%mm5, %3 \n\t"
  647. :"+m"(*(uint32_t*)(dest+0*linesize)),
  648. "+m"(*(uint32_t*)(dest+1*linesize)),
  649. "+m"(*(uint32_t*)(dest+2*linesize)),
  650. "+m"(*(uint32_t*)(dest+3*linesize))
  651. );
  652. }
  653. #endif /* HAVE_INLINE_ASM */
  654. #define LOOP_FILTER(EXT) \
  655. void ff_vc1_v_loop_filter4_ ## EXT(uint8_t *src, int stride, int pq); \
  656. void ff_vc1_h_loop_filter4_ ## EXT(uint8_t *src, int stride, int pq); \
  657. void ff_vc1_v_loop_filter8_ ## EXT(uint8_t *src, int stride, int pq); \
  658. void ff_vc1_h_loop_filter8_ ## EXT(uint8_t *src, int stride, int pq); \
  659. \
  660. static void vc1_v_loop_filter16_ ## EXT(uint8_t *src, int stride, int pq) \
  661. { \
  662. ff_vc1_v_loop_filter8_ ## EXT(src, stride, pq); \
  663. ff_vc1_v_loop_filter8_ ## EXT(src+8, stride, pq); \
  664. } \
  665. \
  666. static void vc1_h_loop_filter16_ ## EXT(uint8_t *src, int stride, int pq) \
  667. { \
  668. ff_vc1_h_loop_filter8_ ## EXT(src, stride, pq); \
  669. ff_vc1_h_loop_filter8_ ## EXT(src+8*stride, stride, pq); \
  670. }
  671. #if HAVE_YASM
  672. LOOP_FILTER(mmx2)
  673. LOOP_FILTER(sse2)
  674. LOOP_FILTER(ssse3)
  675. void ff_vc1_h_loop_filter8_sse4(uint8_t *src, int stride, int pq);
  676. static void vc1_h_loop_filter16_sse4(uint8_t *src, int stride, int pq)
  677. {
  678. ff_vc1_h_loop_filter8_sse4(src, stride, pq);
  679. ff_vc1_h_loop_filter8_sse4(src+8*stride, stride, pq);
  680. }
  681. #endif
  682. void ff_put_vc1_chroma_mc8_mmx_nornd (uint8_t *dst, uint8_t *src,
  683. int stride, int h, int x, int y);
  684. void ff_avg_vc1_chroma_mc8_mmx2_nornd (uint8_t *dst, uint8_t *src,
  685. int stride, int h, int x, int y);
  686. void ff_avg_vc1_chroma_mc8_3dnow_nornd(uint8_t *dst, uint8_t *src,
  687. int stride, int h, int x, int y);
  688. void ff_put_vc1_chroma_mc8_ssse3_nornd(uint8_t *dst, uint8_t *src,
  689. int stride, int h, int x, int y);
  690. void ff_avg_vc1_chroma_mc8_ssse3_nornd(uint8_t *dst, uint8_t *src,
  691. int stride, int h, int x, int y);
  692. void ff_vc1dsp_init_mmx(VC1DSPContext *dsp)
  693. {
  694. int mm_flags = av_get_cpu_flags();
  695. #if HAVE_INLINE_ASM
  696. if (mm_flags & AV_CPU_FLAG_MMX) {
  697. dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_vc1_mspel_mc00_mmx;
  698. dsp->put_vc1_mspel_pixels_tab[ 4] = put_vc1_mspel_mc01_mmx;
  699. dsp->put_vc1_mspel_pixels_tab[ 8] = put_vc1_mspel_mc02_mmx;
  700. dsp->put_vc1_mspel_pixels_tab[12] = put_vc1_mspel_mc03_mmx;
  701. dsp->put_vc1_mspel_pixels_tab[ 1] = put_vc1_mspel_mc10_mmx;
  702. dsp->put_vc1_mspel_pixels_tab[ 5] = put_vc1_mspel_mc11_mmx;
  703. dsp->put_vc1_mspel_pixels_tab[ 9] = put_vc1_mspel_mc12_mmx;
  704. dsp->put_vc1_mspel_pixels_tab[13] = put_vc1_mspel_mc13_mmx;
  705. dsp->put_vc1_mspel_pixels_tab[ 2] = put_vc1_mspel_mc20_mmx;
  706. dsp->put_vc1_mspel_pixels_tab[ 6] = put_vc1_mspel_mc21_mmx;
  707. dsp->put_vc1_mspel_pixels_tab[10] = put_vc1_mspel_mc22_mmx;
  708. dsp->put_vc1_mspel_pixels_tab[14] = put_vc1_mspel_mc23_mmx;
  709. dsp->put_vc1_mspel_pixels_tab[ 3] = put_vc1_mspel_mc30_mmx;
  710. dsp->put_vc1_mspel_pixels_tab[ 7] = put_vc1_mspel_mc31_mmx;
  711. dsp->put_vc1_mspel_pixels_tab[11] = put_vc1_mspel_mc32_mmx;
  712. dsp->put_vc1_mspel_pixels_tab[15] = put_vc1_mspel_mc33_mmx;
  713. }
  714. if (mm_flags & AV_CPU_FLAG_MMX2){
  715. dsp->avg_vc1_mspel_pixels_tab[ 0] = ff_avg_vc1_mspel_mc00_mmx2;
  716. dsp->avg_vc1_mspel_pixels_tab[ 4] = avg_vc1_mspel_mc01_mmx2;
  717. dsp->avg_vc1_mspel_pixels_tab[ 8] = avg_vc1_mspel_mc02_mmx2;
  718. dsp->avg_vc1_mspel_pixels_tab[12] = avg_vc1_mspel_mc03_mmx2;
  719. dsp->avg_vc1_mspel_pixels_tab[ 1] = avg_vc1_mspel_mc10_mmx2;
  720. dsp->avg_vc1_mspel_pixels_tab[ 5] = avg_vc1_mspel_mc11_mmx2;
  721. dsp->avg_vc1_mspel_pixels_tab[ 9] = avg_vc1_mspel_mc12_mmx2;
  722. dsp->avg_vc1_mspel_pixels_tab[13] = avg_vc1_mspel_mc13_mmx2;
  723. dsp->avg_vc1_mspel_pixels_tab[ 2] = avg_vc1_mspel_mc20_mmx2;
  724. dsp->avg_vc1_mspel_pixels_tab[ 6] = avg_vc1_mspel_mc21_mmx2;
  725. dsp->avg_vc1_mspel_pixels_tab[10] = avg_vc1_mspel_mc22_mmx2;
  726. dsp->avg_vc1_mspel_pixels_tab[14] = avg_vc1_mspel_mc23_mmx2;
  727. dsp->avg_vc1_mspel_pixels_tab[ 3] = avg_vc1_mspel_mc30_mmx2;
  728. dsp->avg_vc1_mspel_pixels_tab[ 7] = avg_vc1_mspel_mc31_mmx2;
  729. dsp->avg_vc1_mspel_pixels_tab[11] = avg_vc1_mspel_mc32_mmx2;
  730. dsp->avg_vc1_mspel_pixels_tab[15] = avg_vc1_mspel_mc33_mmx2;
  731. dsp->vc1_inv_trans_8x8_dc = vc1_inv_trans_8x8_dc_mmx2;
  732. dsp->vc1_inv_trans_4x8_dc = vc1_inv_trans_4x8_dc_mmx2;
  733. dsp->vc1_inv_trans_8x4_dc = vc1_inv_trans_8x4_dc_mmx2;
  734. dsp->vc1_inv_trans_4x4_dc = vc1_inv_trans_4x4_dc_mmx2;
  735. }
  736. #endif /* HAVE_INLINE_ASM */
  737. #define ASSIGN_LF(EXT) \
  738. dsp->vc1_v_loop_filter4 = ff_vc1_v_loop_filter4_ ## EXT; \
  739. dsp->vc1_h_loop_filter4 = ff_vc1_h_loop_filter4_ ## EXT; \
  740. dsp->vc1_v_loop_filter8 = ff_vc1_v_loop_filter8_ ## EXT; \
  741. dsp->vc1_h_loop_filter8 = ff_vc1_h_loop_filter8_ ## EXT; \
  742. dsp->vc1_v_loop_filter16 = vc1_v_loop_filter16_ ## EXT; \
  743. dsp->vc1_h_loop_filter16 = vc1_h_loop_filter16_ ## EXT
  744. #if HAVE_YASM
  745. if (mm_flags & AV_CPU_FLAG_MMX) {
  746. dsp->put_no_rnd_vc1_chroma_pixels_tab[0]= ff_put_vc1_chroma_mc8_mmx_nornd;
  747. }
  748. if (mm_flags & AV_CPU_FLAG_MMX2) {
  749. ASSIGN_LF(mmx2);
  750. dsp->avg_no_rnd_vc1_chroma_pixels_tab[0]= ff_avg_vc1_chroma_mc8_mmx2_nornd;
  751. } else if (mm_flags & AV_CPU_FLAG_3DNOW) {
  752. dsp->avg_no_rnd_vc1_chroma_pixels_tab[0]= ff_avg_vc1_chroma_mc8_3dnow_nornd;
  753. }
  754. if (mm_flags & AV_CPU_FLAG_SSE2) {
  755. dsp->vc1_v_loop_filter8 = ff_vc1_v_loop_filter8_sse2;
  756. dsp->vc1_h_loop_filter8 = ff_vc1_h_loop_filter8_sse2;
  757. dsp->vc1_v_loop_filter16 = vc1_v_loop_filter16_sse2;
  758. dsp->vc1_h_loop_filter16 = vc1_h_loop_filter16_sse2;
  759. }
  760. if (mm_flags & AV_CPU_FLAG_SSSE3) {
  761. ASSIGN_LF(ssse3);
  762. dsp->put_no_rnd_vc1_chroma_pixels_tab[0]= ff_put_vc1_chroma_mc8_ssse3_nornd;
  763. dsp->avg_no_rnd_vc1_chroma_pixels_tab[0]= ff_avg_vc1_chroma_mc8_ssse3_nornd;
  764. }
  765. if (mm_flags & AV_CPU_FLAG_SSE4) {
  766. dsp->vc1_h_loop_filter8 = ff_vc1_h_loop_filter8_sse4;
  767. dsp->vc1_h_loop_filter16 = vc1_h_loop_filter16_sse4;
  768. }
  769. #endif
  770. }