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.

1735 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. static void RENAME(yuv2bgr24_X_ar)(SwsContext *c, const int16_t *lumFilter,
  635. const int16_t **lumSrc, int lumFilterSize,
  636. const int16_t *chrFilter, const int16_t **chrUSrc,
  637. const int16_t **chrVSrc,
  638. int chrFilterSize, const int16_t **alpSrc,
  639. uint8_t *dest, int dstW, int dstY)
  640. {
  641. x86_reg dummy=0;
  642. x86_reg dstW_reg = dstW;
  643. x86_reg uv_off = c->uv_offx2;
  644. YSCALEYUV2PACKEDX_ACCURATE
  645. YSCALEYUV2RGBX
  646. "pxor %%mm7, %%mm7 \n\t"
  647. "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"\n\t" //FIXME optimize
  648. "add %4, %%"REG_c" \n\t"
  649. WRITEBGR24(%%REGc, %5, %%REGa)
  650. :: "r" (&c->redDither),
  651. "m" (dummy), "m" (dummy), "m" (dummy),
  652. "r" (dest), "m" (dstW_reg), "m"(uv_off)
  653. NAMED_CONSTRAINTS_ADD(ff_M24A,ff_M24C,ff_M24B)
  654. : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S
  655. );
  656. }
  657. static void RENAME(yuv2bgr24_X)(SwsContext *c, const int16_t *lumFilter,
  658. const int16_t **lumSrc, int lumFilterSize,
  659. const int16_t *chrFilter, const int16_t **chrUSrc,
  660. const int16_t **chrVSrc,
  661. int chrFilterSize, const int16_t **alpSrc,
  662. uint8_t *dest, int dstW, int dstY)
  663. {
  664. x86_reg dummy=0;
  665. x86_reg dstW_reg = dstW;
  666. x86_reg uv_off = c->uv_offx2;
  667. YSCALEYUV2PACKEDX
  668. YSCALEYUV2RGBX
  669. "pxor %%mm7, %%mm7 \n\t"
  670. "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c" \n\t" //FIXME optimize
  671. "add %4, %%"REG_c" \n\t"
  672. WRITEBGR24(%%REGc, %5, %%REGa)
  673. :: "r" (&c->redDither),
  674. "m" (dummy), "m" (dummy), "m" (dummy),
  675. "r" (dest), "m" (dstW_reg), "m"(uv_off)
  676. NAMED_CONSTRAINTS_ADD(ff_M24A,ff_M24C,ff_M24B)
  677. : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S
  678. );
  679. }
  680. #define REAL_WRITEYUY2(dst, dstw, index) \
  681. "packuswb %%mm3, %%mm3 \n\t"\
  682. "packuswb %%mm4, %%mm4 \n\t"\
  683. "packuswb %%mm7, %%mm1 \n\t"\
  684. "punpcklbw %%mm4, %%mm3 \n\t"\
  685. "movq %%mm1, %%mm7 \n\t"\
  686. "punpcklbw %%mm3, %%mm1 \n\t"\
  687. "punpckhbw %%mm3, %%mm7 \n\t"\
  688. \
  689. MOVNTQ(%%mm1, (dst, index, 2))\
  690. MOVNTQ(%%mm7, 8(dst, index, 2))\
  691. \
  692. "add $8, "#index" \n\t"\
  693. "cmp "#dstw", "#index" \n\t"\
  694. " jb 1b \n\t"
  695. #define WRITEYUY2(dst, dstw, index) REAL_WRITEYUY2(dst, dstw, index)
  696. static void RENAME(yuv2yuyv422_X_ar)(SwsContext *c, const int16_t *lumFilter,
  697. const int16_t **lumSrc, int lumFilterSize,
  698. const int16_t *chrFilter, const int16_t **chrUSrc,
  699. const int16_t **chrVSrc,
  700. int chrFilterSize, const int16_t **alpSrc,
  701. uint8_t *dest, int dstW, int dstY)
  702. {
  703. x86_reg dummy=0;
  704. x86_reg dstW_reg = dstW;
  705. x86_reg uv_off = c->uv_offx2;
  706. YSCALEYUV2PACKEDX_ACCURATE
  707. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  708. "psraw $3, %%mm3 \n\t"
  709. "psraw $3, %%mm4 \n\t"
  710. "psraw $3, %%mm1 \n\t"
  711. "psraw $3, %%mm7 \n\t"
  712. WRITEYUY2(%4, %5, %%REGa)
  713. YSCALEYUV2PACKEDX_END
  714. }
  715. static void RENAME(yuv2yuyv422_X)(SwsContext *c, const int16_t *lumFilter,
  716. const int16_t **lumSrc, int lumFilterSize,
  717. const int16_t *chrFilter, const int16_t **chrUSrc,
  718. const int16_t **chrVSrc,
  719. int chrFilterSize, const int16_t **alpSrc,
  720. uint8_t *dest, int dstW, int dstY)
  721. {
  722. x86_reg dummy=0;
  723. x86_reg dstW_reg = dstW;
  724. x86_reg uv_off = c->uv_offx2;
  725. YSCALEYUV2PACKEDX
  726. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  727. "psraw $3, %%mm3 \n\t"
  728. "psraw $3, %%mm4 \n\t"
  729. "psraw $3, %%mm1 \n\t"
  730. "psraw $3, %%mm7 \n\t"
  731. WRITEYUY2(%4, %5, %%REGa)
  732. YSCALEYUV2PACKEDX_END
  733. }
  734. #define REAL_YSCALEYUV2RGB_UV(index, c) \
  735. "xor "#index", "#index" \n\t"\
  736. ".p2align 4 \n\t"\
  737. "1: \n\t"\
  738. "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
  739. "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
  740. "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  741. "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  742. "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  743. "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  744. "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
  745. "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
  746. "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\
  747. "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
  748. "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
  749. "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  750. "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  751. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
  752. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
  753. "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\
  754. "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\
  755. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  756. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  757. "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\
  758. "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\
  759. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  760. #define REAL_YSCALEYUV2RGB_YA(index, c, b1, b2) \
  761. "movq ("#b1", "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\
  762. "movq ("#b2", "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\
  763. "movq 8("#b1", "#index", 2), %%mm6 \n\t" /*buf0[eax]*/\
  764. "movq 8("#b2", "#index", 2), %%mm7 \n\t" /*buf1[eax]*/\
  765. "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
  766. "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\
  767. "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  768. "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  769. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  770. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  771. "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  772. "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  773. #define REAL_YSCALEYUV2RGB_COEFF(c) \
  774. "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\
  775. "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\
  776. "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\
  777. "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\
  778. "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\
  779. "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\
  780. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  781. "paddw %%mm3, %%mm4 \n\t"\
  782. "movq %%mm2, %%mm0 \n\t"\
  783. "movq %%mm5, %%mm6 \n\t"\
  784. "movq %%mm4, %%mm3 \n\t"\
  785. "punpcklwd %%mm2, %%mm2 \n\t"\
  786. "punpcklwd %%mm5, %%mm5 \n\t"\
  787. "punpcklwd %%mm4, %%mm4 \n\t"\
  788. "paddw %%mm1, %%mm2 \n\t"\
  789. "paddw %%mm1, %%mm5 \n\t"\
  790. "paddw %%mm1, %%mm4 \n\t"\
  791. "punpckhwd %%mm0, %%mm0 \n\t"\
  792. "punpckhwd %%mm6, %%mm6 \n\t"\
  793. "punpckhwd %%mm3, %%mm3 \n\t"\
  794. "paddw %%mm7, %%mm0 \n\t"\
  795. "paddw %%mm7, %%mm6 \n\t"\
  796. "paddw %%mm7, %%mm3 \n\t"\
  797. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  798. "packuswb %%mm0, %%mm2 \n\t"\
  799. "packuswb %%mm6, %%mm5 \n\t"\
  800. "packuswb %%mm3, %%mm4 \n\t"\
  801. #define YSCALEYUV2RGB_YA(index, c, b1, b2) REAL_YSCALEYUV2RGB_YA(index, c, b1, b2)
  802. #define YSCALEYUV2RGB(index, c) \
  803. REAL_YSCALEYUV2RGB_UV(index, c) \
  804. REAL_YSCALEYUV2RGB_YA(index, c, %0, %1) \
  805. REAL_YSCALEYUV2RGB_COEFF(c)
  806. /**
  807. * vertical bilinear scale YV12 to RGB
  808. */
  809. static void RENAME(yuv2rgb32_2)(SwsContext *c, const int16_t *buf[2],
  810. const int16_t *ubuf[2], const int16_t *vbuf[2],
  811. const int16_t *abuf[2], uint8_t *dest,
  812. int dstW, int yalpha, int uvalpha, int y)
  813. {
  814. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  815. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  816. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  817. const int16_t *abuf0 = abuf[0], *abuf1 = abuf[1];
  818. #if ARCH_X86_64
  819. __asm__ volatile(
  820. YSCALEYUV2RGB(%%r8, %5)
  821. YSCALEYUV2RGB_YA(%%r8, %5, %6, %7)
  822. "psraw $3, %%mm1 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
  823. "psraw $3, %%mm7 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
  824. "packuswb %%mm7, %%mm1 \n\t"
  825. WRITEBGR32(%4, 8280(%5), %%r8, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6)
  826. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "r" (dest),
  827. "a" (&c->redDither),
  828. "r" (abuf0), "r" (abuf1)
  829. : "%r8"
  830. );
  831. #else
  832. c->u_temp=(intptr_t)abuf0;
  833. c->v_temp=(intptr_t)abuf1;
  834. __asm__ volatile(
  835. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  836. "mov %4, %%"REG_b" \n\t"
  837. "push %%"REG_BP" \n\t"
  838. YSCALEYUV2RGB(%%REGBP, %5)
  839. "push %0 \n\t"
  840. "push %1 \n\t"
  841. "mov "U_TEMP"(%5), %0 \n\t"
  842. "mov "V_TEMP"(%5), %1 \n\t"
  843. YSCALEYUV2RGB_YA(%%REGBP, %5, %0, %1)
  844. "psraw $3, %%mm1 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
  845. "psraw $3, %%mm7 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
  846. "packuswb %%mm7, %%mm1 \n\t"
  847. "pop %1 \n\t"
  848. "pop %0 \n\t"
  849. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6)
  850. "pop %%"REG_BP" \n\t"
  851. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  852. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  853. "a" (&c->redDither)
  854. );
  855. #endif
  856. } else {
  857. __asm__ volatile(
  858. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  859. "mov %4, %%"REG_b" \n\t"
  860. "push %%"REG_BP" \n\t"
  861. YSCALEYUV2RGB(%%REGBP, %5)
  862. "pcmpeqd %%mm7, %%mm7 \n\t"
  863. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  864. "pop %%"REG_BP" \n\t"
  865. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  866. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  867. "a" (&c->redDither)
  868. );
  869. }
  870. }
  871. static void RENAME(yuv2bgr24_2)(SwsContext *c, const int16_t *buf[2],
  872. const int16_t *ubuf[2], const int16_t *vbuf[2],
  873. const int16_t *abuf[2], uint8_t *dest,
  874. int dstW, int yalpha, int uvalpha, int y)
  875. {
  876. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  877. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  878. //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
  879. __asm__ volatile(
  880. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  881. "mov %4, %%"REG_b" \n\t"
  882. "push %%"REG_BP" \n\t"
  883. YSCALEYUV2RGB(%%REGBP, %5)
  884. "pxor %%mm7, %%mm7 \n\t"
  885. WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
  886. "pop %%"REG_BP" \n\t"
  887. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  888. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  889. "a" (&c->redDither)
  890. NAMED_CONSTRAINTS_ADD(ff_M24A,ff_M24C,ff_M24B)
  891. );
  892. }
  893. static void RENAME(yuv2rgb555_2)(SwsContext *c, const int16_t *buf[2],
  894. const int16_t *ubuf[2], const int16_t *vbuf[2],
  895. const int16_t *abuf[2], uint8_t *dest,
  896. int dstW, int yalpha, int uvalpha, int y)
  897. {
  898. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  899. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  900. //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
  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, 8280(%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. //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
  929. __asm__ volatile(
  930. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  931. "mov %4, %%"REG_b" \n\t"
  932. "push %%"REG_BP" \n\t"
  933. YSCALEYUV2RGB(%%REGBP, %5)
  934. "pxor %%mm7, %%mm7 \n\t"
  935. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  936. #ifdef DITHER1XBPP
  937. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  938. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  939. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  940. #endif
  941. WRITERGB16(%%REGb, 8280(%5), %%REGBP)
  942. "pop %%"REG_BP" \n\t"
  943. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  944. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  945. "a" (&c->redDither)
  946. NAMED_CONSTRAINTS_ADD(bF8,bFC)
  947. );
  948. }
  949. #define REAL_YSCALEYUV2PACKED(index, c) \
  950. "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\
  951. "movq "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm1 \n\t"\
  952. "psraw $3, %%mm0 \n\t"\
  953. "psraw $3, %%mm1 \n\t"\
  954. "movq %%mm0, "CHR_MMX_FILTER_OFFSET"+8("#c") \n\t"\
  955. "movq %%mm1, "LUM_MMX_FILTER_OFFSET"+8("#c") \n\t"\
  956. "xor "#index", "#index" \n\t"\
  957. ".p2align 4 \n\t"\
  958. "1: \n\t"\
  959. "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
  960. "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
  961. "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  962. "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  963. "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  964. "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  965. "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
  966. "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
  967. "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\
  968. "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
  969. "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
  970. "psraw $7, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  971. "psraw $7, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  972. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
  973. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
  974. "movq (%0, "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\
  975. "movq (%1, "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\
  976. "movq 8(%0, "#index", 2), %%mm6 \n\t" /*buf0[eax]*/\
  977. "movq 8(%1, "#index", 2), %%mm7 \n\t" /*buf1[eax]*/\
  978. "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
  979. "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\
  980. "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  981. "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  982. "psraw $7, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  983. "psraw $7, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  984. "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  985. "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  986. #define YSCALEYUV2PACKED(index, c) REAL_YSCALEYUV2PACKED(index, c)
  987. static void RENAME(yuv2yuyv422_2)(SwsContext *c, const int16_t *buf[2],
  988. const int16_t *ubuf[2], const int16_t *vbuf[2],
  989. const int16_t *abuf[2], uint8_t *dest,
  990. int dstW, int yalpha, int uvalpha, int y)
  991. {
  992. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  993. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  994. //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
  995. __asm__ volatile(
  996. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  997. "mov %4, %%"REG_b" \n\t"
  998. "push %%"REG_BP" \n\t"
  999. YSCALEYUV2PACKED(%%REGBP, %5)
  1000. WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
  1001. "pop %%"REG_BP" \n\t"
  1002. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1003. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1004. "a" (&c->redDither)
  1005. );
  1006. }
  1007. #define REAL_YSCALEYUV2RGB1(index, c) \
  1008. "xor "#index", "#index" \n\t"\
  1009. ".p2align 4 \n\t"\
  1010. "1: \n\t"\
  1011. "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\
  1012. "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  1013. "movq (%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
  1014. "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  1015. "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  1016. "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  1017. "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\
  1018. "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\
  1019. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  1020. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  1021. "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\
  1022. "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\
  1023. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  1024. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1025. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1026. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1027. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1028. "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\
  1029. "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\
  1030. "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\
  1031. "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\
  1032. "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\
  1033. "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\
  1034. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  1035. "paddw %%mm3, %%mm4 \n\t"\
  1036. "movq %%mm2, %%mm0 \n\t"\
  1037. "movq %%mm5, %%mm6 \n\t"\
  1038. "movq %%mm4, %%mm3 \n\t"\
  1039. "punpcklwd %%mm2, %%mm2 \n\t"\
  1040. "punpcklwd %%mm5, %%mm5 \n\t"\
  1041. "punpcklwd %%mm4, %%mm4 \n\t"\
  1042. "paddw %%mm1, %%mm2 \n\t"\
  1043. "paddw %%mm1, %%mm5 \n\t"\
  1044. "paddw %%mm1, %%mm4 \n\t"\
  1045. "punpckhwd %%mm0, %%mm0 \n\t"\
  1046. "punpckhwd %%mm6, %%mm6 \n\t"\
  1047. "punpckhwd %%mm3, %%mm3 \n\t"\
  1048. "paddw %%mm7, %%mm0 \n\t"\
  1049. "paddw %%mm7, %%mm6 \n\t"\
  1050. "paddw %%mm7, %%mm3 \n\t"\
  1051. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  1052. "packuswb %%mm0, %%mm2 \n\t"\
  1053. "packuswb %%mm6, %%mm5 \n\t"\
  1054. "packuswb %%mm3, %%mm4 \n\t"\
  1055. #define YSCALEYUV2RGB1(index, c) REAL_YSCALEYUV2RGB1(index, c)
  1056. // do vertical chrominance interpolation
  1057. #define REAL_YSCALEYUV2RGB1b(index, c) \
  1058. "xor "#index", "#index" \n\t"\
  1059. ".p2align 4 \n\t"\
  1060. "1: \n\t"\
  1061. "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
  1062. "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
  1063. "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  1064. "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  1065. "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  1066. "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  1067. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
  1068. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
  1069. "psrlw $5, %%mm3 \n\t" /*FIXME might overflow*/\
  1070. "psrlw $5, %%mm4 \n\t" /*FIXME might overflow*/\
  1071. "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\
  1072. "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\
  1073. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  1074. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  1075. "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\
  1076. "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\
  1077. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  1078. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1079. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1080. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1081. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1082. "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\
  1083. "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\
  1084. "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\
  1085. "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\
  1086. "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\
  1087. "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\
  1088. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  1089. "paddw %%mm3, %%mm4 \n\t"\
  1090. "movq %%mm2, %%mm0 \n\t"\
  1091. "movq %%mm5, %%mm6 \n\t"\
  1092. "movq %%mm4, %%mm3 \n\t"\
  1093. "punpcklwd %%mm2, %%mm2 \n\t"\
  1094. "punpcklwd %%mm5, %%mm5 \n\t"\
  1095. "punpcklwd %%mm4, %%mm4 \n\t"\
  1096. "paddw %%mm1, %%mm2 \n\t"\
  1097. "paddw %%mm1, %%mm5 \n\t"\
  1098. "paddw %%mm1, %%mm4 \n\t"\
  1099. "punpckhwd %%mm0, %%mm0 \n\t"\
  1100. "punpckhwd %%mm6, %%mm6 \n\t"\
  1101. "punpckhwd %%mm3, %%mm3 \n\t"\
  1102. "paddw %%mm7, %%mm0 \n\t"\
  1103. "paddw %%mm7, %%mm6 \n\t"\
  1104. "paddw %%mm7, %%mm3 \n\t"\
  1105. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  1106. "packuswb %%mm0, %%mm2 \n\t"\
  1107. "packuswb %%mm6, %%mm5 \n\t"\
  1108. "packuswb %%mm3, %%mm4 \n\t"\
  1109. #define YSCALEYUV2RGB1b(index, c) REAL_YSCALEYUV2RGB1b(index, c)
  1110. #define REAL_YSCALEYUV2RGB1_ALPHA(index) \
  1111. "movq (%1, "#index", 2), %%mm7 \n\t" /* abuf0[index ] */\
  1112. "movq 8(%1, "#index", 2), %%mm1 \n\t" /* abuf0[index+4] */\
  1113. "psraw $7, %%mm7 \n\t" /* abuf0[index ] >>7 */\
  1114. "psraw $7, %%mm1 \n\t" /* abuf0[index+4] >>7 */\
  1115. "packuswb %%mm1, %%mm7 \n\t"
  1116. #define YSCALEYUV2RGB1_ALPHA(index) REAL_YSCALEYUV2RGB1_ALPHA(index)
  1117. /**
  1118. * YV12 to RGB without scaling or interpolating
  1119. */
  1120. static void RENAME(yuv2rgb32_1)(SwsContext *c, const int16_t *buf0,
  1121. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1122. const int16_t *abuf0, uint8_t *dest,
  1123. int dstW, int uvalpha, int y)
  1124. {
  1125. const int16_t *ubuf0 = ubuf[0];
  1126. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1127. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1128. const int16_t *ubuf1 = ubuf[0];
  1129. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  1130. __asm__ volatile(
  1131. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1132. "mov %4, %%"REG_b" \n\t"
  1133. "push %%"REG_BP" \n\t"
  1134. YSCALEYUV2RGB1(%%REGBP, %5)
  1135. YSCALEYUV2RGB1_ALPHA(%%REGBP)
  1136. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  1137. "pop %%"REG_BP" \n\t"
  1138. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1139. :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1140. "a" (&c->redDither)
  1141. );
  1142. } else {
  1143. __asm__ volatile(
  1144. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1145. "mov %4, %%"REG_b" \n\t"
  1146. "push %%"REG_BP" \n\t"
  1147. YSCALEYUV2RGB1(%%REGBP, %5)
  1148. "pcmpeqd %%mm7, %%mm7 \n\t"
  1149. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  1150. "pop %%"REG_BP" \n\t"
  1151. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1152. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1153. "a" (&c->redDither)
  1154. );
  1155. }
  1156. } else {
  1157. const int16_t *ubuf1 = ubuf[1];
  1158. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  1159. __asm__ volatile(
  1160. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1161. "mov %4, %%"REG_b" \n\t"
  1162. "push %%"REG_BP" \n\t"
  1163. YSCALEYUV2RGB1b(%%REGBP, %5)
  1164. YSCALEYUV2RGB1_ALPHA(%%REGBP)
  1165. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  1166. "pop %%"REG_BP" \n\t"
  1167. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1168. :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1169. "a" (&c->redDither)
  1170. );
  1171. } else {
  1172. __asm__ volatile(
  1173. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1174. "mov %4, %%"REG_b" \n\t"
  1175. "push %%"REG_BP" \n\t"
  1176. YSCALEYUV2RGB1b(%%REGBP, %5)
  1177. "pcmpeqd %%mm7, %%mm7 \n\t"
  1178. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  1179. "pop %%"REG_BP" \n\t"
  1180. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1181. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1182. "a" (&c->redDither)
  1183. );
  1184. }
  1185. }
  1186. }
  1187. static void RENAME(yuv2bgr24_1)(SwsContext *c, const int16_t *buf0,
  1188. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1189. const int16_t *abuf0, uint8_t *dest,
  1190. int dstW, int uvalpha, int y)
  1191. {
  1192. const int16_t *ubuf0 = ubuf[0];
  1193. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1194. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1195. const int16_t *ubuf1 = ubuf[0];
  1196. __asm__ volatile(
  1197. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1198. "mov %4, %%"REG_b" \n\t"
  1199. "push %%"REG_BP" \n\t"
  1200. YSCALEYUV2RGB1(%%REGBP, %5)
  1201. "pxor %%mm7, %%mm7 \n\t"
  1202. WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
  1203. "pop %%"REG_BP" \n\t"
  1204. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1205. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1206. "a" (&c->redDither)
  1207. NAMED_CONSTRAINTS_ADD(ff_M24A,ff_M24C,ff_M24B)
  1208. );
  1209. } else {
  1210. const int16_t *ubuf1 = ubuf[1];
  1211. __asm__ volatile(
  1212. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1213. "mov %4, %%"REG_b" \n\t"
  1214. "push %%"REG_BP" \n\t"
  1215. YSCALEYUV2RGB1b(%%REGBP, %5)
  1216. "pxor %%mm7, %%mm7 \n\t"
  1217. WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
  1218. "pop %%"REG_BP" \n\t"
  1219. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1220. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1221. "a" (&c->redDither)
  1222. NAMED_CONSTRAINTS_ADD(ff_M24A,ff_M24C,ff_M24B)
  1223. );
  1224. }
  1225. }
  1226. static void RENAME(yuv2rgb555_1)(SwsContext *c, const int16_t *buf0,
  1227. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1228. const int16_t *abuf0, uint8_t *dest,
  1229. int dstW, int uvalpha, int y)
  1230. {
  1231. const int16_t *ubuf0 = ubuf[0];
  1232. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1233. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1234. const int16_t *ubuf1 = ubuf[0];
  1235. __asm__ volatile(
  1236. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1237. "mov %4, %%"REG_b" \n\t"
  1238. "push %%"REG_BP" \n\t"
  1239. YSCALEYUV2RGB1(%%REGBP, %5)
  1240. "pxor %%mm7, %%mm7 \n\t"
  1241. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1242. #ifdef DITHER1XBPP
  1243. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1244. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1245. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1246. #endif
  1247. WRITERGB15(%%REGb, 8280(%5), %%REGBP)
  1248. "pop %%"REG_BP" \n\t"
  1249. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1250. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1251. "a" (&c->redDither)
  1252. NAMED_CONSTRAINTS_ADD(bF8)
  1253. );
  1254. } else {
  1255. const int16_t *ubuf1 = ubuf[1];
  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. YSCALEYUV2RGB1b(%%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. WRITERGB15(%%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. NAMED_CONSTRAINTS_ADD(bF8)
  1274. );
  1275. }
  1276. }
  1277. static void RENAME(yuv2rgb565_1)(SwsContext *c, const int16_t *buf0,
  1278. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1279. const int16_t *abuf0, uint8_t *dest,
  1280. int dstW, int uvalpha, int y)
  1281. {
  1282. const int16_t *ubuf0 = ubuf[0];
  1283. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1284. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1285. const int16_t *ubuf1 = ubuf[0];
  1286. __asm__ volatile(
  1287. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1288. "mov %4, %%"REG_b" \n\t"
  1289. "push %%"REG_BP" \n\t"
  1290. YSCALEYUV2RGB1(%%REGBP, %5)
  1291. "pxor %%mm7, %%mm7 \n\t"
  1292. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1293. #ifdef DITHER1XBPP
  1294. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1295. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1296. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1297. #endif
  1298. WRITERGB16(%%REGb, 8280(%5), %%REGBP)
  1299. "pop %%"REG_BP" \n\t"
  1300. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1301. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1302. "a" (&c->redDither)
  1303. NAMED_CONSTRAINTS_ADD(bF8,bFC)
  1304. );
  1305. } else {
  1306. const int16_t *ubuf1 = ubuf[1];
  1307. __asm__ volatile(
  1308. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1309. "mov %4, %%"REG_b" \n\t"
  1310. "push %%"REG_BP" \n\t"
  1311. YSCALEYUV2RGB1b(%%REGBP, %5)
  1312. "pxor %%mm7, %%mm7 \n\t"
  1313. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1314. #ifdef DITHER1XBPP
  1315. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1316. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1317. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1318. #endif
  1319. WRITERGB16(%%REGb, 8280(%5), %%REGBP)
  1320. "pop %%"REG_BP" \n\t"
  1321. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1322. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1323. "a" (&c->redDither)
  1324. NAMED_CONSTRAINTS_ADD(bF8,bFC)
  1325. );
  1326. }
  1327. }
  1328. #define REAL_YSCALEYUV2PACKED1(index, c) \
  1329. "xor "#index", "#index" \n\t"\
  1330. ".p2align 4 \n\t"\
  1331. "1: \n\t"\
  1332. "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\
  1333. "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  1334. "movq (%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
  1335. "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  1336. "psraw $7, %%mm3 \n\t" \
  1337. "psraw $7, %%mm4 \n\t" \
  1338. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1339. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1340. "psraw $7, %%mm1 \n\t" \
  1341. "psraw $7, %%mm7 \n\t" \
  1342. #define YSCALEYUV2PACKED1(index, c) REAL_YSCALEYUV2PACKED1(index, c)
  1343. #define REAL_YSCALEYUV2PACKED1b(index, c) \
  1344. "xor "#index", "#index" \n\t"\
  1345. ".p2align 4 \n\t"\
  1346. "1: \n\t"\
  1347. "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
  1348. "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
  1349. "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  1350. "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  1351. "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  1352. "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  1353. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
  1354. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
  1355. "psrlw $8, %%mm3 \n\t" \
  1356. "psrlw $8, %%mm4 \n\t" \
  1357. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1358. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1359. "psraw $7, %%mm1 \n\t" \
  1360. "psraw $7, %%mm7 \n\t"
  1361. #define YSCALEYUV2PACKED1b(index, c) REAL_YSCALEYUV2PACKED1b(index, c)
  1362. static void RENAME(yuv2yuyv422_1)(SwsContext *c, const int16_t *buf0,
  1363. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1364. const int16_t *abuf0, uint8_t *dest,
  1365. int dstW, int uvalpha, int y)
  1366. {
  1367. const int16_t *ubuf0 = ubuf[0];
  1368. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1369. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1370. const int16_t *ubuf1 = ubuf[0];
  1371. __asm__ volatile(
  1372. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1373. "mov %4, %%"REG_b" \n\t"
  1374. "push %%"REG_BP" \n\t"
  1375. YSCALEYUV2PACKED1(%%REGBP, %5)
  1376. WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
  1377. "pop %%"REG_BP" \n\t"
  1378. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1379. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1380. "a" (&c->redDither)
  1381. );
  1382. } else {
  1383. const int16_t *ubuf1 = ubuf[1];
  1384. __asm__ volatile(
  1385. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1386. "mov %4, %%"REG_b" \n\t"
  1387. "push %%"REG_BP" \n\t"
  1388. YSCALEYUV2PACKED1b(%%REGBP, %5)
  1389. WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
  1390. "pop %%"REG_BP" \n\t"
  1391. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1392. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1393. "a" (&c->redDither)
  1394. );
  1395. }
  1396. }
  1397. #if COMPILE_TEMPLATE_MMXEXT
  1398. static void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst,
  1399. int dstWidth, const uint8_t *src,
  1400. int srcW, int xInc)
  1401. {
  1402. int32_t *filterPos = c->hLumFilterPos;
  1403. int16_t *filter = c->hLumFilter;
  1404. void *mmxextFilterCode = c->lumMmxextFilterCode;
  1405. int i;
  1406. #if defined(PIC)
  1407. uint64_t ebxsave;
  1408. #endif
  1409. #if ARCH_X86_64
  1410. uint64_t retsave;
  1411. #endif
  1412. __asm__ volatile(
  1413. #if defined(PIC)
  1414. "mov %%"REG_b", %5 \n\t"
  1415. #if ARCH_X86_64
  1416. "mov -8(%%rsp), %%"REG_a" \n\t"
  1417. "mov %%"REG_a", %6 \n\t"
  1418. #endif
  1419. #else
  1420. #if ARCH_X86_64
  1421. "mov -8(%%rsp), %%"REG_a" \n\t"
  1422. "mov %%"REG_a", %5 \n\t"
  1423. #endif
  1424. #endif
  1425. "pxor %%mm7, %%mm7 \n\t"
  1426. "mov %0, %%"REG_c" \n\t"
  1427. "mov %1, %%"REG_D" \n\t"
  1428. "mov %2, %%"REG_d" \n\t"
  1429. "mov %3, %%"REG_b" \n\t"
  1430. "xor %%"REG_a", %%"REG_a" \n\t" // i
  1431. PREFETCH" (%%"REG_c") \n\t"
  1432. PREFETCH" 32(%%"REG_c") \n\t"
  1433. PREFETCH" 64(%%"REG_c") \n\t"
  1434. #if ARCH_X86_64
  1435. #define CALL_MMXEXT_FILTER_CODE \
  1436. "movl (%%"REG_b"), %%esi \n\t"\
  1437. "call *%4 \n\t"\
  1438. "movl (%%"REG_b", %%"REG_a"), %%esi \n\t"\
  1439. "add %%"REG_S", %%"REG_c" \n\t"\
  1440. "add %%"REG_a", %%"REG_D" \n\t"\
  1441. "xor %%"REG_a", %%"REG_a" \n\t"\
  1442. #else
  1443. #define CALL_MMXEXT_FILTER_CODE \
  1444. "movl (%%"REG_b"), %%esi \n\t"\
  1445. "call *%4 \n\t"\
  1446. "addl (%%"REG_b", %%"REG_a"), %%"REG_c" \n\t"\
  1447. "add %%"REG_a", %%"REG_D" \n\t"\
  1448. "xor %%"REG_a", %%"REG_a" \n\t"\
  1449. #endif /* ARCH_X86_64 */
  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. CALL_MMXEXT_FILTER_CODE
  1457. CALL_MMXEXT_FILTER_CODE
  1458. #if defined(PIC)
  1459. "mov %5, %%"REG_b" \n\t"
  1460. #if ARCH_X86_64
  1461. "mov %6, %%"REG_a" \n\t"
  1462. "mov %%"REG_a", -8(%%rsp) \n\t"
  1463. #endif
  1464. #else
  1465. #if ARCH_X86_64
  1466. "mov %5, %%"REG_a" \n\t"
  1467. "mov %%"REG_a", -8(%%rsp) \n\t"
  1468. #endif
  1469. #endif
  1470. :: "m" (src), "m" (dst), "m" (filter), "m" (filterPos),
  1471. "m" (mmxextFilterCode)
  1472. #if defined(PIC)
  1473. ,"m" (ebxsave)
  1474. #endif
  1475. #if ARCH_X86_64
  1476. ,"m"(retsave)
  1477. #endif
  1478. : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
  1479. #if !defined(PIC)
  1480. ,"%"REG_b
  1481. #endif
  1482. );
  1483. for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--)
  1484. dst[i] = src[srcW-1]*128;
  1485. }
  1486. static void RENAME(hcscale_fast)(SwsContext *c, int16_t *dst1, int16_t *dst2,
  1487. int dstWidth, const uint8_t *src1,
  1488. const uint8_t *src2, int srcW, int xInc)
  1489. {
  1490. int32_t *filterPos = c->hChrFilterPos;
  1491. int16_t *filter = c->hChrFilter;
  1492. void *mmxextFilterCode = c->chrMmxextFilterCode;
  1493. int i;
  1494. #if defined(PIC)
  1495. DECLARE_ALIGNED(8, uint64_t, ebxsave);
  1496. #endif
  1497. #if ARCH_X86_64
  1498. DECLARE_ALIGNED(8, uint64_t, retsave);
  1499. #endif
  1500. __asm__ volatile(
  1501. #if defined(PIC)
  1502. "mov %%"REG_b", %7 \n\t"
  1503. #if ARCH_X86_64
  1504. "mov -8(%%rsp), %%"REG_a" \n\t"
  1505. "mov %%"REG_a", %8 \n\t"
  1506. #endif
  1507. #else
  1508. #if ARCH_X86_64
  1509. "mov -8(%%rsp), %%"REG_a" \n\t"
  1510. "mov %%"REG_a", %7 \n\t"
  1511. #endif
  1512. #endif
  1513. "pxor %%mm7, %%mm7 \n\t"
  1514. "mov %0, %%"REG_c" \n\t"
  1515. "mov %1, %%"REG_D" \n\t"
  1516. "mov %2, %%"REG_d" \n\t"
  1517. "mov %3, %%"REG_b" \n\t"
  1518. "xor %%"REG_a", %%"REG_a" \n\t" // i
  1519. PREFETCH" (%%"REG_c") \n\t"
  1520. PREFETCH" 32(%%"REG_c") \n\t"
  1521. PREFETCH" 64(%%"REG_c") \n\t"
  1522. CALL_MMXEXT_FILTER_CODE
  1523. CALL_MMXEXT_FILTER_CODE
  1524. CALL_MMXEXT_FILTER_CODE
  1525. CALL_MMXEXT_FILTER_CODE
  1526. "xor %%"REG_a", %%"REG_a" \n\t" // i
  1527. "mov %5, %%"REG_c" \n\t" // src
  1528. "mov %6, %%"REG_D" \n\t" // buf2
  1529. PREFETCH" (%%"REG_c") \n\t"
  1530. PREFETCH" 32(%%"REG_c") \n\t"
  1531. PREFETCH" 64(%%"REG_c") \n\t"
  1532. CALL_MMXEXT_FILTER_CODE
  1533. CALL_MMXEXT_FILTER_CODE
  1534. CALL_MMXEXT_FILTER_CODE
  1535. CALL_MMXEXT_FILTER_CODE
  1536. #if defined(PIC)
  1537. "mov %7, %%"REG_b" \n\t"
  1538. #if ARCH_X86_64
  1539. "mov %8, %%"REG_a" \n\t"
  1540. "mov %%"REG_a", -8(%%rsp) \n\t"
  1541. #endif
  1542. #else
  1543. #if ARCH_X86_64
  1544. "mov %7, %%"REG_a" \n\t"
  1545. "mov %%"REG_a", -8(%%rsp) \n\t"
  1546. #endif
  1547. #endif
  1548. :: "m" (src1), "m" (dst1), "m" (filter), "m" (filterPos),
  1549. "m" (mmxextFilterCode), "m" (src2), "m"(dst2)
  1550. #if defined(PIC)
  1551. ,"m" (ebxsave)
  1552. #endif
  1553. #if ARCH_X86_64
  1554. ,"m"(retsave)
  1555. #endif
  1556. : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
  1557. #if !defined(PIC)
  1558. ,"%"REG_b
  1559. #endif
  1560. );
  1561. for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) {
  1562. dst1[i] = src1[srcW-1]*128;
  1563. dst2[i] = src2[srcW-1]*128;
  1564. }
  1565. }
  1566. #endif /* COMPILE_TEMPLATE_MMXEXT */
  1567. static av_cold void RENAME(sws_init_swscale)(SwsContext *c)
  1568. {
  1569. enum AVPixelFormat dstFormat = c->dstFormat;
  1570. c->use_mmx_vfilter= 0;
  1571. if (!is16BPS(dstFormat) && !is9_OR_10BPS(dstFormat) && dstFormat != AV_PIX_FMT_NV12
  1572. && dstFormat != AV_PIX_FMT_NV21 && !(c->flags & SWS_BITEXACT)) {
  1573. if (c->flags & SWS_ACCURATE_RND) {
  1574. if (!(c->flags & SWS_FULL_CHR_H_INT)) {
  1575. switch (c->dstFormat) {
  1576. case AV_PIX_FMT_RGB32: c->yuv2packedX = RENAME(yuv2rgb32_X_ar); break;
  1577. case AV_PIX_FMT_BGR24: c->yuv2packedX = RENAME(yuv2bgr24_X_ar); break;
  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. case AV_PIX_FMT_BGR24: c->yuv2packedX = RENAME(yuv2bgr24_X); break;
  1591. case AV_PIX_FMT_RGB555: c->yuv2packedX = RENAME(yuv2rgb555_X); break;
  1592. case AV_PIX_FMT_RGB565: c->yuv2packedX = RENAME(yuv2rgb565_X); break;
  1593. case AV_PIX_FMT_YUYV422: c->yuv2packedX = RENAME(yuv2yuyv422_X); break;
  1594. default: break;
  1595. }
  1596. }
  1597. }
  1598. if (!(c->flags & SWS_FULL_CHR_H_INT)) {
  1599. switch (c->dstFormat) {
  1600. case AV_PIX_FMT_RGB32:
  1601. c->yuv2packed1 = RENAME(yuv2rgb32_1);
  1602. c->yuv2packed2 = RENAME(yuv2rgb32_2);
  1603. break;
  1604. case AV_PIX_FMT_BGR24:
  1605. c->yuv2packed1 = RENAME(yuv2bgr24_1);
  1606. c->yuv2packed2 = RENAME(yuv2bgr24_2);
  1607. break;
  1608. case AV_PIX_FMT_RGB555:
  1609. c->yuv2packed1 = RENAME(yuv2rgb555_1);
  1610. c->yuv2packed2 = RENAME(yuv2rgb555_2);
  1611. break;
  1612. case AV_PIX_FMT_RGB565:
  1613. c->yuv2packed1 = RENAME(yuv2rgb565_1);
  1614. c->yuv2packed2 = RENAME(yuv2rgb565_2);
  1615. break;
  1616. case AV_PIX_FMT_YUYV422:
  1617. c->yuv2packed1 = RENAME(yuv2yuyv422_1);
  1618. c->yuv2packed2 = RENAME(yuv2yuyv422_2);
  1619. break;
  1620. default:
  1621. break;
  1622. }
  1623. }
  1624. }
  1625. if (c->srcBpc == 8 && c->dstBpc <= 14) {
  1626. // Use the new MMX scaler if the MMXEXT one can't be used (it is faster than the x86 ASM one).
  1627. #if COMPILE_TEMPLATE_MMXEXT
  1628. if (c->flags & SWS_FAST_BILINEAR && c->canMMXEXTBeUsed) {
  1629. c->hyscale_fast = RENAME(hyscale_fast);
  1630. c->hcscale_fast = RENAME(hcscale_fast);
  1631. } else {
  1632. #endif /* COMPILE_TEMPLATE_MMXEXT */
  1633. c->hyscale_fast = NULL;
  1634. c->hcscale_fast = NULL;
  1635. #if COMPILE_TEMPLATE_MMXEXT
  1636. }
  1637. #endif /* COMPILE_TEMPLATE_MMXEXT */
  1638. }
  1639. }