postprocess_template.c 161 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746
  1. /*
  2. * Copyright (C) 2001-2002 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 modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (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
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * 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. /**
  21. * @file
  22. * mmx/mmx2/3dnow postprocess code.
  23. */
  24. #include "libavutil/x86/asm.h"
  25. /* A single TEMPLATE_PP_* should be defined (to 1) when this template is
  26. * included. The following macros will define its dependencies to 1 as well
  27. * (like MMX2 depending on MMX), and will define to 0 all the others. Every
  28. * TEMPLATE_PP_* need to be undef at the end. */
  29. #ifdef TEMPLATE_PP_C
  30. # define RENAME(a) a ## _C
  31. #else
  32. # define TEMPLATE_PP_C 0
  33. #endif
  34. #ifdef TEMPLATE_PP_ALTIVEC
  35. # define RENAME(a) a ## _altivec
  36. #else
  37. # define TEMPLATE_PP_ALTIVEC 0
  38. #endif
  39. #ifdef TEMPLATE_PP_MMX
  40. # define RENAME(a) a ## _MMX
  41. #else
  42. # define TEMPLATE_PP_MMX 0
  43. #endif
  44. #ifdef TEMPLATE_PP_MMXEXT
  45. # undef TEMPLATE_PP_MMX
  46. # define TEMPLATE_PP_MMX 1
  47. # define RENAME(a) a ## _MMX2
  48. #else
  49. # define TEMPLATE_PP_MMXEXT 0
  50. #endif
  51. #ifdef TEMPLATE_PP_3DNOW
  52. # undef TEMPLATE_PP_MMX
  53. # define TEMPLATE_PP_MMX 1
  54. # define RENAME(a) a ## _3DNow
  55. #else
  56. # define TEMPLATE_PP_3DNOW 0
  57. #endif
  58. #ifdef TEMPLATE_PP_SSE2
  59. # undef TEMPLATE_PP_MMX
  60. # define TEMPLATE_PP_MMX 1
  61. # undef TEMPLATE_PP_MMXEXT
  62. # define TEMPLATE_PP_MMXEXT 1
  63. # define RENAME(a) a ## _SSE2
  64. #else
  65. # define TEMPLATE_PP_SSE2 0
  66. #endif
  67. #undef REAL_PAVGB
  68. #undef PAVGB
  69. #undef PMINUB
  70. #undef PMAXUB
  71. #if TEMPLATE_PP_MMXEXT
  72. #define REAL_PAVGB(a,b) "pavgb " #a ", " #b " \n\t"
  73. #elif TEMPLATE_PP_3DNOW
  74. #define REAL_PAVGB(a,b) "pavgusb " #a ", " #b " \n\t"
  75. #endif
  76. #define PAVGB(a,b) REAL_PAVGB(a,b)
  77. #if TEMPLATE_PP_MMXEXT
  78. #define PMINUB(a,b,t) "pminub " #a ", " #b " \n\t"
  79. #elif TEMPLATE_PP_MMX
  80. #define PMINUB(b,a,t) \
  81. "movq " #a ", " #t " \n\t"\
  82. "psubusb " #b ", " #t " \n\t"\
  83. "psubb " #t ", " #a " \n\t"
  84. #endif
  85. #if TEMPLATE_PP_MMXEXT
  86. #define PMAXUB(a,b) "pmaxub " #a ", " #b " \n\t"
  87. #elif TEMPLATE_PP_MMX
  88. #define PMAXUB(a,b) \
  89. "psubusb " #a ", " #b " \n\t"\
  90. "paddb " #a ", " #b " \n\t"
  91. #endif
  92. //FIXME? |255-0| = 1 (should not be a problem ...)
  93. #if TEMPLATE_PP_MMX
  94. /**
  95. * Check if the middle 8x8 Block in the given 8x16 block is flat
  96. */
  97. static inline int RENAME(vertClassify)(const uint8_t src[], int stride, PPContext *c){
  98. int numEq= 0, dcOk;
  99. src+= stride*4; // src points to begin of the 8x8 Block
  100. __asm__ volatile(
  101. "movq %0, %%mm7 \n\t"
  102. "movq %1, %%mm6 \n\t"
  103. : : "m" (c->mmxDcOffset[c->nonBQP]), "m" (c->mmxDcThreshold[c->nonBQP])
  104. );
  105. __asm__ volatile(
  106. "lea (%2, %3), %%"FF_REG_a" \n\t"
  107. // 0 1 2 3 4 5 6 7 8 9
  108. // %1 eax eax+%2 eax+2%2 %1+4%2 ecx ecx+%2 ecx+2%2 %1+8%2 ecx+4%2
  109. "movq (%2), %%mm0 \n\t"
  110. "movq (%%"FF_REG_a"), %%mm1 \n\t"
  111. "movq %%mm0, %%mm3 \n\t"
  112. "movq %%mm0, %%mm4 \n\t"
  113. PMAXUB(%%mm1, %%mm4)
  114. PMINUB(%%mm1, %%mm3, %%mm5)
  115. "psubb %%mm1, %%mm0 \n\t" // mm0 = difference
  116. "paddb %%mm7, %%mm0 \n\t"
  117. "pcmpgtb %%mm6, %%mm0 \n\t"
  118. "movq (%%"FF_REG_a",%3), %%mm2 \n\t"
  119. PMAXUB(%%mm2, %%mm4)
  120. PMINUB(%%mm2, %%mm3, %%mm5)
  121. "psubb %%mm2, %%mm1 \n\t"
  122. "paddb %%mm7, %%mm1 \n\t"
  123. "pcmpgtb %%mm6, %%mm1 \n\t"
  124. "paddb %%mm1, %%mm0 \n\t"
  125. "movq (%%"FF_REG_a", %3, 2), %%mm1 \n\t"
  126. PMAXUB(%%mm1, %%mm4)
  127. PMINUB(%%mm1, %%mm3, %%mm5)
  128. "psubb %%mm1, %%mm2 \n\t"
  129. "paddb %%mm7, %%mm2 \n\t"
  130. "pcmpgtb %%mm6, %%mm2 \n\t"
  131. "paddb %%mm2, %%mm0 \n\t"
  132. "lea (%%"FF_REG_a", %3, 4), %%"FF_REG_a"\n\t"
  133. "movq (%2, %3, 4), %%mm2 \n\t"
  134. PMAXUB(%%mm2, %%mm4)
  135. PMINUB(%%mm2, %%mm3, %%mm5)
  136. "psubb %%mm2, %%mm1 \n\t"
  137. "paddb %%mm7, %%mm1 \n\t"
  138. "pcmpgtb %%mm6, %%mm1 \n\t"
  139. "paddb %%mm1, %%mm0 \n\t"
  140. "movq (%%"FF_REG_a"), %%mm1 \n\t"
  141. PMAXUB(%%mm1, %%mm4)
  142. PMINUB(%%mm1, %%mm3, %%mm5)
  143. "psubb %%mm1, %%mm2 \n\t"
  144. "paddb %%mm7, %%mm2 \n\t"
  145. "pcmpgtb %%mm6, %%mm2 \n\t"
  146. "paddb %%mm2, %%mm0 \n\t"
  147. "movq (%%"FF_REG_a", %3), %%mm2 \n\t"
  148. PMAXUB(%%mm2, %%mm4)
  149. PMINUB(%%mm2, %%mm3, %%mm5)
  150. "psubb %%mm2, %%mm1 \n\t"
  151. "paddb %%mm7, %%mm1 \n\t"
  152. "pcmpgtb %%mm6, %%mm1 \n\t"
  153. "paddb %%mm1, %%mm0 \n\t"
  154. "movq (%%"FF_REG_a", %3, 2), %%mm1 \n\t"
  155. PMAXUB(%%mm1, %%mm4)
  156. PMINUB(%%mm1, %%mm3, %%mm5)
  157. "psubb %%mm1, %%mm2 \n\t"
  158. "paddb %%mm7, %%mm2 \n\t"
  159. "pcmpgtb %%mm6, %%mm2 \n\t"
  160. "paddb %%mm2, %%mm0 \n\t"
  161. "psubusb %%mm3, %%mm4 \n\t"
  162. " \n\t"
  163. #if TEMPLATE_PP_MMXEXT
  164. "pxor %%mm7, %%mm7 \n\t"
  165. "psadbw %%mm7, %%mm0 \n\t"
  166. #else
  167. "movq %%mm0, %%mm1 \n\t"
  168. "psrlw $8, %%mm0 \n\t"
  169. "paddb %%mm1, %%mm0 \n\t"
  170. "movq %%mm0, %%mm1 \n\t"
  171. "psrlq $16, %%mm0 \n\t"
  172. "paddb %%mm1, %%mm0 \n\t"
  173. "movq %%mm0, %%mm1 \n\t"
  174. "psrlq $32, %%mm0 \n\t"
  175. "paddb %%mm1, %%mm0 \n\t"
  176. #endif
  177. "movq %4, %%mm7 \n\t" // QP,..., QP
  178. "paddusb %%mm7, %%mm7 \n\t" // 2QP ... 2QP
  179. "psubusb %%mm7, %%mm4 \n\t" // Diff <= 2QP -> 0
  180. "packssdw %%mm4, %%mm4 \n\t"
  181. "movd %%mm0, %0 \n\t"
  182. "movd %%mm4, %1 \n\t"
  183. : "=r" (numEq), "=r" (dcOk)
  184. : "r" (src), "r" ((x86_reg)stride), "m" (c->pQPb)
  185. : "%"FF_REG_a
  186. );
  187. numEq= (-numEq) &0xFF;
  188. if(numEq > c->ppMode.flatnessThreshold){
  189. if(dcOk) return 0;
  190. else return 1;
  191. }else{
  192. return 2;
  193. }
  194. }
  195. #endif //TEMPLATE_PP_MMX
  196. /**
  197. * Do a vertical low pass filter on the 8x16 block (only write to the 8x8 block in the middle)
  198. * using the 9-Tap Filter (1,1,2,2,4,2,2,1,1)/16
  199. */
  200. #if !TEMPLATE_PP_ALTIVEC
  201. static inline void RENAME(doVertLowPass)(uint8_t *src, int stride, PPContext *c)
  202. {
  203. #if TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  204. src+= stride*3;
  205. __asm__ volatile( //"movv %0 %1 %2\n\t"
  206. "movq %2, %%mm0 \n\t" // QP,..., QP
  207. "pxor %%mm4, %%mm4 \n\t"
  208. "movq (%0), %%mm6 \n\t"
  209. "movq (%0, %1), %%mm5 \n\t"
  210. "movq %%mm5, %%mm1 \n\t"
  211. "movq %%mm6, %%mm2 \n\t"
  212. "psubusb %%mm6, %%mm5 \n\t"
  213. "psubusb %%mm1, %%mm2 \n\t"
  214. "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
  215. "psubusb %%mm0, %%mm2 \n\t" // diff <= QP -> 0
  216. "pcmpeqb %%mm4, %%mm2 \n\t" // diff <= QP -> FF
  217. "pand %%mm2, %%mm6 \n\t"
  218. "pandn %%mm1, %%mm2 \n\t"
  219. "por %%mm2, %%mm6 \n\t"// First Line to Filter
  220. "movq (%0, %1, 8), %%mm5 \n\t"
  221. "lea (%0, %1, 4), %%"FF_REG_a" \n\t"
  222. "lea (%0, %1, 8), %%"FF_REG_c" \n\t"
  223. "sub %1, %%"FF_REG_c" \n\t"
  224. "add %1, %0 \n\t" // %0 points to line 1 not 0
  225. "movq (%0, %1, 8), %%mm7 \n\t"
  226. "movq %%mm5, %%mm1 \n\t"
  227. "movq %%mm7, %%mm2 \n\t"
  228. "psubusb %%mm7, %%mm5 \n\t"
  229. "psubusb %%mm1, %%mm2 \n\t"
  230. "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
  231. "psubusb %%mm0, %%mm2 \n\t" // diff <= QP -> 0
  232. "pcmpeqb %%mm4, %%mm2 \n\t" // diff <= QP -> FF
  233. "pand %%mm2, %%mm7 \n\t"
  234. "pandn %%mm1, %%mm2 \n\t"
  235. "por %%mm2, %%mm7 \n\t" // First Line to Filter
  236. // 1 2 3 4 5 6 7 8
  237. // %0 %0+%1 %0+2%1 eax %0+4%1 eax+2%1 ecx eax+4%1
  238. // 6 4 2 2 1 1
  239. // 6 4 4 2
  240. // 6 8 2
  241. "movq (%0, %1), %%mm0 \n\t" // 1
  242. "movq %%mm0, %%mm1 \n\t" // 1
  243. PAVGB(%%mm6, %%mm0) //1 1 /2
  244. PAVGB(%%mm6, %%mm0) //3 1 /4
  245. "movq (%0, %1, 4), %%mm2 \n\t" // 1
  246. "movq %%mm2, %%mm5 \n\t" // 1
  247. PAVGB((%%FF_REGa), %%mm2) // 11 /2
  248. PAVGB((%0, %1, 2), %%mm2) // 211 /4
  249. "movq %%mm2, %%mm3 \n\t" // 211 /4
  250. "movq (%0), %%mm4 \n\t" // 1
  251. PAVGB(%%mm4, %%mm3) // 4 211 /8
  252. PAVGB(%%mm0, %%mm3) //642211 /16
  253. "movq %%mm3, (%0) \n\t" // X
  254. // mm1=2 mm2=3(211) mm4=1 mm5=5 mm6=0 mm7=9
  255. "movq %%mm1, %%mm0 \n\t" // 1
  256. PAVGB(%%mm6, %%mm0) //1 1 /2
  257. "movq %%mm4, %%mm3 \n\t" // 1
  258. PAVGB((%0,%1,2), %%mm3) // 1 1 /2
  259. PAVGB((%%FF_REGa,%1,2), %%mm5) // 11 /2
  260. PAVGB((%%FF_REGa), %%mm5) // 211 /4
  261. PAVGB(%%mm5, %%mm3) // 2 2211 /8
  262. PAVGB(%%mm0, %%mm3) //4242211 /16
  263. "movq %%mm3, (%0,%1) \n\t" // X
  264. // mm1=2 mm2=3(211) mm4=1 mm5=4(211) mm6=0 mm7=9
  265. PAVGB(%%mm4, %%mm6) //11 /2
  266. "movq (%%"FF_REG_c"), %%mm0 \n\t" // 1
  267. PAVGB((%%FF_REGa, %1, 2), %%mm0) // 11/2
  268. "movq %%mm0, %%mm3 \n\t" // 11/2
  269. PAVGB(%%mm1, %%mm0) // 2 11/4
  270. PAVGB(%%mm6, %%mm0) //222 11/8
  271. PAVGB(%%mm2, %%mm0) //22242211/16
  272. "movq (%0, %1, 2), %%mm2 \n\t" // 1
  273. "movq %%mm0, (%0, %1, 2) \n\t" // X
  274. // mm1=2 mm2=3 mm3=6(11) mm4=1 mm5=4(211) mm6=0(11) mm7=9
  275. "movq (%%"FF_REG_a", %1, 4), %%mm0 \n\t" // 1
  276. PAVGB((%%FF_REGc), %%mm0) // 11 /2
  277. PAVGB(%%mm0, %%mm6) //11 11 /4
  278. PAVGB(%%mm1, %%mm4) // 11 /2
  279. PAVGB(%%mm2, %%mm1) // 11 /2
  280. PAVGB(%%mm1, %%mm6) //1122 11 /8
  281. PAVGB(%%mm5, %%mm6) //112242211 /16
  282. "movq (%%"FF_REG_a"), %%mm5 \n\t" // 1
  283. "movq %%mm6, (%%"FF_REG_a") \n\t" // X
  284. // mm0=7(11) mm1=2(11) mm2=3 mm3=6(11) mm4=1(11) mm5=4 mm7=9
  285. "movq (%%"FF_REG_a", %1, 4), %%mm6 \n\t" // 1
  286. PAVGB(%%mm7, %%mm6) // 11 /2
  287. PAVGB(%%mm4, %%mm6) // 11 11 /4
  288. PAVGB(%%mm3, %%mm6) // 11 2211 /8
  289. PAVGB(%%mm5, %%mm2) // 11 /2
  290. "movq (%0, %1, 4), %%mm4 \n\t" // 1
  291. PAVGB(%%mm4, %%mm2) // 112 /4
  292. PAVGB(%%mm2, %%mm6) // 112242211 /16
  293. "movq %%mm6, (%0, %1, 4) \n\t" // X
  294. // mm0=7(11) mm1=2(11) mm2=3(112) mm3=6(11) mm4=5 mm5=4 mm7=9
  295. PAVGB(%%mm7, %%mm1) // 11 2 /4
  296. PAVGB(%%mm4, %%mm5) // 11 /2
  297. PAVGB(%%mm5, %%mm0) // 11 11 /4
  298. "movq (%%"FF_REG_a", %1, 2), %%mm6 \n\t" // 1
  299. PAVGB(%%mm6, %%mm1) // 11 4 2 /8
  300. PAVGB(%%mm0, %%mm1) // 11224222 /16
  301. "movq %%mm1, (%%"FF_REG_a", %1, 2) \n\t" // X
  302. // mm2=3(112) mm3=6(11) mm4=5 mm5=4(11) mm6=6 mm7=9
  303. PAVGB((%%FF_REGc), %%mm2) // 112 4 /8
  304. "movq (%%"FF_REG_a", %1, 4), %%mm0 \n\t" // 1
  305. PAVGB(%%mm0, %%mm6) // 1 1 /2
  306. PAVGB(%%mm7, %%mm6) // 1 12 /4
  307. PAVGB(%%mm2, %%mm6) // 1122424 /4
  308. "movq %%mm6, (%%"FF_REG_c") \n\t" // X
  309. // mm0=8 mm3=6(11) mm4=5 mm5=4(11) mm7=9
  310. PAVGB(%%mm7, %%mm5) // 11 2 /4
  311. PAVGB(%%mm7, %%mm5) // 11 6 /8
  312. PAVGB(%%mm3, %%mm0) // 112 /4
  313. PAVGB(%%mm0, %%mm5) // 112246 /16
  314. "movq %%mm5, (%%"FF_REG_a", %1, 4) \n\t" // X
  315. "sub %1, %0 \n\t"
  316. :
  317. : "r" (src), "r" ((x86_reg)stride), "m" (c->pQPb)
  318. : "%"FF_REG_a, "%"FF_REG_c
  319. );
  320. #else //TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  321. const int l1= stride;
  322. const int l2= stride + l1;
  323. const int l3= stride + l2;
  324. const int l4= stride + l3;
  325. const int l5= stride + l4;
  326. const int l6= stride + l5;
  327. const int l7= stride + l6;
  328. const int l8= stride + l7;
  329. const int l9= stride + l8;
  330. int x;
  331. src+= stride*3;
  332. for(x=0; x<BLOCK_SIZE; x++){
  333. const int first= FFABS(src[0] - src[l1]) < c->QP ? src[0] : src[l1];
  334. const int last= FFABS(src[l8] - src[l9]) < c->QP ? src[l9] : src[l8];
  335. int sums[10];
  336. sums[0] = 4*first + src[l1] + src[l2] + src[l3] + 4;
  337. sums[1] = sums[0] - first + src[l4];
  338. sums[2] = sums[1] - first + src[l5];
  339. sums[3] = sums[2] - first + src[l6];
  340. sums[4] = sums[3] - first + src[l7];
  341. sums[5] = sums[4] - src[l1] + src[l8];
  342. sums[6] = sums[5] - src[l2] + last;
  343. sums[7] = sums[6] - src[l3] + last;
  344. sums[8] = sums[7] - src[l4] + last;
  345. sums[9] = sums[8] - src[l5] + last;
  346. src[l1]= (sums[0] + sums[2] + 2*src[l1])>>4;
  347. src[l2]= (sums[1] + sums[3] + 2*src[l2])>>4;
  348. src[l3]= (sums[2] + sums[4] + 2*src[l3])>>4;
  349. src[l4]= (sums[3] + sums[5] + 2*src[l4])>>4;
  350. src[l5]= (sums[4] + sums[6] + 2*src[l5])>>4;
  351. src[l6]= (sums[5] + sums[7] + 2*src[l6])>>4;
  352. src[l7]= (sums[6] + sums[8] + 2*src[l7])>>4;
  353. src[l8]= (sums[7] + sums[9] + 2*src[l8])>>4;
  354. src++;
  355. }
  356. #endif //TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  357. }
  358. #endif //TEMPLATE_PP_ALTIVEC
  359. /**
  360. * Experimental Filter 1
  361. * will not damage linear gradients
  362. * Flat blocks should look like they were passed through the (1,1,2,2,4,2,2,1,1) 9-Tap filter
  363. * can only smooth blocks at the expected locations (it cannot smooth them if they did move)
  364. * MMX2 version does correct clipping C version does not
  365. */
  366. static inline void RENAME(vertX1Filter)(uint8_t *src, int stride, PPContext *co)
  367. {
  368. #if TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  369. src+= stride*3;
  370. __asm__ volatile(
  371. "pxor %%mm7, %%mm7 \n\t" // 0
  372. "lea (%0, %1), %%"FF_REG_a" \n\t"
  373. "lea (%%"FF_REG_a", %1, 4), %%"FF_REG_c"\n\t"
  374. // 0 1 2 3 4 5 6 7 8 9
  375. // %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %0+8%1 ecx+4%1
  376. "movq (%%"FF_REG_a", %1, 2), %%mm0 \n\t" // line 3
  377. "movq (%0, %1, 4), %%mm1 \n\t" // line 4
  378. "movq %%mm1, %%mm2 \n\t" // line 4
  379. "psubusb %%mm0, %%mm1 \n\t"
  380. "psubusb %%mm2, %%mm0 \n\t"
  381. "por %%mm1, %%mm0 \n\t" // |l2 - l3|
  382. "movq (%%"FF_REG_c"), %%mm3 \n\t" // line 5
  383. "movq (%%"FF_REG_c", %1), %%mm4 \n\t" // line 6
  384. "movq %%mm3, %%mm5 \n\t" // line 5
  385. "psubusb %%mm4, %%mm3 \n\t"
  386. "psubusb %%mm5, %%mm4 \n\t"
  387. "por %%mm4, %%mm3 \n\t" // |l5 - l6|
  388. PAVGB(%%mm3, %%mm0) // (|l2 - l3| + |l5 - l6|)/2
  389. "movq %%mm2, %%mm1 \n\t" // line 4
  390. "psubusb %%mm5, %%mm2 \n\t"
  391. "movq %%mm2, %%mm4 \n\t"
  392. "pcmpeqb %%mm7, %%mm2 \n\t" // (l4 - l5) <= 0 ? -1 : 0
  393. "psubusb %%mm1, %%mm5 \n\t"
  394. "por %%mm5, %%mm4 \n\t" // |l4 - l5|
  395. "psubusb %%mm0, %%mm4 \n\t" //d = MAX(0, |l4-l5| - (|l2-l3| + |l5-l6|)/2)
  396. "movq %%mm4, %%mm3 \n\t" // d
  397. "movq %2, %%mm0 \n\t"
  398. "paddusb %%mm0, %%mm0 \n\t"
  399. "psubusb %%mm0, %%mm4 \n\t"
  400. "pcmpeqb %%mm7, %%mm4 \n\t" // d <= QP ? -1 : 0
  401. "psubusb "MANGLE(b01)", %%mm3 \n\t"
  402. "pand %%mm4, %%mm3 \n\t" // d <= QP ? d : 0
  403. PAVGB(%%mm7, %%mm3) // d/2
  404. "movq %%mm3, %%mm1 \n\t" // d/2
  405. PAVGB(%%mm7, %%mm3) // d/4
  406. PAVGB(%%mm1, %%mm3) // 3*d/8
  407. "movq (%0, %1, 4), %%mm0 \n\t" // line 4
  408. "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l4-1 : l4
  409. "psubusb %%mm3, %%mm0 \n\t"
  410. "pxor %%mm2, %%mm0 \n\t"
  411. "movq %%mm0, (%0, %1, 4) \n\t" // line 4
  412. "movq (%%"FF_REG_c"), %%mm0 \n\t" // line 5
  413. "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l5-1 : l5
  414. "paddusb %%mm3, %%mm0 \n\t"
  415. "pxor %%mm2, %%mm0 \n\t"
  416. "movq %%mm0, (%%"FF_REG_c") \n\t" // line 5
  417. PAVGB(%%mm7, %%mm1) // d/4
  418. "movq (%%"FF_REG_a", %1, 2), %%mm0 \n\t" // line 3
  419. "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l4-1 : l4
  420. "psubusb %%mm1, %%mm0 \n\t"
  421. "pxor %%mm2, %%mm0 \n\t"
  422. "movq %%mm0, (%%"FF_REG_a", %1, 2) \n\t" // line 3
  423. "movq (%%"FF_REG_c", %1), %%mm0 \n\t" // line 6
  424. "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l5-1 : l5
  425. "paddusb %%mm1, %%mm0 \n\t"
  426. "pxor %%mm2, %%mm0 \n\t"
  427. "movq %%mm0, (%%"FF_REG_c", %1) \n\t" // line 6
  428. PAVGB(%%mm7, %%mm1) // d/8
  429. "movq (%%"FF_REG_a", %1), %%mm0 \n\t" // line 2
  430. "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l2-1 : l2
  431. "psubusb %%mm1, %%mm0 \n\t"
  432. "pxor %%mm2, %%mm0 \n\t"
  433. "movq %%mm0, (%%"FF_REG_a", %1) \n\t" // line 2
  434. "movq (%%"FF_REG_c", %1, 2), %%mm0 \n\t" // line 7
  435. "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l7-1 : l7
  436. "paddusb %%mm1, %%mm0 \n\t"
  437. "pxor %%mm2, %%mm0 \n\t"
  438. "movq %%mm0, (%%"FF_REG_c", %1, 2) \n\t" // line 7
  439. :
  440. : "r" (src), "r" ((x86_reg)stride), "m" (co->pQPb)
  441. NAMED_CONSTRAINTS_ADD(b01)
  442. : "%"FF_REG_a, "%"FF_REG_c
  443. );
  444. #else //TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  445. const int l1= stride;
  446. const int l2= stride + l1;
  447. const int l3= stride + l2;
  448. const int l4= stride + l3;
  449. const int l5= stride + l4;
  450. const int l6= stride + l5;
  451. const int l7= stride + l6;
  452. // const int l8= stride + l7;
  453. // const int l9= stride + l8;
  454. int x;
  455. src+= stride*3;
  456. for(x=0; x<BLOCK_SIZE; x++){
  457. int a= src[l3] - src[l4];
  458. int b= src[l4] - src[l5];
  459. int c= src[l5] - src[l6];
  460. int d= FFABS(b) - ((FFABS(a) + FFABS(c))>>1);
  461. d= FFMAX(d, 0);
  462. if(d < co->QP*2){
  463. int v = d * FFSIGN(-b);
  464. src[l2] +=v>>3;
  465. src[l3] +=v>>2;
  466. src[l4] +=(3*v)>>3;
  467. src[l5] -=(3*v)>>3;
  468. src[l6] -=v>>2;
  469. src[l7] -=v>>3;
  470. }
  471. src++;
  472. }
  473. #endif //TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  474. }
  475. #if !TEMPLATE_PP_ALTIVEC
  476. static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext *c)
  477. {
  478. #if TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  479. /*
  480. uint8_t tmp[16];
  481. const int l1= stride;
  482. const int l2= stride + l1;
  483. const int l3= stride + l2;
  484. const int l4= (int)tmp - (int)src - stride*3;
  485. const int l5= (int)tmp - (int)src - stride*3 + 8;
  486. const int l6= stride*3 + l3;
  487. const int l7= stride + l6;
  488. const int l8= stride + l7;
  489. memcpy(tmp, src+stride*7, 8);
  490. memcpy(tmp+8, src+stride*8, 8);
  491. */
  492. src+= stride*4;
  493. __asm__ volatile(
  494. #if 0 //slightly more accurate and slightly slower
  495. "pxor %%mm7, %%mm7 \n\t" // 0
  496. "lea (%0, %1), %%"FF_REG_a" \n\t"
  497. "lea (%%"FF_REG_a", %1, 4), %%"FF_REG_c"\n\t"
  498. // 0 1 2 3 4 5 6 7
  499. // %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 ecx+%1 ecx+2%1
  500. // %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1
  501. "movq (%0, %1, 2), %%mm0 \n\t" // l2
  502. "movq (%0), %%mm1 \n\t" // l0
  503. "movq %%mm0, %%mm2 \n\t" // l2
  504. PAVGB(%%mm7, %%mm0) // ~l2/2
  505. PAVGB(%%mm1, %%mm0) // ~(l2 + 2l0)/4
  506. PAVGB(%%mm2, %%mm0) // ~(5l2 + 2l0)/8
  507. "movq (%%"FF_REG_a"), %%mm1 \n\t" // l1
  508. "movq (%%"FF_REG_a", %1, 2), %%mm3 \n\t" // l3
  509. "movq %%mm1, %%mm4 \n\t" // l1
  510. PAVGB(%%mm7, %%mm1) // ~l1/2
  511. PAVGB(%%mm3, %%mm1) // ~(l1 + 2l3)/4
  512. PAVGB(%%mm4, %%mm1) // ~(5l1 + 2l3)/8
  513. "movq %%mm0, %%mm4 \n\t" // ~(5l2 + 2l0)/8
  514. "psubusb %%mm1, %%mm0 \n\t"
  515. "psubusb %%mm4, %%mm1 \n\t"
  516. "por %%mm0, %%mm1 \n\t" // ~|2l0 - 5l1 + 5l2 - 2l3|/8
  517. // mm1= |lenergy|, mm2= l2, mm3= l3, mm7=0
  518. "movq (%0, %1, 4), %%mm0 \n\t" // l4
  519. "movq %%mm0, %%mm4 \n\t" // l4
  520. PAVGB(%%mm7, %%mm0) // ~l4/2
  521. PAVGB(%%mm2, %%mm0) // ~(l4 + 2l2)/4
  522. PAVGB(%%mm4, %%mm0) // ~(5l4 + 2l2)/8
  523. "movq (%%"FF_REG_c"), %%mm2 \n\t" // l5
  524. "movq %%mm3, %%mm5 \n\t" // l3
  525. PAVGB(%%mm7, %%mm3) // ~l3/2
  526. PAVGB(%%mm2, %%mm3) // ~(l3 + 2l5)/4
  527. PAVGB(%%mm5, %%mm3) // ~(5l3 + 2l5)/8
  528. "movq %%mm0, %%mm6 \n\t" // ~(5l4 + 2l2)/8
  529. "psubusb %%mm3, %%mm0 \n\t"
  530. "psubusb %%mm6, %%mm3 \n\t"
  531. "por %%mm0, %%mm3 \n\t" // ~|2l2 - 5l3 + 5l4 - 2l5|/8
  532. "pcmpeqb %%mm7, %%mm0 \n\t" // SIGN(2l2 - 5l3 + 5l4 - 2l5)
  533. // mm0= SIGN(menergy), mm1= |lenergy|, mm2= l5, mm3= |menergy|, mm4=l4, mm5= l3, mm7=0
  534. "movq (%%"FF_REG_c", %1), %%mm6 \n\t" // l6
  535. "movq %%mm6, %%mm5 \n\t" // l6
  536. PAVGB(%%mm7, %%mm6) // ~l6/2
  537. PAVGB(%%mm4, %%mm6) // ~(l6 + 2l4)/4
  538. PAVGB(%%mm5, %%mm6) // ~(5l6 + 2l4)/8
  539. "movq (%%"FF_REG_c", %1, 2), %%mm5 \n\t" // l7
  540. "movq %%mm2, %%mm4 \n\t" // l5
  541. PAVGB(%%mm7, %%mm2) // ~l5/2
  542. PAVGB(%%mm5, %%mm2) // ~(l5 + 2l7)/4
  543. PAVGB(%%mm4, %%mm2) // ~(5l5 + 2l7)/8
  544. "movq %%mm6, %%mm4 \n\t" // ~(5l6 + 2l4)/8
  545. "psubusb %%mm2, %%mm6 \n\t"
  546. "psubusb %%mm4, %%mm2 \n\t"
  547. "por %%mm6, %%mm2 \n\t" // ~|2l4 - 5l5 + 5l6 - 2l7|/8
  548. // mm0= SIGN(menergy), mm1= |lenergy|/8, mm2= |renergy|/8, mm3= |menergy|/8, mm7=0
  549. PMINUB(%%mm2, %%mm1, %%mm4) // MIN(|lenergy|,|renergy|)/8
  550. "movq %2, %%mm4 \n\t" // QP //FIXME QP+1 ?
  551. "paddusb "MANGLE(b01)", %%mm4 \n\t"
  552. "pcmpgtb %%mm3, %%mm4 \n\t" // |menergy|/8 < QP
  553. "psubusb %%mm1, %%mm3 \n\t" // d=|menergy|/8-MIN(|lenergy|,|renergy|)/8
  554. "pand %%mm4, %%mm3 \n\t"
  555. "movq %%mm3, %%mm1 \n\t"
  556. // "psubusb "MANGLE(b01)", %%mm3 \n\t"
  557. PAVGB(%%mm7, %%mm3)
  558. PAVGB(%%mm7, %%mm3)
  559. "paddusb %%mm1, %%mm3 \n\t"
  560. // "paddusb "MANGLE(b01)", %%mm3 \n\t"
  561. "movq (%%"FF_REG_a", %1, 2), %%mm6 \n\t" //l3
  562. "movq (%0, %1, 4), %%mm5 \n\t" //l4
  563. "movq (%0, %1, 4), %%mm4 \n\t" //l4
  564. "psubusb %%mm6, %%mm5 \n\t"
  565. "psubusb %%mm4, %%mm6 \n\t"
  566. "por %%mm6, %%mm5 \n\t" // |l3-l4|
  567. "pcmpeqb %%mm7, %%mm6 \n\t" // SIGN(l3-l4)
  568. "pxor %%mm6, %%mm0 \n\t"
  569. "pand %%mm0, %%mm3 \n\t"
  570. PMINUB(%%mm5, %%mm3, %%mm0)
  571. "psubusb "MANGLE(b01)", %%mm3 \n\t"
  572. PAVGB(%%mm7, %%mm3)
  573. "movq (%%"FF_REG_a", %1, 2), %%mm0 \n\t"
  574. "movq (%0, %1, 4), %%mm2 \n\t"
  575. "pxor %%mm6, %%mm0 \n\t"
  576. "pxor %%mm6, %%mm2 \n\t"
  577. "psubb %%mm3, %%mm0 \n\t"
  578. "paddb %%mm3, %%mm2 \n\t"
  579. "pxor %%mm6, %%mm0 \n\t"
  580. "pxor %%mm6, %%mm2 \n\t"
  581. "movq %%mm0, (%%"FF_REG_a", %1, 2) \n\t"
  582. "movq %%mm2, (%0, %1, 4) \n\t"
  583. #endif //0
  584. "lea (%0, %1), %%"FF_REG_a" \n\t"
  585. "pcmpeqb %%mm6, %%mm6 \n\t" // -1
  586. // 0 1 2 3 4 5 6 7
  587. // %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 ecx+%1 ecx+2%1
  588. // %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1
  589. "movq (%%"FF_REG_a", %1, 2), %%mm1 \n\t" // l3
  590. "movq (%0, %1, 4), %%mm0 \n\t" // l4
  591. "pxor %%mm6, %%mm1 \n\t" // -l3-1
  592. PAVGB(%%mm1, %%mm0) // -q+128 = (l4-l3+256)/2
  593. // mm1=-l3-1, mm0=128-q
  594. "movq (%%"FF_REG_a", %1, 4), %%mm2 \n\t" // l5
  595. "movq (%%"FF_REG_a", %1), %%mm3 \n\t" // l2
  596. "pxor %%mm6, %%mm2 \n\t" // -l5-1
  597. "movq %%mm2, %%mm5 \n\t" // -l5-1
  598. "movq "MANGLE(b80)", %%mm4 \n\t" // 128
  599. "lea (%%"FF_REG_a", %1, 4), %%"FF_REG_c"\n\t"
  600. PAVGB(%%mm3, %%mm2) // (l2-l5+256)/2
  601. PAVGB(%%mm0, %%mm4) // ~(l4-l3)/4 + 128
  602. PAVGB(%%mm2, %%mm4) // ~(l2-l5)/4 +(l4-l3)/8 + 128
  603. PAVGB(%%mm0, %%mm4) // ~(l2-l5)/8 +5(l4-l3)/16 + 128
  604. // mm1=-l3-1, mm0=128-q, mm3=l2, mm4=menergy/16 + 128, mm5= -l5-1
  605. "movq (%%"FF_REG_a"), %%mm2 \n\t" // l1
  606. "pxor %%mm6, %%mm2 \n\t" // -l1-1
  607. PAVGB(%%mm3, %%mm2) // (l2-l1+256)/2
  608. PAVGB((%0), %%mm1) // (l0-l3+256)/2
  609. "movq "MANGLE(b80)", %%mm3 \n\t" // 128
  610. PAVGB(%%mm2, %%mm3) // ~(l2-l1)/4 + 128
  611. PAVGB(%%mm1, %%mm3) // ~(l0-l3)/4 +(l2-l1)/8 + 128
  612. PAVGB(%%mm2, %%mm3) // ~(l0-l3)/8 +5(l2-l1)/16 + 128
  613. // mm0=128-q, mm3=lenergy/16 + 128, mm4= menergy/16 + 128, mm5= -l5-1
  614. PAVGB((%%FF_REGc, %1), %%mm5) // (l6-l5+256)/2
  615. "movq (%%"FF_REG_c", %1, 2), %%mm1 \n\t" // l7
  616. "pxor %%mm6, %%mm1 \n\t" // -l7-1
  617. PAVGB((%0, %1, 4), %%mm1) // (l4-l7+256)/2
  618. "movq "MANGLE(b80)", %%mm2 \n\t" // 128
  619. PAVGB(%%mm5, %%mm2) // ~(l6-l5)/4 + 128
  620. PAVGB(%%mm1, %%mm2) // ~(l4-l7)/4 +(l6-l5)/8 + 128
  621. PAVGB(%%mm5, %%mm2) // ~(l4-l7)/8 +5(l6-l5)/16 + 128
  622. // mm0=128-q, mm2=renergy/16 + 128, mm3=lenergy/16 + 128, mm4= menergy/16 + 128
  623. "movq "MANGLE(b00)", %%mm1 \n\t" // 0
  624. "movq "MANGLE(b00)", %%mm5 \n\t" // 0
  625. "psubb %%mm2, %%mm1 \n\t" // 128 - renergy/16
  626. "psubb %%mm3, %%mm5 \n\t" // 128 - lenergy/16
  627. PMAXUB(%%mm1, %%mm2) // 128 + |renergy/16|
  628. PMAXUB(%%mm5, %%mm3) // 128 + |lenergy/16|
  629. PMINUB(%%mm2, %%mm3, %%mm1) // 128 + MIN(|lenergy|,|renergy|)/16
  630. // mm0=128-q, mm3=128 + MIN(|lenergy|,|renergy|)/16, mm4= menergy/16 + 128
  631. "movq "MANGLE(b00)", %%mm7 \n\t" // 0
  632. "movq %2, %%mm2 \n\t" // QP
  633. PAVGB(%%mm6, %%mm2) // 128 + QP/2
  634. "psubb %%mm6, %%mm2 \n\t"
  635. "movq %%mm4, %%mm1 \n\t"
  636. "pcmpgtb %%mm7, %%mm1 \n\t" // SIGN(menergy)
  637. "pxor %%mm1, %%mm4 \n\t"
  638. "psubb %%mm1, %%mm4 \n\t" // 128 + |menergy|/16
  639. "pcmpgtb %%mm4, %%mm2 \n\t" // |menergy|/16 < QP/2
  640. "psubusb %%mm3, %%mm4 \n\t" //d=|menergy|/16 - MIN(|lenergy|,|renergy|)/16
  641. // mm0=128-q, mm1= SIGN(menergy), mm2= |menergy|/16 < QP/2, mm4= d/16
  642. "movq %%mm4, %%mm3 \n\t" // d
  643. "psubusb "MANGLE(b01)", %%mm4 \n\t"
  644. PAVGB(%%mm7, %%mm4) // d/32
  645. PAVGB(%%mm7, %%mm4) // (d + 32)/64
  646. "paddb %%mm3, %%mm4 \n\t" // 5d/64
  647. "pand %%mm2, %%mm4 \n\t"
  648. "movq "MANGLE(b80)", %%mm5 \n\t" // 128
  649. "psubb %%mm0, %%mm5 \n\t" // q
  650. "paddsb %%mm6, %%mm5 \n\t" // fix bad rounding
  651. "pcmpgtb %%mm5, %%mm7 \n\t" // SIGN(q)
  652. "pxor %%mm7, %%mm5 \n\t"
  653. PMINUB(%%mm5, %%mm4, %%mm3) // MIN(|q|, 5d/64)
  654. "pxor %%mm1, %%mm7 \n\t" // SIGN(d*q)
  655. "pand %%mm7, %%mm4 \n\t"
  656. "movq (%%"FF_REG_a", %1, 2), %%mm0 \n\t"
  657. "movq (%0, %1, 4), %%mm2 \n\t"
  658. "pxor %%mm1, %%mm0 \n\t"
  659. "pxor %%mm1, %%mm2 \n\t"
  660. "paddb %%mm4, %%mm0 \n\t"
  661. "psubb %%mm4, %%mm2 \n\t"
  662. "pxor %%mm1, %%mm0 \n\t"
  663. "pxor %%mm1, %%mm2 \n\t"
  664. "movq %%mm0, (%%"FF_REG_a", %1, 2) \n\t"
  665. "movq %%mm2, (%0, %1, 4) \n\t"
  666. :
  667. : "r" (src), "r" ((x86_reg)stride), "m" (c->pQPb)
  668. NAMED_CONSTRAINTS_ADD(b80,b00,b01)
  669. : "%"FF_REG_a, "%"FF_REG_c
  670. );
  671. /*
  672. {
  673. int x;
  674. src-= stride;
  675. for(x=0; x<BLOCK_SIZE; x++){
  676. const int middleEnergy= 5*(src[l5] - src[l4]) + 2*(src[l3] - src[l6]);
  677. if(FFABS(middleEnergy)< 8*QP){
  678. const int q=(src[l4] - src[l5])/2;
  679. const int leftEnergy= 5*(src[l3] - src[l2]) + 2*(src[l1] - src[l4]);
  680. const int rightEnergy= 5*(src[l7] - src[l6]) + 2*(src[l5] - src[l8]);
  681. int d= FFABS(middleEnergy) - FFMIN( FFABS(leftEnergy), FFABS(rightEnergy) );
  682. d= FFMAX(d, 0);
  683. d= (5*d + 32) >> 6;
  684. d*= FFSIGN(-middleEnergy);
  685. if(q>0){
  686. d= d<0 ? 0 : d;
  687. d= d>q ? q : d;
  688. }else{
  689. d= d>0 ? 0 : d;
  690. d= d<q ? q : d;
  691. }
  692. src[l4]-= d;
  693. src[l5]+= d;
  694. }
  695. src++;
  696. }
  697. src-=8;
  698. for(x=0; x<8; x++){
  699. int y;
  700. for(y=4; y<6; y++){
  701. int d= src[x+y*stride] - tmp[x+(y-4)*8];
  702. int ad= FFABS(d);
  703. static int max=0;
  704. static int sum=0;
  705. static int num=0;
  706. static int bias=0;
  707. if(max<ad) max=ad;
  708. sum+= ad>3 ? 1 : 0;
  709. if(ad>3){
  710. src[0] = src[7] = src[stride*7] = src[(stride+1)*7]=255;
  711. }
  712. if(y==4) bias+=d;
  713. num++;
  714. if(num%1000000 == 0){
  715. av_log(c, AV_LOG_INFO, " %d %d %d %d\n", num, sum, max, bias);
  716. }
  717. }
  718. }
  719. }
  720. */
  721. #elif TEMPLATE_PP_MMX
  722. DECLARE_ALIGNED(8, uint64_t, tmp)[4]; // make space for 4 8-byte vars
  723. src+= stride*4;
  724. __asm__ volatile(
  725. "pxor %%mm7, %%mm7 \n\t"
  726. // 0 1 2 3 4 5 6 7
  727. // %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 edx+%1 edx+2%1
  728. // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1
  729. "movq (%0), %%mm0 \n\t"
  730. "movq %%mm0, %%mm1 \n\t"
  731. "punpcklbw %%mm7, %%mm0 \n\t" // low part of line 0
  732. "punpckhbw %%mm7, %%mm1 \n\t" // high part of line 0
  733. "movq (%0, %1), %%mm2 \n\t"
  734. "lea (%0, %1, 2), %%"FF_REG_a" \n\t"
  735. "movq %%mm2, %%mm3 \n\t"
  736. "punpcklbw %%mm7, %%mm2 \n\t" // low part of line 1
  737. "punpckhbw %%mm7, %%mm3 \n\t" // high part of line 1
  738. "movq (%%"FF_REG_a"), %%mm4 \n\t"
  739. "movq %%mm4, %%mm5 \n\t"
  740. "punpcklbw %%mm7, %%mm4 \n\t" // low part of line 2
  741. "punpckhbw %%mm7, %%mm5 \n\t" // high part of line 2
  742. "paddw %%mm0, %%mm0 \n\t" // 2L0
  743. "paddw %%mm1, %%mm1 \n\t" // 2H0
  744. "psubw %%mm4, %%mm2 \n\t" // L1 - L2
  745. "psubw %%mm5, %%mm3 \n\t" // H1 - H2
  746. "psubw %%mm2, %%mm0 \n\t" // 2L0 - L1 + L2
  747. "psubw %%mm3, %%mm1 \n\t" // 2H0 - H1 + H2
  748. "psllw $2, %%mm2 \n\t" // 4L1 - 4L2
  749. "psllw $2, %%mm3 \n\t" // 4H1 - 4H2
  750. "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2
  751. "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2
  752. "movq (%%"FF_REG_a", %1), %%mm2 \n\t"
  753. "movq %%mm2, %%mm3 \n\t"
  754. "punpcklbw %%mm7, %%mm2 \n\t" // L3
  755. "punpckhbw %%mm7, %%mm3 \n\t" // H3
  756. "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - L3
  757. "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - H3
  758. "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
  759. "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
  760. "movq %%mm0, (%3) \n\t" // 2L0 - 5L1 + 5L2 - 2L3
  761. "movq %%mm1, 8(%3) \n\t" // 2H0 - 5H1 + 5H2 - 2H3
  762. "movq (%%"FF_REG_a", %1, 2), %%mm0 \n\t"
  763. "movq %%mm0, %%mm1 \n\t"
  764. "punpcklbw %%mm7, %%mm0 \n\t" // L4
  765. "punpckhbw %%mm7, %%mm1 \n\t" // H4
  766. "psubw %%mm0, %%mm2 \n\t" // L3 - L4
  767. "psubw %%mm1, %%mm3 \n\t" // H3 - H4
  768. "movq %%mm2, 16(%3) \n\t" // L3 - L4
  769. "movq %%mm3, 24(%3) \n\t" // H3 - H4
  770. "paddw %%mm4, %%mm4 \n\t" // 2L2
  771. "paddw %%mm5, %%mm5 \n\t" // 2H2
  772. "psubw %%mm2, %%mm4 \n\t" // 2L2 - L3 + L4
  773. "psubw %%mm3, %%mm5 \n\t" // 2H2 - H3 + H4
  774. "lea (%%"FF_REG_a", %1), %0 \n\t"
  775. "psllw $2, %%mm2 \n\t" // 4L3 - 4L4
  776. "psllw $2, %%mm3 \n\t" // 4H3 - 4H4
  777. "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4
  778. "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4
  779. //50 opcodes so far
  780. "movq (%0, %1, 2), %%mm2 \n\t"
  781. "movq %%mm2, %%mm3 \n\t"
  782. "punpcklbw %%mm7, %%mm2 \n\t" // L5
  783. "punpckhbw %%mm7, %%mm3 \n\t" // H5
  784. "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - L5
  785. "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - H5
  786. "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - 2L5
  787. "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - 2H5
  788. "movq (%%"FF_REG_a", %1, 4), %%mm6 \n\t"
  789. "punpcklbw %%mm7, %%mm6 \n\t" // L6
  790. "psubw %%mm6, %%mm2 \n\t" // L5 - L6
  791. "movq (%%"FF_REG_a", %1, 4), %%mm6 \n\t"
  792. "punpckhbw %%mm7, %%mm6 \n\t" // H6
  793. "psubw %%mm6, %%mm3 \n\t" // H5 - H6
  794. "paddw %%mm0, %%mm0 \n\t" // 2L4
  795. "paddw %%mm1, %%mm1 \n\t" // 2H4
  796. "psubw %%mm2, %%mm0 \n\t" // 2L4 - L5 + L6
  797. "psubw %%mm3, %%mm1 \n\t" // 2H4 - H5 + H6
  798. "psllw $2, %%mm2 \n\t" // 4L5 - 4L6
  799. "psllw $2, %%mm3 \n\t" // 4H5 - 4H6
  800. "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6
  801. "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6
  802. "movq (%0, %1, 4), %%mm2 \n\t"
  803. "movq %%mm2, %%mm3 \n\t"
  804. "punpcklbw %%mm7, %%mm2 \n\t" // L7
  805. "punpckhbw %%mm7, %%mm3 \n\t" // H7
  806. "paddw %%mm2, %%mm2 \n\t" // 2L7
  807. "paddw %%mm3, %%mm3 \n\t" // 2H7
  808. "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6 - 2L7
  809. "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6 - 2H7
  810. "movq (%3), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
  811. "movq 8(%3), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
  812. #if TEMPLATE_PP_MMXEXT
  813. "movq %%mm7, %%mm6 \n\t" // 0
  814. "psubw %%mm0, %%mm6 \n\t"
  815. "pmaxsw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
  816. "movq %%mm7, %%mm6 \n\t" // 0
  817. "psubw %%mm1, %%mm6 \n\t"
  818. "pmaxsw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
  819. "movq %%mm7, %%mm6 \n\t" // 0
  820. "psubw %%mm2, %%mm6 \n\t"
  821. "pmaxsw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
  822. "movq %%mm7, %%mm6 \n\t" // 0
  823. "psubw %%mm3, %%mm6 \n\t"
  824. "pmaxsw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
  825. #else
  826. "movq %%mm7, %%mm6 \n\t" // 0
  827. "pcmpgtw %%mm0, %%mm6 \n\t"
  828. "pxor %%mm6, %%mm0 \n\t"
  829. "psubw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
  830. "movq %%mm7, %%mm6 \n\t" // 0
  831. "pcmpgtw %%mm1, %%mm6 \n\t"
  832. "pxor %%mm6, %%mm1 \n\t"
  833. "psubw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
  834. "movq %%mm7, %%mm6 \n\t" // 0
  835. "pcmpgtw %%mm2, %%mm6 \n\t"
  836. "pxor %%mm6, %%mm2 \n\t"
  837. "psubw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
  838. "movq %%mm7, %%mm6 \n\t" // 0
  839. "pcmpgtw %%mm3, %%mm6 \n\t"
  840. "pxor %%mm6, %%mm3 \n\t"
  841. "psubw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
  842. #endif
  843. #if TEMPLATE_PP_MMXEXT
  844. "pminsw %%mm2, %%mm0 \n\t"
  845. "pminsw %%mm3, %%mm1 \n\t"
  846. #else
  847. "movq %%mm0, %%mm6 \n\t"
  848. "psubusw %%mm2, %%mm6 \n\t"
  849. "psubw %%mm6, %%mm0 \n\t"
  850. "movq %%mm1, %%mm6 \n\t"
  851. "psubusw %%mm3, %%mm6 \n\t"
  852. "psubw %%mm6, %%mm1 \n\t"
  853. #endif
  854. "movd %2, %%mm2 \n\t" // QP
  855. "punpcklbw %%mm7, %%mm2 \n\t"
  856. "movq %%mm7, %%mm6 \n\t" // 0
  857. "pcmpgtw %%mm4, %%mm6 \n\t" // sign(2L2 - 5L3 + 5L4 - 2L5)
  858. "pxor %%mm6, %%mm4 \n\t"
  859. "psubw %%mm6, %%mm4 \n\t" // |2L2 - 5L3 + 5L4 - 2L5|
  860. "pcmpgtw %%mm5, %%mm7 \n\t" // sign(2H2 - 5H3 + 5H4 - 2H5)
  861. "pxor %%mm7, %%mm5 \n\t"
  862. "psubw %%mm7, %%mm5 \n\t" // |2H2 - 5H3 + 5H4 - 2H5|
  863. // 100 opcodes
  864. "psllw $3, %%mm2 \n\t" // 8QP
  865. "movq %%mm2, %%mm3 \n\t" // 8QP
  866. "pcmpgtw %%mm4, %%mm2 \n\t"
  867. "pcmpgtw %%mm5, %%mm3 \n\t"
  868. "pand %%mm2, %%mm4 \n\t"
  869. "pand %%mm3, %%mm5 \n\t"
  870. "psubusw %%mm0, %%mm4 \n\t" // hd
  871. "psubusw %%mm1, %%mm5 \n\t" // ld
  872. "movq "MANGLE(w05)", %%mm2 \n\t" // 5
  873. "pmullw %%mm2, %%mm4 \n\t"
  874. "pmullw %%mm2, %%mm5 \n\t"
  875. "movq "MANGLE(w20)", %%mm2 \n\t" // 32
  876. "paddw %%mm2, %%mm4 \n\t"
  877. "paddw %%mm2, %%mm5 \n\t"
  878. "psrlw $6, %%mm4 \n\t"
  879. "psrlw $6, %%mm5 \n\t"
  880. "movq 16(%3), %%mm0 \n\t" // L3 - L4
  881. "movq 24(%3), %%mm1 \n\t" // H3 - H4
  882. "pxor %%mm2, %%mm2 \n\t"
  883. "pxor %%mm3, %%mm3 \n\t"
  884. "pcmpgtw %%mm0, %%mm2 \n\t" // sign (L3-L4)
  885. "pcmpgtw %%mm1, %%mm3 \n\t" // sign (H3-H4)
  886. "pxor %%mm2, %%mm0 \n\t"
  887. "pxor %%mm3, %%mm1 \n\t"
  888. "psubw %%mm2, %%mm0 \n\t" // |L3-L4|
  889. "psubw %%mm3, %%mm1 \n\t" // |H3-H4|
  890. "psrlw $1, %%mm0 \n\t" // |L3 - L4|/2
  891. "psrlw $1, %%mm1 \n\t" // |H3 - H4|/2
  892. "pxor %%mm6, %%mm2 \n\t"
  893. "pxor %%mm7, %%mm3 \n\t"
  894. "pand %%mm2, %%mm4 \n\t"
  895. "pand %%mm3, %%mm5 \n\t"
  896. #if TEMPLATE_PP_MMXEXT
  897. "pminsw %%mm0, %%mm4 \n\t"
  898. "pminsw %%mm1, %%mm5 \n\t"
  899. #else
  900. "movq %%mm4, %%mm2 \n\t"
  901. "psubusw %%mm0, %%mm2 \n\t"
  902. "psubw %%mm2, %%mm4 \n\t"
  903. "movq %%mm5, %%mm2 \n\t"
  904. "psubusw %%mm1, %%mm2 \n\t"
  905. "psubw %%mm2, %%mm5 \n\t"
  906. #endif
  907. "pxor %%mm6, %%mm4 \n\t"
  908. "pxor %%mm7, %%mm5 \n\t"
  909. "psubw %%mm6, %%mm4 \n\t"
  910. "psubw %%mm7, %%mm5 \n\t"
  911. "packsswb %%mm5, %%mm4 \n\t"
  912. "movq (%0), %%mm0 \n\t"
  913. "paddb %%mm4, %%mm0 \n\t"
  914. "movq %%mm0, (%0) \n\t"
  915. "movq (%0, %1), %%mm0 \n\t"
  916. "psubb %%mm4, %%mm0 \n\t"
  917. "movq %%mm0, (%0, %1) \n\t"
  918. : "+r" (src)
  919. : "r" ((x86_reg)stride), "m" (c->pQPb), "r"(tmp)
  920. NAMED_CONSTRAINTS_ADD(w05,w20)
  921. : "%"FF_REG_a
  922. );
  923. #else //TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  924. const int l1= stride;
  925. const int l2= stride + l1;
  926. const int l3= stride + l2;
  927. const int l4= stride + l3;
  928. const int l5= stride + l4;
  929. const int l6= stride + l5;
  930. const int l7= stride + l6;
  931. const int l8= stride + l7;
  932. // const int l9= stride + l8;
  933. int x;
  934. src+= stride*3;
  935. for(x=0; x<BLOCK_SIZE; x++){
  936. const int middleEnergy= 5*(src[l5] - src[l4]) + 2*(src[l3] - src[l6]);
  937. if(FFABS(middleEnergy) < 8*c->QP){
  938. const int q=(src[l4] - src[l5])/2;
  939. const int leftEnergy= 5*(src[l3] - src[l2]) + 2*(src[l1] - src[l4]);
  940. const int rightEnergy= 5*(src[l7] - src[l6]) + 2*(src[l5] - src[l8]);
  941. int d= FFABS(middleEnergy) - FFMIN( FFABS(leftEnergy), FFABS(rightEnergy) );
  942. d= FFMAX(d, 0);
  943. d= (5*d + 32) >> 6;
  944. d*= FFSIGN(-middleEnergy);
  945. if(q>0){
  946. d = FFMAX(d, 0);
  947. d = FFMIN(d, q);
  948. }else{
  949. d = FFMIN(d, 0);
  950. d = FFMAX(d, q);
  951. }
  952. src[l4]-= d;
  953. src[l5]+= d;
  954. }
  955. src++;
  956. }
  957. #endif //TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  958. }
  959. #endif //TEMPLATE_PP_ALTIVEC
  960. #if !TEMPLATE_PP_ALTIVEC
  961. static inline void RENAME(dering)(uint8_t src[], int stride, PPContext *c)
  962. {
  963. #if HAVE_7REGS && (TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW)
  964. DECLARE_ALIGNED(8, uint64_t, tmp)[3];
  965. __asm__ volatile(
  966. "pxor %%mm6, %%mm6 \n\t"
  967. "pcmpeqb %%mm7, %%mm7 \n\t"
  968. "movq %2, %%mm0 \n\t"
  969. "punpcklbw %%mm6, %%mm0 \n\t"
  970. "psrlw $1, %%mm0 \n\t"
  971. "psubw %%mm7, %%mm0 \n\t"
  972. "packuswb %%mm0, %%mm0 \n\t"
  973. "movq %%mm0, %3 \n\t"
  974. "lea (%0, %1), %%"FF_REG_a" \n\t"
  975. "lea (%%"FF_REG_a", %1, 4), %%"FF_REG_d"\n\t"
  976. // 0 1 2 3 4 5 6 7 8 9
  977. // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
  978. #undef REAL_FIND_MIN_MAX
  979. #undef FIND_MIN_MAX
  980. #if TEMPLATE_PP_MMXEXT
  981. #define REAL_FIND_MIN_MAX(addr)\
  982. "movq " #addr ", %%mm0 \n\t"\
  983. "pminub %%mm0, %%mm7 \n\t"\
  984. "pmaxub %%mm0, %%mm6 \n\t"
  985. #else
  986. #define REAL_FIND_MIN_MAX(addr)\
  987. "movq " #addr ", %%mm0 \n\t"\
  988. "movq %%mm7, %%mm1 \n\t"\
  989. "psubusb %%mm0, %%mm6 \n\t"\
  990. "paddb %%mm0, %%mm6 \n\t"\
  991. "psubusb %%mm0, %%mm1 \n\t"\
  992. "psubb %%mm1, %%mm7 \n\t"
  993. #endif
  994. #define FIND_MIN_MAX(addr) REAL_FIND_MIN_MAX(addr)
  995. FIND_MIN_MAX((%%FF_REGa))
  996. FIND_MIN_MAX((%%FF_REGa, %1))
  997. FIND_MIN_MAX((%%FF_REGa, %1, 2))
  998. FIND_MIN_MAX((%0, %1, 4))
  999. FIND_MIN_MAX((%%FF_REGd))
  1000. FIND_MIN_MAX((%%FF_REGd, %1))
  1001. FIND_MIN_MAX((%%FF_REGd, %1, 2))
  1002. FIND_MIN_MAX((%0, %1, 8))
  1003. "movq %%mm7, %%mm4 \n\t"
  1004. "psrlq $8, %%mm7 \n\t"
  1005. #if TEMPLATE_PP_MMXEXT
  1006. "pminub %%mm4, %%mm7 \n\t" // min of pixels
  1007. "pshufw $0xF9, %%mm7, %%mm4 \n\t"
  1008. "pminub %%mm4, %%mm7 \n\t" // min of pixels
  1009. "pshufw $0xFE, %%mm7, %%mm4 \n\t"
  1010. "pminub %%mm4, %%mm7 \n\t"
  1011. #else
  1012. "movq %%mm7, %%mm1 \n\t"
  1013. "psubusb %%mm4, %%mm1 \n\t"
  1014. "psubb %%mm1, %%mm7 \n\t"
  1015. "movq %%mm7, %%mm4 \n\t"
  1016. "psrlq $16, %%mm7 \n\t"
  1017. "movq %%mm7, %%mm1 \n\t"
  1018. "psubusb %%mm4, %%mm1 \n\t"
  1019. "psubb %%mm1, %%mm7 \n\t"
  1020. "movq %%mm7, %%mm4 \n\t"
  1021. "psrlq $32, %%mm7 \n\t"
  1022. "movq %%mm7, %%mm1 \n\t"
  1023. "psubusb %%mm4, %%mm1 \n\t"
  1024. "psubb %%mm1, %%mm7 \n\t"
  1025. #endif
  1026. "movq %%mm6, %%mm4 \n\t"
  1027. "psrlq $8, %%mm6 \n\t"
  1028. #if TEMPLATE_PP_MMXEXT
  1029. "pmaxub %%mm4, %%mm6 \n\t" // max of pixels
  1030. "pshufw $0xF9, %%mm6, %%mm4 \n\t"
  1031. "pmaxub %%mm4, %%mm6 \n\t"
  1032. "pshufw $0xFE, %%mm6, %%mm4 \n\t"
  1033. "pmaxub %%mm4, %%mm6 \n\t"
  1034. #else
  1035. "psubusb %%mm4, %%mm6 \n\t"
  1036. "paddb %%mm4, %%mm6 \n\t"
  1037. "movq %%mm6, %%mm4 \n\t"
  1038. "psrlq $16, %%mm6 \n\t"
  1039. "psubusb %%mm4, %%mm6 \n\t"
  1040. "paddb %%mm4, %%mm6 \n\t"
  1041. "movq %%mm6, %%mm4 \n\t"
  1042. "psrlq $32, %%mm6 \n\t"
  1043. "psubusb %%mm4, %%mm6 \n\t"
  1044. "paddb %%mm4, %%mm6 \n\t"
  1045. #endif
  1046. "movq %%mm6, %%mm0 \n\t" // max
  1047. "psubb %%mm7, %%mm6 \n\t" // max - min
  1048. "push %%"FF_REG_a" \n\t"
  1049. "movd %%mm6, %%eax \n\t"
  1050. "cmpb "MANGLE(deringThreshold)", %%al \n\t"
  1051. "pop %%"FF_REG_a" \n\t"
  1052. " jb 1f \n\t"
  1053. PAVGB(%%mm0, %%mm7) // a=(max + min)/2
  1054. "punpcklbw %%mm7, %%mm7 \n\t"
  1055. "punpcklbw %%mm7, %%mm7 \n\t"
  1056. "punpcklbw %%mm7, %%mm7 \n\t"
  1057. "movq %%mm7, (%4) \n\t"
  1058. "movq (%0), %%mm0 \n\t" // L10
  1059. "movq %%mm0, %%mm1 \n\t" // L10
  1060. "movq %%mm0, %%mm2 \n\t" // L10
  1061. "psllq $8, %%mm1 \n\t"
  1062. "psrlq $8, %%mm2 \n\t"
  1063. "movd -4(%0), %%mm3 \n\t"
  1064. "movd 8(%0), %%mm4 \n\t"
  1065. "psrlq $24, %%mm3 \n\t"
  1066. "psllq $56, %%mm4 \n\t"
  1067. "por %%mm3, %%mm1 \n\t" // L00
  1068. "por %%mm4, %%mm2 \n\t" // L20
  1069. "movq %%mm1, %%mm3 \n\t" // L00
  1070. PAVGB(%%mm2, %%mm1) // (L20 + L00)/2
  1071. PAVGB(%%mm0, %%mm1) // (L20 + L00 + 2L10)/4
  1072. "psubusb %%mm7, %%mm0 \n\t"
  1073. "psubusb %%mm7, %%mm2 \n\t"
  1074. "psubusb %%mm7, %%mm3 \n\t"
  1075. "pcmpeqb "MANGLE(b00)", %%mm0 \n\t" // L10 > a ? 0 : -1
  1076. "pcmpeqb "MANGLE(b00)", %%mm2 \n\t" // L20 > a ? 0 : -1
  1077. "pcmpeqb "MANGLE(b00)", %%mm3 \n\t" // L00 > a ? 0 : -1
  1078. "paddb %%mm2, %%mm0 \n\t"
  1079. "paddb %%mm3, %%mm0 \n\t"
  1080. "movq (%%"FF_REG_a"), %%mm2 \n\t" // L11
  1081. "movq %%mm2, %%mm3 \n\t" // L11
  1082. "movq %%mm2, %%mm4 \n\t" // L11
  1083. "psllq $8, %%mm3 \n\t"
  1084. "psrlq $8, %%mm4 \n\t"
  1085. "movd -4(%%"FF_REG_a"), %%mm5 \n\t"
  1086. "movd 8(%%"FF_REG_a"), %%mm6 \n\t"
  1087. "psrlq $24, %%mm5 \n\t"
  1088. "psllq $56, %%mm6 \n\t"
  1089. "por %%mm5, %%mm3 \n\t" // L01
  1090. "por %%mm6, %%mm4 \n\t" // L21
  1091. "movq %%mm3, %%mm5 \n\t" // L01
  1092. PAVGB(%%mm4, %%mm3) // (L21 + L01)/2
  1093. PAVGB(%%mm2, %%mm3) // (L21 + L01 + 2L11)/4
  1094. "psubusb %%mm7, %%mm2 \n\t"
  1095. "psubusb %%mm7, %%mm4 \n\t"
  1096. "psubusb %%mm7, %%mm5 \n\t"
  1097. "pcmpeqb "MANGLE(b00)", %%mm2 \n\t" // L11 > a ? 0 : -1
  1098. "pcmpeqb "MANGLE(b00)", %%mm4 \n\t" // L21 > a ? 0 : -1
  1099. "pcmpeqb "MANGLE(b00)", %%mm5 \n\t" // L01 > a ? 0 : -1
  1100. "paddb %%mm4, %%mm2 \n\t"
  1101. "paddb %%mm5, %%mm2 \n\t"
  1102. // 0, 2, 3, 1
  1103. #define REAL_DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1) \
  1104. "movq " #src ", " #sx " \n\t" /* src[0] */\
  1105. "movq " #sx ", " #lx " \n\t" /* src[0] */\
  1106. "movq " #sx ", " #t0 " \n\t" /* src[0] */\
  1107. "psllq $8, " #lx " \n\t"\
  1108. "psrlq $8, " #t0 " \n\t"\
  1109. "movd -4" #src ", " #t1 " \n\t"\
  1110. "psrlq $24, " #t1 " \n\t"\
  1111. "por " #t1 ", " #lx " \n\t" /* src[-1] */\
  1112. "movd 8" #src ", " #t1 " \n\t"\
  1113. "psllq $56, " #t1 " \n\t"\
  1114. "por " #t1 ", " #t0 " \n\t" /* src[+1] */\
  1115. "movq " #lx ", " #t1 " \n\t" /* src[-1] */\
  1116. PAVGB(t0, lx) /* (src[-1] + src[+1])/2 */\
  1117. PAVGB(sx, lx) /* (src[-1] + 2src[0] + src[+1])/4 */\
  1118. PAVGB(lx, pplx) \
  1119. "movq " #lx ", 8(%4) \n\t"\
  1120. "movq (%4), " #lx " \n\t"\
  1121. "psubusb " #lx ", " #t1 " \n\t"\
  1122. "psubusb " #lx ", " #t0 " \n\t"\
  1123. "psubusb " #lx ", " #sx " \n\t"\
  1124. "movq "MANGLE(b00)", " #lx " \n\t"\
  1125. "pcmpeqb " #lx ", " #t1 " \n\t" /* src[-1] > a ? 0 : -1*/\
  1126. "pcmpeqb " #lx ", " #t0 " \n\t" /* src[+1] > a ? 0 : -1*/\
  1127. "pcmpeqb " #lx ", " #sx " \n\t" /* src[0] > a ? 0 : -1*/\
  1128. "paddb " #t1 ", " #t0 " \n\t"\
  1129. "paddb " #t0 ", " #sx " \n\t"\
  1130. \
  1131. PAVGB(plx, pplx) /* filtered */\
  1132. "movq " #dst ", " #t0 " \n\t" /* dst */\
  1133. "movq " #t0 ", " #t1 " \n\t" /* dst */\
  1134. "psubusb %3, " #t0 " \n\t"\
  1135. "paddusb %3, " #t1 " \n\t"\
  1136. PMAXUB(t0, pplx)\
  1137. PMINUB(t1, pplx, t0)\
  1138. "paddb " #sx ", " #ppsx " \n\t"\
  1139. "paddb " #psx ", " #ppsx " \n\t"\
  1140. "#paddb "MANGLE(b02)", " #ppsx " \n\t"\
  1141. "pand "MANGLE(b08)", " #ppsx " \n\t"\
  1142. "pcmpeqb " #lx ", " #ppsx " \n\t"\
  1143. "pand " #ppsx ", " #pplx " \n\t"\
  1144. "pandn " #dst ", " #ppsx " \n\t"\
  1145. "por " #pplx ", " #ppsx " \n\t"\
  1146. "movq " #ppsx ", " #dst " \n\t"\
  1147. "movq 8(%4), " #lx " \n\t"
  1148. #define DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1) \
  1149. REAL_DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1)
  1150. /*
  1151. 0000000
  1152. 1111111
  1153. 1111110
  1154. 1111101
  1155. 1111100
  1156. 1111011
  1157. 1111010
  1158. 1111001
  1159. 1111000
  1160. 1110111
  1161. */
  1162. //DERING_CORE(dst ,src ,ppsx ,psx ,sx ,pplx ,plx ,lx ,t0 ,t1)
  1163. DERING_CORE((%%FF_REGa) ,(%%FF_REGa, %1) ,%%mm0,%%mm2,%%mm4,%%mm1,%%mm3,%%mm5,%%mm6,%%mm7)
  1164. DERING_CORE((%%FF_REGa, %1) ,(%%FF_REGa, %1, 2),%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,%%mm6,%%mm7)
  1165. DERING_CORE((%%FF_REGa, %1, 2),(%0, %1, 4) ,%%mm4,%%mm0,%%mm2,%%mm5,%%mm1,%%mm3,%%mm6,%%mm7)
  1166. DERING_CORE((%0, %1, 4) ,(%%FF_REGd) ,%%mm0,%%mm2,%%mm4,%%mm1,%%mm3,%%mm5,%%mm6,%%mm7)
  1167. DERING_CORE((%%FF_REGd) ,(%%FF_REGd, %1) ,%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,%%mm6,%%mm7)
  1168. DERING_CORE((%%FF_REGd, %1) ,(%%FF_REGd, %1, 2),%%mm4,%%mm0,%%mm2,%%mm5,%%mm1,%%mm3,%%mm6,%%mm7)
  1169. DERING_CORE((%%FF_REGd, %1, 2),(%0, %1, 8) ,%%mm0,%%mm2,%%mm4,%%mm1,%%mm3,%%mm5,%%mm6,%%mm7)
  1170. DERING_CORE((%0, %1, 8) ,(%%FF_REGd, %1, 4),%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,%%mm6,%%mm7)
  1171. "1: \n\t"
  1172. : : "r" (src), "r" ((x86_reg)stride), "m" (c->pQPb), "m"(c->pQPb2), "q"(tmp)
  1173. NAMED_CONSTRAINTS_ADD(deringThreshold,b00,b02,b08)
  1174. : "%"FF_REG_a, "%"FF_REG_d
  1175. );
  1176. #else // HAVE_7REGS && (TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW)
  1177. int y;
  1178. int min=255;
  1179. int max=0;
  1180. int avg;
  1181. uint8_t *p;
  1182. int s[10];
  1183. const int QP2= c->QP/2 + 1;
  1184. src --;
  1185. for(y=1; y<9; y++){
  1186. int x;
  1187. p= src + stride*y;
  1188. for(x=1; x<9; x++){
  1189. p++;
  1190. if(*p > max) max= *p;
  1191. if(*p < min) min= *p;
  1192. }
  1193. }
  1194. avg= (min + max + 1)>>1;
  1195. if(max - min <deringThreshold) return;
  1196. for(y=0; y<10; y++){
  1197. int t = 0;
  1198. if(src[stride*y + 0] > avg) t+= 1;
  1199. if(src[stride*y + 1] > avg) t+= 2;
  1200. if(src[stride*y + 2] > avg) t+= 4;
  1201. if(src[stride*y + 3] > avg) t+= 8;
  1202. if(src[stride*y + 4] > avg) t+= 16;
  1203. if(src[stride*y + 5] > avg) t+= 32;
  1204. if(src[stride*y + 6] > avg) t+= 64;
  1205. if(src[stride*y + 7] > avg) t+= 128;
  1206. if(src[stride*y + 8] > avg) t+= 256;
  1207. if(src[stride*y + 9] > avg) t+= 512;
  1208. t |= (~t)<<16;
  1209. t &= (t<<1) & (t>>1);
  1210. s[y] = t;
  1211. }
  1212. for(y=1; y<9; y++){
  1213. int t = s[y-1] & s[y] & s[y+1];
  1214. t|= t>>16;
  1215. s[y-1]= t;
  1216. }
  1217. for(y=1; y<9; y++){
  1218. int x;
  1219. int t = s[y-1];
  1220. p= src + stride*y;
  1221. for(x=1; x<9; x++){
  1222. p++;
  1223. if(t & (1<<x)){
  1224. int f= (*(p-stride-1)) + 2*(*(p-stride)) + (*(p-stride+1))
  1225. +2*(*(p -1)) + 4*(*p ) + 2*(*(p +1))
  1226. +(*(p+stride-1)) + 2*(*(p+stride)) + (*(p+stride+1));
  1227. f= (f + 8)>>4;
  1228. #ifdef DEBUG_DERING_THRESHOLD
  1229. __asm__ volatile("emms\n\t":);
  1230. {
  1231. static uint64_t numPixels=0;
  1232. if(x!=1 && x!=8 && y!=1 && y!=8) numPixels++;
  1233. // if((max-min)<20 || (max-min)*QP<200)
  1234. // if((max-min)*QP < 500)
  1235. // if(max-min<QP/2)
  1236. if(max-min < 20){
  1237. static int numSkipped=0;
  1238. static int errorSum=0;
  1239. static int worstQP=0;
  1240. static int worstRange=0;
  1241. static int worstDiff=0;
  1242. int diff= (f - *p);
  1243. int absDiff= FFABS(diff);
  1244. int error= diff*diff;
  1245. if(x==1 || x==8 || y==1 || y==8) continue;
  1246. numSkipped++;
  1247. if(absDiff > worstDiff){
  1248. worstDiff= absDiff;
  1249. worstQP= QP;
  1250. worstRange= max-min;
  1251. }
  1252. errorSum+= error;
  1253. if(1024LL*1024LL*1024LL % numSkipped == 0){
  1254. av_log(c, AV_LOG_INFO, "sum:%1.3f, skip:%d, wQP:%d, "
  1255. "wRange:%d, wDiff:%d, relSkip:%1.3f\n",
  1256. (float)errorSum/numSkipped, numSkipped, worstQP, worstRange,
  1257. worstDiff, (float)numSkipped/numPixels);
  1258. }
  1259. }
  1260. }
  1261. #endif
  1262. if (*p + QP2 < f) *p= *p + QP2;
  1263. else if(*p - QP2 > f) *p= *p - QP2;
  1264. else *p=f;
  1265. }
  1266. }
  1267. }
  1268. #ifdef DEBUG_DERING_THRESHOLD
  1269. if(max-min < 20){
  1270. for(y=1; y<9; y++){
  1271. int x;
  1272. int t = 0;
  1273. p= src + stride*y;
  1274. for(x=1; x<9; x++){
  1275. p++;
  1276. *p = FFMIN(*p + 20, 255);
  1277. }
  1278. }
  1279. // src[0] = src[7]=src[stride*7]=src[stride*7 + 7]=255;
  1280. }
  1281. #endif
  1282. #endif //TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  1283. }
  1284. #endif //TEMPLATE_PP_ALTIVEC
  1285. /**
  1286. * Deinterlace the given block by linearly interpolating every second line.
  1287. * will be called for every 8x8 block and can read & write from line 4-15
  1288. * lines 0-3 have been passed through the deblock / dering filters already, but can be read, too.
  1289. * lines 4-12 will be read into the deblocking filter and should be deinterlaced
  1290. */
  1291. static inline void RENAME(deInterlaceInterpolateLinear)(uint8_t src[], int stride)
  1292. {
  1293. #if TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  1294. src+= 4*stride;
  1295. __asm__ volatile(
  1296. "lea (%0, %1), %%"FF_REG_a" \n\t"
  1297. "lea (%%"FF_REG_a", %1, 4), %%"FF_REG_c"\n\t"
  1298. // 0 1 2 3 4 5 6 7 8 9
  1299. // %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %0+8%1 ecx+4%1
  1300. "movq (%0), %%mm0 \n\t"
  1301. "movq (%%"FF_REG_a", %1), %%mm1 \n\t"
  1302. PAVGB(%%mm1, %%mm0)
  1303. "movq %%mm0, (%%"FF_REG_a") \n\t"
  1304. "movq (%0, %1, 4), %%mm0 \n\t"
  1305. PAVGB(%%mm0, %%mm1)
  1306. "movq %%mm1, (%%"FF_REG_a", %1, 2) \n\t"
  1307. "movq (%%"FF_REG_c", %1), %%mm1 \n\t"
  1308. PAVGB(%%mm1, %%mm0)
  1309. "movq %%mm0, (%%"FF_REG_c") \n\t"
  1310. "movq (%0, %1, 8), %%mm0 \n\t"
  1311. PAVGB(%%mm0, %%mm1)
  1312. "movq %%mm1, (%%"FF_REG_c", %1, 2) \n\t"
  1313. : : "r" (src), "r" ((x86_reg)stride)
  1314. : "%"FF_REG_a, "%"FF_REG_c
  1315. );
  1316. #else
  1317. int a, b, x;
  1318. src+= 4*stride;
  1319. for(x=0; x<2; x++){
  1320. a= *(uint32_t*)&src[stride*0];
  1321. b= *(uint32_t*)&src[stride*2];
  1322. *(uint32_t*)&src[stride*1]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
  1323. a= *(uint32_t*)&src[stride*4];
  1324. *(uint32_t*)&src[stride*3]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
  1325. b= *(uint32_t*)&src[stride*6];
  1326. *(uint32_t*)&src[stride*5]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
  1327. a= *(uint32_t*)&src[stride*8];
  1328. *(uint32_t*)&src[stride*7]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
  1329. src += 4;
  1330. }
  1331. #endif
  1332. }
  1333. /**
  1334. * Deinterlace the given block by cubic interpolating every second line.
  1335. * will be called for every 8x8 block and can read & write from line 4-15
  1336. * lines 0-3 have been passed through the deblock / dering filters already, but can be read, too.
  1337. * lines 4-12 will be read into the deblocking filter and should be deinterlaced
  1338. * this filter will read lines 3-15 and write 7-13
  1339. */
  1340. static inline void RENAME(deInterlaceInterpolateCubic)(uint8_t src[], int stride)
  1341. {
  1342. #if TEMPLATE_PP_SSE2 || TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  1343. src+= stride*3;
  1344. __asm__ volatile(
  1345. "lea (%0, %1), %%"FF_REG_a" \n\t"
  1346. "lea (%%"FF_REG_a", %1, 4), %%"FF_REG_d"\n\t"
  1347. "lea (%%"FF_REG_d", %1, 4), %%"FF_REG_c"\n\t"
  1348. "add %1, %%"FF_REG_c" \n\t"
  1349. #if TEMPLATE_PP_SSE2
  1350. "pxor %%xmm7, %%xmm7 \n\t"
  1351. #define REAL_DEINT_CUBIC(a,b,c,d,e)\
  1352. "movq " #a ", %%xmm0 \n\t"\
  1353. "movq " #b ", %%xmm1 \n\t"\
  1354. "movq " #d ", %%xmm2 \n\t"\
  1355. "movq " #e ", %%xmm3 \n\t"\
  1356. "pavgb %%xmm2, %%xmm1 \n\t"\
  1357. "pavgb %%xmm3, %%xmm0 \n\t"\
  1358. "punpcklbw %%xmm7, %%xmm0 \n\t"\
  1359. "punpcklbw %%xmm7, %%xmm1 \n\t"\
  1360. "psubw %%xmm1, %%xmm0 \n\t"\
  1361. "psraw $3, %%xmm0 \n\t"\
  1362. "psubw %%xmm0, %%xmm1 \n\t"\
  1363. "packuswb %%xmm1, %%xmm1 \n\t"\
  1364. "movlps %%xmm1, " #c " \n\t"
  1365. #else //TEMPLATE_PP_SSE2
  1366. "pxor %%mm7, %%mm7 \n\t"
  1367. // 0 1 2 3 4 5 6 7 8 9 10
  1368. // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1 ecx
  1369. #define REAL_DEINT_CUBIC(a,b,c,d,e)\
  1370. "movq " #a ", %%mm0 \n\t"\
  1371. "movq " #b ", %%mm1 \n\t"\
  1372. "movq " #d ", %%mm2 \n\t"\
  1373. "movq " #e ", %%mm3 \n\t"\
  1374. PAVGB(%%mm2, %%mm1) /* (b+d) /2 */\
  1375. PAVGB(%%mm3, %%mm0) /* (a+e) /2 */\
  1376. "movq %%mm0, %%mm2 \n\t"\
  1377. "punpcklbw %%mm7, %%mm0 \n\t"\
  1378. "punpckhbw %%mm7, %%mm2 \n\t"\
  1379. "movq %%mm1, %%mm3 \n\t"\
  1380. "punpcklbw %%mm7, %%mm1 \n\t"\
  1381. "punpckhbw %%mm7, %%mm3 \n\t"\
  1382. "psubw %%mm1, %%mm0 \n\t" /* L(a+e - (b+d))/2 */\
  1383. "psubw %%mm3, %%mm2 \n\t" /* H(a+e - (b+d))/2 */\
  1384. "psraw $3, %%mm0 \n\t" /* L(a+e - (b+d))/16 */\
  1385. "psraw $3, %%mm2 \n\t" /* H(a+e - (b+d))/16 */\
  1386. "psubw %%mm0, %%mm1 \n\t" /* L(9b + 9d - a - e)/16 */\
  1387. "psubw %%mm2, %%mm3 \n\t" /* H(9b + 9d - a - e)/16 */\
  1388. "packuswb %%mm3, %%mm1 \n\t"\
  1389. "movq %%mm1, " #c " \n\t"
  1390. #endif //TEMPLATE_PP_SSE2
  1391. #define DEINT_CUBIC(a,b,c,d,e) REAL_DEINT_CUBIC(a,b,c,d,e)
  1392. DEINT_CUBIC((%0) , (%%FF_REGa, %1), (%%FF_REGa, %1, 2), (%0, %1, 4) , (%%FF_REGd, %1))
  1393. DEINT_CUBIC((%%FF_REGa, %1), (%0, %1, 4) , (%%FF_REGd) , (%%FF_REGd, %1), (%0, %1, 8))
  1394. DEINT_CUBIC((%0, %1, 4) , (%%FF_REGd, %1), (%%FF_REGd, %1, 2), (%0, %1, 8) , (%%FF_REGc))
  1395. DEINT_CUBIC((%%FF_REGd, %1), (%0, %1, 8) , (%%FF_REGd, %1, 4), (%%FF_REGc) , (%%FF_REGc, %1, 2))
  1396. : : "r" (src), "r" ((x86_reg)stride)
  1397. :
  1398. #if TEMPLATE_PP_SSE2
  1399. XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm7",)
  1400. #endif
  1401. "%"FF_REG_a, "%"FF_REG_d, "%"FF_REG_c
  1402. );
  1403. #undef REAL_DEINT_CUBIC
  1404. #else //TEMPLATE_PP_SSE2 || TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  1405. int x;
  1406. src+= stride*3;
  1407. for(x=0; x<8; x++){
  1408. src[stride*3] = av_clip_uint8((-src[0] + 9*src[stride*2] + 9*src[stride*4] - src[stride*6])>>4);
  1409. src[stride*5] = av_clip_uint8((-src[stride*2] + 9*src[stride*4] + 9*src[stride*6] - src[stride*8])>>4);
  1410. src[stride*7] = av_clip_uint8((-src[stride*4] + 9*src[stride*6] + 9*src[stride*8] - src[stride*10])>>4);
  1411. src[stride*9] = av_clip_uint8((-src[stride*6] + 9*src[stride*8] + 9*src[stride*10] - src[stride*12])>>4);
  1412. src++;
  1413. }
  1414. #endif //TEMPLATE_PP_SSE2 || TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  1415. }
  1416. /**
  1417. * Deinterlace the given block by filtering every second line with a (-1 4 2 4 -1) filter.
  1418. * will be called for every 8x8 block and can read & write from line 4-15
  1419. * lines 0-3 have been passed through the deblock / dering filters already, but can be read, too.
  1420. * lines 4-12 will be read into the deblocking filter and should be deinterlaced
  1421. * this filter will read lines 4-13 and write 5-11
  1422. */
  1423. static inline void RENAME(deInterlaceFF)(uint8_t src[], int stride, uint8_t *tmp)
  1424. {
  1425. #if TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  1426. src+= stride*4;
  1427. __asm__ volatile(
  1428. "lea (%0, %1), %%"FF_REG_a" \n\t"
  1429. "lea (%%"FF_REG_a", %1, 4), %%"FF_REG_d"\n\t"
  1430. "pxor %%mm7, %%mm7 \n\t"
  1431. "movq (%2), %%mm0 \n\t"
  1432. // 0 1 2 3 4 5 6 7 8 9 10
  1433. // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1 ecx
  1434. #define REAL_DEINT_FF(a,b,c,d)\
  1435. "movq " #a ", %%mm1 \n\t"\
  1436. "movq " #b ", %%mm2 \n\t"\
  1437. "movq " #c ", %%mm3 \n\t"\
  1438. "movq " #d ", %%mm4 \n\t"\
  1439. PAVGB(%%mm3, %%mm1) \
  1440. PAVGB(%%mm4, %%mm0) \
  1441. "movq %%mm0, %%mm3 \n\t"\
  1442. "punpcklbw %%mm7, %%mm0 \n\t"\
  1443. "punpckhbw %%mm7, %%mm3 \n\t"\
  1444. "movq %%mm1, %%mm4 \n\t"\
  1445. "punpcklbw %%mm7, %%mm1 \n\t"\
  1446. "punpckhbw %%mm7, %%mm4 \n\t"\
  1447. "psllw $2, %%mm1 \n\t"\
  1448. "psllw $2, %%mm4 \n\t"\
  1449. "psubw %%mm0, %%mm1 \n\t"\
  1450. "psubw %%mm3, %%mm4 \n\t"\
  1451. "movq %%mm2, %%mm5 \n\t"\
  1452. "movq %%mm2, %%mm0 \n\t"\
  1453. "punpcklbw %%mm7, %%mm2 \n\t"\
  1454. "punpckhbw %%mm7, %%mm5 \n\t"\
  1455. "paddw %%mm2, %%mm1 \n\t"\
  1456. "paddw %%mm5, %%mm4 \n\t"\
  1457. "psraw $2, %%mm1 \n\t"\
  1458. "psraw $2, %%mm4 \n\t"\
  1459. "packuswb %%mm4, %%mm1 \n\t"\
  1460. "movq %%mm1, " #b " \n\t"\
  1461. #define DEINT_FF(a,b,c,d) REAL_DEINT_FF(a,b,c,d)
  1462. DEINT_FF((%0) , (%%FF_REGa) , (%%FF_REGa, %1), (%%FF_REGa, %1, 2))
  1463. DEINT_FF((%%FF_REGa, %1), (%%FF_REGa, %1, 2), (%0, %1, 4) , (%%FF_REGd) )
  1464. DEINT_FF((%0, %1, 4) , (%%FF_REGd) , (%%FF_REGd, %1), (%%FF_REGd, %1, 2))
  1465. DEINT_FF((%%FF_REGd, %1), (%%FF_REGd, %1, 2), (%0, %1, 8) , (%%FF_REGd, %1, 4))
  1466. "movq %%mm0, (%2) \n\t"
  1467. : : "r" (src), "r" ((x86_reg)stride), "r"(tmp)
  1468. : "%"FF_REG_a, "%"FF_REG_d
  1469. );
  1470. #else //TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  1471. int x;
  1472. src+= stride*4;
  1473. for(x=0; x<8; x++){
  1474. int t1= tmp[x];
  1475. int t2= src[stride*1];
  1476. src[stride*1]= av_clip_uint8((-t1 + 4*src[stride*0] + 2*t2 + 4*src[stride*2] - src[stride*3] + 4)>>3);
  1477. t1= src[stride*4];
  1478. src[stride*3]= av_clip_uint8((-t2 + 4*src[stride*2] + 2*t1 + 4*src[stride*4] - src[stride*5] + 4)>>3);
  1479. t2= src[stride*6];
  1480. src[stride*5]= av_clip_uint8((-t1 + 4*src[stride*4] + 2*t2 + 4*src[stride*6] - src[stride*7] + 4)>>3);
  1481. t1= src[stride*8];
  1482. src[stride*7]= av_clip_uint8((-t2 + 4*src[stride*6] + 2*t1 + 4*src[stride*8] - src[stride*9] + 4)>>3);
  1483. tmp[x]= t1;
  1484. src++;
  1485. }
  1486. #endif //TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  1487. }
  1488. /**
  1489. * Deinterlace the given block by filtering every line with a (-1 2 6 2 -1) filter.
  1490. * will be called for every 8x8 block and can read & write from line 4-15
  1491. * lines 0-3 have been passed through the deblock / dering filters already, but can be read, too.
  1492. * lines 4-12 will be read into the deblocking filter and should be deinterlaced
  1493. * this filter will read lines 4-13 and write 4-11
  1494. */
  1495. static inline void RENAME(deInterlaceL5)(uint8_t src[], int stride, uint8_t *tmp, uint8_t *tmp2)
  1496. {
  1497. #if (TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW) && HAVE_6REGS
  1498. src+= stride*4;
  1499. __asm__ volatile(
  1500. "lea (%0, %1), %%"FF_REG_a" \n\t"
  1501. "lea (%%"FF_REG_a", %1, 4), %%"FF_REG_d"\n\t"
  1502. "pxor %%mm7, %%mm7 \n\t"
  1503. "movq (%2), %%mm0 \n\t"
  1504. "movq (%3), %%mm1 \n\t"
  1505. // 0 1 2 3 4 5 6 7 8 9 10
  1506. // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1 ecx
  1507. #define REAL_DEINT_L5(t1,t2,a,b,c)\
  1508. "movq " #a ", %%mm2 \n\t"\
  1509. "movq " #b ", %%mm3 \n\t"\
  1510. "movq " #c ", %%mm4 \n\t"\
  1511. PAVGB(t2, %%mm3) \
  1512. PAVGB(t1, %%mm4) \
  1513. "movq %%mm2, %%mm5 \n\t"\
  1514. "movq %%mm2, " #t1 " \n\t"\
  1515. "punpcklbw %%mm7, %%mm2 \n\t"\
  1516. "punpckhbw %%mm7, %%mm5 \n\t"\
  1517. "movq %%mm2, %%mm6 \n\t"\
  1518. "paddw %%mm2, %%mm2 \n\t"\
  1519. "paddw %%mm6, %%mm2 \n\t"\
  1520. "movq %%mm5, %%mm6 \n\t"\
  1521. "paddw %%mm5, %%mm5 \n\t"\
  1522. "paddw %%mm6, %%mm5 \n\t"\
  1523. "movq %%mm3, %%mm6 \n\t"\
  1524. "punpcklbw %%mm7, %%mm3 \n\t"\
  1525. "punpckhbw %%mm7, %%mm6 \n\t"\
  1526. "paddw %%mm3, %%mm3 \n\t"\
  1527. "paddw %%mm6, %%mm6 \n\t"\
  1528. "paddw %%mm3, %%mm2 \n\t"\
  1529. "paddw %%mm6, %%mm5 \n\t"\
  1530. "movq %%mm4, %%mm6 \n\t"\
  1531. "punpcklbw %%mm7, %%mm4 \n\t"\
  1532. "punpckhbw %%mm7, %%mm6 \n\t"\
  1533. "psubw %%mm4, %%mm2 \n\t"\
  1534. "psubw %%mm6, %%mm5 \n\t"\
  1535. "psraw $2, %%mm2 \n\t"\
  1536. "psraw $2, %%mm5 \n\t"\
  1537. "packuswb %%mm5, %%mm2 \n\t"\
  1538. "movq %%mm2, " #a " \n\t"\
  1539. #define DEINT_L5(t1,t2,a,b,c) REAL_DEINT_L5(t1,t2,a,b,c)
  1540. DEINT_L5(%%mm0, %%mm1, (%0) , (%%FF_REGa) , (%%FF_REGa, %1) )
  1541. DEINT_L5(%%mm1, %%mm0, (%%FF_REGa) , (%%FF_REGa, %1) , (%%FF_REGa, %1, 2))
  1542. DEINT_L5(%%mm0, %%mm1, (%%FF_REGa, %1) , (%%FF_REGa, %1, 2), (%0, %1, 4) )
  1543. DEINT_L5(%%mm1, %%mm0, (%%FF_REGa, %1, 2), (%0, %1, 4) , (%%FF_REGd) )
  1544. DEINT_L5(%%mm0, %%mm1, (%0, %1, 4) , (%%FF_REGd) , (%%FF_REGd, %1) )
  1545. DEINT_L5(%%mm1, %%mm0, (%%FF_REGd) , (%%FF_REGd, %1) , (%%FF_REGd, %1, 2))
  1546. DEINT_L5(%%mm0, %%mm1, (%%FF_REGd, %1) , (%%FF_REGd, %1, 2), (%0, %1, 8) )
  1547. DEINT_L5(%%mm1, %%mm0, (%%FF_REGd, %1, 2), (%0, %1, 8) , (%%FF_REGd, %1, 4))
  1548. "movq %%mm0, (%2) \n\t"
  1549. "movq %%mm1, (%3) \n\t"
  1550. : : "r" (src), "r" ((x86_reg)stride), "r"(tmp), "r"(tmp2)
  1551. : "%"FF_REG_a, "%"FF_REG_d
  1552. );
  1553. #else //(TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW) && HAVE_6REGS
  1554. int x;
  1555. src+= stride*4;
  1556. for(x=0; x<8; x++){
  1557. int t1= tmp[x];
  1558. int t2= tmp2[x];
  1559. int t3= src[0];
  1560. src[stride*0]= av_clip_uint8((-(t1 + src[stride*2]) + 2*(t2 + src[stride*1]) + 6*t3 + 4)>>3);
  1561. t1= src[stride*1];
  1562. src[stride*1]= av_clip_uint8((-(t2 + src[stride*3]) + 2*(t3 + src[stride*2]) + 6*t1 + 4)>>3);
  1563. t2= src[stride*2];
  1564. src[stride*2]= av_clip_uint8((-(t3 + src[stride*4]) + 2*(t1 + src[stride*3]) + 6*t2 + 4)>>3);
  1565. t3= src[stride*3];
  1566. src[stride*3]= av_clip_uint8((-(t1 + src[stride*5]) + 2*(t2 + src[stride*4]) + 6*t3 + 4)>>3);
  1567. t1= src[stride*4];
  1568. src[stride*4]= av_clip_uint8((-(t2 + src[stride*6]) + 2*(t3 + src[stride*5]) + 6*t1 + 4)>>3);
  1569. t2= src[stride*5];
  1570. src[stride*5]= av_clip_uint8((-(t3 + src[stride*7]) + 2*(t1 + src[stride*6]) + 6*t2 + 4)>>3);
  1571. t3= src[stride*6];
  1572. src[stride*6]= av_clip_uint8((-(t1 + src[stride*8]) + 2*(t2 + src[stride*7]) + 6*t3 + 4)>>3);
  1573. t1= src[stride*7];
  1574. src[stride*7]= av_clip_uint8((-(t2 + src[stride*9]) + 2*(t3 + src[stride*8]) + 6*t1 + 4)>>3);
  1575. tmp[x]= t3;
  1576. tmp2[x]= t1;
  1577. src++;
  1578. }
  1579. #endif //(TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW) && HAVE_6REGS
  1580. }
  1581. /**
  1582. * Deinterlace the given block by filtering all lines with a (1 2 1) filter.
  1583. * will be called for every 8x8 block and can read & write from line 4-15
  1584. * lines 0-3 have been passed through the deblock / dering filters already, but can be read, too.
  1585. * lines 4-12 will be read into the deblocking filter and should be deinterlaced
  1586. * this filter will read lines 4-13 and write 4-11
  1587. */
  1588. static inline void RENAME(deInterlaceBlendLinear)(uint8_t src[], int stride, uint8_t *tmp)
  1589. {
  1590. #if TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  1591. src+= 4*stride;
  1592. __asm__ volatile(
  1593. "lea (%0, %1), %%"FF_REG_a" \n\t"
  1594. "lea (%%"FF_REG_a", %1, 4), %%"FF_REG_d"\n\t"
  1595. // 0 1 2 3 4 5 6 7 8 9
  1596. // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
  1597. "movq (%2), %%mm0 \n\t" // L0
  1598. "movq (%%"FF_REG_a"), %%mm1 \n\t" // L2
  1599. PAVGB(%%mm1, %%mm0) // L0+L2
  1600. "movq (%0), %%mm2 \n\t" // L1
  1601. PAVGB(%%mm2, %%mm0)
  1602. "movq %%mm0, (%0) \n\t"
  1603. "movq (%%"FF_REG_a", %1), %%mm0 \n\t" // L3
  1604. PAVGB(%%mm0, %%mm2) // L1+L3
  1605. PAVGB(%%mm1, %%mm2) // 2L2 + L1 + L3
  1606. "movq %%mm2, (%%"FF_REG_a") \n\t"
  1607. "movq (%%"FF_REG_a", %1, 2), %%mm2 \n\t" // L4
  1608. PAVGB(%%mm2, %%mm1) // L2+L4
  1609. PAVGB(%%mm0, %%mm1) // 2L3 + L2 + L4
  1610. "movq %%mm1, (%%"FF_REG_a", %1) \n\t"
  1611. "movq (%0, %1, 4), %%mm1 \n\t" // L5
  1612. PAVGB(%%mm1, %%mm0) // L3+L5
  1613. PAVGB(%%mm2, %%mm0) // 2L4 + L3 + L5
  1614. "movq %%mm0, (%%"FF_REG_a", %1, 2) \n\t"
  1615. "movq (%%"FF_REG_d"), %%mm0 \n\t" // L6
  1616. PAVGB(%%mm0, %%mm2) // L4+L6
  1617. PAVGB(%%mm1, %%mm2) // 2L5 + L4 + L6
  1618. "movq %%mm2, (%0, %1, 4) \n\t"
  1619. "movq (%%"FF_REG_d", %1), %%mm2 \n\t" // L7
  1620. PAVGB(%%mm2, %%mm1) // L5+L7
  1621. PAVGB(%%mm0, %%mm1) // 2L6 + L5 + L7
  1622. "movq %%mm1, (%%"FF_REG_d") \n\t"
  1623. "movq (%%"FF_REG_d", %1, 2), %%mm1 \n\t" // L8
  1624. PAVGB(%%mm1, %%mm0) // L6+L8
  1625. PAVGB(%%mm2, %%mm0) // 2L7 + L6 + L8
  1626. "movq %%mm0, (%%"FF_REG_d", %1) \n\t"
  1627. "movq (%0, %1, 8), %%mm0 \n\t" // L9
  1628. PAVGB(%%mm0, %%mm2) // L7+L9
  1629. PAVGB(%%mm1, %%mm2) // 2L8 + L7 + L9
  1630. "movq %%mm2, (%%"FF_REG_d", %1, 2) \n\t"
  1631. "movq %%mm1, (%2) \n\t"
  1632. : : "r" (src), "r" ((x86_reg)stride), "r" (tmp)
  1633. : "%"FF_REG_a, "%"FF_REG_d
  1634. );
  1635. #else //TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  1636. int a, b, c, x;
  1637. src+= 4*stride;
  1638. for(x=0; x<2; x++){
  1639. a= *(uint32_t*)&tmp[stride*0];
  1640. b= *(uint32_t*)&src[stride*0];
  1641. c= *(uint32_t*)&src[stride*1];
  1642. a= (a&c) + (((a^c)&0xFEFEFEFEUL)>>1);
  1643. *(uint32_t*)&src[stride*0]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
  1644. a= *(uint32_t*)&src[stride*2];
  1645. b= (a&b) + (((a^b)&0xFEFEFEFEUL)>>1);
  1646. *(uint32_t*)&src[stride*1]= (c|b) - (((c^b)&0xFEFEFEFEUL)>>1);
  1647. b= *(uint32_t*)&src[stride*3];
  1648. c= (b&c) + (((b^c)&0xFEFEFEFEUL)>>1);
  1649. *(uint32_t*)&src[stride*2]= (c|a) - (((c^a)&0xFEFEFEFEUL)>>1);
  1650. c= *(uint32_t*)&src[stride*4];
  1651. a= (a&c) + (((a^c)&0xFEFEFEFEUL)>>1);
  1652. *(uint32_t*)&src[stride*3]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
  1653. a= *(uint32_t*)&src[stride*5];
  1654. b= (a&b) + (((a^b)&0xFEFEFEFEUL)>>1);
  1655. *(uint32_t*)&src[stride*4]= (c|b) - (((c^b)&0xFEFEFEFEUL)>>1);
  1656. b= *(uint32_t*)&src[stride*6];
  1657. c= (b&c) + (((b^c)&0xFEFEFEFEUL)>>1);
  1658. *(uint32_t*)&src[stride*5]= (c|a) - (((c^a)&0xFEFEFEFEUL)>>1);
  1659. c= *(uint32_t*)&src[stride*7];
  1660. a= (a&c) + (((a^c)&0xFEFEFEFEUL)>>1);
  1661. *(uint32_t*)&src[stride*6]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
  1662. a= *(uint32_t*)&src[stride*8];
  1663. b= (a&b) + (((a^b)&0xFEFEFEFEUL)>>1);
  1664. *(uint32_t*)&src[stride*7]= (c|b) - (((c^b)&0xFEFEFEFEUL)>>1);
  1665. *(uint32_t*)&tmp[stride*0]= c;
  1666. src += 4;
  1667. tmp += 4;
  1668. }
  1669. #endif //TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW
  1670. }
  1671. /**
  1672. * Deinterlace the given block by applying a median filter to every second line.
  1673. * will be called for every 8x8 block and can read & write from line 4-15,
  1674. * lines 0-3 have been passed through the deblock / dering filters already, but can be read, too.
  1675. * lines 4-12 will be read into the deblocking filter and should be deinterlaced
  1676. */
  1677. static inline void RENAME(deInterlaceMedian)(uint8_t src[], int stride)
  1678. {
  1679. #if TEMPLATE_PP_MMX
  1680. src+= 4*stride;
  1681. #if TEMPLATE_PP_MMXEXT
  1682. __asm__ volatile(
  1683. "lea (%0, %1), %%"FF_REG_a" \n\t"
  1684. "lea (%%"FF_REG_a", %1, 4), %%"FF_REG_d"\n\t"
  1685. // 0 1 2 3 4 5 6 7 8 9
  1686. // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
  1687. "movq (%0), %%mm0 \n\t"
  1688. "movq (%%"FF_REG_a", %1), %%mm2 \n\t"
  1689. "movq (%%"FF_REG_a"), %%mm1 \n\t"
  1690. "movq %%mm0, %%mm3 \n\t"
  1691. "pmaxub %%mm1, %%mm0 \n\t"
  1692. "pminub %%mm3, %%mm1 \n\t"
  1693. "pmaxub %%mm2, %%mm1 \n\t"
  1694. "pminub %%mm1, %%mm0 \n\t"
  1695. "movq %%mm0, (%%"FF_REG_a") \n\t"
  1696. "movq (%0, %1, 4), %%mm0 \n\t"
  1697. "movq (%%"FF_REG_a", %1, 2), %%mm1 \n\t"
  1698. "movq %%mm2, %%mm3 \n\t"
  1699. "pmaxub %%mm1, %%mm2 \n\t"
  1700. "pminub %%mm3, %%mm1 \n\t"
  1701. "pmaxub %%mm0, %%mm1 \n\t"
  1702. "pminub %%mm1, %%mm2 \n\t"
  1703. "movq %%mm2, (%%"FF_REG_a", %1, 2) \n\t"
  1704. "movq (%%"FF_REG_d"), %%mm2 \n\t"
  1705. "movq (%%"FF_REG_d", %1), %%mm1 \n\t"
  1706. "movq %%mm2, %%mm3 \n\t"
  1707. "pmaxub %%mm0, %%mm2 \n\t"
  1708. "pminub %%mm3, %%mm0 \n\t"
  1709. "pmaxub %%mm1, %%mm0 \n\t"
  1710. "pminub %%mm0, %%mm2 \n\t"
  1711. "movq %%mm2, (%%"FF_REG_d") \n\t"
  1712. "movq (%%"FF_REG_d", %1, 2), %%mm2 \n\t"
  1713. "movq (%0, %1, 8), %%mm0 \n\t"
  1714. "movq %%mm2, %%mm3 \n\t"
  1715. "pmaxub %%mm0, %%mm2 \n\t"
  1716. "pminub %%mm3, %%mm0 \n\t"
  1717. "pmaxub %%mm1, %%mm0 \n\t"
  1718. "pminub %%mm0, %%mm2 \n\t"
  1719. "movq %%mm2, (%%"FF_REG_d", %1, 2) \n\t"
  1720. : : "r" (src), "r" ((x86_reg)stride)
  1721. : "%"FF_REG_a, "%"FF_REG_d
  1722. );
  1723. #else // MMX without MMX2
  1724. __asm__ volatile(
  1725. "lea (%0, %1), %%"FF_REG_a" \n\t"
  1726. "lea (%%"FF_REG_a", %1, 4), %%"FF_REG_d"\n\t"
  1727. // 0 1 2 3 4 5 6 7 8 9
  1728. // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
  1729. "pxor %%mm7, %%mm7 \n\t"
  1730. #define REAL_MEDIAN(a,b,c)\
  1731. "movq " #a ", %%mm0 \n\t"\
  1732. "movq " #b ", %%mm2 \n\t"\
  1733. "movq " #c ", %%mm1 \n\t"\
  1734. "movq %%mm0, %%mm3 \n\t"\
  1735. "movq %%mm1, %%mm4 \n\t"\
  1736. "movq %%mm2, %%mm5 \n\t"\
  1737. "psubusb %%mm1, %%mm3 \n\t"\
  1738. "psubusb %%mm2, %%mm4 \n\t"\
  1739. "psubusb %%mm0, %%mm5 \n\t"\
  1740. "pcmpeqb %%mm7, %%mm3 \n\t"\
  1741. "pcmpeqb %%mm7, %%mm4 \n\t"\
  1742. "pcmpeqb %%mm7, %%mm5 \n\t"\
  1743. "movq %%mm3, %%mm6 \n\t"\
  1744. "pxor %%mm4, %%mm3 \n\t"\
  1745. "pxor %%mm5, %%mm4 \n\t"\
  1746. "pxor %%mm6, %%mm5 \n\t"\
  1747. "por %%mm3, %%mm1 \n\t"\
  1748. "por %%mm4, %%mm2 \n\t"\
  1749. "por %%mm5, %%mm0 \n\t"\
  1750. "pand %%mm2, %%mm0 \n\t"\
  1751. "pand %%mm1, %%mm0 \n\t"\
  1752. "movq %%mm0, " #b " \n\t"
  1753. #define MEDIAN(a,b,c) REAL_MEDIAN(a,b,c)
  1754. MEDIAN((%0) , (%%FF_REGa) , (%%FF_REGa, %1))
  1755. MEDIAN((%%FF_REGa, %1), (%%FF_REGa, %1, 2), (%0, %1, 4))
  1756. MEDIAN((%0, %1, 4) , (%%FF_REGd) , (%%FF_REGd, %1))
  1757. MEDIAN((%%FF_REGd, %1), (%%FF_REGd, %1, 2), (%0, %1, 8))
  1758. : : "r" (src), "r" ((x86_reg)stride)
  1759. : "%"FF_REG_a, "%"FF_REG_d
  1760. );
  1761. #endif //TEMPLATE_PP_MMXEXT
  1762. #else //TEMPLATE_PP_MMX
  1763. int x, y;
  1764. src+= 4*stride;
  1765. // FIXME - there should be a way to do a few columns in parallel like w/mmx
  1766. for(x=0; x<8; x++){
  1767. uint8_t *colsrc = src;
  1768. for (y=0; y<4; y++){
  1769. int a, b, c, d, e, f;
  1770. a = colsrc[0 ];
  1771. b = colsrc[stride ];
  1772. c = colsrc[stride*2];
  1773. d = (a-b)>>31;
  1774. e = (b-c)>>31;
  1775. f = (c-a)>>31;
  1776. colsrc[stride ] = (a|(d^f)) & (b|(d^e)) & (c|(e^f));
  1777. colsrc += stride*2;
  1778. }
  1779. src++;
  1780. }
  1781. #endif //TEMPLATE_PP_MMX
  1782. }
  1783. #if TEMPLATE_PP_MMX
  1784. /**
  1785. * Transpose and shift the given 8x8 Block into dst1 and dst2.
  1786. */
  1787. static inline void RENAME(transpose1)(uint8_t *dst1, uint8_t *dst2, const uint8_t *src, int srcStride)
  1788. {
  1789. __asm__(
  1790. "lea (%0, %1), %%"FF_REG_a" \n\t"
  1791. // 0 1 2 3 4 5 6 7 8 9
  1792. // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
  1793. "movq (%0), %%mm0 \n\t" // 12345678
  1794. "movq (%%"FF_REG_a"), %%mm1 \n\t" // abcdefgh
  1795. "movq %%mm0, %%mm2 \n\t" // 12345678
  1796. "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
  1797. "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
  1798. "movq (%%"FF_REG_a", %1), %%mm1 \n\t"
  1799. "movq (%%"FF_REG_a", %1, 2), %%mm3 \n\t"
  1800. "movq %%mm1, %%mm4 \n\t"
  1801. "punpcklbw %%mm3, %%mm1 \n\t"
  1802. "punpckhbw %%mm3, %%mm4 \n\t"
  1803. "movq %%mm0, %%mm3 \n\t"
  1804. "punpcklwd %%mm1, %%mm0 \n\t"
  1805. "punpckhwd %%mm1, %%mm3 \n\t"
  1806. "movq %%mm2, %%mm1 \n\t"
  1807. "punpcklwd %%mm4, %%mm2 \n\t"
  1808. "punpckhwd %%mm4, %%mm1 \n\t"
  1809. "movd %%mm0, 128(%2) \n\t"
  1810. "psrlq $32, %%mm0 \n\t"
  1811. "movd %%mm0, 144(%2) \n\t"
  1812. "movd %%mm3, 160(%2) \n\t"
  1813. "psrlq $32, %%mm3 \n\t"
  1814. "movd %%mm3, 176(%2) \n\t"
  1815. "movd %%mm3, 48(%3) \n\t"
  1816. "movd %%mm2, 192(%2) \n\t"
  1817. "movd %%mm2, 64(%3) \n\t"
  1818. "psrlq $32, %%mm2 \n\t"
  1819. "movd %%mm2, 80(%3) \n\t"
  1820. "movd %%mm1, 96(%3) \n\t"
  1821. "psrlq $32, %%mm1 \n\t"
  1822. "movd %%mm1, 112(%3) \n\t"
  1823. "lea (%%"FF_REG_a", %1, 4), %%"FF_REG_a"\n\t"
  1824. "movq (%0, %1, 4), %%mm0 \n\t" // 12345678
  1825. "movq (%%"FF_REG_a"), %%mm1 \n\t" // abcdefgh
  1826. "movq %%mm0, %%mm2 \n\t" // 12345678
  1827. "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
  1828. "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
  1829. "movq (%%"FF_REG_a", %1), %%mm1 \n\t"
  1830. "movq (%%"FF_REG_a", %1, 2), %%mm3 \n\t"
  1831. "movq %%mm1, %%mm4 \n\t"
  1832. "punpcklbw %%mm3, %%mm1 \n\t"
  1833. "punpckhbw %%mm3, %%mm4 \n\t"
  1834. "movq %%mm0, %%mm3 \n\t"
  1835. "punpcklwd %%mm1, %%mm0 \n\t"
  1836. "punpckhwd %%mm1, %%mm3 \n\t"
  1837. "movq %%mm2, %%mm1 \n\t"
  1838. "punpcklwd %%mm4, %%mm2 \n\t"
  1839. "punpckhwd %%mm4, %%mm1 \n\t"
  1840. "movd %%mm0, 132(%2) \n\t"
  1841. "psrlq $32, %%mm0 \n\t"
  1842. "movd %%mm0, 148(%2) \n\t"
  1843. "movd %%mm3, 164(%2) \n\t"
  1844. "psrlq $32, %%mm3 \n\t"
  1845. "movd %%mm3, 180(%2) \n\t"
  1846. "movd %%mm3, 52(%3) \n\t"
  1847. "movd %%mm2, 196(%2) \n\t"
  1848. "movd %%mm2, 68(%3) \n\t"
  1849. "psrlq $32, %%mm2 \n\t"
  1850. "movd %%mm2, 84(%3) \n\t"
  1851. "movd %%mm1, 100(%3) \n\t"
  1852. "psrlq $32, %%mm1 \n\t"
  1853. "movd %%mm1, 116(%3) \n\t"
  1854. :: "r" (src), "r" ((x86_reg)srcStride), "r" (dst1), "r" (dst2)
  1855. : "%"FF_REG_a
  1856. );
  1857. }
  1858. /**
  1859. * Transpose the given 8x8 block.
  1860. */
  1861. static inline void RENAME(transpose2)(uint8_t *dst, int dstStride, const uint8_t *src)
  1862. {
  1863. __asm__(
  1864. "lea (%0, %1), %%"FF_REG_a" \n\t"
  1865. "lea (%%"FF_REG_a",%1,4), %%"FF_REG_d" \n\t"
  1866. // 0 1 2 3 4 5 6 7 8 9
  1867. // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
  1868. "movq (%2), %%mm0 \n\t" // 12345678
  1869. "movq 16(%2), %%mm1 \n\t" // abcdefgh
  1870. "movq %%mm0, %%mm2 \n\t" // 12345678
  1871. "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
  1872. "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
  1873. "movq 32(%2), %%mm1 \n\t"
  1874. "movq 48(%2), %%mm3 \n\t"
  1875. "movq %%mm1, %%mm4 \n\t"
  1876. "punpcklbw %%mm3, %%mm1 \n\t"
  1877. "punpckhbw %%mm3, %%mm4 \n\t"
  1878. "movq %%mm0, %%mm3 \n\t"
  1879. "punpcklwd %%mm1, %%mm0 \n\t"
  1880. "punpckhwd %%mm1, %%mm3 \n\t"
  1881. "movq %%mm2, %%mm1 \n\t"
  1882. "punpcklwd %%mm4, %%mm2 \n\t"
  1883. "punpckhwd %%mm4, %%mm1 \n\t"
  1884. "movd %%mm0, (%0) \n\t"
  1885. "psrlq $32, %%mm0 \n\t"
  1886. "movd %%mm0, (%%"FF_REG_a") \n\t"
  1887. "movd %%mm3, (%%"FF_REG_a", %1) \n\t"
  1888. "psrlq $32, %%mm3 \n\t"
  1889. "movd %%mm3, (%%"FF_REG_a", %1, 2) \n\t"
  1890. "movd %%mm2, (%0, %1, 4) \n\t"
  1891. "psrlq $32, %%mm2 \n\t"
  1892. "movd %%mm2, (%%"FF_REG_d") \n\t"
  1893. "movd %%mm1, (%%"FF_REG_d", %1) \n\t"
  1894. "psrlq $32, %%mm1 \n\t"
  1895. "movd %%mm1, (%%"FF_REG_d", %1, 2) \n\t"
  1896. "movq 64(%2), %%mm0 \n\t" // 12345678
  1897. "movq 80(%2), %%mm1 \n\t" // abcdefgh
  1898. "movq %%mm0, %%mm2 \n\t" // 12345678
  1899. "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
  1900. "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
  1901. "movq 96(%2), %%mm1 \n\t"
  1902. "movq 112(%2), %%mm3 \n\t"
  1903. "movq %%mm1, %%mm4 \n\t"
  1904. "punpcklbw %%mm3, %%mm1 \n\t"
  1905. "punpckhbw %%mm3, %%mm4 \n\t"
  1906. "movq %%mm0, %%mm3 \n\t"
  1907. "punpcklwd %%mm1, %%mm0 \n\t"
  1908. "punpckhwd %%mm1, %%mm3 \n\t"
  1909. "movq %%mm2, %%mm1 \n\t"
  1910. "punpcklwd %%mm4, %%mm2 \n\t"
  1911. "punpckhwd %%mm4, %%mm1 \n\t"
  1912. "movd %%mm0, 4(%0) \n\t"
  1913. "psrlq $32, %%mm0 \n\t"
  1914. "movd %%mm0, 4(%%"FF_REG_a") \n\t"
  1915. "movd %%mm3, 4(%%"FF_REG_a", %1) \n\t"
  1916. "psrlq $32, %%mm3 \n\t"
  1917. "movd %%mm3, 4(%%"FF_REG_a", %1, 2) \n\t"
  1918. "movd %%mm2, 4(%0, %1, 4) \n\t"
  1919. "psrlq $32, %%mm2 \n\t"
  1920. "movd %%mm2, 4(%%"FF_REG_d") \n\t"
  1921. "movd %%mm1, 4(%%"FF_REG_d", %1) \n\t"
  1922. "psrlq $32, %%mm1 \n\t"
  1923. "movd %%mm1, 4(%%"FF_REG_d", %1, 2) \n\t"
  1924. :: "r" (dst), "r" ((x86_reg)dstStride), "r" (src)
  1925. : "%"FF_REG_a, "%"FF_REG_d
  1926. );
  1927. }
  1928. #endif //TEMPLATE_PP_MMX
  1929. //static long test=0;
  1930. #if !TEMPLATE_PP_ALTIVEC
  1931. static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
  1932. uint8_t *tempBlurred, uint32_t *tempBlurredPast, const int *maxNoise)
  1933. {
  1934. // to save a register (FIXME do this outside of the loops)
  1935. tempBlurredPast[127]= maxNoise[0];
  1936. tempBlurredPast[128]= maxNoise[1];
  1937. tempBlurredPast[129]= maxNoise[2];
  1938. #define FAST_L2_DIFF
  1939. //#define L1_DIFF //u should change the thresholds too if u try that one
  1940. #if (TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW) && HAVE_6REGS
  1941. __asm__ volatile(
  1942. "lea (%2, %2, 2), %%"FF_REG_a" \n\t" // 3*stride
  1943. "lea (%2, %2, 4), %%"FF_REG_d" \n\t" // 5*stride
  1944. "lea (%%"FF_REG_d", %2, 2), %%"FF_REG_c"\n\t" // 7*stride
  1945. // 0 1 2 3 4 5 6 7 8 9
  1946. // %x %x+%2 %x+2%2 %x+eax %x+4%2 %x+edx %x+2eax %x+ecx %x+8%2
  1947. //FIXME reorder?
  1948. #ifdef L1_DIFF //needs mmx2
  1949. "movq (%0), %%mm0 \n\t" // L0
  1950. "psadbw (%1), %%mm0 \n\t" // |L0-R0|
  1951. "movq (%0, %2), %%mm1 \n\t" // L1
  1952. "psadbw (%1, %2), %%mm1 \n\t" // |L1-R1|
  1953. "movq (%0, %2, 2), %%mm2 \n\t" // L2
  1954. "psadbw (%1, %2, 2), %%mm2 \n\t" // |L2-R2|
  1955. "movq (%0, %%"FF_REG_a"), %%mm3 \n\t" // L3
  1956. "psadbw (%1, %%"FF_REG_a"), %%mm3 \n\t" // |L3-R3|
  1957. "movq (%0, %2, 4), %%mm4 \n\t" // L4
  1958. "paddw %%mm1, %%mm0 \n\t"
  1959. "psadbw (%1, %2, 4), %%mm4 \n\t" // |L4-R4|
  1960. "movq (%0, %%"FF_REG_d"), %%mm5 \n\t" // L5
  1961. "paddw %%mm2, %%mm0 \n\t"
  1962. "psadbw (%1, %%"FF_REG_d"), %%mm5 \n\t" // |L5-R5|
  1963. "movq (%0, %%"FF_REG_a", 2), %%mm6 \n\t" // L6
  1964. "paddw %%mm3, %%mm0 \n\t"
  1965. "psadbw (%1, %%"FF_REG_a", 2), %%mm6 \n\t" // |L6-R6|
  1966. "movq (%0, %%"FF_REG_c"), %%mm7 \n\t" // L7
  1967. "paddw %%mm4, %%mm0 \n\t"
  1968. "psadbw (%1, %%"FF_REG_c"), %%mm7 \n\t" // |L7-R7|
  1969. "paddw %%mm5, %%mm6 \n\t"
  1970. "paddw %%mm7, %%mm6 \n\t"
  1971. "paddw %%mm6, %%mm0 \n\t"
  1972. #else //L1_DIFF
  1973. #if defined (FAST_L2_DIFF)
  1974. "pcmpeqb %%mm7, %%mm7 \n\t"
  1975. "movq "MANGLE(b80)", %%mm6 \n\t"
  1976. "pxor %%mm0, %%mm0 \n\t"
  1977. #define REAL_L2_DIFF_CORE(a, b)\
  1978. "movq " #a ", %%mm5 \n\t"\
  1979. "movq " #b ", %%mm2 \n\t"\
  1980. "pxor %%mm7, %%mm2 \n\t"\
  1981. PAVGB(%%mm2, %%mm5)\
  1982. "paddb %%mm6, %%mm5 \n\t"\
  1983. "movq %%mm5, %%mm2 \n\t"\
  1984. "psllw $8, %%mm5 \n\t"\
  1985. "pmaddwd %%mm5, %%mm5 \n\t"\
  1986. "pmaddwd %%mm2, %%mm2 \n\t"\
  1987. "paddd %%mm2, %%mm5 \n\t"\
  1988. "psrld $14, %%mm5 \n\t"\
  1989. "paddd %%mm5, %%mm0 \n\t"
  1990. #else //defined (FAST_L2_DIFF)
  1991. "pxor %%mm7, %%mm7 \n\t"
  1992. "pxor %%mm0, %%mm0 \n\t"
  1993. #define REAL_L2_DIFF_CORE(a, b)\
  1994. "movq " #a ", %%mm5 \n\t"\
  1995. "movq " #b ", %%mm2 \n\t"\
  1996. "movq %%mm5, %%mm1 \n\t"\
  1997. "movq %%mm2, %%mm3 \n\t"\
  1998. "punpcklbw %%mm7, %%mm5 \n\t"\
  1999. "punpckhbw %%mm7, %%mm1 \n\t"\
  2000. "punpcklbw %%mm7, %%mm2 \n\t"\
  2001. "punpckhbw %%mm7, %%mm3 \n\t"\
  2002. "psubw %%mm2, %%mm5 \n\t"\
  2003. "psubw %%mm3, %%mm1 \n\t"\
  2004. "pmaddwd %%mm5, %%mm5 \n\t"\
  2005. "pmaddwd %%mm1, %%mm1 \n\t"\
  2006. "paddd %%mm1, %%mm5 \n\t"\
  2007. "paddd %%mm5, %%mm0 \n\t"
  2008. #endif //defined (FAST_L2_DIFF)
  2009. #define L2_DIFF_CORE(a, b) REAL_L2_DIFF_CORE(a, b)
  2010. L2_DIFF_CORE((%0) , (%1))
  2011. L2_DIFF_CORE((%0, %2) , (%1, %2))
  2012. L2_DIFF_CORE((%0, %2, 2) , (%1, %2, 2))
  2013. L2_DIFF_CORE((%0, %%FF_REGa) , (%1, %%FF_REGa))
  2014. L2_DIFF_CORE((%0, %2, 4) , (%1, %2, 4))
  2015. L2_DIFF_CORE((%0, %%FF_REGd) , (%1, %%FF_REGd))
  2016. L2_DIFF_CORE((%0, %%FF_REGa,2), (%1, %%FF_REGa,2))
  2017. L2_DIFF_CORE((%0, %%FF_REGc) , (%1, %%FF_REGc))
  2018. #endif //L1_DIFF
  2019. "movq %%mm0, %%mm4 \n\t"
  2020. "psrlq $32, %%mm0 \n\t"
  2021. "paddd %%mm0, %%mm4 \n\t"
  2022. "movd %%mm4, %%ecx \n\t"
  2023. "shll $2, %%ecx \n\t"
  2024. "mov %3, %%"FF_REG_d" \n\t"
  2025. "addl -4(%%"FF_REG_d"), %%ecx \n\t"
  2026. "addl 4(%%"FF_REG_d"), %%ecx \n\t"
  2027. "addl -1024(%%"FF_REG_d"), %%ecx \n\t"
  2028. "addl $4, %%ecx \n\t"
  2029. "addl 1024(%%"FF_REG_d"), %%ecx \n\t"
  2030. "shrl $3, %%ecx \n\t"
  2031. "movl %%ecx, (%%"FF_REG_d") \n\t"
  2032. // "mov %3, %%"FF_REG_c" \n\t"
  2033. // "mov %%"FF_REG_c", test \n\t"
  2034. // "jmp 4f \n\t"
  2035. "cmpl 512(%%"FF_REG_d"), %%ecx \n\t"
  2036. " jb 2f \n\t"
  2037. "cmpl 516(%%"FF_REG_d"), %%ecx \n\t"
  2038. " jb 1f \n\t"
  2039. "lea (%%"FF_REG_a", %2, 2), %%"FF_REG_d"\n\t" // 5*stride
  2040. "lea (%%"FF_REG_d", %2, 2), %%"FF_REG_c"\n\t" // 7*stride
  2041. "movq (%0), %%mm0 \n\t" // L0
  2042. "movq (%0, %2), %%mm1 \n\t" // L1
  2043. "movq (%0, %2, 2), %%mm2 \n\t" // L2
  2044. "movq (%0, %%"FF_REG_a"), %%mm3 \n\t" // L3
  2045. "movq (%0, %2, 4), %%mm4 \n\t" // L4
  2046. "movq (%0, %%"FF_REG_d"), %%mm5 \n\t" // L5
  2047. "movq (%0, %%"FF_REG_a", 2), %%mm6 \n\t" // L6
  2048. "movq (%0, %%"FF_REG_c"), %%mm7 \n\t" // L7
  2049. "movq %%mm0, (%1) \n\t" // L0
  2050. "movq %%mm1, (%1, %2) \n\t" // L1
  2051. "movq %%mm2, (%1, %2, 2) \n\t" // L2
  2052. "movq %%mm3, (%1, %%"FF_REG_a") \n\t" // L3
  2053. "movq %%mm4, (%1, %2, 4) \n\t" // L4
  2054. "movq %%mm5, (%1, %%"FF_REG_d") \n\t" // L5
  2055. "movq %%mm6, (%1, %%"FF_REG_a", 2) \n\t" // L6
  2056. "movq %%mm7, (%1, %%"FF_REG_c") \n\t" // L7
  2057. "jmp 4f \n\t"
  2058. "1: \n\t"
  2059. "lea (%%"FF_REG_a", %2, 2), %%"FF_REG_d"\n\t" // 5*stride
  2060. "lea (%%"FF_REG_d", %2, 2), %%"FF_REG_c"\n\t" // 7*stride
  2061. "movq (%0), %%mm0 \n\t" // L0
  2062. PAVGB((%1), %%mm0) // L0
  2063. "movq (%0, %2), %%mm1 \n\t" // L1
  2064. PAVGB((%1, %2), %%mm1) // L1
  2065. "movq (%0, %2, 2), %%mm2 \n\t" // L2
  2066. PAVGB((%1, %2, 2), %%mm2) // L2
  2067. "movq (%0, %%"FF_REG_a"), %%mm3 \n\t" // L3
  2068. PAVGB((%1, %%FF_REGa), %%mm3) // L3
  2069. "movq (%0, %2, 4), %%mm4 \n\t" // L4
  2070. PAVGB((%1, %2, 4), %%mm4) // L4
  2071. "movq (%0, %%"FF_REG_d"), %%mm5 \n\t" // L5
  2072. PAVGB((%1, %%FF_REGd), %%mm5) // L5
  2073. "movq (%0, %%"FF_REG_a", 2), %%mm6 \n\t" // L6
  2074. PAVGB((%1, %%FF_REGa, 2), %%mm6) // L6
  2075. "movq (%0, %%"FF_REG_c"), %%mm7 \n\t" // L7
  2076. PAVGB((%1, %%FF_REGc), %%mm7) // L7
  2077. "movq %%mm0, (%1) \n\t" // R0
  2078. "movq %%mm1, (%1, %2) \n\t" // R1
  2079. "movq %%mm2, (%1, %2, 2) \n\t" // R2
  2080. "movq %%mm3, (%1, %%"FF_REG_a") \n\t" // R3
  2081. "movq %%mm4, (%1, %2, 4) \n\t" // R4
  2082. "movq %%mm5, (%1, %%"FF_REG_d") \n\t" // R5
  2083. "movq %%mm6, (%1, %%"FF_REG_a", 2) \n\t" // R6
  2084. "movq %%mm7, (%1, %%"FF_REG_c") \n\t" // R7
  2085. "movq %%mm0, (%0) \n\t" // L0
  2086. "movq %%mm1, (%0, %2) \n\t" // L1
  2087. "movq %%mm2, (%0, %2, 2) \n\t" // L2
  2088. "movq %%mm3, (%0, %%"FF_REG_a") \n\t" // L3
  2089. "movq %%mm4, (%0, %2, 4) \n\t" // L4
  2090. "movq %%mm5, (%0, %%"FF_REG_d") \n\t" // L5
  2091. "movq %%mm6, (%0, %%"FF_REG_a", 2) \n\t" // L6
  2092. "movq %%mm7, (%0, %%"FF_REG_c") \n\t" // L7
  2093. "jmp 4f \n\t"
  2094. "2: \n\t"
  2095. "cmpl 508(%%"FF_REG_d"), %%ecx \n\t"
  2096. " jb 3f \n\t"
  2097. "lea (%%"FF_REG_a", %2, 2), %%"FF_REG_d"\n\t" // 5*stride
  2098. "lea (%%"FF_REG_d", %2, 2), %%"FF_REG_c"\n\t" // 7*stride
  2099. "movq (%0), %%mm0 \n\t" // L0
  2100. "movq (%0, %2), %%mm1 \n\t" // L1
  2101. "movq (%0, %2, 2), %%mm2 \n\t" // L2
  2102. "movq (%0, %%"FF_REG_a"), %%mm3 \n\t" // L3
  2103. "movq (%1), %%mm4 \n\t" // R0
  2104. "movq (%1, %2), %%mm5 \n\t" // R1
  2105. "movq (%1, %2, 2), %%mm6 \n\t" // R2
  2106. "movq (%1, %%"FF_REG_a"), %%mm7 \n\t" // R3
  2107. PAVGB(%%mm4, %%mm0)
  2108. PAVGB(%%mm5, %%mm1)
  2109. PAVGB(%%mm6, %%mm2)
  2110. PAVGB(%%mm7, %%mm3)
  2111. PAVGB(%%mm4, %%mm0)
  2112. PAVGB(%%mm5, %%mm1)
  2113. PAVGB(%%mm6, %%mm2)
  2114. PAVGB(%%mm7, %%mm3)
  2115. "movq %%mm0, (%1) \n\t" // R0
  2116. "movq %%mm1, (%1, %2) \n\t" // R1
  2117. "movq %%mm2, (%1, %2, 2) \n\t" // R2
  2118. "movq %%mm3, (%1, %%"FF_REG_a") \n\t" // R3
  2119. "movq %%mm0, (%0) \n\t" // L0
  2120. "movq %%mm1, (%0, %2) \n\t" // L1
  2121. "movq %%mm2, (%0, %2, 2) \n\t" // L2
  2122. "movq %%mm3, (%0, %%"FF_REG_a") \n\t" // L3
  2123. "movq (%0, %2, 4), %%mm0 \n\t" // L4
  2124. "movq (%0, %%"FF_REG_d"), %%mm1 \n\t" // L5
  2125. "movq (%0, %%"FF_REG_a", 2), %%mm2 \n\t" // L6
  2126. "movq (%0, %%"FF_REG_c"), %%mm3 \n\t" // L7
  2127. "movq (%1, %2, 4), %%mm4 \n\t" // R4
  2128. "movq (%1, %%"FF_REG_d"), %%mm5 \n\t" // R5
  2129. "movq (%1, %%"FF_REG_a", 2), %%mm6 \n\t" // R6
  2130. "movq (%1, %%"FF_REG_c"), %%mm7 \n\t" // R7
  2131. PAVGB(%%mm4, %%mm0)
  2132. PAVGB(%%mm5, %%mm1)
  2133. PAVGB(%%mm6, %%mm2)
  2134. PAVGB(%%mm7, %%mm3)
  2135. PAVGB(%%mm4, %%mm0)
  2136. PAVGB(%%mm5, %%mm1)
  2137. PAVGB(%%mm6, %%mm2)
  2138. PAVGB(%%mm7, %%mm3)
  2139. "movq %%mm0, (%1, %2, 4) \n\t" // R4
  2140. "movq %%mm1, (%1, %%"FF_REG_d") \n\t" // R5
  2141. "movq %%mm2, (%1, %%"FF_REG_a", 2) \n\t" // R6
  2142. "movq %%mm3, (%1, %%"FF_REG_c") \n\t" // R7
  2143. "movq %%mm0, (%0, %2, 4) \n\t" // L4
  2144. "movq %%mm1, (%0, %%"FF_REG_d") \n\t" // L5
  2145. "movq %%mm2, (%0, %%"FF_REG_a", 2) \n\t" // L6
  2146. "movq %%mm3, (%0, %%"FF_REG_c") \n\t" // L7
  2147. "jmp 4f \n\t"
  2148. "3: \n\t"
  2149. "lea (%%"FF_REG_a", %2, 2), %%"FF_REG_d"\n\t" // 5*stride
  2150. "lea (%%"FF_REG_d", %2, 2), %%"FF_REG_c"\n\t" // 7*stride
  2151. "movq (%0), %%mm0 \n\t" // L0
  2152. "movq (%0, %2), %%mm1 \n\t" // L1
  2153. "movq (%0, %2, 2), %%mm2 \n\t" // L2
  2154. "movq (%0, %%"FF_REG_a"), %%mm3 \n\t" // L3
  2155. "movq (%1), %%mm4 \n\t" // R0
  2156. "movq (%1, %2), %%mm5 \n\t" // R1
  2157. "movq (%1, %2, 2), %%mm6 \n\t" // R2
  2158. "movq (%1, %%"FF_REG_a"), %%mm7 \n\t" // R3
  2159. PAVGB(%%mm4, %%mm0)
  2160. PAVGB(%%mm5, %%mm1)
  2161. PAVGB(%%mm6, %%mm2)
  2162. PAVGB(%%mm7, %%mm3)
  2163. PAVGB(%%mm4, %%mm0)
  2164. PAVGB(%%mm5, %%mm1)
  2165. PAVGB(%%mm6, %%mm2)
  2166. PAVGB(%%mm7, %%mm3)
  2167. PAVGB(%%mm4, %%mm0)
  2168. PAVGB(%%mm5, %%mm1)
  2169. PAVGB(%%mm6, %%mm2)
  2170. PAVGB(%%mm7, %%mm3)
  2171. "movq %%mm0, (%1) \n\t" // R0
  2172. "movq %%mm1, (%1, %2) \n\t" // R1
  2173. "movq %%mm2, (%1, %2, 2) \n\t" // R2
  2174. "movq %%mm3, (%1, %%"FF_REG_a") \n\t" // R3
  2175. "movq %%mm0, (%0) \n\t" // L0
  2176. "movq %%mm1, (%0, %2) \n\t" // L1
  2177. "movq %%mm2, (%0, %2, 2) \n\t" // L2
  2178. "movq %%mm3, (%0, %%"FF_REG_a") \n\t" // L3
  2179. "movq (%0, %2, 4), %%mm0 \n\t" // L4
  2180. "movq (%0, %%"FF_REG_d"), %%mm1 \n\t" // L5
  2181. "movq (%0, %%"FF_REG_a", 2), %%mm2 \n\t" // L6
  2182. "movq (%0, %%"FF_REG_c"), %%mm3 \n\t" // L7
  2183. "movq (%1, %2, 4), %%mm4 \n\t" // R4
  2184. "movq (%1, %%"FF_REG_d"), %%mm5 \n\t" // R5
  2185. "movq (%1, %%"FF_REG_a", 2), %%mm6 \n\t" // R6
  2186. "movq (%1, %%"FF_REG_c"), %%mm7 \n\t" // R7
  2187. PAVGB(%%mm4, %%mm0)
  2188. PAVGB(%%mm5, %%mm1)
  2189. PAVGB(%%mm6, %%mm2)
  2190. PAVGB(%%mm7, %%mm3)
  2191. PAVGB(%%mm4, %%mm0)
  2192. PAVGB(%%mm5, %%mm1)
  2193. PAVGB(%%mm6, %%mm2)
  2194. PAVGB(%%mm7, %%mm3)
  2195. PAVGB(%%mm4, %%mm0)
  2196. PAVGB(%%mm5, %%mm1)
  2197. PAVGB(%%mm6, %%mm2)
  2198. PAVGB(%%mm7, %%mm3)
  2199. "movq %%mm0, (%1, %2, 4) \n\t" // R4
  2200. "movq %%mm1, (%1, %%"FF_REG_d") \n\t" // R5
  2201. "movq %%mm2, (%1, %%"FF_REG_a", 2) \n\t" // R6
  2202. "movq %%mm3, (%1, %%"FF_REG_c") \n\t" // R7
  2203. "movq %%mm0, (%0, %2, 4) \n\t" // L4
  2204. "movq %%mm1, (%0, %%"FF_REG_d") \n\t" // L5
  2205. "movq %%mm2, (%0, %%"FF_REG_a", 2) \n\t" // L6
  2206. "movq %%mm3, (%0, %%"FF_REG_c") \n\t" // L7
  2207. "4: \n\t"
  2208. :: "r" (src), "r" (tempBlurred), "r"((x86_reg)stride), "m" (tempBlurredPast)
  2209. NAMED_CONSTRAINTS_ADD(b80)
  2210. : "%"FF_REG_a, "%"FF_REG_d, "%"FF_REG_c, "memory"
  2211. );
  2212. #else //(TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW) && HAVE_6REGS
  2213. {
  2214. int y;
  2215. int d=0;
  2216. // int sysd=0;
  2217. int i;
  2218. for(y=0; y<8; y++){
  2219. int x;
  2220. for(x=0; x<8; x++){
  2221. int ref= tempBlurred[ x + y*stride ];
  2222. int cur= src[ x + y*stride ];
  2223. int d1=ref - cur;
  2224. // if(x==0 || x==7) d1+= d1>>1;
  2225. // if(y==0 || y==7) d1+= d1>>1;
  2226. // d+= FFABS(d1);
  2227. d+= d1*d1;
  2228. // sysd+= d1;
  2229. }
  2230. }
  2231. i=d;
  2232. d= (
  2233. 4*d
  2234. +(*(tempBlurredPast-256))
  2235. +(*(tempBlurredPast-1))+ (*(tempBlurredPast+1))
  2236. +(*(tempBlurredPast+256))
  2237. +4)>>3;
  2238. *tempBlurredPast=i;
  2239. // ((*tempBlurredPast)*3 + d + 2)>>2;
  2240. /*
  2241. Switch between
  2242. 1 0 0 0 0 0 0 (0)
  2243. 64 32 16 8 4 2 1 (1)
  2244. 64 48 36 27 20 15 11 (33) (approx)
  2245. 64 56 49 43 37 33 29 (200) (approx)
  2246. */
  2247. if(d > maxNoise[1]){
  2248. if(d < maxNoise[2]){
  2249. for(y=0; y<8; y++){
  2250. int x;
  2251. for(x=0; x<8; x++){
  2252. int ref= tempBlurred[ x + y*stride ];
  2253. int cur= src[ x + y*stride ];
  2254. tempBlurred[ x + y*stride ]=
  2255. src[ x + y*stride ]=
  2256. (ref + cur + 1)>>1;
  2257. }
  2258. }
  2259. }else{
  2260. for(y=0; y<8; y++){
  2261. int x;
  2262. for(x=0; x<8; x++){
  2263. tempBlurred[ x + y*stride ]= src[ x + y*stride ];
  2264. }
  2265. }
  2266. }
  2267. }else{
  2268. if(d < maxNoise[0]){
  2269. for(y=0; y<8; y++){
  2270. int x;
  2271. for(x=0; x<8; x++){
  2272. int ref= tempBlurred[ x + y*stride ];
  2273. int cur= src[ x + y*stride ];
  2274. tempBlurred[ x + y*stride ]=
  2275. src[ x + y*stride ]=
  2276. (ref*7 + cur + 4)>>3;
  2277. }
  2278. }
  2279. }else{
  2280. for(y=0; y<8; y++){
  2281. int x;
  2282. for(x=0; x<8; x++){
  2283. int ref= tempBlurred[ x + y*stride ];
  2284. int cur= src[ x + y*stride ];
  2285. tempBlurred[ x + y*stride ]=
  2286. src[ x + y*stride ]=
  2287. (ref*3 + cur + 2)>>2;
  2288. }
  2289. }
  2290. }
  2291. }
  2292. }
  2293. #endif //(TEMPLATE_PP_MMXEXT || TEMPLATE_PP_3DNOW) && HAVE_6REGS
  2294. }
  2295. #endif //TEMPLATE_PP_ALTIVEC
  2296. #if TEMPLATE_PP_MMX
  2297. /**
  2298. * accurate deblock filter
  2299. */
  2300. static av_always_inline void RENAME(do_a_deblock)(uint8_t *src, int step, int stride, const PPContext *c, int mode){
  2301. int64_t dc_mask, eq_mask, both_masks;
  2302. int64_t sums[10*8*2];
  2303. src+= step*3; // src points to begin of the 8x8 Block
  2304. //{ START_TIMER
  2305. __asm__ volatile(
  2306. "movq %0, %%mm7 \n\t"
  2307. "movq %1, %%mm6 \n\t"
  2308. : : "m" (c->mmxDcOffset[c->nonBQP]), "m" (c->mmxDcThreshold[c->nonBQP])
  2309. );
  2310. __asm__ volatile(
  2311. "lea (%2, %3), %%"FF_REG_a" \n\t"
  2312. // 0 1 2 3 4 5 6 7 8 9
  2313. // %1 eax eax+%2 eax+2%2 %1+4%2 ecx ecx+%2 ecx+2%2 %1+8%2 ecx+4%2
  2314. "movq (%2), %%mm0 \n\t"
  2315. "movq (%%"FF_REG_a"), %%mm1 \n\t"
  2316. "movq %%mm1, %%mm3 \n\t"
  2317. "movq %%mm1, %%mm4 \n\t"
  2318. "psubb %%mm1, %%mm0 \n\t" // mm0 = difference
  2319. "paddb %%mm7, %%mm0 \n\t"
  2320. "pcmpgtb %%mm6, %%mm0 \n\t"
  2321. "movq (%%"FF_REG_a",%3), %%mm2 \n\t"
  2322. PMAXUB(%%mm2, %%mm4)
  2323. PMINUB(%%mm2, %%mm3, %%mm5)
  2324. "psubb %%mm2, %%mm1 \n\t"
  2325. "paddb %%mm7, %%mm1 \n\t"
  2326. "pcmpgtb %%mm6, %%mm1 \n\t"
  2327. "paddb %%mm1, %%mm0 \n\t"
  2328. "movq (%%"FF_REG_a", %3, 2), %%mm1 \n\t"
  2329. PMAXUB(%%mm1, %%mm4)
  2330. PMINUB(%%mm1, %%mm3, %%mm5)
  2331. "psubb %%mm1, %%mm2 \n\t"
  2332. "paddb %%mm7, %%mm2 \n\t"
  2333. "pcmpgtb %%mm6, %%mm2 \n\t"
  2334. "paddb %%mm2, %%mm0 \n\t"
  2335. "lea (%%"FF_REG_a", %3, 4), %%"FF_REG_a"\n\t"
  2336. "movq (%2, %3, 4), %%mm2 \n\t"
  2337. PMAXUB(%%mm2, %%mm4)
  2338. PMINUB(%%mm2, %%mm3, %%mm5)
  2339. "psubb %%mm2, %%mm1 \n\t"
  2340. "paddb %%mm7, %%mm1 \n\t"
  2341. "pcmpgtb %%mm6, %%mm1 \n\t"
  2342. "paddb %%mm1, %%mm0 \n\t"
  2343. "movq (%%"FF_REG_a"), %%mm1 \n\t"
  2344. PMAXUB(%%mm1, %%mm4)
  2345. PMINUB(%%mm1, %%mm3, %%mm5)
  2346. "psubb %%mm1, %%mm2 \n\t"
  2347. "paddb %%mm7, %%mm2 \n\t"
  2348. "pcmpgtb %%mm6, %%mm2 \n\t"
  2349. "paddb %%mm2, %%mm0 \n\t"
  2350. "movq (%%"FF_REG_a", %3), %%mm2 \n\t"
  2351. PMAXUB(%%mm2, %%mm4)
  2352. PMINUB(%%mm2, %%mm3, %%mm5)
  2353. "psubb %%mm2, %%mm1 \n\t"
  2354. "paddb %%mm7, %%mm1 \n\t"
  2355. "pcmpgtb %%mm6, %%mm1 \n\t"
  2356. "paddb %%mm1, %%mm0 \n\t"
  2357. "movq (%%"FF_REG_a", %3, 2), %%mm1 \n\t"
  2358. PMAXUB(%%mm1, %%mm4)
  2359. PMINUB(%%mm1, %%mm3, %%mm5)
  2360. "psubb %%mm1, %%mm2 \n\t"
  2361. "paddb %%mm7, %%mm2 \n\t"
  2362. "pcmpgtb %%mm6, %%mm2 \n\t"
  2363. "paddb %%mm2, %%mm0 \n\t"
  2364. "movq (%2, %3, 8), %%mm2 \n\t"
  2365. PMAXUB(%%mm2, %%mm4)
  2366. PMINUB(%%mm2, %%mm3, %%mm5)
  2367. "psubb %%mm2, %%mm1 \n\t"
  2368. "paddb %%mm7, %%mm1 \n\t"
  2369. "pcmpgtb %%mm6, %%mm1 \n\t"
  2370. "paddb %%mm1, %%mm0 \n\t"
  2371. "movq (%%"FF_REG_a", %3, 4), %%mm1 \n\t"
  2372. "psubb %%mm1, %%mm2 \n\t"
  2373. "paddb %%mm7, %%mm2 \n\t"
  2374. "pcmpgtb %%mm6, %%mm2 \n\t"
  2375. "paddb %%mm2, %%mm0 \n\t"
  2376. "psubusb %%mm3, %%mm4 \n\t"
  2377. "pxor %%mm6, %%mm6 \n\t"
  2378. "movq %4, %%mm7 \n\t" // QP,..., QP
  2379. "paddusb %%mm7, %%mm7 \n\t" // 2QP ... 2QP
  2380. "psubusb %%mm4, %%mm7 \n\t" // Diff >=2QP -> 0
  2381. "pcmpeqb %%mm6, %%mm7 \n\t" // Diff < 2QP -> 0
  2382. "pcmpeqb %%mm6, %%mm7 \n\t" // Diff < 2QP -> 0
  2383. "movq %%mm7, %1 \n\t"
  2384. "movq %5, %%mm7 \n\t"
  2385. "punpcklbw %%mm7, %%mm7 \n\t"
  2386. "punpcklbw %%mm7, %%mm7 \n\t"
  2387. "punpcklbw %%mm7, %%mm7 \n\t"
  2388. "psubb %%mm0, %%mm6 \n\t"
  2389. "pcmpgtb %%mm7, %%mm6 \n\t"
  2390. "movq %%mm6, %0 \n\t"
  2391. : "=m" (eq_mask), "=m" (dc_mask)
  2392. : "r" (src), "r" ((x86_reg)step), "m" (c->pQPb), "m"(c->ppMode.flatnessThreshold)
  2393. : "%"FF_REG_a
  2394. );
  2395. both_masks = dc_mask & eq_mask;
  2396. if(both_masks){
  2397. x86_reg offset= -8*step;
  2398. int64_t *temp_sums= sums;
  2399. __asm__ volatile(
  2400. "movq %2, %%mm0 \n\t" // QP,..., QP
  2401. "pxor %%mm4, %%mm4 \n\t"
  2402. "movq (%0), %%mm6 \n\t"
  2403. "movq (%0, %1), %%mm5 \n\t"
  2404. "movq %%mm5, %%mm1 \n\t"
  2405. "movq %%mm6, %%mm2 \n\t"
  2406. "psubusb %%mm6, %%mm5 \n\t"
  2407. "psubusb %%mm1, %%mm2 \n\t"
  2408. "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
  2409. "psubusb %%mm2, %%mm0 \n\t" // diff >= QP -> 0
  2410. "pcmpeqb %%mm4, %%mm0 \n\t" // diff >= QP -> FF
  2411. "pxor %%mm6, %%mm1 \n\t"
  2412. "pand %%mm0, %%mm1 \n\t"
  2413. "pxor %%mm1, %%mm6 \n\t"
  2414. // 0:QP 6:First
  2415. "movq (%0, %1, 8), %%mm5 \n\t"
  2416. "add %1, %0 \n\t" // %0 points to line 1 not 0
  2417. "movq (%0, %1, 8), %%mm7 \n\t"
  2418. "movq %%mm5, %%mm1 \n\t"
  2419. "movq %%mm7, %%mm2 \n\t"
  2420. "psubusb %%mm7, %%mm5 \n\t"
  2421. "psubusb %%mm1, %%mm2 \n\t"
  2422. "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
  2423. "movq %2, %%mm0 \n\t" // QP,..., QP
  2424. "psubusb %%mm2, %%mm0 \n\t" // diff >= QP -> 0
  2425. "pcmpeqb %%mm4, %%mm0 \n\t" // diff >= QP -> FF
  2426. "pxor %%mm7, %%mm1 \n\t"
  2427. "pand %%mm0, %%mm1 \n\t"
  2428. "pxor %%mm1, %%mm7 \n\t"
  2429. "movq %%mm6, %%mm5 \n\t"
  2430. "punpckhbw %%mm4, %%mm6 \n\t"
  2431. "punpcklbw %%mm4, %%mm5 \n\t"
  2432. // 4:0 5/6:First 7:Last
  2433. "movq %%mm5, %%mm0 \n\t"
  2434. "movq %%mm6, %%mm1 \n\t"
  2435. "psllw $2, %%mm0 \n\t"
  2436. "psllw $2, %%mm1 \n\t"
  2437. "paddw "MANGLE(w04)", %%mm0 \n\t"
  2438. "paddw "MANGLE(w04)", %%mm1 \n\t"
  2439. #define NEXT\
  2440. "movq (%0), %%mm2 \n\t"\
  2441. "movq (%0), %%mm3 \n\t"\
  2442. "add %1, %0 \n\t"\
  2443. "punpcklbw %%mm4, %%mm2 \n\t"\
  2444. "punpckhbw %%mm4, %%mm3 \n\t"\
  2445. "paddw %%mm2, %%mm0 \n\t"\
  2446. "paddw %%mm3, %%mm1 \n\t"
  2447. #define PREV\
  2448. "movq (%0), %%mm2 \n\t"\
  2449. "movq (%0), %%mm3 \n\t"\
  2450. "add %1, %0 \n\t"\
  2451. "punpcklbw %%mm4, %%mm2 \n\t"\
  2452. "punpckhbw %%mm4, %%mm3 \n\t"\
  2453. "psubw %%mm2, %%mm0 \n\t"\
  2454. "psubw %%mm3, %%mm1 \n\t"
  2455. NEXT //0
  2456. NEXT //1
  2457. NEXT //2
  2458. "movq %%mm0, (%3) \n\t"
  2459. "movq %%mm1, 8(%3) \n\t"
  2460. NEXT //3
  2461. "psubw %%mm5, %%mm0 \n\t"
  2462. "psubw %%mm6, %%mm1 \n\t"
  2463. "movq %%mm0, 16(%3) \n\t"
  2464. "movq %%mm1, 24(%3) \n\t"
  2465. NEXT //4
  2466. "psubw %%mm5, %%mm0 \n\t"
  2467. "psubw %%mm6, %%mm1 \n\t"
  2468. "movq %%mm0, 32(%3) \n\t"
  2469. "movq %%mm1, 40(%3) \n\t"
  2470. NEXT //5
  2471. "psubw %%mm5, %%mm0 \n\t"
  2472. "psubw %%mm6, %%mm1 \n\t"
  2473. "movq %%mm0, 48(%3) \n\t"
  2474. "movq %%mm1, 56(%3) \n\t"
  2475. NEXT //6
  2476. "psubw %%mm5, %%mm0 \n\t"
  2477. "psubw %%mm6, %%mm1 \n\t"
  2478. "movq %%mm0, 64(%3) \n\t"
  2479. "movq %%mm1, 72(%3) \n\t"
  2480. "movq %%mm7, %%mm6 \n\t"
  2481. "punpckhbw %%mm4, %%mm7 \n\t"
  2482. "punpcklbw %%mm4, %%mm6 \n\t"
  2483. NEXT //7
  2484. "mov %4, %0 \n\t"
  2485. "add %1, %0 \n\t"
  2486. PREV //0
  2487. "movq %%mm0, 80(%3) \n\t"
  2488. "movq %%mm1, 88(%3) \n\t"
  2489. PREV //1
  2490. "paddw %%mm6, %%mm0 \n\t"
  2491. "paddw %%mm7, %%mm1 \n\t"
  2492. "movq %%mm0, 96(%3) \n\t"
  2493. "movq %%mm1, 104(%3) \n\t"
  2494. PREV //2
  2495. "paddw %%mm6, %%mm0 \n\t"
  2496. "paddw %%mm7, %%mm1 \n\t"
  2497. "movq %%mm0, 112(%3) \n\t"
  2498. "movq %%mm1, 120(%3) \n\t"
  2499. PREV //3
  2500. "paddw %%mm6, %%mm0 \n\t"
  2501. "paddw %%mm7, %%mm1 \n\t"
  2502. "movq %%mm0, 128(%3) \n\t"
  2503. "movq %%mm1, 136(%3) \n\t"
  2504. PREV //4
  2505. "paddw %%mm6, %%mm0 \n\t"
  2506. "paddw %%mm7, %%mm1 \n\t"
  2507. "movq %%mm0, 144(%3) \n\t"
  2508. "movq %%mm1, 152(%3) \n\t"
  2509. "mov %4, %0 \n\t" //FIXME
  2510. : "+&r"(src)
  2511. : "r" ((x86_reg)step), "m" (c->pQPb), "r"(sums), "g"(src)
  2512. NAMED_CONSTRAINTS_ADD(w04)
  2513. );
  2514. src+= step; // src points to begin of the 8x8 Block
  2515. __asm__ volatile(
  2516. "movq %4, %%mm6 \n\t"
  2517. "pcmpeqb %%mm5, %%mm5 \n\t"
  2518. "pxor %%mm6, %%mm5 \n\t"
  2519. "pxor %%mm7, %%mm7 \n\t"
  2520. "1: \n\t"
  2521. "movq (%1), %%mm0 \n\t"
  2522. "movq 8(%1), %%mm1 \n\t"
  2523. "paddw 32(%1), %%mm0 \n\t"
  2524. "paddw 40(%1), %%mm1 \n\t"
  2525. "movq (%0, %3), %%mm2 \n\t"
  2526. "movq %%mm2, %%mm3 \n\t"
  2527. "movq %%mm2, %%mm4 \n\t"
  2528. "punpcklbw %%mm7, %%mm2 \n\t"
  2529. "punpckhbw %%mm7, %%mm3 \n\t"
  2530. "paddw %%mm2, %%mm0 \n\t"
  2531. "paddw %%mm3, %%mm1 \n\t"
  2532. "paddw %%mm2, %%mm0 \n\t"
  2533. "paddw %%mm3, %%mm1 \n\t"
  2534. "psrlw $4, %%mm0 \n\t"
  2535. "psrlw $4, %%mm1 \n\t"
  2536. "packuswb %%mm1, %%mm0 \n\t"
  2537. "pand %%mm6, %%mm0 \n\t"
  2538. "pand %%mm5, %%mm4 \n\t"
  2539. "por %%mm4, %%mm0 \n\t"
  2540. "movq %%mm0, (%0, %3) \n\t"
  2541. "add $16, %1 \n\t"
  2542. "add %2, %0 \n\t"
  2543. " js 1b \n\t"
  2544. : "+r"(offset), "+r"(temp_sums)
  2545. : "r" ((x86_reg)step), "r"(src - offset), "m"(both_masks)
  2546. );
  2547. }else
  2548. src+= step; // src points to begin of the 8x8 Block
  2549. if(eq_mask != -1LL){
  2550. uint8_t *temp_src= src;
  2551. DECLARE_ALIGNED(8, uint64_t, tmp)[4]; // make space for 4 8-byte vars
  2552. __asm__ volatile(
  2553. "pxor %%mm7, %%mm7 \n\t"
  2554. // 0 1 2 3 4 5 6 7 8 9
  2555. // %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %1+8%1 ecx+4%1
  2556. "movq (%0), %%mm0 \n\t"
  2557. "movq %%mm0, %%mm1 \n\t"
  2558. "punpcklbw %%mm7, %%mm0 \n\t" // low part of line 0
  2559. "punpckhbw %%mm7, %%mm1 \n\t" // high part of line 0
  2560. "movq (%0, %1), %%mm2 \n\t"
  2561. "lea (%0, %1, 2), %%"FF_REG_a" \n\t"
  2562. "movq %%mm2, %%mm3 \n\t"
  2563. "punpcklbw %%mm7, %%mm2 \n\t" // low part of line 1
  2564. "punpckhbw %%mm7, %%mm3 \n\t" // high part of line 1
  2565. "movq (%%"FF_REG_a"), %%mm4 \n\t"
  2566. "movq %%mm4, %%mm5 \n\t"
  2567. "punpcklbw %%mm7, %%mm4 \n\t" // low part of line 2
  2568. "punpckhbw %%mm7, %%mm5 \n\t" // high part of line 2
  2569. "paddw %%mm0, %%mm0 \n\t" // 2L0
  2570. "paddw %%mm1, %%mm1 \n\t" // 2H0
  2571. "psubw %%mm4, %%mm2 \n\t" // L1 - L2
  2572. "psubw %%mm5, %%mm3 \n\t" // H1 - H2
  2573. "psubw %%mm2, %%mm0 \n\t" // 2L0 - L1 + L2
  2574. "psubw %%mm3, %%mm1 \n\t" // 2H0 - H1 + H2
  2575. "psllw $2, %%mm2 \n\t" // 4L1 - 4L2
  2576. "psllw $2, %%mm3 \n\t" // 4H1 - 4H2
  2577. "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2
  2578. "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2
  2579. "movq (%%"FF_REG_a", %1), %%mm2 \n\t"
  2580. "movq %%mm2, %%mm3 \n\t"
  2581. "punpcklbw %%mm7, %%mm2 \n\t" // L3
  2582. "punpckhbw %%mm7, %%mm3 \n\t" // H3
  2583. "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - L3
  2584. "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - H3
  2585. "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
  2586. "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
  2587. "movq %%mm0, (%4) \n\t" // 2L0 - 5L1 + 5L2 - 2L3
  2588. "movq %%mm1, 8(%4) \n\t" // 2H0 - 5H1 + 5H2 - 2H3
  2589. "movq (%%"FF_REG_a", %1, 2), %%mm0 \n\t"
  2590. "movq %%mm0, %%mm1 \n\t"
  2591. "punpcklbw %%mm7, %%mm0 \n\t" // L4
  2592. "punpckhbw %%mm7, %%mm1 \n\t" // H4
  2593. "psubw %%mm0, %%mm2 \n\t" // L3 - L4
  2594. "psubw %%mm1, %%mm3 \n\t" // H3 - H4
  2595. "movq %%mm2, 16(%4) \n\t" // L3 - L4
  2596. "movq %%mm3, 24(%4) \n\t" // H3 - H4
  2597. "paddw %%mm4, %%mm4 \n\t" // 2L2
  2598. "paddw %%mm5, %%mm5 \n\t" // 2H2
  2599. "psubw %%mm2, %%mm4 \n\t" // 2L2 - L3 + L4
  2600. "psubw %%mm3, %%mm5 \n\t" // 2H2 - H3 + H4
  2601. "lea (%%"FF_REG_a", %1), %0 \n\t"
  2602. "psllw $2, %%mm2 \n\t" // 4L3 - 4L4
  2603. "psllw $2, %%mm3 \n\t" // 4H3 - 4H4
  2604. "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4
  2605. "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4
  2606. //50 opcodes so far
  2607. "movq (%0, %1, 2), %%mm2 \n\t"
  2608. "movq %%mm2, %%mm3 \n\t"
  2609. "punpcklbw %%mm7, %%mm2 \n\t" // L5
  2610. "punpckhbw %%mm7, %%mm3 \n\t" // H5
  2611. "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - L5
  2612. "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - H5
  2613. "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - 2L5
  2614. "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - 2H5
  2615. "movq (%%"FF_REG_a", %1, 4), %%mm6 \n\t"
  2616. "punpcklbw %%mm7, %%mm6 \n\t" // L6
  2617. "psubw %%mm6, %%mm2 \n\t" // L5 - L6
  2618. "movq (%%"FF_REG_a", %1, 4), %%mm6 \n\t"
  2619. "punpckhbw %%mm7, %%mm6 \n\t" // H6
  2620. "psubw %%mm6, %%mm3 \n\t" // H5 - H6
  2621. "paddw %%mm0, %%mm0 \n\t" // 2L4
  2622. "paddw %%mm1, %%mm1 \n\t" // 2H4
  2623. "psubw %%mm2, %%mm0 \n\t" // 2L4 - L5 + L6
  2624. "psubw %%mm3, %%mm1 \n\t" // 2H4 - H5 + H6
  2625. "psllw $2, %%mm2 \n\t" // 4L5 - 4L6
  2626. "psllw $2, %%mm3 \n\t" // 4H5 - 4H6
  2627. "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6
  2628. "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6
  2629. "movq (%0, %1, 4), %%mm2 \n\t"
  2630. "movq %%mm2, %%mm3 \n\t"
  2631. "punpcklbw %%mm7, %%mm2 \n\t" // L7
  2632. "punpckhbw %%mm7, %%mm3 \n\t" // H7
  2633. "paddw %%mm2, %%mm2 \n\t" // 2L7
  2634. "paddw %%mm3, %%mm3 \n\t" // 2H7
  2635. "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6 - 2L7
  2636. "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6 - 2H7
  2637. "movq (%4), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
  2638. "movq 8(%4), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
  2639. #if TEMPLATE_PP_MMXEXT
  2640. "movq %%mm7, %%mm6 \n\t" // 0
  2641. "psubw %%mm0, %%mm6 \n\t"
  2642. "pmaxsw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
  2643. "movq %%mm7, %%mm6 \n\t" // 0
  2644. "psubw %%mm1, %%mm6 \n\t"
  2645. "pmaxsw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
  2646. "movq %%mm7, %%mm6 \n\t" // 0
  2647. "psubw %%mm2, %%mm6 \n\t"
  2648. "pmaxsw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
  2649. "movq %%mm7, %%mm6 \n\t" // 0
  2650. "psubw %%mm3, %%mm6 \n\t"
  2651. "pmaxsw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
  2652. #else
  2653. "movq %%mm7, %%mm6 \n\t" // 0
  2654. "pcmpgtw %%mm0, %%mm6 \n\t"
  2655. "pxor %%mm6, %%mm0 \n\t"
  2656. "psubw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
  2657. "movq %%mm7, %%mm6 \n\t" // 0
  2658. "pcmpgtw %%mm1, %%mm6 \n\t"
  2659. "pxor %%mm6, %%mm1 \n\t"
  2660. "psubw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
  2661. "movq %%mm7, %%mm6 \n\t" // 0
  2662. "pcmpgtw %%mm2, %%mm6 \n\t"
  2663. "pxor %%mm6, %%mm2 \n\t"
  2664. "psubw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
  2665. "movq %%mm7, %%mm6 \n\t" // 0
  2666. "pcmpgtw %%mm3, %%mm6 \n\t"
  2667. "pxor %%mm6, %%mm3 \n\t"
  2668. "psubw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
  2669. #endif
  2670. #if TEMPLATE_PP_MMXEXT
  2671. "pminsw %%mm2, %%mm0 \n\t"
  2672. "pminsw %%mm3, %%mm1 \n\t"
  2673. #else
  2674. "movq %%mm0, %%mm6 \n\t"
  2675. "psubusw %%mm2, %%mm6 \n\t"
  2676. "psubw %%mm6, %%mm0 \n\t"
  2677. "movq %%mm1, %%mm6 \n\t"
  2678. "psubusw %%mm3, %%mm6 \n\t"
  2679. "psubw %%mm6, %%mm1 \n\t"
  2680. #endif
  2681. "movd %2, %%mm2 \n\t" // QP
  2682. "punpcklbw %%mm7, %%mm2 \n\t"
  2683. "movq %%mm7, %%mm6 \n\t" // 0
  2684. "pcmpgtw %%mm4, %%mm6 \n\t" // sign(2L2 - 5L3 + 5L4 - 2L5)
  2685. "pxor %%mm6, %%mm4 \n\t"
  2686. "psubw %%mm6, %%mm4 \n\t" // |2L2 - 5L3 + 5L4 - 2L5|
  2687. "pcmpgtw %%mm5, %%mm7 \n\t" // sign(2H2 - 5H3 + 5H4 - 2H5)
  2688. "pxor %%mm7, %%mm5 \n\t"
  2689. "psubw %%mm7, %%mm5 \n\t" // |2H2 - 5H3 + 5H4 - 2H5|
  2690. // 100 opcodes
  2691. "psllw $3, %%mm2 \n\t" // 8QP
  2692. "movq %%mm2, %%mm3 \n\t" // 8QP
  2693. "pcmpgtw %%mm4, %%mm2 \n\t"
  2694. "pcmpgtw %%mm5, %%mm3 \n\t"
  2695. "pand %%mm2, %%mm4 \n\t"
  2696. "pand %%mm3, %%mm5 \n\t"
  2697. "psubusw %%mm0, %%mm4 \n\t" // hd
  2698. "psubusw %%mm1, %%mm5 \n\t" // ld
  2699. "movq "MANGLE(w05)", %%mm2 \n\t" // 5
  2700. "pmullw %%mm2, %%mm4 \n\t"
  2701. "pmullw %%mm2, %%mm5 \n\t"
  2702. "movq "MANGLE(w20)", %%mm2 \n\t" // 32
  2703. "paddw %%mm2, %%mm4 \n\t"
  2704. "paddw %%mm2, %%mm5 \n\t"
  2705. "psrlw $6, %%mm4 \n\t"
  2706. "psrlw $6, %%mm5 \n\t"
  2707. "movq 16(%4), %%mm0 \n\t" // L3 - L4
  2708. "movq 24(%4), %%mm1 \n\t" // H3 - H4
  2709. "pxor %%mm2, %%mm2 \n\t"
  2710. "pxor %%mm3, %%mm3 \n\t"
  2711. "pcmpgtw %%mm0, %%mm2 \n\t" // sign (L3-L4)
  2712. "pcmpgtw %%mm1, %%mm3 \n\t" // sign (H3-H4)
  2713. "pxor %%mm2, %%mm0 \n\t"
  2714. "pxor %%mm3, %%mm1 \n\t"
  2715. "psubw %%mm2, %%mm0 \n\t" // |L3-L4|
  2716. "psubw %%mm3, %%mm1 \n\t" // |H3-H4|
  2717. "psrlw $1, %%mm0 \n\t" // |L3 - L4|/2
  2718. "psrlw $1, %%mm1 \n\t" // |H3 - H4|/2
  2719. "pxor %%mm6, %%mm2 \n\t"
  2720. "pxor %%mm7, %%mm3 \n\t"
  2721. "pand %%mm2, %%mm4 \n\t"
  2722. "pand %%mm3, %%mm5 \n\t"
  2723. #if TEMPLATE_PP_MMXEXT
  2724. "pminsw %%mm0, %%mm4 \n\t"
  2725. "pminsw %%mm1, %%mm5 \n\t"
  2726. #else
  2727. "movq %%mm4, %%mm2 \n\t"
  2728. "psubusw %%mm0, %%mm2 \n\t"
  2729. "psubw %%mm2, %%mm4 \n\t"
  2730. "movq %%mm5, %%mm2 \n\t"
  2731. "psubusw %%mm1, %%mm2 \n\t"
  2732. "psubw %%mm2, %%mm5 \n\t"
  2733. #endif
  2734. "pxor %%mm6, %%mm4 \n\t"
  2735. "pxor %%mm7, %%mm5 \n\t"
  2736. "psubw %%mm6, %%mm4 \n\t"
  2737. "psubw %%mm7, %%mm5 \n\t"
  2738. "packsswb %%mm5, %%mm4 \n\t"
  2739. "movq %3, %%mm1 \n\t"
  2740. "pandn %%mm4, %%mm1 \n\t"
  2741. "movq (%0), %%mm0 \n\t"
  2742. "paddb %%mm1, %%mm0 \n\t"
  2743. "movq %%mm0, (%0) \n\t"
  2744. "movq (%0, %1), %%mm0 \n\t"
  2745. "psubb %%mm1, %%mm0 \n\t"
  2746. "movq %%mm0, (%0, %1) \n\t"
  2747. : "+r" (temp_src)
  2748. : "r" ((x86_reg)step), "m" (c->pQPb), "m"(eq_mask), "r"(tmp)
  2749. NAMED_CONSTRAINTS_ADD(w05,w20)
  2750. : "%"FF_REG_a
  2751. );
  2752. }
  2753. /*if(step==16){
  2754. STOP_TIMER("step16")
  2755. }else{
  2756. STOP_TIMER("stepX")
  2757. }
  2758. } */
  2759. }
  2760. #endif //TEMPLATE_PP_MMX
  2761. static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
  2762. const QP_STORE_T QPs[], int QPStride, int isColor, PPContext *c);
  2763. /**
  2764. * Copy a block from src to dst and fixes the blacklevel.
  2765. * levelFix == 0 -> do not touch the brightness & contrast
  2766. */
  2767. #undef REAL_SCALED_CPY
  2768. #undef SCALED_CPY
  2769. static inline void RENAME(blockCopy)(uint8_t dst[], int dstStride, const uint8_t src[], int srcStride,
  2770. int levelFix, int64_t *packedOffsetAndScale)
  2771. {
  2772. #if !TEMPLATE_PP_MMX || !HAVE_6REGS
  2773. int i;
  2774. #endif
  2775. if(levelFix){
  2776. #if TEMPLATE_PP_MMX && HAVE_6REGS
  2777. __asm__ volatile(
  2778. "movq (%%"FF_REG_a"), %%mm2 \n\t" // packedYOffset
  2779. "movq 8(%%"FF_REG_a"), %%mm3 \n\t" // packedYScale
  2780. "lea (%2,%4), %%"FF_REG_a" \n\t"
  2781. "lea (%3,%5), %%"FF_REG_d" \n\t"
  2782. "pxor %%mm4, %%mm4 \n\t"
  2783. #if TEMPLATE_PP_MMXEXT
  2784. #define REAL_SCALED_CPY(src1, src2, dst1, dst2) \
  2785. "movq " #src1 ", %%mm0 \n\t"\
  2786. "movq " #src1 ", %%mm5 \n\t"\
  2787. "movq " #src2 ", %%mm1 \n\t"\
  2788. "movq " #src2 ", %%mm6 \n\t"\
  2789. "punpcklbw %%mm0, %%mm0 \n\t"\
  2790. "punpckhbw %%mm5, %%mm5 \n\t"\
  2791. "punpcklbw %%mm1, %%mm1 \n\t"\
  2792. "punpckhbw %%mm6, %%mm6 \n\t"\
  2793. "pmulhuw %%mm3, %%mm0 \n\t"\
  2794. "pmulhuw %%mm3, %%mm5 \n\t"\
  2795. "pmulhuw %%mm3, %%mm1 \n\t"\
  2796. "pmulhuw %%mm3, %%mm6 \n\t"\
  2797. "psubw %%mm2, %%mm0 \n\t"\
  2798. "psubw %%mm2, %%mm5 \n\t"\
  2799. "psubw %%mm2, %%mm1 \n\t"\
  2800. "psubw %%mm2, %%mm6 \n\t"\
  2801. "packuswb %%mm5, %%mm0 \n\t"\
  2802. "packuswb %%mm6, %%mm1 \n\t"\
  2803. "movq %%mm0, " #dst1 " \n\t"\
  2804. "movq %%mm1, " #dst2 " \n\t"\
  2805. #else //TEMPLATE_PP_MMXEXT
  2806. #define REAL_SCALED_CPY(src1, src2, dst1, dst2) \
  2807. "movq " #src1 ", %%mm0 \n\t"\
  2808. "movq " #src1 ", %%mm5 \n\t"\
  2809. "punpcklbw %%mm4, %%mm0 \n\t"\
  2810. "punpckhbw %%mm4, %%mm5 \n\t"\
  2811. "psubw %%mm2, %%mm0 \n\t"\
  2812. "psubw %%mm2, %%mm5 \n\t"\
  2813. "movq " #src2 ", %%mm1 \n\t"\
  2814. "psllw $6, %%mm0 \n\t"\
  2815. "psllw $6, %%mm5 \n\t"\
  2816. "pmulhw %%mm3, %%mm0 \n\t"\
  2817. "movq " #src2 ", %%mm6 \n\t"\
  2818. "pmulhw %%mm3, %%mm5 \n\t"\
  2819. "punpcklbw %%mm4, %%mm1 \n\t"\
  2820. "punpckhbw %%mm4, %%mm6 \n\t"\
  2821. "psubw %%mm2, %%mm1 \n\t"\
  2822. "psubw %%mm2, %%mm6 \n\t"\
  2823. "psllw $6, %%mm1 \n\t"\
  2824. "psllw $6, %%mm6 \n\t"\
  2825. "pmulhw %%mm3, %%mm1 \n\t"\
  2826. "pmulhw %%mm3, %%mm6 \n\t"\
  2827. "packuswb %%mm5, %%mm0 \n\t"\
  2828. "packuswb %%mm6, %%mm1 \n\t"\
  2829. "movq %%mm0, " #dst1 " \n\t"\
  2830. "movq %%mm1, " #dst2 " \n\t"\
  2831. #endif //TEMPLATE_PP_MMXEXT
  2832. #define SCALED_CPY(src1, src2, dst1, dst2)\
  2833. REAL_SCALED_CPY(src1, src2, dst1, dst2)
  2834. SCALED_CPY((%2) , (%2, %4) , (%3) , (%3, %5))
  2835. SCALED_CPY((%2, %4, 2), (%%FF_REGa, %4, 2), (%3, %5, 2), (%%FF_REGd, %5, 2))
  2836. SCALED_CPY((%2, %4, 4), (%%FF_REGa, %4, 4), (%3, %5, 4), (%%FF_REGd, %5, 4))
  2837. "lea (%%"FF_REG_a",%4,4), %%"FF_REG_a" \n\t"
  2838. "lea (%%"FF_REG_d",%5,4), %%"FF_REG_d" \n\t"
  2839. SCALED_CPY((%%FF_REGa, %4), (%%FF_REGa, %4, 2), (%%FF_REGd, %5), (%%FF_REGd, %5, 2))
  2840. : "=&a" (packedOffsetAndScale)
  2841. : "0" (packedOffsetAndScale),
  2842. "r"(src),
  2843. "r"(dst),
  2844. "r" ((x86_reg)srcStride),
  2845. "r" ((x86_reg)dstStride)
  2846. : "%"FF_REG_d
  2847. );
  2848. #else //TEMPLATE_PP_MMX && HAVE_6REGS
  2849. for(i=0; i<8; i++)
  2850. memcpy( &(dst[dstStride*i]),
  2851. &(src[srcStride*i]), BLOCK_SIZE);
  2852. #endif //TEMPLATE_PP_MMX && HAVE_6REGS
  2853. }else{
  2854. #if TEMPLATE_PP_MMX && HAVE_6REGS
  2855. __asm__ volatile(
  2856. "lea (%0,%2), %%"FF_REG_a" \n\t"
  2857. "lea (%1,%3), %%"FF_REG_d" \n\t"
  2858. #define REAL_SIMPLE_CPY(src1, src2, dst1, dst2) \
  2859. "movq " #src1 ", %%mm0 \n\t"\
  2860. "movq " #src2 ", %%mm1 \n\t"\
  2861. "movq %%mm0, " #dst1 " \n\t"\
  2862. "movq %%mm1, " #dst2 " \n\t"\
  2863. #define SIMPLE_CPY(src1, src2, dst1, dst2)\
  2864. REAL_SIMPLE_CPY(src1, src2, dst1, dst2)
  2865. SIMPLE_CPY((%0) , (%0, %2) , (%1) , (%1, %3))
  2866. SIMPLE_CPY((%0, %2, 2), (%%FF_REGa, %2, 2), (%1, %3, 2), (%%FF_REGd, %3, 2))
  2867. SIMPLE_CPY((%0, %2, 4), (%%FF_REGa, %2, 4), (%1, %3, 4), (%%FF_REGd, %3, 4))
  2868. "lea (%%"FF_REG_a",%2,4), %%"FF_REG_a" \n\t"
  2869. "lea (%%"FF_REG_d",%3,4), %%"FF_REG_d" \n\t"
  2870. SIMPLE_CPY((%%FF_REGa, %2), (%%FF_REGa, %2, 2), (%%FF_REGd, %3), (%%FF_REGd, %3, 2))
  2871. : : "r" (src),
  2872. "r" (dst),
  2873. "r" ((x86_reg)srcStride),
  2874. "r" ((x86_reg)dstStride)
  2875. : "%"FF_REG_a, "%"FF_REG_d
  2876. );
  2877. #else //TEMPLATE_PP_MMX && HAVE_6REGS
  2878. for(i=0; i<8; i++)
  2879. memcpy( &(dst[dstStride*i]),
  2880. &(src[srcStride*i]), BLOCK_SIZE);
  2881. #endif //TEMPLATE_PP_MMX && HAVE_6REGS
  2882. }
  2883. }
  2884. /**
  2885. * Duplicate the given 8 src pixels ? times upward
  2886. */
  2887. static inline void RENAME(duplicate)(uint8_t src[], int stride)
  2888. {
  2889. #if TEMPLATE_PP_MMX
  2890. __asm__ volatile(
  2891. "movq (%0), %%mm0 \n\t"
  2892. "movq %%mm0, (%0, %1, 4) \n\t"
  2893. "add %1, %0 \n\t"
  2894. "movq %%mm0, (%0) \n\t"
  2895. "movq %%mm0, (%0, %1) \n\t"
  2896. "movq %%mm0, (%0, %1, 2) \n\t"
  2897. "movq %%mm0, (%0, %1, 4) \n\t"
  2898. : "+r" (src)
  2899. : "r" ((x86_reg)-stride)
  2900. );
  2901. #else
  2902. int i;
  2903. uint8_t *p=src;
  2904. for(i=0; i<5; i++){
  2905. p-= stride;
  2906. memcpy(p, src, 8);
  2907. }
  2908. #endif
  2909. }
  2910. #if ARCH_X86 && TEMPLATE_PP_MMXEXT
  2911. static inline void RENAME(prefetchnta)(const void *p)
  2912. {
  2913. __asm__ volatile( "prefetchnta (%0)\n\t"
  2914. : : "r" (p)
  2915. );
  2916. }
  2917. static inline void RENAME(prefetcht0)(const void *p)
  2918. {
  2919. __asm__ volatile( "prefetcht0 (%0)\n\t"
  2920. : : "r" (p)
  2921. );
  2922. }
  2923. static inline void RENAME(prefetcht1)(const void *p)
  2924. {
  2925. __asm__ volatile( "prefetcht1 (%0)\n\t"
  2926. : : "r" (p)
  2927. );
  2928. }
  2929. static inline void RENAME(prefetcht2)(const void *p)
  2930. {
  2931. __asm__ volatile( "prefetcht2 (%0)\n\t"
  2932. : : "r" (p)
  2933. );
  2934. }
  2935. #elif !ARCH_X86 && AV_GCC_VERSION_AT_LEAST(3,2)
  2936. static inline void RENAME(prefetchnta)(const void *p)
  2937. {
  2938. __builtin_prefetch(p,0,0);
  2939. }
  2940. static inline void RENAME(prefetcht0)(const void *p)
  2941. {
  2942. __builtin_prefetch(p,0,1);
  2943. }
  2944. static inline void RENAME(prefetcht1)(const void *p)
  2945. {
  2946. __builtin_prefetch(p,0,2);
  2947. }
  2948. static inline void RENAME(prefetcht2)(const void *p)
  2949. {
  2950. __builtin_prefetch(p,0,3);
  2951. }
  2952. #else
  2953. static inline void RENAME(prefetchnta)(const void *p)
  2954. {
  2955. return;
  2956. }
  2957. static inline void RENAME(prefetcht0)(const void *p)
  2958. {
  2959. return;
  2960. }
  2961. static inline void RENAME(prefetcht1)(const void *p)
  2962. {
  2963. return;
  2964. }
  2965. static inline void RENAME(prefetcht2)(const void *p)
  2966. {
  2967. return;
  2968. }
  2969. #endif
  2970. /**
  2971. * Filter array of bytes (Y or U or V values)
  2972. */
  2973. static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
  2974. const QP_STORE_T QPs[], int QPStride, int isColor, PPContext *c2)
  2975. {
  2976. DECLARE_ALIGNED(8, PPContext, c)= *c2; //copy to stack for faster access
  2977. int x,y;
  2978. #ifdef TEMPLATE_PP_TIME_MODE
  2979. const int mode= TEMPLATE_PP_TIME_MODE;
  2980. #else
  2981. const int mode= isColor ? c.ppMode.chromMode : c.ppMode.lumMode;
  2982. #endif
  2983. int black=0, white=255; // blackest black and whitest white in the picture
  2984. int QPCorrecture= 256*256;
  2985. int copyAhead;
  2986. #if TEMPLATE_PP_MMX
  2987. int i;
  2988. #endif
  2989. const int qpHShift= isColor ? 4-c.hChromaSubSample : 4;
  2990. const int qpVShift= isColor ? 4-c.vChromaSubSample : 4;
  2991. //FIXME remove
  2992. uint64_t * const yHistogram= c.yHistogram;
  2993. uint8_t * const tempSrc= srcStride > 0 ? c.tempSrc : c.tempSrc - 23*srcStride;
  2994. uint8_t * const tempDst= (dstStride > 0 ? c.tempDst : c.tempDst - 23*dstStride) + 32;
  2995. //const int mbWidth= isColor ? (width+7)>>3 : (width+15)>>4;
  2996. if (mode & VISUALIZE){
  2997. if(!(mode & (V_A_DEBLOCK | H_A_DEBLOCK)) || TEMPLATE_PP_MMX) {
  2998. av_log(c2, AV_LOG_WARNING, "Visualization is currently only supported with the accurate deblock filter without SIMD\n");
  2999. }
  3000. }
  3001. #if TEMPLATE_PP_MMX
  3002. for(i=0; i<57; i++){
  3003. int offset= ((i*c.ppMode.baseDcDiff)>>8) + 1;
  3004. int threshold= offset*2 + 1;
  3005. c.mmxDcOffset[i]= 0x7F - offset;
  3006. c.mmxDcThreshold[i]= 0x7F - threshold;
  3007. c.mmxDcOffset[i]*= 0x0101010101010101LL;
  3008. c.mmxDcThreshold[i]*= 0x0101010101010101LL;
  3009. }
  3010. #endif
  3011. if(mode & CUBIC_IPOL_DEINT_FILTER) copyAhead=16;
  3012. else if( (mode & LINEAR_BLEND_DEINT_FILTER)
  3013. || (mode & FFMPEG_DEINT_FILTER)
  3014. || (mode & LOWPASS5_DEINT_FILTER)) copyAhead=14;
  3015. else if( (mode & V_DEBLOCK)
  3016. || (mode & LINEAR_IPOL_DEINT_FILTER)
  3017. || (mode & MEDIAN_DEINT_FILTER)
  3018. || (mode & V_A_DEBLOCK)) copyAhead=13;
  3019. else if(mode & V_X1_FILTER) copyAhead=11;
  3020. // else if(mode & V_RK1_FILTER) copyAhead=10;
  3021. else if(mode & DERING) copyAhead=9;
  3022. else copyAhead=8;
  3023. copyAhead-= 8;
  3024. if(!isColor){
  3025. uint64_t sum= 0;
  3026. int i;
  3027. uint64_t maxClipped;
  3028. uint64_t clipped;
  3029. AVRational scale;
  3030. c.frameNum++;
  3031. // first frame is fscked so we ignore it
  3032. if(c.frameNum == 1) yHistogram[0]= width*(uint64_t)height/64*15/256;
  3033. for(i=0; i<256; i++){
  3034. sum+= yHistogram[i];
  3035. }
  3036. /* We always get a completely black picture first. */
  3037. maxClipped= av_rescale(sum, c.ppMode.maxClippedThreshold.num, c.ppMode.maxClippedThreshold.den);
  3038. clipped= sum;
  3039. for(black=255; black>0; black--){
  3040. if(clipped < maxClipped) break;
  3041. clipped-= yHistogram[black];
  3042. }
  3043. clipped= sum;
  3044. for(white=0; white<256; white++){
  3045. if(clipped < maxClipped) break;
  3046. clipped-= yHistogram[white];
  3047. }
  3048. scale = (AVRational){c.ppMode.maxAllowedY - c.ppMode.minAllowedY, white - black};
  3049. #if TEMPLATE_PP_MMXEXT
  3050. c.packedYScale = (uint16_t)av_rescale(scale.num, 256, scale.den);
  3051. c.packedYOffset= (((black*c.packedYScale)>>8) - c.ppMode.minAllowedY) & 0xFFFF;
  3052. #else
  3053. c.packedYScale = (uint16_t)av_rescale(scale.num, 1024, scale.den);
  3054. c.packedYOffset= (black - c.ppMode.minAllowedY) & 0xFFFF;
  3055. #endif
  3056. c.packedYOffset|= c.packedYOffset<<32;
  3057. c.packedYOffset|= c.packedYOffset<<16;
  3058. c.packedYScale|= c.packedYScale<<32;
  3059. c.packedYScale|= c.packedYScale<<16;
  3060. if(mode & LEVEL_FIX) QPCorrecture= (int)av_rescale(scale.num, 256*256, scale.den);
  3061. else QPCorrecture= 256*256;
  3062. }else{
  3063. c.packedYScale= 0x0100010001000100LL;
  3064. c.packedYOffset= 0;
  3065. QPCorrecture= 256*256;
  3066. }
  3067. /* copy & deinterlace first row of blocks */
  3068. y=-BLOCK_SIZE;
  3069. {
  3070. const uint8_t *srcBlock= &(src[y*srcStride]);
  3071. uint8_t *dstBlock= tempDst + dstStride;
  3072. // From this point on it is guaranteed that we can read and write 16 lines downward
  3073. // finish 1 block before the next otherwise we might have a problem
  3074. // with the L1 Cache of the P4 ... or only a few blocks at a time or something
  3075. for(x=0; x<width; x+=BLOCK_SIZE){
  3076. RENAME(prefetchnta)(srcBlock + (((x>>2)&6) + copyAhead)*srcStride + 32);
  3077. RENAME(prefetchnta)(srcBlock + (((x>>2)&6) + copyAhead+1)*srcStride + 32);
  3078. RENAME(prefetcht0)(dstBlock + (((x>>2)&6) + copyAhead)*dstStride + 32);
  3079. RENAME(prefetcht0)(dstBlock + (((x>>2)&6) + copyAhead+1)*dstStride + 32);
  3080. RENAME(blockCopy)(dstBlock + dstStride*8, dstStride,
  3081. srcBlock + srcStride*8, srcStride, mode & LEVEL_FIX, &c.packedYOffset);
  3082. RENAME(duplicate)(dstBlock + dstStride*8, dstStride);
  3083. if(mode & LINEAR_IPOL_DEINT_FILTER)
  3084. RENAME(deInterlaceInterpolateLinear)(dstBlock, dstStride);
  3085. else if(mode & LINEAR_BLEND_DEINT_FILTER)
  3086. RENAME(deInterlaceBlendLinear)(dstBlock, dstStride, c.deintTemp + x);
  3087. else if(mode & MEDIAN_DEINT_FILTER)
  3088. RENAME(deInterlaceMedian)(dstBlock, dstStride);
  3089. else if(mode & CUBIC_IPOL_DEINT_FILTER)
  3090. RENAME(deInterlaceInterpolateCubic)(dstBlock, dstStride);
  3091. else if(mode & FFMPEG_DEINT_FILTER)
  3092. RENAME(deInterlaceFF)(dstBlock, dstStride, c.deintTemp + x);
  3093. else if(mode & LOWPASS5_DEINT_FILTER)
  3094. RENAME(deInterlaceL5)(dstBlock, dstStride, c.deintTemp + x, c.deintTemp + width + x);
  3095. /* else if(mode & CUBIC_BLEND_DEINT_FILTER)
  3096. RENAME(deInterlaceBlendCubic)(dstBlock, dstStride);
  3097. */
  3098. dstBlock+=8;
  3099. srcBlock+=8;
  3100. }
  3101. if(width==FFABS(dstStride))
  3102. linecpy(dst, tempDst + 9*dstStride, copyAhead, dstStride);
  3103. else{
  3104. int i;
  3105. for(i=0; i<copyAhead; i++){
  3106. memcpy(dst + i*dstStride, tempDst + (9+i)*dstStride, width);
  3107. }
  3108. }
  3109. }
  3110. for(y=0; y<height; y+=BLOCK_SIZE){
  3111. //1% speedup if these are here instead of the inner loop
  3112. const uint8_t *srcBlock= &(src[y*srcStride]);
  3113. uint8_t *dstBlock= &(dst[y*dstStride]);
  3114. #if TEMPLATE_PP_MMX
  3115. uint8_t *tempBlock1= c.tempBlocks;
  3116. uint8_t *tempBlock2= c.tempBlocks + 8;
  3117. #endif
  3118. const int8_t *QPptr= &QPs[(y>>qpVShift)*QPStride];
  3119. int8_t *nonBQPptr= &c.nonBQPTable[(y>>qpVShift)*FFABS(QPStride)];
  3120. int QP=0, nonBQP=0;
  3121. /* can we mess with a 8x16 block from srcBlock/dstBlock downwards and 1 line upwards
  3122. if not than use a temporary buffer */
  3123. if(y+15 >= height){
  3124. int i;
  3125. /* copy from line (copyAhead) to (copyAhead+7) of src, these will be copied with
  3126. blockcopy to dst later */
  3127. linecpy(tempSrc + srcStride*copyAhead, srcBlock + srcStride*copyAhead,
  3128. FFMAX(height-y-copyAhead, 0), srcStride);
  3129. /* duplicate last line of src to fill the void up to line (copyAhead+7) */
  3130. for(i=FFMAX(height-y, 8); i<copyAhead+8; i++)
  3131. memcpy(tempSrc + srcStride*i, src + srcStride*(height-1), FFABS(srcStride));
  3132. /* copy up to (copyAhead+1) lines of dst (line -1 to (copyAhead-1))*/
  3133. linecpy(tempDst, dstBlock - dstStride, FFMIN(height-y+1, copyAhead+1), dstStride);
  3134. /* duplicate last line of dst to fill the void up to line (copyAhead) */
  3135. for(i=height-y+1; i<=copyAhead; i++)
  3136. memcpy(tempDst + dstStride*i, dst + dstStride*(height-1), FFABS(dstStride));
  3137. dstBlock= tempDst + dstStride;
  3138. srcBlock= tempSrc;
  3139. }
  3140. // From this point on it is guaranteed that we can read and write 16 lines downward
  3141. // finish 1 block before the next otherwise we might have a problem
  3142. // with the L1 Cache of the P4 ... or only a few blocks at a time or something
  3143. for(x=0; x<width; ){
  3144. int startx = x;
  3145. int endx = FFMIN(width, x+32);
  3146. uint8_t *dstBlockStart = dstBlock;
  3147. const uint8_t *srcBlockStart = srcBlock;
  3148. int qp_index = 0;
  3149. for(qp_index=0; qp_index < (endx-startx)/BLOCK_SIZE; qp_index++){
  3150. QP = QPptr[(x+qp_index*BLOCK_SIZE)>>qpHShift];
  3151. nonBQP = nonBQPptr[(x+qp_index*BLOCK_SIZE)>>qpHShift];
  3152. if(!isColor){
  3153. QP= (QP* QPCorrecture + 256*128)>>16;
  3154. nonBQP= (nonBQP* QPCorrecture + 256*128)>>16;
  3155. yHistogram[(srcBlock+qp_index*8)[srcStride*12 + 4]]++;
  3156. }
  3157. c.QP_block[qp_index] = QP;
  3158. c.nonBQP_block[qp_index] = nonBQP;
  3159. #if TEMPLATE_PP_MMX
  3160. __asm__ volatile(
  3161. "movd %1, %%mm7 \n\t"
  3162. "packuswb %%mm7, %%mm7 \n\t" // 0, 0, 0, QP, 0, 0, 0, QP
  3163. "packuswb %%mm7, %%mm7 \n\t" // 0,QP, 0, QP, 0,QP, 0, QP
  3164. "packuswb %%mm7, %%mm7 \n\t" // QP,..., QP
  3165. "movq %%mm7, %0 \n\t"
  3166. : "=m" (c.pQPb_block[qp_index])
  3167. : "r" (QP)
  3168. );
  3169. #endif
  3170. }
  3171. for(; x < endx; x+=BLOCK_SIZE){
  3172. RENAME(prefetchnta)(srcBlock + (((x>>2)&6) + copyAhead)*srcStride + 32);
  3173. RENAME(prefetchnta)(srcBlock + (((x>>2)&6) + copyAhead+1)*srcStride + 32);
  3174. RENAME(prefetcht0)(dstBlock + (((x>>2)&6) + copyAhead)*dstStride + 32);
  3175. RENAME(prefetcht0)(dstBlock + (((x>>2)&6) + copyAhead+1)*dstStride + 32);
  3176. RENAME(blockCopy)(dstBlock + dstStride*copyAhead, dstStride,
  3177. srcBlock + srcStride*copyAhead, srcStride, mode & LEVEL_FIX, &c.packedYOffset);
  3178. if(mode & LINEAR_IPOL_DEINT_FILTER)
  3179. RENAME(deInterlaceInterpolateLinear)(dstBlock, dstStride);
  3180. else if(mode & LINEAR_BLEND_DEINT_FILTER)
  3181. RENAME(deInterlaceBlendLinear)(dstBlock, dstStride, c.deintTemp + x);
  3182. else if(mode & MEDIAN_DEINT_FILTER)
  3183. RENAME(deInterlaceMedian)(dstBlock, dstStride);
  3184. else if(mode & CUBIC_IPOL_DEINT_FILTER)
  3185. RENAME(deInterlaceInterpolateCubic)(dstBlock, dstStride);
  3186. else if(mode & FFMPEG_DEINT_FILTER)
  3187. RENAME(deInterlaceFF)(dstBlock, dstStride, c.deintTemp + x);
  3188. else if(mode & LOWPASS5_DEINT_FILTER)
  3189. RENAME(deInterlaceL5)(dstBlock, dstStride, c.deintTemp + x, c.deintTemp + width + x);
  3190. /* else if(mode & CUBIC_BLEND_DEINT_FILTER)
  3191. RENAME(deInterlaceBlendCubic)(dstBlock, dstStride);
  3192. */
  3193. dstBlock+=8;
  3194. srcBlock+=8;
  3195. }
  3196. dstBlock = dstBlockStart;
  3197. srcBlock = srcBlockStart;
  3198. for(x = startx, qp_index = 0; x < endx; x+=BLOCK_SIZE, qp_index++){
  3199. const int stride= dstStride;
  3200. //temporary while changing QP stuff to make things continue to work
  3201. //eventually QP,nonBQP,etc will be arrays and this will be unnecessary
  3202. c.QP = c.QP_block[qp_index];
  3203. c.nonBQP = c.nonBQP_block[qp_index];
  3204. c.pQPb = c.pQPb_block[qp_index];
  3205. c.pQPb2 = c.pQPb2_block[qp_index];
  3206. /* only deblock if we have 2 blocks */
  3207. if(y + 8 < height){
  3208. if(mode & V_X1_FILTER)
  3209. RENAME(vertX1Filter)(dstBlock, stride, &c);
  3210. else if(mode & V_DEBLOCK){
  3211. const int t= RENAME(vertClassify)(dstBlock, stride, &c);
  3212. if(t==1)
  3213. RENAME(doVertLowPass)(dstBlock, stride, &c);
  3214. else if(t==2)
  3215. RENAME(doVertDefFilter)(dstBlock, stride, &c);
  3216. }else if(mode & V_A_DEBLOCK){
  3217. RENAME(do_a_deblock)(dstBlock, stride, 1, &c, mode);
  3218. }
  3219. }
  3220. dstBlock+=8;
  3221. srcBlock+=8;
  3222. }
  3223. dstBlock = dstBlockStart;
  3224. srcBlock = srcBlockStart;
  3225. for(x = startx, qp_index=0; x < endx; x+=BLOCK_SIZE, qp_index++){
  3226. const int stride= dstStride;
  3227. av_unused uint8_t *tmpXchg;
  3228. c.QP = c.QP_block[qp_index];
  3229. c.nonBQP = c.nonBQP_block[qp_index];
  3230. c.pQPb = c.pQPb_block[qp_index];
  3231. c.pQPb2 = c.pQPb2_block[qp_index];
  3232. #if TEMPLATE_PP_MMX
  3233. RENAME(transpose1)(tempBlock1, tempBlock2, dstBlock, dstStride);
  3234. #endif
  3235. /* check if we have a previous block to deblock it with dstBlock */
  3236. if(x - 8 >= 0){
  3237. #if TEMPLATE_PP_MMX
  3238. if(mode & H_X1_FILTER)
  3239. RENAME(vertX1Filter)(tempBlock1, 16, &c);
  3240. else if(mode & H_DEBLOCK){
  3241. const int t= RENAME(vertClassify)(tempBlock1, 16, &c);
  3242. if(t==1)
  3243. RENAME(doVertLowPass)(tempBlock1, 16, &c);
  3244. else if(t==2)
  3245. RENAME(doVertDefFilter)(tempBlock1, 16, &c);
  3246. }else if(mode & H_A_DEBLOCK){
  3247. RENAME(do_a_deblock)(tempBlock1, 16, 1, &c, mode);
  3248. }
  3249. RENAME(transpose2)(dstBlock-4, dstStride, tempBlock1 + 4*16);
  3250. #else
  3251. if(mode & H_X1_FILTER)
  3252. horizX1Filter(dstBlock-4, stride, c.QP);
  3253. else if(mode & H_DEBLOCK){
  3254. #if TEMPLATE_PP_ALTIVEC
  3255. DECLARE_ALIGNED(16, unsigned char, tempBlock)[272];
  3256. int t;
  3257. transpose_16x8_char_toPackedAlign_altivec(tempBlock, dstBlock - (4 + 1), stride);
  3258. t = vertClassify_altivec(tempBlock-48, 16, &c);
  3259. if(t==1) {
  3260. doVertLowPass_altivec(tempBlock-48, 16, &c);
  3261. transpose_8x16_char_fromPackedAlign_altivec(dstBlock - (4 + 1), tempBlock, stride);
  3262. }
  3263. else if(t==2) {
  3264. doVertDefFilter_altivec(tempBlock-48, 16, &c);
  3265. transpose_8x16_char_fromPackedAlign_altivec(dstBlock - (4 + 1), tempBlock, stride);
  3266. }
  3267. #else
  3268. const int t= RENAME(horizClassify)(dstBlock-4, stride, &c);
  3269. if(t==1)
  3270. RENAME(doHorizLowPass)(dstBlock-4, stride, &c);
  3271. else if(t==2)
  3272. RENAME(doHorizDefFilter)(dstBlock-4, stride, &c);
  3273. #endif
  3274. }else if(mode & H_A_DEBLOCK){
  3275. RENAME(do_a_deblock)(dstBlock-8, 1, stride, &c, mode);
  3276. }
  3277. #endif //TEMPLATE_PP_MMX
  3278. if(mode & DERING){
  3279. //FIXME filter first line
  3280. if(y>0) RENAME(dering)(dstBlock - stride - 8, stride, &c);
  3281. }
  3282. if(mode & TEMP_NOISE_FILTER)
  3283. {
  3284. RENAME(tempNoiseReducer)(dstBlock-8, stride,
  3285. c.tempBlurred[isColor] + y*dstStride + x,
  3286. c.tempBlurredPast[isColor] + (y>>3)*256 + (x>>3) + 256,
  3287. c.ppMode.maxTmpNoise);
  3288. }
  3289. }
  3290. dstBlock+=8;
  3291. srcBlock+=8;
  3292. #if TEMPLATE_PP_MMX
  3293. tmpXchg= tempBlock1;
  3294. tempBlock1= tempBlock2;
  3295. tempBlock2 = tmpXchg;
  3296. #endif
  3297. }
  3298. }
  3299. if(mode & DERING){
  3300. if(y > 0) RENAME(dering)(dstBlock - dstStride - 8, dstStride, &c);
  3301. }
  3302. if((mode & TEMP_NOISE_FILTER)){
  3303. RENAME(tempNoiseReducer)(dstBlock-8, dstStride,
  3304. c.tempBlurred[isColor] + y*dstStride + x,
  3305. c.tempBlurredPast[isColor] + (y>>3)*256 + (x>>3) + 256,
  3306. c.ppMode.maxTmpNoise);
  3307. }
  3308. /* did we use a tmp buffer for the last lines*/
  3309. if(y+15 >= height){
  3310. uint8_t *dstBlock= &(dst[y*dstStride]);
  3311. if(width==FFABS(dstStride))
  3312. linecpy(dstBlock, tempDst + dstStride, height-y, dstStride);
  3313. else{
  3314. int i;
  3315. for(i=0; i<height-y; i++){
  3316. memcpy(dstBlock + i*dstStride, tempDst + (i+1)*dstStride, width);
  3317. }
  3318. }
  3319. }
  3320. }
  3321. #if TEMPLATE_PP_3DNOW
  3322. __asm__ volatile("femms");
  3323. #elif TEMPLATE_PP_MMX
  3324. __asm__ volatile("emms");
  3325. #endif
  3326. #ifdef DEBUG_BRIGHTNESS
  3327. if(!isColor){
  3328. int max=1;
  3329. int i;
  3330. for(i=0; i<256; i++)
  3331. if(yHistogram[i] > max) max=yHistogram[i];
  3332. for(i=1; i<256; i++){
  3333. int x;
  3334. int start=yHistogram[i-1]/(max/256+1);
  3335. int end=yHistogram[i]/(max/256+1);
  3336. int inc= end > start ? 1 : -1;
  3337. for(x=start; x!=end+inc; x+=inc)
  3338. dst[ i*dstStride + x]+=128;
  3339. }
  3340. for(i=0; i<100; i+=2){
  3341. dst[ (white)*dstStride + i]+=128;
  3342. dst[ (black)*dstStride + i]+=128;
  3343. }
  3344. }
  3345. #endif
  3346. *c2= c; //copy local context back
  3347. }
  3348. #undef RENAME
  3349. #undef TEMPLATE_PP_C
  3350. #undef TEMPLATE_PP_ALTIVEC
  3351. #undef TEMPLATE_PP_MMX
  3352. #undef TEMPLATE_PP_MMXEXT
  3353. #undef TEMPLATE_PP_3DNOW
  3354. #undef TEMPLATE_PP_SSE2