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.

1967 lines
87KB

  1. /*
  2. * Copyright (C) 2001-2011 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #undef REAL_MOVNTQ
  21. #undef MOVNTQ
  22. #undef MOVNTQ2
  23. #undef PREFETCH
  24. #if COMPILE_TEMPLATE_MMX2
  25. #define PREFETCH "prefetchnta"
  26. #else
  27. #define PREFETCH " # nop"
  28. #endif
  29. #if COMPILE_TEMPLATE_MMX2
  30. #define REAL_MOVNTQ(a,b) "movntq " #a ", " #b " \n\t"
  31. #define MOVNTQ2 "movntq "
  32. #else
  33. #define REAL_MOVNTQ(a,b) "movq " #a ", " #b " \n\t"
  34. #define MOVNTQ2 "movq "
  35. #endif
  36. #define MOVNTQ(a,b) REAL_MOVNTQ(a,b)
  37. #if !COMPILE_TEMPLATE_MMX2
  38. static av_always_inline void
  39. dither_8to16(const uint8_t *srcDither, int rot)
  40. {
  41. if (rot) {
  42. __asm__ volatile("pxor %%mm0, %%mm0\n\t"
  43. "movq (%0), %%mm3\n\t"
  44. "movq %%mm3, %%mm4\n\t"
  45. "psrlq $24, %%mm3\n\t"
  46. "psllq $40, %%mm4\n\t"
  47. "por %%mm4, %%mm3\n\t"
  48. "movq %%mm3, %%mm4\n\t"
  49. "punpcklbw %%mm0, %%mm3\n\t"
  50. "punpckhbw %%mm0, %%mm4\n\t"
  51. :: "r"(srcDither)
  52. );
  53. } else {
  54. __asm__ volatile("pxor %%mm0, %%mm0\n\t"
  55. "movq (%0), %%mm3\n\t"
  56. "movq %%mm3, %%mm4\n\t"
  57. "punpcklbw %%mm0, %%mm3\n\t"
  58. "punpckhbw %%mm0, %%mm4\n\t"
  59. :: "r"(srcDither)
  60. );
  61. }
  62. }
  63. #endif
  64. static void RENAME(yuv2yuvX)(const int16_t *filter, int filterSize,
  65. const int16_t **src, uint8_t *dest, int dstW,
  66. const uint8_t *dither, int offset)
  67. {
  68. dither_8to16(dither, offset);
  69. __asm__ volatile(\
  70. "psraw $4, %%mm3\n\t"
  71. "psraw $4, %%mm4\n\t"
  72. "movq %%mm3, %%mm6\n\t"
  73. "movq %%mm4, %%mm7\n\t"
  74. "movl %3, %%ecx\n\t"
  75. "mov %0, %%"REG_d" \n\t"\
  76. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  77. ".p2align 4 \n\t" /* FIXME Unroll? */\
  78. "1: \n\t"\
  79. "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\
  80. "movq (%%"REG_S", %%"REG_c", 2), %%mm2 \n\t" /* srcData */\
  81. "movq 8(%%"REG_S", %%"REG_c", 2), %%mm5 \n\t" /* srcData */\
  82. "add $16, %%"REG_d" \n\t"\
  83. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  84. "test %%"REG_S", %%"REG_S" \n\t"\
  85. "pmulhw %%mm0, %%mm2 \n\t"\
  86. "pmulhw %%mm0, %%mm5 \n\t"\
  87. "paddw %%mm2, %%mm3 \n\t"\
  88. "paddw %%mm5, %%mm4 \n\t"\
  89. " jnz 1b \n\t"\
  90. "psraw $3, %%mm3 \n\t"\
  91. "psraw $3, %%mm4 \n\t"\
  92. "packuswb %%mm4, %%mm3 \n\t"
  93. MOVNTQ2 " %%mm3, (%1, %%"REG_c")\n\t"
  94. "add $8, %%"REG_c" \n\t"\
  95. "cmp %2, %%"REG_c" \n\t"\
  96. "movq %%mm6, %%mm3\n\t"
  97. "movq %%mm7, %%mm4\n\t"
  98. "mov %0, %%"REG_d" \n\t"\
  99. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  100. "jb 1b \n\t"\
  101. :: "g" (filter),
  102. "r" (dest-offset), "g" ((x86_reg)(dstW+offset)), "m" (offset)
  103. : "%"REG_d, "%"REG_S, "%"REG_c
  104. );
  105. }
  106. #define YSCALEYUV2PACKEDX_UV \
  107. __asm__ volatile(\
  108. "xor %%"REG_a", %%"REG_a" \n\t"\
  109. ".p2align 4 \n\t"\
  110. "nop \n\t"\
  111. "1: \n\t"\
  112. "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d" \n\t"\
  113. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  114. "movq "VROUNDER_OFFSET"(%0), %%mm3 \n\t"\
  115. "movq %%mm3, %%mm4 \n\t"\
  116. ".p2align 4 \n\t"\
  117. "2: \n\t"\
  118. "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\
  119. "movq (%%"REG_S", %%"REG_a"), %%mm2 \n\t" /* UsrcData */\
  120. "add %6, %%"REG_S" \n\t" \
  121. "movq (%%"REG_S", %%"REG_a"), %%mm5 \n\t" /* VsrcData */\
  122. "add $16, %%"REG_d" \n\t"\
  123. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  124. "pmulhw %%mm0, %%mm2 \n\t"\
  125. "pmulhw %%mm0, %%mm5 \n\t"\
  126. "paddw %%mm2, %%mm3 \n\t"\
  127. "paddw %%mm5, %%mm4 \n\t"\
  128. "test %%"REG_S", %%"REG_S" \n\t"\
  129. " jnz 2b \n\t"\
  130. #define YSCALEYUV2PACKEDX_YA(offset,coeff,src1,src2,dst1,dst2) \
  131. "lea "offset"(%0), %%"REG_d" \n\t"\
  132. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  133. "movq "VROUNDER_OFFSET"(%0), "#dst1" \n\t"\
  134. "movq "#dst1", "#dst2" \n\t"\
  135. ".p2align 4 \n\t"\
  136. "2: \n\t"\
  137. "movq 8(%%"REG_d"), "#coeff" \n\t" /* filterCoeff */\
  138. "movq (%%"REG_S", %%"REG_a", 2), "#src1" \n\t" /* Y1srcData */\
  139. "movq 8(%%"REG_S", %%"REG_a", 2), "#src2" \n\t" /* Y2srcData */\
  140. "add $16, %%"REG_d" \n\t"\
  141. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  142. "pmulhw "#coeff", "#src1" \n\t"\
  143. "pmulhw "#coeff", "#src2" \n\t"\
  144. "paddw "#src1", "#dst1" \n\t"\
  145. "paddw "#src2", "#dst2" \n\t"\
  146. "test %%"REG_S", %%"REG_S" \n\t"\
  147. " jnz 2b \n\t"\
  148. #define YSCALEYUV2PACKEDX \
  149. YSCALEYUV2PACKEDX_UV \
  150. YSCALEYUV2PACKEDX_YA(LUM_MMX_FILTER_OFFSET,%%mm0,%%mm2,%%mm5,%%mm1,%%mm7) \
  151. #define YSCALEYUV2PACKEDX_END \
  152. :: "r" (&c->redDither), \
  153. "m" (dummy), "m" (dummy), "m" (dummy),\
  154. "r" (dest), "m" (dstW_reg), "m"(uv_off) \
  155. : "%"REG_a, "%"REG_d, "%"REG_S \
  156. );
  157. #define YSCALEYUV2PACKEDX_ACCURATE_UV \
  158. __asm__ volatile(\
  159. "xor %%"REG_a", %%"REG_a" \n\t"\
  160. ".p2align 4 \n\t"\
  161. "nop \n\t"\
  162. "1: \n\t"\
  163. "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d" \n\t"\
  164. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  165. "pxor %%mm4, %%mm4 \n\t"\
  166. "pxor %%mm5, %%mm5 \n\t"\
  167. "pxor %%mm6, %%mm6 \n\t"\
  168. "pxor %%mm7, %%mm7 \n\t"\
  169. ".p2align 4 \n\t"\
  170. "2: \n\t"\
  171. "movq (%%"REG_S", %%"REG_a"), %%mm0 \n\t" /* UsrcData */\
  172. "add %6, %%"REG_S" \n\t" \
  173. "movq (%%"REG_S", %%"REG_a"), %%mm2 \n\t" /* VsrcData */\
  174. "mov "STR(APCK_PTR2)"(%%"REG_d"), %%"REG_S" \n\t"\
  175. "movq (%%"REG_S", %%"REG_a"), %%mm1 \n\t" /* UsrcData */\
  176. "movq %%mm0, %%mm3 \n\t"\
  177. "punpcklwd %%mm1, %%mm0 \n\t"\
  178. "punpckhwd %%mm1, %%mm3 \n\t"\
  179. "movq "STR(APCK_COEF)"(%%"REG_d"),%%mm1 \n\t" /* filterCoeff */\
  180. "pmaddwd %%mm1, %%mm0 \n\t"\
  181. "pmaddwd %%mm1, %%mm3 \n\t"\
  182. "paddd %%mm0, %%mm4 \n\t"\
  183. "paddd %%mm3, %%mm5 \n\t"\
  184. "add %6, %%"REG_S" \n\t" \
  185. "movq (%%"REG_S", %%"REG_a"), %%mm3 \n\t" /* VsrcData */\
  186. "mov "STR(APCK_SIZE)"(%%"REG_d"), %%"REG_S" \n\t"\
  187. "add $"STR(APCK_SIZE)", %%"REG_d" \n\t"\
  188. "test %%"REG_S", %%"REG_S" \n\t"\
  189. "movq %%mm2, %%mm0 \n\t"\
  190. "punpcklwd %%mm3, %%mm2 \n\t"\
  191. "punpckhwd %%mm3, %%mm0 \n\t"\
  192. "pmaddwd %%mm1, %%mm2 \n\t"\
  193. "pmaddwd %%mm1, %%mm0 \n\t"\
  194. "paddd %%mm2, %%mm6 \n\t"\
  195. "paddd %%mm0, %%mm7 \n\t"\
  196. " jnz 2b \n\t"\
  197. "psrad $16, %%mm4 \n\t"\
  198. "psrad $16, %%mm5 \n\t"\
  199. "psrad $16, %%mm6 \n\t"\
  200. "psrad $16, %%mm7 \n\t"\
  201. "movq "VROUNDER_OFFSET"(%0), %%mm0 \n\t"\
  202. "packssdw %%mm5, %%mm4 \n\t"\
  203. "packssdw %%mm7, %%mm6 \n\t"\
  204. "paddw %%mm0, %%mm4 \n\t"\
  205. "paddw %%mm0, %%mm6 \n\t"\
  206. "movq %%mm4, "U_TEMP"(%0) \n\t"\
  207. "movq %%mm6, "V_TEMP"(%0) \n\t"\
  208. #define YSCALEYUV2PACKEDX_ACCURATE_YA(offset) \
  209. "lea "offset"(%0), %%"REG_d" \n\t"\
  210. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  211. "pxor %%mm1, %%mm1 \n\t"\
  212. "pxor %%mm5, %%mm5 \n\t"\
  213. "pxor %%mm7, %%mm7 \n\t"\
  214. "pxor %%mm6, %%mm6 \n\t"\
  215. ".p2align 4 \n\t"\
  216. "2: \n\t"\
  217. "movq (%%"REG_S", %%"REG_a", 2), %%mm0 \n\t" /* Y1srcData */\
  218. "movq 8(%%"REG_S", %%"REG_a", 2), %%mm2 \n\t" /* Y2srcData */\
  219. "mov "STR(APCK_PTR2)"(%%"REG_d"), %%"REG_S" \n\t"\
  220. "movq (%%"REG_S", %%"REG_a", 2), %%mm4 \n\t" /* Y1srcData */\
  221. "movq %%mm0, %%mm3 \n\t"\
  222. "punpcklwd %%mm4, %%mm0 \n\t"\
  223. "punpckhwd %%mm4, %%mm3 \n\t"\
  224. "movq "STR(APCK_COEF)"(%%"REG_d"), %%mm4 \n\t" /* filterCoeff */\
  225. "pmaddwd %%mm4, %%mm0 \n\t"\
  226. "pmaddwd %%mm4, %%mm3 \n\t"\
  227. "paddd %%mm0, %%mm1 \n\t"\
  228. "paddd %%mm3, %%mm5 \n\t"\
  229. "movq 8(%%"REG_S", %%"REG_a", 2), %%mm3 \n\t" /* Y2srcData */\
  230. "mov "STR(APCK_SIZE)"(%%"REG_d"), %%"REG_S" \n\t"\
  231. "add $"STR(APCK_SIZE)", %%"REG_d" \n\t"\
  232. "test %%"REG_S", %%"REG_S" \n\t"\
  233. "movq %%mm2, %%mm0 \n\t"\
  234. "punpcklwd %%mm3, %%mm2 \n\t"\
  235. "punpckhwd %%mm3, %%mm0 \n\t"\
  236. "pmaddwd %%mm4, %%mm2 \n\t"\
  237. "pmaddwd %%mm4, %%mm0 \n\t"\
  238. "paddd %%mm2, %%mm7 \n\t"\
  239. "paddd %%mm0, %%mm6 \n\t"\
  240. " jnz 2b \n\t"\
  241. "psrad $16, %%mm1 \n\t"\
  242. "psrad $16, %%mm5 \n\t"\
  243. "psrad $16, %%mm7 \n\t"\
  244. "psrad $16, %%mm6 \n\t"\
  245. "movq "VROUNDER_OFFSET"(%0), %%mm0 \n\t"\
  246. "packssdw %%mm5, %%mm1 \n\t"\
  247. "packssdw %%mm6, %%mm7 \n\t"\
  248. "paddw %%mm0, %%mm1 \n\t"\
  249. "paddw %%mm0, %%mm7 \n\t"\
  250. "movq "U_TEMP"(%0), %%mm3 \n\t"\
  251. "movq "V_TEMP"(%0), %%mm4 \n\t"\
  252. #define YSCALEYUV2PACKEDX_ACCURATE \
  253. YSCALEYUV2PACKEDX_ACCURATE_UV \
  254. YSCALEYUV2PACKEDX_ACCURATE_YA(LUM_MMX_FILTER_OFFSET)
  255. #define YSCALEYUV2RGBX \
  256. "psubw "U_OFFSET"(%0), %%mm3 \n\t" /* (U-128)8*/\
  257. "psubw "V_OFFSET"(%0), %%mm4 \n\t" /* (V-128)8*/\
  258. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  259. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  260. "pmulhw "UG_COEFF"(%0), %%mm3 \n\t"\
  261. "pmulhw "VG_COEFF"(%0), %%mm4 \n\t"\
  262. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  263. "pmulhw "UB_COEFF"(%0), %%mm2 \n\t"\
  264. "pmulhw "VR_COEFF"(%0), %%mm5 \n\t"\
  265. "psubw "Y_OFFSET"(%0), %%mm1 \n\t" /* 8(Y-16)*/\
  266. "psubw "Y_OFFSET"(%0), %%mm7 \n\t" /* 8(Y-16)*/\
  267. "pmulhw "Y_COEFF"(%0), %%mm1 \n\t"\
  268. "pmulhw "Y_COEFF"(%0), %%mm7 \n\t"\
  269. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  270. "paddw %%mm3, %%mm4 \n\t"\
  271. "movq %%mm2, %%mm0 \n\t"\
  272. "movq %%mm5, %%mm6 \n\t"\
  273. "movq %%mm4, %%mm3 \n\t"\
  274. "punpcklwd %%mm2, %%mm2 \n\t"\
  275. "punpcklwd %%mm5, %%mm5 \n\t"\
  276. "punpcklwd %%mm4, %%mm4 \n\t"\
  277. "paddw %%mm1, %%mm2 \n\t"\
  278. "paddw %%mm1, %%mm5 \n\t"\
  279. "paddw %%mm1, %%mm4 \n\t"\
  280. "punpckhwd %%mm0, %%mm0 \n\t"\
  281. "punpckhwd %%mm6, %%mm6 \n\t"\
  282. "punpckhwd %%mm3, %%mm3 \n\t"\
  283. "paddw %%mm7, %%mm0 \n\t"\
  284. "paddw %%mm7, %%mm6 \n\t"\
  285. "paddw %%mm7, %%mm3 \n\t"\
  286. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  287. "packuswb %%mm0, %%mm2 \n\t"\
  288. "packuswb %%mm6, %%mm5 \n\t"\
  289. "packuswb %%mm3, %%mm4 \n\t"\
  290. #define REAL_WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t) \
  291. "movq "#b", "#q2" \n\t" /* B */\
  292. "movq "#r", "#t" \n\t" /* R */\
  293. "punpcklbw "#g", "#b" \n\t" /* GBGBGBGB 0 */\
  294. "punpcklbw "#a", "#r" \n\t" /* ARARARAR 0 */\
  295. "punpckhbw "#g", "#q2" \n\t" /* GBGBGBGB 2 */\
  296. "punpckhbw "#a", "#t" \n\t" /* ARARARAR 2 */\
  297. "movq "#b", "#q0" \n\t" /* GBGBGBGB 0 */\
  298. "movq "#q2", "#q3" \n\t" /* GBGBGBGB 2 */\
  299. "punpcklwd "#r", "#q0" \n\t" /* ARGBARGB 0 */\
  300. "punpckhwd "#r", "#b" \n\t" /* ARGBARGB 1 */\
  301. "punpcklwd "#t", "#q2" \n\t" /* ARGBARGB 2 */\
  302. "punpckhwd "#t", "#q3" \n\t" /* ARGBARGB 3 */\
  303. \
  304. MOVNTQ( q0, (dst, index, 4))\
  305. MOVNTQ( b, 8(dst, index, 4))\
  306. MOVNTQ( q2, 16(dst, index, 4))\
  307. MOVNTQ( q3, 24(dst, index, 4))\
  308. \
  309. "add $8, "#index" \n\t"\
  310. "cmp "#dstw", "#index" \n\t"\
  311. " jb 1b \n\t"
  312. #define WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t) REAL_WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t)
  313. static void RENAME(yuv2rgb32_X_ar)(SwsContext *c, const int16_t *lumFilter,
  314. const int16_t **lumSrc, int lumFilterSize,
  315. const int16_t *chrFilter, const int16_t **chrUSrc,
  316. const int16_t **chrVSrc,
  317. int chrFilterSize, const int16_t **alpSrc,
  318. uint8_t *dest, int dstW, int dstY)
  319. {
  320. x86_reg dummy=0;
  321. x86_reg dstW_reg = dstW;
  322. x86_reg uv_off = c->uv_offx2;
  323. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  324. YSCALEYUV2PACKEDX_ACCURATE
  325. YSCALEYUV2RGBX
  326. "movq %%mm2, "U_TEMP"(%0) \n\t"
  327. "movq %%mm4, "V_TEMP"(%0) \n\t"
  328. "movq %%mm5, "Y_TEMP"(%0) \n\t"
  329. YSCALEYUV2PACKEDX_ACCURATE_YA(ALP_MMX_FILTER_OFFSET)
  330. "movq "Y_TEMP"(%0), %%mm5 \n\t"
  331. "psraw $3, %%mm1 \n\t"
  332. "psraw $3, %%mm7 \n\t"
  333. "packuswb %%mm7, %%mm1 \n\t"
  334. WRITEBGR32(%4, %5, %%REGa, %%mm3, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm2, %%mm6)
  335. YSCALEYUV2PACKEDX_END
  336. } else {
  337. YSCALEYUV2PACKEDX_ACCURATE
  338. YSCALEYUV2RGBX
  339. "pcmpeqd %%mm7, %%mm7 \n\t"
  340. WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  341. YSCALEYUV2PACKEDX_END
  342. }
  343. }
  344. static void RENAME(yuv2rgb32_X)(SwsContext *c, const int16_t *lumFilter,
  345. const int16_t **lumSrc, int lumFilterSize,
  346. const int16_t *chrFilter, const int16_t **chrUSrc,
  347. const int16_t **chrVSrc,
  348. int chrFilterSize, const int16_t **alpSrc,
  349. uint8_t *dest, int dstW, int dstY)
  350. {
  351. x86_reg dummy=0;
  352. x86_reg dstW_reg = dstW;
  353. x86_reg uv_off = c->uv_offx2;
  354. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  355. YSCALEYUV2PACKEDX
  356. YSCALEYUV2RGBX
  357. YSCALEYUV2PACKEDX_YA(ALP_MMX_FILTER_OFFSET, %%mm0, %%mm3, %%mm6, %%mm1, %%mm7)
  358. "psraw $3, %%mm1 \n\t"
  359. "psraw $3, %%mm7 \n\t"
  360. "packuswb %%mm7, %%mm1 \n\t"
  361. WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6)
  362. YSCALEYUV2PACKEDX_END
  363. } else {
  364. YSCALEYUV2PACKEDX
  365. YSCALEYUV2RGBX
  366. "pcmpeqd %%mm7, %%mm7 \n\t"
  367. WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  368. YSCALEYUV2PACKEDX_END
  369. }
  370. }
  371. #define REAL_WRITERGB16(dst, dstw, index) \
  372. "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\
  373. "pand "MANGLE(bFC)", %%mm4 \n\t" /* G */\
  374. "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\
  375. "psrlq $3, %%mm2 \n\t"\
  376. \
  377. "movq %%mm2, %%mm1 \n\t"\
  378. "movq %%mm4, %%mm3 \n\t"\
  379. \
  380. "punpcklbw %%mm7, %%mm3 \n\t"\
  381. "punpcklbw %%mm5, %%mm2 \n\t"\
  382. "punpckhbw %%mm7, %%mm4 \n\t"\
  383. "punpckhbw %%mm5, %%mm1 \n\t"\
  384. \
  385. "psllq $3, %%mm3 \n\t"\
  386. "psllq $3, %%mm4 \n\t"\
  387. \
  388. "por %%mm3, %%mm2 \n\t"\
  389. "por %%mm4, %%mm1 \n\t"\
  390. \
  391. MOVNTQ(%%mm2, (dst, index, 2))\
  392. MOVNTQ(%%mm1, 8(dst, index, 2))\
  393. \
  394. "add $8, "#index" \n\t"\
  395. "cmp "#dstw", "#index" \n\t"\
  396. " jb 1b \n\t"
  397. #define WRITERGB16(dst, dstw, index) REAL_WRITERGB16(dst, dstw, index)
  398. static void RENAME(yuv2rgb565_X_ar)(SwsContext *c, const int16_t *lumFilter,
  399. const int16_t **lumSrc, int lumFilterSize,
  400. const int16_t *chrFilter, const int16_t **chrUSrc,
  401. const int16_t **chrVSrc,
  402. int chrFilterSize, const int16_t **alpSrc,
  403. uint8_t *dest, int dstW, int dstY)
  404. {
  405. x86_reg dummy=0;
  406. x86_reg dstW_reg = dstW;
  407. x86_reg uv_off = c->uv_offx2;
  408. YSCALEYUV2PACKEDX_ACCURATE
  409. YSCALEYUV2RGBX
  410. "pxor %%mm7, %%mm7 \n\t"
  411. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  412. #ifdef DITHER1XBPP
  413. "paddusb "BLUE_DITHER"(%0), %%mm2\n\t"
  414. "paddusb "GREEN_DITHER"(%0), %%mm4\n\t"
  415. "paddusb "RED_DITHER"(%0), %%mm5\n\t"
  416. #endif
  417. WRITERGB16(%4, %5, %%REGa)
  418. YSCALEYUV2PACKEDX_END
  419. }
  420. static void RENAME(yuv2rgb565_X)(SwsContext *c, const int16_t *lumFilter,
  421. const int16_t **lumSrc, int lumFilterSize,
  422. const int16_t *chrFilter, const int16_t **chrUSrc,
  423. const int16_t **chrVSrc,
  424. int chrFilterSize, const int16_t **alpSrc,
  425. uint8_t *dest, int dstW, int dstY)
  426. {
  427. x86_reg dummy=0;
  428. x86_reg dstW_reg = dstW;
  429. x86_reg uv_off = c->uv_offx2;
  430. YSCALEYUV2PACKEDX
  431. YSCALEYUV2RGBX
  432. "pxor %%mm7, %%mm7 \n\t"
  433. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  434. #ifdef DITHER1XBPP
  435. "paddusb "BLUE_DITHER"(%0), %%mm2 \n\t"
  436. "paddusb "GREEN_DITHER"(%0), %%mm4 \n\t"
  437. "paddusb "RED_DITHER"(%0), %%mm5 \n\t"
  438. #endif
  439. WRITERGB16(%4, %5, %%REGa)
  440. YSCALEYUV2PACKEDX_END
  441. }
  442. #define REAL_WRITERGB15(dst, dstw, index) \
  443. "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\
  444. "pand "MANGLE(bF8)", %%mm4 \n\t" /* G */\
  445. "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\
  446. "psrlq $3, %%mm2 \n\t"\
  447. "psrlq $1, %%mm5 \n\t"\
  448. \
  449. "movq %%mm2, %%mm1 \n\t"\
  450. "movq %%mm4, %%mm3 \n\t"\
  451. \
  452. "punpcklbw %%mm7, %%mm3 \n\t"\
  453. "punpcklbw %%mm5, %%mm2 \n\t"\
  454. "punpckhbw %%mm7, %%mm4 \n\t"\
  455. "punpckhbw %%mm5, %%mm1 \n\t"\
  456. \
  457. "psllq $2, %%mm3 \n\t"\
  458. "psllq $2, %%mm4 \n\t"\
  459. \
  460. "por %%mm3, %%mm2 \n\t"\
  461. "por %%mm4, %%mm1 \n\t"\
  462. \
  463. MOVNTQ(%%mm2, (dst, index, 2))\
  464. MOVNTQ(%%mm1, 8(dst, index, 2))\
  465. \
  466. "add $8, "#index" \n\t"\
  467. "cmp "#dstw", "#index" \n\t"\
  468. " jb 1b \n\t"
  469. #define WRITERGB15(dst, dstw, index) REAL_WRITERGB15(dst, dstw, index)
  470. static void RENAME(yuv2rgb555_X_ar)(SwsContext *c, const int16_t *lumFilter,
  471. const int16_t **lumSrc, int lumFilterSize,
  472. const int16_t *chrFilter, const int16_t **chrUSrc,
  473. const int16_t **chrVSrc,
  474. int chrFilterSize, const int16_t **alpSrc,
  475. uint8_t *dest, int dstW, int dstY)
  476. {
  477. x86_reg dummy=0;
  478. x86_reg dstW_reg = dstW;
  479. x86_reg uv_off = c->uv_offx2;
  480. YSCALEYUV2PACKEDX_ACCURATE
  481. YSCALEYUV2RGBX
  482. "pxor %%mm7, %%mm7 \n\t"
  483. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  484. #ifdef DITHER1XBPP
  485. "paddusb "BLUE_DITHER"(%0), %%mm2\n\t"
  486. "paddusb "GREEN_DITHER"(%0), %%mm4\n\t"
  487. "paddusb "RED_DITHER"(%0), %%mm5\n\t"
  488. #endif
  489. WRITERGB15(%4, %5, %%REGa)
  490. YSCALEYUV2PACKEDX_END
  491. }
  492. static void RENAME(yuv2rgb555_X)(SwsContext *c, const int16_t *lumFilter,
  493. const int16_t **lumSrc, int lumFilterSize,
  494. const int16_t *chrFilter, const int16_t **chrUSrc,
  495. const int16_t **chrVSrc,
  496. int chrFilterSize, const int16_t **alpSrc,
  497. uint8_t *dest, int dstW, int dstY)
  498. {
  499. x86_reg dummy=0;
  500. x86_reg dstW_reg = dstW;
  501. x86_reg uv_off = c->uv_offx2;
  502. YSCALEYUV2PACKEDX
  503. YSCALEYUV2RGBX
  504. "pxor %%mm7, %%mm7 \n\t"
  505. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  506. #ifdef DITHER1XBPP
  507. "paddusb "BLUE_DITHER"(%0), %%mm2 \n\t"
  508. "paddusb "GREEN_DITHER"(%0), %%mm4 \n\t"
  509. "paddusb "RED_DITHER"(%0), %%mm5 \n\t"
  510. #endif
  511. WRITERGB15(%4, %5, %%REGa)
  512. YSCALEYUV2PACKEDX_END
  513. }
  514. #define WRITEBGR24MMX(dst, dstw, index) \
  515. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
  516. "movq %%mm2, %%mm1 \n\t" /* B */\
  517. "movq %%mm5, %%mm6 \n\t" /* R */\
  518. "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\
  519. "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\
  520. "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\
  521. "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\
  522. "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\
  523. "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\
  524. "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\
  525. "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\
  526. "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\
  527. "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\
  528. \
  529. "movq %%mm0, %%mm4 \n\t" /* 0RGB0RGB 0 */\
  530. "movq %%mm2, %%mm6 \n\t" /* 0RGB0RGB 1 */\
  531. "movq %%mm1, %%mm5 \n\t" /* 0RGB0RGB 2 */\
  532. "movq %%mm3, %%mm7 \n\t" /* 0RGB0RGB 3 */\
  533. \
  534. "psllq $40, %%mm0 \n\t" /* RGB00000 0 */\
  535. "psllq $40, %%mm2 \n\t" /* RGB00000 1 */\
  536. "psllq $40, %%mm1 \n\t" /* RGB00000 2 */\
  537. "psllq $40, %%mm3 \n\t" /* RGB00000 3 */\
  538. \
  539. "punpckhdq %%mm4, %%mm0 \n\t" /* 0RGBRGB0 0 */\
  540. "punpckhdq %%mm6, %%mm2 \n\t" /* 0RGBRGB0 1 */\
  541. "punpckhdq %%mm5, %%mm1 \n\t" /* 0RGBRGB0 2 */\
  542. "punpckhdq %%mm7, %%mm3 \n\t" /* 0RGBRGB0 3 */\
  543. \
  544. "psrlq $8, %%mm0 \n\t" /* 00RGBRGB 0 */\
  545. "movq %%mm2, %%mm6 \n\t" /* 0RGBRGB0 1 */\
  546. "psllq $40, %%mm2 \n\t" /* GB000000 1 */\
  547. "por %%mm2, %%mm0 \n\t" /* GBRGBRGB 0 */\
  548. MOVNTQ(%%mm0, (dst))\
  549. \
  550. "psrlq $24, %%mm6 \n\t" /* 0000RGBR 1 */\
  551. "movq %%mm1, %%mm5 \n\t" /* 0RGBRGB0 2 */\
  552. "psllq $24, %%mm1 \n\t" /* BRGB0000 2 */\
  553. "por %%mm1, %%mm6 \n\t" /* BRGBRGBR 1 */\
  554. MOVNTQ(%%mm6, 8(dst))\
  555. \
  556. "psrlq $40, %%mm5 \n\t" /* 000000RG 2 */\
  557. "psllq $8, %%mm3 \n\t" /* RGBRGB00 3 */\
  558. "por %%mm3, %%mm5 \n\t" /* RGBRGBRG 2 */\
  559. MOVNTQ(%%mm5, 16(dst))\
  560. \
  561. "add $24, "#dst" \n\t"\
  562. \
  563. "add $8, "#index" \n\t"\
  564. "cmp "#dstw", "#index" \n\t"\
  565. " jb 1b \n\t"
  566. #define WRITEBGR24MMX2(dst, dstw, index) \
  567. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
  568. "movq "MANGLE(ff_M24A)", %%mm0 \n\t"\
  569. "movq "MANGLE(ff_M24C)", %%mm7 \n\t"\
  570. "pshufw $0x50, %%mm2, %%mm1 \n\t" /* B3 B2 B3 B2 B1 B0 B1 B0 */\
  571. "pshufw $0x50, %%mm4, %%mm3 \n\t" /* G3 G2 G3 G2 G1 G0 G1 G0 */\
  572. "pshufw $0x00, %%mm5, %%mm6 \n\t" /* R1 R0 R1 R0 R1 R0 R1 R0 */\
  573. \
  574. "pand %%mm0, %%mm1 \n\t" /* B2 B1 B0 */\
  575. "pand %%mm0, %%mm3 \n\t" /* G2 G1 G0 */\
  576. "pand %%mm7, %%mm6 \n\t" /* R1 R0 */\
  577. \
  578. "psllq $8, %%mm3 \n\t" /* G2 G1 G0 */\
  579. "por %%mm1, %%mm6 \n\t"\
  580. "por %%mm3, %%mm6 \n\t"\
  581. MOVNTQ(%%mm6, (dst))\
  582. \
  583. "psrlq $8, %%mm4 \n\t" /* 00 G7 G6 G5 G4 G3 G2 G1 */\
  584. "pshufw $0xA5, %%mm2, %%mm1 \n\t" /* B5 B4 B5 B4 B3 B2 B3 B2 */\
  585. "pshufw $0x55, %%mm4, %%mm3 \n\t" /* G4 G3 G4 G3 G4 G3 G4 G3 */\
  586. "pshufw $0xA5, %%mm5, %%mm6 \n\t" /* R5 R4 R5 R4 R3 R2 R3 R2 */\
  587. \
  588. "pand "MANGLE(ff_M24B)", %%mm1 \n\t" /* B5 B4 B3 */\
  589. "pand %%mm7, %%mm3 \n\t" /* G4 G3 */\
  590. "pand %%mm0, %%mm6 \n\t" /* R4 R3 R2 */\
  591. \
  592. "por %%mm1, %%mm3 \n\t" /* B5 G4 B4 G3 B3 */\
  593. "por %%mm3, %%mm6 \n\t"\
  594. MOVNTQ(%%mm6, 8(dst))\
  595. \
  596. "pshufw $0xFF, %%mm2, %%mm1 \n\t" /* B7 B6 B7 B6 B7 B6 B6 B7 */\
  597. "pshufw $0xFA, %%mm4, %%mm3 \n\t" /* 00 G7 00 G7 G6 G5 G6 G5 */\
  598. "pshufw $0xFA, %%mm5, %%mm6 \n\t" /* R7 R6 R7 R6 R5 R4 R5 R4 */\
  599. \
  600. "pand %%mm7, %%mm1 \n\t" /* B7 B6 */\
  601. "pand %%mm0, %%mm3 \n\t" /* G7 G6 G5 */\
  602. "pand "MANGLE(ff_M24B)", %%mm6 \n\t" /* R7 R6 R5 */\
  603. \
  604. "por %%mm1, %%mm3 \n\t"\
  605. "por %%mm3, %%mm6 \n\t"\
  606. MOVNTQ(%%mm6, 16(dst))\
  607. \
  608. "add $24, "#dst" \n\t"\
  609. \
  610. "add $8, "#index" \n\t"\
  611. "cmp "#dstw", "#index" \n\t"\
  612. " jb 1b \n\t"
  613. #if COMPILE_TEMPLATE_MMX2
  614. #undef WRITEBGR24
  615. #define WRITEBGR24(dst, dstw, index) WRITEBGR24MMX2(dst, dstw, index)
  616. #else
  617. #undef WRITEBGR24
  618. #define WRITEBGR24(dst, dstw, index) WRITEBGR24MMX(dst, dstw, index)
  619. #endif
  620. static void RENAME(yuv2bgr24_X_ar)(SwsContext *c, const int16_t *lumFilter,
  621. const int16_t **lumSrc, int lumFilterSize,
  622. const int16_t *chrFilter, const int16_t **chrUSrc,
  623. const int16_t **chrVSrc,
  624. int chrFilterSize, const int16_t **alpSrc,
  625. uint8_t *dest, int dstW, int dstY)
  626. {
  627. x86_reg dummy=0;
  628. x86_reg dstW_reg = dstW;
  629. x86_reg uv_off = c->uv_offx2;
  630. YSCALEYUV2PACKEDX_ACCURATE
  631. YSCALEYUV2RGBX
  632. "pxor %%mm7, %%mm7 \n\t"
  633. "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"\n\t" //FIXME optimize
  634. "add %4, %%"REG_c" \n\t"
  635. WRITEBGR24(%%REGc, %5, %%REGa)
  636. :: "r" (&c->redDither),
  637. "m" (dummy), "m" (dummy), "m" (dummy),
  638. "r" (dest), "m" (dstW_reg), "m"(uv_off)
  639. : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S
  640. );
  641. }
  642. static void RENAME(yuv2bgr24_X)(SwsContext *c, const int16_t *lumFilter,
  643. const int16_t **lumSrc, int lumFilterSize,
  644. const int16_t *chrFilter, const int16_t **chrUSrc,
  645. const int16_t **chrVSrc,
  646. int chrFilterSize, const int16_t **alpSrc,
  647. uint8_t *dest, int dstW, int dstY)
  648. {
  649. x86_reg dummy=0;
  650. x86_reg dstW_reg = dstW;
  651. x86_reg uv_off = c->uv_offx2;
  652. YSCALEYUV2PACKEDX
  653. YSCALEYUV2RGBX
  654. "pxor %%mm7, %%mm7 \n\t"
  655. "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c" \n\t" //FIXME optimize
  656. "add %4, %%"REG_c" \n\t"
  657. WRITEBGR24(%%REGc, %5, %%REGa)
  658. :: "r" (&c->redDither),
  659. "m" (dummy), "m" (dummy), "m" (dummy),
  660. "r" (dest), "m" (dstW_reg), "m"(uv_off)
  661. : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S
  662. );
  663. }
  664. #define REAL_WRITEYUY2(dst, dstw, index) \
  665. "packuswb %%mm3, %%mm3 \n\t"\
  666. "packuswb %%mm4, %%mm4 \n\t"\
  667. "packuswb %%mm7, %%mm1 \n\t"\
  668. "punpcklbw %%mm4, %%mm3 \n\t"\
  669. "movq %%mm1, %%mm7 \n\t"\
  670. "punpcklbw %%mm3, %%mm1 \n\t"\
  671. "punpckhbw %%mm3, %%mm7 \n\t"\
  672. \
  673. MOVNTQ(%%mm1, (dst, index, 2))\
  674. MOVNTQ(%%mm7, 8(dst, index, 2))\
  675. \
  676. "add $8, "#index" \n\t"\
  677. "cmp "#dstw", "#index" \n\t"\
  678. " jb 1b \n\t"
  679. #define WRITEYUY2(dst, dstw, index) REAL_WRITEYUY2(dst, dstw, index)
  680. static void RENAME(yuv2yuyv422_X_ar)(SwsContext *c, const int16_t *lumFilter,
  681. const int16_t **lumSrc, int lumFilterSize,
  682. const int16_t *chrFilter, const int16_t **chrUSrc,
  683. const int16_t **chrVSrc,
  684. int chrFilterSize, const int16_t **alpSrc,
  685. uint8_t *dest, int dstW, int dstY)
  686. {
  687. x86_reg dummy=0;
  688. x86_reg dstW_reg = dstW;
  689. x86_reg uv_off = c->uv_offx2;
  690. YSCALEYUV2PACKEDX_ACCURATE
  691. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  692. "psraw $3, %%mm3 \n\t"
  693. "psraw $3, %%mm4 \n\t"
  694. "psraw $3, %%mm1 \n\t"
  695. "psraw $3, %%mm7 \n\t"
  696. WRITEYUY2(%4, %5, %%REGa)
  697. YSCALEYUV2PACKEDX_END
  698. }
  699. static void RENAME(yuv2yuyv422_X)(SwsContext *c, const int16_t *lumFilter,
  700. const int16_t **lumSrc, int lumFilterSize,
  701. const int16_t *chrFilter, const int16_t **chrUSrc,
  702. const int16_t **chrVSrc,
  703. int chrFilterSize, const int16_t **alpSrc,
  704. uint8_t *dest, int dstW, int dstY)
  705. {
  706. x86_reg dummy=0;
  707. x86_reg dstW_reg = dstW;
  708. x86_reg uv_off = c->uv_offx2;
  709. YSCALEYUV2PACKEDX
  710. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  711. "psraw $3, %%mm3 \n\t"
  712. "psraw $3, %%mm4 \n\t"
  713. "psraw $3, %%mm1 \n\t"
  714. "psraw $3, %%mm7 \n\t"
  715. WRITEYUY2(%4, %5, %%REGa)
  716. YSCALEYUV2PACKEDX_END
  717. }
  718. #define REAL_YSCALEYUV2RGB_UV(index, c) \
  719. "xor "#index", "#index" \n\t"\
  720. ".p2align 4 \n\t"\
  721. "1: \n\t"\
  722. "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
  723. "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
  724. "add "UV_OFFx2"("#c"), "#index" \n\t" \
  725. "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  726. "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  727. "sub "UV_OFFx2"("#c"), "#index" \n\t" \
  728. "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
  729. "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
  730. "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\
  731. "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
  732. "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
  733. "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  734. "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  735. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
  736. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
  737. "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\
  738. "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\
  739. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  740. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  741. "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\
  742. "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\
  743. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  744. #define REAL_YSCALEYUV2RGB_YA(index, c, b1, b2) \
  745. "movq ("#b1", "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\
  746. "movq ("#b2", "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\
  747. "movq 8("#b1", "#index", 2), %%mm6 \n\t" /*buf0[eax]*/\
  748. "movq 8("#b2", "#index", 2), %%mm7 \n\t" /*buf1[eax]*/\
  749. "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
  750. "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\
  751. "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  752. "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  753. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  754. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  755. "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  756. "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  757. #define REAL_YSCALEYUV2RGB_COEFF(c) \
  758. "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\
  759. "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\
  760. "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\
  761. "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\
  762. "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\
  763. "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\
  764. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  765. "paddw %%mm3, %%mm4 \n\t"\
  766. "movq %%mm2, %%mm0 \n\t"\
  767. "movq %%mm5, %%mm6 \n\t"\
  768. "movq %%mm4, %%mm3 \n\t"\
  769. "punpcklwd %%mm2, %%mm2 \n\t"\
  770. "punpcklwd %%mm5, %%mm5 \n\t"\
  771. "punpcklwd %%mm4, %%mm4 \n\t"\
  772. "paddw %%mm1, %%mm2 \n\t"\
  773. "paddw %%mm1, %%mm5 \n\t"\
  774. "paddw %%mm1, %%mm4 \n\t"\
  775. "punpckhwd %%mm0, %%mm0 \n\t"\
  776. "punpckhwd %%mm6, %%mm6 \n\t"\
  777. "punpckhwd %%mm3, %%mm3 \n\t"\
  778. "paddw %%mm7, %%mm0 \n\t"\
  779. "paddw %%mm7, %%mm6 \n\t"\
  780. "paddw %%mm7, %%mm3 \n\t"\
  781. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  782. "packuswb %%mm0, %%mm2 \n\t"\
  783. "packuswb %%mm6, %%mm5 \n\t"\
  784. "packuswb %%mm3, %%mm4 \n\t"\
  785. #define YSCALEYUV2RGB_YA(index, c, b1, b2) REAL_YSCALEYUV2RGB_YA(index, c, b1, b2)
  786. #define YSCALEYUV2RGB(index, c) \
  787. REAL_YSCALEYUV2RGB_UV(index, c) \
  788. REAL_YSCALEYUV2RGB_YA(index, c, %0, %1) \
  789. REAL_YSCALEYUV2RGB_COEFF(c)
  790. /**
  791. * vertical bilinear scale YV12 to RGB
  792. */
  793. static void RENAME(yuv2rgb32_2)(SwsContext *c, const int16_t *buf[2],
  794. const int16_t *ubuf[2], const int16_t *vbuf[2],
  795. const int16_t *abuf[2], uint8_t *dest,
  796. int dstW, int yalpha, int uvalpha, int y)
  797. {
  798. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  799. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  800. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  801. const int16_t *abuf0 = abuf[0], *abuf1 = abuf[1];
  802. #if ARCH_X86_64
  803. __asm__ volatile(
  804. YSCALEYUV2RGB(%%r8, %5)
  805. YSCALEYUV2RGB_YA(%%r8, %5, %6, %7)
  806. "psraw $3, %%mm1 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
  807. "psraw $3, %%mm7 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
  808. "packuswb %%mm7, %%mm1 \n\t"
  809. WRITEBGR32(%4, 8280(%5), %%r8, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6)
  810. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "r" (dest),
  811. "a" (&c->redDither),
  812. "r" (abuf0), "r" (abuf1)
  813. : "%r8"
  814. );
  815. #else
  816. c->u_temp=(intptr_t)abuf0;
  817. c->v_temp=(intptr_t)abuf1;
  818. __asm__ volatile(
  819. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  820. "mov %4, %%"REG_b" \n\t"
  821. "push %%"REG_BP" \n\t"
  822. YSCALEYUV2RGB(%%REGBP, %5)
  823. "push %0 \n\t"
  824. "push %1 \n\t"
  825. "mov "U_TEMP"(%5), %0 \n\t"
  826. "mov "V_TEMP"(%5), %1 \n\t"
  827. YSCALEYUV2RGB_YA(%%REGBP, %5, %0, %1)
  828. "psraw $3, %%mm1 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
  829. "psraw $3, %%mm7 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
  830. "packuswb %%mm7, %%mm1 \n\t"
  831. "pop %1 \n\t"
  832. "pop %0 \n\t"
  833. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6)
  834. "pop %%"REG_BP" \n\t"
  835. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  836. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  837. "a" (&c->redDither)
  838. );
  839. #endif
  840. } else {
  841. __asm__ volatile(
  842. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  843. "mov %4, %%"REG_b" \n\t"
  844. "push %%"REG_BP" \n\t"
  845. YSCALEYUV2RGB(%%REGBP, %5)
  846. "pcmpeqd %%mm7, %%mm7 \n\t"
  847. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  848. "pop %%"REG_BP" \n\t"
  849. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  850. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  851. "a" (&c->redDither)
  852. );
  853. }
  854. }
  855. static void RENAME(yuv2bgr24_2)(SwsContext *c, const int16_t *buf[2],
  856. const int16_t *ubuf[2], const int16_t *vbuf[2],
  857. const int16_t *abuf[2], uint8_t *dest,
  858. int dstW, int yalpha, int uvalpha, int y)
  859. {
  860. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  861. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  862. //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
  863. __asm__ volatile(
  864. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  865. "mov %4, %%"REG_b" \n\t"
  866. "push %%"REG_BP" \n\t"
  867. YSCALEYUV2RGB(%%REGBP, %5)
  868. "pxor %%mm7, %%mm7 \n\t"
  869. WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
  870. "pop %%"REG_BP" \n\t"
  871. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  872. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  873. "a" (&c->redDither)
  874. );
  875. }
  876. static void RENAME(yuv2rgb555_2)(SwsContext *c, const int16_t *buf[2],
  877. const int16_t *ubuf[2], const int16_t *vbuf[2],
  878. const int16_t *abuf[2], uint8_t *dest,
  879. int dstW, int yalpha, int uvalpha, int y)
  880. {
  881. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  882. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  883. //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
  884. __asm__ volatile(
  885. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  886. "mov %4, %%"REG_b" \n\t"
  887. "push %%"REG_BP" \n\t"
  888. YSCALEYUV2RGB(%%REGBP, %5)
  889. "pxor %%mm7, %%mm7 \n\t"
  890. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  891. #ifdef DITHER1XBPP
  892. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  893. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  894. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  895. #endif
  896. WRITERGB15(%%REGb, 8280(%5), %%REGBP)
  897. "pop %%"REG_BP" \n\t"
  898. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  899. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  900. "a" (&c->redDither)
  901. );
  902. }
  903. static void RENAME(yuv2rgb565_2)(SwsContext *c, const int16_t *buf[2],
  904. const int16_t *ubuf[2], const int16_t *vbuf[2],
  905. const int16_t *abuf[2], uint8_t *dest,
  906. int dstW, int yalpha, int uvalpha, int y)
  907. {
  908. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  909. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  910. //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
  911. __asm__ volatile(
  912. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  913. "mov %4, %%"REG_b" \n\t"
  914. "push %%"REG_BP" \n\t"
  915. YSCALEYUV2RGB(%%REGBP, %5)
  916. "pxor %%mm7, %%mm7 \n\t"
  917. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  918. #ifdef DITHER1XBPP
  919. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  920. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  921. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  922. #endif
  923. WRITERGB16(%%REGb, 8280(%5), %%REGBP)
  924. "pop %%"REG_BP" \n\t"
  925. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  926. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  927. "a" (&c->redDither)
  928. );
  929. }
  930. #define REAL_YSCALEYUV2PACKED(index, c) \
  931. "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\
  932. "movq "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm1 \n\t"\
  933. "psraw $3, %%mm0 \n\t"\
  934. "psraw $3, %%mm1 \n\t"\
  935. "movq %%mm0, "CHR_MMX_FILTER_OFFSET"+8("#c") \n\t"\
  936. "movq %%mm1, "LUM_MMX_FILTER_OFFSET"+8("#c") \n\t"\
  937. "xor "#index", "#index" \n\t"\
  938. ".p2align 4 \n\t"\
  939. "1: \n\t"\
  940. "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
  941. "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
  942. "add "UV_OFFx2"("#c"), "#index" \n\t" \
  943. "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  944. "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  945. "sub "UV_OFFx2"("#c"), "#index" \n\t" \
  946. "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
  947. "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
  948. "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\
  949. "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
  950. "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
  951. "psraw $7, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  952. "psraw $7, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  953. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
  954. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
  955. "movq (%0, "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\
  956. "movq (%1, "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\
  957. "movq 8(%0, "#index", 2), %%mm6 \n\t" /*buf0[eax]*/\
  958. "movq 8(%1, "#index", 2), %%mm7 \n\t" /*buf1[eax]*/\
  959. "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
  960. "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\
  961. "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  962. "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  963. "psraw $7, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  964. "psraw $7, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  965. "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  966. "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  967. #define YSCALEYUV2PACKED(index, c) REAL_YSCALEYUV2PACKED(index, c)
  968. static void RENAME(yuv2yuyv422_2)(SwsContext *c, const int16_t *buf[2],
  969. const int16_t *ubuf[2], const int16_t *vbuf[2],
  970. const int16_t *abuf[2], uint8_t *dest,
  971. int dstW, int yalpha, int uvalpha, int y)
  972. {
  973. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  974. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  975. //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
  976. __asm__ volatile(
  977. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  978. "mov %4, %%"REG_b" \n\t"
  979. "push %%"REG_BP" \n\t"
  980. YSCALEYUV2PACKED(%%REGBP, %5)
  981. WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
  982. "pop %%"REG_BP" \n\t"
  983. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  984. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  985. "a" (&c->redDither)
  986. );
  987. }
  988. #define REAL_YSCALEYUV2RGB1(index, c) \
  989. "xor "#index", "#index" \n\t"\
  990. ".p2align 4 \n\t"\
  991. "1: \n\t"\
  992. "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\
  993. "add "UV_OFFx2"("#c"), "#index" \n\t" \
  994. "movq (%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
  995. "sub "UV_OFFx2"("#c"), "#index" \n\t" \
  996. "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  997. "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  998. "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\
  999. "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\
  1000. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  1001. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  1002. "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\
  1003. "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\
  1004. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  1005. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1006. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1007. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1008. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1009. "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\
  1010. "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\
  1011. "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\
  1012. "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\
  1013. "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\
  1014. "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\
  1015. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  1016. "paddw %%mm3, %%mm4 \n\t"\
  1017. "movq %%mm2, %%mm0 \n\t"\
  1018. "movq %%mm5, %%mm6 \n\t"\
  1019. "movq %%mm4, %%mm3 \n\t"\
  1020. "punpcklwd %%mm2, %%mm2 \n\t"\
  1021. "punpcklwd %%mm5, %%mm5 \n\t"\
  1022. "punpcklwd %%mm4, %%mm4 \n\t"\
  1023. "paddw %%mm1, %%mm2 \n\t"\
  1024. "paddw %%mm1, %%mm5 \n\t"\
  1025. "paddw %%mm1, %%mm4 \n\t"\
  1026. "punpckhwd %%mm0, %%mm0 \n\t"\
  1027. "punpckhwd %%mm6, %%mm6 \n\t"\
  1028. "punpckhwd %%mm3, %%mm3 \n\t"\
  1029. "paddw %%mm7, %%mm0 \n\t"\
  1030. "paddw %%mm7, %%mm6 \n\t"\
  1031. "paddw %%mm7, %%mm3 \n\t"\
  1032. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  1033. "packuswb %%mm0, %%mm2 \n\t"\
  1034. "packuswb %%mm6, %%mm5 \n\t"\
  1035. "packuswb %%mm3, %%mm4 \n\t"\
  1036. #define YSCALEYUV2RGB1(index, c) REAL_YSCALEYUV2RGB1(index, c)
  1037. // do vertical chrominance interpolation
  1038. #define REAL_YSCALEYUV2RGB1b(index, c) \
  1039. "xor "#index", "#index" \n\t"\
  1040. ".p2align 4 \n\t"\
  1041. "1: \n\t"\
  1042. "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
  1043. "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
  1044. "add "UV_OFFx2"("#c"), "#index" \n\t" \
  1045. "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  1046. "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  1047. "sub "UV_OFFx2"("#c"), "#index" \n\t" \
  1048. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
  1049. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
  1050. "psrlw $5, %%mm3 \n\t" /*FIXME might overflow*/\
  1051. "psrlw $5, %%mm4 \n\t" /*FIXME might overflow*/\
  1052. "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\
  1053. "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\
  1054. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  1055. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  1056. "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\
  1057. "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\
  1058. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  1059. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1060. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1061. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1062. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1063. "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\
  1064. "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\
  1065. "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\
  1066. "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\
  1067. "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\
  1068. "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\
  1069. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  1070. "paddw %%mm3, %%mm4 \n\t"\
  1071. "movq %%mm2, %%mm0 \n\t"\
  1072. "movq %%mm5, %%mm6 \n\t"\
  1073. "movq %%mm4, %%mm3 \n\t"\
  1074. "punpcklwd %%mm2, %%mm2 \n\t"\
  1075. "punpcklwd %%mm5, %%mm5 \n\t"\
  1076. "punpcklwd %%mm4, %%mm4 \n\t"\
  1077. "paddw %%mm1, %%mm2 \n\t"\
  1078. "paddw %%mm1, %%mm5 \n\t"\
  1079. "paddw %%mm1, %%mm4 \n\t"\
  1080. "punpckhwd %%mm0, %%mm0 \n\t"\
  1081. "punpckhwd %%mm6, %%mm6 \n\t"\
  1082. "punpckhwd %%mm3, %%mm3 \n\t"\
  1083. "paddw %%mm7, %%mm0 \n\t"\
  1084. "paddw %%mm7, %%mm6 \n\t"\
  1085. "paddw %%mm7, %%mm3 \n\t"\
  1086. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  1087. "packuswb %%mm0, %%mm2 \n\t"\
  1088. "packuswb %%mm6, %%mm5 \n\t"\
  1089. "packuswb %%mm3, %%mm4 \n\t"\
  1090. #define YSCALEYUV2RGB1b(index, c) REAL_YSCALEYUV2RGB1b(index, c)
  1091. #define REAL_YSCALEYUV2RGB1_ALPHA(index) \
  1092. "movq (%1, "#index", 2), %%mm7 \n\t" /* abuf0[index ] */\
  1093. "movq 8(%1, "#index", 2), %%mm1 \n\t" /* abuf0[index+4] */\
  1094. "psraw $7, %%mm7 \n\t" /* abuf0[index ] >>7 */\
  1095. "psraw $7, %%mm1 \n\t" /* abuf0[index+4] >>7 */\
  1096. "packuswb %%mm1, %%mm7 \n\t"
  1097. #define YSCALEYUV2RGB1_ALPHA(index) REAL_YSCALEYUV2RGB1_ALPHA(index)
  1098. /**
  1099. * YV12 to RGB without scaling or interpolating
  1100. */
  1101. static void RENAME(yuv2rgb32_1)(SwsContext *c, const int16_t *buf0,
  1102. const int16_t *ubuf[2], const int16_t *bguf[2],
  1103. const int16_t *abuf0, uint8_t *dest,
  1104. int dstW, int uvalpha, int y)
  1105. {
  1106. const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  1107. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1108. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1109. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  1110. __asm__ volatile(
  1111. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1112. "mov %4, %%"REG_b" \n\t"
  1113. "push %%"REG_BP" \n\t"
  1114. YSCALEYUV2RGB1(%%REGBP, %5)
  1115. YSCALEYUV2RGB1_ALPHA(%%REGBP)
  1116. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  1117. "pop %%"REG_BP" \n\t"
  1118. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1119. :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1120. "a" (&c->redDither)
  1121. );
  1122. } else {
  1123. __asm__ volatile(
  1124. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1125. "mov %4, %%"REG_b" \n\t"
  1126. "push %%"REG_BP" \n\t"
  1127. YSCALEYUV2RGB1(%%REGBP, %5)
  1128. "pcmpeqd %%mm7, %%mm7 \n\t"
  1129. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  1130. "pop %%"REG_BP" \n\t"
  1131. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1132. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1133. "a" (&c->redDither)
  1134. );
  1135. }
  1136. } else {
  1137. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  1138. __asm__ volatile(
  1139. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1140. "mov %4, %%"REG_b" \n\t"
  1141. "push %%"REG_BP" \n\t"
  1142. YSCALEYUV2RGB1b(%%REGBP, %5)
  1143. YSCALEYUV2RGB1_ALPHA(%%REGBP)
  1144. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  1145. "pop %%"REG_BP" \n\t"
  1146. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1147. :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1148. "a" (&c->redDither)
  1149. );
  1150. } else {
  1151. __asm__ volatile(
  1152. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1153. "mov %4, %%"REG_b" \n\t"
  1154. "push %%"REG_BP" \n\t"
  1155. YSCALEYUV2RGB1b(%%REGBP, %5)
  1156. "pcmpeqd %%mm7, %%mm7 \n\t"
  1157. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  1158. "pop %%"REG_BP" \n\t"
  1159. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1160. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1161. "a" (&c->redDither)
  1162. );
  1163. }
  1164. }
  1165. }
  1166. static void RENAME(yuv2bgr24_1)(SwsContext *c, const int16_t *buf0,
  1167. const int16_t *ubuf[2], const int16_t *bguf[2],
  1168. const int16_t *abuf0, uint8_t *dest,
  1169. int dstW, int uvalpha, int y)
  1170. {
  1171. const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  1172. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1173. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1174. __asm__ volatile(
  1175. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1176. "mov %4, %%"REG_b" \n\t"
  1177. "push %%"REG_BP" \n\t"
  1178. YSCALEYUV2RGB1(%%REGBP, %5)
  1179. "pxor %%mm7, %%mm7 \n\t"
  1180. WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
  1181. "pop %%"REG_BP" \n\t"
  1182. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1183. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1184. "a" (&c->redDither)
  1185. );
  1186. } else {
  1187. __asm__ volatile(
  1188. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1189. "mov %4, %%"REG_b" \n\t"
  1190. "push %%"REG_BP" \n\t"
  1191. YSCALEYUV2RGB1b(%%REGBP, %5)
  1192. "pxor %%mm7, %%mm7 \n\t"
  1193. WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
  1194. "pop %%"REG_BP" \n\t"
  1195. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1196. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1197. "a" (&c->redDither)
  1198. );
  1199. }
  1200. }
  1201. static void RENAME(yuv2rgb555_1)(SwsContext *c, const int16_t *buf0,
  1202. const int16_t *ubuf[2], const int16_t *bguf[2],
  1203. const int16_t *abuf0, uint8_t *dest,
  1204. int dstW, int uvalpha, int y)
  1205. {
  1206. const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  1207. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1208. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1209. __asm__ volatile(
  1210. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1211. "mov %4, %%"REG_b" \n\t"
  1212. "push %%"REG_BP" \n\t"
  1213. YSCALEYUV2RGB1(%%REGBP, %5)
  1214. "pxor %%mm7, %%mm7 \n\t"
  1215. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1216. #ifdef DITHER1XBPP
  1217. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1218. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1219. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1220. #endif
  1221. WRITERGB15(%%REGb, 8280(%5), %%REGBP)
  1222. "pop %%"REG_BP" \n\t"
  1223. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1224. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1225. "a" (&c->redDither)
  1226. );
  1227. } else {
  1228. __asm__ volatile(
  1229. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1230. "mov %4, %%"REG_b" \n\t"
  1231. "push %%"REG_BP" \n\t"
  1232. YSCALEYUV2RGB1b(%%REGBP, %5)
  1233. "pxor %%mm7, %%mm7 \n\t"
  1234. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1235. #ifdef DITHER1XBPP
  1236. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1237. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1238. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1239. #endif
  1240. WRITERGB15(%%REGb, 8280(%5), %%REGBP)
  1241. "pop %%"REG_BP" \n\t"
  1242. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1243. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1244. "a" (&c->redDither)
  1245. );
  1246. }
  1247. }
  1248. static void RENAME(yuv2rgb565_1)(SwsContext *c, const int16_t *buf0,
  1249. const int16_t *ubuf[2], const int16_t *bguf[2],
  1250. const int16_t *abuf0, uint8_t *dest,
  1251. int dstW, int uvalpha, int y)
  1252. {
  1253. const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  1254. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1255. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1256. __asm__ volatile(
  1257. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1258. "mov %4, %%"REG_b" \n\t"
  1259. "push %%"REG_BP" \n\t"
  1260. YSCALEYUV2RGB1(%%REGBP, %5)
  1261. "pxor %%mm7, %%mm7 \n\t"
  1262. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1263. #ifdef DITHER1XBPP
  1264. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1265. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1266. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1267. #endif
  1268. WRITERGB16(%%REGb, 8280(%5), %%REGBP)
  1269. "pop %%"REG_BP" \n\t"
  1270. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1271. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1272. "a" (&c->redDither)
  1273. );
  1274. } else {
  1275. __asm__ volatile(
  1276. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1277. "mov %4, %%"REG_b" \n\t"
  1278. "push %%"REG_BP" \n\t"
  1279. YSCALEYUV2RGB1b(%%REGBP, %5)
  1280. "pxor %%mm7, %%mm7 \n\t"
  1281. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1282. #ifdef DITHER1XBPP
  1283. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1284. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1285. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1286. #endif
  1287. WRITERGB16(%%REGb, 8280(%5), %%REGBP)
  1288. "pop %%"REG_BP" \n\t"
  1289. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1290. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1291. "a" (&c->redDither)
  1292. );
  1293. }
  1294. }
  1295. #define REAL_YSCALEYUV2PACKED1(index, c) \
  1296. "xor "#index", "#index" \n\t"\
  1297. ".p2align 4 \n\t"\
  1298. "1: \n\t"\
  1299. "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\
  1300. "add "UV_OFFx2"("#c"), "#index" \n\t" \
  1301. "movq (%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
  1302. "sub "UV_OFFx2"("#c"), "#index" \n\t" \
  1303. "psraw $7, %%mm3 \n\t" \
  1304. "psraw $7, %%mm4 \n\t" \
  1305. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1306. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1307. "psraw $7, %%mm1 \n\t" \
  1308. "psraw $7, %%mm7 \n\t" \
  1309. #define YSCALEYUV2PACKED1(index, c) REAL_YSCALEYUV2PACKED1(index, c)
  1310. #define REAL_YSCALEYUV2PACKED1b(index, c) \
  1311. "xor "#index", "#index" \n\t"\
  1312. ".p2align 4 \n\t"\
  1313. "1: \n\t"\
  1314. "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
  1315. "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
  1316. "add "UV_OFFx2"("#c"), "#index" \n\t" \
  1317. "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  1318. "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  1319. "sub "UV_OFFx2"("#c"), "#index" \n\t" \
  1320. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
  1321. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
  1322. "psrlw $8, %%mm3 \n\t" \
  1323. "psrlw $8, %%mm4 \n\t" \
  1324. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1325. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1326. "psraw $7, %%mm1 \n\t" \
  1327. "psraw $7, %%mm7 \n\t"
  1328. #define YSCALEYUV2PACKED1b(index, c) REAL_YSCALEYUV2PACKED1b(index, c)
  1329. static void RENAME(yuv2yuyv422_1)(SwsContext *c, const int16_t *buf0,
  1330. const int16_t *ubuf[2], const int16_t *bguf[2],
  1331. const int16_t *abuf0, uint8_t *dest,
  1332. int dstW, int uvalpha, int y)
  1333. {
  1334. const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  1335. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1336. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1337. __asm__ volatile(
  1338. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1339. "mov %4, %%"REG_b" \n\t"
  1340. "push %%"REG_BP" \n\t"
  1341. YSCALEYUV2PACKED1(%%REGBP, %5)
  1342. WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
  1343. "pop %%"REG_BP" \n\t"
  1344. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1345. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1346. "a" (&c->redDither)
  1347. );
  1348. } else {
  1349. __asm__ volatile(
  1350. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1351. "mov %4, %%"REG_b" \n\t"
  1352. "push %%"REG_BP" \n\t"
  1353. YSCALEYUV2PACKED1b(%%REGBP, %5)
  1354. WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
  1355. "pop %%"REG_BP" \n\t"
  1356. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1357. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1358. "a" (&c->redDither)
  1359. );
  1360. }
  1361. }
  1362. #if !COMPILE_TEMPLATE_MMX2
  1363. //FIXME yuy2* can read up to 7 samples too much
  1364. static void RENAME(yuy2ToY)(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,
  1365. int width, uint32_t *unused)
  1366. {
  1367. __asm__ volatile(
  1368. "movq "MANGLE(bm01010101)", %%mm2 \n\t"
  1369. "mov %0, %%"REG_a" \n\t"
  1370. "1: \n\t"
  1371. "movq (%1, %%"REG_a",2), %%mm0 \n\t"
  1372. "movq 8(%1, %%"REG_a",2), %%mm1 \n\t"
  1373. "pand %%mm2, %%mm0 \n\t"
  1374. "pand %%mm2, %%mm1 \n\t"
  1375. "packuswb %%mm1, %%mm0 \n\t"
  1376. "movq %%mm0, (%2, %%"REG_a") \n\t"
  1377. "add $8, %%"REG_a" \n\t"
  1378. " js 1b \n\t"
  1379. : : "g" ((x86_reg)-width), "r" (src+width*2), "r" (dst+width)
  1380. : "%"REG_a
  1381. );
  1382. }
  1383. static void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV,
  1384. const uint8_t *unused1, const uint8_t *src1, const uint8_t *src2,
  1385. int width, uint32_t *unused)
  1386. {
  1387. __asm__ volatile(
  1388. "movq "MANGLE(bm01010101)", %%mm4 \n\t"
  1389. "mov %0, %%"REG_a" \n\t"
  1390. "1: \n\t"
  1391. "movq (%1, %%"REG_a",4), %%mm0 \n\t"
  1392. "movq 8(%1, %%"REG_a",4), %%mm1 \n\t"
  1393. "psrlw $8, %%mm0 \n\t"
  1394. "psrlw $8, %%mm1 \n\t"
  1395. "packuswb %%mm1, %%mm0 \n\t"
  1396. "movq %%mm0, %%mm1 \n\t"
  1397. "psrlw $8, %%mm0 \n\t"
  1398. "pand %%mm4, %%mm1 \n\t"
  1399. "packuswb %%mm0, %%mm0 \n\t"
  1400. "packuswb %%mm1, %%mm1 \n\t"
  1401. "movd %%mm0, (%3, %%"REG_a") \n\t"
  1402. "movd %%mm1, (%2, %%"REG_a") \n\t"
  1403. "add $4, %%"REG_a" \n\t"
  1404. " js 1b \n\t"
  1405. : : "g" ((x86_reg)-width), "r" (src1+width*4), "r" (dstU+width), "r" (dstV+width)
  1406. : "%"REG_a
  1407. );
  1408. assert(src1 == src2);
  1409. }
  1410. /* This is almost identical to the previous, end exists only because
  1411. * yuy2ToY/UV)(dst, src+1, ...) would have 100% unaligned accesses. */
  1412. static void RENAME(uyvyToY)(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,
  1413. int width, uint32_t *unused)
  1414. {
  1415. __asm__ volatile(
  1416. "mov %0, %%"REG_a" \n\t"
  1417. "1: \n\t"
  1418. "movq (%1, %%"REG_a",2), %%mm0 \n\t"
  1419. "movq 8(%1, %%"REG_a",2), %%mm1 \n\t"
  1420. "psrlw $8, %%mm0 \n\t"
  1421. "psrlw $8, %%mm1 \n\t"
  1422. "packuswb %%mm1, %%mm0 \n\t"
  1423. "movq %%mm0, (%2, %%"REG_a") \n\t"
  1424. "add $8, %%"REG_a" \n\t"
  1425. " js 1b \n\t"
  1426. : : "g" ((x86_reg)-width), "r" (src+width*2), "r" (dst+width)
  1427. : "%"REG_a
  1428. );
  1429. }
  1430. static void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV,
  1431. const uint8_t *unused1, const uint8_t *src1, const uint8_t *src2,
  1432. int width, uint32_t *unused)
  1433. {
  1434. __asm__ volatile(
  1435. "movq "MANGLE(bm01010101)", %%mm4 \n\t"
  1436. "mov %0, %%"REG_a" \n\t"
  1437. "1: \n\t"
  1438. "movq (%1, %%"REG_a",4), %%mm0 \n\t"
  1439. "movq 8(%1, %%"REG_a",4), %%mm1 \n\t"
  1440. "pand %%mm4, %%mm0 \n\t"
  1441. "pand %%mm4, %%mm1 \n\t"
  1442. "packuswb %%mm1, %%mm0 \n\t"
  1443. "movq %%mm0, %%mm1 \n\t"
  1444. "psrlw $8, %%mm0 \n\t"
  1445. "pand %%mm4, %%mm1 \n\t"
  1446. "packuswb %%mm0, %%mm0 \n\t"
  1447. "packuswb %%mm1, %%mm1 \n\t"
  1448. "movd %%mm0, (%3, %%"REG_a") \n\t"
  1449. "movd %%mm1, (%2, %%"REG_a") \n\t"
  1450. "add $4, %%"REG_a" \n\t"
  1451. " js 1b \n\t"
  1452. : : "g" ((x86_reg)-width), "r" (src1+width*4), "r" (dstU+width), "r" (dstV+width)
  1453. : "%"REG_a
  1454. );
  1455. assert(src1 == src2);
  1456. }
  1457. static av_always_inline void RENAME(nvXXtoUV)(uint8_t *dst1, uint8_t *dst2,
  1458. const uint8_t *src, int width)
  1459. {
  1460. __asm__ volatile(
  1461. "movq "MANGLE(bm01010101)", %%mm4 \n\t"
  1462. "mov %0, %%"REG_a" \n\t"
  1463. "1: \n\t"
  1464. "movq (%1, %%"REG_a",2), %%mm0 \n\t"
  1465. "movq 8(%1, %%"REG_a",2), %%mm1 \n\t"
  1466. "movq %%mm0, %%mm2 \n\t"
  1467. "movq %%mm1, %%mm3 \n\t"
  1468. "pand %%mm4, %%mm0 \n\t"
  1469. "pand %%mm4, %%mm1 \n\t"
  1470. "psrlw $8, %%mm2 \n\t"
  1471. "psrlw $8, %%mm3 \n\t"
  1472. "packuswb %%mm1, %%mm0 \n\t"
  1473. "packuswb %%mm3, %%mm2 \n\t"
  1474. "movq %%mm0, (%2, %%"REG_a") \n\t"
  1475. "movq %%mm2, (%3, %%"REG_a") \n\t"
  1476. "add $8, %%"REG_a" \n\t"
  1477. " js 1b \n\t"
  1478. : : "g" ((x86_reg)-width), "r" (src+width*2), "r" (dst1+width), "r" (dst2+width)
  1479. : "%"REG_a
  1480. );
  1481. }
  1482. static void RENAME(nv12ToUV)(uint8_t *dstU, uint8_t *dstV,
  1483. const uint8_t *unused1, const uint8_t *src1, const uint8_t *src2,
  1484. int width, uint32_t *unused)
  1485. {
  1486. RENAME(nvXXtoUV)(dstU, dstV, src1, width);
  1487. }
  1488. static void RENAME(nv21ToUV)(uint8_t *dstU, uint8_t *dstV,
  1489. const uint8_t *unused1, const uint8_t *src1, const uint8_t *src2,
  1490. int width, uint32_t *unused)
  1491. {
  1492. RENAME(nvXXtoUV)(dstV, dstU, src1, width);
  1493. }
  1494. #endif /* !COMPILE_TEMPLATE_MMX2 */
  1495. static av_always_inline void RENAME(bgr24ToY_mmx)(int16_t *dst, const uint8_t *src,
  1496. int width, enum PixelFormat srcFormat)
  1497. {
  1498. if(srcFormat == PIX_FMT_BGR24) {
  1499. __asm__ volatile(
  1500. "movq "MANGLE(ff_bgr24toY1Coeff)", %%mm5 \n\t"
  1501. "movq "MANGLE(ff_bgr24toY2Coeff)", %%mm6 \n\t"
  1502. :
  1503. );
  1504. } else {
  1505. __asm__ volatile(
  1506. "movq "MANGLE(ff_rgb24toY1Coeff)", %%mm5 \n\t"
  1507. "movq "MANGLE(ff_rgb24toY2Coeff)", %%mm6 \n\t"
  1508. :
  1509. );
  1510. }
  1511. __asm__ volatile(
  1512. "movq "MANGLE(ff_bgr24toYOffset)", %%mm4 \n\t"
  1513. "mov %2, %%"REG_a" \n\t"
  1514. "pxor %%mm7, %%mm7 \n\t"
  1515. "1: \n\t"
  1516. PREFETCH" 64(%0) \n\t"
  1517. "movd (%0), %%mm0 \n\t"
  1518. "movd 2(%0), %%mm1 \n\t"
  1519. "movd 6(%0), %%mm2 \n\t"
  1520. "movd 8(%0), %%mm3 \n\t"
  1521. "add $12, %0 \n\t"
  1522. "punpcklbw %%mm7, %%mm0 \n\t"
  1523. "punpcklbw %%mm7, %%mm1 \n\t"
  1524. "punpcklbw %%mm7, %%mm2 \n\t"
  1525. "punpcklbw %%mm7, %%mm3 \n\t"
  1526. "pmaddwd %%mm5, %%mm0 \n\t"
  1527. "pmaddwd %%mm6, %%mm1 \n\t"
  1528. "pmaddwd %%mm5, %%mm2 \n\t"
  1529. "pmaddwd %%mm6, %%mm3 \n\t"
  1530. "paddd %%mm1, %%mm0 \n\t"
  1531. "paddd %%mm3, %%mm2 \n\t"
  1532. "paddd %%mm4, %%mm0 \n\t"
  1533. "paddd %%mm4, %%mm2 \n\t"
  1534. "psrad $9, %%mm0 \n\t"
  1535. "psrad $9, %%mm2 \n\t"
  1536. "packssdw %%mm2, %%mm0 \n\t"
  1537. "movq %%mm0, (%1, %%"REG_a") \n\t"
  1538. "add $8, %%"REG_a" \n\t"
  1539. " js 1b \n\t"
  1540. : "+r" (src)
  1541. : "r" (dst+width), "g" ((x86_reg)-2*width)
  1542. : "%"REG_a
  1543. );
  1544. }
  1545. static void RENAME(bgr24ToY)(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,
  1546. int width, uint32_t *unused)
  1547. {
  1548. RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_BGR24);
  1549. }
  1550. static void RENAME(rgb24ToY)(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,
  1551. int width, uint32_t *unused)
  1552. {
  1553. RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_RGB24);
  1554. }
  1555. static av_always_inline void RENAME(bgr24ToUV_mmx)(int16_t *dstU, int16_t *dstV,
  1556. const uint8_t *src, int width,
  1557. enum PixelFormat srcFormat)
  1558. {
  1559. __asm__ volatile(
  1560. "movq 24(%4), %%mm6 \n\t"
  1561. "mov %3, %%"REG_a" \n\t"
  1562. "pxor %%mm7, %%mm7 \n\t"
  1563. "1: \n\t"
  1564. PREFETCH" 64(%0) \n\t"
  1565. "movd (%0), %%mm0 \n\t"
  1566. "movd 2(%0), %%mm1 \n\t"
  1567. "punpcklbw %%mm7, %%mm0 \n\t"
  1568. "punpcklbw %%mm7, %%mm1 \n\t"
  1569. "movq %%mm0, %%mm2 \n\t"
  1570. "movq %%mm1, %%mm3 \n\t"
  1571. "pmaddwd (%4), %%mm0 \n\t"
  1572. "pmaddwd 8(%4), %%mm1 \n\t"
  1573. "pmaddwd 16(%4), %%mm2 \n\t"
  1574. "pmaddwd %%mm6, %%mm3 \n\t"
  1575. "paddd %%mm1, %%mm0 \n\t"
  1576. "paddd %%mm3, %%mm2 \n\t"
  1577. "movd 6(%0), %%mm1 \n\t"
  1578. "movd 8(%0), %%mm3 \n\t"
  1579. "add $12, %0 \n\t"
  1580. "punpcklbw %%mm7, %%mm1 \n\t"
  1581. "punpcklbw %%mm7, %%mm3 \n\t"
  1582. "movq %%mm1, %%mm4 \n\t"
  1583. "movq %%mm3, %%mm5 \n\t"
  1584. "pmaddwd (%4), %%mm1 \n\t"
  1585. "pmaddwd 8(%4), %%mm3 \n\t"
  1586. "pmaddwd 16(%4), %%mm4 \n\t"
  1587. "pmaddwd %%mm6, %%mm5 \n\t"
  1588. "paddd %%mm3, %%mm1 \n\t"
  1589. "paddd %%mm5, %%mm4 \n\t"
  1590. "movq "MANGLE(ff_bgr24toUVOffset)", %%mm3 \n\t"
  1591. "paddd %%mm3, %%mm0 \n\t"
  1592. "paddd %%mm3, %%mm2 \n\t"
  1593. "paddd %%mm3, %%mm1 \n\t"
  1594. "paddd %%mm3, %%mm4 \n\t"
  1595. "psrad $9, %%mm0 \n\t"
  1596. "psrad $9, %%mm2 \n\t"
  1597. "psrad $9, %%mm1 \n\t"
  1598. "psrad $9, %%mm4 \n\t"
  1599. "packssdw %%mm1, %%mm0 \n\t"
  1600. "packssdw %%mm4, %%mm2 \n\t"
  1601. "movq %%mm0, (%1, %%"REG_a") \n\t"
  1602. "movq %%mm2, (%2, %%"REG_a") \n\t"
  1603. "add $8, %%"REG_a" \n\t"
  1604. " js 1b \n\t"
  1605. : "+r" (src)
  1606. : "r" (dstU+width), "r" (dstV+width), "g" ((x86_reg)-2*width), "r"(ff_bgr24toUV[srcFormat == PIX_FMT_RGB24])
  1607. : "%"REG_a
  1608. );
  1609. }
  1610. static void RENAME(bgr24ToUV)(int16_t *dstU, int16_t *dstV,
  1611. const uint8_t *unused1, const uint8_t *src1, const uint8_t *src2,
  1612. int width, uint32_t *unused)
  1613. {
  1614. RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_BGR24);
  1615. assert(src1 == src2);
  1616. }
  1617. static void RENAME(rgb24ToUV)(int16_t *dstU, int16_t *dstV,
  1618. const uint8_t *unused1, const uint8_t *src1, const uint8_t *src2,
  1619. int width, uint32_t *unused)
  1620. {
  1621. assert(src1==src2);
  1622. RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_RGB24);
  1623. }
  1624. #if COMPILE_TEMPLATE_MMX2
  1625. static void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst,
  1626. int dstWidth, const uint8_t *src,
  1627. int srcW, int xInc)
  1628. {
  1629. int16_t *filterPos = c->hLumFilterPos;
  1630. int16_t *filter = c->hLumFilter;
  1631. void *mmx2FilterCode= c->lumMmx2FilterCode;
  1632. int i;
  1633. #if defined(PIC)
  1634. DECLARE_ALIGNED(8, uint64_t, ebxsave);
  1635. #endif
  1636. __asm__ volatile(
  1637. #if defined(PIC)
  1638. "mov %%"REG_b", %5 \n\t"
  1639. #endif
  1640. "pxor %%mm7, %%mm7 \n\t"
  1641. "mov %0, %%"REG_c" \n\t"
  1642. "mov %1, %%"REG_D" \n\t"
  1643. "mov %2, %%"REG_d" \n\t"
  1644. "mov %3, %%"REG_b" \n\t"
  1645. "xor %%"REG_a", %%"REG_a" \n\t" // i
  1646. PREFETCH" (%%"REG_c") \n\t"
  1647. PREFETCH" 32(%%"REG_c") \n\t"
  1648. PREFETCH" 64(%%"REG_c") \n\t"
  1649. #if ARCH_X86_64
  1650. #define CALL_MMX2_FILTER_CODE \
  1651. "movl (%%"REG_b"), %%esi \n\t"\
  1652. "call *%4 \n\t"\
  1653. "movl (%%"REG_b", %%"REG_a"), %%esi \n\t"\
  1654. "add %%"REG_S", %%"REG_c" \n\t"\
  1655. "add %%"REG_a", %%"REG_D" \n\t"\
  1656. "xor %%"REG_a", %%"REG_a" \n\t"\
  1657. #else
  1658. #define CALL_MMX2_FILTER_CODE \
  1659. "movl (%%"REG_b"), %%esi \n\t"\
  1660. "call *%4 \n\t"\
  1661. "addl (%%"REG_b", %%"REG_a"), %%"REG_c" \n\t"\
  1662. "add %%"REG_a", %%"REG_D" \n\t"\
  1663. "xor %%"REG_a", %%"REG_a" \n\t"\
  1664. #endif /* ARCH_X86_64 */
  1665. CALL_MMX2_FILTER_CODE
  1666. CALL_MMX2_FILTER_CODE
  1667. CALL_MMX2_FILTER_CODE
  1668. CALL_MMX2_FILTER_CODE
  1669. CALL_MMX2_FILTER_CODE
  1670. CALL_MMX2_FILTER_CODE
  1671. CALL_MMX2_FILTER_CODE
  1672. CALL_MMX2_FILTER_CODE
  1673. #if defined(PIC)
  1674. "mov %5, %%"REG_b" \n\t"
  1675. #endif
  1676. :: "m" (src), "m" (dst), "m" (filter), "m" (filterPos),
  1677. "m" (mmx2FilterCode)
  1678. #if defined(PIC)
  1679. ,"m" (ebxsave)
  1680. #endif
  1681. : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
  1682. #if !defined(PIC)
  1683. ,"%"REG_b
  1684. #endif
  1685. );
  1686. for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--)
  1687. dst[i] = src[srcW-1]*128;
  1688. }
  1689. static void RENAME(hcscale_fast)(SwsContext *c, int16_t *dst1, int16_t *dst2,
  1690. int dstWidth, const uint8_t *src1,
  1691. const uint8_t *src2, int srcW, int xInc)
  1692. {
  1693. int16_t *filterPos = c->hChrFilterPos;
  1694. int16_t *filter = c->hChrFilter;
  1695. void *mmx2FilterCode= c->chrMmx2FilterCode;
  1696. int i;
  1697. #if defined(PIC)
  1698. DECLARE_ALIGNED(8, uint64_t, ebxsave);
  1699. #endif
  1700. __asm__ volatile(
  1701. #if defined(PIC)
  1702. "mov %%"REG_b", %7 \n\t"
  1703. #endif
  1704. "pxor %%mm7, %%mm7 \n\t"
  1705. "mov %0, %%"REG_c" \n\t"
  1706. "mov %1, %%"REG_D" \n\t"
  1707. "mov %2, %%"REG_d" \n\t"
  1708. "mov %3, %%"REG_b" \n\t"
  1709. "xor %%"REG_a", %%"REG_a" \n\t" // i
  1710. PREFETCH" (%%"REG_c") \n\t"
  1711. PREFETCH" 32(%%"REG_c") \n\t"
  1712. PREFETCH" 64(%%"REG_c") \n\t"
  1713. CALL_MMX2_FILTER_CODE
  1714. CALL_MMX2_FILTER_CODE
  1715. CALL_MMX2_FILTER_CODE
  1716. CALL_MMX2_FILTER_CODE
  1717. "xor %%"REG_a", %%"REG_a" \n\t" // i
  1718. "mov %5, %%"REG_c" \n\t" // src
  1719. "mov %6, %%"REG_D" \n\t" // buf2
  1720. PREFETCH" (%%"REG_c") \n\t"
  1721. PREFETCH" 32(%%"REG_c") \n\t"
  1722. PREFETCH" 64(%%"REG_c") \n\t"
  1723. CALL_MMX2_FILTER_CODE
  1724. CALL_MMX2_FILTER_CODE
  1725. CALL_MMX2_FILTER_CODE
  1726. CALL_MMX2_FILTER_CODE
  1727. #if defined(PIC)
  1728. "mov %7, %%"REG_b" \n\t"
  1729. #endif
  1730. :: "m" (src1), "m" (dst1), "m" (filter), "m" (filterPos),
  1731. "m" (mmx2FilterCode), "m" (src2), "m"(dst2)
  1732. #if defined(PIC)
  1733. ,"m" (ebxsave)
  1734. #endif
  1735. : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
  1736. #if !defined(PIC)
  1737. ,"%"REG_b
  1738. #endif
  1739. );
  1740. for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) {
  1741. dst1[i] = src1[srcW-1]*128;
  1742. dst2[i] = src2[srcW-1]*128;
  1743. }
  1744. }
  1745. #endif /* COMPILE_TEMPLATE_MMX2 */
  1746. static av_cold void RENAME(sws_init_swScale)(SwsContext *c)
  1747. {
  1748. enum PixelFormat srcFormat = c->srcFormat,
  1749. dstFormat = c->dstFormat;
  1750. c->use_mmx_vfilter= 0;
  1751. if (!is16BPS(dstFormat) && !is9_OR_10BPS(dstFormat) && dstFormat != PIX_FMT_NV12
  1752. && dstFormat != PIX_FMT_NV21 && !(c->flags & SWS_BITEXACT)) {
  1753. if (c->flags & SWS_ACCURATE_RND) {
  1754. if (!(c->flags & SWS_FULL_CHR_H_INT)) {
  1755. switch (c->dstFormat) {
  1756. case PIX_FMT_RGB32: c->yuv2packedX = RENAME(yuv2rgb32_X_ar); break;
  1757. case PIX_FMT_BGR24: c->yuv2packedX = RENAME(yuv2bgr24_X_ar); break;
  1758. case PIX_FMT_RGB555: c->yuv2packedX = RENAME(yuv2rgb555_X_ar); break;
  1759. case PIX_FMT_RGB565: c->yuv2packedX = RENAME(yuv2rgb565_X_ar); break;
  1760. case PIX_FMT_YUYV422: c->yuv2packedX = RENAME(yuv2yuyv422_X_ar); break;
  1761. default: break;
  1762. }
  1763. }
  1764. } else {
  1765. int should_dither= isNBPS(c->srcFormat) || is16BPS(c->srcFormat);
  1766. c->use_mmx_vfilter= 1;
  1767. c->yuv2planeX = RENAME(yuv2yuvX );
  1768. if (!(c->flags & SWS_FULL_CHR_H_INT)) {
  1769. switch (c->dstFormat) {
  1770. case PIX_FMT_RGB32: c->yuv2packedX = RENAME(yuv2rgb32_X); break;
  1771. case PIX_FMT_BGR24: c->yuv2packedX = RENAME(yuv2bgr24_X); break;
  1772. case PIX_FMT_RGB555: c->yuv2packedX = RENAME(yuv2rgb555_X); break;
  1773. case PIX_FMT_RGB565: c->yuv2packedX = RENAME(yuv2rgb565_X); break;
  1774. case PIX_FMT_YUYV422: c->yuv2packedX = RENAME(yuv2yuyv422_X); break;
  1775. default: break;
  1776. }
  1777. }
  1778. }
  1779. if (!(c->flags & SWS_FULL_CHR_H_INT)) {
  1780. switch (c->dstFormat) {
  1781. case PIX_FMT_RGB32:
  1782. c->yuv2packed1 = RENAME(yuv2rgb32_1);
  1783. c->yuv2packed2 = RENAME(yuv2rgb32_2);
  1784. break;
  1785. case PIX_FMT_BGR24:
  1786. c->yuv2packed1 = RENAME(yuv2bgr24_1);
  1787. c->yuv2packed2 = RENAME(yuv2bgr24_2);
  1788. break;
  1789. case PIX_FMT_RGB555:
  1790. c->yuv2packed1 = RENAME(yuv2rgb555_1);
  1791. c->yuv2packed2 = RENAME(yuv2rgb555_2);
  1792. break;
  1793. case PIX_FMT_RGB565:
  1794. c->yuv2packed1 = RENAME(yuv2rgb565_1);
  1795. c->yuv2packed2 = RENAME(yuv2rgb565_2);
  1796. break;
  1797. case PIX_FMT_YUYV422:
  1798. c->yuv2packed1 = RENAME(yuv2yuyv422_1);
  1799. c->yuv2packed2 = RENAME(yuv2yuyv422_2);
  1800. break;
  1801. default:
  1802. break;
  1803. }
  1804. }
  1805. }
  1806. if (c->srcBpc == 8 && c->dstBpc <= 10) {
  1807. // Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one).
  1808. #if COMPILE_TEMPLATE_MMX2
  1809. if (c->flags & SWS_FAST_BILINEAR && c->canMMX2BeUsed)
  1810. {
  1811. c->hyscale_fast = RENAME(hyscale_fast);
  1812. c->hcscale_fast = RENAME(hcscale_fast);
  1813. } else {
  1814. #endif /* COMPILE_TEMPLATE_MMX2 */
  1815. c->hyscale_fast = NULL;
  1816. c->hcscale_fast = NULL;
  1817. #if COMPILE_TEMPLATE_MMX2
  1818. }
  1819. #endif /* COMPILE_TEMPLATE_MMX2 */
  1820. }
  1821. #if !COMPILE_TEMPLATE_MMX2
  1822. switch(srcFormat) {
  1823. case PIX_FMT_YUYV422 : c->chrToYV12 = RENAME(yuy2ToUV); break;
  1824. case PIX_FMT_UYVY422 : c->chrToYV12 = RENAME(uyvyToUV); break;
  1825. case PIX_FMT_NV12 : c->chrToYV12 = RENAME(nv12ToUV); break;
  1826. case PIX_FMT_NV21 : c->chrToYV12 = RENAME(nv21ToUV); break;
  1827. default: break;
  1828. }
  1829. #endif /* !COMPILE_TEMPLATE_MMX2 */
  1830. if (!c->chrSrcHSubSample) {
  1831. switch(srcFormat) {
  1832. case PIX_FMT_BGR24 : c->chrToYV12 = RENAME(bgr24ToUV); break;
  1833. case PIX_FMT_RGB24 : c->chrToYV12 = RENAME(rgb24ToUV); break;
  1834. default: break;
  1835. }
  1836. }
  1837. switch (srcFormat) {
  1838. #if !COMPILE_TEMPLATE_MMX2
  1839. case PIX_FMT_YUYV422 :
  1840. case PIX_FMT_Y400A : c->lumToYV12 = RENAME(yuy2ToY); break;
  1841. case PIX_FMT_UYVY422 : c->lumToYV12 = RENAME(uyvyToY); break;
  1842. #endif /* !COMPILE_TEMPLATE_MMX2 */
  1843. case PIX_FMT_BGR24 : c->lumToYV12 = RENAME(bgr24ToY); break;
  1844. case PIX_FMT_RGB24 : c->lumToYV12 = RENAME(rgb24ToY); break;
  1845. default: break;
  1846. }
  1847. #if !COMPILE_TEMPLATE_MMX2
  1848. if (c->alpPixBuf) {
  1849. switch (srcFormat) {
  1850. case PIX_FMT_Y400A : c->alpToYV12 = RENAME(yuy2ToY); break;
  1851. default: break;
  1852. }
  1853. }
  1854. #endif /* !COMPILE_TEMPLATE_MMX2 */
  1855. }