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.

2538 lines
114KB

  1. /*
  2. * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #undef REAL_MOVNTQ
  21. #undef MOVNTQ
  22. #undef PREFETCH
  23. #if COMPILE_TEMPLATE_MMX2
  24. #define PREFETCH "prefetchnta"
  25. #else
  26. #define PREFETCH " # nop"
  27. #endif
  28. #if COMPILE_TEMPLATE_MMX2
  29. #define REAL_MOVNTQ(a,b) "movntq " #a ", " #b " \n\t"
  30. #else
  31. #define REAL_MOVNTQ(a,b) "movq " #a ", " #b " \n\t"
  32. #endif
  33. #define MOVNTQ(a,b) REAL_MOVNTQ(a,b)
  34. #define YSCALEYUV2YV12X(offset, dest, end, pos) \
  35. __asm__ volatile(\
  36. "movq "DITHER16"+0(%0), %%mm3 \n\t"\
  37. "movq "DITHER16"+8(%0), %%mm4 \n\t"\
  38. "lea " offset "(%0), %%"REG_d" \n\t"\
  39. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  40. ".p2align 4 \n\t" /* FIXME Unroll? */\
  41. "1: \n\t"\
  42. "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\
  43. "movq (%%"REG_S", %3, 2), %%mm2 \n\t" /* srcData */\
  44. "movq 8(%%"REG_S", %3, 2), %%mm5 \n\t" /* srcData */\
  45. "add $16, %%"REG_d" \n\t"\
  46. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  47. "test %%"REG_S", %%"REG_S" \n\t"\
  48. "pmulhw %%mm0, %%mm2 \n\t"\
  49. "pmulhw %%mm0, %%mm5 \n\t"\
  50. "paddw %%mm2, %%mm3 \n\t"\
  51. "paddw %%mm5, %%mm4 \n\t"\
  52. " jnz 1b \n\t"\
  53. "psraw $3, %%mm3 \n\t"\
  54. "psraw $3, %%mm4 \n\t"\
  55. "packuswb %%mm4, %%mm3 \n\t"\
  56. MOVNTQ(%%mm3, (%1, %3))\
  57. "add $8, %3 \n\t"\
  58. "cmp %2, %3 \n\t"\
  59. "movq "DITHER16"+0(%0), %%mm3 \n\t"\
  60. "movq "DITHER16"+8(%0), %%mm4 \n\t"\
  61. "lea " offset "(%0), %%"REG_d" \n\t"\
  62. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  63. "jb 1b \n\t"\
  64. :: "r" (&c->redDither),\
  65. "r" (dest), "g" ((x86_reg)(end)), "r"((x86_reg)(pos))\
  66. : "%"REG_d, "%"REG_S\
  67. );
  68. #if !COMPILE_TEMPLATE_MMX2
  69. static av_always_inline void
  70. dither_8to16(SwsContext *c, const uint8_t *srcDither, int rot)
  71. {
  72. if (rot) {
  73. __asm__ volatile("pxor %%mm0, %%mm0\n\t"
  74. "movq (%0), %%mm3\n\t"
  75. "movq %%mm3, %%mm4\n\t"
  76. "psrlq $24, %%mm3\n\t"
  77. "psllq $40, %%mm4\n\t"
  78. "por %%mm4, %%mm3\n\t"
  79. "movq %%mm3, %%mm4\n\t"
  80. "punpcklbw %%mm0, %%mm3\n\t"
  81. "punpckhbw %%mm0, %%mm4\n\t"
  82. "psraw $4, %%mm3\n\t"
  83. "psraw $4, %%mm4\n\t"
  84. "movq %%mm3, "DITHER16"+0(%1)\n\t"
  85. "movq %%mm4, "DITHER16"+8(%1)\n\t"
  86. :: "r"(srcDither), "r"(&c->redDither)
  87. );
  88. } else {
  89. __asm__ volatile("pxor %%mm0, %%mm0\n\t"
  90. "movq (%0), %%mm3\n\t"
  91. "movq %%mm3, %%mm4\n\t"
  92. "punpcklbw %%mm0, %%mm3\n\t"
  93. "punpckhbw %%mm0, %%mm4\n\t"
  94. "psraw $4, %%mm3\n\t"
  95. "psraw $4, %%mm4\n\t"
  96. "movq %%mm3, "DITHER16"+0(%1)\n\t"
  97. "movq %%mm4, "DITHER16"+8(%1)\n\t"
  98. :: "r"(srcDither), "r"(&c->redDither)
  99. );
  100. }
  101. }
  102. #endif
  103. static void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter,
  104. const int16_t **lumSrc, int lumFilterSize,
  105. const int16_t *chrFilter, const int16_t **chrUSrc,
  106. const int16_t **chrVSrc,
  107. int chrFilterSize, const int16_t **alpSrc,
  108. uint8_t *dest[4], int dstW, int chrDstW)
  109. {
  110. int i;
  111. uint8_t *yDest = dest[0], *uDest = dest[1], *vDest = dest[2],
  112. *aDest = CONFIG_SWSCALE_ALPHA ? dest[3] : NULL;
  113. const uint8_t *lumDither = c->lumDither8, *chrDither = c->chrDither8;
  114. if (uDest) {
  115. x86_reg uv_off = c->uv_offx2 >> 1;
  116. dither_8to16(c, chrDither, 0);
  117. YSCALEYUV2YV12X(CHR_MMX_FILTER_OFFSET, uDest, chrDstW, 0)
  118. dither_8to16(c, chrDither, 1);
  119. YSCALEYUV2YV12X(CHR_MMX_FILTER_OFFSET, vDest - uv_off, chrDstW + uv_off, uv_off)
  120. }
  121. dither_8to16(c, lumDither, 0);
  122. if (CONFIG_SWSCALE_ALPHA && aDest) {
  123. YSCALEYUV2YV12X(ALP_MMX_FILTER_OFFSET, aDest, dstW, 0)
  124. }
  125. YSCALEYUV2YV12X(LUM_MMX_FILTER_OFFSET, yDest, dstW, 0)
  126. }
  127. #define YSCALEYUV2YV12X_ACCURATE(offset, dest, end, pos) \
  128. __asm__ volatile(\
  129. "lea " offset "(%0), %%"REG_d" \n\t"\
  130. "movq "DITHER32"+0(%0), %%mm4 \n\t"\
  131. "movq "DITHER32"+8(%0), %%mm5 \n\t"\
  132. "movq "DITHER32"+16(%0), %%mm6 \n\t"\
  133. "movq "DITHER32"+24(%0), %%mm7 \n\t"\
  134. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  135. ".p2align 4 \n\t"\
  136. "1: \n\t"\
  137. "movq (%%"REG_S", %3, 2), %%mm0 \n\t" /* srcData */\
  138. "movq 8(%%"REG_S", %3, 2), %%mm2 \n\t" /* srcData */\
  139. "mov "STR(APCK_PTR2)"(%%"REG_d"), %%"REG_S" \n\t"\
  140. "movq (%%"REG_S", %3, 2), %%mm1 \n\t" /* srcData */\
  141. "movq %%mm0, %%mm3 \n\t"\
  142. "punpcklwd %%mm1, %%mm0 \n\t"\
  143. "punpckhwd %%mm1, %%mm3 \n\t"\
  144. "movq "STR(APCK_COEF)"(%%"REG_d"), %%mm1 \n\t" /* filterCoeff */\
  145. "pmaddwd %%mm1, %%mm0 \n\t"\
  146. "pmaddwd %%mm1, %%mm3 \n\t"\
  147. "paddd %%mm0, %%mm4 \n\t"\
  148. "paddd %%mm3, %%mm5 \n\t"\
  149. "movq 8(%%"REG_S", %3, 2), %%mm3 \n\t" /* srcData */\
  150. "mov "STR(APCK_SIZE)"(%%"REG_d"), %%"REG_S" \n\t"\
  151. "add $"STR(APCK_SIZE)", %%"REG_d" \n\t"\
  152. "test %%"REG_S", %%"REG_S" \n\t"\
  153. "movq %%mm2, %%mm0 \n\t"\
  154. "punpcklwd %%mm3, %%mm2 \n\t"\
  155. "punpckhwd %%mm3, %%mm0 \n\t"\
  156. "pmaddwd %%mm1, %%mm2 \n\t"\
  157. "pmaddwd %%mm1, %%mm0 \n\t"\
  158. "paddd %%mm2, %%mm6 \n\t"\
  159. "paddd %%mm0, %%mm7 \n\t"\
  160. " jnz 1b \n\t"\
  161. "psrad $19, %%mm4 \n\t"\
  162. "psrad $19, %%mm5 \n\t"\
  163. "psrad $19, %%mm6 \n\t"\
  164. "psrad $19, %%mm7 \n\t"\
  165. "packssdw %%mm5, %%mm4 \n\t"\
  166. "packssdw %%mm7, %%mm6 \n\t"\
  167. "packuswb %%mm6, %%mm4 \n\t"\
  168. MOVNTQ(%%mm4, (%1, %3))\
  169. "add $8, %3 \n\t"\
  170. "cmp %2, %3 \n\t"\
  171. "lea " offset "(%0), %%"REG_d" \n\t"\
  172. "movq "DITHER32"+0(%0), %%mm4 \n\t"\
  173. "movq "DITHER32"+8(%0), %%mm5 \n\t"\
  174. "movq "DITHER32"+16(%0), %%mm6 \n\t"\
  175. "movq "DITHER32"+24(%0), %%mm7 \n\t"\
  176. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  177. "jb 1b \n\t"\
  178. :: "r" (&c->redDither),\
  179. "r" (dest), "g" ((x86_reg)(end)), "r"((x86_reg)(pos))\
  180. : "%"REG_a, "%"REG_d, "%"REG_S\
  181. );
  182. #if !COMPILE_TEMPLATE_MMX2
  183. static av_always_inline void
  184. dither_8to32(SwsContext *c, const uint8_t *srcDither, int rot)
  185. {
  186. int i;
  187. if(rot) for(i=0; i<8; i++) c->dither32[i] = srcDither[(i+3)&7]<<12;
  188. else for(i=0; i<8; i++) c->dither32[i] = srcDither[i&7]<<12;
  189. return;
  190. if (rot) {
  191. __asm__ volatile("pxor %%mm0, %%mm0\n\t"
  192. "movq (%0), %%mm4\n\t"
  193. "movq %%mm4, %%mm5\n\t"
  194. "psrlq $24, %%mm4\n\t"
  195. "psllq $40, %%mm5\n\t"
  196. "por %%mm5, %%mm4\n\t"
  197. "movq %%mm4, %%mm6\n\t"
  198. "punpcklbw %%mm0, %%mm4\n\t"
  199. "punpckhbw %%mm0, %%mm6\n\t"
  200. "movq %%mm4, %%mm5\n\t"
  201. "movq %%mm6, %%mm7\n\t"
  202. "punpcklwd %%mm0, %%mm4\n\t"
  203. "punpckhwd %%mm0, %%mm5\n\t"
  204. "punpcklwd %%mm0, %%mm6\n\t"
  205. "punpckhwd %%mm0, %%mm7\n\t"
  206. "psllw $12, %%mm4\n\t"
  207. "psllw $12, %%mm5\n\t"
  208. "psllw $12, %%mm6\n\t"
  209. "psllw $12, %%mm7\n\t"
  210. "movq %%mm4, "DITHER32"+0(%1)\n\t"
  211. "movq %%mm5, "DITHER32"+8(%1)\n\t"
  212. "movq %%mm6, "DITHER32"+16(%1)\n\t"
  213. "movq %%mm7, "DITHER32"+24(%1)\n\t"
  214. :: "r"(srcDither), "r"(&c->redDither)
  215. );
  216. } else {
  217. __asm__ volatile("pxor %%mm0, %%mm0\n\t"
  218. "movq (%0), %%mm4\n\t"
  219. "movq %%mm4, %%mm6\n\t"
  220. "punpcklbw %%mm0, %%mm4\n\t"
  221. "punpckhbw %%mm0, %%mm6\n\t"
  222. "movq %%mm4, %%mm5\n\t"
  223. "movq %%mm6, %%mm7\n\t"
  224. "punpcklwd %%mm0, %%mm4\n\t"
  225. "punpckhwd %%mm0, %%mm5\n\t"
  226. "punpcklwd %%mm0, %%mm6\n\t"
  227. "punpckhwd %%mm0, %%mm7\n\t"
  228. "psllw $12, %%mm4\n\t"
  229. "psllw $12, %%mm5\n\t"
  230. "psllw $12, %%mm6\n\t"
  231. "psllw $12, %%mm7\n\t"
  232. "movq %%mm4, "DITHER32"+0(%1)\n\t"
  233. "movq %%mm5, "DITHER32"+8(%1)\n\t"
  234. "movq %%mm6, "DITHER32"+16(%1)\n\t"
  235. "movq %%mm7, "DITHER32"+24(%1)\n\t"
  236. :: "r"(srcDither), "r"(&c->redDither)
  237. );
  238. }
  239. }
  240. #endif
  241. static void RENAME(yuv2yuvX_ar)(SwsContext *c, const int16_t *lumFilter,
  242. const int16_t **lumSrc, int lumFilterSize,
  243. const int16_t *chrFilter, const int16_t **chrUSrc,
  244. const int16_t **chrVSrc,
  245. int chrFilterSize, const int16_t **alpSrc,
  246. uint8_t *dest[4], int dstW, int chrDstW)
  247. {
  248. int i;
  249. uint8_t *yDest = dest[0], *uDest = dest[1], *vDest = dest[2],
  250. *aDest = CONFIG_SWSCALE_ALPHA ? dest[3] : NULL;
  251. const uint8_t *lumDither = c->lumDither8, *chrDither = c->chrDither8;
  252. if (uDest) {
  253. x86_reg uv_off = c->uv_offx2 >> 1;
  254. dither_8to32(c, chrDither, 0);
  255. YSCALEYUV2YV12X_ACCURATE(CHR_MMX_FILTER_OFFSET, uDest, chrDstW, 0)
  256. dither_8to32(c, chrDither, 1);
  257. YSCALEYUV2YV12X_ACCURATE(CHR_MMX_FILTER_OFFSET, vDest - uv_off, chrDstW + uv_off, uv_off)
  258. }
  259. dither_8to32(c, lumDither, 0);
  260. if (CONFIG_SWSCALE_ALPHA && aDest) {
  261. YSCALEYUV2YV12X_ACCURATE(ALP_MMX_FILTER_OFFSET, aDest, dstW, 0)
  262. }
  263. YSCALEYUV2YV12X_ACCURATE(LUM_MMX_FILTER_OFFSET, yDest, dstW, 0)
  264. }
  265. static void RENAME(yuv2yuv1)(SwsContext *c, const int16_t *lumSrc,
  266. const int16_t *chrUSrc, const int16_t *chrVSrc,
  267. const int16_t *alpSrc,
  268. uint8_t *dst[4], int dstW, int chrDstW)
  269. {
  270. int p= 4;
  271. const int16_t *src[4]= {
  272. lumSrc + dstW, chrUSrc + chrDstW,
  273. chrVSrc + chrDstW, alpSrc + dstW
  274. };
  275. x86_reg counter[4]= { dstW, chrDstW, chrDstW, dstW };
  276. while (p--) {
  277. if (dst[p]) {
  278. __asm__ volatile(
  279. "mov %2, %%"REG_a" \n\t"
  280. ".p2align 4 \n\t" /* FIXME Unroll? */
  281. "1: \n\t"
  282. "movq (%0, %%"REG_a", 2), %%mm0 \n\t"
  283. "movq 8(%0, %%"REG_a", 2), %%mm1 \n\t"
  284. "psraw $7, %%mm0 \n\t"
  285. "psraw $7, %%mm1 \n\t"
  286. "packuswb %%mm1, %%mm0 \n\t"
  287. MOVNTQ(%%mm0, (%1, %%REGa))
  288. "add $8, %%"REG_a" \n\t"
  289. "jnc 1b \n\t"
  290. :: "r" (src[p]), "r" (dst[p] + counter[p]),
  291. "g" (-counter[p])
  292. : "%"REG_a
  293. );
  294. }
  295. }
  296. }
  297. static void RENAME(yuv2yuv1_ar)(SwsContext *c, const int16_t *lumSrc,
  298. const int16_t *chrUSrc, const int16_t *chrVSrc,
  299. const int16_t *alpSrc,
  300. uint8_t *dst[4], int dstW, int chrDstW)
  301. {
  302. int p= 4;
  303. const int16_t *src[4]= {
  304. lumSrc + dstW, chrUSrc + chrDstW,
  305. chrVSrc + chrDstW, alpSrc + dstW
  306. };
  307. x86_reg counter[4]= { dstW, chrDstW, chrDstW, dstW };
  308. const uint8_t *lumDither = c->lumDither8, *chrDither = c->chrDither8;
  309. while (p--) {
  310. if (dst[p]) {
  311. int i;
  312. for(i=0; i<8; i++) c->dither16[i] = (p == 2 || p == 3) ? lumDither[i] : chrDither[i];
  313. __asm__ volatile(
  314. "mov %2, %%"REG_a" \n\t"
  315. "movq "DITHER16"+0(%3), %%mm6 \n\t"
  316. "movq "DITHER16"+8(%3), %%mm7 \n\t"
  317. ".p2align 4 \n\t" /* FIXME Unroll? */
  318. "1: \n\t"
  319. "movq (%0, %%"REG_a", 2), %%mm0 \n\t"
  320. "movq 8(%0, %%"REG_a", 2), %%mm1 \n\t"
  321. "paddsw %%mm6, %%mm0 \n\t"
  322. "paddsw %%mm7, %%mm1 \n\t"
  323. "psraw $7, %%mm0 \n\t"
  324. "psraw $7, %%mm1 \n\t"
  325. "packuswb %%mm1, %%mm0 \n\t"
  326. MOVNTQ(%%mm0, (%1, %%REGa))
  327. "add $8, %%"REG_a" \n\t"
  328. "jnc 1b \n\t"
  329. :: "r" (src[p]), "r" (dst[p] + counter[p]),
  330. "g" (-counter[p]), "r"(&c->redDither)
  331. : "%"REG_a
  332. );
  333. }
  334. }
  335. }
  336. #define YSCALEYUV2PACKEDX_UV \
  337. __asm__ volatile(\
  338. "xor %%"REG_a", %%"REG_a" \n\t"\
  339. ".p2align 4 \n\t"\
  340. "nop \n\t"\
  341. "1: \n\t"\
  342. "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d" \n\t"\
  343. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  344. "movq "VROUNDER_OFFSET"(%0), %%mm3 \n\t"\
  345. "movq %%mm3, %%mm4 \n\t"\
  346. ".p2align 4 \n\t"\
  347. "2: \n\t"\
  348. "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\
  349. "movq (%%"REG_S", %%"REG_a"), %%mm2 \n\t" /* UsrcData */\
  350. "add %6, %%"REG_S" \n\t" \
  351. "movq (%%"REG_S", %%"REG_a"), %%mm5 \n\t" /* VsrcData */\
  352. "add $16, %%"REG_d" \n\t"\
  353. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  354. "pmulhw %%mm0, %%mm2 \n\t"\
  355. "pmulhw %%mm0, %%mm5 \n\t"\
  356. "paddw %%mm2, %%mm3 \n\t"\
  357. "paddw %%mm5, %%mm4 \n\t"\
  358. "test %%"REG_S", %%"REG_S" \n\t"\
  359. " jnz 2b \n\t"\
  360. #define YSCALEYUV2PACKEDX_YA(offset,coeff,src1,src2,dst1,dst2) \
  361. "lea "offset"(%0), %%"REG_d" \n\t"\
  362. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  363. "movq "VROUNDER_OFFSET"(%0), "#dst1" \n\t"\
  364. "movq "#dst1", "#dst2" \n\t"\
  365. ".p2align 4 \n\t"\
  366. "2: \n\t"\
  367. "movq 8(%%"REG_d"), "#coeff" \n\t" /* filterCoeff */\
  368. "movq (%%"REG_S", %%"REG_a", 2), "#src1" \n\t" /* Y1srcData */\
  369. "movq 8(%%"REG_S", %%"REG_a", 2), "#src2" \n\t" /* Y2srcData */\
  370. "add $16, %%"REG_d" \n\t"\
  371. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  372. "pmulhw "#coeff", "#src1" \n\t"\
  373. "pmulhw "#coeff", "#src2" \n\t"\
  374. "paddw "#src1", "#dst1" \n\t"\
  375. "paddw "#src2", "#dst2" \n\t"\
  376. "test %%"REG_S", %%"REG_S" \n\t"\
  377. " jnz 2b \n\t"\
  378. #define YSCALEYUV2PACKEDX \
  379. YSCALEYUV2PACKEDX_UV \
  380. YSCALEYUV2PACKEDX_YA(LUM_MMX_FILTER_OFFSET,%%mm0,%%mm2,%%mm5,%%mm1,%%mm7) \
  381. #define YSCALEYUV2PACKEDX_END \
  382. :: "r" (&c->redDither), \
  383. "m" (dummy), "m" (dummy), "m" (dummy),\
  384. "r" (dest), "m" (dstW_reg), "m"(uv_off) \
  385. : "%"REG_a, "%"REG_d, "%"REG_S \
  386. );
  387. #define YSCALEYUV2PACKEDX_ACCURATE_UV \
  388. __asm__ volatile(\
  389. "xor %%"REG_a", %%"REG_a" \n\t"\
  390. ".p2align 4 \n\t"\
  391. "nop \n\t"\
  392. "1: \n\t"\
  393. "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d" \n\t"\
  394. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  395. "pxor %%mm4, %%mm4 \n\t"\
  396. "pxor %%mm5, %%mm5 \n\t"\
  397. "pxor %%mm6, %%mm6 \n\t"\
  398. "pxor %%mm7, %%mm7 \n\t"\
  399. ".p2align 4 \n\t"\
  400. "2: \n\t"\
  401. "movq (%%"REG_S", %%"REG_a"), %%mm0 \n\t" /* UsrcData */\
  402. "add %6, %%"REG_S" \n\t" \
  403. "movq (%%"REG_S", %%"REG_a"), %%mm2 \n\t" /* VsrcData */\
  404. "mov "STR(APCK_PTR2)"(%%"REG_d"), %%"REG_S" \n\t"\
  405. "movq (%%"REG_S", %%"REG_a"), %%mm1 \n\t" /* UsrcData */\
  406. "movq %%mm0, %%mm3 \n\t"\
  407. "punpcklwd %%mm1, %%mm0 \n\t"\
  408. "punpckhwd %%mm1, %%mm3 \n\t"\
  409. "movq "STR(APCK_COEF)"(%%"REG_d"),%%mm1 \n\t" /* filterCoeff */\
  410. "pmaddwd %%mm1, %%mm0 \n\t"\
  411. "pmaddwd %%mm1, %%mm3 \n\t"\
  412. "paddd %%mm0, %%mm4 \n\t"\
  413. "paddd %%mm3, %%mm5 \n\t"\
  414. "add %6, %%"REG_S" \n\t" \
  415. "movq (%%"REG_S", %%"REG_a"), %%mm3 \n\t" /* VsrcData */\
  416. "mov "STR(APCK_SIZE)"(%%"REG_d"), %%"REG_S" \n\t"\
  417. "add $"STR(APCK_SIZE)", %%"REG_d" \n\t"\
  418. "test %%"REG_S", %%"REG_S" \n\t"\
  419. "movq %%mm2, %%mm0 \n\t"\
  420. "punpcklwd %%mm3, %%mm2 \n\t"\
  421. "punpckhwd %%mm3, %%mm0 \n\t"\
  422. "pmaddwd %%mm1, %%mm2 \n\t"\
  423. "pmaddwd %%mm1, %%mm0 \n\t"\
  424. "paddd %%mm2, %%mm6 \n\t"\
  425. "paddd %%mm0, %%mm7 \n\t"\
  426. " jnz 2b \n\t"\
  427. "psrad $16, %%mm4 \n\t"\
  428. "psrad $16, %%mm5 \n\t"\
  429. "psrad $16, %%mm6 \n\t"\
  430. "psrad $16, %%mm7 \n\t"\
  431. "movq "VROUNDER_OFFSET"(%0), %%mm0 \n\t"\
  432. "packssdw %%mm5, %%mm4 \n\t"\
  433. "packssdw %%mm7, %%mm6 \n\t"\
  434. "paddw %%mm0, %%mm4 \n\t"\
  435. "paddw %%mm0, %%mm6 \n\t"\
  436. "movq %%mm4, "U_TEMP"(%0) \n\t"\
  437. "movq %%mm6, "V_TEMP"(%0) \n\t"\
  438. #define YSCALEYUV2PACKEDX_ACCURATE_YA(offset) \
  439. "lea "offset"(%0), %%"REG_d" \n\t"\
  440. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  441. "pxor %%mm1, %%mm1 \n\t"\
  442. "pxor %%mm5, %%mm5 \n\t"\
  443. "pxor %%mm7, %%mm7 \n\t"\
  444. "pxor %%mm6, %%mm6 \n\t"\
  445. ".p2align 4 \n\t"\
  446. "2: \n\t"\
  447. "movq (%%"REG_S", %%"REG_a", 2), %%mm0 \n\t" /* Y1srcData */\
  448. "movq 8(%%"REG_S", %%"REG_a", 2), %%mm2 \n\t" /* Y2srcData */\
  449. "mov "STR(APCK_PTR2)"(%%"REG_d"), %%"REG_S" \n\t"\
  450. "movq (%%"REG_S", %%"REG_a", 2), %%mm4 \n\t" /* Y1srcData */\
  451. "movq %%mm0, %%mm3 \n\t"\
  452. "punpcklwd %%mm4, %%mm0 \n\t"\
  453. "punpckhwd %%mm4, %%mm3 \n\t"\
  454. "movq "STR(APCK_COEF)"(%%"REG_d"), %%mm4 \n\t" /* filterCoeff */\
  455. "pmaddwd %%mm4, %%mm0 \n\t"\
  456. "pmaddwd %%mm4, %%mm3 \n\t"\
  457. "paddd %%mm0, %%mm1 \n\t"\
  458. "paddd %%mm3, %%mm5 \n\t"\
  459. "movq 8(%%"REG_S", %%"REG_a", 2), %%mm3 \n\t" /* Y2srcData */\
  460. "mov "STR(APCK_SIZE)"(%%"REG_d"), %%"REG_S" \n\t"\
  461. "add $"STR(APCK_SIZE)", %%"REG_d" \n\t"\
  462. "test %%"REG_S", %%"REG_S" \n\t"\
  463. "movq %%mm2, %%mm0 \n\t"\
  464. "punpcklwd %%mm3, %%mm2 \n\t"\
  465. "punpckhwd %%mm3, %%mm0 \n\t"\
  466. "pmaddwd %%mm4, %%mm2 \n\t"\
  467. "pmaddwd %%mm4, %%mm0 \n\t"\
  468. "paddd %%mm2, %%mm7 \n\t"\
  469. "paddd %%mm0, %%mm6 \n\t"\
  470. " jnz 2b \n\t"\
  471. "psrad $16, %%mm1 \n\t"\
  472. "psrad $16, %%mm5 \n\t"\
  473. "psrad $16, %%mm7 \n\t"\
  474. "psrad $16, %%mm6 \n\t"\
  475. "movq "VROUNDER_OFFSET"(%0), %%mm0 \n\t"\
  476. "packssdw %%mm5, %%mm1 \n\t"\
  477. "packssdw %%mm6, %%mm7 \n\t"\
  478. "paddw %%mm0, %%mm1 \n\t"\
  479. "paddw %%mm0, %%mm7 \n\t"\
  480. "movq "U_TEMP"(%0), %%mm3 \n\t"\
  481. "movq "V_TEMP"(%0), %%mm4 \n\t"\
  482. #define YSCALEYUV2PACKEDX_ACCURATE \
  483. YSCALEYUV2PACKEDX_ACCURATE_UV \
  484. YSCALEYUV2PACKEDX_ACCURATE_YA(LUM_MMX_FILTER_OFFSET)
  485. #define YSCALEYUV2RGBX \
  486. "psubw "U_OFFSET"(%0), %%mm3 \n\t" /* (U-128)8*/\
  487. "psubw "V_OFFSET"(%0), %%mm4 \n\t" /* (V-128)8*/\
  488. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  489. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  490. "pmulhw "UG_COEFF"(%0), %%mm3 \n\t"\
  491. "pmulhw "VG_COEFF"(%0), %%mm4 \n\t"\
  492. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  493. "pmulhw "UB_COEFF"(%0), %%mm2 \n\t"\
  494. "pmulhw "VR_COEFF"(%0), %%mm5 \n\t"\
  495. "psubw "Y_OFFSET"(%0), %%mm1 \n\t" /* 8(Y-16)*/\
  496. "psubw "Y_OFFSET"(%0), %%mm7 \n\t" /* 8(Y-16)*/\
  497. "pmulhw "Y_COEFF"(%0), %%mm1 \n\t"\
  498. "pmulhw "Y_COEFF"(%0), %%mm7 \n\t"\
  499. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  500. "paddw %%mm3, %%mm4 \n\t"\
  501. "movq %%mm2, %%mm0 \n\t"\
  502. "movq %%mm5, %%mm6 \n\t"\
  503. "movq %%mm4, %%mm3 \n\t"\
  504. "punpcklwd %%mm2, %%mm2 \n\t"\
  505. "punpcklwd %%mm5, %%mm5 \n\t"\
  506. "punpcklwd %%mm4, %%mm4 \n\t"\
  507. "paddw %%mm1, %%mm2 \n\t"\
  508. "paddw %%mm1, %%mm5 \n\t"\
  509. "paddw %%mm1, %%mm4 \n\t"\
  510. "punpckhwd %%mm0, %%mm0 \n\t"\
  511. "punpckhwd %%mm6, %%mm6 \n\t"\
  512. "punpckhwd %%mm3, %%mm3 \n\t"\
  513. "paddw %%mm7, %%mm0 \n\t"\
  514. "paddw %%mm7, %%mm6 \n\t"\
  515. "paddw %%mm7, %%mm3 \n\t"\
  516. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  517. "packuswb %%mm0, %%mm2 \n\t"\
  518. "packuswb %%mm6, %%mm5 \n\t"\
  519. "packuswb %%mm3, %%mm4 \n\t"\
  520. #define REAL_WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t) \
  521. "movq "#b", "#q2" \n\t" /* B */\
  522. "movq "#r", "#t" \n\t" /* R */\
  523. "punpcklbw "#g", "#b" \n\t" /* GBGBGBGB 0 */\
  524. "punpcklbw "#a", "#r" \n\t" /* ARARARAR 0 */\
  525. "punpckhbw "#g", "#q2" \n\t" /* GBGBGBGB 2 */\
  526. "punpckhbw "#a", "#t" \n\t" /* ARARARAR 2 */\
  527. "movq "#b", "#q0" \n\t" /* GBGBGBGB 0 */\
  528. "movq "#q2", "#q3" \n\t" /* GBGBGBGB 2 */\
  529. "punpcklwd "#r", "#q0" \n\t" /* ARGBARGB 0 */\
  530. "punpckhwd "#r", "#b" \n\t" /* ARGBARGB 1 */\
  531. "punpcklwd "#t", "#q2" \n\t" /* ARGBARGB 2 */\
  532. "punpckhwd "#t", "#q3" \n\t" /* ARGBARGB 3 */\
  533. \
  534. MOVNTQ( q0, (dst, index, 4))\
  535. MOVNTQ( b, 8(dst, index, 4))\
  536. MOVNTQ( q2, 16(dst, index, 4))\
  537. MOVNTQ( q3, 24(dst, index, 4))\
  538. \
  539. "add $8, "#index" \n\t"\
  540. "cmp "#dstw", "#index" \n\t"\
  541. " jb 1b \n\t"
  542. #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)
  543. static void RENAME(yuv2rgb32_X_ar)(SwsContext *c, const int16_t *lumFilter,
  544. const int16_t **lumSrc, int lumFilterSize,
  545. const int16_t *chrFilter, const int16_t **chrUSrc,
  546. const int16_t **chrVSrc,
  547. int chrFilterSize, const int16_t **alpSrc,
  548. uint8_t *dest, int dstW, int dstY)
  549. {
  550. x86_reg dummy=0;
  551. x86_reg dstW_reg = dstW;
  552. x86_reg uv_off = c->uv_offx2;
  553. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  554. YSCALEYUV2PACKEDX_ACCURATE
  555. YSCALEYUV2RGBX
  556. "movq %%mm2, "U_TEMP"(%0) \n\t"
  557. "movq %%mm4, "V_TEMP"(%0) \n\t"
  558. "movq %%mm5, "Y_TEMP"(%0) \n\t"
  559. YSCALEYUV2PACKEDX_ACCURATE_YA(ALP_MMX_FILTER_OFFSET)
  560. "movq "Y_TEMP"(%0), %%mm5 \n\t"
  561. "psraw $3, %%mm1 \n\t"
  562. "psraw $3, %%mm7 \n\t"
  563. "packuswb %%mm7, %%mm1 \n\t"
  564. WRITEBGR32(%4, %5, %%REGa, %%mm3, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm2, %%mm6)
  565. YSCALEYUV2PACKEDX_END
  566. } else {
  567. YSCALEYUV2PACKEDX_ACCURATE
  568. YSCALEYUV2RGBX
  569. "pcmpeqd %%mm7, %%mm7 \n\t"
  570. WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  571. YSCALEYUV2PACKEDX_END
  572. }
  573. }
  574. static void RENAME(yuv2rgb32_X)(SwsContext *c, const int16_t *lumFilter,
  575. const int16_t **lumSrc, int lumFilterSize,
  576. const int16_t *chrFilter, const int16_t **chrUSrc,
  577. const int16_t **chrVSrc,
  578. int chrFilterSize, const int16_t **alpSrc,
  579. uint8_t *dest, int dstW, int dstY)
  580. {
  581. x86_reg dummy=0;
  582. x86_reg dstW_reg = dstW;
  583. x86_reg uv_off = c->uv_offx2;
  584. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  585. YSCALEYUV2PACKEDX
  586. YSCALEYUV2RGBX
  587. YSCALEYUV2PACKEDX_YA(ALP_MMX_FILTER_OFFSET, %%mm0, %%mm3, %%mm6, %%mm1, %%mm7)
  588. "psraw $3, %%mm1 \n\t"
  589. "psraw $3, %%mm7 \n\t"
  590. "packuswb %%mm7, %%mm1 \n\t"
  591. WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6)
  592. YSCALEYUV2PACKEDX_END
  593. } else {
  594. YSCALEYUV2PACKEDX
  595. YSCALEYUV2RGBX
  596. "pcmpeqd %%mm7, %%mm7 \n\t"
  597. WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  598. YSCALEYUV2PACKEDX_END
  599. }
  600. }
  601. #define REAL_WRITERGB16(dst, dstw, index) \
  602. "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\
  603. "pand "MANGLE(bFC)", %%mm4 \n\t" /* G */\
  604. "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\
  605. "psrlq $3, %%mm2 \n\t"\
  606. \
  607. "movq %%mm2, %%mm1 \n\t"\
  608. "movq %%mm4, %%mm3 \n\t"\
  609. \
  610. "punpcklbw %%mm7, %%mm3 \n\t"\
  611. "punpcklbw %%mm5, %%mm2 \n\t"\
  612. "punpckhbw %%mm7, %%mm4 \n\t"\
  613. "punpckhbw %%mm5, %%mm1 \n\t"\
  614. \
  615. "psllq $3, %%mm3 \n\t"\
  616. "psllq $3, %%mm4 \n\t"\
  617. \
  618. "por %%mm3, %%mm2 \n\t"\
  619. "por %%mm4, %%mm1 \n\t"\
  620. \
  621. MOVNTQ(%%mm2, (dst, index, 2))\
  622. MOVNTQ(%%mm1, 8(dst, index, 2))\
  623. \
  624. "add $8, "#index" \n\t"\
  625. "cmp "#dstw", "#index" \n\t"\
  626. " jb 1b \n\t"
  627. #define WRITERGB16(dst, dstw, index) REAL_WRITERGB16(dst, dstw, index)
  628. static void RENAME(yuv2rgb565_X_ar)(SwsContext *c, const int16_t *lumFilter,
  629. const int16_t **lumSrc, int lumFilterSize,
  630. const int16_t *chrFilter, const int16_t **chrUSrc,
  631. const int16_t **chrVSrc,
  632. int chrFilterSize, const int16_t **alpSrc,
  633. uint8_t *dest, int dstW, int dstY)
  634. {
  635. x86_reg dummy=0;
  636. x86_reg dstW_reg = dstW;
  637. x86_reg uv_off = c->uv_offx2;
  638. YSCALEYUV2PACKEDX_ACCURATE
  639. YSCALEYUV2RGBX
  640. "pxor %%mm7, %%mm7 \n\t"
  641. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  642. #ifdef DITHER1XBPP
  643. "paddusb "BLUE_DITHER"(%0), %%mm2\n\t"
  644. "paddusb "GREEN_DITHER"(%0), %%mm4\n\t"
  645. "paddusb "RED_DITHER"(%0), %%mm5\n\t"
  646. #endif
  647. WRITERGB16(%4, %5, %%REGa)
  648. YSCALEYUV2PACKEDX_END
  649. }
  650. static void RENAME(yuv2rgb565_X)(SwsContext *c, const int16_t *lumFilter,
  651. const int16_t **lumSrc, int lumFilterSize,
  652. const int16_t *chrFilter, const int16_t **chrUSrc,
  653. const int16_t **chrVSrc,
  654. int chrFilterSize, const int16_t **alpSrc,
  655. uint8_t *dest, int dstW, int dstY)
  656. {
  657. x86_reg dummy=0;
  658. x86_reg dstW_reg = dstW;
  659. x86_reg uv_off = c->uv_offx2;
  660. YSCALEYUV2PACKEDX
  661. YSCALEYUV2RGBX
  662. "pxor %%mm7, %%mm7 \n\t"
  663. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  664. #ifdef DITHER1XBPP
  665. "paddusb "BLUE_DITHER"(%0), %%mm2 \n\t"
  666. "paddusb "GREEN_DITHER"(%0), %%mm4 \n\t"
  667. "paddusb "RED_DITHER"(%0), %%mm5 \n\t"
  668. #endif
  669. WRITERGB16(%4, %5, %%REGa)
  670. YSCALEYUV2PACKEDX_END
  671. }
  672. #define REAL_WRITERGB15(dst, dstw, index) \
  673. "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\
  674. "pand "MANGLE(bF8)", %%mm4 \n\t" /* G */\
  675. "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\
  676. "psrlq $3, %%mm2 \n\t"\
  677. "psrlq $1, %%mm5 \n\t"\
  678. \
  679. "movq %%mm2, %%mm1 \n\t"\
  680. "movq %%mm4, %%mm3 \n\t"\
  681. \
  682. "punpcklbw %%mm7, %%mm3 \n\t"\
  683. "punpcklbw %%mm5, %%mm2 \n\t"\
  684. "punpckhbw %%mm7, %%mm4 \n\t"\
  685. "punpckhbw %%mm5, %%mm1 \n\t"\
  686. \
  687. "psllq $2, %%mm3 \n\t"\
  688. "psllq $2, %%mm4 \n\t"\
  689. \
  690. "por %%mm3, %%mm2 \n\t"\
  691. "por %%mm4, %%mm1 \n\t"\
  692. \
  693. MOVNTQ(%%mm2, (dst, index, 2))\
  694. MOVNTQ(%%mm1, 8(dst, index, 2))\
  695. \
  696. "add $8, "#index" \n\t"\
  697. "cmp "#dstw", "#index" \n\t"\
  698. " jb 1b \n\t"
  699. #define WRITERGB15(dst, dstw, index) REAL_WRITERGB15(dst, dstw, index)
  700. static void RENAME(yuv2rgb555_X_ar)(SwsContext *c, const int16_t *lumFilter,
  701. const int16_t **lumSrc, int lumFilterSize,
  702. const int16_t *chrFilter, const int16_t **chrUSrc,
  703. const int16_t **chrVSrc,
  704. int chrFilterSize, const int16_t **alpSrc,
  705. uint8_t *dest, int dstW, int dstY)
  706. {
  707. x86_reg dummy=0;
  708. x86_reg dstW_reg = dstW;
  709. x86_reg uv_off = c->uv_offx2;
  710. YSCALEYUV2PACKEDX_ACCURATE
  711. YSCALEYUV2RGBX
  712. "pxor %%mm7, %%mm7 \n\t"
  713. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  714. #ifdef DITHER1XBPP
  715. "paddusb "BLUE_DITHER"(%0), %%mm2\n\t"
  716. "paddusb "GREEN_DITHER"(%0), %%mm4\n\t"
  717. "paddusb "RED_DITHER"(%0), %%mm5\n\t"
  718. #endif
  719. WRITERGB15(%4, %5, %%REGa)
  720. YSCALEYUV2PACKEDX_END
  721. }
  722. static void RENAME(yuv2rgb555_X)(SwsContext *c, const int16_t *lumFilter,
  723. const int16_t **lumSrc, int lumFilterSize,
  724. const int16_t *chrFilter, const int16_t **chrUSrc,
  725. const int16_t **chrVSrc,
  726. int chrFilterSize, const int16_t **alpSrc,
  727. uint8_t *dest, int dstW, int dstY)
  728. {
  729. x86_reg dummy=0;
  730. x86_reg dstW_reg = dstW;
  731. x86_reg uv_off = c->uv_offx2;
  732. YSCALEYUV2PACKEDX
  733. YSCALEYUV2RGBX
  734. "pxor %%mm7, %%mm7 \n\t"
  735. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  736. #ifdef DITHER1XBPP
  737. "paddusb "BLUE_DITHER"(%0), %%mm2 \n\t"
  738. "paddusb "GREEN_DITHER"(%0), %%mm4 \n\t"
  739. "paddusb "RED_DITHER"(%0), %%mm5 \n\t"
  740. #endif
  741. WRITERGB15(%4, %5, %%REGa)
  742. YSCALEYUV2PACKEDX_END
  743. }
  744. #define WRITEBGR24MMX(dst, dstw, index) \
  745. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
  746. "movq %%mm2, %%mm1 \n\t" /* B */\
  747. "movq %%mm5, %%mm6 \n\t" /* R */\
  748. "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\
  749. "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\
  750. "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\
  751. "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\
  752. "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\
  753. "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\
  754. "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\
  755. "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\
  756. "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\
  757. "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\
  758. \
  759. "movq %%mm0, %%mm4 \n\t" /* 0RGB0RGB 0 */\
  760. "movq %%mm2, %%mm6 \n\t" /* 0RGB0RGB 1 */\
  761. "movq %%mm1, %%mm5 \n\t" /* 0RGB0RGB 2 */\
  762. "movq %%mm3, %%mm7 \n\t" /* 0RGB0RGB 3 */\
  763. \
  764. "psllq $40, %%mm0 \n\t" /* RGB00000 0 */\
  765. "psllq $40, %%mm2 \n\t" /* RGB00000 1 */\
  766. "psllq $40, %%mm1 \n\t" /* RGB00000 2 */\
  767. "psllq $40, %%mm3 \n\t" /* RGB00000 3 */\
  768. \
  769. "punpckhdq %%mm4, %%mm0 \n\t" /* 0RGBRGB0 0 */\
  770. "punpckhdq %%mm6, %%mm2 \n\t" /* 0RGBRGB0 1 */\
  771. "punpckhdq %%mm5, %%mm1 \n\t" /* 0RGBRGB0 2 */\
  772. "punpckhdq %%mm7, %%mm3 \n\t" /* 0RGBRGB0 3 */\
  773. \
  774. "psrlq $8, %%mm0 \n\t" /* 00RGBRGB 0 */\
  775. "movq %%mm2, %%mm6 \n\t" /* 0RGBRGB0 1 */\
  776. "psllq $40, %%mm2 \n\t" /* GB000000 1 */\
  777. "por %%mm2, %%mm0 \n\t" /* GBRGBRGB 0 */\
  778. MOVNTQ(%%mm0, (dst))\
  779. \
  780. "psrlq $24, %%mm6 \n\t" /* 0000RGBR 1 */\
  781. "movq %%mm1, %%mm5 \n\t" /* 0RGBRGB0 2 */\
  782. "psllq $24, %%mm1 \n\t" /* BRGB0000 2 */\
  783. "por %%mm1, %%mm6 \n\t" /* BRGBRGBR 1 */\
  784. MOVNTQ(%%mm6, 8(dst))\
  785. \
  786. "psrlq $40, %%mm5 \n\t" /* 000000RG 2 */\
  787. "psllq $8, %%mm3 \n\t" /* RGBRGB00 3 */\
  788. "por %%mm3, %%mm5 \n\t" /* RGBRGBRG 2 */\
  789. MOVNTQ(%%mm5, 16(dst))\
  790. \
  791. "add $24, "#dst" \n\t"\
  792. \
  793. "add $8, "#index" \n\t"\
  794. "cmp "#dstw", "#index" \n\t"\
  795. " jb 1b \n\t"
  796. #define WRITEBGR24MMX2(dst, dstw, index) \
  797. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
  798. "movq "MANGLE(ff_M24A)", %%mm0 \n\t"\
  799. "movq "MANGLE(ff_M24C)", %%mm7 \n\t"\
  800. "pshufw $0x50, %%mm2, %%mm1 \n\t" /* B3 B2 B3 B2 B1 B0 B1 B0 */\
  801. "pshufw $0x50, %%mm4, %%mm3 \n\t" /* G3 G2 G3 G2 G1 G0 G1 G0 */\
  802. "pshufw $0x00, %%mm5, %%mm6 \n\t" /* R1 R0 R1 R0 R1 R0 R1 R0 */\
  803. \
  804. "pand %%mm0, %%mm1 \n\t" /* B2 B1 B0 */\
  805. "pand %%mm0, %%mm3 \n\t" /* G2 G1 G0 */\
  806. "pand %%mm7, %%mm6 \n\t" /* R1 R0 */\
  807. \
  808. "psllq $8, %%mm3 \n\t" /* G2 G1 G0 */\
  809. "por %%mm1, %%mm6 \n\t"\
  810. "por %%mm3, %%mm6 \n\t"\
  811. MOVNTQ(%%mm6, (dst))\
  812. \
  813. "psrlq $8, %%mm4 \n\t" /* 00 G7 G6 G5 G4 G3 G2 G1 */\
  814. "pshufw $0xA5, %%mm2, %%mm1 \n\t" /* B5 B4 B5 B4 B3 B2 B3 B2 */\
  815. "pshufw $0x55, %%mm4, %%mm3 \n\t" /* G4 G3 G4 G3 G4 G3 G4 G3 */\
  816. "pshufw $0xA5, %%mm5, %%mm6 \n\t" /* R5 R4 R5 R4 R3 R2 R3 R2 */\
  817. \
  818. "pand "MANGLE(ff_M24B)", %%mm1 \n\t" /* B5 B4 B3 */\
  819. "pand %%mm7, %%mm3 \n\t" /* G4 G3 */\
  820. "pand %%mm0, %%mm6 \n\t" /* R4 R3 R2 */\
  821. \
  822. "por %%mm1, %%mm3 \n\t" /* B5 G4 B4 G3 B3 */\
  823. "por %%mm3, %%mm6 \n\t"\
  824. MOVNTQ(%%mm6, 8(dst))\
  825. \
  826. "pshufw $0xFF, %%mm2, %%mm1 \n\t" /* B7 B6 B7 B6 B7 B6 B6 B7 */\
  827. "pshufw $0xFA, %%mm4, %%mm3 \n\t" /* 00 G7 00 G7 G6 G5 G6 G5 */\
  828. "pshufw $0xFA, %%mm5, %%mm6 \n\t" /* R7 R6 R7 R6 R5 R4 R5 R4 */\
  829. \
  830. "pand %%mm7, %%mm1 \n\t" /* B7 B6 */\
  831. "pand %%mm0, %%mm3 \n\t" /* G7 G6 G5 */\
  832. "pand "MANGLE(ff_M24B)", %%mm6 \n\t" /* R7 R6 R5 */\
  833. \
  834. "por %%mm1, %%mm3 \n\t"\
  835. "por %%mm3, %%mm6 \n\t"\
  836. MOVNTQ(%%mm6, 16(dst))\
  837. \
  838. "add $24, "#dst" \n\t"\
  839. \
  840. "add $8, "#index" \n\t"\
  841. "cmp "#dstw", "#index" \n\t"\
  842. " jb 1b \n\t"
  843. #if COMPILE_TEMPLATE_MMX2
  844. #undef WRITEBGR24
  845. #define WRITEBGR24(dst, dstw, index) WRITEBGR24MMX2(dst, dstw, index)
  846. #else
  847. #undef WRITEBGR24
  848. #define WRITEBGR24(dst, dstw, index) WRITEBGR24MMX(dst, dstw, index)
  849. #endif
  850. static void RENAME(yuv2bgr24_X_ar)(SwsContext *c, const int16_t *lumFilter,
  851. const int16_t **lumSrc, int lumFilterSize,
  852. const int16_t *chrFilter, const int16_t **chrUSrc,
  853. const int16_t **chrVSrc,
  854. int chrFilterSize, const int16_t **alpSrc,
  855. uint8_t *dest, int dstW, int dstY)
  856. {
  857. x86_reg dummy=0;
  858. x86_reg dstW_reg = dstW;
  859. x86_reg uv_off = c->uv_offx2;
  860. YSCALEYUV2PACKEDX_ACCURATE
  861. YSCALEYUV2RGBX
  862. "pxor %%mm7, %%mm7 \n\t"
  863. "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"\n\t" //FIXME optimize
  864. "add %4, %%"REG_c" \n\t"
  865. WRITEBGR24(%%REGc, %5, %%REGa)
  866. :: "r" (&c->redDither),
  867. "m" (dummy), "m" (dummy), "m" (dummy),
  868. "r" (dest), "m" (dstW_reg), "m"(uv_off)
  869. : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S
  870. );
  871. }
  872. static void RENAME(yuv2bgr24_X)(SwsContext *c, const int16_t *lumFilter,
  873. const int16_t **lumSrc, int lumFilterSize,
  874. const int16_t *chrFilter, const int16_t **chrUSrc,
  875. const int16_t **chrVSrc,
  876. int chrFilterSize, const int16_t **alpSrc,
  877. uint8_t *dest, int dstW, int dstY)
  878. {
  879. x86_reg dummy=0;
  880. x86_reg dstW_reg = dstW;
  881. x86_reg uv_off = c->uv_offx2;
  882. YSCALEYUV2PACKEDX
  883. YSCALEYUV2RGBX
  884. "pxor %%mm7, %%mm7 \n\t"
  885. "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c" \n\t" //FIXME optimize
  886. "add %4, %%"REG_c" \n\t"
  887. WRITEBGR24(%%REGc, %5, %%REGa)
  888. :: "r" (&c->redDither),
  889. "m" (dummy), "m" (dummy), "m" (dummy),
  890. "r" (dest), "m" (dstW_reg), "m"(uv_off)
  891. : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S
  892. );
  893. }
  894. #define REAL_WRITEYUY2(dst, dstw, index) \
  895. "packuswb %%mm3, %%mm3 \n\t"\
  896. "packuswb %%mm4, %%mm4 \n\t"\
  897. "packuswb %%mm7, %%mm1 \n\t"\
  898. "punpcklbw %%mm4, %%mm3 \n\t"\
  899. "movq %%mm1, %%mm7 \n\t"\
  900. "punpcklbw %%mm3, %%mm1 \n\t"\
  901. "punpckhbw %%mm3, %%mm7 \n\t"\
  902. \
  903. MOVNTQ(%%mm1, (dst, index, 2))\
  904. MOVNTQ(%%mm7, 8(dst, index, 2))\
  905. \
  906. "add $8, "#index" \n\t"\
  907. "cmp "#dstw", "#index" \n\t"\
  908. " jb 1b \n\t"
  909. #define WRITEYUY2(dst, dstw, index) REAL_WRITEYUY2(dst, dstw, index)
  910. static void RENAME(yuv2yuyv422_X_ar)(SwsContext *c, const int16_t *lumFilter,
  911. const int16_t **lumSrc, int lumFilterSize,
  912. const int16_t *chrFilter, const int16_t **chrUSrc,
  913. const int16_t **chrVSrc,
  914. int chrFilterSize, const int16_t **alpSrc,
  915. uint8_t *dest, int dstW, int dstY)
  916. {
  917. x86_reg dummy=0;
  918. x86_reg dstW_reg = dstW;
  919. x86_reg uv_off = c->uv_offx2;
  920. YSCALEYUV2PACKEDX_ACCURATE
  921. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  922. "psraw $3, %%mm3 \n\t"
  923. "psraw $3, %%mm4 \n\t"
  924. "psraw $3, %%mm1 \n\t"
  925. "psraw $3, %%mm7 \n\t"
  926. WRITEYUY2(%4, %5, %%REGa)
  927. YSCALEYUV2PACKEDX_END
  928. }
  929. static void RENAME(yuv2yuyv422_X)(SwsContext *c, const int16_t *lumFilter,
  930. const int16_t **lumSrc, int lumFilterSize,
  931. const int16_t *chrFilter, const int16_t **chrUSrc,
  932. const int16_t **chrVSrc,
  933. int chrFilterSize, const int16_t **alpSrc,
  934. uint8_t *dest, int dstW, int dstY)
  935. {
  936. x86_reg dummy=0;
  937. x86_reg dstW_reg = dstW;
  938. x86_reg uv_off = c->uv_offx2;
  939. YSCALEYUV2PACKEDX
  940. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  941. "psraw $3, %%mm3 \n\t"
  942. "psraw $3, %%mm4 \n\t"
  943. "psraw $3, %%mm1 \n\t"
  944. "psraw $3, %%mm7 \n\t"
  945. WRITEYUY2(%4, %5, %%REGa)
  946. YSCALEYUV2PACKEDX_END
  947. }
  948. #define REAL_YSCALEYUV2RGB_UV(index, c) \
  949. "xor "#index", "#index" \n\t"\
  950. ".p2align 4 \n\t"\
  951. "1: \n\t"\
  952. "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
  953. "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
  954. "add "UV_OFFx2"("#c"), "#index" \n\t" \
  955. "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  956. "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  957. "sub "UV_OFFx2"("#c"), "#index" \n\t" \
  958. "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
  959. "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
  960. "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\
  961. "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
  962. "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
  963. "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  964. "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  965. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
  966. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
  967. "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\
  968. "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\
  969. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  970. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  971. "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\
  972. "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\
  973. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  974. #define REAL_YSCALEYUV2RGB_YA(index, c, b1, b2) \
  975. "movq ("#b1", "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\
  976. "movq ("#b2", "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\
  977. "movq 8("#b1", "#index", 2), %%mm6 \n\t" /*buf0[eax]*/\
  978. "movq 8("#b2", "#index", 2), %%mm7 \n\t" /*buf1[eax]*/\
  979. "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
  980. "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\
  981. "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  982. "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  983. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  984. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  985. "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  986. "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  987. #define REAL_YSCALEYUV2RGB_COEFF(c) \
  988. "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\
  989. "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\
  990. "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\
  991. "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\
  992. "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\
  993. "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\
  994. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  995. "paddw %%mm3, %%mm4 \n\t"\
  996. "movq %%mm2, %%mm0 \n\t"\
  997. "movq %%mm5, %%mm6 \n\t"\
  998. "movq %%mm4, %%mm3 \n\t"\
  999. "punpcklwd %%mm2, %%mm2 \n\t"\
  1000. "punpcklwd %%mm5, %%mm5 \n\t"\
  1001. "punpcklwd %%mm4, %%mm4 \n\t"\
  1002. "paddw %%mm1, %%mm2 \n\t"\
  1003. "paddw %%mm1, %%mm5 \n\t"\
  1004. "paddw %%mm1, %%mm4 \n\t"\
  1005. "punpckhwd %%mm0, %%mm0 \n\t"\
  1006. "punpckhwd %%mm6, %%mm6 \n\t"\
  1007. "punpckhwd %%mm3, %%mm3 \n\t"\
  1008. "paddw %%mm7, %%mm0 \n\t"\
  1009. "paddw %%mm7, %%mm6 \n\t"\
  1010. "paddw %%mm7, %%mm3 \n\t"\
  1011. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  1012. "packuswb %%mm0, %%mm2 \n\t"\
  1013. "packuswb %%mm6, %%mm5 \n\t"\
  1014. "packuswb %%mm3, %%mm4 \n\t"\
  1015. #define YSCALEYUV2RGB_YA(index, c, b1, b2) REAL_YSCALEYUV2RGB_YA(index, c, b1, b2)
  1016. #define YSCALEYUV2RGB(index, c) \
  1017. REAL_YSCALEYUV2RGB_UV(index, c) \
  1018. REAL_YSCALEYUV2RGB_YA(index, c, %0, %1) \
  1019. REAL_YSCALEYUV2RGB_COEFF(c)
  1020. /**
  1021. * vertical bilinear scale YV12 to RGB
  1022. */
  1023. static void RENAME(yuv2rgb32_2)(SwsContext *c, const int16_t *buf[2],
  1024. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1025. const int16_t *abuf[2], uint8_t *dest,
  1026. int dstW, int yalpha, int uvalpha, int y)
  1027. {
  1028. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1029. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  1030. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  1031. const int16_t *abuf0 = abuf[0], *abuf1 = abuf[1];
  1032. #if ARCH_X86_64
  1033. __asm__ volatile(
  1034. YSCALEYUV2RGB(%%r8, %5)
  1035. YSCALEYUV2RGB_YA(%%r8, %5, %6, %7)
  1036. "psraw $3, %%mm1 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
  1037. "psraw $3, %%mm7 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
  1038. "packuswb %%mm7, %%mm1 \n\t"
  1039. WRITEBGR32(%4, 8280(%5), %%r8, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6)
  1040. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "r" (dest),
  1041. "a" (&c->redDither),
  1042. "r" (abuf0), "r" (abuf1)
  1043. : "%r8"
  1044. );
  1045. #else
  1046. c->u_temp=(intptr_t)abuf0;
  1047. c->v_temp=(intptr_t)abuf1;
  1048. __asm__ volatile(
  1049. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1050. "mov %4, %%"REG_b" \n\t"
  1051. "push %%"REG_BP" \n\t"
  1052. YSCALEYUV2RGB(%%REGBP, %5)
  1053. "push %0 \n\t"
  1054. "push %1 \n\t"
  1055. "mov "U_TEMP"(%5), %0 \n\t"
  1056. "mov "V_TEMP"(%5), %1 \n\t"
  1057. YSCALEYUV2RGB_YA(%%REGBP, %5, %0, %1)
  1058. "psraw $3, %%mm1 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
  1059. "psraw $3, %%mm7 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
  1060. "packuswb %%mm7, %%mm1 \n\t"
  1061. "pop %1 \n\t"
  1062. "pop %0 \n\t"
  1063. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6)
  1064. "pop %%"REG_BP" \n\t"
  1065. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1066. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1067. "a" (&c->redDither)
  1068. );
  1069. #endif
  1070. } else {
  1071. __asm__ volatile(
  1072. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1073. "mov %4, %%"REG_b" \n\t"
  1074. "push %%"REG_BP" \n\t"
  1075. YSCALEYUV2RGB(%%REGBP, %5)
  1076. "pcmpeqd %%mm7, %%mm7 \n\t"
  1077. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  1078. "pop %%"REG_BP" \n\t"
  1079. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1080. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1081. "a" (&c->redDither)
  1082. );
  1083. }
  1084. }
  1085. static void RENAME(yuv2bgr24_2)(SwsContext *c, const int16_t *buf[2],
  1086. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1087. const int16_t *abuf[2], uint8_t *dest,
  1088. int dstW, int yalpha, int uvalpha, int y)
  1089. {
  1090. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1091. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  1092. //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
  1093. __asm__ volatile(
  1094. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1095. "mov %4, %%"REG_b" \n\t"
  1096. "push %%"REG_BP" \n\t"
  1097. YSCALEYUV2RGB(%%REGBP, %5)
  1098. "pxor %%mm7, %%mm7 \n\t"
  1099. WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
  1100. "pop %%"REG_BP" \n\t"
  1101. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1102. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1103. "a" (&c->redDither)
  1104. );
  1105. }
  1106. static void RENAME(yuv2rgb555_2)(SwsContext *c, const int16_t *buf[2],
  1107. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1108. const int16_t *abuf[2], uint8_t *dest,
  1109. int dstW, int yalpha, int uvalpha, int y)
  1110. {
  1111. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1112. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  1113. //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
  1114. __asm__ volatile(
  1115. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1116. "mov %4, %%"REG_b" \n\t"
  1117. "push %%"REG_BP" \n\t"
  1118. YSCALEYUV2RGB(%%REGBP, %5)
  1119. "pxor %%mm7, %%mm7 \n\t"
  1120. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1121. #ifdef DITHER1XBPP
  1122. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1123. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1124. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1125. #endif
  1126. WRITERGB15(%%REGb, 8280(%5), %%REGBP)
  1127. "pop %%"REG_BP" \n\t"
  1128. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1129. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1130. "a" (&c->redDither)
  1131. );
  1132. }
  1133. static void RENAME(yuv2rgb565_2)(SwsContext *c, const int16_t *buf[2],
  1134. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1135. const int16_t *abuf[2], uint8_t *dest,
  1136. int dstW, int yalpha, int uvalpha, int y)
  1137. {
  1138. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1139. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  1140. //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
  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. YSCALEYUV2RGB(%%REGBP, %5)
  1146. "pxor %%mm7, %%mm7 \n\t"
  1147. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1148. #ifdef DITHER1XBPP
  1149. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1150. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1151. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1152. #endif
  1153. WRITERGB16(%%REGb, 8280(%5), %%REGBP)
  1154. "pop %%"REG_BP" \n\t"
  1155. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1156. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1157. "a" (&c->redDither)
  1158. );
  1159. }
  1160. #define REAL_YSCALEYUV2PACKED(index, c) \
  1161. "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\
  1162. "movq "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm1 \n\t"\
  1163. "psraw $3, %%mm0 \n\t"\
  1164. "psraw $3, %%mm1 \n\t"\
  1165. "movq %%mm0, "CHR_MMX_FILTER_OFFSET"+8("#c") \n\t"\
  1166. "movq %%mm1, "LUM_MMX_FILTER_OFFSET"+8("#c") \n\t"\
  1167. "xor "#index", "#index" \n\t"\
  1168. ".p2align 4 \n\t"\
  1169. "1: \n\t"\
  1170. "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
  1171. "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
  1172. "add "UV_OFFx2"("#c"), "#index" \n\t" \
  1173. "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  1174. "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  1175. "sub "UV_OFFx2"("#c"), "#index" \n\t" \
  1176. "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
  1177. "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
  1178. "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\
  1179. "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
  1180. "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
  1181. "psraw $7, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  1182. "psraw $7, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  1183. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
  1184. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
  1185. "movq (%0, "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\
  1186. "movq (%1, "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\
  1187. "movq 8(%0, "#index", 2), %%mm6 \n\t" /*buf0[eax]*/\
  1188. "movq 8(%1, "#index", 2), %%mm7 \n\t" /*buf1[eax]*/\
  1189. "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
  1190. "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\
  1191. "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  1192. "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  1193. "psraw $7, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1194. "psraw $7, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1195. "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  1196. "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  1197. #define YSCALEYUV2PACKED(index, c) REAL_YSCALEYUV2PACKED(index, c)
  1198. static void RENAME(yuv2yuyv422_2)(SwsContext *c, const int16_t *buf[2],
  1199. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1200. const int16_t *abuf[2], uint8_t *dest,
  1201. int dstW, int yalpha, int uvalpha, int y)
  1202. {
  1203. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1204. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  1205. //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
  1206. __asm__ volatile(
  1207. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1208. "mov %4, %%"REG_b" \n\t"
  1209. "push %%"REG_BP" \n\t"
  1210. YSCALEYUV2PACKED(%%REGBP, %5)
  1211. WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
  1212. "pop %%"REG_BP" \n\t"
  1213. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1214. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1215. "a" (&c->redDither)
  1216. );
  1217. }
  1218. #define REAL_YSCALEYUV2RGB1(index, c) \
  1219. "xor "#index", "#index" \n\t"\
  1220. ".p2align 4 \n\t"\
  1221. "1: \n\t"\
  1222. "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\
  1223. "add "UV_OFFx2"("#c"), "#index" \n\t" \
  1224. "movq (%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
  1225. "sub "UV_OFFx2"("#c"), "#index" \n\t" \
  1226. "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  1227. "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  1228. "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\
  1229. "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\
  1230. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  1231. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  1232. "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\
  1233. "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\
  1234. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  1235. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1236. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1237. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1238. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1239. "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\
  1240. "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\
  1241. "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\
  1242. "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\
  1243. "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\
  1244. "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\
  1245. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  1246. "paddw %%mm3, %%mm4 \n\t"\
  1247. "movq %%mm2, %%mm0 \n\t"\
  1248. "movq %%mm5, %%mm6 \n\t"\
  1249. "movq %%mm4, %%mm3 \n\t"\
  1250. "punpcklwd %%mm2, %%mm2 \n\t"\
  1251. "punpcklwd %%mm5, %%mm5 \n\t"\
  1252. "punpcklwd %%mm4, %%mm4 \n\t"\
  1253. "paddw %%mm1, %%mm2 \n\t"\
  1254. "paddw %%mm1, %%mm5 \n\t"\
  1255. "paddw %%mm1, %%mm4 \n\t"\
  1256. "punpckhwd %%mm0, %%mm0 \n\t"\
  1257. "punpckhwd %%mm6, %%mm6 \n\t"\
  1258. "punpckhwd %%mm3, %%mm3 \n\t"\
  1259. "paddw %%mm7, %%mm0 \n\t"\
  1260. "paddw %%mm7, %%mm6 \n\t"\
  1261. "paddw %%mm7, %%mm3 \n\t"\
  1262. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  1263. "packuswb %%mm0, %%mm2 \n\t"\
  1264. "packuswb %%mm6, %%mm5 \n\t"\
  1265. "packuswb %%mm3, %%mm4 \n\t"\
  1266. #define YSCALEYUV2RGB1(index, c) REAL_YSCALEYUV2RGB1(index, c)
  1267. // do vertical chrominance interpolation
  1268. #define REAL_YSCALEYUV2RGB1b(index, c) \
  1269. "xor "#index", "#index" \n\t"\
  1270. ".p2align 4 \n\t"\
  1271. "1: \n\t"\
  1272. "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
  1273. "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
  1274. "add "UV_OFFx2"("#c"), "#index" \n\t" \
  1275. "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  1276. "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  1277. "sub "UV_OFFx2"("#c"), "#index" \n\t" \
  1278. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
  1279. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
  1280. "psrlw $5, %%mm3 \n\t" /*FIXME might overflow*/\
  1281. "psrlw $5, %%mm4 \n\t" /*FIXME might overflow*/\
  1282. "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\
  1283. "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\
  1284. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  1285. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  1286. "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\
  1287. "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\
  1288. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  1289. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1290. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1291. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1292. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1293. "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\
  1294. "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\
  1295. "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\
  1296. "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\
  1297. "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\
  1298. "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\
  1299. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  1300. "paddw %%mm3, %%mm4 \n\t"\
  1301. "movq %%mm2, %%mm0 \n\t"\
  1302. "movq %%mm5, %%mm6 \n\t"\
  1303. "movq %%mm4, %%mm3 \n\t"\
  1304. "punpcklwd %%mm2, %%mm2 \n\t"\
  1305. "punpcklwd %%mm5, %%mm5 \n\t"\
  1306. "punpcklwd %%mm4, %%mm4 \n\t"\
  1307. "paddw %%mm1, %%mm2 \n\t"\
  1308. "paddw %%mm1, %%mm5 \n\t"\
  1309. "paddw %%mm1, %%mm4 \n\t"\
  1310. "punpckhwd %%mm0, %%mm0 \n\t"\
  1311. "punpckhwd %%mm6, %%mm6 \n\t"\
  1312. "punpckhwd %%mm3, %%mm3 \n\t"\
  1313. "paddw %%mm7, %%mm0 \n\t"\
  1314. "paddw %%mm7, %%mm6 \n\t"\
  1315. "paddw %%mm7, %%mm3 \n\t"\
  1316. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  1317. "packuswb %%mm0, %%mm2 \n\t"\
  1318. "packuswb %%mm6, %%mm5 \n\t"\
  1319. "packuswb %%mm3, %%mm4 \n\t"\
  1320. #define YSCALEYUV2RGB1b(index, c) REAL_YSCALEYUV2RGB1b(index, c)
  1321. #define REAL_YSCALEYUV2RGB1_ALPHA(index) \
  1322. "movq (%1, "#index", 2), %%mm7 \n\t" /* abuf0[index ] */\
  1323. "movq 8(%1, "#index", 2), %%mm1 \n\t" /* abuf0[index+4] */\
  1324. "psraw $7, %%mm7 \n\t" /* abuf0[index ] >>7 */\
  1325. "psraw $7, %%mm1 \n\t" /* abuf0[index+4] >>7 */\
  1326. "packuswb %%mm1, %%mm7 \n\t"
  1327. #define YSCALEYUV2RGB1_ALPHA(index) REAL_YSCALEYUV2RGB1_ALPHA(index)
  1328. /**
  1329. * YV12 to RGB without scaling or interpolating
  1330. */
  1331. static void RENAME(yuv2rgb32_1)(SwsContext *c, const int16_t *buf0,
  1332. const int16_t *ubuf[2], const int16_t *bguf[2],
  1333. const int16_t *abuf0, uint8_t *dest,
  1334. int dstW, int uvalpha, int y)
  1335. {
  1336. const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  1337. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1338. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1339. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  1340. __asm__ volatile(
  1341. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1342. "mov %4, %%"REG_b" \n\t"
  1343. "push %%"REG_BP" \n\t"
  1344. YSCALEYUV2RGB1(%%REGBP, %5)
  1345. YSCALEYUV2RGB1_ALPHA(%%REGBP)
  1346. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  1347. "pop %%"REG_BP" \n\t"
  1348. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1349. :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1350. "a" (&c->redDither)
  1351. );
  1352. } else {
  1353. __asm__ volatile(
  1354. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1355. "mov %4, %%"REG_b" \n\t"
  1356. "push %%"REG_BP" \n\t"
  1357. YSCALEYUV2RGB1(%%REGBP, %5)
  1358. "pcmpeqd %%mm7, %%mm7 \n\t"
  1359. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  1360. "pop %%"REG_BP" \n\t"
  1361. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1362. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1363. "a" (&c->redDither)
  1364. );
  1365. }
  1366. } else {
  1367. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  1368. __asm__ volatile(
  1369. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1370. "mov %4, %%"REG_b" \n\t"
  1371. "push %%"REG_BP" \n\t"
  1372. YSCALEYUV2RGB1b(%%REGBP, %5)
  1373. YSCALEYUV2RGB1_ALPHA(%%REGBP)
  1374. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  1375. "pop %%"REG_BP" \n\t"
  1376. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1377. :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1378. "a" (&c->redDither)
  1379. );
  1380. } else {
  1381. __asm__ volatile(
  1382. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1383. "mov %4, %%"REG_b" \n\t"
  1384. "push %%"REG_BP" \n\t"
  1385. YSCALEYUV2RGB1b(%%REGBP, %5)
  1386. "pcmpeqd %%mm7, %%mm7 \n\t"
  1387. WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  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. }
  1396. static void RENAME(yuv2bgr24_1)(SwsContext *c, const int16_t *buf0,
  1397. const int16_t *ubuf[2], const int16_t *bguf[2],
  1398. const int16_t *abuf0, uint8_t *dest,
  1399. int dstW, int uvalpha, int y)
  1400. {
  1401. const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  1402. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1403. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1404. __asm__ volatile(
  1405. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1406. "mov %4, %%"REG_b" \n\t"
  1407. "push %%"REG_BP" \n\t"
  1408. YSCALEYUV2RGB1(%%REGBP, %5)
  1409. "pxor %%mm7, %%mm7 \n\t"
  1410. WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
  1411. "pop %%"REG_BP" \n\t"
  1412. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1413. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1414. "a" (&c->redDither)
  1415. );
  1416. } else {
  1417. __asm__ volatile(
  1418. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1419. "mov %4, %%"REG_b" \n\t"
  1420. "push %%"REG_BP" \n\t"
  1421. YSCALEYUV2RGB1b(%%REGBP, %5)
  1422. "pxor %%mm7, %%mm7 \n\t"
  1423. WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
  1424. "pop %%"REG_BP" \n\t"
  1425. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1426. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1427. "a" (&c->redDither)
  1428. );
  1429. }
  1430. }
  1431. static void RENAME(yuv2rgb555_1)(SwsContext *c, const int16_t *buf0,
  1432. const int16_t *ubuf[2], const int16_t *bguf[2],
  1433. const int16_t *abuf0, uint8_t *dest,
  1434. int dstW, int uvalpha, int y)
  1435. {
  1436. const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  1437. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1438. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1439. __asm__ volatile(
  1440. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1441. "mov %4, %%"REG_b" \n\t"
  1442. "push %%"REG_BP" \n\t"
  1443. YSCALEYUV2RGB1(%%REGBP, %5)
  1444. "pxor %%mm7, %%mm7 \n\t"
  1445. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1446. #ifdef DITHER1XBPP
  1447. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1448. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1449. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1450. #endif
  1451. WRITERGB15(%%REGb, 8280(%5), %%REGBP)
  1452. "pop %%"REG_BP" \n\t"
  1453. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1454. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1455. "a" (&c->redDither)
  1456. );
  1457. } else {
  1458. __asm__ volatile(
  1459. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1460. "mov %4, %%"REG_b" \n\t"
  1461. "push %%"REG_BP" \n\t"
  1462. YSCALEYUV2RGB1b(%%REGBP, %5)
  1463. "pxor %%mm7, %%mm7 \n\t"
  1464. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1465. #ifdef DITHER1XBPP
  1466. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1467. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1468. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1469. #endif
  1470. WRITERGB15(%%REGb, 8280(%5), %%REGBP)
  1471. "pop %%"REG_BP" \n\t"
  1472. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1473. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1474. "a" (&c->redDither)
  1475. );
  1476. }
  1477. }
  1478. static void RENAME(yuv2rgb565_1)(SwsContext *c, const int16_t *buf0,
  1479. const int16_t *ubuf[2], const int16_t *bguf[2],
  1480. const int16_t *abuf0, uint8_t *dest,
  1481. int dstW, int uvalpha, int y)
  1482. {
  1483. const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  1484. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1485. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1486. __asm__ volatile(
  1487. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1488. "mov %4, %%"REG_b" \n\t"
  1489. "push %%"REG_BP" \n\t"
  1490. YSCALEYUV2RGB1(%%REGBP, %5)
  1491. "pxor %%mm7, %%mm7 \n\t"
  1492. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1493. #ifdef DITHER1XBPP
  1494. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1495. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1496. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1497. #endif
  1498. WRITERGB16(%%REGb, 8280(%5), %%REGBP)
  1499. "pop %%"REG_BP" \n\t"
  1500. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1501. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1502. "a" (&c->redDither)
  1503. );
  1504. } else {
  1505. __asm__ volatile(
  1506. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1507. "mov %4, %%"REG_b" \n\t"
  1508. "push %%"REG_BP" \n\t"
  1509. YSCALEYUV2RGB1b(%%REGBP, %5)
  1510. "pxor %%mm7, %%mm7 \n\t"
  1511. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1512. #ifdef DITHER1XBPP
  1513. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1514. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1515. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1516. #endif
  1517. WRITERGB16(%%REGb, 8280(%5), %%REGBP)
  1518. "pop %%"REG_BP" \n\t"
  1519. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1520. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1521. "a" (&c->redDither)
  1522. );
  1523. }
  1524. }
  1525. #define REAL_YSCALEYUV2PACKED1(index, c) \
  1526. "xor "#index", "#index" \n\t"\
  1527. ".p2align 4 \n\t"\
  1528. "1: \n\t"\
  1529. "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\
  1530. "add "UV_OFFx2"("#c"), "#index" \n\t" \
  1531. "movq (%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
  1532. "sub "UV_OFFx2"("#c"), "#index" \n\t" \
  1533. "psraw $7, %%mm3 \n\t" \
  1534. "psraw $7, %%mm4 \n\t" \
  1535. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1536. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1537. "psraw $7, %%mm1 \n\t" \
  1538. "psraw $7, %%mm7 \n\t" \
  1539. #define YSCALEYUV2PACKED1(index, c) REAL_YSCALEYUV2PACKED1(index, c)
  1540. #define REAL_YSCALEYUV2PACKED1b(index, c) \
  1541. "xor "#index", "#index" \n\t"\
  1542. ".p2align 4 \n\t"\
  1543. "1: \n\t"\
  1544. "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
  1545. "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
  1546. "add "UV_OFFx2"("#c"), "#index" \n\t" \
  1547. "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  1548. "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  1549. "sub "UV_OFFx2"("#c"), "#index" \n\t" \
  1550. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
  1551. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
  1552. "psrlw $8, %%mm3 \n\t" \
  1553. "psrlw $8, %%mm4 \n\t" \
  1554. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1555. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1556. "psraw $7, %%mm1 \n\t" \
  1557. "psraw $7, %%mm7 \n\t"
  1558. #define YSCALEYUV2PACKED1b(index, c) REAL_YSCALEYUV2PACKED1b(index, c)
  1559. static void RENAME(yuv2yuyv422_1)(SwsContext *c, const int16_t *buf0,
  1560. const int16_t *ubuf[2], const int16_t *bguf[2],
  1561. const int16_t *abuf0, uint8_t *dest,
  1562. int dstW, int uvalpha, int y)
  1563. {
  1564. const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  1565. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1566. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1567. __asm__ volatile(
  1568. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1569. "mov %4, %%"REG_b" \n\t"
  1570. "push %%"REG_BP" \n\t"
  1571. YSCALEYUV2PACKED1(%%REGBP, %5)
  1572. WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
  1573. "pop %%"REG_BP" \n\t"
  1574. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1575. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1576. "a" (&c->redDither)
  1577. );
  1578. } else {
  1579. __asm__ volatile(
  1580. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1581. "mov %4, %%"REG_b" \n\t"
  1582. "push %%"REG_BP" \n\t"
  1583. YSCALEYUV2PACKED1b(%%REGBP, %5)
  1584. WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
  1585. "pop %%"REG_BP" \n\t"
  1586. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1587. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1588. "a" (&c->redDither)
  1589. );
  1590. }
  1591. }
  1592. #if !COMPILE_TEMPLATE_MMX2
  1593. //FIXME yuy2* can read up to 7 samples too much
  1594. static void RENAME(yuy2ToY)(uint8_t *dst, const uint8_t *src,
  1595. int width, uint32_t *unused)
  1596. {
  1597. __asm__ volatile(
  1598. "movq "MANGLE(bm01010101)", %%mm2 \n\t"
  1599. "mov %0, %%"REG_a" \n\t"
  1600. "1: \n\t"
  1601. "movq (%1, %%"REG_a",2), %%mm0 \n\t"
  1602. "movq 8(%1, %%"REG_a",2), %%mm1 \n\t"
  1603. "pand %%mm2, %%mm0 \n\t"
  1604. "pand %%mm2, %%mm1 \n\t"
  1605. "packuswb %%mm1, %%mm0 \n\t"
  1606. "movq %%mm0, (%2, %%"REG_a") \n\t"
  1607. "add $8, %%"REG_a" \n\t"
  1608. " js 1b \n\t"
  1609. : : "g" ((x86_reg)-width), "r" (src+width*2), "r" (dst+width)
  1610. : "%"REG_a
  1611. );
  1612. }
  1613. static void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV,
  1614. const uint8_t *src1, const uint8_t *src2,
  1615. int width, uint32_t *unused)
  1616. {
  1617. __asm__ volatile(
  1618. "movq "MANGLE(bm01010101)", %%mm4 \n\t"
  1619. "mov %0, %%"REG_a" \n\t"
  1620. "1: \n\t"
  1621. "movq (%1, %%"REG_a",4), %%mm0 \n\t"
  1622. "movq 8(%1, %%"REG_a",4), %%mm1 \n\t"
  1623. "psrlw $8, %%mm0 \n\t"
  1624. "psrlw $8, %%mm1 \n\t"
  1625. "packuswb %%mm1, %%mm0 \n\t"
  1626. "movq %%mm0, %%mm1 \n\t"
  1627. "psrlw $8, %%mm0 \n\t"
  1628. "pand %%mm4, %%mm1 \n\t"
  1629. "packuswb %%mm0, %%mm0 \n\t"
  1630. "packuswb %%mm1, %%mm1 \n\t"
  1631. "movd %%mm0, (%3, %%"REG_a") \n\t"
  1632. "movd %%mm1, (%2, %%"REG_a") \n\t"
  1633. "add $4, %%"REG_a" \n\t"
  1634. " js 1b \n\t"
  1635. : : "g" ((x86_reg)-width), "r" (src1+width*4), "r" (dstU+width), "r" (dstV+width)
  1636. : "%"REG_a
  1637. );
  1638. assert(src1 == src2);
  1639. }
  1640. /* This is almost identical to the previous, end exists only because
  1641. * yuy2ToY/UV)(dst, src+1, ...) would have 100% unaligned accesses. */
  1642. static void RENAME(uyvyToY)(uint8_t *dst, const uint8_t *src,
  1643. int width, uint32_t *unused)
  1644. {
  1645. __asm__ volatile(
  1646. "mov %0, %%"REG_a" \n\t"
  1647. "1: \n\t"
  1648. "movq (%1, %%"REG_a",2), %%mm0 \n\t"
  1649. "movq 8(%1, %%"REG_a",2), %%mm1 \n\t"
  1650. "psrlw $8, %%mm0 \n\t"
  1651. "psrlw $8, %%mm1 \n\t"
  1652. "packuswb %%mm1, %%mm0 \n\t"
  1653. "movq %%mm0, (%2, %%"REG_a") \n\t"
  1654. "add $8, %%"REG_a" \n\t"
  1655. " js 1b \n\t"
  1656. : : "g" ((x86_reg)-width), "r" (src+width*2), "r" (dst+width)
  1657. : "%"REG_a
  1658. );
  1659. }
  1660. static void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV,
  1661. const uint8_t *src1, const uint8_t *src2,
  1662. int width, uint32_t *unused)
  1663. {
  1664. __asm__ volatile(
  1665. "movq "MANGLE(bm01010101)", %%mm4 \n\t"
  1666. "mov %0, %%"REG_a" \n\t"
  1667. "1: \n\t"
  1668. "movq (%1, %%"REG_a",4), %%mm0 \n\t"
  1669. "movq 8(%1, %%"REG_a",4), %%mm1 \n\t"
  1670. "pand %%mm4, %%mm0 \n\t"
  1671. "pand %%mm4, %%mm1 \n\t"
  1672. "packuswb %%mm1, %%mm0 \n\t"
  1673. "movq %%mm0, %%mm1 \n\t"
  1674. "psrlw $8, %%mm0 \n\t"
  1675. "pand %%mm4, %%mm1 \n\t"
  1676. "packuswb %%mm0, %%mm0 \n\t"
  1677. "packuswb %%mm1, %%mm1 \n\t"
  1678. "movd %%mm0, (%3, %%"REG_a") \n\t"
  1679. "movd %%mm1, (%2, %%"REG_a") \n\t"
  1680. "add $4, %%"REG_a" \n\t"
  1681. " js 1b \n\t"
  1682. : : "g" ((x86_reg)-width), "r" (src1+width*4), "r" (dstU+width), "r" (dstV+width)
  1683. : "%"REG_a
  1684. );
  1685. assert(src1 == src2);
  1686. }
  1687. static av_always_inline void RENAME(nvXXtoUV)(uint8_t *dst1, uint8_t *dst2,
  1688. const uint8_t *src, int width)
  1689. {
  1690. __asm__ volatile(
  1691. "movq "MANGLE(bm01010101)", %%mm4 \n\t"
  1692. "mov %0, %%"REG_a" \n\t"
  1693. "1: \n\t"
  1694. "movq (%1, %%"REG_a",2), %%mm0 \n\t"
  1695. "movq 8(%1, %%"REG_a",2), %%mm1 \n\t"
  1696. "movq %%mm0, %%mm2 \n\t"
  1697. "movq %%mm1, %%mm3 \n\t"
  1698. "pand %%mm4, %%mm0 \n\t"
  1699. "pand %%mm4, %%mm1 \n\t"
  1700. "psrlw $8, %%mm2 \n\t"
  1701. "psrlw $8, %%mm3 \n\t"
  1702. "packuswb %%mm1, %%mm0 \n\t"
  1703. "packuswb %%mm3, %%mm2 \n\t"
  1704. "movq %%mm0, (%2, %%"REG_a") \n\t"
  1705. "movq %%mm2, (%3, %%"REG_a") \n\t"
  1706. "add $8, %%"REG_a" \n\t"
  1707. " js 1b \n\t"
  1708. : : "g" ((x86_reg)-width), "r" (src+width*2), "r" (dst1+width), "r" (dst2+width)
  1709. : "%"REG_a
  1710. );
  1711. }
  1712. static void RENAME(nv12ToUV)(uint8_t *dstU, uint8_t *dstV,
  1713. const uint8_t *src1, const uint8_t *src2,
  1714. int width, uint32_t *unused)
  1715. {
  1716. RENAME(nvXXtoUV)(dstU, dstV, src1, width);
  1717. }
  1718. static void RENAME(nv21ToUV)(uint8_t *dstU, uint8_t *dstV,
  1719. const uint8_t *src1, const uint8_t *src2,
  1720. int width, uint32_t *unused)
  1721. {
  1722. RENAME(nvXXtoUV)(dstV, dstU, src1, width);
  1723. }
  1724. #endif /* !COMPILE_TEMPLATE_MMX2 */
  1725. static av_always_inline void RENAME(bgr24ToY_mmx)(int16_t *dst, const uint8_t *src,
  1726. int width, enum PixelFormat srcFormat)
  1727. {
  1728. if(srcFormat == PIX_FMT_BGR24) {
  1729. __asm__ volatile(
  1730. "movq "MANGLE(ff_bgr24toY1Coeff)", %%mm5 \n\t"
  1731. "movq "MANGLE(ff_bgr24toY2Coeff)", %%mm6 \n\t"
  1732. :
  1733. );
  1734. } else {
  1735. __asm__ volatile(
  1736. "movq "MANGLE(ff_rgb24toY1Coeff)", %%mm5 \n\t"
  1737. "movq "MANGLE(ff_rgb24toY2Coeff)", %%mm6 \n\t"
  1738. :
  1739. );
  1740. }
  1741. __asm__ volatile(
  1742. "movq "MANGLE(ff_bgr24toYOffset)", %%mm4 \n\t"
  1743. "mov %2, %%"REG_a" \n\t"
  1744. "pxor %%mm7, %%mm7 \n\t"
  1745. "1: \n\t"
  1746. PREFETCH" 64(%0) \n\t"
  1747. "movd (%0), %%mm0 \n\t"
  1748. "movd 2(%0), %%mm1 \n\t"
  1749. "movd 6(%0), %%mm2 \n\t"
  1750. "movd 8(%0), %%mm3 \n\t"
  1751. "add $12, %0 \n\t"
  1752. "punpcklbw %%mm7, %%mm0 \n\t"
  1753. "punpcklbw %%mm7, %%mm1 \n\t"
  1754. "punpcklbw %%mm7, %%mm2 \n\t"
  1755. "punpcklbw %%mm7, %%mm3 \n\t"
  1756. "pmaddwd %%mm5, %%mm0 \n\t"
  1757. "pmaddwd %%mm6, %%mm1 \n\t"
  1758. "pmaddwd %%mm5, %%mm2 \n\t"
  1759. "pmaddwd %%mm6, %%mm3 \n\t"
  1760. "paddd %%mm1, %%mm0 \n\t"
  1761. "paddd %%mm3, %%mm2 \n\t"
  1762. "paddd %%mm4, %%mm0 \n\t"
  1763. "paddd %%mm4, %%mm2 \n\t"
  1764. "psrad $9, %%mm0 \n\t"
  1765. "psrad $9, %%mm2 \n\t"
  1766. "packssdw %%mm2, %%mm0 \n\t"
  1767. "movq %%mm0, (%1, %%"REG_a") \n\t"
  1768. "add $8, %%"REG_a" \n\t"
  1769. " js 1b \n\t"
  1770. : "+r" (src)
  1771. : "r" (dst+width), "g" ((x86_reg)-2*width)
  1772. : "%"REG_a
  1773. );
  1774. }
  1775. static void RENAME(bgr24ToY)(int16_t *dst, const uint8_t *src,
  1776. int width, uint32_t *unused)
  1777. {
  1778. RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_BGR24);
  1779. }
  1780. static void RENAME(rgb24ToY)(int16_t *dst, const uint8_t *src,
  1781. int width, uint32_t *unused)
  1782. {
  1783. RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_RGB24);
  1784. }
  1785. static av_always_inline void RENAME(bgr24ToUV_mmx)(int16_t *dstU, int16_t *dstV,
  1786. const uint8_t *src, int width,
  1787. enum PixelFormat srcFormat)
  1788. {
  1789. __asm__ volatile(
  1790. "movq 24(%4), %%mm6 \n\t"
  1791. "mov %3, %%"REG_a" \n\t"
  1792. "pxor %%mm7, %%mm7 \n\t"
  1793. "1: \n\t"
  1794. PREFETCH" 64(%0) \n\t"
  1795. "movd (%0), %%mm0 \n\t"
  1796. "movd 2(%0), %%mm1 \n\t"
  1797. "punpcklbw %%mm7, %%mm0 \n\t"
  1798. "punpcklbw %%mm7, %%mm1 \n\t"
  1799. "movq %%mm0, %%mm2 \n\t"
  1800. "movq %%mm1, %%mm3 \n\t"
  1801. "pmaddwd (%4), %%mm0 \n\t"
  1802. "pmaddwd 8(%4), %%mm1 \n\t"
  1803. "pmaddwd 16(%4), %%mm2 \n\t"
  1804. "pmaddwd %%mm6, %%mm3 \n\t"
  1805. "paddd %%mm1, %%mm0 \n\t"
  1806. "paddd %%mm3, %%mm2 \n\t"
  1807. "movd 6(%0), %%mm1 \n\t"
  1808. "movd 8(%0), %%mm3 \n\t"
  1809. "add $12, %0 \n\t"
  1810. "punpcklbw %%mm7, %%mm1 \n\t"
  1811. "punpcklbw %%mm7, %%mm3 \n\t"
  1812. "movq %%mm1, %%mm4 \n\t"
  1813. "movq %%mm3, %%mm5 \n\t"
  1814. "pmaddwd (%4), %%mm1 \n\t"
  1815. "pmaddwd 8(%4), %%mm3 \n\t"
  1816. "pmaddwd 16(%4), %%mm4 \n\t"
  1817. "pmaddwd %%mm6, %%mm5 \n\t"
  1818. "paddd %%mm3, %%mm1 \n\t"
  1819. "paddd %%mm5, %%mm4 \n\t"
  1820. "movq "MANGLE(ff_bgr24toUVOffset)", %%mm3 \n\t"
  1821. "paddd %%mm3, %%mm0 \n\t"
  1822. "paddd %%mm3, %%mm2 \n\t"
  1823. "paddd %%mm3, %%mm1 \n\t"
  1824. "paddd %%mm3, %%mm4 \n\t"
  1825. "psrad $9, %%mm0 \n\t"
  1826. "psrad $9, %%mm2 \n\t"
  1827. "psrad $9, %%mm1 \n\t"
  1828. "psrad $9, %%mm4 \n\t"
  1829. "packssdw %%mm1, %%mm0 \n\t"
  1830. "packssdw %%mm4, %%mm2 \n\t"
  1831. "movq %%mm0, (%1, %%"REG_a") \n\t"
  1832. "movq %%mm2, (%2, %%"REG_a") \n\t"
  1833. "add $8, %%"REG_a" \n\t"
  1834. " js 1b \n\t"
  1835. : "+r" (src)
  1836. : "r" (dstU+width), "r" (dstV+width), "g" ((x86_reg)-2*width), "r"(ff_bgr24toUV[srcFormat == PIX_FMT_RGB24])
  1837. : "%"REG_a
  1838. );
  1839. }
  1840. static void RENAME(bgr24ToUV)(int16_t *dstU, int16_t *dstV,
  1841. const uint8_t *src1, const uint8_t *src2,
  1842. int width, uint32_t *unused)
  1843. {
  1844. RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_BGR24);
  1845. assert(src1 == src2);
  1846. }
  1847. static void RENAME(rgb24ToUV)(int16_t *dstU, int16_t *dstV,
  1848. const uint8_t *src1, const uint8_t *src2,
  1849. int width, uint32_t *unused)
  1850. {
  1851. assert(src1==src2);
  1852. RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_RGB24);
  1853. }
  1854. #if !COMPILE_TEMPLATE_MMX2
  1855. // bilinear / bicubic scaling
  1856. static void RENAME(hScale)(SwsContext *c, int16_t *dst, int dstW,
  1857. const uint8_t *src, const int16_t *filter,
  1858. const int16_t *filterPos, int filterSize)
  1859. {
  1860. assert(filterSize % 4 == 0 && filterSize>0);
  1861. if (filterSize==4) { // Always true for upscaling, sometimes for down, too.
  1862. x86_reg counter= -2*dstW;
  1863. filter-= counter*2;
  1864. filterPos-= counter/2;
  1865. dst-= counter/2;
  1866. __asm__ volatile(
  1867. #if defined(PIC)
  1868. "push %%"REG_b" \n\t"
  1869. #endif
  1870. "pxor %%mm7, %%mm7 \n\t"
  1871. "push %%"REG_BP" \n\t" // we use 7 regs here ...
  1872. "mov %%"REG_a", %%"REG_BP" \n\t"
  1873. ".p2align 4 \n\t"
  1874. "1: \n\t"
  1875. "movzwl (%2, %%"REG_BP"), %%eax \n\t"
  1876. "movzwl 2(%2, %%"REG_BP"), %%ebx \n\t"
  1877. "movq (%1, %%"REG_BP", 4), %%mm1 \n\t"
  1878. "movq 8(%1, %%"REG_BP", 4), %%mm3 \n\t"
  1879. "movd (%3, %%"REG_a"), %%mm0 \n\t"
  1880. "movd (%3, %%"REG_b"), %%mm2 \n\t"
  1881. "punpcklbw %%mm7, %%mm0 \n\t"
  1882. "punpcklbw %%mm7, %%mm2 \n\t"
  1883. "pmaddwd %%mm1, %%mm0 \n\t"
  1884. "pmaddwd %%mm2, %%mm3 \n\t"
  1885. "movq %%mm0, %%mm4 \n\t"
  1886. "punpckldq %%mm3, %%mm0 \n\t"
  1887. "punpckhdq %%mm3, %%mm4 \n\t"
  1888. "paddd %%mm4, %%mm0 \n\t"
  1889. "psrad $7, %%mm0 \n\t"
  1890. "packssdw %%mm0, %%mm0 \n\t"
  1891. "movd %%mm0, (%4, %%"REG_BP") \n\t"
  1892. "add $4, %%"REG_BP" \n\t"
  1893. " jnc 1b \n\t"
  1894. "pop %%"REG_BP" \n\t"
  1895. #if defined(PIC)
  1896. "pop %%"REG_b" \n\t"
  1897. #endif
  1898. : "+a" (counter)
  1899. : "c" (filter), "d" (filterPos), "S" (src), "D" (dst)
  1900. #if !defined(PIC)
  1901. : "%"REG_b
  1902. #endif
  1903. );
  1904. } else if (filterSize==8) {
  1905. x86_reg counter= -2*dstW;
  1906. filter-= counter*4;
  1907. filterPos-= counter/2;
  1908. dst-= counter/2;
  1909. __asm__ volatile(
  1910. #if defined(PIC)
  1911. "push %%"REG_b" \n\t"
  1912. #endif
  1913. "pxor %%mm7, %%mm7 \n\t"
  1914. "push %%"REG_BP" \n\t" // we use 7 regs here ...
  1915. "mov %%"REG_a", %%"REG_BP" \n\t"
  1916. ".p2align 4 \n\t"
  1917. "1: \n\t"
  1918. "movzwl (%2, %%"REG_BP"), %%eax \n\t"
  1919. "movzwl 2(%2, %%"REG_BP"), %%ebx \n\t"
  1920. "movq (%1, %%"REG_BP", 8), %%mm1 \n\t"
  1921. "movq 16(%1, %%"REG_BP", 8), %%mm3 \n\t"
  1922. "movd (%3, %%"REG_a"), %%mm0 \n\t"
  1923. "movd (%3, %%"REG_b"), %%mm2 \n\t"
  1924. "punpcklbw %%mm7, %%mm0 \n\t"
  1925. "punpcklbw %%mm7, %%mm2 \n\t"
  1926. "pmaddwd %%mm1, %%mm0 \n\t"
  1927. "pmaddwd %%mm2, %%mm3 \n\t"
  1928. "movq 8(%1, %%"REG_BP", 8), %%mm1 \n\t"
  1929. "movq 24(%1, %%"REG_BP", 8), %%mm5 \n\t"
  1930. "movd 4(%3, %%"REG_a"), %%mm4 \n\t"
  1931. "movd 4(%3, %%"REG_b"), %%mm2 \n\t"
  1932. "punpcklbw %%mm7, %%mm4 \n\t"
  1933. "punpcklbw %%mm7, %%mm2 \n\t"
  1934. "pmaddwd %%mm1, %%mm4 \n\t"
  1935. "pmaddwd %%mm2, %%mm5 \n\t"
  1936. "paddd %%mm4, %%mm0 \n\t"
  1937. "paddd %%mm5, %%mm3 \n\t"
  1938. "movq %%mm0, %%mm4 \n\t"
  1939. "punpckldq %%mm3, %%mm0 \n\t"
  1940. "punpckhdq %%mm3, %%mm4 \n\t"
  1941. "paddd %%mm4, %%mm0 \n\t"
  1942. "psrad $7, %%mm0 \n\t"
  1943. "packssdw %%mm0, %%mm0 \n\t"
  1944. "movd %%mm0, (%4, %%"REG_BP") \n\t"
  1945. "add $4, %%"REG_BP" \n\t"
  1946. " jnc 1b \n\t"
  1947. "pop %%"REG_BP" \n\t"
  1948. #if defined(PIC)
  1949. "pop %%"REG_b" \n\t"
  1950. #endif
  1951. : "+a" (counter)
  1952. : "c" (filter), "d" (filterPos), "S" (src), "D" (dst)
  1953. #if !defined(PIC)
  1954. : "%"REG_b
  1955. #endif
  1956. );
  1957. } else {
  1958. const uint8_t *offset = src+filterSize;
  1959. x86_reg counter= -2*dstW;
  1960. //filter-= counter*filterSize/2;
  1961. filterPos-= counter/2;
  1962. dst-= counter/2;
  1963. __asm__ volatile(
  1964. "pxor %%mm7, %%mm7 \n\t"
  1965. ".p2align 4 \n\t"
  1966. "1: \n\t"
  1967. "mov %2, %%"REG_c" \n\t"
  1968. "movzwl (%%"REG_c", %0), %%eax \n\t"
  1969. "movzwl 2(%%"REG_c", %0), %%edx \n\t"
  1970. "mov %5, %%"REG_c" \n\t"
  1971. "pxor %%mm4, %%mm4 \n\t"
  1972. "pxor %%mm5, %%mm5 \n\t"
  1973. "2: \n\t"
  1974. "movq (%1), %%mm1 \n\t"
  1975. "movq (%1, %6), %%mm3 \n\t"
  1976. "movd (%%"REG_c", %%"REG_a"), %%mm0 \n\t"
  1977. "movd (%%"REG_c", %%"REG_d"), %%mm2 \n\t"
  1978. "punpcklbw %%mm7, %%mm0 \n\t"
  1979. "punpcklbw %%mm7, %%mm2 \n\t"
  1980. "pmaddwd %%mm1, %%mm0 \n\t"
  1981. "pmaddwd %%mm2, %%mm3 \n\t"
  1982. "paddd %%mm3, %%mm5 \n\t"
  1983. "paddd %%mm0, %%mm4 \n\t"
  1984. "add $8, %1 \n\t"
  1985. "add $4, %%"REG_c" \n\t"
  1986. "cmp %4, %%"REG_c" \n\t"
  1987. " jb 2b \n\t"
  1988. "add %6, %1 \n\t"
  1989. "movq %%mm4, %%mm0 \n\t"
  1990. "punpckldq %%mm5, %%mm4 \n\t"
  1991. "punpckhdq %%mm5, %%mm0 \n\t"
  1992. "paddd %%mm0, %%mm4 \n\t"
  1993. "psrad $7, %%mm4 \n\t"
  1994. "packssdw %%mm4, %%mm4 \n\t"
  1995. "mov %3, %%"REG_a" \n\t"
  1996. "movd %%mm4, (%%"REG_a", %0) \n\t"
  1997. "add $4, %0 \n\t"
  1998. " jnc 1b \n\t"
  1999. : "+r" (counter), "+r" (filter)
  2000. : "m" (filterPos), "m" (dst), "m"(offset),
  2001. "m" (src), "r" ((x86_reg)filterSize*2)
  2002. : "%"REG_a, "%"REG_c, "%"REG_d
  2003. );
  2004. }
  2005. }
  2006. #endif /* !COMPILE_TEMPLATE_MMX2 */
  2007. static inline void RENAME(hScale16)(int16_t *dst, int dstW, const uint16_t *src, int srcW, int xInc,
  2008. const int16_t *filter, const int16_t *filterPos, long filterSize, int shift)
  2009. {
  2010. int i, j;
  2011. assert(filterSize % 4 == 0 && filterSize>0);
  2012. if (filterSize==4 && shift<15) { // Always true for upscaling, sometimes for down, too.
  2013. x86_reg counter= -2*dstW;
  2014. filter-= counter*2;
  2015. filterPos-= counter/2;
  2016. dst-= counter/2;
  2017. __asm__ volatile(
  2018. "movd %5, %%mm7 \n\t"
  2019. #if defined(PIC)
  2020. "push %%"REG_b" \n\t"
  2021. #endif
  2022. "push %%"REG_BP" \n\t" // we use 7 regs here ...
  2023. "mov %%"REG_a", %%"REG_BP" \n\t"
  2024. ".p2align 4 \n\t"
  2025. "1: \n\t"
  2026. "movzwl (%2, %%"REG_BP"), %%eax \n\t"
  2027. "movzwl 2(%2, %%"REG_BP"), %%ebx \n\t"
  2028. "movq (%1, %%"REG_BP", 4), %%mm1 \n\t"
  2029. "movq 8(%1, %%"REG_BP", 4), %%mm3 \n\t"
  2030. "movq (%3, %%"REG_a", 2), %%mm0 \n\t"
  2031. "movq (%3, %%"REG_b", 2), %%mm2 \n\t"
  2032. "pmaddwd %%mm1, %%mm0 \n\t"
  2033. "pmaddwd %%mm2, %%mm3 \n\t"
  2034. "movq %%mm0, %%mm4 \n\t"
  2035. "punpckldq %%mm3, %%mm0 \n\t"
  2036. "punpckhdq %%mm3, %%mm4 \n\t"
  2037. "paddd %%mm4, %%mm0 \n\t"
  2038. "psrad %%mm7, %%mm0 \n\t"
  2039. "packssdw %%mm0, %%mm0 \n\t"
  2040. "movd %%mm0, (%4, %%"REG_BP") \n\t"
  2041. "add $4, %%"REG_BP" \n\t"
  2042. " jnc 1b \n\t"
  2043. "pop %%"REG_BP" \n\t"
  2044. #if defined(PIC)
  2045. "pop %%"REG_b" \n\t"
  2046. #endif
  2047. : "+a" (counter)
  2048. : "c" (filter), "d" (filterPos), "S" (src), "D" (dst), "m"(shift)
  2049. #if !defined(PIC)
  2050. : "%"REG_b
  2051. #endif
  2052. );
  2053. } else if (filterSize==8 && shift<15) {
  2054. x86_reg counter= -2*dstW;
  2055. filter-= counter*4;
  2056. filterPos-= counter/2;
  2057. dst-= counter/2;
  2058. __asm__ volatile(
  2059. "movd %5, %%mm7 \n\t"
  2060. #if defined(PIC)
  2061. "push %%"REG_b" \n\t"
  2062. #endif
  2063. "push %%"REG_BP" \n\t" // we use 7 regs here ...
  2064. "mov %%"REG_a", %%"REG_BP" \n\t"
  2065. ".p2align 4 \n\t"
  2066. "1: \n\t"
  2067. "movzwl (%2, %%"REG_BP"), %%eax \n\t"
  2068. "movzwl 2(%2, %%"REG_BP"), %%ebx \n\t"
  2069. "movq (%1, %%"REG_BP", 8), %%mm1 \n\t"
  2070. "movq 16(%1, %%"REG_BP", 8), %%mm3 \n\t"
  2071. "movq (%3, %%"REG_a", 2), %%mm0 \n\t"
  2072. "movq (%3, %%"REG_b", 2), %%mm2 \n\t"
  2073. "pmaddwd %%mm1, %%mm0 \n\t"
  2074. "pmaddwd %%mm2, %%mm3 \n\t"
  2075. "movq 8(%1, %%"REG_BP", 8), %%mm1 \n\t"
  2076. "movq 24(%1, %%"REG_BP", 8), %%mm5 \n\t"
  2077. "movq 8(%3, %%"REG_a", 2), %%mm4 \n\t"
  2078. "movq 8(%3, %%"REG_b", 2), %%mm2 \n\t"
  2079. "pmaddwd %%mm1, %%mm4 \n\t"
  2080. "pmaddwd %%mm2, %%mm5 \n\t"
  2081. "paddd %%mm4, %%mm0 \n\t"
  2082. "paddd %%mm5, %%mm3 \n\t"
  2083. "movq %%mm0, %%mm4 \n\t"
  2084. "punpckldq %%mm3, %%mm0 \n\t"
  2085. "punpckhdq %%mm3, %%mm4 \n\t"
  2086. "paddd %%mm4, %%mm0 \n\t"
  2087. "psrad %%mm7, %%mm0 \n\t"
  2088. "packssdw %%mm0, %%mm0 \n\t"
  2089. "movd %%mm0, (%4, %%"REG_BP") \n\t"
  2090. "add $4, %%"REG_BP" \n\t"
  2091. " jnc 1b \n\t"
  2092. "pop %%"REG_BP" \n\t"
  2093. #if defined(PIC)
  2094. "pop %%"REG_b" \n\t"
  2095. #endif
  2096. : "+a" (counter)
  2097. : "c" (filter), "d" (filterPos), "S" (src), "D" (dst), "m"(shift)
  2098. #if !defined(PIC)
  2099. : "%"REG_b
  2100. #endif
  2101. );
  2102. } else if (shift<15){
  2103. const uint16_t *offset = src+filterSize;
  2104. x86_reg counter= -2*dstW;
  2105. //filter-= counter*filterSize/2;
  2106. filterPos-= counter/2;
  2107. dst-= counter/2;
  2108. __asm__ volatile(
  2109. "movd %7, %%mm7 \n\t"
  2110. ".p2align 4 \n\t"
  2111. "1: \n\t"
  2112. "mov %2, %%"REG_c" \n\t"
  2113. "movzwl (%%"REG_c", %0), %%eax \n\t"
  2114. "movzwl 2(%%"REG_c", %0), %%edx \n\t"
  2115. "mov %5, %%"REG_c" \n\t"
  2116. "pxor %%mm4, %%mm4 \n\t"
  2117. "pxor %%mm5, %%mm5 \n\t"
  2118. "2: \n\t"
  2119. "movq (%1), %%mm1 \n\t"
  2120. "movq (%1, %6), %%mm3 \n\t"
  2121. "movq (%%"REG_c", %%"REG_a", 2), %%mm0 \n\t"
  2122. "movq (%%"REG_c", %%"REG_d", 2), %%mm2 \n\t"
  2123. "pmaddwd %%mm1, %%mm0 \n\t"
  2124. "pmaddwd %%mm2, %%mm3 \n\t"
  2125. "paddd %%mm3, %%mm5 \n\t"
  2126. "paddd %%mm0, %%mm4 \n\t"
  2127. "add $8, %1 \n\t"
  2128. "add $8, %%"REG_c" \n\t"
  2129. "cmp %4, %%"REG_c" \n\t"
  2130. " jb 2b \n\t"
  2131. "add %6, %1 \n\t"
  2132. "movq %%mm4, %%mm0 \n\t"
  2133. "punpckldq %%mm5, %%mm4 \n\t"
  2134. "punpckhdq %%mm5, %%mm0 \n\t"
  2135. "paddd %%mm0, %%mm4 \n\t"
  2136. "psrad %%mm7, %%mm4 \n\t"
  2137. "packssdw %%mm4, %%mm4 \n\t"
  2138. "mov %3, %%"REG_a" \n\t"
  2139. "movd %%mm4, (%%"REG_a", %0) \n\t"
  2140. "add $4, %0 \n\t"
  2141. " jnc 1b \n\t"
  2142. : "+r" (counter), "+r" (filter)
  2143. : "m" (filterPos), "m" (dst), "m"(offset),
  2144. "m" (src), "r" ((x86_reg)filterSize*2), "m"(shift)
  2145. : "%"REG_a, "%"REG_c, "%"REG_d
  2146. );
  2147. } else
  2148. for (i=0; i<dstW; i++) {
  2149. int srcPos= filterPos[i];
  2150. int val=0;
  2151. for (j=0; j<filterSize; j++) {
  2152. val += ((int)src[srcPos + j])*filter[filterSize*i + j];
  2153. }
  2154. dst[i] = FFMIN(val>>shift, (1<<15)-1); // the cubic equation does overflow ...
  2155. }
  2156. }
  2157. #if COMPILE_TEMPLATE_MMX2
  2158. static void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst,
  2159. int dstWidth, const uint8_t *src,
  2160. int srcW, int xInc)
  2161. {
  2162. int16_t *filterPos = c->hLumFilterPos;
  2163. int16_t *filter = c->hLumFilter;
  2164. void *mmx2FilterCode= c->lumMmx2FilterCode;
  2165. int i;
  2166. #if defined(PIC)
  2167. DECLARE_ALIGNED(8, uint64_t, ebxsave);
  2168. #endif
  2169. __asm__ volatile(
  2170. #if defined(PIC)
  2171. "mov %%"REG_b", %5 \n\t"
  2172. #endif
  2173. "pxor %%mm7, %%mm7 \n\t"
  2174. "mov %0, %%"REG_c" \n\t"
  2175. "mov %1, %%"REG_D" \n\t"
  2176. "mov %2, %%"REG_d" \n\t"
  2177. "mov %3, %%"REG_b" \n\t"
  2178. "xor %%"REG_a", %%"REG_a" \n\t" // i
  2179. PREFETCH" (%%"REG_c") \n\t"
  2180. PREFETCH" 32(%%"REG_c") \n\t"
  2181. PREFETCH" 64(%%"REG_c") \n\t"
  2182. #if ARCH_X86_64
  2183. #define CALL_MMX2_FILTER_CODE \
  2184. "movl (%%"REG_b"), %%esi \n\t"\
  2185. "call *%4 \n\t"\
  2186. "movl (%%"REG_b", %%"REG_a"), %%esi \n\t"\
  2187. "add %%"REG_S", %%"REG_c" \n\t"\
  2188. "add %%"REG_a", %%"REG_D" \n\t"\
  2189. "xor %%"REG_a", %%"REG_a" \n\t"\
  2190. #else
  2191. #define CALL_MMX2_FILTER_CODE \
  2192. "movl (%%"REG_b"), %%esi \n\t"\
  2193. "call *%4 \n\t"\
  2194. "addl (%%"REG_b", %%"REG_a"), %%"REG_c" \n\t"\
  2195. "add %%"REG_a", %%"REG_D" \n\t"\
  2196. "xor %%"REG_a", %%"REG_a" \n\t"\
  2197. #endif /* ARCH_X86_64 */
  2198. CALL_MMX2_FILTER_CODE
  2199. CALL_MMX2_FILTER_CODE
  2200. CALL_MMX2_FILTER_CODE
  2201. CALL_MMX2_FILTER_CODE
  2202. CALL_MMX2_FILTER_CODE
  2203. CALL_MMX2_FILTER_CODE
  2204. CALL_MMX2_FILTER_CODE
  2205. CALL_MMX2_FILTER_CODE
  2206. #if defined(PIC)
  2207. "mov %5, %%"REG_b" \n\t"
  2208. #endif
  2209. :: "m" (src), "m" (dst), "m" (filter), "m" (filterPos),
  2210. "m" (mmx2FilterCode)
  2211. #if defined(PIC)
  2212. ,"m" (ebxsave)
  2213. #endif
  2214. : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
  2215. #if !defined(PIC)
  2216. ,"%"REG_b
  2217. #endif
  2218. );
  2219. for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--)
  2220. dst[i] = src[srcW-1]*128;
  2221. }
  2222. static void RENAME(hcscale_fast)(SwsContext *c, int16_t *dst1, int16_t *dst2,
  2223. int dstWidth, const uint8_t *src1,
  2224. const uint8_t *src2, int srcW, int xInc)
  2225. {
  2226. int16_t *filterPos = c->hChrFilterPos;
  2227. int16_t *filter = c->hChrFilter;
  2228. void *mmx2FilterCode= c->chrMmx2FilterCode;
  2229. int i;
  2230. #if defined(PIC)
  2231. DECLARE_ALIGNED(8, uint64_t, ebxsave);
  2232. #endif
  2233. __asm__ volatile(
  2234. #if defined(PIC)
  2235. "mov %%"REG_b", %7 \n\t"
  2236. #endif
  2237. "pxor %%mm7, %%mm7 \n\t"
  2238. "mov %0, %%"REG_c" \n\t"
  2239. "mov %1, %%"REG_D" \n\t"
  2240. "mov %2, %%"REG_d" \n\t"
  2241. "mov %3, %%"REG_b" \n\t"
  2242. "xor %%"REG_a", %%"REG_a" \n\t" // i
  2243. PREFETCH" (%%"REG_c") \n\t"
  2244. PREFETCH" 32(%%"REG_c") \n\t"
  2245. PREFETCH" 64(%%"REG_c") \n\t"
  2246. CALL_MMX2_FILTER_CODE
  2247. CALL_MMX2_FILTER_CODE
  2248. CALL_MMX2_FILTER_CODE
  2249. CALL_MMX2_FILTER_CODE
  2250. "xor %%"REG_a", %%"REG_a" \n\t" // i
  2251. "mov %5, %%"REG_c" \n\t" // src
  2252. "mov %6, %%"REG_D" \n\t" // buf2
  2253. PREFETCH" (%%"REG_c") \n\t"
  2254. PREFETCH" 32(%%"REG_c") \n\t"
  2255. PREFETCH" 64(%%"REG_c") \n\t"
  2256. CALL_MMX2_FILTER_CODE
  2257. CALL_MMX2_FILTER_CODE
  2258. CALL_MMX2_FILTER_CODE
  2259. CALL_MMX2_FILTER_CODE
  2260. #if defined(PIC)
  2261. "mov %7, %%"REG_b" \n\t"
  2262. #endif
  2263. :: "m" (src1), "m" (dst1), "m" (filter), "m" (filterPos),
  2264. "m" (mmx2FilterCode), "m" (src2), "m"(dst2)
  2265. #if defined(PIC)
  2266. ,"m" (ebxsave)
  2267. #endif
  2268. : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
  2269. #if !defined(PIC)
  2270. ,"%"REG_b
  2271. #endif
  2272. );
  2273. for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) {
  2274. dst1[i] = src1[srcW-1]*128;
  2275. dst2[i] = src2[srcW-1]*128;
  2276. }
  2277. }
  2278. #endif /* COMPILE_TEMPLATE_MMX2 */
  2279. static av_cold void RENAME(sws_init_swScale)(SwsContext *c)
  2280. {
  2281. enum PixelFormat srcFormat = c->srcFormat,
  2282. dstFormat = c->dstFormat;
  2283. if (!is16BPS(dstFormat) && !is9_OR_10BPS(dstFormat) && dstFormat != PIX_FMT_NV12
  2284. && dstFormat != PIX_FMT_NV21 && !(c->flags & SWS_BITEXACT)) {
  2285. if (c->flags & SWS_ACCURATE_RND) {
  2286. c->yuv2yuv1 = RENAME(yuv2yuv1_ar );
  2287. c->yuv2yuvX = RENAME(yuv2yuvX_ar );
  2288. if (!(c->flags & SWS_FULL_CHR_H_INT)) {
  2289. switch (c->dstFormat) {
  2290. case PIX_FMT_RGB32: c->yuv2packedX = RENAME(yuv2rgb32_X_ar); break;
  2291. case PIX_FMT_BGR24: c->yuv2packedX = RENAME(yuv2bgr24_X_ar); break;
  2292. case PIX_FMT_RGB555: c->yuv2packedX = RENAME(yuv2rgb555_X_ar); break;
  2293. case PIX_FMT_RGB565: c->yuv2packedX = RENAME(yuv2rgb565_X_ar); break;
  2294. case PIX_FMT_YUYV422: c->yuv2packedX = RENAME(yuv2yuyv422_X_ar); break;
  2295. default: break;
  2296. }
  2297. }
  2298. } else {
  2299. int should_dither= isNBPS(c->srcFormat) || is16BPS(c->srcFormat);
  2300. c->yuv2yuv1 = should_dither ? RENAME(yuv2yuv1_ar ) : RENAME(yuv2yuv1 );
  2301. c->yuv2yuvX = RENAME(yuv2yuvX );
  2302. if (!(c->flags & SWS_FULL_CHR_H_INT)) {
  2303. switch (c->dstFormat) {
  2304. case PIX_FMT_RGB32: c->yuv2packedX = RENAME(yuv2rgb32_X); break;
  2305. case PIX_FMT_BGR24: c->yuv2packedX = RENAME(yuv2bgr24_X); break;
  2306. case PIX_FMT_RGB555: c->yuv2packedX = RENAME(yuv2rgb555_X); break;
  2307. case PIX_FMT_RGB565: c->yuv2packedX = RENAME(yuv2rgb565_X); break;
  2308. case PIX_FMT_YUYV422: c->yuv2packedX = RENAME(yuv2yuyv422_X); break;
  2309. default: break;
  2310. }
  2311. }
  2312. }
  2313. if (!(c->flags & SWS_FULL_CHR_H_INT)) {
  2314. switch (c->dstFormat) {
  2315. case PIX_FMT_RGB32:
  2316. c->yuv2packed1 = RENAME(yuv2rgb32_1);
  2317. c->yuv2packed2 = RENAME(yuv2rgb32_2);
  2318. break;
  2319. case PIX_FMT_BGR24:
  2320. c->yuv2packed1 = RENAME(yuv2bgr24_1);
  2321. c->yuv2packed2 = RENAME(yuv2bgr24_2);
  2322. break;
  2323. case PIX_FMT_RGB555:
  2324. c->yuv2packed1 = RENAME(yuv2rgb555_1);
  2325. c->yuv2packed2 = RENAME(yuv2rgb555_2);
  2326. break;
  2327. case PIX_FMT_RGB565:
  2328. c->yuv2packed1 = RENAME(yuv2rgb565_1);
  2329. c->yuv2packed2 = RENAME(yuv2rgb565_2);
  2330. break;
  2331. case PIX_FMT_YUYV422:
  2332. c->yuv2packed1 = RENAME(yuv2yuyv422_1);
  2333. c->yuv2packed2 = RENAME(yuv2yuyv422_2);
  2334. break;
  2335. default:
  2336. break;
  2337. }
  2338. }
  2339. }
  2340. if (c->scalingBpp == 8) {
  2341. #if !COMPILE_TEMPLATE_MMX2
  2342. c->hScale = RENAME(hScale );
  2343. #endif /* !COMPILE_TEMPLATE_MMX2 */
  2344. // Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one).
  2345. #if COMPILE_TEMPLATE_MMX2
  2346. if (c->flags & SWS_FAST_BILINEAR && c->canMMX2BeUsed)
  2347. {
  2348. c->hyscale_fast = RENAME(hyscale_fast);
  2349. c->hcscale_fast = RENAME(hcscale_fast);
  2350. } else {
  2351. #endif /* COMPILE_TEMPLATE_MMX2 */
  2352. c->hyscale_fast = NULL;
  2353. c->hcscale_fast = NULL;
  2354. #if COMPILE_TEMPLATE_MMX2
  2355. }
  2356. #endif /* COMPILE_TEMPLATE_MMX2 */
  2357. }
  2358. #if !COMPILE_TEMPLATE_MMX2
  2359. switch(srcFormat) {
  2360. case PIX_FMT_YUYV422 : c->chrToYV12 = RENAME(yuy2ToUV); break;
  2361. case PIX_FMT_UYVY422 : c->chrToYV12 = RENAME(uyvyToUV); break;
  2362. case PIX_FMT_NV12 : c->chrToYV12 = RENAME(nv12ToUV); break;
  2363. case PIX_FMT_NV21 : c->chrToYV12 = RENAME(nv21ToUV); break;
  2364. case PIX_FMT_YUV420P9LE:
  2365. case PIX_FMT_YUV422P10LE:
  2366. case PIX_FMT_YUV420P10LE: c->hScale16= RENAME(hScale16); break;
  2367. default: break;
  2368. }
  2369. #endif /* !COMPILE_TEMPLATE_MMX2 */
  2370. if (!c->chrSrcHSubSample) {
  2371. switch(srcFormat) {
  2372. case PIX_FMT_BGR24 : c->chrToYV12 = RENAME(bgr24ToUV); break;
  2373. case PIX_FMT_RGB24 : c->chrToYV12 = RENAME(rgb24ToUV); break;
  2374. default: break;
  2375. }
  2376. }
  2377. switch (srcFormat) {
  2378. #if !COMPILE_TEMPLATE_MMX2
  2379. case PIX_FMT_YUYV422 :
  2380. case PIX_FMT_Y400A : c->lumToYV12 = RENAME(yuy2ToY); break;
  2381. case PIX_FMT_UYVY422 : c->lumToYV12 = RENAME(uyvyToY); break;
  2382. #endif /* !COMPILE_TEMPLATE_MMX2 */
  2383. case PIX_FMT_BGR24 : c->lumToYV12 = RENAME(bgr24ToY); break;
  2384. case PIX_FMT_RGB24 : c->lumToYV12 = RENAME(rgb24ToY); break;
  2385. default: break;
  2386. }
  2387. #if !COMPILE_TEMPLATE_MMX2
  2388. if (c->alpPixBuf) {
  2389. switch (srcFormat) {
  2390. case PIX_FMT_Y400A : c->alpToYV12 = RENAME(yuy2ToY); break;
  2391. default: break;
  2392. }
  2393. }
  2394. #endif /* !COMPILE_TEMPLATE_MMX2 */
  2395. if(isAnyRGB(c->srcFormat) && av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1<15)
  2396. c->hScale16= RENAME(hScale16);
  2397. if(c->scalingBpp != 8)
  2398. c->hScale16 = NULL;
  2399. }