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.

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