postprocess_template.c 161 KB

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