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.

752 lines
33KB

  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/mem.h"
  28. #include "libavutil/x86/asm.h"
  29. #include "libavutil/x86/cpu.h"
  30. #include "libavcodec/dsputil.h"
  31. #include "dsputil_mmx.h"
  32. #include "libavcodec/vc1dsp.h"
  33. #include "vc1dsp.h"
  34. #if HAVE_INLINE_ASM
  35. #define OP_PUT(S,D)
  36. #define OP_AVG(S,D) "pavgb " #S ", " #D " \n\t"
  37. /** Add rounder from mm7 to mm3 and pack result at destination */
  38. #define NORMALIZE_MMX(SHIFT) \
  39. "paddw %%mm7, %%mm3 \n\t" /* +bias-r */ \
  40. "paddw %%mm7, %%mm4 \n\t" /* +bias-r */ \
  41. "psraw "SHIFT", %%mm3 \n\t" \
  42. "psraw "SHIFT", %%mm4 \n\t"
  43. #define TRANSFER_DO_PACK(OP) \
  44. "packuswb %%mm4, %%mm3 \n\t" \
  45. OP((%2), %%mm3) \
  46. "movq %%mm3, (%2) \n\t"
  47. #define TRANSFER_DONT_PACK(OP) \
  48. OP(0(%2), %%mm3) \
  49. OP(8(%2), %%mm4) \
  50. "movq %%mm3, 0(%2) \n\t" \
  51. "movq %%mm4, 8(%2) \n\t"
  52. /** @see MSPEL_FILTER13_CORE for use as UNPACK macro */
  53. #define DO_UNPACK(reg) "punpcklbw %%mm0, " reg "\n\t"
  54. #define DONT_UNPACK(reg)
  55. /** Compute the rounder 32-r or 8-r and unpacks it to mm7 */
  56. #define LOAD_ROUNDER_MMX(ROUND) \
  57. "movd "ROUND", %%mm7 \n\t" \
  58. "punpcklwd %%mm7, %%mm7 \n\t" \
  59. "punpckldq %%mm7, %%mm7 \n\t"
  60. #define SHIFT2_LINE(OFF, R0,R1,R2,R3) \
  61. "paddw %%mm"#R2", %%mm"#R1" \n\t" \
  62. "movd (%0,%3), %%mm"#R0" \n\t" \
  63. "pmullw %%mm6, %%mm"#R1" \n\t" \
  64. "punpcklbw %%mm0, %%mm"#R0" \n\t" \
  65. "movd (%0,%2), %%mm"#R3" \n\t" \
  66. "psubw %%mm"#R0", %%mm"#R1" \n\t" \
  67. "punpcklbw %%mm0, %%mm"#R3" \n\t" \
  68. "paddw %%mm7, %%mm"#R1" \n\t" \
  69. "psubw %%mm"#R3", %%mm"#R1" \n\t" \
  70. "psraw %4, %%mm"#R1" \n\t" \
  71. "movq %%mm"#R1", "#OFF"(%1) \n\t" \
  72. "add %2, %0 \n\t"
  73. /** Sacrifying mm6 allows to pipeline loads from src */
  74. static void vc1_put_ver_16b_shift2_mmx(int16_t *dst,
  75. const uint8_t *src, x86_reg stride,
  76. int rnd, int64_t shift)
  77. {
  78. __asm__ volatile(
  79. "mov $3, %%"REG_c" \n\t"
  80. LOAD_ROUNDER_MMX("%5")
  81. "movq "MANGLE(ff_pw_9)", %%mm6 \n\t"
  82. "1: \n\t"
  83. "movd (%0), %%mm2 \n\t"
  84. "add %2, %0 \n\t"
  85. "movd (%0), %%mm3 \n\t"
  86. "punpcklbw %%mm0, %%mm2 \n\t"
  87. "punpcklbw %%mm0, %%mm3 \n\t"
  88. SHIFT2_LINE( 0, 1, 2, 3, 4)
  89. SHIFT2_LINE( 24, 2, 3, 4, 1)
  90. SHIFT2_LINE( 48, 3, 4, 1, 2)
  91. SHIFT2_LINE( 72, 4, 1, 2, 3)
  92. SHIFT2_LINE( 96, 1, 2, 3, 4)
  93. SHIFT2_LINE(120, 2, 3, 4, 1)
  94. SHIFT2_LINE(144, 3, 4, 1, 2)
  95. SHIFT2_LINE(168, 4, 1, 2, 3)
  96. "sub %6, %0 \n\t"
  97. "add $8, %1 \n\t"
  98. "dec %%"REG_c" \n\t"
  99. "jnz 1b \n\t"
  100. : "+r"(src), "+r"(dst)
  101. : "r"(stride), "r"(-2*stride),
  102. "m"(shift), "m"(rnd), "r"(9*stride-4)
  103. : "%"REG_c, "memory"
  104. );
  105. }
  106. /**
  107. * Data is already unpacked, so some operations can directly be made from
  108. * memory.
  109. */
  110. #define VC1_HOR_16b_SHIFT2(OP, OPNAME)\
  111. static void OPNAME ## vc1_hor_16b_shift2_mmx(uint8_t *dst, x86_reg stride,\
  112. const int16_t *src, int rnd)\
  113. {\
  114. int h = 8;\
  115. \
  116. src -= 1;\
  117. rnd -= (-1+9+9-1)*1024; /* Add -1024 bias */\
  118. __asm__ volatile(\
  119. LOAD_ROUNDER_MMX("%4")\
  120. "movq "MANGLE(ff_pw_128)", %%mm6\n\t"\
  121. "movq "MANGLE(ff_pw_9)", %%mm5 \n\t"\
  122. "1: \n\t"\
  123. "movq 2*0+0(%1), %%mm1 \n\t"\
  124. "movq 2*0+8(%1), %%mm2 \n\t"\
  125. "movq 2*1+0(%1), %%mm3 \n\t"\
  126. "movq 2*1+8(%1), %%mm4 \n\t"\
  127. "paddw 2*3+0(%1), %%mm1 \n\t"\
  128. "paddw 2*3+8(%1), %%mm2 \n\t"\
  129. "paddw 2*2+0(%1), %%mm3 \n\t"\
  130. "paddw 2*2+8(%1), %%mm4 \n\t"\
  131. "pmullw %%mm5, %%mm3 \n\t"\
  132. "pmullw %%mm5, %%mm4 \n\t"\
  133. "psubw %%mm1, %%mm3 \n\t"\
  134. "psubw %%mm2, %%mm4 \n\t"\
  135. NORMALIZE_MMX("$7")\
  136. /* Remove bias */\
  137. "paddw %%mm6, %%mm3 \n\t"\
  138. "paddw %%mm6, %%mm4 \n\t"\
  139. TRANSFER_DO_PACK(OP)\
  140. "add $24, %1 \n\t"\
  141. "add %3, %2 \n\t"\
  142. "decl %0 \n\t"\
  143. "jnz 1b \n\t"\
  144. : "+r"(h), "+r" (src), "+r" (dst)\
  145. : "r"(stride), "m"(rnd)\
  146. : "memory"\
  147. );\
  148. }
  149. VC1_HOR_16b_SHIFT2(OP_PUT, put_)
  150. VC1_HOR_16b_SHIFT2(OP_AVG, avg_)
  151. /**
  152. * Purely vertical or horizontal 1/2 shift interpolation.
  153. * Sacrify mm6 for *9 factor.
  154. */
  155. #define VC1_SHIFT2(OP, OPNAME)\
  156. static void OPNAME ## vc1_shift2_mmx(uint8_t *dst, const uint8_t *src,\
  157. x86_reg stride, int rnd, x86_reg offset)\
  158. {\
  159. rnd = 8-rnd;\
  160. __asm__ volatile(\
  161. "mov $8, %%"REG_c" \n\t"\
  162. LOAD_ROUNDER_MMX("%5")\
  163. "movq "MANGLE(ff_pw_9)", %%mm6\n\t"\
  164. "1: \n\t"\
  165. "movd 0(%0 ), %%mm3 \n\t"\
  166. "movd 4(%0 ), %%mm4 \n\t"\
  167. "movd 0(%0,%2), %%mm1 \n\t"\
  168. "movd 4(%0,%2), %%mm2 \n\t"\
  169. "add %2, %0 \n\t"\
  170. "punpcklbw %%mm0, %%mm3 \n\t"\
  171. "punpcklbw %%mm0, %%mm4 \n\t"\
  172. "punpcklbw %%mm0, %%mm1 \n\t"\
  173. "punpcklbw %%mm0, %%mm2 \n\t"\
  174. "paddw %%mm1, %%mm3 \n\t"\
  175. "paddw %%mm2, %%mm4 \n\t"\
  176. "movd 0(%0,%3), %%mm1 \n\t"\
  177. "movd 4(%0,%3), %%mm2 \n\t"\
  178. "pmullw %%mm6, %%mm3 \n\t" /* 0,9,9,0*/\
  179. "pmullw %%mm6, %%mm4 \n\t" /* 0,9,9,0*/\
  180. "punpcklbw %%mm0, %%mm1 \n\t"\
  181. "punpcklbw %%mm0, %%mm2 \n\t"\
  182. "psubw %%mm1, %%mm3 \n\t" /*-1,9,9,0*/\
  183. "psubw %%mm2, %%mm4 \n\t" /*-1,9,9,0*/\
  184. "movd 0(%0,%2), %%mm1 \n\t"\
  185. "movd 4(%0,%2), %%mm2 \n\t"\
  186. "punpcklbw %%mm0, %%mm1 \n\t"\
  187. "punpcklbw %%mm0, %%mm2 \n\t"\
  188. "psubw %%mm1, %%mm3 \n\t" /*-1,9,9,-1*/\
  189. "psubw %%mm2, %%mm4 \n\t" /*-1,9,9,-1*/\
  190. NORMALIZE_MMX("$4")\
  191. "packuswb %%mm4, %%mm3 \n\t"\
  192. OP((%1), %%mm3)\
  193. "movq %%mm3, (%1) \n\t"\
  194. "add %6, %0 \n\t"\
  195. "add %4, %1 \n\t"\
  196. "dec %%"REG_c" \n\t"\
  197. "jnz 1b \n\t"\
  198. : "+r"(src), "+r"(dst)\
  199. : "r"(offset), "r"(-2*offset), "g"(stride), "m"(rnd),\
  200. "g"(stride-offset)\
  201. : "%"REG_c, "memory"\
  202. );\
  203. }
  204. VC1_SHIFT2(OP_PUT, put_)
  205. VC1_SHIFT2(OP_AVG, avg_)
  206. /**
  207. * Core of the 1/4 and 3/4 shift bicubic interpolation.
  208. *
  209. * @param UNPACK Macro unpacking arguments from 8 to 16bits (can be empty).
  210. * @param MOVQ "movd 1" or "movq 2", if data read is already unpacked.
  211. * @param A1 Address of 1st tap (beware of unpacked/packed).
  212. * @param A2 Address of 2nd tap
  213. * @param A3 Address of 3rd tap
  214. * @param A4 Address of 4th tap
  215. */
  216. #define MSPEL_FILTER13_CORE(UNPACK, MOVQ, A1, A2, A3, A4) \
  217. MOVQ "*0+"A1", %%mm1 \n\t" \
  218. MOVQ "*4+"A1", %%mm2 \n\t" \
  219. UNPACK("%%mm1") \
  220. UNPACK("%%mm2") \
  221. "pmullw "MANGLE(ff_pw_3)", %%mm1\n\t" \
  222. "pmullw "MANGLE(ff_pw_3)", %%mm2\n\t" \
  223. MOVQ "*0+"A2", %%mm3 \n\t" \
  224. MOVQ "*4+"A2", %%mm4 \n\t" \
  225. UNPACK("%%mm3") \
  226. UNPACK("%%mm4") \
  227. "pmullw %%mm6, %%mm3 \n\t" /* *18 */ \
  228. "pmullw %%mm6, %%mm4 \n\t" /* *18 */ \
  229. "psubw %%mm1, %%mm3 \n\t" /* 18,-3 */ \
  230. "psubw %%mm2, %%mm4 \n\t" /* 18,-3 */ \
  231. MOVQ "*0+"A4", %%mm1 \n\t" \
  232. MOVQ "*4+"A4", %%mm2 \n\t" \
  233. UNPACK("%%mm1") \
  234. UNPACK("%%mm2") \
  235. "psllw $2, %%mm1 \n\t" /* 4* */ \
  236. "psllw $2, %%mm2 \n\t" /* 4* */ \
  237. "psubw %%mm1, %%mm3 \n\t" /* -4,18,-3 */ \
  238. "psubw %%mm2, %%mm4 \n\t" /* -4,18,-3 */ \
  239. MOVQ "*0+"A3", %%mm1 \n\t" \
  240. MOVQ "*4+"A3", %%mm2 \n\t" \
  241. UNPACK("%%mm1") \
  242. UNPACK("%%mm2") \
  243. "pmullw %%mm5, %%mm1 \n\t" /* *53 */ \
  244. "pmullw %%mm5, %%mm2 \n\t" /* *53 */ \
  245. "paddw %%mm1, %%mm3 \n\t" /* 4,53,18,-3 */ \
  246. "paddw %%mm2, %%mm4 \n\t" /* 4,53,18,-3 */
  247. /**
  248. * Macro to build the vertical 16bits version of vc1_put_shift[13].
  249. * Here, offset=src_stride. Parameters passed A1 to A4 must use
  250. * %3 (src_stride) and %4 (3*src_stride).
  251. *
  252. * @param NAME Either 1 or 3
  253. * @see MSPEL_FILTER13_CORE for information on A1->A4
  254. */
  255. #define MSPEL_FILTER13_VER_16B(NAME, A1, A2, A3, A4) \
  256. static void \
  257. vc1_put_ver_16b_ ## NAME ## _mmx(int16_t *dst, const uint8_t *src, \
  258. x86_reg src_stride, \
  259. int rnd, int64_t shift) \
  260. { \
  261. int h = 8; \
  262. src -= src_stride; \
  263. __asm__ volatile( \
  264. LOAD_ROUNDER_MMX("%5") \
  265. "movq "MANGLE(ff_pw_53)", %%mm5\n\t" \
  266. "movq "MANGLE(ff_pw_18)", %%mm6\n\t" \
  267. ".p2align 3 \n\t" \
  268. "1: \n\t" \
  269. MSPEL_FILTER13_CORE(DO_UNPACK, "movd 1", A1, A2, A3, A4) \
  270. NORMALIZE_MMX("%6") \
  271. TRANSFER_DONT_PACK(OP_PUT) \
  272. /* Last 3 (in fact 4) bytes on the line */ \
  273. "movd 8+"A1", %%mm1 \n\t" \
  274. DO_UNPACK("%%mm1") \
  275. "movq %%mm1, %%mm3 \n\t" \
  276. "paddw %%mm1, %%mm1 \n\t" \
  277. "paddw %%mm3, %%mm1 \n\t" /* 3* */ \
  278. "movd 8+"A2", %%mm3 \n\t" \
  279. DO_UNPACK("%%mm3") \
  280. "pmullw %%mm6, %%mm3 \n\t" /* *18 */ \
  281. "psubw %%mm1, %%mm3 \n\t" /*18,-3 */ \
  282. "movd 8+"A3", %%mm1 \n\t" \
  283. DO_UNPACK("%%mm1") \
  284. "pmullw %%mm5, %%mm1 \n\t" /* *53 */ \
  285. "paddw %%mm1, %%mm3 \n\t" /*53,18,-3 */ \
  286. "movd 8+"A4", %%mm1 \n\t" \
  287. DO_UNPACK("%%mm1") \
  288. "psllw $2, %%mm1 \n\t" /* 4* */ \
  289. "psubw %%mm1, %%mm3 \n\t" \
  290. "paddw %%mm7, %%mm3 \n\t" \
  291. "psraw %6, %%mm3 \n\t" \
  292. "movq %%mm3, 16(%2) \n\t" \
  293. "add %3, %1 \n\t" \
  294. "add $24, %2 \n\t" \
  295. "decl %0 \n\t" \
  296. "jnz 1b \n\t" \
  297. : "+r"(h), "+r" (src), "+r" (dst) \
  298. : "r"(src_stride), "r"(3*src_stride), \
  299. "m"(rnd), "m"(shift) \
  300. : "memory" \
  301. ); \
  302. }
  303. /**
  304. * Macro to build the horizontal 16bits version of vc1_put_shift[13].
  305. * Here, offset=16bits, so parameters passed A1 to A4 should be simple.
  306. *
  307. * @param NAME Either 1 or 3
  308. * @see MSPEL_FILTER13_CORE for information on A1->A4
  309. */
  310. #define MSPEL_FILTER13_HOR_16B(NAME, A1, A2, A3, A4, OP, OPNAME) \
  311. static void \
  312. OPNAME ## vc1_hor_16b_ ## NAME ## _mmx(uint8_t *dst, x86_reg stride, \
  313. const int16_t *src, int rnd) \
  314. { \
  315. int h = 8; \
  316. src -= 1; \
  317. rnd -= (-4+58+13-3)*256; /* Add -256 bias */ \
  318. __asm__ volatile( \
  319. LOAD_ROUNDER_MMX("%4") \
  320. "movq "MANGLE(ff_pw_18)", %%mm6 \n\t" \
  321. "movq "MANGLE(ff_pw_53)", %%mm5 \n\t" \
  322. ".p2align 3 \n\t" \
  323. "1: \n\t" \
  324. MSPEL_FILTER13_CORE(DONT_UNPACK, "movq 2", A1, A2, A3, A4) \
  325. NORMALIZE_MMX("$7") \
  326. /* Remove bias */ \
  327. "paddw "MANGLE(ff_pw_128)", %%mm3 \n\t" \
  328. "paddw "MANGLE(ff_pw_128)", %%mm4 \n\t" \
  329. TRANSFER_DO_PACK(OP) \
  330. "add $24, %1 \n\t" \
  331. "add %3, %2 \n\t" \
  332. "decl %0 \n\t" \
  333. "jnz 1b \n\t" \
  334. : "+r"(h), "+r" (src), "+r" (dst) \
  335. : "r"(stride), "m"(rnd) \
  336. : "memory" \
  337. ); \
  338. }
  339. /**
  340. * Macro to build the 8bits, any direction, version of vc1_put_shift[13].
  341. * Here, offset=src_stride. Parameters passed A1 to A4 must use
  342. * %3 (offset) and %4 (3*offset).
  343. *
  344. * @param NAME Either 1 or 3
  345. * @see MSPEL_FILTER13_CORE for information on A1->A4
  346. */
  347. #define MSPEL_FILTER13_8B(NAME, A1, A2, A3, A4, OP, OPNAME) \
  348. static void \
  349. OPNAME ## vc1_## NAME ## _mmx(uint8_t *dst, const uint8_t *src, \
  350. x86_reg stride, int rnd, x86_reg offset) \
  351. { \
  352. int h = 8; \
  353. src -= offset; \
  354. rnd = 32-rnd; \
  355. __asm__ volatile ( \
  356. LOAD_ROUNDER_MMX("%6") \
  357. "movq "MANGLE(ff_pw_53)", %%mm5 \n\t" \
  358. "movq "MANGLE(ff_pw_18)", %%mm6 \n\t" \
  359. ".p2align 3 \n\t" \
  360. "1: \n\t" \
  361. MSPEL_FILTER13_CORE(DO_UNPACK, "movd 1", A1, A2, A3, A4) \
  362. NORMALIZE_MMX("$6") \
  363. TRANSFER_DO_PACK(OP) \
  364. "add %5, %1 \n\t" \
  365. "add %5, %2 \n\t" \
  366. "decl %0 \n\t" \
  367. "jnz 1b \n\t" \
  368. : "+r"(h), "+r" (src), "+r" (dst) \
  369. : "r"(offset), "r"(3*offset), "g"(stride), "m"(rnd) \
  370. : "memory" \
  371. ); \
  372. }
  373. /** 1/4 shift bicubic interpolation */
  374. MSPEL_FILTER13_8B (shift1, "0(%1,%4 )", "0(%1,%3,2)", "0(%1,%3 )", "0(%1 )", OP_PUT, put_)
  375. MSPEL_FILTER13_8B (shift1, "0(%1,%4 )", "0(%1,%3,2)", "0(%1,%3 )", "0(%1 )", OP_AVG, avg_)
  376. MSPEL_FILTER13_VER_16B(shift1, "0(%1,%4 )", "0(%1,%3,2)", "0(%1,%3 )", "0(%1 )")
  377. MSPEL_FILTER13_HOR_16B(shift1, "2*3(%1)", "2*2(%1)", "2*1(%1)", "2*0(%1)", OP_PUT, put_)
  378. MSPEL_FILTER13_HOR_16B(shift1, "2*3(%1)", "2*2(%1)", "2*1(%1)", "2*0(%1)", OP_AVG, avg_)
  379. /** 3/4 shift bicubic interpolation */
  380. MSPEL_FILTER13_8B (shift3, "0(%1 )", "0(%1,%3 )", "0(%1,%3,2)", "0(%1,%4 )", OP_PUT, put_)
  381. MSPEL_FILTER13_8B (shift3, "0(%1 )", "0(%1,%3 )", "0(%1,%3,2)", "0(%1,%4 )", OP_AVG, avg_)
  382. MSPEL_FILTER13_VER_16B(shift3, "0(%1 )", "0(%1,%3 )", "0(%1,%3,2)", "0(%1,%4 )")
  383. MSPEL_FILTER13_HOR_16B(shift3, "2*0(%1)", "2*1(%1)", "2*2(%1)", "2*3(%1)", OP_PUT, put_)
  384. MSPEL_FILTER13_HOR_16B(shift3, "2*0(%1)", "2*1(%1)", "2*2(%1)", "2*3(%1)", OP_AVG, avg_)
  385. typedef void (*vc1_mspel_mc_filter_ver_16bits)(int16_t *dst, const uint8_t *src, x86_reg src_stride, int rnd, int64_t shift);
  386. typedef void (*vc1_mspel_mc_filter_hor_16bits)(uint8_t *dst, x86_reg dst_stride, const int16_t *src, int rnd);
  387. typedef void (*vc1_mspel_mc_filter_8bits)(uint8_t *dst, const uint8_t *src, x86_reg stride, int rnd, x86_reg offset);
  388. /**
  389. * Interpolate fractional pel values by applying proper vertical then
  390. * horizontal filter.
  391. *
  392. * @param dst Destination buffer for interpolated pels.
  393. * @param src Source buffer.
  394. * @param stride Stride for both src and dst buffers.
  395. * @param hmode Horizontal filter (expressed in quarter pixels shift).
  396. * @param hmode Vertical filter.
  397. * @param rnd Rounding bias.
  398. */
  399. #define VC1_MSPEL_MC(OP)\
  400. static void OP ## vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride,\
  401. int hmode, int vmode, int rnd)\
  402. {\
  403. static const vc1_mspel_mc_filter_ver_16bits vc1_put_shift_ver_16bits[] =\
  404. { NULL, vc1_put_ver_16b_shift1_mmx, vc1_put_ver_16b_shift2_mmx, vc1_put_ver_16b_shift3_mmx };\
  405. static const vc1_mspel_mc_filter_hor_16bits vc1_put_shift_hor_16bits[] =\
  406. { NULL, OP ## vc1_hor_16b_shift1_mmx, OP ## vc1_hor_16b_shift2_mmx, OP ## vc1_hor_16b_shift3_mmx };\
  407. static const vc1_mspel_mc_filter_8bits vc1_put_shift_8bits[] =\
  408. { NULL, OP ## vc1_shift1_mmx, OP ## vc1_shift2_mmx, OP ## vc1_shift3_mmx };\
  409. \
  410. __asm__ volatile(\
  411. "pxor %%mm0, %%mm0 \n\t"\
  412. ::: "memory"\
  413. );\
  414. \
  415. if (vmode) { /* Vertical filter to apply */\
  416. if (hmode) { /* Horizontal filter to apply, output to tmp */\
  417. static const int shift_value[] = { 0, 5, 1, 5 };\
  418. int shift = (shift_value[hmode]+shift_value[vmode])>>1;\
  419. int r;\
  420. DECLARE_ALIGNED(16, int16_t, tmp)[12*8];\
  421. \
  422. r = (1<<(shift-1)) + rnd-1;\
  423. vc1_put_shift_ver_16bits[vmode](tmp, src-1, stride, r, shift);\
  424. \
  425. vc1_put_shift_hor_16bits[hmode](dst, stride, tmp+1, 64-rnd);\
  426. return;\
  427. }\
  428. else { /* No horizontal filter, output 8 lines to dst */\
  429. vc1_put_shift_8bits[vmode](dst, src, stride, 1-rnd, stride);\
  430. return;\
  431. }\
  432. }\
  433. \
  434. /* Horizontal mode with no vertical mode */\
  435. vc1_put_shift_8bits[hmode](dst, src, stride, rnd, 1);\
  436. }
  437. VC1_MSPEL_MC(put_)
  438. VC1_MSPEL_MC(avg_)
  439. /** Macro to ease bicubic filter interpolation functions declarations */
  440. #define DECLARE_FUNCTION(a, b) \
  441. static void put_vc1_mspel_mc ## a ## b ## _mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd) { \
  442. put_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
  443. }\
  444. static void avg_vc1_mspel_mc ## a ## b ## _mmxext(uint8_t *dst, \
  445. const uint8_t *src, \
  446. int stride, int rnd) \
  447. { \
  448. avg_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
  449. }
  450. DECLARE_FUNCTION(0, 1)
  451. DECLARE_FUNCTION(0, 2)
  452. DECLARE_FUNCTION(0, 3)
  453. DECLARE_FUNCTION(1, 0)
  454. DECLARE_FUNCTION(1, 1)
  455. DECLARE_FUNCTION(1, 2)
  456. DECLARE_FUNCTION(1, 3)
  457. DECLARE_FUNCTION(2, 0)
  458. DECLARE_FUNCTION(2, 1)
  459. DECLARE_FUNCTION(2, 2)
  460. DECLARE_FUNCTION(2, 3)
  461. DECLARE_FUNCTION(3, 0)
  462. DECLARE_FUNCTION(3, 1)
  463. DECLARE_FUNCTION(3, 2)
  464. DECLARE_FUNCTION(3, 3)
  465. static void vc1_inv_trans_4x4_dc_mmxext(uint8_t *dest, int linesize,
  466. int16_t *block)
  467. {
  468. int dc = block[0];
  469. dc = (17 * dc + 4) >> 3;
  470. dc = (17 * dc + 64) >> 7;
  471. __asm__ volatile(
  472. "movd %0, %%mm0 \n\t"
  473. "pshufw $0, %%mm0, %%mm0 \n\t"
  474. "pxor %%mm1, %%mm1 \n\t"
  475. "psubw %%mm0, %%mm1 \n\t"
  476. "packuswb %%mm0, %%mm0 \n\t"
  477. "packuswb %%mm1, %%mm1 \n\t"
  478. ::"r"(dc)
  479. );
  480. __asm__ volatile(
  481. "movd %0, %%mm2 \n\t"
  482. "movd %1, %%mm3 \n\t"
  483. "movd %2, %%mm4 \n\t"
  484. "movd %3, %%mm5 \n\t"
  485. "paddusb %%mm0, %%mm2 \n\t"
  486. "paddusb %%mm0, %%mm3 \n\t"
  487. "paddusb %%mm0, %%mm4 \n\t"
  488. "paddusb %%mm0, %%mm5 \n\t"
  489. "psubusb %%mm1, %%mm2 \n\t"
  490. "psubusb %%mm1, %%mm3 \n\t"
  491. "psubusb %%mm1, %%mm4 \n\t"
  492. "psubusb %%mm1, %%mm5 \n\t"
  493. "movd %%mm2, %0 \n\t"
  494. "movd %%mm3, %1 \n\t"
  495. "movd %%mm4, %2 \n\t"
  496. "movd %%mm5, %3 \n\t"
  497. :"+m"(*(uint32_t*)(dest+0*linesize)),
  498. "+m"(*(uint32_t*)(dest+1*linesize)),
  499. "+m"(*(uint32_t*)(dest+2*linesize)),
  500. "+m"(*(uint32_t*)(dest+3*linesize))
  501. );
  502. }
  503. static void vc1_inv_trans_4x8_dc_mmxext(uint8_t *dest, int linesize,
  504. int16_t *block)
  505. {
  506. int dc = block[0];
  507. dc = (17 * dc + 4) >> 3;
  508. dc = (12 * dc + 64) >> 7;
  509. __asm__ volatile(
  510. "movd %0, %%mm0 \n\t"
  511. "pshufw $0, %%mm0, %%mm0 \n\t"
  512. "pxor %%mm1, %%mm1 \n\t"
  513. "psubw %%mm0, %%mm1 \n\t"
  514. "packuswb %%mm0, %%mm0 \n\t"
  515. "packuswb %%mm1, %%mm1 \n\t"
  516. ::"r"(dc)
  517. );
  518. __asm__ volatile(
  519. "movd %0, %%mm2 \n\t"
  520. "movd %1, %%mm3 \n\t"
  521. "movd %2, %%mm4 \n\t"
  522. "movd %3, %%mm5 \n\t"
  523. "paddusb %%mm0, %%mm2 \n\t"
  524. "paddusb %%mm0, %%mm3 \n\t"
  525. "paddusb %%mm0, %%mm4 \n\t"
  526. "paddusb %%mm0, %%mm5 \n\t"
  527. "psubusb %%mm1, %%mm2 \n\t"
  528. "psubusb %%mm1, %%mm3 \n\t"
  529. "psubusb %%mm1, %%mm4 \n\t"
  530. "psubusb %%mm1, %%mm5 \n\t"
  531. "movd %%mm2, %0 \n\t"
  532. "movd %%mm3, %1 \n\t"
  533. "movd %%mm4, %2 \n\t"
  534. "movd %%mm5, %3 \n\t"
  535. :"+m"(*(uint32_t*)(dest+0*linesize)),
  536. "+m"(*(uint32_t*)(dest+1*linesize)),
  537. "+m"(*(uint32_t*)(dest+2*linesize)),
  538. "+m"(*(uint32_t*)(dest+3*linesize))
  539. );
  540. dest += 4*linesize;
  541. __asm__ volatile(
  542. "movd %0, %%mm2 \n\t"
  543. "movd %1, %%mm3 \n\t"
  544. "movd %2, %%mm4 \n\t"
  545. "movd %3, %%mm5 \n\t"
  546. "paddusb %%mm0, %%mm2 \n\t"
  547. "paddusb %%mm0, %%mm3 \n\t"
  548. "paddusb %%mm0, %%mm4 \n\t"
  549. "paddusb %%mm0, %%mm5 \n\t"
  550. "psubusb %%mm1, %%mm2 \n\t"
  551. "psubusb %%mm1, %%mm3 \n\t"
  552. "psubusb %%mm1, %%mm4 \n\t"
  553. "psubusb %%mm1, %%mm5 \n\t"
  554. "movd %%mm2, %0 \n\t"
  555. "movd %%mm3, %1 \n\t"
  556. "movd %%mm4, %2 \n\t"
  557. "movd %%mm5, %3 \n\t"
  558. :"+m"(*(uint32_t*)(dest+0*linesize)),
  559. "+m"(*(uint32_t*)(dest+1*linesize)),
  560. "+m"(*(uint32_t*)(dest+2*linesize)),
  561. "+m"(*(uint32_t*)(dest+3*linesize))
  562. );
  563. }
  564. static void vc1_inv_trans_8x4_dc_mmxext(uint8_t *dest, int linesize,
  565. int16_t *block)
  566. {
  567. int dc = block[0];
  568. dc = ( 3 * dc + 1) >> 1;
  569. dc = (17 * dc + 64) >> 7;
  570. __asm__ volatile(
  571. "movd %0, %%mm0 \n\t"
  572. "pshufw $0, %%mm0, %%mm0 \n\t"
  573. "pxor %%mm1, %%mm1 \n\t"
  574. "psubw %%mm0, %%mm1 \n\t"
  575. "packuswb %%mm0, %%mm0 \n\t"
  576. "packuswb %%mm1, %%mm1 \n\t"
  577. ::"r"(dc)
  578. );
  579. __asm__ volatile(
  580. "movq %0, %%mm2 \n\t"
  581. "movq %1, %%mm3 \n\t"
  582. "movq %2, %%mm4 \n\t"
  583. "movq %3, %%mm5 \n\t"
  584. "paddusb %%mm0, %%mm2 \n\t"
  585. "paddusb %%mm0, %%mm3 \n\t"
  586. "paddusb %%mm0, %%mm4 \n\t"
  587. "paddusb %%mm0, %%mm5 \n\t"
  588. "psubusb %%mm1, %%mm2 \n\t"
  589. "psubusb %%mm1, %%mm3 \n\t"
  590. "psubusb %%mm1, %%mm4 \n\t"
  591. "psubusb %%mm1, %%mm5 \n\t"
  592. "movq %%mm2, %0 \n\t"
  593. "movq %%mm3, %1 \n\t"
  594. "movq %%mm4, %2 \n\t"
  595. "movq %%mm5, %3 \n\t"
  596. :"+m"(*(uint32_t*)(dest+0*linesize)),
  597. "+m"(*(uint32_t*)(dest+1*linesize)),
  598. "+m"(*(uint32_t*)(dest+2*linesize)),
  599. "+m"(*(uint32_t*)(dest+3*linesize))
  600. );
  601. }
  602. static void vc1_inv_trans_8x8_dc_mmxext(uint8_t *dest, int linesize,
  603. int16_t *block)
  604. {
  605. int dc = block[0];
  606. dc = (3 * dc + 1) >> 1;
  607. dc = (3 * dc + 16) >> 5;
  608. __asm__ volatile(
  609. "movd %0, %%mm0 \n\t"
  610. "pshufw $0, %%mm0, %%mm0 \n\t"
  611. "pxor %%mm1, %%mm1 \n\t"
  612. "psubw %%mm0, %%mm1 \n\t"
  613. "packuswb %%mm0, %%mm0 \n\t"
  614. "packuswb %%mm1, %%mm1 \n\t"
  615. ::"r"(dc)
  616. );
  617. __asm__ volatile(
  618. "movq %0, %%mm2 \n\t"
  619. "movq %1, %%mm3 \n\t"
  620. "movq %2, %%mm4 \n\t"
  621. "movq %3, %%mm5 \n\t"
  622. "paddusb %%mm0, %%mm2 \n\t"
  623. "paddusb %%mm0, %%mm3 \n\t"
  624. "paddusb %%mm0, %%mm4 \n\t"
  625. "paddusb %%mm0, %%mm5 \n\t"
  626. "psubusb %%mm1, %%mm2 \n\t"
  627. "psubusb %%mm1, %%mm3 \n\t"
  628. "psubusb %%mm1, %%mm4 \n\t"
  629. "psubusb %%mm1, %%mm5 \n\t"
  630. "movq %%mm2, %0 \n\t"
  631. "movq %%mm3, %1 \n\t"
  632. "movq %%mm4, %2 \n\t"
  633. "movq %%mm5, %3 \n\t"
  634. :"+m"(*(uint32_t*)(dest+0*linesize)),
  635. "+m"(*(uint32_t*)(dest+1*linesize)),
  636. "+m"(*(uint32_t*)(dest+2*linesize)),
  637. "+m"(*(uint32_t*)(dest+3*linesize))
  638. );
  639. dest += 4*linesize;
  640. __asm__ volatile(
  641. "movq %0, %%mm2 \n\t"
  642. "movq %1, %%mm3 \n\t"
  643. "movq %2, %%mm4 \n\t"
  644. "movq %3, %%mm5 \n\t"
  645. "paddusb %%mm0, %%mm2 \n\t"
  646. "paddusb %%mm0, %%mm3 \n\t"
  647. "paddusb %%mm0, %%mm4 \n\t"
  648. "paddusb %%mm0, %%mm5 \n\t"
  649. "psubusb %%mm1, %%mm2 \n\t"
  650. "psubusb %%mm1, %%mm3 \n\t"
  651. "psubusb %%mm1, %%mm4 \n\t"
  652. "psubusb %%mm1, %%mm5 \n\t"
  653. "movq %%mm2, %0 \n\t"
  654. "movq %%mm3, %1 \n\t"
  655. "movq %%mm4, %2 \n\t"
  656. "movq %%mm5, %3 \n\t"
  657. :"+m"(*(uint32_t*)(dest+0*linesize)),
  658. "+m"(*(uint32_t*)(dest+1*linesize)),
  659. "+m"(*(uint32_t*)(dest+2*linesize)),
  660. "+m"(*(uint32_t*)(dest+3*linesize))
  661. );
  662. }
  663. av_cold void ff_vc1dsp_init_mmx(VC1DSPContext *dsp)
  664. {
  665. #if HAVE_YASM
  666. dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_vc1_mspel_mc00_mmx;
  667. #endif /* HAVE_YASM */
  668. dsp->put_vc1_mspel_pixels_tab[ 4] = put_vc1_mspel_mc01_mmx;
  669. dsp->put_vc1_mspel_pixels_tab[ 8] = put_vc1_mspel_mc02_mmx;
  670. dsp->put_vc1_mspel_pixels_tab[12] = put_vc1_mspel_mc03_mmx;
  671. dsp->put_vc1_mspel_pixels_tab[ 1] = put_vc1_mspel_mc10_mmx;
  672. dsp->put_vc1_mspel_pixels_tab[ 5] = put_vc1_mspel_mc11_mmx;
  673. dsp->put_vc1_mspel_pixels_tab[ 9] = put_vc1_mspel_mc12_mmx;
  674. dsp->put_vc1_mspel_pixels_tab[13] = put_vc1_mspel_mc13_mmx;
  675. dsp->put_vc1_mspel_pixels_tab[ 2] = put_vc1_mspel_mc20_mmx;
  676. dsp->put_vc1_mspel_pixels_tab[ 6] = put_vc1_mspel_mc21_mmx;
  677. dsp->put_vc1_mspel_pixels_tab[10] = put_vc1_mspel_mc22_mmx;
  678. dsp->put_vc1_mspel_pixels_tab[14] = put_vc1_mspel_mc23_mmx;
  679. dsp->put_vc1_mspel_pixels_tab[ 3] = put_vc1_mspel_mc30_mmx;
  680. dsp->put_vc1_mspel_pixels_tab[ 7] = put_vc1_mspel_mc31_mmx;
  681. dsp->put_vc1_mspel_pixels_tab[11] = put_vc1_mspel_mc32_mmx;
  682. dsp->put_vc1_mspel_pixels_tab[15] = put_vc1_mspel_mc33_mmx;
  683. }
  684. av_cold void ff_vc1dsp_init_mmxext(VC1DSPContext *dsp)
  685. {
  686. #if HAVE_YASM
  687. dsp->avg_vc1_mspel_pixels_tab[ 0] = ff_avg_vc1_mspel_mc00_mmxext;
  688. #endif /* HAVE_YASM */
  689. dsp->avg_vc1_mspel_pixels_tab[ 4] = avg_vc1_mspel_mc01_mmxext;
  690. dsp->avg_vc1_mspel_pixels_tab[ 8] = avg_vc1_mspel_mc02_mmxext;
  691. dsp->avg_vc1_mspel_pixels_tab[12] = avg_vc1_mspel_mc03_mmxext;
  692. dsp->avg_vc1_mspel_pixels_tab[ 1] = avg_vc1_mspel_mc10_mmxext;
  693. dsp->avg_vc1_mspel_pixels_tab[ 5] = avg_vc1_mspel_mc11_mmxext;
  694. dsp->avg_vc1_mspel_pixels_tab[ 9] = avg_vc1_mspel_mc12_mmxext;
  695. dsp->avg_vc1_mspel_pixels_tab[13] = avg_vc1_mspel_mc13_mmxext;
  696. dsp->avg_vc1_mspel_pixels_tab[ 2] = avg_vc1_mspel_mc20_mmxext;
  697. dsp->avg_vc1_mspel_pixels_tab[ 6] = avg_vc1_mspel_mc21_mmxext;
  698. dsp->avg_vc1_mspel_pixels_tab[10] = avg_vc1_mspel_mc22_mmxext;
  699. dsp->avg_vc1_mspel_pixels_tab[14] = avg_vc1_mspel_mc23_mmxext;
  700. dsp->avg_vc1_mspel_pixels_tab[ 3] = avg_vc1_mspel_mc30_mmxext;
  701. dsp->avg_vc1_mspel_pixels_tab[ 7] = avg_vc1_mspel_mc31_mmxext;
  702. dsp->avg_vc1_mspel_pixels_tab[11] = avg_vc1_mspel_mc32_mmxext;
  703. dsp->avg_vc1_mspel_pixels_tab[15] = avg_vc1_mspel_mc33_mmxext;
  704. dsp->vc1_inv_trans_8x8_dc = vc1_inv_trans_8x8_dc_mmxext;
  705. dsp->vc1_inv_trans_4x8_dc = vc1_inv_trans_4x8_dc_mmxext;
  706. dsp->vc1_inv_trans_8x4_dc = vc1_inv_trans_8x4_dc_mmxext;
  707. dsp->vc1_inv_trans_4x4_dc = vc1_inv_trans_4x4_dc_mmxext;
  708. }
  709. #endif /* HAVE_INLINE_ASM */