swscale_template.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703
  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_MMXEXT
  25. #define PREFETCH "prefetchnta"
  26. #else
  27. #define PREFETCH " # nop"
  28. #endif
  29. #if COMPILE_TEMPLATE_MMXEXT
  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_MMXEXT
  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_MMXEXT
  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, DSTW_OFFSET"(%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, DSTW_OFFSET"(%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, DSTW_OFFSET"(%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. __asm__ volatile(
  863. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  864. "mov %4, %%"REG_b" \n\t"
  865. "push %%"REG_BP" \n\t"
  866. YSCALEYUV2RGB(%%REGBP, %5)
  867. "pxor %%mm7, %%mm7 \n\t"
  868. WRITEBGR24(%%REGb, DSTW_OFFSET"(%5)", %%REGBP)
  869. "pop %%"REG_BP" \n\t"
  870. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  871. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  872. "a" (&c->redDither)
  873. );
  874. }
  875. static void RENAME(yuv2rgb555_2)(SwsContext *c, const int16_t *buf[2],
  876. const int16_t *ubuf[2], const int16_t *vbuf[2],
  877. const int16_t *abuf[2], uint8_t *dest,
  878. int dstW, int yalpha, int uvalpha, int y)
  879. {
  880. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  881. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  882. __asm__ volatile(
  883. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  884. "mov %4, %%"REG_b" \n\t"
  885. "push %%"REG_BP" \n\t"
  886. YSCALEYUV2RGB(%%REGBP, %5)
  887. "pxor %%mm7, %%mm7 \n\t"
  888. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  889. #ifdef DITHER1XBPP
  890. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  891. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  892. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  893. #endif
  894. WRITERGB15(%%REGb, DSTW_OFFSET"(%5)", %%REGBP)
  895. "pop %%"REG_BP" \n\t"
  896. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  897. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  898. "a" (&c->redDither)
  899. );
  900. }
  901. static void RENAME(yuv2rgb565_2)(SwsContext *c, const int16_t *buf[2],
  902. const int16_t *ubuf[2], const int16_t *vbuf[2],
  903. const int16_t *abuf[2], uint8_t *dest,
  904. int dstW, int yalpha, int uvalpha, int y)
  905. {
  906. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  907. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  908. __asm__ volatile(
  909. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  910. "mov %4, %%"REG_b" \n\t"
  911. "push %%"REG_BP" \n\t"
  912. YSCALEYUV2RGB(%%REGBP, %5)
  913. "pxor %%mm7, %%mm7 \n\t"
  914. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  915. #ifdef DITHER1XBPP
  916. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  917. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  918. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  919. #endif
  920. WRITERGB16(%%REGb, DSTW_OFFSET"(%5)", %%REGBP)
  921. "pop %%"REG_BP" \n\t"
  922. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  923. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  924. "a" (&c->redDither)
  925. );
  926. }
  927. #define REAL_YSCALEYUV2PACKED(index, c) \
  928. "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\
  929. "movq "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm1 \n\t"\
  930. "psraw $3, %%mm0 \n\t"\
  931. "psraw $3, %%mm1 \n\t"\
  932. "movq %%mm0, "CHR_MMX_FILTER_OFFSET"+8("#c") \n\t"\
  933. "movq %%mm1, "LUM_MMX_FILTER_OFFSET"+8("#c") \n\t"\
  934. "xor "#index", "#index" \n\t"\
  935. ".p2align 4 \n\t"\
  936. "1: \n\t"\
  937. "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
  938. "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
  939. "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  940. "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  941. "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  942. "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  943. "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
  944. "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
  945. "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\
  946. "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
  947. "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
  948. "psraw $7, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  949. "psraw $7, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  950. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
  951. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
  952. "movq (%0, "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\
  953. "movq (%1, "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\
  954. "movq 8(%0, "#index", 2), %%mm6 \n\t" /*buf0[eax]*/\
  955. "movq 8(%1, "#index", 2), %%mm7 \n\t" /*buf1[eax]*/\
  956. "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
  957. "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\
  958. "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  959. "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  960. "psraw $7, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  961. "psraw $7, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  962. "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  963. "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  964. #define YSCALEYUV2PACKED(index, c) REAL_YSCALEYUV2PACKED(index, c)
  965. static void RENAME(yuv2yuyv422_2)(SwsContext *c, const int16_t *buf[2],
  966. const int16_t *ubuf[2], const int16_t *vbuf[2],
  967. const int16_t *abuf[2], uint8_t *dest,
  968. int dstW, int yalpha, int uvalpha, int y)
  969. {
  970. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  971. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
  972. __asm__ volatile(
  973. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  974. "mov %4, %%"REG_b" \n\t"
  975. "push %%"REG_BP" \n\t"
  976. YSCALEYUV2PACKED(%%REGBP, %5)
  977. WRITEYUY2(%%REGb, DSTW_OFFSET"(%5)", %%REGBP)
  978. "pop %%"REG_BP" \n\t"
  979. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  980. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  981. "a" (&c->redDither)
  982. );
  983. }
  984. #define REAL_YSCALEYUV2RGB1(index, c) \
  985. "xor "#index", "#index" \n\t"\
  986. ".p2align 4 \n\t"\
  987. "1: \n\t"\
  988. "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\
  989. "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  990. "movq (%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
  991. "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  992. "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  993. "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  994. "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\
  995. "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\
  996. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  997. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  998. "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\
  999. "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\
  1000. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  1001. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1002. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1003. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1004. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1005. "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\
  1006. "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\
  1007. "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\
  1008. "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\
  1009. "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\
  1010. "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\
  1011. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  1012. "paddw %%mm3, %%mm4 \n\t"\
  1013. "movq %%mm2, %%mm0 \n\t"\
  1014. "movq %%mm5, %%mm6 \n\t"\
  1015. "movq %%mm4, %%mm3 \n\t"\
  1016. "punpcklwd %%mm2, %%mm2 \n\t"\
  1017. "punpcklwd %%mm5, %%mm5 \n\t"\
  1018. "punpcklwd %%mm4, %%mm4 \n\t"\
  1019. "paddw %%mm1, %%mm2 \n\t"\
  1020. "paddw %%mm1, %%mm5 \n\t"\
  1021. "paddw %%mm1, %%mm4 \n\t"\
  1022. "punpckhwd %%mm0, %%mm0 \n\t"\
  1023. "punpckhwd %%mm6, %%mm6 \n\t"\
  1024. "punpckhwd %%mm3, %%mm3 \n\t"\
  1025. "paddw %%mm7, %%mm0 \n\t"\
  1026. "paddw %%mm7, %%mm6 \n\t"\
  1027. "paddw %%mm7, %%mm3 \n\t"\
  1028. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  1029. "packuswb %%mm0, %%mm2 \n\t"\
  1030. "packuswb %%mm6, %%mm5 \n\t"\
  1031. "packuswb %%mm3, %%mm4 \n\t"\
  1032. #define YSCALEYUV2RGB1(index, c) REAL_YSCALEYUV2RGB1(index, c)
  1033. // do vertical chrominance interpolation
  1034. #define REAL_YSCALEYUV2RGB1b(index, c) \
  1035. "xor "#index", "#index" \n\t"\
  1036. ".p2align 4 \n\t"\
  1037. "1: \n\t"\
  1038. "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
  1039. "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
  1040. "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  1041. "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  1042. "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  1043. "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  1044. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
  1045. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
  1046. "psrlw $5, %%mm3 \n\t" /*FIXME might overflow*/\
  1047. "psrlw $5, %%mm4 \n\t" /*FIXME might overflow*/\
  1048. "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\
  1049. "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\
  1050. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  1051. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  1052. "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\
  1053. "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\
  1054. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  1055. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1056. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1057. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1058. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  1059. "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\
  1060. "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\
  1061. "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\
  1062. "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\
  1063. "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\
  1064. "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\
  1065. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  1066. "paddw %%mm3, %%mm4 \n\t"\
  1067. "movq %%mm2, %%mm0 \n\t"\
  1068. "movq %%mm5, %%mm6 \n\t"\
  1069. "movq %%mm4, %%mm3 \n\t"\
  1070. "punpcklwd %%mm2, %%mm2 \n\t"\
  1071. "punpcklwd %%mm5, %%mm5 \n\t"\
  1072. "punpcklwd %%mm4, %%mm4 \n\t"\
  1073. "paddw %%mm1, %%mm2 \n\t"\
  1074. "paddw %%mm1, %%mm5 \n\t"\
  1075. "paddw %%mm1, %%mm4 \n\t"\
  1076. "punpckhwd %%mm0, %%mm0 \n\t"\
  1077. "punpckhwd %%mm6, %%mm6 \n\t"\
  1078. "punpckhwd %%mm3, %%mm3 \n\t"\
  1079. "paddw %%mm7, %%mm0 \n\t"\
  1080. "paddw %%mm7, %%mm6 \n\t"\
  1081. "paddw %%mm7, %%mm3 \n\t"\
  1082. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  1083. "packuswb %%mm0, %%mm2 \n\t"\
  1084. "packuswb %%mm6, %%mm5 \n\t"\
  1085. "packuswb %%mm3, %%mm4 \n\t"\
  1086. #define YSCALEYUV2RGB1b(index, c) REAL_YSCALEYUV2RGB1b(index, c)
  1087. #define REAL_YSCALEYUV2RGB1_ALPHA(index) \
  1088. "movq (%1, "#index", 2), %%mm7 \n\t" /* abuf0[index ] */\
  1089. "movq 8(%1, "#index", 2), %%mm1 \n\t" /* abuf0[index+4] */\
  1090. "psraw $7, %%mm7 \n\t" /* abuf0[index ] >>7 */\
  1091. "psraw $7, %%mm1 \n\t" /* abuf0[index+4] >>7 */\
  1092. "packuswb %%mm1, %%mm7 \n\t"
  1093. #define YSCALEYUV2RGB1_ALPHA(index) REAL_YSCALEYUV2RGB1_ALPHA(index)
  1094. /**
  1095. * YV12 to RGB without scaling or interpolating
  1096. */
  1097. static void RENAME(yuv2rgb32_1)(SwsContext *c, const int16_t *buf0,
  1098. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1099. const int16_t *abuf0, uint8_t *dest,
  1100. int dstW, int uvalpha, int y)
  1101. {
  1102. const int16_t *ubuf0 = ubuf[0];
  1103. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1104. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1105. const int16_t *ubuf1 = ubuf[0];
  1106. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  1107. __asm__ volatile(
  1108. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1109. "mov %4, %%"REG_b" \n\t"
  1110. "push %%"REG_BP" \n\t"
  1111. YSCALEYUV2RGB1(%%REGBP, %5)
  1112. YSCALEYUV2RGB1_ALPHA(%%REGBP)
  1113. WRITEBGR32(%%REGb, DSTW_OFFSET"(%5)", %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  1114. "pop %%"REG_BP" \n\t"
  1115. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1116. :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1117. "a" (&c->redDither)
  1118. );
  1119. } else {
  1120. __asm__ volatile(
  1121. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1122. "mov %4, %%"REG_b" \n\t"
  1123. "push %%"REG_BP" \n\t"
  1124. YSCALEYUV2RGB1(%%REGBP, %5)
  1125. "pcmpeqd %%mm7, %%mm7 \n\t"
  1126. WRITEBGR32(%%REGb, DSTW_OFFSET"(%5)", %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  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. } else {
  1134. const int16_t *ubuf1 = ubuf[1];
  1135. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  1136. __asm__ volatile(
  1137. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1138. "mov %4, %%"REG_b" \n\t"
  1139. "push %%"REG_BP" \n\t"
  1140. YSCALEYUV2RGB1b(%%REGBP, %5)
  1141. YSCALEYUV2RGB1_ALPHA(%%REGBP)
  1142. WRITEBGR32(%%REGb, DSTW_OFFSET"(%5)", %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  1143. "pop %%"REG_BP" \n\t"
  1144. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1145. :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1146. "a" (&c->redDither)
  1147. );
  1148. } else {
  1149. __asm__ volatile(
  1150. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1151. "mov %4, %%"REG_b" \n\t"
  1152. "push %%"REG_BP" \n\t"
  1153. YSCALEYUV2RGB1b(%%REGBP, %5)
  1154. "pcmpeqd %%mm7, %%mm7 \n\t"
  1155. WRITEBGR32(%%REGb, DSTW_OFFSET"(%5)", %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
  1156. "pop %%"REG_BP" \n\t"
  1157. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1158. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1159. "a" (&c->redDither)
  1160. );
  1161. }
  1162. }
  1163. }
  1164. static void RENAME(yuv2bgr24_1)(SwsContext *c, const int16_t *buf0,
  1165. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1166. const int16_t *abuf0, uint8_t *dest,
  1167. int dstW, int uvalpha, int y)
  1168. {
  1169. const int16_t *ubuf0 = ubuf[0];
  1170. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1171. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1172. const int16_t *ubuf1 = ubuf[0];
  1173. __asm__ volatile(
  1174. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1175. "mov %4, %%"REG_b" \n\t"
  1176. "push %%"REG_BP" \n\t"
  1177. YSCALEYUV2RGB1(%%REGBP, %5)
  1178. "pxor %%mm7, %%mm7 \n\t"
  1179. WRITEBGR24(%%REGb, DSTW_OFFSET"(%5)", %%REGBP)
  1180. "pop %%"REG_BP" \n\t"
  1181. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1182. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1183. "a" (&c->redDither)
  1184. );
  1185. } else {
  1186. const int16_t *ubuf1 = ubuf[1];
  1187. __asm__ volatile(
  1188. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1189. "mov %4, %%"REG_b" \n\t"
  1190. "push %%"REG_BP" \n\t"
  1191. YSCALEYUV2RGB1b(%%REGBP, %5)
  1192. "pxor %%mm7, %%mm7 \n\t"
  1193. WRITEBGR24(%%REGb, DSTW_OFFSET"(%5)", %%REGBP)
  1194. "pop %%"REG_BP" \n\t"
  1195. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1196. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1197. "a" (&c->redDither)
  1198. );
  1199. }
  1200. }
  1201. static void RENAME(yuv2rgb555_1)(SwsContext *c, const int16_t *buf0,
  1202. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1203. const int16_t *abuf0, uint8_t *dest,
  1204. int dstW, int uvalpha, int y)
  1205. {
  1206. const int16_t *ubuf0 = ubuf[0];
  1207. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1208. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1209. const int16_t *ubuf1 = ubuf[0];
  1210. __asm__ volatile(
  1211. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1212. "mov %4, %%"REG_b" \n\t"
  1213. "push %%"REG_BP" \n\t"
  1214. YSCALEYUV2RGB1(%%REGBP, %5)
  1215. "pxor %%mm7, %%mm7 \n\t"
  1216. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1217. #ifdef DITHER1XBPP
  1218. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1219. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1220. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1221. #endif
  1222. WRITERGB15(%%REGb, DSTW_OFFSET"(%5)", %%REGBP)
  1223. "pop %%"REG_BP" \n\t"
  1224. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1225. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1226. "a" (&c->redDither)
  1227. );
  1228. } else {
  1229. const int16_t *ubuf1 = ubuf[1];
  1230. __asm__ volatile(
  1231. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1232. "mov %4, %%"REG_b" \n\t"
  1233. "push %%"REG_BP" \n\t"
  1234. YSCALEYUV2RGB1b(%%REGBP, %5)
  1235. "pxor %%mm7, %%mm7 \n\t"
  1236. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1237. #ifdef DITHER1XBPP
  1238. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1239. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1240. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1241. #endif
  1242. WRITERGB15(%%REGb, DSTW_OFFSET"(%5)", %%REGBP)
  1243. "pop %%"REG_BP" \n\t"
  1244. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1245. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1246. "a" (&c->redDither)
  1247. );
  1248. }
  1249. }
  1250. static void RENAME(yuv2rgb565_1)(SwsContext *c, const int16_t *buf0,
  1251. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1252. const int16_t *abuf0, uint8_t *dest,
  1253. int dstW, int uvalpha, int y)
  1254. {
  1255. const int16_t *ubuf0 = ubuf[0];
  1256. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1257. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1258. const int16_t *ubuf1 = ubuf[0];
  1259. __asm__ volatile(
  1260. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1261. "mov %4, %%"REG_b" \n\t"
  1262. "push %%"REG_BP" \n\t"
  1263. YSCALEYUV2RGB1(%%REGBP, %5)
  1264. "pxor %%mm7, %%mm7 \n\t"
  1265. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1266. #ifdef DITHER1XBPP
  1267. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1268. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1269. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1270. #endif
  1271. WRITERGB16(%%REGb, DSTW_OFFSET"(%5)", %%REGBP)
  1272. "pop %%"REG_BP" \n\t"
  1273. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1274. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1275. "a" (&c->redDither)
  1276. );
  1277. } else {
  1278. const int16_t *ubuf1 = ubuf[1];
  1279. __asm__ volatile(
  1280. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1281. "mov %4, %%"REG_b" \n\t"
  1282. "push %%"REG_BP" \n\t"
  1283. YSCALEYUV2RGB1b(%%REGBP, %5)
  1284. "pxor %%mm7, %%mm7 \n\t"
  1285. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  1286. #ifdef DITHER1XBPP
  1287. "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t"
  1288. "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t"
  1289. "paddusb "RED_DITHER"(%5), %%mm5 \n\t"
  1290. #endif
  1291. WRITERGB16(%%REGb, DSTW_OFFSET"(%5)", %%REGBP)
  1292. "pop %%"REG_BP" \n\t"
  1293. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1294. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1295. "a" (&c->redDither)
  1296. );
  1297. }
  1298. }
  1299. #define REAL_YSCALEYUV2PACKED1(index, c) \
  1300. "xor "#index", "#index" \n\t"\
  1301. ".p2align 4 \n\t"\
  1302. "1: \n\t"\
  1303. "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\
  1304. "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  1305. "movq (%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
  1306. "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  1307. "psraw $7, %%mm3 \n\t" \
  1308. "psraw $7, %%mm4 \n\t" \
  1309. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1310. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1311. "psraw $7, %%mm1 \n\t" \
  1312. "psraw $7, %%mm7 \n\t" \
  1313. #define YSCALEYUV2PACKED1(index, c) REAL_YSCALEYUV2PACKED1(index, c)
  1314. #define REAL_YSCALEYUV2PACKED1b(index, c) \
  1315. "xor "#index", "#index" \n\t"\
  1316. ".p2align 4 \n\t"\
  1317. "1: \n\t"\
  1318. "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
  1319. "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
  1320. "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  1321. "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  1322. "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  1323. "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \
  1324. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
  1325. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
  1326. "psrlw $8, %%mm3 \n\t" \
  1327. "psrlw $8, %%mm4 \n\t" \
  1328. "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
  1329. "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
  1330. "psraw $7, %%mm1 \n\t" \
  1331. "psraw $7, %%mm7 \n\t"
  1332. #define YSCALEYUV2PACKED1b(index, c) REAL_YSCALEYUV2PACKED1b(index, c)
  1333. static void RENAME(yuv2yuyv422_1)(SwsContext *c, const int16_t *buf0,
  1334. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1335. const int16_t *abuf0, uint8_t *dest,
  1336. int dstW, int uvalpha, int y)
  1337. {
  1338. const int16_t *ubuf0 = ubuf[0];
  1339. const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  1340. if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
  1341. const int16_t *ubuf1 = ubuf[0];
  1342. __asm__ volatile(
  1343. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1344. "mov %4, %%"REG_b" \n\t"
  1345. "push %%"REG_BP" \n\t"
  1346. YSCALEYUV2PACKED1(%%REGBP, %5)
  1347. WRITEYUY2(%%REGb, DSTW_OFFSET"(%5)", %%REGBP)
  1348. "pop %%"REG_BP" \n\t"
  1349. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1350. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1351. "a" (&c->redDither)
  1352. );
  1353. } else {
  1354. const int16_t *ubuf1 = ubuf[1];
  1355. __asm__ volatile(
  1356. "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
  1357. "mov %4, %%"REG_b" \n\t"
  1358. "push %%"REG_BP" \n\t"
  1359. YSCALEYUV2PACKED1b(%%REGBP, %5)
  1360. WRITEYUY2(%%REGb, DSTW_OFFSET"(%5)", %%REGBP)
  1361. "pop %%"REG_BP" \n\t"
  1362. "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
  1363. :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
  1364. "a" (&c->redDither)
  1365. );
  1366. }
  1367. }
  1368. #if COMPILE_TEMPLATE_MMXEXT
  1369. static void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst,
  1370. int dstWidth, const uint8_t *src,
  1371. int srcW, int xInc)
  1372. {
  1373. int32_t *filterPos = c->hLumFilterPos;
  1374. int16_t *filter = c->hLumFilter;
  1375. void *mmx2FilterCode= c->lumMmx2FilterCode;
  1376. int i;
  1377. #if defined(PIC)
  1378. uint64_t ebxsave;
  1379. #endif
  1380. #if ARCH_X86_64
  1381. uint64_t retsave;
  1382. #endif
  1383. __asm__ volatile(
  1384. #if defined(PIC)
  1385. "mov %%"REG_b", %5 \n\t"
  1386. #if ARCH_X86_64
  1387. "mov -8(%%rsp), %%"REG_a" \n\t"
  1388. "mov %%"REG_a", %6 \n\t"
  1389. #endif
  1390. #else
  1391. #if ARCH_X86_64
  1392. "mov -8(%%rsp), %%"REG_a" \n\t"
  1393. "mov %%"REG_a", %5 \n\t"
  1394. #endif
  1395. #endif
  1396. "pxor %%mm7, %%mm7 \n\t"
  1397. "mov %0, %%"REG_c" \n\t"
  1398. "mov %1, %%"REG_D" \n\t"
  1399. "mov %2, %%"REG_d" \n\t"
  1400. "mov %3, %%"REG_b" \n\t"
  1401. "xor %%"REG_a", %%"REG_a" \n\t" // i
  1402. PREFETCH" (%%"REG_c") \n\t"
  1403. PREFETCH" 32(%%"REG_c") \n\t"
  1404. PREFETCH" 64(%%"REG_c") \n\t"
  1405. #if ARCH_X86_64
  1406. #define CALL_MMX2_FILTER_CODE \
  1407. "movl (%%"REG_b"), %%esi \n\t"\
  1408. "call *%4 \n\t"\
  1409. "movl (%%"REG_b", %%"REG_a"), %%esi \n\t"\
  1410. "add %%"REG_S", %%"REG_c" \n\t"\
  1411. "add %%"REG_a", %%"REG_D" \n\t"\
  1412. "xor %%"REG_a", %%"REG_a" \n\t"\
  1413. #else
  1414. #define CALL_MMX2_FILTER_CODE \
  1415. "movl (%%"REG_b"), %%esi \n\t"\
  1416. "call *%4 \n\t"\
  1417. "addl (%%"REG_b", %%"REG_a"), %%"REG_c" \n\t"\
  1418. "add %%"REG_a", %%"REG_D" \n\t"\
  1419. "xor %%"REG_a", %%"REG_a" \n\t"\
  1420. #endif /* ARCH_X86_64 */
  1421. CALL_MMX2_FILTER_CODE
  1422. CALL_MMX2_FILTER_CODE
  1423. CALL_MMX2_FILTER_CODE
  1424. CALL_MMX2_FILTER_CODE
  1425. CALL_MMX2_FILTER_CODE
  1426. CALL_MMX2_FILTER_CODE
  1427. CALL_MMX2_FILTER_CODE
  1428. CALL_MMX2_FILTER_CODE
  1429. #if defined(PIC)
  1430. "mov %5, %%"REG_b" \n\t"
  1431. #if ARCH_X86_64
  1432. "mov %6, %%"REG_a" \n\t"
  1433. "mov %%"REG_a", -8(%%rsp) \n\t"
  1434. #endif
  1435. #else
  1436. #if ARCH_X86_64
  1437. "mov %5, %%"REG_a" \n\t"
  1438. "mov %%"REG_a", -8(%%rsp) \n\t"
  1439. #endif
  1440. #endif
  1441. :: "m" (src), "m" (dst), "m" (filter), "m" (filterPos),
  1442. "m" (mmx2FilterCode)
  1443. #if defined(PIC)
  1444. ,"m" (ebxsave)
  1445. #endif
  1446. #if ARCH_X86_64
  1447. ,"m"(retsave)
  1448. #endif
  1449. : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
  1450. #if !defined(PIC)
  1451. ,"%"REG_b
  1452. #endif
  1453. );
  1454. for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--)
  1455. dst[i] = src[srcW-1]*128;
  1456. }
  1457. static void RENAME(hcscale_fast)(SwsContext *c, int16_t *dst1, int16_t *dst2,
  1458. int dstWidth, const uint8_t *src1,
  1459. const uint8_t *src2, int srcW, int xInc)
  1460. {
  1461. int32_t *filterPos = c->hChrFilterPos;
  1462. int16_t *filter = c->hChrFilter;
  1463. void *mmx2FilterCode= c->chrMmx2FilterCode;
  1464. int i;
  1465. #if defined(PIC)
  1466. DECLARE_ALIGNED(8, uint64_t, ebxsave);
  1467. #endif
  1468. #if ARCH_X86_64
  1469. DECLARE_ALIGNED(8, uint64_t, retsave);
  1470. #endif
  1471. __asm__ volatile(
  1472. #if defined(PIC)
  1473. "mov %%"REG_b", %7 \n\t"
  1474. #if ARCH_X86_64
  1475. "mov -8(%%rsp), %%"REG_a" \n\t"
  1476. "mov %%"REG_a", %8 \n\t"
  1477. #endif
  1478. #else
  1479. #if ARCH_X86_64
  1480. "mov -8(%%rsp), %%"REG_a" \n\t"
  1481. "mov %%"REG_a", %7 \n\t"
  1482. #endif
  1483. #endif
  1484. "pxor %%mm7, %%mm7 \n\t"
  1485. "mov %0, %%"REG_c" \n\t"
  1486. "mov %1, %%"REG_D" \n\t"
  1487. "mov %2, %%"REG_d" \n\t"
  1488. "mov %3, %%"REG_b" \n\t"
  1489. "xor %%"REG_a", %%"REG_a" \n\t" // i
  1490. PREFETCH" (%%"REG_c") \n\t"
  1491. PREFETCH" 32(%%"REG_c") \n\t"
  1492. PREFETCH" 64(%%"REG_c") \n\t"
  1493. CALL_MMX2_FILTER_CODE
  1494. CALL_MMX2_FILTER_CODE
  1495. CALL_MMX2_FILTER_CODE
  1496. CALL_MMX2_FILTER_CODE
  1497. "xor %%"REG_a", %%"REG_a" \n\t" // i
  1498. "mov %5, %%"REG_c" \n\t" // src
  1499. "mov %6, %%"REG_D" \n\t" // buf2
  1500. PREFETCH" (%%"REG_c") \n\t"
  1501. PREFETCH" 32(%%"REG_c") \n\t"
  1502. PREFETCH" 64(%%"REG_c") \n\t"
  1503. CALL_MMX2_FILTER_CODE
  1504. CALL_MMX2_FILTER_CODE
  1505. CALL_MMX2_FILTER_CODE
  1506. CALL_MMX2_FILTER_CODE
  1507. #if defined(PIC)
  1508. "mov %7, %%"REG_b" \n\t"
  1509. #if ARCH_X86_64
  1510. "mov %8, %%"REG_a" \n\t"
  1511. "mov %%"REG_a", -8(%%rsp) \n\t"
  1512. #endif
  1513. #else
  1514. #if ARCH_X86_64
  1515. "mov %7, %%"REG_a" \n\t"
  1516. "mov %%"REG_a", -8(%%rsp) \n\t"
  1517. #endif
  1518. #endif
  1519. :: "m" (src1), "m" (dst1), "m" (filter), "m" (filterPos),
  1520. "m" (mmx2FilterCode), "m" (src2), "m"(dst2)
  1521. #if defined(PIC)
  1522. ,"m" (ebxsave)
  1523. #endif
  1524. #if ARCH_X86_64
  1525. ,"m"(retsave)
  1526. #endif
  1527. : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
  1528. #if !defined(PIC)
  1529. ,"%"REG_b
  1530. #endif
  1531. );
  1532. for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) {
  1533. dst1[i] = src1[srcW-1]*128;
  1534. dst2[i] = src2[srcW-1]*128;
  1535. }
  1536. }
  1537. #endif /* COMPILE_TEMPLATE_MMXEXT */
  1538. static av_cold void RENAME(sws_init_swScale)(SwsContext *c)
  1539. {
  1540. enum PixelFormat dstFormat = c->dstFormat;
  1541. c->use_mmx_vfilter= 0;
  1542. if (!is16BPS(dstFormat) && !is9_OR_10BPS(dstFormat) && dstFormat != PIX_FMT_NV12
  1543. && dstFormat != PIX_FMT_NV21 && !(c->flags & SWS_BITEXACT)) {
  1544. if (c->flags & SWS_ACCURATE_RND) {
  1545. if (!(c->flags & SWS_FULL_CHR_H_INT)) {
  1546. switch (c->dstFormat) {
  1547. case PIX_FMT_RGB32: c->yuv2packedX = RENAME(yuv2rgb32_X_ar); break;
  1548. case PIX_FMT_BGR24: c->yuv2packedX = RENAME(yuv2bgr24_X_ar); break;
  1549. case PIX_FMT_RGB555: c->yuv2packedX = RENAME(yuv2rgb555_X_ar); break;
  1550. case PIX_FMT_RGB565: c->yuv2packedX = RENAME(yuv2rgb565_X_ar); break;
  1551. case PIX_FMT_YUYV422: c->yuv2packedX = RENAME(yuv2yuyv422_X_ar); break;
  1552. default: break;
  1553. }
  1554. }
  1555. } else {
  1556. c->use_mmx_vfilter= 1;
  1557. c->yuv2planeX = RENAME(yuv2yuvX );
  1558. if (!(c->flags & SWS_FULL_CHR_H_INT)) {
  1559. switch (c->dstFormat) {
  1560. case PIX_FMT_RGB32: c->yuv2packedX = RENAME(yuv2rgb32_X); break;
  1561. case PIX_FMT_BGR24: c->yuv2packedX = RENAME(yuv2bgr24_X); break;
  1562. case PIX_FMT_RGB555: c->yuv2packedX = RENAME(yuv2rgb555_X); break;
  1563. case PIX_FMT_RGB565: c->yuv2packedX = RENAME(yuv2rgb565_X); break;
  1564. case PIX_FMT_YUYV422: c->yuv2packedX = RENAME(yuv2yuyv422_X); break;
  1565. default: break;
  1566. }
  1567. }
  1568. }
  1569. if (!(c->flags & SWS_FULL_CHR_H_INT)) {
  1570. switch (c->dstFormat) {
  1571. case PIX_FMT_RGB32:
  1572. c->yuv2packed1 = RENAME(yuv2rgb32_1);
  1573. c->yuv2packed2 = RENAME(yuv2rgb32_2);
  1574. break;
  1575. case PIX_FMT_BGR24:
  1576. c->yuv2packed1 = RENAME(yuv2bgr24_1);
  1577. c->yuv2packed2 = RENAME(yuv2bgr24_2);
  1578. break;
  1579. case PIX_FMT_RGB555:
  1580. c->yuv2packed1 = RENAME(yuv2rgb555_1);
  1581. c->yuv2packed2 = RENAME(yuv2rgb555_2);
  1582. break;
  1583. case PIX_FMT_RGB565:
  1584. c->yuv2packed1 = RENAME(yuv2rgb565_1);
  1585. c->yuv2packed2 = RENAME(yuv2rgb565_2);
  1586. break;
  1587. case PIX_FMT_YUYV422:
  1588. c->yuv2packed1 = RENAME(yuv2yuyv422_1);
  1589. c->yuv2packed2 = RENAME(yuv2yuyv422_2);
  1590. break;
  1591. default:
  1592. break;
  1593. }
  1594. }
  1595. }
  1596. if (c->srcBpc == 8 && c->dstBpc <= 14) {
  1597. // Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one).
  1598. #if COMPILE_TEMPLATE_MMXEXT
  1599. if (c->flags & SWS_FAST_BILINEAR && c->canMMX2BeUsed)
  1600. {
  1601. c->hyscale_fast = RENAME(hyscale_fast);
  1602. c->hcscale_fast = RENAME(hcscale_fast);
  1603. } else {
  1604. #endif /* COMPILE_TEMPLATE_MMXEXT */
  1605. c->hyscale_fast = NULL;
  1606. c->hcscale_fast = NULL;
  1607. #if COMPILE_TEMPLATE_MMXEXT
  1608. }
  1609. #endif /* COMPILE_TEMPLATE_MMXEXT */
  1610. }
  1611. }