postprocess_template.c 161 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740
  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. __asm__ volatile(
  2305. "movq %0, %%mm7 \n\t"
  2306. "movq %1, %%mm6 \n\t"
  2307. : : "m" (c->mmxDcOffset[c->nonBQP]), "m" (c->mmxDcThreshold[c->nonBQP])
  2308. );
  2309. __asm__ volatile(
  2310. "lea (%2, %3), %%"FF_REG_a" \n\t"
  2311. // 0 1 2 3 4 5 6 7 8 9
  2312. // %1 eax eax+%2 eax+2%2 %1+4%2 ecx ecx+%2 ecx+2%2 %1+8%2 ecx+4%2
  2313. "movq (%2), %%mm0 \n\t"
  2314. "movq (%%"FF_REG_a"), %%mm1 \n\t"
  2315. "movq %%mm1, %%mm3 \n\t"
  2316. "movq %%mm1, %%mm4 \n\t"
  2317. "psubb %%mm1, %%mm0 \n\t" // mm0 = difference
  2318. "paddb %%mm7, %%mm0 \n\t"
  2319. "pcmpgtb %%mm6, %%mm0 \n\t"
  2320. "movq (%%"FF_REG_a",%3), %%mm2 \n\t"
  2321. PMAXUB(%%mm2, %%mm4)
  2322. PMINUB(%%mm2, %%mm3, %%mm5)
  2323. "psubb %%mm2, %%mm1 \n\t"
  2324. "paddb %%mm7, %%mm1 \n\t"
  2325. "pcmpgtb %%mm6, %%mm1 \n\t"
  2326. "paddb %%mm1, %%mm0 \n\t"
  2327. "movq (%%"FF_REG_a", %3, 2), %%mm1 \n\t"
  2328. PMAXUB(%%mm1, %%mm4)
  2329. PMINUB(%%mm1, %%mm3, %%mm5)
  2330. "psubb %%mm1, %%mm2 \n\t"
  2331. "paddb %%mm7, %%mm2 \n\t"
  2332. "pcmpgtb %%mm6, %%mm2 \n\t"
  2333. "paddb %%mm2, %%mm0 \n\t"
  2334. "lea (%%"FF_REG_a", %3, 4), %%"FF_REG_a"\n\t"
  2335. "movq (%2, %3, 4), %%mm2 \n\t"
  2336. PMAXUB(%%mm2, %%mm4)
  2337. PMINUB(%%mm2, %%mm3, %%mm5)
  2338. "psubb %%mm2, %%mm1 \n\t"
  2339. "paddb %%mm7, %%mm1 \n\t"
  2340. "pcmpgtb %%mm6, %%mm1 \n\t"
  2341. "paddb %%mm1, %%mm0 \n\t"
  2342. "movq (%%"FF_REG_a"), %%mm1 \n\t"
  2343. PMAXUB(%%mm1, %%mm4)
  2344. PMINUB(%%mm1, %%mm3, %%mm5)
  2345. "psubb %%mm1, %%mm2 \n\t"
  2346. "paddb %%mm7, %%mm2 \n\t"
  2347. "pcmpgtb %%mm6, %%mm2 \n\t"
  2348. "paddb %%mm2, %%mm0 \n\t"
  2349. "movq (%%"FF_REG_a", %3), %%mm2 \n\t"
  2350. PMAXUB(%%mm2, %%mm4)
  2351. PMINUB(%%mm2, %%mm3, %%mm5)
  2352. "psubb %%mm2, %%mm1 \n\t"
  2353. "paddb %%mm7, %%mm1 \n\t"
  2354. "pcmpgtb %%mm6, %%mm1 \n\t"
  2355. "paddb %%mm1, %%mm0 \n\t"
  2356. "movq (%%"FF_REG_a", %3, 2), %%mm1 \n\t"
  2357. PMAXUB(%%mm1, %%mm4)
  2358. PMINUB(%%mm1, %%mm3, %%mm5)
  2359. "psubb %%mm1, %%mm2 \n\t"
  2360. "paddb %%mm7, %%mm2 \n\t"
  2361. "pcmpgtb %%mm6, %%mm2 \n\t"
  2362. "paddb %%mm2, %%mm0 \n\t"
  2363. "movq (%2, %3, 8), %%mm2 \n\t"
  2364. PMAXUB(%%mm2, %%mm4)
  2365. PMINUB(%%mm2, %%mm3, %%mm5)
  2366. "psubb %%mm2, %%mm1 \n\t"
  2367. "paddb %%mm7, %%mm1 \n\t"
  2368. "pcmpgtb %%mm6, %%mm1 \n\t"
  2369. "paddb %%mm1, %%mm0 \n\t"
  2370. "movq (%%"FF_REG_a", %3, 4), %%mm1 \n\t"
  2371. "psubb %%mm1, %%mm2 \n\t"
  2372. "paddb %%mm7, %%mm2 \n\t"
  2373. "pcmpgtb %%mm6, %%mm2 \n\t"
  2374. "paddb %%mm2, %%mm0 \n\t"
  2375. "psubusb %%mm3, %%mm4 \n\t"
  2376. "pxor %%mm6, %%mm6 \n\t"
  2377. "movq %4, %%mm7 \n\t" // QP,..., QP
  2378. "paddusb %%mm7, %%mm7 \n\t" // 2QP ... 2QP
  2379. "psubusb %%mm4, %%mm7 \n\t" // Diff >=2QP -> 0
  2380. "pcmpeqb %%mm6, %%mm7 \n\t" // Diff < 2QP -> 0
  2381. "pcmpeqb %%mm6, %%mm7 \n\t" // Diff < 2QP -> 0
  2382. "movq %%mm7, %1 \n\t"
  2383. "movq %5, %%mm7 \n\t"
  2384. "punpcklbw %%mm7, %%mm7 \n\t"
  2385. "punpcklbw %%mm7, %%mm7 \n\t"
  2386. "punpcklbw %%mm7, %%mm7 \n\t"
  2387. "psubb %%mm0, %%mm6 \n\t"
  2388. "pcmpgtb %%mm7, %%mm6 \n\t"
  2389. "movq %%mm6, %0 \n\t"
  2390. : "=m" (eq_mask), "=m" (dc_mask)
  2391. : "r" (src), "r" ((x86_reg)step), "m" (c->pQPb), "m"(c->ppMode.flatnessThreshold)
  2392. : "%"FF_REG_a
  2393. );
  2394. both_masks = dc_mask & eq_mask;
  2395. if(both_masks){
  2396. x86_reg offset= -8*step;
  2397. int64_t *temp_sums= sums;
  2398. __asm__ volatile(
  2399. "movq %2, %%mm0 \n\t" // QP,..., QP
  2400. "pxor %%mm4, %%mm4 \n\t"
  2401. "movq (%0), %%mm6 \n\t"
  2402. "movq (%0, %1), %%mm5 \n\t"
  2403. "movq %%mm5, %%mm1 \n\t"
  2404. "movq %%mm6, %%mm2 \n\t"
  2405. "psubusb %%mm6, %%mm5 \n\t"
  2406. "psubusb %%mm1, %%mm2 \n\t"
  2407. "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
  2408. "psubusb %%mm2, %%mm0 \n\t" // diff >= QP -> 0
  2409. "pcmpeqb %%mm4, %%mm0 \n\t" // diff >= QP -> FF
  2410. "pxor %%mm6, %%mm1 \n\t"
  2411. "pand %%mm0, %%mm1 \n\t"
  2412. "pxor %%mm1, %%mm6 \n\t"
  2413. // 0:QP 6:First
  2414. "movq (%0, %1, 8), %%mm5 \n\t"
  2415. "add %1, %0 \n\t" // %0 points to line 1 not 0
  2416. "movq (%0, %1, 8), %%mm7 \n\t"
  2417. "movq %%mm5, %%mm1 \n\t"
  2418. "movq %%mm7, %%mm2 \n\t"
  2419. "psubusb %%mm7, %%mm5 \n\t"
  2420. "psubusb %%mm1, %%mm2 \n\t"
  2421. "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
  2422. "movq %2, %%mm0 \n\t" // QP,..., QP
  2423. "psubusb %%mm2, %%mm0 \n\t" // diff >= QP -> 0
  2424. "pcmpeqb %%mm4, %%mm0 \n\t" // diff >= QP -> FF
  2425. "pxor %%mm7, %%mm1 \n\t"
  2426. "pand %%mm0, %%mm1 \n\t"
  2427. "pxor %%mm1, %%mm7 \n\t"
  2428. "movq %%mm6, %%mm5 \n\t"
  2429. "punpckhbw %%mm4, %%mm6 \n\t"
  2430. "punpcklbw %%mm4, %%mm5 \n\t"
  2431. // 4:0 5/6:First 7:Last
  2432. "movq %%mm5, %%mm0 \n\t"
  2433. "movq %%mm6, %%mm1 \n\t"
  2434. "psllw $2, %%mm0 \n\t"
  2435. "psllw $2, %%mm1 \n\t"
  2436. "paddw "MANGLE(w04)", %%mm0 \n\t"
  2437. "paddw "MANGLE(w04)", %%mm1 \n\t"
  2438. #define NEXT\
  2439. "movq (%0), %%mm2 \n\t"\
  2440. "movq (%0), %%mm3 \n\t"\
  2441. "add %1, %0 \n\t"\
  2442. "punpcklbw %%mm4, %%mm2 \n\t"\
  2443. "punpckhbw %%mm4, %%mm3 \n\t"\
  2444. "paddw %%mm2, %%mm0 \n\t"\
  2445. "paddw %%mm3, %%mm1 \n\t"
  2446. #define PREV\
  2447. "movq (%0), %%mm2 \n\t"\
  2448. "movq (%0), %%mm3 \n\t"\
  2449. "add %1, %0 \n\t"\
  2450. "punpcklbw %%mm4, %%mm2 \n\t"\
  2451. "punpckhbw %%mm4, %%mm3 \n\t"\
  2452. "psubw %%mm2, %%mm0 \n\t"\
  2453. "psubw %%mm3, %%mm1 \n\t"
  2454. NEXT //0
  2455. NEXT //1
  2456. NEXT //2
  2457. "movq %%mm0, (%3) \n\t"
  2458. "movq %%mm1, 8(%3) \n\t"
  2459. NEXT //3
  2460. "psubw %%mm5, %%mm0 \n\t"
  2461. "psubw %%mm6, %%mm1 \n\t"
  2462. "movq %%mm0, 16(%3) \n\t"
  2463. "movq %%mm1, 24(%3) \n\t"
  2464. NEXT //4
  2465. "psubw %%mm5, %%mm0 \n\t"
  2466. "psubw %%mm6, %%mm1 \n\t"
  2467. "movq %%mm0, 32(%3) \n\t"
  2468. "movq %%mm1, 40(%3) \n\t"
  2469. NEXT //5
  2470. "psubw %%mm5, %%mm0 \n\t"
  2471. "psubw %%mm6, %%mm1 \n\t"
  2472. "movq %%mm0, 48(%3) \n\t"
  2473. "movq %%mm1, 56(%3) \n\t"
  2474. NEXT //6
  2475. "psubw %%mm5, %%mm0 \n\t"
  2476. "psubw %%mm6, %%mm1 \n\t"
  2477. "movq %%mm0, 64(%3) \n\t"
  2478. "movq %%mm1, 72(%3) \n\t"
  2479. "movq %%mm7, %%mm6 \n\t"
  2480. "punpckhbw %%mm4, %%mm7 \n\t"
  2481. "punpcklbw %%mm4, %%mm6 \n\t"
  2482. NEXT //7
  2483. "mov %4, %0 \n\t"
  2484. "add %1, %0 \n\t"
  2485. PREV //0
  2486. "movq %%mm0, 80(%3) \n\t"
  2487. "movq %%mm1, 88(%3) \n\t"
  2488. PREV //1
  2489. "paddw %%mm6, %%mm0 \n\t"
  2490. "paddw %%mm7, %%mm1 \n\t"
  2491. "movq %%mm0, 96(%3) \n\t"
  2492. "movq %%mm1, 104(%3) \n\t"
  2493. PREV //2
  2494. "paddw %%mm6, %%mm0 \n\t"
  2495. "paddw %%mm7, %%mm1 \n\t"
  2496. "movq %%mm0, 112(%3) \n\t"
  2497. "movq %%mm1, 120(%3) \n\t"
  2498. PREV //3
  2499. "paddw %%mm6, %%mm0 \n\t"
  2500. "paddw %%mm7, %%mm1 \n\t"
  2501. "movq %%mm0, 128(%3) \n\t"
  2502. "movq %%mm1, 136(%3) \n\t"
  2503. PREV //4
  2504. "paddw %%mm6, %%mm0 \n\t"
  2505. "paddw %%mm7, %%mm1 \n\t"
  2506. "movq %%mm0, 144(%3) \n\t"
  2507. "movq %%mm1, 152(%3) \n\t"
  2508. "mov %4, %0 \n\t" //FIXME
  2509. : "+&r"(src)
  2510. : "r" ((x86_reg)step), "m" (c->pQPb), "r"(sums), "g"(src)
  2511. NAMED_CONSTRAINTS_ADD(w04)
  2512. );
  2513. src+= step; // src points to begin of the 8x8 Block
  2514. __asm__ volatile(
  2515. "movq %4, %%mm6 \n\t"
  2516. "pcmpeqb %%mm5, %%mm5 \n\t"
  2517. "pxor %%mm6, %%mm5 \n\t"
  2518. "pxor %%mm7, %%mm7 \n\t"
  2519. "1: \n\t"
  2520. "movq (%1), %%mm0 \n\t"
  2521. "movq 8(%1), %%mm1 \n\t"
  2522. "paddw 32(%1), %%mm0 \n\t"
  2523. "paddw 40(%1), %%mm1 \n\t"
  2524. "movq (%0, %3), %%mm2 \n\t"
  2525. "movq %%mm2, %%mm3 \n\t"
  2526. "movq %%mm2, %%mm4 \n\t"
  2527. "punpcklbw %%mm7, %%mm2 \n\t"
  2528. "punpckhbw %%mm7, %%mm3 \n\t"
  2529. "paddw %%mm2, %%mm0 \n\t"
  2530. "paddw %%mm3, %%mm1 \n\t"
  2531. "paddw %%mm2, %%mm0 \n\t"
  2532. "paddw %%mm3, %%mm1 \n\t"
  2533. "psrlw $4, %%mm0 \n\t"
  2534. "psrlw $4, %%mm1 \n\t"
  2535. "packuswb %%mm1, %%mm0 \n\t"
  2536. "pand %%mm6, %%mm0 \n\t"
  2537. "pand %%mm5, %%mm4 \n\t"
  2538. "por %%mm4, %%mm0 \n\t"
  2539. "movq %%mm0, (%0, %3) \n\t"
  2540. "add $16, %1 \n\t"
  2541. "add %2, %0 \n\t"
  2542. " js 1b \n\t"
  2543. : "+r"(offset), "+r"(temp_sums)
  2544. : "r" ((x86_reg)step), "r"(src - offset), "m"(both_masks)
  2545. );
  2546. }else
  2547. src+= step; // src points to begin of the 8x8 Block
  2548. if(eq_mask != -1LL){
  2549. uint8_t *temp_src= src;
  2550. DECLARE_ALIGNED(8, uint64_t, tmp)[4]; // make space for 4 8-byte vars
  2551. __asm__ volatile(
  2552. "pxor %%mm7, %%mm7 \n\t"
  2553. // 0 1 2 3 4 5 6 7 8 9
  2554. // %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %1+8%1 ecx+4%1
  2555. "movq (%0), %%mm0 \n\t"
  2556. "movq %%mm0, %%mm1 \n\t"
  2557. "punpcklbw %%mm7, %%mm0 \n\t" // low part of line 0
  2558. "punpckhbw %%mm7, %%mm1 \n\t" // high part of line 0
  2559. "movq (%0, %1), %%mm2 \n\t"
  2560. "lea (%0, %1, 2), %%"FF_REG_a" \n\t"
  2561. "movq %%mm2, %%mm3 \n\t"
  2562. "punpcklbw %%mm7, %%mm2 \n\t" // low part of line 1
  2563. "punpckhbw %%mm7, %%mm3 \n\t" // high part of line 1
  2564. "movq (%%"FF_REG_a"), %%mm4 \n\t"
  2565. "movq %%mm4, %%mm5 \n\t"
  2566. "punpcklbw %%mm7, %%mm4 \n\t" // low part of line 2
  2567. "punpckhbw %%mm7, %%mm5 \n\t" // high part of line 2
  2568. "paddw %%mm0, %%mm0 \n\t" // 2L0
  2569. "paddw %%mm1, %%mm1 \n\t" // 2H0
  2570. "psubw %%mm4, %%mm2 \n\t" // L1 - L2
  2571. "psubw %%mm5, %%mm3 \n\t" // H1 - H2
  2572. "psubw %%mm2, %%mm0 \n\t" // 2L0 - L1 + L2
  2573. "psubw %%mm3, %%mm1 \n\t" // 2H0 - H1 + H2
  2574. "psllw $2, %%mm2 \n\t" // 4L1 - 4L2
  2575. "psllw $2, %%mm3 \n\t" // 4H1 - 4H2
  2576. "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2
  2577. "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2
  2578. "movq (%%"FF_REG_a", %1), %%mm2 \n\t"
  2579. "movq %%mm2, %%mm3 \n\t"
  2580. "punpcklbw %%mm7, %%mm2 \n\t" // L3
  2581. "punpckhbw %%mm7, %%mm3 \n\t" // H3
  2582. "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - L3
  2583. "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - H3
  2584. "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
  2585. "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
  2586. "movq %%mm0, (%4) \n\t" // 2L0 - 5L1 + 5L2 - 2L3
  2587. "movq %%mm1, 8(%4) \n\t" // 2H0 - 5H1 + 5H2 - 2H3
  2588. "movq (%%"FF_REG_a", %1, 2), %%mm0 \n\t"
  2589. "movq %%mm0, %%mm1 \n\t"
  2590. "punpcklbw %%mm7, %%mm0 \n\t" // L4
  2591. "punpckhbw %%mm7, %%mm1 \n\t" // H4
  2592. "psubw %%mm0, %%mm2 \n\t" // L3 - L4
  2593. "psubw %%mm1, %%mm3 \n\t" // H3 - H4
  2594. "movq %%mm2, 16(%4) \n\t" // L3 - L4
  2595. "movq %%mm3, 24(%4) \n\t" // H3 - H4
  2596. "paddw %%mm4, %%mm4 \n\t" // 2L2
  2597. "paddw %%mm5, %%mm5 \n\t" // 2H2
  2598. "psubw %%mm2, %%mm4 \n\t" // 2L2 - L3 + L4
  2599. "psubw %%mm3, %%mm5 \n\t" // 2H2 - H3 + H4
  2600. "lea (%%"FF_REG_a", %1), %0 \n\t"
  2601. "psllw $2, %%mm2 \n\t" // 4L3 - 4L4
  2602. "psllw $2, %%mm3 \n\t" // 4H3 - 4H4
  2603. "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4
  2604. "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4
  2605. //50 opcodes so far
  2606. "movq (%0, %1, 2), %%mm2 \n\t"
  2607. "movq %%mm2, %%mm3 \n\t"
  2608. "punpcklbw %%mm7, %%mm2 \n\t" // L5
  2609. "punpckhbw %%mm7, %%mm3 \n\t" // H5
  2610. "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - L5
  2611. "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - H5
  2612. "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - 2L5
  2613. "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - 2H5
  2614. "movq (%%"FF_REG_a", %1, 4), %%mm6 \n\t"
  2615. "punpcklbw %%mm7, %%mm6 \n\t" // L6
  2616. "psubw %%mm6, %%mm2 \n\t" // L5 - L6
  2617. "movq (%%"FF_REG_a", %1, 4), %%mm6 \n\t"
  2618. "punpckhbw %%mm7, %%mm6 \n\t" // H6
  2619. "psubw %%mm6, %%mm3 \n\t" // H5 - H6
  2620. "paddw %%mm0, %%mm0 \n\t" // 2L4
  2621. "paddw %%mm1, %%mm1 \n\t" // 2H4
  2622. "psubw %%mm2, %%mm0 \n\t" // 2L4 - L5 + L6
  2623. "psubw %%mm3, %%mm1 \n\t" // 2H4 - H5 + H6
  2624. "psllw $2, %%mm2 \n\t" // 4L5 - 4L6
  2625. "psllw $2, %%mm3 \n\t" // 4H5 - 4H6
  2626. "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6
  2627. "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6
  2628. "movq (%0, %1, 4), %%mm2 \n\t"
  2629. "movq %%mm2, %%mm3 \n\t"
  2630. "punpcklbw %%mm7, %%mm2 \n\t" // L7
  2631. "punpckhbw %%mm7, %%mm3 \n\t" // H7
  2632. "paddw %%mm2, %%mm2 \n\t" // 2L7
  2633. "paddw %%mm3, %%mm3 \n\t" // 2H7
  2634. "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6 - 2L7
  2635. "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6 - 2H7
  2636. "movq (%4), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
  2637. "movq 8(%4), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
  2638. #if TEMPLATE_PP_MMXEXT
  2639. "movq %%mm7, %%mm6 \n\t" // 0
  2640. "psubw %%mm0, %%mm6 \n\t"
  2641. "pmaxsw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
  2642. "movq %%mm7, %%mm6 \n\t" // 0
  2643. "psubw %%mm1, %%mm6 \n\t"
  2644. "pmaxsw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
  2645. "movq %%mm7, %%mm6 \n\t" // 0
  2646. "psubw %%mm2, %%mm6 \n\t"
  2647. "pmaxsw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
  2648. "movq %%mm7, %%mm6 \n\t" // 0
  2649. "psubw %%mm3, %%mm6 \n\t"
  2650. "pmaxsw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
  2651. #else
  2652. "movq %%mm7, %%mm6 \n\t" // 0
  2653. "pcmpgtw %%mm0, %%mm6 \n\t"
  2654. "pxor %%mm6, %%mm0 \n\t"
  2655. "psubw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
  2656. "movq %%mm7, %%mm6 \n\t" // 0
  2657. "pcmpgtw %%mm1, %%mm6 \n\t"
  2658. "pxor %%mm6, %%mm1 \n\t"
  2659. "psubw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
  2660. "movq %%mm7, %%mm6 \n\t" // 0
  2661. "pcmpgtw %%mm2, %%mm6 \n\t"
  2662. "pxor %%mm6, %%mm2 \n\t"
  2663. "psubw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
  2664. "movq %%mm7, %%mm6 \n\t" // 0
  2665. "pcmpgtw %%mm3, %%mm6 \n\t"
  2666. "pxor %%mm6, %%mm3 \n\t"
  2667. "psubw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
  2668. #endif
  2669. #if TEMPLATE_PP_MMXEXT
  2670. "pminsw %%mm2, %%mm0 \n\t"
  2671. "pminsw %%mm3, %%mm1 \n\t"
  2672. #else
  2673. "movq %%mm0, %%mm6 \n\t"
  2674. "psubusw %%mm2, %%mm6 \n\t"
  2675. "psubw %%mm6, %%mm0 \n\t"
  2676. "movq %%mm1, %%mm6 \n\t"
  2677. "psubusw %%mm3, %%mm6 \n\t"
  2678. "psubw %%mm6, %%mm1 \n\t"
  2679. #endif
  2680. "movd %2, %%mm2 \n\t" // QP
  2681. "punpcklbw %%mm7, %%mm2 \n\t"
  2682. "movq %%mm7, %%mm6 \n\t" // 0
  2683. "pcmpgtw %%mm4, %%mm6 \n\t" // sign(2L2 - 5L3 + 5L4 - 2L5)
  2684. "pxor %%mm6, %%mm4 \n\t"
  2685. "psubw %%mm6, %%mm4 \n\t" // |2L2 - 5L3 + 5L4 - 2L5|
  2686. "pcmpgtw %%mm5, %%mm7 \n\t" // sign(2H2 - 5H3 + 5H4 - 2H5)
  2687. "pxor %%mm7, %%mm5 \n\t"
  2688. "psubw %%mm7, %%mm5 \n\t" // |2H2 - 5H3 + 5H4 - 2H5|
  2689. // 100 opcodes
  2690. "psllw $3, %%mm2 \n\t" // 8QP
  2691. "movq %%mm2, %%mm3 \n\t" // 8QP
  2692. "pcmpgtw %%mm4, %%mm2 \n\t"
  2693. "pcmpgtw %%mm5, %%mm3 \n\t"
  2694. "pand %%mm2, %%mm4 \n\t"
  2695. "pand %%mm3, %%mm5 \n\t"
  2696. "psubusw %%mm0, %%mm4 \n\t" // hd
  2697. "psubusw %%mm1, %%mm5 \n\t" // ld
  2698. "movq "MANGLE(w05)", %%mm2 \n\t" // 5
  2699. "pmullw %%mm2, %%mm4 \n\t"
  2700. "pmullw %%mm2, %%mm5 \n\t"
  2701. "movq "MANGLE(w20)", %%mm2 \n\t" // 32
  2702. "paddw %%mm2, %%mm4 \n\t"
  2703. "paddw %%mm2, %%mm5 \n\t"
  2704. "psrlw $6, %%mm4 \n\t"
  2705. "psrlw $6, %%mm5 \n\t"
  2706. "movq 16(%4), %%mm0 \n\t" // L3 - L4
  2707. "movq 24(%4), %%mm1 \n\t" // H3 - H4
  2708. "pxor %%mm2, %%mm2 \n\t"
  2709. "pxor %%mm3, %%mm3 \n\t"
  2710. "pcmpgtw %%mm0, %%mm2 \n\t" // sign (L3-L4)
  2711. "pcmpgtw %%mm1, %%mm3 \n\t" // sign (H3-H4)
  2712. "pxor %%mm2, %%mm0 \n\t"
  2713. "pxor %%mm3, %%mm1 \n\t"
  2714. "psubw %%mm2, %%mm0 \n\t" // |L3-L4|
  2715. "psubw %%mm3, %%mm1 \n\t" // |H3-H4|
  2716. "psrlw $1, %%mm0 \n\t" // |L3 - L4|/2
  2717. "psrlw $1, %%mm1 \n\t" // |H3 - H4|/2
  2718. "pxor %%mm6, %%mm2 \n\t"
  2719. "pxor %%mm7, %%mm3 \n\t"
  2720. "pand %%mm2, %%mm4 \n\t"
  2721. "pand %%mm3, %%mm5 \n\t"
  2722. #if TEMPLATE_PP_MMXEXT
  2723. "pminsw %%mm0, %%mm4 \n\t"
  2724. "pminsw %%mm1, %%mm5 \n\t"
  2725. #else
  2726. "movq %%mm4, %%mm2 \n\t"
  2727. "psubusw %%mm0, %%mm2 \n\t"
  2728. "psubw %%mm2, %%mm4 \n\t"
  2729. "movq %%mm5, %%mm2 \n\t"
  2730. "psubusw %%mm1, %%mm2 \n\t"
  2731. "psubw %%mm2, %%mm5 \n\t"
  2732. #endif
  2733. "pxor %%mm6, %%mm4 \n\t"
  2734. "pxor %%mm7, %%mm5 \n\t"
  2735. "psubw %%mm6, %%mm4 \n\t"
  2736. "psubw %%mm7, %%mm5 \n\t"
  2737. "packsswb %%mm5, %%mm4 \n\t"
  2738. "movq %3, %%mm1 \n\t"
  2739. "pandn %%mm4, %%mm1 \n\t"
  2740. "movq (%0), %%mm0 \n\t"
  2741. "paddb %%mm1, %%mm0 \n\t"
  2742. "movq %%mm0, (%0) \n\t"
  2743. "movq (%0, %1), %%mm0 \n\t"
  2744. "psubb %%mm1, %%mm0 \n\t"
  2745. "movq %%mm0, (%0, %1) \n\t"
  2746. : "+r" (temp_src)
  2747. : "r" ((x86_reg)step), "m" (c->pQPb), "m"(eq_mask), "r"(tmp)
  2748. NAMED_CONSTRAINTS_ADD(w05,w20)
  2749. : "%"FF_REG_a
  2750. );
  2751. }
  2752. }
  2753. #endif //TEMPLATE_PP_MMX
  2754. static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
  2755. const int8_t QPs[], int QPStride, int isColor, PPContext *c);
  2756. /**
  2757. * Copy a block from src to dst and fixes the blacklevel.
  2758. * levelFix == 0 -> do not touch the brightness & contrast
  2759. */
  2760. #undef REAL_SCALED_CPY
  2761. #undef SCALED_CPY
  2762. static inline void RENAME(blockCopy)(uint8_t dst[], int dstStride, const uint8_t src[], int srcStride,
  2763. int levelFix, int64_t *packedOffsetAndScale)
  2764. {
  2765. #if !TEMPLATE_PP_MMX || !HAVE_6REGS
  2766. int i;
  2767. #endif
  2768. if(levelFix){
  2769. #if TEMPLATE_PP_MMX && HAVE_6REGS
  2770. __asm__ volatile(
  2771. "movq (%%"FF_REG_a"), %%mm2 \n\t" // packedYOffset
  2772. "movq 8(%%"FF_REG_a"), %%mm3 \n\t" // packedYScale
  2773. "lea (%2,%4), %%"FF_REG_a" \n\t"
  2774. "lea (%3,%5), %%"FF_REG_d" \n\t"
  2775. "pxor %%mm4, %%mm4 \n\t"
  2776. #if TEMPLATE_PP_MMXEXT
  2777. #define REAL_SCALED_CPY(src1, src2, dst1, dst2) \
  2778. "movq " #src1 ", %%mm0 \n\t"\
  2779. "movq " #src1 ", %%mm5 \n\t"\
  2780. "movq " #src2 ", %%mm1 \n\t"\
  2781. "movq " #src2 ", %%mm6 \n\t"\
  2782. "punpcklbw %%mm0, %%mm0 \n\t"\
  2783. "punpckhbw %%mm5, %%mm5 \n\t"\
  2784. "punpcklbw %%mm1, %%mm1 \n\t"\
  2785. "punpckhbw %%mm6, %%mm6 \n\t"\
  2786. "pmulhuw %%mm3, %%mm0 \n\t"\
  2787. "pmulhuw %%mm3, %%mm5 \n\t"\
  2788. "pmulhuw %%mm3, %%mm1 \n\t"\
  2789. "pmulhuw %%mm3, %%mm6 \n\t"\
  2790. "psubw %%mm2, %%mm0 \n\t"\
  2791. "psubw %%mm2, %%mm5 \n\t"\
  2792. "psubw %%mm2, %%mm1 \n\t"\
  2793. "psubw %%mm2, %%mm6 \n\t"\
  2794. "packuswb %%mm5, %%mm0 \n\t"\
  2795. "packuswb %%mm6, %%mm1 \n\t"\
  2796. "movq %%mm0, " #dst1 " \n\t"\
  2797. "movq %%mm1, " #dst2 " \n\t"\
  2798. #else //TEMPLATE_PP_MMXEXT
  2799. #define REAL_SCALED_CPY(src1, src2, dst1, dst2) \
  2800. "movq " #src1 ", %%mm0 \n\t"\
  2801. "movq " #src1 ", %%mm5 \n\t"\
  2802. "punpcklbw %%mm4, %%mm0 \n\t"\
  2803. "punpckhbw %%mm4, %%mm5 \n\t"\
  2804. "psubw %%mm2, %%mm0 \n\t"\
  2805. "psubw %%mm2, %%mm5 \n\t"\
  2806. "movq " #src2 ", %%mm1 \n\t"\
  2807. "psllw $6, %%mm0 \n\t"\
  2808. "psllw $6, %%mm5 \n\t"\
  2809. "pmulhw %%mm3, %%mm0 \n\t"\
  2810. "movq " #src2 ", %%mm6 \n\t"\
  2811. "pmulhw %%mm3, %%mm5 \n\t"\
  2812. "punpcklbw %%mm4, %%mm1 \n\t"\
  2813. "punpckhbw %%mm4, %%mm6 \n\t"\
  2814. "psubw %%mm2, %%mm1 \n\t"\
  2815. "psubw %%mm2, %%mm6 \n\t"\
  2816. "psllw $6, %%mm1 \n\t"\
  2817. "psllw $6, %%mm6 \n\t"\
  2818. "pmulhw %%mm3, %%mm1 \n\t"\
  2819. "pmulhw %%mm3, %%mm6 \n\t"\
  2820. "packuswb %%mm5, %%mm0 \n\t"\
  2821. "packuswb %%mm6, %%mm1 \n\t"\
  2822. "movq %%mm0, " #dst1 " \n\t"\
  2823. "movq %%mm1, " #dst2 " \n\t"\
  2824. #endif //TEMPLATE_PP_MMXEXT
  2825. #define SCALED_CPY(src1, src2, dst1, dst2)\
  2826. REAL_SCALED_CPY(src1, src2, dst1, dst2)
  2827. SCALED_CPY((%2) , (%2, %4) , (%3) , (%3, %5))
  2828. SCALED_CPY((%2, %4, 2), (%%FF_REGa, %4, 2), (%3, %5, 2), (%%FF_REGd, %5, 2))
  2829. SCALED_CPY((%2, %4, 4), (%%FF_REGa, %4, 4), (%3, %5, 4), (%%FF_REGd, %5, 4))
  2830. "lea (%%"FF_REG_a",%4,4), %%"FF_REG_a" \n\t"
  2831. "lea (%%"FF_REG_d",%5,4), %%"FF_REG_d" \n\t"
  2832. SCALED_CPY((%%FF_REGa, %4), (%%FF_REGa, %4, 2), (%%FF_REGd, %5), (%%FF_REGd, %5, 2))
  2833. : "=&a" (packedOffsetAndScale)
  2834. : "0" (packedOffsetAndScale),
  2835. "r"(src),
  2836. "r"(dst),
  2837. "r" ((x86_reg)srcStride),
  2838. "r" ((x86_reg)dstStride)
  2839. : "%"FF_REG_d
  2840. );
  2841. #else //TEMPLATE_PP_MMX && HAVE_6REGS
  2842. for(i=0; i<8; i++)
  2843. memcpy( &(dst[dstStride*i]),
  2844. &(src[srcStride*i]), BLOCK_SIZE);
  2845. #endif //TEMPLATE_PP_MMX && HAVE_6REGS
  2846. }else{
  2847. #if TEMPLATE_PP_MMX && HAVE_6REGS
  2848. __asm__ volatile(
  2849. "lea (%0,%2), %%"FF_REG_a" \n\t"
  2850. "lea (%1,%3), %%"FF_REG_d" \n\t"
  2851. #define REAL_SIMPLE_CPY(src1, src2, dst1, dst2) \
  2852. "movq " #src1 ", %%mm0 \n\t"\
  2853. "movq " #src2 ", %%mm1 \n\t"\
  2854. "movq %%mm0, " #dst1 " \n\t"\
  2855. "movq %%mm1, " #dst2 " \n\t"\
  2856. #define SIMPLE_CPY(src1, src2, dst1, dst2)\
  2857. REAL_SIMPLE_CPY(src1, src2, dst1, dst2)
  2858. SIMPLE_CPY((%0) , (%0, %2) , (%1) , (%1, %3))
  2859. SIMPLE_CPY((%0, %2, 2), (%%FF_REGa, %2, 2), (%1, %3, 2), (%%FF_REGd, %3, 2))
  2860. SIMPLE_CPY((%0, %2, 4), (%%FF_REGa, %2, 4), (%1, %3, 4), (%%FF_REGd, %3, 4))
  2861. "lea (%%"FF_REG_a",%2,4), %%"FF_REG_a" \n\t"
  2862. "lea (%%"FF_REG_d",%3,4), %%"FF_REG_d" \n\t"
  2863. SIMPLE_CPY((%%FF_REGa, %2), (%%FF_REGa, %2, 2), (%%FF_REGd, %3), (%%FF_REGd, %3, 2))
  2864. : : "r" (src),
  2865. "r" (dst),
  2866. "r" ((x86_reg)srcStride),
  2867. "r" ((x86_reg)dstStride)
  2868. : "%"FF_REG_a, "%"FF_REG_d
  2869. );
  2870. #else //TEMPLATE_PP_MMX && HAVE_6REGS
  2871. for(i=0; i<8; i++)
  2872. memcpy( &(dst[dstStride*i]),
  2873. &(src[srcStride*i]), BLOCK_SIZE);
  2874. #endif //TEMPLATE_PP_MMX && HAVE_6REGS
  2875. }
  2876. }
  2877. /**
  2878. * Duplicate the given 8 src pixels ? times upward
  2879. */
  2880. static inline void RENAME(duplicate)(uint8_t src[], int stride)
  2881. {
  2882. #if TEMPLATE_PP_MMX
  2883. __asm__ volatile(
  2884. "movq (%0), %%mm0 \n\t"
  2885. "movq %%mm0, (%0, %1, 4) \n\t"
  2886. "add %1, %0 \n\t"
  2887. "movq %%mm0, (%0) \n\t"
  2888. "movq %%mm0, (%0, %1) \n\t"
  2889. "movq %%mm0, (%0, %1, 2) \n\t"
  2890. "movq %%mm0, (%0, %1, 4) \n\t"
  2891. : "+r" (src)
  2892. : "r" ((x86_reg)-stride)
  2893. );
  2894. #else
  2895. int i;
  2896. uint8_t *p=src;
  2897. for(i=0; i<5; i++){
  2898. p-= stride;
  2899. memcpy(p, src, 8);
  2900. }
  2901. #endif
  2902. }
  2903. #if ARCH_X86 && TEMPLATE_PP_MMXEXT
  2904. static inline void RENAME(prefetchnta)(const void *p)
  2905. {
  2906. __asm__ volatile( "prefetchnta (%0)\n\t"
  2907. : : "r" (p)
  2908. );
  2909. }
  2910. static inline void RENAME(prefetcht0)(const void *p)
  2911. {
  2912. __asm__ volatile( "prefetcht0 (%0)\n\t"
  2913. : : "r" (p)
  2914. );
  2915. }
  2916. static inline void RENAME(prefetcht1)(const void *p)
  2917. {
  2918. __asm__ volatile( "prefetcht1 (%0)\n\t"
  2919. : : "r" (p)
  2920. );
  2921. }
  2922. static inline void RENAME(prefetcht2)(const void *p)
  2923. {
  2924. __asm__ volatile( "prefetcht2 (%0)\n\t"
  2925. : : "r" (p)
  2926. );
  2927. }
  2928. #elif !ARCH_X86 && AV_GCC_VERSION_AT_LEAST(3,2)
  2929. static inline void RENAME(prefetchnta)(const void *p)
  2930. {
  2931. __builtin_prefetch(p,0,0);
  2932. }
  2933. static inline void RENAME(prefetcht0)(const void *p)
  2934. {
  2935. __builtin_prefetch(p,0,1);
  2936. }
  2937. static inline void RENAME(prefetcht1)(const void *p)
  2938. {
  2939. __builtin_prefetch(p,0,2);
  2940. }
  2941. static inline void RENAME(prefetcht2)(const void *p)
  2942. {
  2943. __builtin_prefetch(p,0,3);
  2944. }
  2945. #else
  2946. static inline void RENAME(prefetchnta)(const void *p)
  2947. {
  2948. return;
  2949. }
  2950. static inline void RENAME(prefetcht0)(const void *p)
  2951. {
  2952. return;
  2953. }
  2954. static inline void RENAME(prefetcht1)(const void *p)
  2955. {
  2956. return;
  2957. }
  2958. static inline void RENAME(prefetcht2)(const void *p)
  2959. {
  2960. return;
  2961. }
  2962. #endif
  2963. /**
  2964. * Filter array of bytes (Y or U or V values)
  2965. */
  2966. static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
  2967. const int8_t QPs[], int QPStride, int isColor, PPContext *c2)
  2968. {
  2969. DECLARE_ALIGNED(8, PPContext, c)= *c2; //copy to stack for faster access
  2970. int x,y;
  2971. #ifdef TEMPLATE_PP_TIME_MODE
  2972. const int mode= TEMPLATE_PP_TIME_MODE;
  2973. #else
  2974. const int mode= isColor ? c.ppMode.chromMode : c.ppMode.lumMode;
  2975. #endif
  2976. int black=0, white=255; // blackest black and whitest white in the picture
  2977. int QPCorrecture= 256*256;
  2978. int copyAhead;
  2979. #if TEMPLATE_PP_MMX
  2980. int i;
  2981. #endif
  2982. const int qpHShift= isColor ? 4-c.hChromaSubSample : 4;
  2983. const int qpVShift= isColor ? 4-c.vChromaSubSample : 4;
  2984. //FIXME remove
  2985. uint64_t * const yHistogram= c.yHistogram;
  2986. uint8_t * const tempSrc= srcStride > 0 ? c.tempSrc : c.tempSrc - 23*srcStride;
  2987. uint8_t * const tempDst= (dstStride > 0 ? c.tempDst : c.tempDst - 23*dstStride) + 32;
  2988. //const int mbWidth= isColor ? (width+7)>>3 : (width+15)>>4;
  2989. if (mode & VISUALIZE){
  2990. if(!(mode & (V_A_DEBLOCK | H_A_DEBLOCK)) || TEMPLATE_PP_MMX) {
  2991. av_log(c2, AV_LOG_WARNING, "Visualization is currently only supported with the accurate deblock filter without SIMD\n");
  2992. }
  2993. }
  2994. #if TEMPLATE_PP_MMX
  2995. for(i=0; i<57; i++){
  2996. int offset= ((i*c.ppMode.baseDcDiff)>>8) + 1;
  2997. int threshold= offset*2 + 1;
  2998. c.mmxDcOffset[i]= 0x7F - offset;
  2999. c.mmxDcThreshold[i]= 0x7F - threshold;
  3000. c.mmxDcOffset[i]*= 0x0101010101010101LL;
  3001. c.mmxDcThreshold[i]*= 0x0101010101010101LL;
  3002. }
  3003. #endif
  3004. if(mode & CUBIC_IPOL_DEINT_FILTER) copyAhead=16;
  3005. else if( (mode & LINEAR_BLEND_DEINT_FILTER)
  3006. || (mode & FFMPEG_DEINT_FILTER)
  3007. || (mode & LOWPASS5_DEINT_FILTER)) copyAhead=14;
  3008. else if( (mode & V_DEBLOCK)
  3009. || (mode & LINEAR_IPOL_DEINT_FILTER)
  3010. || (mode & MEDIAN_DEINT_FILTER)
  3011. || (mode & V_A_DEBLOCK)) copyAhead=13;
  3012. else if(mode & V_X1_FILTER) copyAhead=11;
  3013. // else if(mode & V_RK1_FILTER) copyAhead=10;
  3014. else if(mode & DERING) copyAhead=9;
  3015. else copyAhead=8;
  3016. copyAhead-= 8;
  3017. if(!isColor){
  3018. uint64_t sum= 0;
  3019. int i;
  3020. uint64_t maxClipped;
  3021. uint64_t clipped;
  3022. AVRational scale;
  3023. c.frameNum++;
  3024. // first frame is fscked so we ignore it
  3025. if(c.frameNum == 1) yHistogram[0]= width*(uint64_t)height/64*15/256;
  3026. for(i=0; i<256; i++){
  3027. sum+= yHistogram[i];
  3028. }
  3029. /* We always get a completely black picture first. */
  3030. maxClipped= av_rescale(sum, c.ppMode.maxClippedThreshold.num, c.ppMode.maxClippedThreshold.den);
  3031. clipped= sum;
  3032. for(black=255; black>0; black--){
  3033. if(clipped < maxClipped) break;
  3034. clipped-= yHistogram[black];
  3035. }
  3036. clipped= sum;
  3037. for(white=0; white<256; white++){
  3038. if(clipped < maxClipped) break;
  3039. clipped-= yHistogram[white];
  3040. }
  3041. scale = (AVRational){c.ppMode.maxAllowedY - c.ppMode.minAllowedY, white - black};
  3042. #if TEMPLATE_PP_MMXEXT
  3043. c.packedYScale = (uint16_t)av_rescale(scale.num, 256, scale.den);
  3044. c.packedYOffset= (((black*c.packedYScale)>>8) - c.ppMode.minAllowedY) & 0xFFFF;
  3045. #else
  3046. c.packedYScale = (uint16_t)av_rescale(scale.num, 1024, scale.den);
  3047. c.packedYOffset= (black - c.ppMode.minAllowedY) & 0xFFFF;
  3048. #endif
  3049. c.packedYOffset|= c.packedYOffset<<32;
  3050. c.packedYOffset|= c.packedYOffset<<16;
  3051. c.packedYScale|= c.packedYScale<<32;
  3052. c.packedYScale|= c.packedYScale<<16;
  3053. if(mode & LEVEL_FIX) QPCorrecture= (int)av_rescale(scale.num, 256*256, scale.den);
  3054. else QPCorrecture= 256*256;
  3055. }else{
  3056. c.packedYScale= 0x0100010001000100LL;
  3057. c.packedYOffset= 0;
  3058. QPCorrecture= 256*256;
  3059. }
  3060. /* copy & deinterlace first row of blocks */
  3061. y=-BLOCK_SIZE;
  3062. {
  3063. const uint8_t *srcBlock= &(src[y*srcStride]);
  3064. uint8_t *dstBlock= tempDst + dstStride;
  3065. // From this point on it is guaranteed that we can read and write 16 lines downward
  3066. // finish 1 block before the next otherwise we might have a problem
  3067. // with the L1 Cache of the P4 ... or only a few blocks at a time or something
  3068. for(x=0; x<width; x+=BLOCK_SIZE){
  3069. RENAME(prefetchnta)(srcBlock + (((x>>2)&6) + copyAhead)*srcStride + 32);
  3070. RENAME(prefetchnta)(srcBlock + (((x>>2)&6) + copyAhead+1)*srcStride + 32);
  3071. RENAME(prefetcht0)(dstBlock + (((x>>2)&6) + copyAhead)*dstStride + 32);
  3072. RENAME(prefetcht0)(dstBlock + (((x>>2)&6) + copyAhead+1)*dstStride + 32);
  3073. RENAME(blockCopy)(dstBlock + dstStride*8, dstStride,
  3074. srcBlock + srcStride*8, srcStride, mode & LEVEL_FIX, &c.packedYOffset);
  3075. RENAME(duplicate)(dstBlock + dstStride*8, dstStride);
  3076. if(mode & LINEAR_IPOL_DEINT_FILTER)
  3077. RENAME(deInterlaceInterpolateLinear)(dstBlock, dstStride);
  3078. else if(mode & LINEAR_BLEND_DEINT_FILTER)
  3079. RENAME(deInterlaceBlendLinear)(dstBlock, dstStride, c.deintTemp + x);
  3080. else if(mode & MEDIAN_DEINT_FILTER)
  3081. RENAME(deInterlaceMedian)(dstBlock, dstStride);
  3082. else if(mode & CUBIC_IPOL_DEINT_FILTER)
  3083. RENAME(deInterlaceInterpolateCubic)(dstBlock, dstStride);
  3084. else if(mode & FFMPEG_DEINT_FILTER)
  3085. RENAME(deInterlaceFF)(dstBlock, dstStride, c.deintTemp + x);
  3086. else if(mode & LOWPASS5_DEINT_FILTER)
  3087. RENAME(deInterlaceL5)(dstBlock, dstStride, c.deintTemp + x, c.deintTemp + width + x);
  3088. /* else if(mode & CUBIC_BLEND_DEINT_FILTER)
  3089. RENAME(deInterlaceBlendCubic)(dstBlock, dstStride);
  3090. */
  3091. dstBlock+=8;
  3092. srcBlock+=8;
  3093. }
  3094. if(width==FFABS(dstStride))
  3095. linecpy(dst, tempDst + 9*dstStride, copyAhead, dstStride);
  3096. else{
  3097. int i;
  3098. for(i=0; i<copyAhead; i++){
  3099. memcpy(dst + i*dstStride, tempDst + (9+i)*dstStride, width);
  3100. }
  3101. }
  3102. }
  3103. for(y=0; y<height; y+=BLOCK_SIZE){
  3104. //1% speedup if these are here instead of the inner loop
  3105. const uint8_t *srcBlock= &(src[y*srcStride]);
  3106. uint8_t *dstBlock= &(dst[y*dstStride]);
  3107. #if TEMPLATE_PP_MMX
  3108. uint8_t *tempBlock1= c.tempBlocks;
  3109. uint8_t *tempBlock2= c.tempBlocks + 8;
  3110. #endif
  3111. const int8_t *QPptr= &QPs[(y>>qpVShift)*QPStride];
  3112. int8_t *nonBQPptr= &c.nonBQPTable[(y>>qpVShift)*FFABS(QPStride)];
  3113. int QP=0, nonBQP=0;
  3114. /* can we mess with a 8x16 block from srcBlock/dstBlock downwards and 1 line upwards
  3115. if not than use a temporary buffer */
  3116. if(y+15 >= height){
  3117. int i;
  3118. /* copy from line (copyAhead) to (copyAhead+7) of src, these will be copied with
  3119. blockcopy to dst later */
  3120. linecpy(tempSrc + srcStride*copyAhead, srcBlock + srcStride*copyAhead,
  3121. FFMAX(height-y-copyAhead, 0), srcStride);
  3122. /* duplicate last line of src to fill the void up to line (copyAhead+7) */
  3123. for(i=FFMAX(height-y, 8); i<copyAhead+8; i++)
  3124. memcpy(tempSrc + srcStride*i, src + srcStride*(height-1), FFABS(srcStride));
  3125. /* copy up to (copyAhead+1) lines of dst (line -1 to (copyAhead-1))*/
  3126. linecpy(tempDst, dstBlock - dstStride, FFMIN(height-y+1, copyAhead+1), dstStride);
  3127. /* duplicate last line of dst to fill the void up to line (copyAhead) */
  3128. for(i=height-y+1; i<=copyAhead; i++)
  3129. memcpy(tempDst + dstStride*i, dst + dstStride*(height-1), FFABS(dstStride));
  3130. dstBlock= tempDst + dstStride;
  3131. srcBlock= tempSrc;
  3132. }
  3133. // From this point on it is guaranteed that we can read and write 16 lines downward
  3134. // finish 1 block before the next otherwise we might have a problem
  3135. // with the L1 Cache of the P4 ... or only a few blocks at a time or something
  3136. for(x=0; x<width; ){
  3137. int startx = x;
  3138. int endx = FFMIN(width, x+32);
  3139. uint8_t *dstBlockStart = dstBlock;
  3140. const uint8_t *srcBlockStart = srcBlock;
  3141. int qp_index = 0;
  3142. for(qp_index=0; qp_index < (endx-startx)/BLOCK_SIZE; qp_index++){
  3143. QP = QPptr[(x+qp_index*BLOCK_SIZE)>>qpHShift];
  3144. nonBQP = nonBQPptr[(x+qp_index*BLOCK_SIZE)>>qpHShift];
  3145. if(!isColor){
  3146. QP= (QP* QPCorrecture + 256*128)>>16;
  3147. nonBQP= (nonBQP* QPCorrecture + 256*128)>>16;
  3148. yHistogram[(srcBlock+qp_index*8)[srcStride*12 + 4]]++;
  3149. }
  3150. c.QP_block[qp_index] = QP;
  3151. c.nonBQP_block[qp_index] = nonBQP;
  3152. #if TEMPLATE_PP_MMX
  3153. __asm__ volatile(
  3154. "movd %1, %%mm7 \n\t"
  3155. "packuswb %%mm7, %%mm7 \n\t" // 0, 0, 0, QP, 0, 0, 0, QP
  3156. "packuswb %%mm7, %%mm7 \n\t" // 0,QP, 0, QP, 0,QP, 0, QP
  3157. "packuswb %%mm7, %%mm7 \n\t" // QP,..., QP
  3158. "movq %%mm7, %0 \n\t"
  3159. : "=m" (c.pQPb_block[qp_index])
  3160. : "r" (QP)
  3161. );
  3162. #endif
  3163. }
  3164. for(; x < endx; x+=BLOCK_SIZE){
  3165. RENAME(prefetchnta)(srcBlock + (((x>>2)&6) + copyAhead)*srcStride + 32);
  3166. RENAME(prefetchnta)(srcBlock + (((x>>2)&6) + copyAhead+1)*srcStride + 32);
  3167. RENAME(prefetcht0)(dstBlock + (((x>>2)&6) + copyAhead)*dstStride + 32);
  3168. RENAME(prefetcht0)(dstBlock + (((x>>2)&6) + copyAhead+1)*dstStride + 32);
  3169. RENAME(blockCopy)(dstBlock + dstStride*copyAhead, dstStride,
  3170. srcBlock + srcStride*copyAhead, srcStride, mode & LEVEL_FIX, &c.packedYOffset);
  3171. if(mode & LINEAR_IPOL_DEINT_FILTER)
  3172. RENAME(deInterlaceInterpolateLinear)(dstBlock, dstStride);
  3173. else if(mode & LINEAR_BLEND_DEINT_FILTER)
  3174. RENAME(deInterlaceBlendLinear)(dstBlock, dstStride, c.deintTemp + x);
  3175. else if(mode & MEDIAN_DEINT_FILTER)
  3176. RENAME(deInterlaceMedian)(dstBlock, dstStride);
  3177. else if(mode & CUBIC_IPOL_DEINT_FILTER)
  3178. RENAME(deInterlaceInterpolateCubic)(dstBlock, dstStride);
  3179. else if(mode & FFMPEG_DEINT_FILTER)
  3180. RENAME(deInterlaceFF)(dstBlock, dstStride, c.deintTemp + x);
  3181. else if(mode & LOWPASS5_DEINT_FILTER)
  3182. RENAME(deInterlaceL5)(dstBlock, dstStride, c.deintTemp + x, c.deintTemp + width + x);
  3183. /* else if(mode & CUBIC_BLEND_DEINT_FILTER)
  3184. RENAME(deInterlaceBlendCubic)(dstBlock, dstStride);
  3185. */
  3186. dstBlock+=8;
  3187. srcBlock+=8;
  3188. }
  3189. dstBlock = dstBlockStart;
  3190. srcBlock = srcBlockStart;
  3191. for(x = startx, qp_index = 0; x < endx; x+=BLOCK_SIZE, qp_index++){
  3192. const int stride= dstStride;
  3193. //temporary while changing QP stuff to make things continue to work
  3194. //eventually QP,nonBQP,etc will be arrays and this will be unnecessary
  3195. c.QP = c.QP_block[qp_index];
  3196. c.nonBQP = c.nonBQP_block[qp_index];
  3197. c.pQPb = c.pQPb_block[qp_index];
  3198. c.pQPb2 = c.pQPb2_block[qp_index];
  3199. /* only deblock if we have 2 blocks */
  3200. if(y + 8 < height){
  3201. if(mode & V_X1_FILTER)
  3202. RENAME(vertX1Filter)(dstBlock, stride, &c);
  3203. else if(mode & V_DEBLOCK){
  3204. const int t= RENAME(vertClassify)(dstBlock, stride, &c);
  3205. if(t==1)
  3206. RENAME(doVertLowPass)(dstBlock, stride, &c);
  3207. else if(t==2)
  3208. RENAME(doVertDefFilter)(dstBlock, stride, &c);
  3209. }else if(mode & V_A_DEBLOCK){
  3210. RENAME(do_a_deblock)(dstBlock, stride, 1, &c, mode);
  3211. }
  3212. }
  3213. dstBlock+=8;
  3214. srcBlock+=8;
  3215. }
  3216. dstBlock = dstBlockStart;
  3217. srcBlock = srcBlockStart;
  3218. for(x = startx, qp_index=0; x < endx; x+=BLOCK_SIZE, qp_index++){
  3219. const int stride= dstStride;
  3220. av_unused uint8_t *tmpXchg;
  3221. c.QP = c.QP_block[qp_index];
  3222. c.nonBQP = c.nonBQP_block[qp_index];
  3223. c.pQPb = c.pQPb_block[qp_index];
  3224. c.pQPb2 = c.pQPb2_block[qp_index];
  3225. #if TEMPLATE_PP_MMX
  3226. RENAME(transpose1)(tempBlock1, tempBlock2, dstBlock, dstStride);
  3227. #endif
  3228. /* check if we have a previous block to deblock it with dstBlock */
  3229. if(x - 8 >= 0){
  3230. #if TEMPLATE_PP_MMX
  3231. if(mode & H_X1_FILTER)
  3232. RENAME(vertX1Filter)(tempBlock1, 16, &c);
  3233. else if(mode & H_DEBLOCK){
  3234. const int t= RENAME(vertClassify)(tempBlock1, 16, &c);
  3235. if(t==1)
  3236. RENAME(doVertLowPass)(tempBlock1, 16, &c);
  3237. else if(t==2)
  3238. RENAME(doVertDefFilter)(tempBlock1, 16, &c);
  3239. }else if(mode & H_A_DEBLOCK){
  3240. RENAME(do_a_deblock)(tempBlock1, 16, 1, &c, mode);
  3241. }
  3242. RENAME(transpose2)(dstBlock-4, dstStride, tempBlock1 + 4*16);
  3243. #else
  3244. if(mode & H_X1_FILTER)
  3245. horizX1Filter(dstBlock-4, stride, c.QP);
  3246. else if(mode & H_DEBLOCK){
  3247. #if TEMPLATE_PP_ALTIVEC
  3248. DECLARE_ALIGNED(16, unsigned char, tempBlock)[272];
  3249. int t;
  3250. transpose_16x8_char_toPackedAlign_altivec(tempBlock, dstBlock - (4 + 1), stride);
  3251. t = vertClassify_altivec(tempBlock-48, 16, &c);
  3252. if(t==1) {
  3253. doVertLowPass_altivec(tempBlock-48, 16, &c);
  3254. transpose_8x16_char_fromPackedAlign_altivec(dstBlock - (4 + 1), tempBlock, stride);
  3255. }
  3256. else if(t==2) {
  3257. doVertDefFilter_altivec(tempBlock-48, 16, &c);
  3258. transpose_8x16_char_fromPackedAlign_altivec(dstBlock - (4 + 1), tempBlock, stride);
  3259. }
  3260. #else
  3261. const int t= RENAME(horizClassify)(dstBlock-4, stride, &c);
  3262. if(t==1)
  3263. RENAME(doHorizLowPass)(dstBlock-4, stride, &c);
  3264. else if(t==2)
  3265. RENAME(doHorizDefFilter)(dstBlock-4, stride, &c);
  3266. #endif
  3267. }else if(mode & H_A_DEBLOCK){
  3268. RENAME(do_a_deblock)(dstBlock-8, 1, stride, &c, mode);
  3269. }
  3270. #endif //TEMPLATE_PP_MMX
  3271. if(mode & DERING){
  3272. //FIXME filter first line
  3273. if(y>0) RENAME(dering)(dstBlock - stride - 8, stride, &c);
  3274. }
  3275. if(mode & TEMP_NOISE_FILTER)
  3276. {
  3277. RENAME(tempNoiseReducer)(dstBlock-8, stride,
  3278. c.tempBlurred[isColor] + y*dstStride + x,
  3279. c.tempBlurredPast[isColor] + (y>>3)*256 + (x>>3) + 256,
  3280. c.ppMode.maxTmpNoise);
  3281. }
  3282. }
  3283. dstBlock+=8;
  3284. srcBlock+=8;
  3285. #if TEMPLATE_PP_MMX
  3286. tmpXchg= tempBlock1;
  3287. tempBlock1= tempBlock2;
  3288. tempBlock2 = tmpXchg;
  3289. #endif
  3290. }
  3291. }
  3292. if(mode & DERING){
  3293. if(y > 0) RENAME(dering)(dstBlock - dstStride - 8, dstStride, &c);
  3294. }
  3295. if((mode & TEMP_NOISE_FILTER)){
  3296. RENAME(tempNoiseReducer)(dstBlock-8, dstStride,
  3297. c.tempBlurred[isColor] + y*dstStride + x,
  3298. c.tempBlurredPast[isColor] + (y>>3)*256 + (x>>3) + 256,
  3299. c.ppMode.maxTmpNoise);
  3300. }
  3301. /* did we use a tmp buffer for the last lines*/
  3302. if(y+15 >= height){
  3303. uint8_t *dstBlock= &(dst[y*dstStride]);
  3304. if(width==FFABS(dstStride))
  3305. linecpy(dstBlock, tempDst + dstStride, height-y, dstStride);
  3306. else{
  3307. int i;
  3308. for(i=0; i<height-y; i++){
  3309. memcpy(dstBlock + i*dstStride, tempDst + (i+1)*dstStride, width);
  3310. }
  3311. }
  3312. }
  3313. }
  3314. #if TEMPLATE_PP_3DNOW
  3315. __asm__ volatile("femms");
  3316. #elif TEMPLATE_PP_MMX
  3317. __asm__ volatile("emms");
  3318. #endif
  3319. #ifdef DEBUG_BRIGHTNESS
  3320. if(!isColor){
  3321. int max=1;
  3322. int i;
  3323. for(i=0; i<256; i++)
  3324. if(yHistogram[i] > max) max=yHistogram[i];
  3325. for(i=1; i<256; i++){
  3326. int x;
  3327. int start=yHistogram[i-1]/(max/256+1);
  3328. int end=yHistogram[i]/(max/256+1);
  3329. int inc= end > start ? 1 : -1;
  3330. for(x=start; x!=end+inc; x+=inc)
  3331. dst[ i*dstStride + x]+=128;
  3332. }
  3333. for(i=0; i<100; i+=2){
  3334. dst[ (white)*dstStride + i]+=128;
  3335. dst[ (black)*dstStride + i]+=128;
  3336. }
  3337. }
  3338. #endif
  3339. *c2= c; //copy local context back
  3340. }
  3341. #undef RENAME
  3342. #undef TEMPLATE_PP_C
  3343. #undef TEMPLATE_PP_ALTIVEC
  3344. #undef TEMPLATE_PP_MMX
  3345. #undef TEMPLATE_PP_MMXEXT
  3346. #undef TEMPLATE_PP_3DNOW
  3347. #undef TEMPLATE_PP_SSE2