swscale_template.c 75 KB

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