postprocess_template.c 160 KB

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