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.

1737 lines
76KB

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