dsputil_mmx.c 124 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047
  1. /*
  2. * MMX optimized DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
  23. */
  24. #include "libavutil/x86_cpu.h"
  25. #include "libavcodec/dsputil.h"
  26. #include "libavcodec/h263.h"
  27. #include "libavcodec/mpegvideo.h"
  28. #include "libavcodec/simple_idct.h"
  29. #include "dsputil_mmx.h"
  30. #include "mmx.h"
  31. #include "vp3dsp_mmx.h"
  32. #include "vp3dsp_sse2.h"
  33. #include "vp6dsp_mmx.h"
  34. #include "vp6dsp_sse2.h"
  35. #include "idct_xvid.h"
  36. //#undef NDEBUG
  37. //#include <assert.h>
  38. int mm_flags; /* multimedia extension flags */
  39. /* pixel operations */
  40. DECLARE_ALIGNED_8 (const uint64_t, ff_bone) = 0x0101010101010101ULL;
  41. DECLARE_ALIGNED_8 (const uint64_t, ff_wtwo) = 0x0002000200020002ULL;
  42. DECLARE_ALIGNED_16(const uint64_t, ff_pdw_80000000[2]) =
  43. {0x8000000080000000ULL, 0x8000000080000000ULL};
  44. DECLARE_ALIGNED_8 (const uint64_t, ff_pw_3 ) = 0x0003000300030003ULL;
  45. DECLARE_ALIGNED_8 (const uint64_t, ff_pw_4 ) = 0x0004000400040004ULL;
  46. DECLARE_ALIGNED_16(const xmm_reg, ff_pw_5 ) = {0x0005000500050005ULL, 0x0005000500050005ULL};
  47. DECLARE_ALIGNED_16(const xmm_reg, ff_pw_8 ) = {0x0008000800080008ULL, 0x0008000800080008ULL};
  48. DECLARE_ALIGNED_8 (const uint64_t, ff_pw_15 ) = 0x000F000F000F000FULL;
  49. DECLARE_ALIGNED_16(const xmm_reg, ff_pw_16 ) = {0x0010001000100010ULL, 0x0010001000100010ULL};
  50. DECLARE_ALIGNED_8 (const uint64_t, ff_pw_20 ) = 0x0014001400140014ULL;
  51. DECLARE_ALIGNED_16(const xmm_reg, ff_pw_28 ) = {0x001C001C001C001CULL, 0x001C001C001C001CULL};
  52. DECLARE_ALIGNED_16(const xmm_reg, ff_pw_32 ) = {0x0020002000200020ULL, 0x0020002000200020ULL};
  53. DECLARE_ALIGNED_8 (const uint64_t, ff_pw_42 ) = 0x002A002A002A002AULL;
  54. DECLARE_ALIGNED_16(const xmm_reg, ff_pw_64 ) = {0x0040004000400040ULL, 0x0040004000400040ULL};
  55. DECLARE_ALIGNED_8 (const uint64_t, ff_pw_96 ) = 0x0060006000600060ULL;
  56. DECLARE_ALIGNED_8 (const uint64_t, ff_pw_128) = 0x0080008000800080ULL;
  57. DECLARE_ALIGNED_8 (const uint64_t, ff_pw_255) = 0x00ff00ff00ff00ffULL;
  58. DECLARE_ALIGNED_8 (const uint64_t, ff_pb_1 ) = 0x0101010101010101ULL;
  59. DECLARE_ALIGNED_8 (const uint64_t, ff_pb_3 ) = 0x0303030303030303ULL;
  60. DECLARE_ALIGNED_8 (const uint64_t, ff_pb_7 ) = 0x0707070707070707ULL;
  61. DECLARE_ALIGNED_8 (const uint64_t, ff_pb_1F ) = 0x1F1F1F1F1F1F1F1FULL;
  62. DECLARE_ALIGNED_8 (const uint64_t, ff_pb_3F ) = 0x3F3F3F3F3F3F3F3FULL;
  63. DECLARE_ALIGNED_8 (const uint64_t, ff_pb_81 ) = 0x8181818181818181ULL;
  64. DECLARE_ALIGNED_8 (const uint64_t, ff_pb_A1 ) = 0xA1A1A1A1A1A1A1A1ULL;
  65. DECLARE_ALIGNED_8 (const uint64_t, ff_pb_FC ) = 0xFCFCFCFCFCFCFCFCULL;
  66. DECLARE_ALIGNED_16(const double, ff_pd_1[2]) = { 1.0, 1.0 };
  67. DECLARE_ALIGNED_16(const double, ff_pd_2[2]) = { 2.0, 2.0 };
  68. #define JUMPALIGN() __asm__ volatile (ASMALIGN(3)::)
  69. #define MOVQ_ZERO(regd) __asm__ volatile ("pxor %%" #regd ", %%" #regd ::)
  70. #define MOVQ_BFE(regd) \
  71. __asm__ volatile ( \
  72. "pcmpeqd %%" #regd ", %%" #regd " \n\t"\
  73. "paddb %%" #regd ", %%" #regd " \n\t" ::)
  74. #ifndef PIC
  75. #define MOVQ_BONE(regd) __asm__ volatile ("movq %0, %%" #regd " \n\t" ::"m"(ff_bone))
  76. #define MOVQ_WTWO(regd) __asm__ volatile ("movq %0, %%" #regd " \n\t" ::"m"(ff_wtwo))
  77. #else
  78. // for shared library it's better to use this way for accessing constants
  79. // pcmpeqd -> -1
  80. #define MOVQ_BONE(regd) \
  81. __asm__ volatile ( \
  82. "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
  83. "psrlw $15, %%" #regd " \n\t" \
  84. "packuswb %%" #regd ", %%" #regd " \n\t" ::)
  85. #define MOVQ_WTWO(regd) \
  86. __asm__ volatile ( \
  87. "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
  88. "psrlw $15, %%" #regd " \n\t" \
  89. "psllw $1, %%" #regd " \n\t"::)
  90. #endif
  91. // using regr as temporary and for the output result
  92. // first argument is unmodifed and second is trashed
  93. // regfe is supposed to contain 0xfefefefefefefefe
  94. #define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
  95. "movq " #rega ", " #regr " \n\t"\
  96. "pand " #regb ", " #regr " \n\t"\
  97. "pxor " #rega ", " #regb " \n\t"\
  98. "pand " #regfe "," #regb " \n\t"\
  99. "psrlq $1, " #regb " \n\t"\
  100. "paddb " #regb ", " #regr " \n\t"
  101. #define PAVGB_MMX(rega, regb, regr, regfe) \
  102. "movq " #rega ", " #regr " \n\t"\
  103. "por " #regb ", " #regr " \n\t"\
  104. "pxor " #rega ", " #regb " \n\t"\
  105. "pand " #regfe "," #regb " \n\t"\
  106. "psrlq $1, " #regb " \n\t"\
  107. "psubb " #regb ", " #regr " \n\t"
  108. // mm6 is supposed to contain 0xfefefefefefefefe
  109. #define PAVGBP_MMX_NO_RND(rega, regb, regr, regc, regd, regp) \
  110. "movq " #rega ", " #regr " \n\t"\
  111. "movq " #regc ", " #regp " \n\t"\
  112. "pand " #regb ", " #regr " \n\t"\
  113. "pand " #regd ", " #regp " \n\t"\
  114. "pxor " #rega ", " #regb " \n\t"\
  115. "pxor " #regc ", " #regd " \n\t"\
  116. "pand %%mm6, " #regb " \n\t"\
  117. "pand %%mm6, " #regd " \n\t"\
  118. "psrlq $1, " #regb " \n\t"\
  119. "psrlq $1, " #regd " \n\t"\
  120. "paddb " #regb ", " #regr " \n\t"\
  121. "paddb " #regd ", " #regp " \n\t"
  122. #define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
  123. "movq " #rega ", " #regr " \n\t"\
  124. "movq " #regc ", " #regp " \n\t"\
  125. "por " #regb ", " #regr " \n\t"\
  126. "por " #regd ", " #regp " \n\t"\
  127. "pxor " #rega ", " #regb " \n\t"\
  128. "pxor " #regc ", " #regd " \n\t"\
  129. "pand %%mm6, " #regb " \n\t"\
  130. "pand %%mm6, " #regd " \n\t"\
  131. "psrlq $1, " #regd " \n\t"\
  132. "psrlq $1, " #regb " \n\t"\
  133. "psubb " #regb ", " #regr " \n\t"\
  134. "psubb " #regd ", " #regp " \n\t"
  135. /***********************************/
  136. /* MMX no rounding */
  137. #define DEF(x, y) x ## _no_rnd_ ## y ##_mmx
  138. #define SET_RND MOVQ_WONE
  139. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
  140. #define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
  141. #include "dsputil_mmx_rnd_template.c"
  142. #undef DEF
  143. #undef SET_RND
  144. #undef PAVGBP
  145. #undef PAVGB
  146. /***********************************/
  147. /* MMX rounding */
  148. #define DEF(x, y) x ## _ ## y ##_mmx
  149. #define SET_RND MOVQ_WTWO
  150. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
  151. #define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
  152. #include "dsputil_mmx_rnd_template.c"
  153. #undef DEF
  154. #undef SET_RND
  155. #undef PAVGBP
  156. #undef PAVGB
  157. /***********************************/
  158. /* 3Dnow specific */
  159. #define DEF(x) x ## _3dnow
  160. #define PAVGB "pavgusb"
  161. #include "dsputil_mmx_avg_template.c"
  162. #undef DEF
  163. #undef PAVGB
  164. /***********************************/
  165. /* MMX2 specific */
  166. #define DEF(x) x ## _mmx2
  167. /* Introduced only in MMX2 set */
  168. #define PAVGB "pavgb"
  169. #include "dsputil_mmx_avg_template.c"
  170. #undef DEF
  171. #undef PAVGB
  172. #define put_no_rnd_pixels16_mmx put_pixels16_mmx
  173. #define put_no_rnd_pixels8_mmx put_pixels8_mmx
  174. #define put_pixels16_mmx2 put_pixels16_mmx
  175. #define put_pixels8_mmx2 put_pixels8_mmx
  176. #define put_pixels4_mmx2 put_pixels4_mmx
  177. #define put_no_rnd_pixels16_mmx2 put_no_rnd_pixels16_mmx
  178. #define put_no_rnd_pixels8_mmx2 put_no_rnd_pixels8_mmx
  179. #define put_pixels16_3dnow put_pixels16_mmx
  180. #define put_pixels8_3dnow put_pixels8_mmx
  181. #define put_pixels4_3dnow put_pixels4_mmx
  182. #define put_no_rnd_pixels16_3dnow put_no_rnd_pixels16_mmx
  183. #define put_no_rnd_pixels8_3dnow put_no_rnd_pixels8_mmx
  184. /***********************************/
  185. /* standard MMX */
  186. void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
  187. {
  188. const DCTELEM *p;
  189. uint8_t *pix;
  190. /* read the pixels */
  191. p = block;
  192. pix = pixels;
  193. /* unrolled loop */
  194. __asm__ volatile(
  195. "movq %3, %%mm0 \n\t"
  196. "movq 8%3, %%mm1 \n\t"
  197. "movq 16%3, %%mm2 \n\t"
  198. "movq 24%3, %%mm3 \n\t"
  199. "movq 32%3, %%mm4 \n\t"
  200. "movq 40%3, %%mm5 \n\t"
  201. "movq 48%3, %%mm6 \n\t"
  202. "movq 56%3, %%mm7 \n\t"
  203. "packuswb %%mm1, %%mm0 \n\t"
  204. "packuswb %%mm3, %%mm2 \n\t"
  205. "packuswb %%mm5, %%mm4 \n\t"
  206. "packuswb %%mm7, %%mm6 \n\t"
  207. "movq %%mm0, (%0) \n\t"
  208. "movq %%mm2, (%0, %1) \n\t"
  209. "movq %%mm4, (%0, %1, 2) \n\t"
  210. "movq %%mm6, (%0, %2) \n\t"
  211. ::"r" (pix), "r" ((x86_reg)line_size), "r" ((x86_reg)line_size*3), "m"(*p)
  212. :"memory");
  213. pix += line_size*4;
  214. p += 32;
  215. // if here would be an exact copy of the code above
  216. // compiler would generate some very strange code
  217. // thus using "r"
  218. __asm__ volatile(
  219. "movq (%3), %%mm0 \n\t"
  220. "movq 8(%3), %%mm1 \n\t"
  221. "movq 16(%3), %%mm2 \n\t"
  222. "movq 24(%3), %%mm3 \n\t"
  223. "movq 32(%3), %%mm4 \n\t"
  224. "movq 40(%3), %%mm5 \n\t"
  225. "movq 48(%3), %%mm6 \n\t"
  226. "movq 56(%3), %%mm7 \n\t"
  227. "packuswb %%mm1, %%mm0 \n\t"
  228. "packuswb %%mm3, %%mm2 \n\t"
  229. "packuswb %%mm5, %%mm4 \n\t"
  230. "packuswb %%mm7, %%mm6 \n\t"
  231. "movq %%mm0, (%0) \n\t"
  232. "movq %%mm2, (%0, %1) \n\t"
  233. "movq %%mm4, (%0, %1, 2) \n\t"
  234. "movq %%mm6, (%0, %2) \n\t"
  235. ::"r" (pix), "r" ((x86_reg)line_size), "r" ((x86_reg)line_size*3), "r"(p)
  236. :"memory");
  237. }
  238. static DECLARE_ALIGNED_8(const unsigned char, vector128[8]) =
  239. { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
  240. void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
  241. {
  242. int i;
  243. movq_m2r(*vector128, mm1);
  244. for (i = 0; i < 8; i++) {
  245. movq_m2r(*(block), mm0);
  246. packsswb_m2r(*(block + 4), mm0);
  247. block += 8;
  248. paddb_r2r(mm1, mm0);
  249. movq_r2m(mm0, *pixels);
  250. pixels += line_size;
  251. }
  252. }
  253. void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
  254. {
  255. const DCTELEM *p;
  256. uint8_t *pix;
  257. int i;
  258. /* read the pixels */
  259. p = block;
  260. pix = pixels;
  261. MOVQ_ZERO(mm7);
  262. i = 4;
  263. do {
  264. __asm__ volatile(
  265. "movq (%2), %%mm0 \n\t"
  266. "movq 8(%2), %%mm1 \n\t"
  267. "movq 16(%2), %%mm2 \n\t"
  268. "movq 24(%2), %%mm3 \n\t"
  269. "movq %0, %%mm4 \n\t"
  270. "movq %1, %%mm6 \n\t"
  271. "movq %%mm4, %%mm5 \n\t"
  272. "punpcklbw %%mm7, %%mm4 \n\t"
  273. "punpckhbw %%mm7, %%mm5 \n\t"
  274. "paddsw %%mm4, %%mm0 \n\t"
  275. "paddsw %%mm5, %%mm1 \n\t"
  276. "movq %%mm6, %%mm5 \n\t"
  277. "punpcklbw %%mm7, %%mm6 \n\t"
  278. "punpckhbw %%mm7, %%mm5 \n\t"
  279. "paddsw %%mm6, %%mm2 \n\t"
  280. "paddsw %%mm5, %%mm3 \n\t"
  281. "packuswb %%mm1, %%mm0 \n\t"
  282. "packuswb %%mm3, %%mm2 \n\t"
  283. "movq %%mm0, %0 \n\t"
  284. "movq %%mm2, %1 \n\t"
  285. :"+m"(*pix), "+m"(*(pix+line_size))
  286. :"r"(p)
  287. :"memory");
  288. pix += line_size*2;
  289. p += 16;
  290. } while (--i);
  291. }
  292. static void put_pixels4_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  293. {
  294. __asm__ volatile(
  295. "lea (%3, %3), %%"REG_a" \n\t"
  296. ASMALIGN(3)
  297. "1: \n\t"
  298. "movd (%1), %%mm0 \n\t"
  299. "movd (%1, %3), %%mm1 \n\t"
  300. "movd %%mm0, (%2) \n\t"
  301. "movd %%mm1, (%2, %3) \n\t"
  302. "add %%"REG_a", %1 \n\t"
  303. "add %%"REG_a", %2 \n\t"
  304. "movd (%1), %%mm0 \n\t"
  305. "movd (%1, %3), %%mm1 \n\t"
  306. "movd %%mm0, (%2) \n\t"
  307. "movd %%mm1, (%2, %3) \n\t"
  308. "add %%"REG_a", %1 \n\t"
  309. "add %%"REG_a", %2 \n\t"
  310. "subl $4, %0 \n\t"
  311. "jnz 1b \n\t"
  312. : "+g"(h), "+r" (pixels), "+r" (block)
  313. : "r"((x86_reg)line_size)
  314. : "%"REG_a, "memory"
  315. );
  316. }
  317. static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  318. {
  319. __asm__ volatile(
  320. "lea (%3, %3), %%"REG_a" \n\t"
  321. ASMALIGN(3)
  322. "1: \n\t"
  323. "movq (%1), %%mm0 \n\t"
  324. "movq (%1, %3), %%mm1 \n\t"
  325. "movq %%mm0, (%2) \n\t"
  326. "movq %%mm1, (%2, %3) \n\t"
  327. "add %%"REG_a", %1 \n\t"
  328. "add %%"REG_a", %2 \n\t"
  329. "movq (%1), %%mm0 \n\t"
  330. "movq (%1, %3), %%mm1 \n\t"
  331. "movq %%mm0, (%2) \n\t"
  332. "movq %%mm1, (%2, %3) \n\t"
  333. "add %%"REG_a", %1 \n\t"
  334. "add %%"REG_a", %2 \n\t"
  335. "subl $4, %0 \n\t"
  336. "jnz 1b \n\t"
  337. : "+g"(h), "+r" (pixels), "+r" (block)
  338. : "r"((x86_reg)line_size)
  339. : "%"REG_a, "memory"
  340. );
  341. }
  342. static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  343. {
  344. __asm__ volatile(
  345. "lea (%3, %3), %%"REG_a" \n\t"
  346. ASMALIGN(3)
  347. "1: \n\t"
  348. "movq (%1), %%mm0 \n\t"
  349. "movq 8(%1), %%mm4 \n\t"
  350. "movq (%1, %3), %%mm1 \n\t"
  351. "movq 8(%1, %3), %%mm5 \n\t"
  352. "movq %%mm0, (%2) \n\t"
  353. "movq %%mm4, 8(%2) \n\t"
  354. "movq %%mm1, (%2, %3) \n\t"
  355. "movq %%mm5, 8(%2, %3) \n\t"
  356. "add %%"REG_a", %1 \n\t"
  357. "add %%"REG_a", %2 \n\t"
  358. "movq (%1), %%mm0 \n\t"
  359. "movq 8(%1), %%mm4 \n\t"
  360. "movq (%1, %3), %%mm1 \n\t"
  361. "movq 8(%1, %3), %%mm5 \n\t"
  362. "movq %%mm0, (%2) \n\t"
  363. "movq %%mm4, 8(%2) \n\t"
  364. "movq %%mm1, (%2, %3) \n\t"
  365. "movq %%mm5, 8(%2, %3) \n\t"
  366. "add %%"REG_a", %1 \n\t"
  367. "add %%"REG_a", %2 \n\t"
  368. "subl $4, %0 \n\t"
  369. "jnz 1b \n\t"
  370. : "+g"(h), "+r" (pixels), "+r" (block)
  371. : "r"((x86_reg)line_size)
  372. : "%"REG_a, "memory"
  373. );
  374. }
  375. static void put_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  376. {
  377. __asm__ volatile(
  378. "1: \n\t"
  379. "movdqu (%1), %%xmm0 \n\t"
  380. "movdqu (%1,%3), %%xmm1 \n\t"
  381. "movdqu (%1,%3,2), %%xmm2 \n\t"
  382. "movdqu (%1,%4), %%xmm3 \n\t"
  383. "movdqa %%xmm0, (%2) \n\t"
  384. "movdqa %%xmm1, (%2,%3) \n\t"
  385. "movdqa %%xmm2, (%2,%3,2) \n\t"
  386. "movdqa %%xmm3, (%2,%4) \n\t"
  387. "subl $4, %0 \n\t"
  388. "lea (%1,%3,4), %1 \n\t"
  389. "lea (%2,%3,4), %2 \n\t"
  390. "jnz 1b \n\t"
  391. : "+g"(h), "+r" (pixels), "+r" (block)
  392. : "r"((x86_reg)line_size), "r"((x86_reg)3L*line_size)
  393. : "memory"
  394. );
  395. }
  396. static void avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  397. {
  398. __asm__ volatile(
  399. "1: \n\t"
  400. "movdqu (%1), %%xmm0 \n\t"
  401. "movdqu (%1,%3), %%xmm1 \n\t"
  402. "movdqu (%1,%3,2), %%xmm2 \n\t"
  403. "movdqu (%1,%4), %%xmm3 \n\t"
  404. "pavgb (%2), %%xmm0 \n\t"
  405. "pavgb (%2,%3), %%xmm1 \n\t"
  406. "pavgb (%2,%3,2), %%xmm2 \n\t"
  407. "pavgb (%2,%4), %%xmm3 \n\t"
  408. "movdqa %%xmm0, (%2) \n\t"
  409. "movdqa %%xmm1, (%2,%3) \n\t"
  410. "movdqa %%xmm2, (%2,%3,2) \n\t"
  411. "movdqa %%xmm3, (%2,%4) \n\t"
  412. "subl $4, %0 \n\t"
  413. "lea (%1,%3,4), %1 \n\t"
  414. "lea (%2,%3,4), %2 \n\t"
  415. "jnz 1b \n\t"
  416. : "+g"(h), "+r" (pixels), "+r" (block)
  417. : "r"((x86_reg)line_size), "r"((x86_reg)3L*line_size)
  418. : "memory"
  419. );
  420. }
  421. #define CLEAR_BLOCKS(name,n) \
  422. static void name(DCTELEM *blocks)\
  423. {\
  424. __asm__ volatile(\
  425. "pxor %%mm7, %%mm7 \n\t"\
  426. "mov %1, %%"REG_a" \n\t"\
  427. "1: \n\t"\
  428. "movq %%mm7, (%0, %%"REG_a") \n\t"\
  429. "movq %%mm7, 8(%0, %%"REG_a") \n\t"\
  430. "movq %%mm7, 16(%0, %%"REG_a") \n\t"\
  431. "movq %%mm7, 24(%0, %%"REG_a") \n\t"\
  432. "add $32, %%"REG_a" \n\t"\
  433. " js 1b \n\t"\
  434. : : "r" (((uint8_t *)blocks)+128*n),\
  435. "i" (-128*n)\
  436. : "%"REG_a\
  437. );\
  438. }
  439. CLEAR_BLOCKS(clear_blocks_mmx, 6)
  440. CLEAR_BLOCKS(clear_block_mmx, 1)
  441. static void clear_block_sse(DCTELEM *block)
  442. {
  443. __asm__ volatile(
  444. "xorps %%xmm0, %%xmm0 \n"
  445. "movaps %%xmm0, (%0) \n"
  446. "movaps %%xmm0, 16(%0) \n"
  447. "movaps %%xmm0, 32(%0) \n"
  448. "movaps %%xmm0, 48(%0) \n"
  449. "movaps %%xmm0, 64(%0) \n"
  450. "movaps %%xmm0, 80(%0) \n"
  451. "movaps %%xmm0, 96(%0) \n"
  452. "movaps %%xmm0, 112(%0) \n"
  453. :: "r"(block)
  454. : "memory"
  455. );
  456. }
  457. static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){
  458. x86_reg i=0;
  459. __asm__ volatile(
  460. "jmp 2f \n\t"
  461. "1: \n\t"
  462. "movq (%1, %0), %%mm0 \n\t"
  463. "movq (%2, %0), %%mm1 \n\t"
  464. "paddb %%mm0, %%mm1 \n\t"
  465. "movq %%mm1, (%2, %0) \n\t"
  466. "movq 8(%1, %0), %%mm0 \n\t"
  467. "movq 8(%2, %0), %%mm1 \n\t"
  468. "paddb %%mm0, %%mm1 \n\t"
  469. "movq %%mm1, 8(%2, %0) \n\t"
  470. "add $16, %0 \n\t"
  471. "2: \n\t"
  472. "cmp %3, %0 \n\t"
  473. " js 1b \n\t"
  474. : "+r" (i)
  475. : "r"(src), "r"(dst), "r"((x86_reg)w-15)
  476. );
  477. for(; i<w; i++)
  478. dst[i+0] += src[i+0];
  479. }
  480. static void add_bytes_l2_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
  481. x86_reg i=0;
  482. __asm__ volatile(
  483. "jmp 2f \n\t"
  484. "1: \n\t"
  485. "movq (%2, %0), %%mm0 \n\t"
  486. "movq 8(%2, %0), %%mm1 \n\t"
  487. "paddb (%3, %0), %%mm0 \n\t"
  488. "paddb 8(%3, %0), %%mm1 \n\t"
  489. "movq %%mm0, (%1, %0) \n\t"
  490. "movq %%mm1, 8(%1, %0) \n\t"
  491. "add $16, %0 \n\t"
  492. "2: \n\t"
  493. "cmp %4, %0 \n\t"
  494. " js 1b \n\t"
  495. : "+r" (i)
  496. : "r"(dst), "r"(src1), "r"(src2), "r"((x86_reg)w-15)
  497. );
  498. for(; i<w; i++)
  499. dst[i] = src1[i] + src2[i];
  500. }
  501. #if HAVE_7REGS && HAVE_TEN_OPERANDS
  502. static void add_hfyu_median_prediction_cmov(uint8_t *dst, uint8_t *top, uint8_t *diff, int w, int *left, int *left_top) {
  503. x86_reg w2 = -w;
  504. x86_reg x;
  505. int l = *left & 0xff;
  506. int tl = *left_top & 0xff;
  507. int t;
  508. __asm__ volatile(
  509. "mov %7, %3 \n"
  510. "1: \n"
  511. "movzx (%3,%4), %2 \n"
  512. "mov %2, %k3 \n"
  513. "sub %b1, %b3 \n"
  514. "add %b0, %b3 \n"
  515. "mov %2, %1 \n"
  516. "cmp %0, %2 \n"
  517. "cmovg %0, %2 \n"
  518. "cmovg %1, %0 \n"
  519. "cmp %k3, %0 \n"
  520. "cmovg %k3, %0 \n"
  521. "mov %7, %3 \n"
  522. "cmp %2, %0 \n"
  523. "cmovl %2, %0 \n"
  524. "add (%6,%4), %b0 \n"
  525. "mov %b0, (%5,%4) \n"
  526. "inc %4 \n"
  527. "jl 1b \n"
  528. :"+&q"(l), "+&q"(tl), "=&r"(t), "=&q"(x), "+&r"(w2)
  529. :"r"(dst+w), "r"(diff+w), "rm"(top+w)
  530. );
  531. *left = l;
  532. *left_top = tl;
  533. }
  534. #endif
  535. #define H263_LOOP_FILTER \
  536. "pxor %%mm7, %%mm7 \n\t"\
  537. "movq %0, %%mm0 \n\t"\
  538. "movq %0, %%mm1 \n\t"\
  539. "movq %3, %%mm2 \n\t"\
  540. "movq %3, %%mm3 \n\t"\
  541. "punpcklbw %%mm7, %%mm0 \n\t"\
  542. "punpckhbw %%mm7, %%mm1 \n\t"\
  543. "punpcklbw %%mm7, %%mm2 \n\t"\
  544. "punpckhbw %%mm7, %%mm3 \n\t"\
  545. "psubw %%mm2, %%mm0 \n\t"\
  546. "psubw %%mm3, %%mm1 \n\t"\
  547. "movq %1, %%mm2 \n\t"\
  548. "movq %1, %%mm3 \n\t"\
  549. "movq %2, %%mm4 \n\t"\
  550. "movq %2, %%mm5 \n\t"\
  551. "punpcklbw %%mm7, %%mm2 \n\t"\
  552. "punpckhbw %%mm7, %%mm3 \n\t"\
  553. "punpcklbw %%mm7, %%mm4 \n\t"\
  554. "punpckhbw %%mm7, %%mm5 \n\t"\
  555. "psubw %%mm2, %%mm4 \n\t"\
  556. "psubw %%mm3, %%mm5 \n\t"\
  557. "psllw $2, %%mm4 \n\t"\
  558. "psllw $2, %%mm5 \n\t"\
  559. "paddw %%mm0, %%mm4 \n\t"\
  560. "paddw %%mm1, %%mm5 \n\t"\
  561. "pxor %%mm6, %%mm6 \n\t"\
  562. "pcmpgtw %%mm4, %%mm6 \n\t"\
  563. "pcmpgtw %%mm5, %%mm7 \n\t"\
  564. "pxor %%mm6, %%mm4 \n\t"\
  565. "pxor %%mm7, %%mm5 \n\t"\
  566. "psubw %%mm6, %%mm4 \n\t"\
  567. "psubw %%mm7, %%mm5 \n\t"\
  568. "psrlw $3, %%mm4 \n\t"\
  569. "psrlw $3, %%mm5 \n\t"\
  570. "packuswb %%mm5, %%mm4 \n\t"\
  571. "packsswb %%mm7, %%mm6 \n\t"\
  572. "pxor %%mm7, %%mm7 \n\t"\
  573. "movd %4, %%mm2 \n\t"\
  574. "punpcklbw %%mm2, %%mm2 \n\t"\
  575. "punpcklbw %%mm2, %%mm2 \n\t"\
  576. "punpcklbw %%mm2, %%mm2 \n\t"\
  577. "psubusb %%mm4, %%mm2 \n\t"\
  578. "movq %%mm2, %%mm3 \n\t"\
  579. "psubusb %%mm4, %%mm3 \n\t"\
  580. "psubb %%mm3, %%mm2 \n\t"\
  581. "movq %1, %%mm3 \n\t"\
  582. "movq %2, %%mm4 \n\t"\
  583. "pxor %%mm6, %%mm3 \n\t"\
  584. "pxor %%mm6, %%mm4 \n\t"\
  585. "paddusb %%mm2, %%mm3 \n\t"\
  586. "psubusb %%mm2, %%mm4 \n\t"\
  587. "pxor %%mm6, %%mm3 \n\t"\
  588. "pxor %%mm6, %%mm4 \n\t"\
  589. "paddusb %%mm2, %%mm2 \n\t"\
  590. "packsswb %%mm1, %%mm0 \n\t"\
  591. "pcmpgtb %%mm0, %%mm7 \n\t"\
  592. "pxor %%mm7, %%mm0 \n\t"\
  593. "psubb %%mm7, %%mm0 \n\t"\
  594. "movq %%mm0, %%mm1 \n\t"\
  595. "psubusb %%mm2, %%mm0 \n\t"\
  596. "psubb %%mm0, %%mm1 \n\t"\
  597. "pand %5, %%mm1 \n\t"\
  598. "psrlw $2, %%mm1 \n\t"\
  599. "pxor %%mm7, %%mm1 \n\t"\
  600. "psubb %%mm7, %%mm1 \n\t"\
  601. "movq %0, %%mm5 \n\t"\
  602. "movq %3, %%mm6 \n\t"\
  603. "psubb %%mm1, %%mm5 \n\t"\
  604. "paddb %%mm1, %%mm6 \n\t"
  605. static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale){
  606. if(CONFIG_ANY_H263) {
  607. const int strength= ff_h263_loop_filter_strength[qscale];
  608. __asm__ volatile(
  609. H263_LOOP_FILTER
  610. "movq %%mm3, %1 \n\t"
  611. "movq %%mm4, %2 \n\t"
  612. "movq %%mm5, %0 \n\t"
  613. "movq %%mm6, %3 \n\t"
  614. : "+m" (*(uint64_t*)(src - 2*stride)),
  615. "+m" (*(uint64_t*)(src - 1*stride)),
  616. "+m" (*(uint64_t*)(src + 0*stride)),
  617. "+m" (*(uint64_t*)(src + 1*stride))
  618. : "g" (2*strength), "m"(ff_pb_FC)
  619. );
  620. }
  621. }
  622. static inline void transpose4x4(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride){
  623. __asm__ volatile( //FIXME could save 1 instruction if done as 8x4 ...
  624. "movd %4, %%mm0 \n\t"
  625. "movd %5, %%mm1 \n\t"
  626. "movd %6, %%mm2 \n\t"
  627. "movd %7, %%mm3 \n\t"
  628. "punpcklbw %%mm1, %%mm0 \n\t"
  629. "punpcklbw %%mm3, %%mm2 \n\t"
  630. "movq %%mm0, %%mm1 \n\t"
  631. "punpcklwd %%mm2, %%mm0 \n\t"
  632. "punpckhwd %%mm2, %%mm1 \n\t"
  633. "movd %%mm0, %0 \n\t"
  634. "punpckhdq %%mm0, %%mm0 \n\t"
  635. "movd %%mm0, %1 \n\t"
  636. "movd %%mm1, %2 \n\t"
  637. "punpckhdq %%mm1, %%mm1 \n\t"
  638. "movd %%mm1, %3 \n\t"
  639. : "=m" (*(uint32_t*)(dst + 0*dst_stride)),
  640. "=m" (*(uint32_t*)(dst + 1*dst_stride)),
  641. "=m" (*(uint32_t*)(dst + 2*dst_stride)),
  642. "=m" (*(uint32_t*)(dst + 3*dst_stride))
  643. : "m" (*(uint32_t*)(src + 0*src_stride)),
  644. "m" (*(uint32_t*)(src + 1*src_stride)),
  645. "m" (*(uint32_t*)(src + 2*src_stride)),
  646. "m" (*(uint32_t*)(src + 3*src_stride))
  647. );
  648. }
  649. static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){
  650. if(CONFIG_ANY_H263) {
  651. const int strength= ff_h263_loop_filter_strength[qscale];
  652. DECLARE_ALIGNED(8, uint64_t, temp[4]);
  653. uint8_t *btemp= (uint8_t*)temp;
  654. src -= 2;
  655. transpose4x4(btemp , src , 8, stride);
  656. transpose4x4(btemp+4, src + 4*stride, 8, stride);
  657. __asm__ volatile(
  658. H263_LOOP_FILTER // 5 3 4 6
  659. : "+m" (temp[0]),
  660. "+m" (temp[1]),
  661. "+m" (temp[2]),
  662. "+m" (temp[3])
  663. : "g" (2*strength), "m"(ff_pb_FC)
  664. );
  665. __asm__ volatile(
  666. "movq %%mm5, %%mm1 \n\t"
  667. "movq %%mm4, %%mm0 \n\t"
  668. "punpcklbw %%mm3, %%mm5 \n\t"
  669. "punpcklbw %%mm6, %%mm4 \n\t"
  670. "punpckhbw %%mm3, %%mm1 \n\t"
  671. "punpckhbw %%mm6, %%mm0 \n\t"
  672. "movq %%mm5, %%mm3 \n\t"
  673. "movq %%mm1, %%mm6 \n\t"
  674. "punpcklwd %%mm4, %%mm5 \n\t"
  675. "punpcklwd %%mm0, %%mm1 \n\t"
  676. "punpckhwd %%mm4, %%mm3 \n\t"
  677. "punpckhwd %%mm0, %%mm6 \n\t"
  678. "movd %%mm5, (%0) \n\t"
  679. "punpckhdq %%mm5, %%mm5 \n\t"
  680. "movd %%mm5, (%0,%2) \n\t"
  681. "movd %%mm3, (%0,%2,2) \n\t"
  682. "punpckhdq %%mm3, %%mm3 \n\t"
  683. "movd %%mm3, (%0,%3) \n\t"
  684. "movd %%mm1, (%1) \n\t"
  685. "punpckhdq %%mm1, %%mm1 \n\t"
  686. "movd %%mm1, (%1,%2) \n\t"
  687. "movd %%mm6, (%1,%2,2) \n\t"
  688. "punpckhdq %%mm6, %%mm6 \n\t"
  689. "movd %%mm6, (%1,%3) \n\t"
  690. :: "r" (src),
  691. "r" (src + 4*stride),
  692. "r" ((x86_reg) stride ),
  693. "r" ((x86_reg)(3*stride))
  694. );
  695. }
  696. }
  697. /* draw the edges of width 'w' of an image of size width, height
  698. this mmx version can only handle w==8 || w==16 */
  699. static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, int w)
  700. {
  701. uint8_t *ptr, *last_line;
  702. int i;
  703. last_line = buf + (height - 1) * wrap;
  704. /* left and right */
  705. ptr = buf;
  706. if(w==8)
  707. {
  708. __asm__ volatile(
  709. "1: \n\t"
  710. "movd (%0), %%mm0 \n\t"
  711. "punpcklbw %%mm0, %%mm0 \n\t"
  712. "punpcklwd %%mm0, %%mm0 \n\t"
  713. "punpckldq %%mm0, %%mm0 \n\t"
  714. "movq %%mm0, -8(%0) \n\t"
  715. "movq -8(%0, %2), %%mm1 \n\t"
  716. "punpckhbw %%mm1, %%mm1 \n\t"
  717. "punpckhwd %%mm1, %%mm1 \n\t"
  718. "punpckhdq %%mm1, %%mm1 \n\t"
  719. "movq %%mm1, (%0, %2) \n\t"
  720. "add %1, %0 \n\t"
  721. "cmp %3, %0 \n\t"
  722. " jb 1b \n\t"
  723. : "+r" (ptr)
  724. : "r" ((x86_reg)wrap), "r" ((x86_reg)width), "r" (ptr + wrap*height)
  725. );
  726. }
  727. else
  728. {
  729. __asm__ volatile(
  730. "1: \n\t"
  731. "movd (%0), %%mm0 \n\t"
  732. "punpcklbw %%mm0, %%mm0 \n\t"
  733. "punpcklwd %%mm0, %%mm0 \n\t"
  734. "punpckldq %%mm0, %%mm0 \n\t"
  735. "movq %%mm0, -8(%0) \n\t"
  736. "movq %%mm0, -16(%0) \n\t"
  737. "movq -8(%0, %2), %%mm1 \n\t"
  738. "punpckhbw %%mm1, %%mm1 \n\t"
  739. "punpckhwd %%mm1, %%mm1 \n\t"
  740. "punpckhdq %%mm1, %%mm1 \n\t"
  741. "movq %%mm1, (%0, %2) \n\t"
  742. "movq %%mm1, 8(%0, %2) \n\t"
  743. "add %1, %0 \n\t"
  744. "cmp %3, %0 \n\t"
  745. " jb 1b \n\t"
  746. : "+r" (ptr)
  747. : "r" ((x86_reg)wrap), "r" ((x86_reg)width), "r" (ptr + wrap*height)
  748. );
  749. }
  750. for(i=0;i<w;i+=4) {
  751. /* top and bottom (and hopefully also the corners) */
  752. ptr= buf - (i + 1) * wrap - w;
  753. __asm__ volatile(
  754. "1: \n\t"
  755. "movq (%1, %0), %%mm0 \n\t"
  756. "movq %%mm0, (%0) \n\t"
  757. "movq %%mm0, (%0, %2) \n\t"
  758. "movq %%mm0, (%0, %2, 2) \n\t"
  759. "movq %%mm0, (%0, %3) \n\t"
  760. "add $8, %0 \n\t"
  761. "cmp %4, %0 \n\t"
  762. " jb 1b \n\t"
  763. : "+r" (ptr)
  764. : "r" ((x86_reg)buf - (x86_reg)ptr - w), "r" ((x86_reg)-wrap), "r" ((x86_reg)-wrap*3), "r" (ptr+width+2*w)
  765. );
  766. ptr= last_line + (i + 1) * wrap - w;
  767. __asm__ volatile(
  768. "1: \n\t"
  769. "movq (%1, %0), %%mm0 \n\t"
  770. "movq %%mm0, (%0) \n\t"
  771. "movq %%mm0, (%0, %2) \n\t"
  772. "movq %%mm0, (%0, %2, 2) \n\t"
  773. "movq %%mm0, (%0, %3) \n\t"
  774. "add $8, %0 \n\t"
  775. "cmp %4, %0 \n\t"
  776. " jb 1b \n\t"
  777. : "+r" (ptr)
  778. : "r" ((x86_reg)last_line - (x86_reg)ptr - w), "r" ((x86_reg)wrap), "r" ((x86_reg)wrap*3), "r" (ptr+width+2*w)
  779. );
  780. }
  781. }
  782. #define PAETH(cpu, abs3)\
  783. static void add_png_paeth_prediction_##cpu(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)\
  784. {\
  785. x86_reg i = -bpp;\
  786. x86_reg end = w-3;\
  787. __asm__ volatile(\
  788. "pxor %%mm7, %%mm7 \n"\
  789. "movd (%1,%0), %%mm0 \n"\
  790. "movd (%2,%0), %%mm1 \n"\
  791. "punpcklbw %%mm7, %%mm0 \n"\
  792. "punpcklbw %%mm7, %%mm1 \n"\
  793. "add %4, %0 \n"\
  794. "1: \n"\
  795. "movq %%mm1, %%mm2 \n"\
  796. "movd (%2,%0), %%mm1 \n"\
  797. "movq %%mm2, %%mm3 \n"\
  798. "punpcklbw %%mm7, %%mm1 \n"\
  799. "movq %%mm2, %%mm4 \n"\
  800. "psubw %%mm1, %%mm3 \n"\
  801. "psubw %%mm0, %%mm4 \n"\
  802. "movq %%mm3, %%mm5 \n"\
  803. "paddw %%mm4, %%mm5 \n"\
  804. abs3\
  805. "movq %%mm4, %%mm6 \n"\
  806. "pminsw %%mm5, %%mm6 \n"\
  807. "pcmpgtw %%mm6, %%mm3 \n"\
  808. "pcmpgtw %%mm5, %%mm4 \n"\
  809. "movq %%mm4, %%mm6 \n"\
  810. "pand %%mm3, %%mm4 \n"\
  811. "pandn %%mm3, %%mm6 \n"\
  812. "pandn %%mm0, %%mm3 \n"\
  813. "movd (%3,%0), %%mm0 \n"\
  814. "pand %%mm1, %%mm6 \n"\
  815. "pand %%mm4, %%mm2 \n"\
  816. "punpcklbw %%mm7, %%mm0 \n"\
  817. "movq %6, %%mm5 \n"\
  818. "paddw %%mm6, %%mm0 \n"\
  819. "paddw %%mm2, %%mm3 \n"\
  820. "paddw %%mm3, %%mm0 \n"\
  821. "pand %%mm5, %%mm0 \n"\
  822. "movq %%mm0, %%mm3 \n"\
  823. "packuswb %%mm3, %%mm3 \n"\
  824. "movd %%mm3, (%1,%0) \n"\
  825. "add %4, %0 \n"\
  826. "cmp %5, %0 \n"\
  827. "jle 1b \n"\
  828. :"+r"(i)\
  829. :"r"(dst), "r"(top), "r"(src), "r"((x86_reg)bpp), "g"(end),\
  830. "m"(ff_pw_255)\
  831. :"memory"\
  832. );\
  833. }
  834. #define ABS3_MMX2\
  835. "psubw %%mm5, %%mm7 \n"\
  836. "pmaxsw %%mm7, %%mm5 \n"\
  837. "pxor %%mm6, %%mm6 \n"\
  838. "pxor %%mm7, %%mm7 \n"\
  839. "psubw %%mm3, %%mm6 \n"\
  840. "psubw %%mm4, %%mm7 \n"\
  841. "pmaxsw %%mm6, %%mm3 \n"\
  842. "pmaxsw %%mm7, %%mm4 \n"\
  843. "pxor %%mm7, %%mm7 \n"
  844. #define ABS3_SSSE3\
  845. "pabsw %%mm3, %%mm3 \n"\
  846. "pabsw %%mm4, %%mm4 \n"\
  847. "pabsw %%mm5, %%mm5 \n"
  848. PAETH(mmx2, ABS3_MMX2)
  849. #if HAVE_SSSE3
  850. PAETH(ssse3, ABS3_SSSE3)
  851. #endif
  852. #define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
  853. "paddw " #m4 ", " #m3 " \n\t" /* x1 */\
  854. "movq "MANGLE(ff_pw_20)", %%mm4 \n\t" /* 20 */\
  855. "pmullw " #m3 ", %%mm4 \n\t" /* 20x1 */\
  856. "movq "#in7", " #m3 " \n\t" /* d */\
  857. "movq "#in0", %%mm5 \n\t" /* D */\
  858. "paddw " #m3 ", %%mm5 \n\t" /* x4 */\
  859. "psubw %%mm5, %%mm4 \n\t" /* 20x1 - x4 */\
  860. "movq "#in1", %%mm5 \n\t" /* C */\
  861. "movq "#in2", %%mm6 \n\t" /* B */\
  862. "paddw " #m6 ", %%mm5 \n\t" /* x3 */\
  863. "paddw " #m5 ", %%mm6 \n\t" /* x2 */\
  864. "paddw %%mm6, %%mm6 \n\t" /* 2x2 */\
  865. "psubw %%mm6, %%mm5 \n\t" /* -2x2 + x3 */\
  866. "pmullw "MANGLE(ff_pw_3)", %%mm5 \n\t" /* -6x2 + 3x3 */\
  867. "paddw " #rnd ", %%mm4 \n\t" /* x2 */\
  868. "paddw %%mm4, %%mm5 \n\t" /* 20x1 - 6x2 + 3x3 - x4 */\
  869. "psraw $5, %%mm5 \n\t"\
  870. "packuswb %%mm5, %%mm5 \n\t"\
  871. OP(%%mm5, out, %%mm7, d)
  872. #define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMX2, OP_3DNOW)\
  873. static void OPNAME ## mpeg4_qpel16_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  874. uint64_t temp;\
  875. \
  876. __asm__ volatile(\
  877. "pxor %%mm7, %%mm7 \n\t"\
  878. "1: \n\t"\
  879. "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
  880. "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
  881. "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
  882. "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
  883. "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
  884. "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
  885. "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
  886. "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
  887. "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
  888. "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
  889. "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
  890. "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
  891. "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
  892. "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
  893. "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
  894. "paddw %%mm3, %%mm5 \n\t" /* b */\
  895. "paddw %%mm2, %%mm6 \n\t" /* c */\
  896. "paddw %%mm5, %%mm5 \n\t" /* 2b */\
  897. "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
  898. "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
  899. "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
  900. "paddw %%mm4, %%mm0 \n\t" /* a */\
  901. "paddw %%mm1, %%mm5 \n\t" /* d */\
  902. "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
  903. "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
  904. "paddw %6, %%mm6 \n\t"\
  905. "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
  906. "psraw $5, %%mm0 \n\t"\
  907. "movq %%mm0, %5 \n\t"\
  908. /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
  909. \
  910. "movq 5(%0), %%mm0 \n\t" /* FGHIJKLM */\
  911. "movq %%mm0, %%mm5 \n\t" /* FGHIJKLM */\
  912. "movq %%mm0, %%mm6 \n\t" /* FGHIJKLM */\
  913. "psrlq $8, %%mm0 \n\t" /* GHIJKLM0 */\
  914. "psrlq $16, %%mm5 \n\t" /* HIJKLM00 */\
  915. "punpcklbw %%mm7, %%mm0 \n\t" /* 0G0H0I0J */\
  916. "punpcklbw %%mm7, %%mm5 \n\t" /* 0H0I0J0K */\
  917. "paddw %%mm0, %%mm2 \n\t" /* b */\
  918. "paddw %%mm5, %%mm3 \n\t" /* c */\
  919. "paddw %%mm2, %%mm2 \n\t" /* 2b */\
  920. "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
  921. "movq %%mm6, %%mm2 \n\t" /* FGHIJKLM */\
  922. "psrlq $24, %%mm6 \n\t" /* IJKLM000 */\
  923. "punpcklbw %%mm7, %%mm2 \n\t" /* 0F0G0H0I */\
  924. "punpcklbw %%mm7, %%mm6 \n\t" /* 0I0J0K0L */\
  925. "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
  926. "paddw %%mm2, %%mm1 \n\t" /* a */\
  927. "paddw %%mm6, %%mm4 \n\t" /* d */\
  928. "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
  929. "psubw %%mm4, %%mm3 \n\t" /* - 6b +3c - d */\
  930. "paddw %6, %%mm1 \n\t"\
  931. "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b +3c - d */\
  932. "psraw $5, %%mm3 \n\t"\
  933. "movq %5, %%mm1 \n\t"\
  934. "packuswb %%mm3, %%mm1 \n\t"\
  935. OP_MMX2(%%mm1, (%1),%%mm4, q)\
  936. /* mm0= GHIJ, mm2=FGHI, mm5=HIJK, mm6=IJKL, mm7=0 */\
  937. \
  938. "movq 9(%0), %%mm1 \n\t" /* JKLMNOPQ */\
  939. "movq %%mm1, %%mm4 \n\t" /* JKLMNOPQ */\
  940. "movq %%mm1, %%mm3 \n\t" /* JKLMNOPQ */\
  941. "psrlq $8, %%mm1 \n\t" /* KLMNOPQ0 */\
  942. "psrlq $16, %%mm4 \n\t" /* LMNOPQ00 */\
  943. "punpcklbw %%mm7, %%mm1 \n\t" /* 0K0L0M0N */\
  944. "punpcklbw %%mm7, %%mm4 \n\t" /* 0L0M0N0O */\
  945. "paddw %%mm1, %%mm5 \n\t" /* b */\
  946. "paddw %%mm4, %%mm0 \n\t" /* c */\
  947. "paddw %%mm5, %%mm5 \n\t" /* 2b */\
  948. "psubw %%mm5, %%mm0 \n\t" /* c - 2b */\
  949. "movq %%mm3, %%mm5 \n\t" /* JKLMNOPQ */\
  950. "psrlq $24, %%mm3 \n\t" /* MNOPQ000 */\
  951. "pmullw "MANGLE(ff_pw_3)", %%mm0 \n\t" /* 3c - 6b */\
  952. "punpcklbw %%mm7, %%mm3 \n\t" /* 0M0N0O0P */\
  953. "paddw %%mm3, %%mm2 \n\t" /* d */\
  954. "psubw %%mm2, %%mm0 \n\t" /* -6b + 3c - d */\
  955. "movq %%mm5, %%mm2 \n\t" /* JKLMNOPQ */\
  956. "punpcklbw %%mm7, %%mm2 \n\t" /* 0J0K0L0M */\
  957. "punpckhbw %%mm7, %%mm5 \n\t" /* 0N0O0P0Q */\
  958. "paddw %%mm2, %%mm6 \n\t" /* a */\
  959. "pmullw "MANGLE(ff_pw_20)", %%mm6 \n\t" /* 20a */\
  960. "paddw %6, %%mm0 \n\t"\
  961. "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
  962. "psraw $5, %%mm0 \n\t"\
  963. /* mm1=KLMN, mm2=JKLM, mm3=MNOP, mm4=LMNO, mm5=NOPQ mm7=0 */\
  964. \
  965. "paddw %%mm5, %%mm3 \n\t" /* a */\
  966. "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0O0P0Q0Q */\
  967. "paddw %%mm4, %%mm6 \n\t" /* b */\
  968. "pshufw $0xBE, %%mm5, %%mm4 \n\t" /* 0P0Q0Q0P */\
  969. "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0Q0Q0P0O */\
  970. "paddw %%mm1, %%mm4 \n\t" /* c */\
  971. "paddw %%mm2, %%mm5 \n\t" /* d */\
  972. "paddw %%mm6, %%mm6 \n\t" /* 2b */\
  973. "psubw %%mm6, %%mm4 \n\t" /* c - 2b */\
  974. "pmullw "MANGLE(ff_pw_20)", %%mm3 \n\t" /* 20a */\
  975. "pmullw "MANGLE(ff_pw_3)", %%mm4 \n\t" /* 3c - 6b */\
  976. "psubw %%mm5, %%mm3 \n\t" /* -6b + 3c - d */\
  977. "paddw %6, %%mm4 \n\t"\
  978. "paddw %%mm3, %%mm4 \n\t" /* 20a - 6b + 3c - d */\
  979. "psraw $5, %%mm4 \n\t"\
  980. "packuswb %%mm4, %%mm0 \n\t"\
  981. OP_MMX2(%%mm0, 8(%1), %%mm4, q)\
  982. \
  983. "add %3, %0 \n\t"\
  984. "add %4, %1 \n\t"\
  985. "decl %2 \n\t"\
  986. " jnz 1b \n\t"\
  987. : "+a"(src), "+c"(dst), "+D"(h)\
  988. : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
  989. : "memory"\
  990. );\
  991. }\
  992. \
  993. static void OPNAME ## mpeg4_qpel16_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  994. int i;\
  995. int16_t temp[16];\
  996. /* quick HACK, XXX FIXME MUST be optimized */\
  997. for(i=0; i<h; i++)\
  998. {\
  999. temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
  1000. temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
  1001. temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
  1002. temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
  1003. temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
  1004. temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]);\
  1005. temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]);\
  1006. temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]);\
  1007. temp[ 8]= (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]);\
  1008. temp[ 9]= (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]);\
  1009. temp[10]= (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]);\
  1010. temp[11]= (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]);\
  1011. temp[12]= (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]);\
  1012. temp[13]= (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]);\
  1013. temp[14]= (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]);\
  1014. temp[15]= (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]);\
  1015. __asm__ volatile(\
  1016. "movq (%0), %%mm0 \n\t"\
  1017. "movq 8(%0), %%mm1 \n\t"\
  1018. "paddw %2, %%mm0 \n\t"\
  1019. "paddw %2, %%mm1 \n\t"\
  1020. "psraw $5, %%mm0 \n\t"\
  1021. "psraw $5, %%mm1 \n\t"\
  1022. "packuswb %%mm1, %%mm0 \n\t"\
  1023. OP_3DNOW(%%mm0, (%1), %%mm1, q)\
  1024. "movq 16(%0), %%mm0 \n\t"\
  1025. "movq 24(%0), %%mm1 \n\t"\
  1026. "paddw %2, %%mm0 \n\t"\
  1027. "paddw %2, %%mm1 \n\t"\
  1028. "psraw $5, %%mm0 \n\t"\
  1029. "psraw $5, %%mm1 \n\t"\
  1030. "packuswb %%mm1, %%mm0 \n\t"\
  1031. OP_3DNOW(%%mm0, 8(%1), %%mm1, q)\
  1032. :: "r"(temp), "r"(dst), "m"(ROUNDER)\
  1033. : "memory"\
  1034. );\
  1035. dst+=dstStride;\
  1036. src+=srcStride;\
  1037. }\
  1038. }\
  1039. \
  1040. static void OPNAME ## mpeg4_qpel8_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  1041. __asm__ volatile(\
  1042. "pxor %%mm7, %%mm7 \n\t"\
  1043. "1: \n\t"\
  1044. "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
  1045. "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
  1046. "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
  1047. "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
  1048. "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
  1049. "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
  1050. "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
  1051. "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
  1052. "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
  1053. "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
  1054. "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
  1055. "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
  1056. "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
  1057. "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
  1058. "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
  1059. "paddw %%mm3, %%mm5 \n\t" /* b */\
  1060. "paddw %%mm2, %%mm6 \n\t" /* c */\
  1061. "paddw %%mm5, %%mm5 \n\t" /* 2b */\
  1062. "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
  1063. "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
  1064. "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
  1065. "paddw %%mm4, %%mm0 \n\t" /* a */\
  1066. "paddw %%mm1, %%mm5 \n\t" /* d */\
  1067. "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
  1068. "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
  1069. "paddw %5, %%mm6 \n\t"\
  1070. "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
  1071. "psraw $5, %%mm0 \n\t"\
  1072. /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
  1073. \
  1074. "movd 5(%0), %%mm5 \n\t" /* FGHI */\
  1075. "punpcklbw %%mm7, %%mm5 \n\t" /* 0F0G0H0I */\
  1076. "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0G0H0I0I */\
  1077. "paddw %%mm5, %%mm1 \n\t" /* a */\
  1078. "paddw %%mm6, %%mm2 \n\t" /* b */\
  1079. "pshufw $0xBE, %%mm5, %%mm6 \n\t" /* 0H0I0I0H */\
  1080. "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0I0I0H0G */\
  1081. "paddw %%mm6, %%mm3 \n\t" /* c */\
  1082. "paddw %%mm5, %%mm4 \n\t" /* d */\
  1083. "paddw %%mm2, %%mm2 \n\t" /* 2b */\
  1084. "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
  1085. "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
  1086. "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
  1087. "psubw %%mm4, %%mm3 \n\t" /* -6b + 3c - d */\
  1088. "paddw %5, %%mm1 \n\t"\
  1089. "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b + 3c - d */\
  1090. "psraw $5, %%mm3 \n\t"\
  1091. "packuswb %%mm3, %%mm0 \n\t"\
  1092. OP_MMX2(%%mm0, (%1), %%mm4, q)\
  1093. \
  1094. "add %3, %0 \n\t"\
  1095. "add %4, %1 \n\t"\
  1096. "decl %2 \n\t"\
  1097. " jnz 1b \n\t"\
  1098. : "+a"(src), "+c"(dst), "+d"(h)\
  1099. : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER)\
  1100. : "memory"\
  1101. );\
  1102. }\
  1103. \
  1104. static void OPNAME ## mpeg4_qpel8_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  1105. int i;\
  1106. int16_t temp[8];\
  1107. /* quick HACK, XXX FIXME MUST be optimized */\
  1108. for(i=0; i<h; i++)\
  1109. {\
  1110. temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
  1111. temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
  1112. temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
  1113. temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
  1114. temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
  1115. temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 8]);\
  1116. temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 8])*3 - (src[ 3]+src[ 7]);\
  1117. temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 8])*6 + (src[ 5]+src[ 7])*3 - (src[ 4]+src[ 6]);\
  1118. __asm__ volatile(\
  1119. "movq (%0), %%mm0 \n\t"\
  1120. "movq 8(%0), %%mm1 \n\t"\
  1121. "paddw %2, %%mm0 \n\t"\
  1122. "paddw %2, %%mm1 \n\t"\
  1123. "psraw $5, %%mm0 \n\t"\
  1124. "psraw $5, %%mm1 \n\t"\
  1125. "packuswb %%mm1, %%mm0 \n\t"\
  1126. OP_3DNOW(%%mm0, (%1), %%mm1, q)\
  1127. :: "r"(temp), "r"(dst), "m"(ROUNDER)\
  1128. :"memory"\
  1129. );\
  1130. dst+=dstStride;\
  1131. src+=srcStride;\
  1132. }\
  1133. }
  1134. #define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX)\
  1135. \
  1136. static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1137. uint64_t temp[17*4];\
  1138. uint64_t *temp_ptr= temp;\
  1139. int count= 17;\
  1140. \
  1141. /*FIXME unroll */\
  1142. __asm__ volatile(\
  1143. "pxor %%mm7, %%mm7 \n\t"\
  1144. "1: \n\t"\
  1145. "movq (%0), %%mm0 \n\t"\
  1146. "movq (%0), %%mm1 \n\t"\
  1147. "movq 8(%0), %%mm2 \n\t"\
  1148. "movq 8(%0), %%mm3 \n\t"\
  1149. "punpcklbw %%mm7, %%mm0 \n\t"\
  1150. "punpckhbw %%mm7, %%mm1 \n\t"\
  1151. "punpcklbw %%mm7, %%mm2 \n\t"\
  1152. "punpckhbw %%mm7, %%mm3 \n\t"\
  1153. "movq %%mm0, (%1) \n\t"\
  1154. "movq %%mm1, 17*8(%1) \n\t"\
  1155. "movq %%mm2, 2*17*8(%1) \n\t"\
  1156. "movq %%mm3, 3*17*8(%1) \n\t"\
  1157. "add $8, %1 \n\t"\
  1158. "add %3, %0 \n\t"\
  1159. "decl %2 \n\t"\
  1160. " jnz 1b \n\t"\
  1161. : "+r" (src), "+r" (temp_ptr), "+r"(count)\
  1162. : "r" ((x86_reg)srcStride)\
  1163. : "memory"\
  1164. );\
  1165. \
  1166. temp_ptr= temp;\
  1167. count=4;\
  1168. \
  1169. /*FIXME reorder for speed */\
  1170. __asm__ volatile(\
  1171. /*"pxor %%mm7, %%mm7 \n\t"*/\
  1172. "1: \n\t"\
  1173. "movq (%0), %%mm0 \n\t"\
  1174. "movq 8(%0), %%mm1 \n\t"\
  1175. "movq 16(%0), %%mm2 \n\t"\
  1176. "movq 24(%0), %%mm3 \n\t"\
  1177. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
  1178. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
  1179. "add %4, %1 \n\t"\
  1180. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
  1181. \
  1182. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
  1183. "add %4, %1 \n\t"\
  1184. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
  1185. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 72(%0), (%1, %3), OP)\
  1186. "add %4, %1 \n\t"\
  1187. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 80(%0), (%1), OP)\
  1188. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 88(%0), (%1, %3), OP)\
  1189. "add %4, %1 \n\t"\
  1190. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0), 48(%0), 56(%0), 96(%0), (%1), OP)\
  1191. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0), 56(%0), 64(%0),104(%0), (%1, %3), OP)\
  1192. "add %4, %1 \n\t"\
  1193. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0), 64(%0), 72(%0),112(%0), (%1), OP)\
  1194. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0), 72(%0), 80(%0),120(%0), (%1, %3), OP)\
  1195. "add %4, %1 \n\t"\
  1196. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0), 80(%0), 88(%0),128(%0), (%1), OP)\
  1197. \
  1198. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0), 88(%0), 96(%0),128(%0), (%1, %3), OP)\
  1199. "add %4, %1 \n\t" \
  1200. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0), 96(%0),104(%0),120(%0), (%1), OP)\
  1201. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0),104(%0),112(%0),112(%0), (%1, %3), OP)\
  1202. \
  1203. "add $136, %0 \n\t"\
  1204. "add %6, %1 \n\t"\
  1205. "decl %2 \n\t"\
  1206. " jnz 1b \n\t"\
  1207. \
  1208. : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
  1209. : "r"((x86_reg)dstStride), "r"(2*(x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-14*(x86_reg)dstStride)\
  1210. :"memory"\
  1211. );\
  1212. }\
  1213. \
  1214. static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1215. uint64_t temp[9*2];\
  1216. uint64_t *temp_ptr= temp;\
  1217. int count= 9;\
  1218. \
  1219. /*FIXME unroll */\
  1220. __asm__ volatile(\
  1221. "pxor %%mm7, %%mm7 \n\t"\
  1222. "1: \n\t"\
  1223. "movq (%0), %%mm0 \n\t"\
  1224. "movq (%0), %%mm1 \n\t"\
  1225. "punpcklbw %%mm7, %%mm0 \n\t"\
  1226. "punpckhbw %%mm7, %%mm1 \n\t"\
  1227. "movq %%mm0, (%1) \n\t"\
  1228. "movq %%mm1, 9*8(%1) \n\t"\
  1229. "add $8, %1 \n\t"\
  1230. "add %3, %0 \n\t"\
  1231. "decl %2 \n\t"\
  1232. " jnz 1b \n\t"\
  1233. : "+r" (src), "+r" (temp_ptr), "+r"(count)\
  1234. : "r" ((x86_reg)srcStride)\
  1235. : "memory"\
  1236. );\
  1237. \
  1238. temp_ptr= temp;\
  1239. count=2;\
  1240. \
  1241. /*FIXME reorder for speed */\
  1242. __asm__ volatile(\
  1243. /*"pxor %%mm7, %%mm7 \n\t"*/\
  1244. "1: \n\t"\
  1245. "movq (%0), %%mm0 \n\t"\
  1246. "movq 8(%0), %%mm1 \n\t"\
  1247. "movq 16(%0), %%mm2 \n\t"\
  1248. "movq 24(%0), %%mm3 \n\t"\
  1249. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
  1250. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
  1251. "add %4, %1 \n\t"\
  1252. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
  1253. \
  1254. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
  1255. "add %4, %1 \n\t"\
  1256. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
  1257. \
  1258. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 64(%0), (%1, %3), OP)\
  1259. "add %4, %1 \n\t"\
  1260. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 56(%0), (%1), OP)\
  1261. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 48(%0), (%1, %3), OP)\
  1262. \
  1263. "add $72, %0 \n\t"\
  1264. "add %6, %1 \n\t"\
  1265. "decl %2 \n\t"\
  1266. " jnz 1b \n\t"\
  1267. \
  1268. : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
  1269. : "r"((x86_reg)dstStride), "r"(2*(x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-6*(x86_reg)dstStride)\
  1270. : "memory"\
  1271. );\
  1272. }\
  1273. \
  1274. static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
  1275. OPNAME ## pixels8_ ## MMX(dst, src, stride, 8);\
  1276. }\
  1277. \
  1278. static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1279. uint64_t temp[8];\
  1280. uint8_t * const half= (uint8_t*)temp;\
  1281. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
  1282. OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
  1283. }\
  1284. \
  1285. static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1286. OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, stride, 8);\
  1287. }\
  1288. \
  1289. static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1290. uint64_t temp[8];\
  1291. uint8_t * const half= (uint8_t*)temp;\
  1292. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
  1293. OPNAME ## pixels8_l2_ ## MMX(dst, src+1, half, stride, stride, 8);\
  1294. }\
  1295. \
  1296. static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1297. uint64_t temp[8];\
  1298. uint8_t * const half= (uint8_t*)temp;\
  1299. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
  1300. OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
  1301. }\
  1302. \
  1303. static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1304. OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, stride, stride);\
  1305. }\
  1306. \
  1307. static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1308. uint64_t temp[8];\
  1309. uint8_t * const half= (uint8_t*)temp;\
  1310. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
  1311. OPNAME ## pixels8_l2_ ## MMX(dst, src+stride, half, stride, stride, 8);\
  1312. }\
  1313. static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1314. uint64_t half[8 + 9];\
  1315. uint8_t * const halfH= ((uint8_t*)half) + 64;\
  1316. uint8_t * const halfHV= ((uint8_t*)half);\
  1317. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1318. put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
  1319. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  1320. OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
  1321. }\
  1322. static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1323. uint64_t half[8 + 9];\
  1324. uint8_t * const halfH= ((uint8_t*)half) + 64;\
  1325. uint8_t * const halfHV= ((uint8_t*)half);\
  1326. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1327. put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
  1328. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  1329. OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
  1330. }\
  1331. static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1332. uint64_t half[8 + 9];\
  1333. uint8_t * const halfH= ((uint8_t*)half) + 64;\
  1334. uint8_t * const halfHV= ((uint8_t*)half);\
  1335. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1336. put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
  1337. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  1338. OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
  1339. }\
  1340. static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1341. uint64_t half[8 + 9];\
  1342. uint8_t * const halfH= ((uint8_t*)half) + 64;\
  1343. uint8_t * const halfHV= ((uint8_t*)half);\
  1344. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1345. put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
  1346. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  1347. OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
  1348. }\
  1349. static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1350. uint64_t half[8 + 9];\
  1351. uint8_t * const halfH= ((uint8_t*)half) + 64;\
  1352. uint8_t * const halfHV= ((uint8_t*)half);\
  1353. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1354. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  1355. OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
  1356. }\
  1357. static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1358. uint64_t half[8 + 9];\
  1359. uint8_t * const halfH= ((uint8_t*)half) + 64;\
  1360. uint8_t * const halfHV= ((uint8_t*)half);\
  1361. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1362. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  1363. OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
  1364. }\
  1365. static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1366. uint64_t half[8 + 9];\
  1367. uint8_t * const halfH= ((uint8_t*)half);\
  1368. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1369. put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
  1370. OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
  1371. }\
  1372. static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1373. uint64_t half[8 + 9];\
  1374. uint8_t * const halfH= ((uint8_t*)half);\
  1375. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1376. put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
  1377. OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
  1378. }\
  1379. static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1380. uint64_t half[9];\
  1381. uint8_t * const halfH= ((uint8_t*)half);\
  1382. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1383. OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
  1384. }\
  1385. static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
  1386. OPNAME ## pixels16_ ## MMX(dst, src, stride, 16);\
  1387. }\
  1388. \
  1389. static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1390. uint64_t temp[32];\
  1391. uint8_t * const half= (uint8_t*)temp;\
  1392. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
  1393. OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
  1394. }\
  1395. \
  1396. static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1397. OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, stride, stride, 16);\
  1398. }\
  1399. \
  1400. static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1401. uint64_t temp[32];\
  1402. uint8_t * const half= (uint8_t*)temp;\
  1403. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
  1404. OPNAME ## pixels16_l2_ ## MMX(dst, src+1, half, stride, stride, 16);\
  1405. }\
  1406. \
  1407. static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1408. uint64_t temp[32];\
  1409. uint8_t * const half= (uint8_t*)temp;\
  1410. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
  1411. OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
  1412. }\
  1413. \
  1414. static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1415. OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, stride, stride);\
  1416. }\
  1417. \
  1418. static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1419. uint64_t temp[32];\
  1420. uint8_t * const half= (uint8_t*)temp;\
  1421. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
  1422. OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, stride, stride, 16);\
  1423. }\
  1424. static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1425. uint64_t half[16*2 + 17*2];\
  1426. uint8_t * const halfH= ((uint8_t*)half) + 256;\
  1427. uint8_t * const halfHV= ((uint8_t*)half);\
  1428. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1429. put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
  1430. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
  1431. OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
  1432. }\
  1433. static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1434. uint64_t half[16*2 + 17*2];\
  1435. uint8_t * const halfH= ((uint8_t*)half) + 256;\
  1436. uint8_t * const halfHV= ((uint8_t*)half);\
  1437. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1438. put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
  1439. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
  1440. OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
  1441. }\
  1442. static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1443. uint64_t half[16*2 + 17*2];\
  1444. uint8_t * const halfH= ((uint8_t*)half) + 256;\
  1445. uint8_t * const halfHV= ((uint8_t*)half);\
  1446. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1447. put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
  1448. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
  1449. OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
  1450. }\
  1451. static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1452. uint64_t half[16*2 + 17*2];\
  1453. uint8_t * const halfH= ((uint8_t*)half) + 256;\
  1454. uint8_t * const halfHV= ((uint8_t*)half);\
  1455. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1456. put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
  1457. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
  1458. OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
  1459. }\
  1460. static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1461. uint64_t half[16*2 + 17*2];\
  1462. uint8_t * const halfH= ((uint8_t*)half) + 256;\
  1463. uint8_t * const halfHV= ((uint8_t*)half);\
  1464. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1465. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
  1466. OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
  1467. }\
  1468. static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1469. uint64_t half[16*2 + 17*2];\
  1470. uint8_t * const halfH= ((uint8_t*)half) + 256;\
  1471. uint8_t * const halfHV= ((uint8_t*)half);\
  1472. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1473. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
  1474. OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
  1475. }\
  1476. static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1477. uint64_t half[17*2];\
  1478. uint8_t * const halfH= ((uint8_t*)half);\
  1479. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1480. put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
  1481. OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
  1482. }\
  1483. static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1484. uint64_t half[17*2];\
  1485. uint8_t * const halfH= ((uint8_t*)half);\
  1486. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1487. put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
  1488. OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
  1489. }\
  1490. static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1491. uint64_t half[17*2];\
  1492. uint8_t * const halfH= ((uint8_t*)half);\
  1493. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1494. OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
  1495. }
  1496. #define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b " \n\t"
  1497. #define AVG_3DNOW_OP(a,b,temp, size) \
  1498. "mov" #size " " #b ", " #temp " \n\t"\
  1499. "pavgusb " #temp ", " #a " \n\t"\
  1500. "mov" #size " " #a ", " #b " \n\t"
  1501. #define AVG_MMX2_OP(a,b,temp, size) \
  1502. "mov" #size " " #b ", " #temp " \n\t"\
  1503. "pavgb " #temp ", " #a " \n\t"\
  1504. "mov" #size " " #a ", " #b " \n\t"
  1505. QPEL_BASE(put_ , ff_pw_16, _ , PUT_OP, PUT_OP)
  1506. QPEL_BASE(avg_ , ff_pw_16, _ , AVG_MMX2_OP, AVG_3DNOW_OP)
  1507. QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, PUT_OP)
  1508. QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, 3dnow)
  1509. QPEL_OP(avg_ , ff_pw_16, _ , AVG_3DNOW_OP, 3dnow)
  1510. QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, 3dnow)
  1511. QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, mmx2)
  1512. QPEL_OP(avg_ , ff_pw_16, _ , AVG_MMX2_OP, mmx2)
  1513. QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, mmx2)
  1514. /***********************************/
  1515. /* bilinear qpel: not compliant to any spec, only for -lavdopts fast */
  1516. #define QPEL_2TAP_XY(OPNAME, SIZE, MMX, XY, HPEL)\
  1517. static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1518. OPNAME ## pixels ## SIZE ## HPEL(dst, src, stride, SIZE);\
  1519. }
  1520. #define QPEL_2TAP_L3(OPNAME, SIZE, MMX, XY, S0, S1, S2)\
  1521. static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1522. OPNAME ## 2tap_qpel ## SIZE ## _l3_ ## MMX(dst, src+S0, stride, SIZE, S1, S2);\
  1523. }
  1524. #define QPEL_2TAP(OPNAME, SIZE, MMX)\
  1525. QPEL_2TAP_XY(OPNAME, SIZE, MMX, 20, _x2_ ## MMX)\
  1526. QPEL_2TAP_XY(OPNAME, SIZE, MMX, 02, _y2_ ## MMX)\
  1527. QPEL_2TAP_XY(OPNAME, SIZE, MMX, 22, _xy2_mmx)\
  1528. static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc00_ ## MMX =\
  1529. OPNAME ## qpel ## SIZE ## _mc00_ ## MMX;\
  1530. static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc21_ ## MMX =\
  1531. OPNAME ## 2tap_qpel ## SIZE ## _mc20_ ## MMX;\
  1532. static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc12_ ## MMX =\
  1533. OPNAME ## 2tap_qpel ## SIZE ## _mc02_ ## MMX;\
  1534. static void OPNAME ## 2tap_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1535. OPNAME ## pixels ## SIZE ## _y2_ ## MMX(dst, src+1, stride, SIZE);\
  1536. }\
  1537. static void OPNAME ## 2tap_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1538. OPNAME ## pixels ## SIZE ## _x2_ ## MMX(dst, src+stride, stride, SIZE);\
  1539. }\
  1540. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 10, 0, 1, 0)\
  1541. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 30, 1, -1, 0)\
  1542. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 01, 0, stride, 0)\
  1543. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 03, stride, -stride, 0)\
  1544. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 11, 0, stride, 1)\
  1545. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 31, 1, stride, -1)\
  1546. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 13, stride, -stride, 1)\
  1547. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 33, stride+1, -stride, -1)\
  1548. QPEL_2TAP(put_, 16, mmx2)
  1549. QPEL_2TAP(avg_, 16, mmx2)
  1550. QPEL_2TAP(put_, 8, mmx2)
  1551. QPEL_2TAP(avg_, 8, mmx2)
  1552. QPEL_2TAP(put_, 16, 3dnow)
  1553. QPEL_2TAP(avg_, 16, 3dnow)
  1554. QPEL_2TAP(put_, 8, 3dnow)
  1555. QPEL_2TAP(avg_, 8, 3dnow)
  1556. #if 0
  1557. static void just_return(void) { return; }
  1558. #endif
  1559. static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  1560. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height){
  1561. const int w = 8;
  1562. const int ix = ox>>(16+shift);
  1563. const int iy = oy>>(16+shift);
  1564. const int oxs = ox>>4;
  1565. const int oys = oy>>4;
  1566. const int dxxs = dxx>>4;
  1567. const int dxys = dxy>>4;
  1568. const int dyxs = dyx>>4;
  1569. const int dyys = dyy>>4;
  1570. const uint16_t r4[4] = {r,r,r,r};
  1571. const uint16_t dxy4[4] = {dxys,dxys,dxys,dxys};
  1572. const uint16_t dyy4[4] = {dyys,dyys,dyys,dyys};
  1573. const uint64_t shift2 = 2*shift;
  1574. uint8_t edge_buf[(h+1)*stride];
  1575. int x, y;
  1576. const int dxw = (dxx-(1<<(16+shift)))*(w-1);
  1577. const int dyh = (dyy-(1<<(16+shift)))*(h-1);
  1578. const int dxh = dxy*(h-1);
  1579. const int dyw = dyx*(w-1);
  1580. if( // non-constant fullpel offset (3% of blocks)
  1581. ((ox^(ox+dxw)) | (ox^(ox+dxh)) | (ox^(ox+dxw+dxh)) |
  1582. (oy^(oy+dyw)) | (oy^(oy+dyh)) | (oy^(oy+dyw+dyh))) >> (16+shift)
  1583. // uses more than 16 bits of subpel mv (only at huge resolution)
  1584. || (dxx|dxy|dyx|dyy)&15 )
  1585. {
  1586. //FIXME could still use mmx for some of the rows
  1587. ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r, width, height);
  1588. return;
  1589. }
  1590. src += ix + iy*stride;
  1591. if( (unsigned)ix >= width-w ||
  1592. (unsigned)iy >= height-h )
  1593. {
  1594. ff_emulated_edge_mc(edge_buf, src, stride, w+1, h+1, ix, iy, width, height);
  1595. src = edge_buf;
  1596. }
  1597. __asm__ volatile(
  1598. "movd %0, %%mm6 \n\t"
  1599. "pxor %%mm7, %%mm7 \n\t"
  1600. "punpcklwd %%mm6, %%mm6 \n\t"
  1601. "punpcklwd %%mm6, %%mm6 \n\t"
  1602. :: "r"(1<<shift)
  1603. );
  1604. for(x=0; x<w; x+=4){
  1605. uint16_t dx4[4] = { oxs - dxys + dxxs*(x+0),
  1606. oxs - dxys + dxxs*(x+1),
  1607. oxs - dxys + dxxs*(x+2),
  1608. oxs - dxys + dxxs*(x+3) };
  1609. uint16_t dy4[4] = { oys - dyys + dyxs*(x+0),
  1610. oys - dyys + dyxs*(x+1),
  1611. oys - dyys + dyxs*(x+2),
  1612. oys - dyys + dyxs*(x+3) };
  1613. for(y=0; y<h; y++){
  1614. __asm__ volatile(
  1615. "movq %0, %%mm4 \n\t"
  1616. "movq %1, %%mm5 \n\t"
  1617. "paddw %2, %%mm4 \n\t"
  1618. "paddw %3, %%mm5 \n\t"
  1619. "movq %%mm4, %0 \n\t"
  1620. "movq %%mm5, %1 \n\t"
  1621. "psrlw $12, %%mm4 \n\t"
  1622. "psrlw $12, %%mm5 \n\t"
  1623. : "+m"(*dx4), "+m"(*dy4)
  1624. : "m"(*dxy4), "m"(*dyy4)
  1625. );
  1626. __asm__ volatile(
  1627. "movq %%mm6, %%mm2 \n\t"
  1628. "movq %%mm6, %%mm1 \n\t"
  1629. "psubw %%mm4, %%mm2 \n\t"
  1630. "psubw %%mm5, %%mm1 \n\t"
  1631. "movq %%mm2, %%mm0 \n\t"
  1632. "movq %%mm4, %%mm3 \n\t"
  1633. "pmullw %%mm1, %%mm0 \n\t" // (s-dx)*(s-dy)
  1634. "pmullw %%mm5, %%mm3 \n\t" // dx*dy
  1635. "pmullw %%mm5, %%mm2 \n\t" // (s-dx)*dy
  1636. "pmullw %%mm4, %%mm1 \n\t" // dx*(s-dy)
  1637. "movd %4, %%mm5 \n\t"
  1638. "movd %3, %%mm4 \n\t"
  1639. "punpcklbw %%mm7, %%mm5 \n\t"
  1640. "punpcklbw %%mm7, %%mm4 \n\t"
  1641. "pmullw %%mm5, %%mm3 \n\t" // src[1,1] * dx*dy
  1642. "pmullw %%mm4, %%mm2 \n\t" // src[0,1] * (s-dx)*dy
  1643. "movd %2, %%mm5 \n\t"
  1644. "movd %1, %%mm4 \n\t"
  1645. "punpcklbw %%mm7, %%mm5 \n\t"
  1646. "punpcklbw %%mm7, %%mm4 \n\t"
  1647. "pmullw %%mm5, %%mm1 \n\t" // src[1,0] * dx*(s-dy)
  1648. "pmullw %%mm4, %%mm0 \n\t" // src[0,0] * (s-dx)*(s-dy)
  1649. "paddw %5, %%mm1 \n\t"
  1650. "paddw %%mm3, %%mm2 \n\t"
  1651. "paddw %%mm1, %%mm0 \n\t"
  1652. "paddw %%mm2, %%mm0 \n\t"
  1653. "psrlw %6, %%mm0 \n\t"
  1654. "packuswb %%mm0, %%mm0 \n\t"
  1655. "movd %%mm0, %0 \n\t"
  1656. : "=m"(dst[x+y*stride])
  1657. : "m"(src[0]), "m"(src[1]),
  1658. "m"(src[stride]), "m"(src[stride+1]),
  1659. "m"(*r4), "m"(shift2)
  1660. );
  1661. src += stride;
  1662. }
  1663. src += 4-h*stride;
  1664. }
  1665. }
  1666. #define PREFETCH(name, op) \
  1667. static void name(void *mem, int stride, int h){\
  1668. const uint8_t *p= mem;\
  1669. do{\
  1670. __asm__ volatile(#op" %0" :: "m"(*p));\
  1671. p+= stride;\
  1672. }while(--h);\
  1673. }
  1674. PREFETCH(prefetch_mmx2, prefetcht0)
  1675. PREFETCH(prefetch_3dnow, prefetch)
  1676. #undef PREFETCH
  1677. #include "h264dsp_mmx.c"
  1678. #include "rv40dsp_mmx.c"
  1679. /* CAVS specific */
  1680. void ff_cavsdsp_init_mmx2(DSPContext* c, AVCodecContext *avctx);
  1681. void ff_cavsdsp_init_3dnow(DSPContext* c, AVCodecContext *avctx);
  1682. void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
  1683. put_pixels8_mmx(dst, src, stride, 8);
  1684. }
  1685. void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
  1686. avg_pixels8_mmx(dst, src, stride, 8);
  1687. }
  1688. void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
  1689. put_pixels16_mmx(dst, src, stride, 16);
  1690. }
  1691. void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
  1692. avg_pixels16_mmx(dst, src, stride, 16);
  1693. }
  1694. /* VC1 specific */
  1695. void ff_vc1dsp_init_mmx(DSPContext* dsp, AVCodecContext *avctx);
  1696. void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
  1697. put_pixels8_mmx(dst, src, stride, 8);
  1698. }
  1699. /* external functions, from idct_mmx.c */
  1700. void ff_mmx_idct(DCTELEM *block);
  1701. void ff_mmxext_idct(DCTELEM *block);
  1702. /* XXX: those functions should be suppressed ASAP when all IDCTs are
  1703. converted */
  1704. #if CONFIG_GPL
  1705. static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
  1706. {
  1707. ff_mmx_idct (block);
  1708. put_pixels_clamped_mmx(block, dest, line_size);
  1709. }
  1710. static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
  1711. {
  1712. ff_mmx_idct (block);
  1713. add_pixels_clamped_mmx(block, dest, line_size);
  1714. }
  1715. static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
  1716. {
  1717. ff_mmxext_idct (block);
  1718. put_pixels_clamped_mmx(block, dest, line_size);
  1719. }
  1720. static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
  1721. {
  1722. ff_mmxext_idct (block);
  1723. add_pixels_clamped_mmx(block, dest, line_size);
  1724. }
  1725. #endif
  1726. static void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, DCTELEM *block)
  1727. {
  1728. ff_idct_xvid_mmx (block);
  1729. put_pixels_clamped_mmx(block, dest, line_size);
  1730. }
  1731. static void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, DCTELEM *block)
  1732. {
  1733. ff_idct_xvid_mmx (block);
  1734. add_pixels_clamped_mmx(block, dest, line_size);
  1735. }
  1736. static void ff_idct_xvid_mmx2_put(uint8_t *dest, int line_size, DCTELEM *block)
  1737. {
  1738. ff_idct_xvid_mmx2 (block);
  1739. put_pixels_clamped_mmx(block, dest, line_size);
  1740. }
  1741. static void ff_idct_xvid_mmx2_add(uint8_t *dest, int line_size, DCTELEM *block)
  1742. {
  1743. ff_idct_xvid_mmx2 (block);
  1744. add_pixels_clamped_mmx(block, dest, line_size);
  1745. }
  1746. static void vorbis_inverse_coupling_3dnow(float *mag, float *ang, int blocksize)
  1747. {
  1748. int i;
  1749. __asm__ volatile("pxor %%mm7, %%mm7":);
  1750. for(i=0; i<blocksize; i+=2) {
  1751. __asm__ volatile(
  1752. "movq %0, %%mm0 \n\t"
  1753. "movq %1, %%mm1 \n\t"
  1754. "movq %%mm0, %%mm2 \n\t"
  1755. "movq %%mm1, %%mm3 \n\t"
  1756. "pfcmpge %%mm7, %%mm2 \n\t" // m <= 0.0
  1757. "pfcmpge %%mm7, %%mm3 \n\t" // a <= 0.0
  1758. "pslld $31, %%mm2 \n\t" // keep only the sign bit
  1759. "pxor %%mm2, %%mm1 \n\t"
  1760. "movq %%mm3, %%mm4 \n\t"
  1761. "pand %%mm1, %%mm3 \n\t"
  1762. "pandn %%mm1, %%mm4 \n\t"
  1763. "pfadd %%mm0, %%mm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
  1764. "pfsub %%mm4, %%mm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
  1765. "movq %%mm3, %1 \n\t"
  1766. "movq %%mm0, %0 \n\t"
  1767. :"+m"(mag[i]), "+m"(ang[i])
  1768. ::"memory"
  1769. );
  1770. }
  1771. __asm__ volatile("femms");
  1772. }
  1773. static void vorbis_inverse_coupling_sse(float *mag, float *ang, int blocksize)
  1774. {
  1775. int i;
  1776. __asm__ volatile(
  1777. "movaps %0, %%xmm5 \n\t"
  1778. ::"m"(ff_pdw_80000000[0])
  1779. );
  1780. for(i=0; i<blocksize; i+=4) {
  1781. __asm__ volatile(
  1782. "movaps %0, %%xmm0 \n\t"
  1783. "movaps %1, %%xmm1 \n\t"
  1784. "xorps %%xmm2, %%xmm2 \n\t"
  1785. "xorps %%xmm3, %%xmm3 \n\t"
  1786. "cmpleps %%xmm0, %%xmm2 \n\t" // m <= 0.0
  1787. "cmpleps %%xmm1, %%xmm3 \n\t" // a <= 0.0
  1788. "andps %%xmm5, %%xmm2 \n\t" // keep only the sign bit
  1789. "xorps %%xmm2, %%xmm1 \n\t"
  1790. "movaps %%xmm3, %%xmm4 \n\t"
  1791. "andps %%xmm1, %%xmm3 \n\t"
  1792. "andnps %%xmm1, %%xmm4 \n\t"
  1793. "addps %%xmm0, %%xmm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
  1794. "subps %%xmm4, %%xmm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
  1795. "movaps %%xmm3, %1 \n\t"
  1796. "movaps %%xmm0, %0 \n\t"
  1797. :"+m"(mag[i]), "+m"(ang[i])
  1798. ::"memory"
  1799. );
  1800. }
  1801. }
  1802. #define IF1(x) x
  1803. #define IF0(x)
  1804. #define MIX5(mono,stereo)\
  1805. __asm__ volatile(\
  1806. "movss 0(%2), %%xmm5 \n"\
  1807. "movss 8(%2), %%xmm6 \n"\
  1808. "movss 24(%2), %%xmm7 \n"\
  1809. "shufps $0, %%xmm5, %%xmm5 \n"\
  1810. "shufps $0, %%xmm6, %%xmm6 \n"\
  1811. "shufps $0, %%xmm7, %%xmm7 \n"\
  1812. "1: \n"\
  1813. "movaps (%0,%1), %%xmm0 \n"\
  1814. "movaps 0x400(%0,%1), %%xmm1 \n"\
  1815. "movaps 0x800(%0,%1), %%xmm2 \n"\
  1816. "movaps 0xc00(%0,%1), %%xmm3 \n"\
  1817. "movaps 0x1000(%0,%1), %%xmm4 \n"\
  1818. "mulps %%xmm5, %%xmm0 \n"\
  1819. "mulps %%xmm6, %%xmm1 \n"\
  1820. "mulps %%xmm5, %%xmm2 \n"\
  1821. "mulps %%xmm7, %%xmm3 \n"\
  1822. "mulps %%xmm7, %%xmm4 \n"\
  1823. stereo("addps %%xmm1, %%xmm0 \n")\
  1824. "addps %%xmm1, %%xmm2 \n"\
  1825. "addps %%xmm3, %%xmm0 \n"\
  1826. "addps %%xmm4, %%xmm2 \n"\
  1827. mono("addps %%xmm2, %%xmm0 \n")\
  1828. "movaps %%xmm0, (%0,%1) \n"\
  1829. stereo("movaps %%xmm2, 0x400(%0,%1) \n")\
  1830. "add $16, %0 \n"\
  1831. "jl 1b \n"\
  1832. :"+&r"(i)\
  1833. :"r"(samples[0]+len), "r"(matrix)\
  1834. :"memory"\
  1835. );
  1836. #define MIX_MISC(stereo)\
  1837. __asm__ volatile(\
  1838. "1: \n"\
  1839. "movaps (%3,%0), %%xmm0 \n"\
  1840. stereo("movaps %%xmm0, %%xmm1 \n")\
  1841. "mulps %%xmm6, %%xmm0 \n"\
  1842. stereo("mulps %%xmm7, %%xmm1 \n")\
  1843. "lea 1024(%3,%0), %1 \n"\
  1844. "mov %5, %2 \n"\
  1845. "2: \n"\
  1846. "movaps (%1), %%xmm2 \n"\
  1847. stereo("movaps %%xmm2, %%xmm3 \n")\
  1848. "mulps (%4,%2), %%xmm2 \n"\
  1849. stereo("mulps 16(%4,%2), %%xmm3 \n")\
  1850. "addps %%xmm2, %%xmm0 \n"\
  1851. stereo("addps %%xmm3, %%xmm1 \n")\
  1852. "add $1024, %1 \n"\
  1853. "add $32, %2 \n"\
  1854. "jl 2b \n"\
  1855. "movaps %%xmm0, (%3,%0) \n"\
  1856. stereo("movaps %%xmm1, 1024(%3,%0) \n")\
  1857. "add $16, %0 \n"\
  1858. "jl 1b \n"\
  1859. :"+&r"(i), "=&r"(j), "=&r"(k)\
  1860. :"r"(samples[0]+len), "r"(matrix_simd+in_ch), "g"((intptr_t)-32*(in_ch-1))\
  1861. :"memory"\
  1862. );
  1863. static void ac3_downmix_sse(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len)
  1864. {
  1865. int (*matrix_cmp)[2] = (int(*)[2])matrix;
  1866. intptr_t i,j,k;
  1867. i = -len*sizeof(float);
  1868. if(in_ch == 5 && out_ch == 2 && !(matrix_cmp[0][1]|matrix_cmp[2][0]|matrix_cmp[3][1]|matrix_cmp[4][0]|(matrix_cmp[1][0]^matrix_cmp[1][1])|(matrix_cmp[0][0]^matrix_cmp[2][1]))) {
  1869. MIX5(IF0,IF1);
  1870. } else if(in_ch == 5 && out_ch == 1 && matrix_cmp[0][0]==matrix_cmp[2][0] && matrix_cmp[3][0]==matrix_cmp[4][0]) {
  1871. MIX5(IF1,IF0);
  1872. } else {
  1873. DECLARE_ALIGNED_16(float, matrix_simd[in_ch][2][4]);
  1874. j = 2*in_ch*sizeof(float);
  1875. __asm__ volatile(
  1876. "1: \n"
  1877. "sub $8, %0 \n"
  1878. "movss (%2,%0), %%xmm6 \n"
  1879. "movss 4(%2,%0), %%xmm7 \n"
  1880. "shufps $0, %%xmm6, %%xmm6 \n"
  1881. "shufps $0, %%xmm7, %%xmm7 \n"
  1882. "movaps %%xmm6, (%1,%0,4) \n"
  1883. "movaps %%xmm7, 16(%1,%0,4) \n"
  1884. "jg 1b \n"
  1885. :"+&r"(j)
  1886. :"r"(matrix_simd), "r"(matrix)
  1887. :"memory"
  1888. );
  1889. if(out_ch == 2) {
  1890. MIX_MISC(IF1);
  1891. } else {
  1892. MIX_MISC(IF0);
  1893. }
  1894. }
  1895. }
  1896. static void vector_fmul_3dnow(float *dst, const float *src, int len){
  1897. x86_reg i = (len-4)*4;
  1898. __asm__ volatile(
  1899. "1: \n\t"
  1900. "movq (%1,%0), %%mm0 \n\t"
  1901. "movq 8(%1,%0), %%mm1 \n\t"
  1902. "pfmul (%2,%0), %%mm0 \n\t"
  1903. "pfmul 8(%2,%0), %%mm1 \n\t"
  1904. "movq %%mm0, (%1,%0) \n\t"
  1905. "movq %%mm1, 8(%1,%0) \n\t"
  1906. "sub $16, %0 \n\t"
  1907. "jge 1b \n\t"
  1908. "femms \n\t"
  1909. :"+r"(i)
  1910. :"r"(dst), "r"(src)
  1911. :"memory"
  1912. );
  1913. }
  1914. static void vector_fmul_sse(float *dst, const float *src, int len){
  1915. x86_reg i = (len-8)*4;
  1916. __asm__ volatile(
  1917. "1: \n\t"
  1918. "movaps (%1,%0), %%xmm0 \n\t"
  1919. "movaps 16(%1,%0), %%xmm1 \n\t"
  1920. "mulps (%2,%0), %%xmm0 \n\t"
  1921. "mulps 16(%2,%0), %%xmm1 \n\t"
  1922. "movaps %%xmm0, (%1,%0) \n\t"
  1923. "movaps %%xmm1, 16(%1,%0) \n\t"
  1924. "sub $32, %0 \n\t"
  1925. "jge 1b \n\t"
  1926. :"+r"(i)
  1927. :"r"(dst), "r"(src)
  1928. :"memory"
  1929. );
  1930. }
  1931. static void vector_fmul_reverse_3dnow2(float *dst, const float *src0, const float *src1, int len){
  1932. x86_reg i = len*4-16;
  1933. __asm__ volatile(
  1934. "1: \n\t"
  1935. "pswapd 8(%1), %%mm0 \n\t"
  1936. "pswapd (%1), %%mm1 \n\t"
  1937. "pfmul (%3,%0), %%mm0 \n\t"
  1938. "pfmul 8(%3,%0), %%mm1 \n\t"
  1939. "movq %%mm0, (%2,%0) \n\t"
  1940. "movq %%mm1, 8(%2,%0) \n\t"
  1941. "add $16, %1 \n\t"
  1942. "sub $16, %0 \n\t"
  1943. "jge 1b \n\t"
  1944. :"+r"(i), "+r"(src1)
  1945. :"r"(dst), "r"(src0)
  1946. );
  1947. __asm__ volatile("femms");
  1948. }
  1949. static void vector_fmul_reverse_sse(float *dst, const float *src0, const float *src1, int len){
  1950. x86_reg i = len*4-32;
  1951. __asm__ volatile(
  1952. "1: \n\t"
  1953. "movaps 16(%1), %%xmm0 \n\t"
  1954. "movaps (%1), %%xmm1 \n\t"
  1955. "shufps $0x1b, %%xmm0, %%xmm0 \n\t"
  1956. "shufps $0x1b, %%xmm1, %%xmm1 \n\t"
  1957. "mulps (%3,%0), %%xmm0 \n\t"
  1958. "mulps 16(%3,%0), %%xmm1 \n\t"
  1959. "movaps %%xmm0, (%2,%0) \n\t"
  1960. "movaps %%xmm1, 16(%2,%0) \n\t"
  1961. "add $32, %1 \n\t"
  1962. "sub $32, %0 \n\t"
  1963. "jge 1b \n\t"
  1964. :"+r"(i), "+r"(src1)
  1965. :"r"(dst), "r"(src0)
  1966. );
  1967. }
  1968. static void vector_fmul_add_add_3dnow(float *dst, const float *src0, const float *src1,
  1969. const float *src2, int src3, int len, int step){
  1970. x86_reg i = (len-4)*4;
  1971. if(step == 2 && src3 == 0){
  1972. dst += (len-4)*2;
  1973. __asm__ volatile(
  1974. "1: \n\t"
  1975. "movq (%2,%0), %%mm0 \n\t"
  1976. "movq 8(%2,%0), %%mm1 \n\t"
  1977. "pfmul (%3,%0), %%mm0 \n\t"
  1978. "pfmul 8(%3,%0), %%mm1 \n\t"
  1979. "pfadd (%4,%0), %%mm0 \n\t"
  1980. "pfadd 8(%4,%0), %%mm1 \n\t"
  1981. "movd %%mm0, (%1) \n\t"
  1982. "movd %%mm1, 16(%1) \n\t"
  1983. "psrlq $32, %%mm0 \n\t"
  1984. "psrlq $32, %%mm1 \n\t"
  1985. "movd %%mm0, 8(%1) \n\t"
  1986. "movd %%mm1, 24(%1) \n\t"
  1987. "sub $32, %1 \n\t"
  1988. "sub $16, %0 \n\t"
  1989. "jge 1b \n\t"
  1990. :"+r"(i), "+r"(dst)
  1991. :"r"(src0), "r"(src1), "r"(src2)
  1992. :"memory"
  1993. );
  1994. }
  1995. else if(step == 1 && src3 == 0){
  1996. __asm__ volatile(
  1997. "1: \n\t"
  1998. "movq (%2,%0), %%mm0 \n\t"
  1999. "movq 8(%2,%0), %%mm1 \n\t"
  2000. "pfmul (%3,%0), %%mm0 \n\t"
  2001. "pfmul 8(%3,%0), %%mm1 \n\t"
  2002. "pfadd (%4,%0), %%mm0 \n\t"
  2003. "pfadd 8(%4,%0), %%mm1 \n\t"
  2004. "movq %%mm0, (%1,%0) \n\t"
  2005. "movq %%mm1, 8(%1,%0) \n\t"
  2006. "sub $16, %0 \n\t"
  2007. "jge 1b \n\t"
  2008. :"+r"(i)
  2009. :"r"(dst), "r"(src0), "r"(src1), "r"(src2)
  2010. :"memory"
  2011. );
  2012. }
  2013. else
  2014. ff_vector_fmul_add_add_c(dst, src0, src1, src2, src3, len, step);
  2015. __asm__ volatile("femms");
  2016. }
  2017. static void vector_fmul_add_add_sse(float *dst, const float *src0, const float *src1,
  2018. const float *src2, int src3, int len, int step){
  2019. x86_reg i = (len-8)*4;
  2020. if(step == 2 && src3 == 0){
  2021. dst += (len-8)*2;
  2022. __asm__ volatile(
  2023. "1: \n\t"
  2024. "movaps (%2,%0), %%xmm0 \n\t"
  2025. "movaps 16(%2,%0), %%xmm1 \n\t"
  2026. "mulps (%3,%0), %%xmm0 \n\t"
  2027. "mulps 16(%3,%0), %%xmm1 \n\t"
  2028. "addps (%4,%0), %%xmm0 \n\t"
  2029. "addps 16(%4,%0), %%xmm1 \n\t"
  2030. "movss %%xmm0, (%1) \n\t"
  2031. "movss %%xmm1, 32(%1) \n\t"
  2032. "movhlps %%xmm0, %%xmm2 \n\t"
  2033. "movhlps %%xmm1, %%xmm3 \n\t"
  2034. "movss %%xmm2, 16(%1) \n\t"
  2035. "movss %%xmm3, 48(%1) \n\t"
  2036. "shufps $0xb1, %%xmm0, %%xmm0 \n\t"
  2037. "shufps $0xb1, %%xmm1, %%xmm1 \n\t"
  2038. "movss %%xmm0, 8(%1) \n\t"
  2039. "movss %%xmm1, 40(%1) \n\t"
  2040. "movhlps %%xmm0, %%xmm2 \n\t"
  2041. "movhlps %%xmm1, %%xmm3 \n\t"
  2042. "movss %%xmm2, 24(%1) \n\t"
  2043. "movss %%xmm3, 56(%1) \n\t"
  2044. "sub $64, %1 \n\t"
  2045. "sub $32, %0 \n\t"
  2046. "jge 1b \n\t"
  2047. :"+r"(i), "+r"(dst)
  2048. :"r"(src0), "r"(src1), "r"(src2)
  2049. :"memory"
  2050. );
  2051. }
  2052. else if(step == 1 && src3 == 0){
  2053. __asm__ volatile(
  2054. "1: \n\t"
  2055. "movaps (%2,%0), %%xmm0 \n\t"
  2056. "movaps 16(%2,%0), %%xmm1 \n\t"
  2057. "mulps (%3,%0), %%xmm0 \n\t"
  2058. "mulps 16(%3,%0), %%xmm1 \n\t"
  2059. "addps (%4,%0), %%xmm0 \n\t"
  2060. "addps 16(%4,%0), %%xmm1 \n\t"
  2061. "movaps %%xmm0, (%1,%0) \n\t"
  2062. "movaps %%xmm1, 16(%1,%0) \n\t"
  2063. "sub $32, %0 \n\t"
  2064. "jge 1b \n\t"
  2065. :"+r"(i)
  2066. :"r"(dst), "r"(src0), "r"(src1), "r"(src2)
  2067. :"memory"
  2068. );
  2069. }
  2070. else
  2071. ff_vector_fmul_add_add_c(dst, src0, src1, src2, src3, len, step);
  2072. }
  2073. static void vector_fmul_window_3dnow2(float *dst, const float *src0, const float *src1,
  2074. const float *win, float add_bias, int len){
  2075. #if HAVE_6REGS
  2076. if(add_bias == 0){
  2077. x86_reg i = -len*4;
  2078. x86_reg j = len*4-8;
  2079. __asm__ volatile(
  2080. "1: \n"
  2081. "pswapd (%5,%1), %%mm1 \n"
  2082. "movq (%5,%0), %%mm0 \n"
  2083. "pswapd (%4,%1), %%mm5 \n"
  2084. "movq (%3,%0), %%mm4 \n"
  2085. "movq %%mm0, %%mm2 \n"
  2086. "movq %%mm1, %%mm3 \n"
  2087. "pfmul %%mm4, %%mm2 \n" // src0[len+i]*win[len+i]
  2088. "pfmul %%mm5, %%mm3 \n" // src1[ j]*win[len+j]
  2089. "pfmul %%mm4, %%mm1 \n" // src0[len+i]*win[len+j]
  2090. "pfmul %%mm5, %%mm0 \n" // src1[ j]*win[len+i]
  2091. "pfadd %%mm3, %%mm2 \n"
  2092. "pfsub %%mm0, %%mm1 \n"
  2093. "pswapd %%mm2, %%mm2 \n"
  2094. "movq %%mm1, (%2,%0) \n"
  2095. "movq %%mm2, (%2,%1) \n"
  2096. "sub $8, %1 \n"
  2097. "add $8, %0 \n"
  2098. "jl 1b \n"
  2099. "femms \n"
  2100. :"+r"(i), "+r"(j)
  2101. :"r"(dst+len), "r"(src0+len), "r"(src1), "r"(win+len)
  2102. );
  2103. }else
  2104. #endif
  2105. ff_vector_fmul_window_c(dst, src0, src1, win, add_bias, len);
  2106. }
  2107. static void vector_fmul_window_sse(float *dst, const float *src0, const float *src1,
  2108. const float *win, float add_bias, int len){
  2109. #if HAVE_6REGS
  2110. if(add_bias == 0){
  2111. x86_reg i = -len*4;
  2112. x86_reg j = len*4-16;
  2113. __asm__ volatile(
  2114. "1: \n"
  2115. "movaps (%5,%1), %%xmm1 \n"
  2116. "movaps (%5,%0), %%xmm0 \n"
  2117. "movaps (%4,%1), %%xmm5 \n"
  2118. "movaps (%3,%0), %%xmm4 \n"
  2119. "shufps $0x1b, %%xmm1, %%xmm1 \n"
  2120. "shufps $0x1b, %%xmm5, %%xmm5 \n"
  2121. "movaps %%xmm0, %%xmm2 \n"
  2122. "movaps %%xmm1, %%xmm3 \n"
  2123. "mulps %%xmm4, %%xmm2 \n" // src0[len+i]*win[len+i]
  2124. "mulps %%xmm5, %%xmm3 \n" // src1[ j]*win[len+j]
  2125. "mulps %%xmm4, %%xmm1 \n" // src0[len+i]*win[len+j]
  2126. "mulps %%xmm5, %%xmm0 \n" // src1[ j]*win[len+i]
  2127. "addps %%xmm3, %%xmm2 \n"
  2128. "subps %%xmm0, %%xmm1 \n"
  2129. "shufps $0x1b, %%xmm2, %%xmm2 \n"
  2130. "movaps %%xmm1, (%2,%0) \n"
  2131. "movaps %%xmm2, (%2,%1) \n"
  2132. "sub $16, %1 \n"
  2133. "add $16, %0 \n"
  2134. "jl 1b \n"
  2135. :"+r"(i), "+r"(j)
  2136. :"r"(dst+len), "r"(src0+len), "r"(src1), "r"(win+len)
  2137. );
  2138. }else
  2139. #endif
  2140. ff_vector_fmul_window_c(dst, src0, src1, win, add_bias, len);
  2141. }
  2142. static void int32_to_float_fmul_scalar_sse(float *dst, const int *src, float mul, int len)
  2143. {
  2144. x86_reg i = -4*len;
  2145. __asm__ volatile(
  2146. "movss %3, %%xmm4 \n"
  2147. "shufps $0, %%xmm4, %%xmm4 \n"
  2148. "1: \n"
  2149. "cvtpi2ps (%2,%0), %%xmm0 \n"
  2150. "cvtpi2ps 8(%2,%0), %%xmm1 \n"
  2151. "cvtpi2ps 16(%2,%0), %%xmm2 \n"
  2152. "cvtpi2ps 24(%2,%0), %%xmm3 \n"
  2153. "movlhps %%xmm1, %%xmm0 \n"
  2154. "movlhps %%xmm3, %%xmm2 \n"
  2155. "mulps %%xmm4, %%xmm0 \n"
  2156. "mulps %%xmm4, %%xmm2 \n"
  2157. "movaps %%xmm0, (%1,%0) \n"
  2158. "movaps %%xmm2, 16(%1,%0) \n"
  2159. "add $32, %0 \n"
  2160. "jl 1b \n"
  2161. :"+r"(i)
  2162. :"r"(dst+len), "r"(src+len), "m"(mul)
  2163. );
  2164. }
  2165. static void int32_to_float_fmul_scalar_sse2(float *dst, const int *src, float mul, int len)
  2166. {
  2167. x86_reg i = -4*len;
  2168. __asm__ volatile(
  2169. "movss %3, %%xmm4 \n"
  2170. "shufps $0, %%xmm4, %%xmm4 \n"
  2171. "1: \n"
  2172. "cvtdq2ps (%2,%0), %%xmm0 \n"
  2173. "cvtdq2ps 16(%2,%0), %%xmm1 \n"
  2174. "mulps %%xmm4, %%xmm0 \n"
  2175. "mulps %%xmm4, %%xmm1 \n"
  2176. "movaps %%xmm0, (%1,%0) \n"
  2177. "movaps %%xmm1, 16(%1,%0) \n"
  2178. "add $32, %0 \n"
  2179. "jl 1b \n"
  2180. :"+r"(i)
  2181. :"r"(dst+len), "r"(src+len), "m"(mul)
  2182. );
  2183. }
  2184. static void float_to_int16_3dnow(int16_t *dst, const float *src, long len){
  2185. x86_reg reglen = len;
  2186. // not bit-exact: pf2id uses different rounding than C and SSE
  2187. __asm__ volatile(
  2188. "add %0 , %0 \n\t"
  2189. "lea (%2,%0,2) , %2 \n\t"
  2190. "add %0 , %1 \n\t"
  2191. "neg %0 \n\t"
  2192. "1: \n\t"
  2193. "pf2id (%2,%0,2) , %%mm0 \n\t"
  2194. "pf2id 8(%2,%0,2) , %%mm1 \n\t"
  2195. "pf2id 16(%2,%0,2) , %%mm2 \n\t"
  2196. "pf2id 24(%2,%0,2) , %%mm3 \n\t"
  2197. "packssdw %%mm1 , %%mm0 \n\t"
  2198. "packssdw %%mm3 , %%mm2 \n\t"
  2199. "movq %%mm0 , (%1,%0) \n\t"
  2200. "movq %%mm2 , 8(%1,%0) \n\t"
  2201. "add $16 , %0 \n\t"
  2202. " js 1b \n\t"
  2203. "femms \n\t"
  2204. :"+r"(reglen), "+r"(dst), "+r"(src)
  2205. );
  2206. }
  2207. static void float_to_int16_sse(int16_t *dst, const float *src, long len){
  2208. x86_reg reglen = len;
  2209. __asm__ volatile(
  2210. "add %0 , %0 \n\t"
  2211. "lea (%2,%0,2) , %2 \n\t"
  2212. "add %0 , %1 \n\t"
  2213. "neg %0 \n\t"
  2214. "1: \n\t"
  2215. "cvtps2pi (%2,%0,2) , %%mm0 \n\t"
  2216. "cvtps2pi 8(%2,%0,2) , %%mm1 \n\t"
  2217. "cvtps2pi 16(%2,%0,2) , %%mm2 \n\t"
  2218. "cvtps2pi 24(%2,%0,2) , %%mm3 \n\t"
  2219. "packssdw %%mm1 , %%mm0 \n\t"
  2220. "packssdw %%mm3 , %%mm2 \n\t"
  2221. "movq %%mm0 , (%1,%0) \n\t"
  2222. "movq %%mm2 , 8(%1,%0) \n\t"
  2223. "add $16 , %0 \n\t"
  2224. " js 1b \n\t"
  2225. "emms \n\t"
  2226. :"+r"(reglen), "+r"(dst), "+r"(src)
  2227. );
  2228. }
  2229. static void float_to_int16_sse2(int16_t *dst, const float *src, long len){
  2230. x86_reg reglen = len;
  2231. __asm__ volatile(
  2232. "add %0 , %0 \n\t"
  2233. "lea (%2,%0,2) , %2 \n\t"
  2234. "add %0 , %1 \n\t"
  2235. "neg %0 \n\t"
  2236. "1: \n\t"
  2237. "cvtps2dq (%2,%0,2) , %%xmm0 \n\t"
  2238. "cvtps2dq 16(%2,%0,2) , %%xmm1 \n\t"
  2239. "packssdw %%xmm1 , %%xmm0 \n\t"
  2240. "movdqa %%xmm0 , (%1,%0) \n\t"
  2241. "add $16 , %0 \n\t"
  2242. " js 1b \n\t"
  2243. :"+r"(reglen), "+r"(dst), "+r"(src)
  2244. );
  2245. }
  2246. #if HAVE_YASM
  2247. void ff_float_to_int16_interleave6_sse(int16_t *dst, const float **src, int len);
  2248. void ff_float_to_int16_interleave6_3dnow(int16_t *dst, const float **src, int len);
  2249. void ff_float_to_int16_interleave6_3dn2(int16_t *dst, const float **src, int len);
  2250. void ff_add_hfyu_median_prediction_mmx2(uint8_t *dst, uint8_t *top, uint8_t *diff, int w, int *left, int *left_top);
  2251. void ff_x264_deblock_v_luma_sse2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
  2252. void ff_x264_deblock_h_luma_sse2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
  2253. void ff_x264_deblock_v8_luma_intra_mmxext(uint8_t *pix, int stride, int alpha, int beta);
  2254. void ff_x264_deblock_h_luma_intra_mmxext(uint8_t *pix, int stride, int alpha, int beta);
  2255. #if ARCH_X86_32
  2256. static void ff_x264_deblock_v_luma_intra_mmxext(uint8_t *pix, int stride, int alpha, int beta)
  2257. {
  2258. ff_x264_deblock_v8_luma_intra_mmxext(pix+0, stride, alpha, beta);
  2259. ff_x264_deblock_v8_luma_intra_mmxext(pix+8, stride, alpha, beta);
  2260. }
  2261. #endif
  2262. void ff_x264_deblock_v_luma_intra_sse2(uint8_t *pix, int stride, int alpha, int beta);
  2263. void ff_x264_deblock_h_luma_intra_sse2(uint8_t *pix, int stride, int alpha, int beta);
  2264. #else
  2265. #define ff_float_to_int16_interleave6_sse(a,b,c) float_to_int16_interleave_misc_sse(a,b,c,6)
  2266. #define ff_float_to_int16_interleave6_3dnow(a,b,c) float_to_int16_interleave_misc_3dnow(a,b,c,6)
  2267. #define ff_float_to_int16_interleave6_3dn2(a,b,c) float_to_int16_interleave_misc_3dnow(a,b,c,6)
  2268. #endif
  2269. #define ff_float_to_int16_interleave6_sse2 ff_float_to_int16_interleave6_sse
  2270. #define FLOAT_TO_INT16_INTERLEAVE(cpu, body) \
  2271. /* gcc pessimizes register allocation if this is in the same function as float_to_int16_interleave_sse2*/\
  2272. static av_noinline void float_to_int16_interleave_misc_##cpu(int16_t *dst, const float **src, long len, int channels){\
  2273. DECLARE_ALIGNED_16(int16_t, tmp[len]);\
  2274. int i,j,c;\
  2275. for(c=0; c<channels; c++){\
  2276. float_to_int16_##cpu(tmp, src[c], len);\
  2277. for(i=0, j=c; i<len; i++, j+=channels)\
  2278. dst[j] = tmp[i];\
  2279. }\
  2280. }\
  2281. \
  2282. static void float_to_int16_interleave_##cpu(int16_t *dst, const float **src, long len, int channels){\
  2283. if(channels==1)\
  2284. float_to_int16_##cpu(dst, src[0], len);\
  2285. else if(channels==2){\
  2286. x86_reg reglen = len; \
  2287. const float *src0 = src[0];\
  2288. const float *src1 = src[1];\
  2289. __asm__ volatile(\
  2290. "shl $2, %0 \n"\
  2291. "add %0, %1 \n"\
  2292. "add %0, %2 \n"\
  2293. "add %0, %3 \n"\
  2294. "neg %0 \n"\
  2295. body\
  2296. :"+r"(reglen), "+r"(dst), "+r"(src0), "+r"(src1)\
  2297. );\
  2298. }else if(channels==6){\
  2299. ff_float_to_int16_interleave6_##cpu(dst, src, len);\
  2300. }else\
  2301. float_to_int16_interleave_misc_##cpu(dst, src, len, channels);\
  2302. }
  2303. FLOAT_TO_INT16_INTERLEAVE(3dnow,
  2304. "1: \n"
  2305. "pf2id (%2,%0), %%mm0 \n"
  2306. "pf2id 8(%2,%0), %%mm1 \n"
  2307. "pf2id (%3,%0), %%mm2 \n"
  2308. "pf2id 8(%3,%0), %%mm3 \n"
  2309. "packssdw %%mm1, %%mm0 \n"
  2310. "packssdw %%mm3, %%mm2 \n"
  2311. "movq %%mm0, %%mm1 \n"
  2312. "punpcklwd %%mm2, %%mm0 \n"
  2313. "punpckhwd %%mm2, %%mm1 \n"
  2314. "movq %%mm0, (%1,%0)\n"
  2315. "movq %%mm1, 8(%1,%0)\n"
  2316. "add $16, %0 \n"
  2317. "js 1b \n"
  2318. "femms \n"
  2319. )
  2320. FLOAT_TO_INT16_INTERLEAVE(sse,
  2321. "1: \n"
  2322. "cvtps2pi (%2,%0), %%mm0 \n"
  2323. "cvtps2pi 8(%2,%0), %%mm1 \n"
  2324. "cvtps2pi (%3,%0), %%mm2 \n"
  2325. "cvtps2pi 8(%3,%0), %%mm3 \n"
  2326. "packssdw %%mm1, %%mm0 \n"
  2327. "packssdw %%mm3, %%mm2 \n"
  2328. "movq %%mm0, %%mm1 \n"
  2329. "punpcklwd %%mm2, %%mm0 \n"
  2330. "punpckhwd %%mm2, %%mm1 \n"
  2331. "movq %%mm0, (%1,%0)\n"
  2332. "movq %%mm1, 8(%1,%0)\n"
  2333. "add $16, %0 \n"
  2334. "js 1b \n"
  2335. "emms \n"
  2336. )
  2337. FLOAT_TO_INT16_INTERLEAVE(sse2,
  2338. "1: \n"
  2339. "cvtps2dq (%2,%0), %%xmm0 \n"
  2340. "cvtps2dq (%3,%0), %%xmm1 \n"
  2341. "packssdw %%xmm1, %%xmm0 \n"
  2342. "movhlps %%xmm0, %%xmm1 \n"
  2343. "punpcklwd %%xmm1, %%xmm0 \n"
  2344. "movdqa %%xmm0, (%1,%0) \n"
  2345. "add $16, %0 \n"
  2346. "js 1b \n"
  2347. )
  2348. static void float_to_int16_interleave_3dn2(int16_t *dst, const float **src, long len, int channels){
  2349. if(channels==6)
  2350. ff_float_to_int16_interleave6_3dn2(dst, src, len);
  2351. else
  2352. float_to_int16_interleave_3dnow(dst, src, len, channels);
  2353. }
  2354. void ff_snow_horizontal_compose97i_sse2(IDWTELEM *b, int width);
  2355. void ff_snow_horizontal_compose97i_mmx(IDWTELEM *b, int width);
  2356. void ff_snow_vertical_compose97i_sse2(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width);
  2357. void ff_snow_vertical_compose97i_mmx(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width);
  2358. void ff_snow_inner_add_yblock_sse2(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h,
  2359. int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8);
  2360. void ff_snow_inner_add_yblock_mmx(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h,
  2361. int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8);
  2362. static void add_int16_sse2(int16_t * v1, int16_t * v2, int order)
  2363. {
  2364. x86_reg o = -(order << 1);
  2365. v1 += order;
  2366. v2 += order;
  2367. __asm__ volatile(
  2368. "1: \n\t"
  2369. "movdqu (%1,%2), %%xmm0 \n\t"
  2370. "movdqu 16(%1,%2), %%xmm1 \n\t"
  2371. "paddw (%0,%2), %%xmm0 \n\t"
  2372. "paddw 16(%0,%2), %%xmm1 \n\t"
  2373. "movdqa %%xmm0, (%0,%2) \n\t"
  2374. "movdqa %%xmm1, 16(%0,%2) \n\t"
  2375. "add $32, %2 \n\t"
  2376. "js 1b \n\t"
  2377. : "+r"(v1), "+r"(v2), "+r"(o)
  2378. );
  2379. }
  2380. static void sub_int16_sse2(int16_t * v1, int16_t * v2, int order)
  2381. {
  2382. x86_reg o = -(order << 1);
  2383. v1 += order;
  2384. v2 += order;
  2385. __asm__ volatile(
  2386. "1: \n\t"
  2387. "movdqa (%0,%2), %%xmm0 \n\t"
  2388. "movdqa 16(%0,%2), %%xmm2 \n\t"
  2389. "movdqu (%1,%2), %%xmm1 \n\t"
  2390. "movdqu 16(%1,%2), %%xmm3 \n\t"
  2391. "psubw %%xmm1, %%xmm0 \n\t"
  2392. "psubw %%xmm3, %%xmm2 \n\t"
  2393. "movdqa %%xmm0, (%0,%2) \n\t"
  2394. "movdqa %%xmm2, 16(%0,%2) \n\t"
  2395. "add $32, %2 \n\t"
  2396. "js 1b \n\t"
  2397. : "+r"(v1), "+r"(v2), "+r"(o)
  2398. );
  2399. }
  2400. static int32_t scalarproduct_int16_sse2(int16_t * v1, int16_t * v2, int order, int shift)
  2401. {
  2402. int res = 0;
  2403. DECLARE_ALIGNED_16(xmm_reg, sh);
  2404. x86_reg o = -(order << 1);
  2405. v1 += order;
  2406. v2 += order;
  2407. sh.a = shift;
  2408. __asm__ volatile(
  2409. "pxor %%xmm7, %%xmm7 \n\t"
  2410. "1: \n\t"
  2411. "movdqu (%0,%3), %%xmm0 \n\t"
  2412. "movdqu 16(%0,%3), %%xmm1 \n\t"
  2413. "pmaddwd (%1,%3), %%xmm0 \n\t"
  2414. "pmaddwd 16(%1,%3), %%xmm1 \n\t"
  2415. "paddd %%xmm0, %%xmm7 \n\t"
  2416. "paddd %%xmm1, %%xmm7 \n\t"
  2417. "add $32, %3 \n\t"
  2418. "js 1b \n\t"
  2419. "movhlps %%xmm7, %%xmm2 \n\t"
  2420. "paddd %%xmm2, %%xmm7 \n\t"
  2421. "psrad %4, %%xmm7 \n\t"
  2422. "pshuflw $0x4E, %%xmm7,%%xmm2 \n\t"
  2423. "paddd %%xmm2, %%xmm7 \n\t"
  2424. "movd %%xmm7, %2 \n\t"
  2425. : "+r"(v1), "+r"(v2), "=r"(res), "+r"(o)
  2426. : "m"(sh)
  2427. );
  2428. return res;
  2429. }
  2430. void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
  2431. {
  2432. mm_flags = mm_support();
  2433. if (avctx->dsp_mask) {
  2434. if (avctx->dsp_mask & FF_MM_FORCE)
  2435. mm_flags |= (avctx->dsp_mask & 0xffff);
  2436. else
  2437. mm_flags &= ~(avctx->dsp_mask & 0xffff);
  2438. }
  2439. #if 0
  2440. av_log(avctx, AV_LOG_INFO, "libavcodec: CPU flags:");
  2441. if (mm_flags & FF_MM_MMX)
  2442. av_log(avctx, AV_LOG_INFO, " mmx");
  2443. if (mm_flags & FF_MM_MMXEXT)
  2444. av_log(avctx, AV_LOG_INFO, " mmxext");
  2445. if (mm_flags & FF_MM_3DNOW)
  2446. av_log(avctx, AV_LOG_INFO, " 3dnow");
  2447. if (mm_flags & FF_MM_SSE)
  2448. av_log(avctx, AV_LOG_INFO, " sse");
  2449. if (mm_flags & FF_MM_SSE2)
  2450. av_log(avctx, AV_LOG_INFO, " sse2");
  2451. av_log(avctx, AV_LOG_INFO, "\n");
  2452. #endif
  2453. if (mm_flags & FF_MM_MMX) {
  2454. const int idct_algo= avctx->idct_algo;
  2455. if(avctx->lowres==0){
  2456. if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){
  2457. c->idct_put= ff_simple_idct_put_mmx;
  2458. c->idct_add= ff_simple_idct_add_mmx;
  2459. c->idct = ff_simple_idct_mmx;
  2460. c->idct_permutation_type= FF_SIMPLE_IDCT_PERM;
  2461. #if CONFIG_GPL
  2462. }else if(idct_algo==FF_IDCT_LIBMPEG2MMX){
  2463. if(mm_flags & FF_MM_MMXEXT){
  2464. c->idct_put= ff_libmpeg2mmx2_idct_put;
  2465. c->idct_add= ff_libmpeg2mmx2_idct_add;
  2466. c->idct = ff_mmxext_idct;
  2467. }else{
  2468. c->idct_put= ff_libmpeg2mmx_idct_put;
  2469. c->idct_add= ff_libmpeg2mmx_idct_add;
  2470. c->idct = ff_mmx_idct;
  2471. }
  2472. c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
  2473. #endif
  2474. }else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER || CONFIG_THEORA_DECODER) &&
  2475. idct_algo==FF_IDCT_VP3){
  2476. if(mm_flags & FF_MM_SSE2){
  2477. c->idct_put= ff_vp3_idct_put_sse2;
  2478. c->idct_add= ff_vp3_idct_add_sse2;
  2479. c->idct = ff_vp3_idct_sse2;
  2480. c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
  2481. }else{
  2482. c->idct_put= ff_vp3_idct_put_mmx;
  2483. c->idct_add= ff_vp3_idct_add_mmx;
  2484. c->idct = ff_vp3_idct_mmx;
  2485. c->idct_permutation_type= FF_PARTTRANS_IDCT_PERM;
  2486. }
  2487. }else if(idct_algo==FF_IDCT_CAVS){
  2488. c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
  2489. }else if(idct_algo==FF_IDCT_XVIDMMX){
  2490. if(mm_flags & FF_MM_SSE2){
  2491. c->idct_put= ff_idct_xvid_sse2_put;
  2492. c->idct_add= ff_idct_xvid_sse2_add;
  2493. c->idct = ff_idct_xvid_sse2;
  2494. c->idct_permutation_type= FF_SSE2_IDCT_PERM;
  2495. }else if(mm_flags & FF_MM_MMXEXT){
  2496. c->idct_put= ff_idct_xvid_mmx2_put;
  2497. c->idct_add= ff_idct_xvid_mmx2_add;
  2498. c->idct = ff_idct_xvid_mmx2;
  2499. }else{
  2500. c->idct_put= ff_idct_xvid_mmx_put;
  2501. c->idct_add= ff_idct_xvid_mmx_add;
  2502. c->idct = ff_idct_xvid_mmx;
  2503. }
  2504. }
  2505. }
  2506. c->put_pixels_clamped = put_pixels_clamped_mmx;
  2507. c->put_signed_pixels_clamped = put_signed_pixels_clamped_mmx;
  2508. c->add_pixels_clamped = add_pixels_clamped_mmx;
  2509. c->clear_block = clear_block_mmx;
  2510. c->clear_blocks = clear_blocks_mmx;
  2511. if (mm_flags & FF_MM_SSE)
  2512. c->clear_block = clear_block_sse;
  2513. #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
  2514. c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## SIZE ## _ ## CPU; \
  2515. c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
  2516. c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
  2517. c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU
  2518. SET_HPEL_FUNCS(put, 0, 16, mmx);
  2519. SET_HPEL_FUNCS(put_no_rnd, 0, 16, mmx);
  2520. SET_HPEL_FUNCS(avg, 0, 16, mmx);
  2521. SET_HPEL_FUNCS(avg_no_rnd, 0, 16, mmx);
  2522. SET_HPEL_FUNCS(put, 1, 8, mmx);
  2523. SET_HPEL_FUNCS(put_no_rnd, 1, 8, mmx);
  2524. SET_HPEL_FUNCS(avg, 1, 8, mmx);
  2525. SET_HPEL_FUNCS(avg_no_rnd, 1, 8, mmx);
  2526. c->gmc= gmc_mmx;
  2527. c->add_bytes= add_bytes_mmx;
  2528. c->add_bytes_l2= add_bytes_l2_mmx;
  2529. c->draw_edges = draw_edges_mmx;
  2530. if (CONFIG_ANY_H263) {
  2531. c->h263_v_loop_filter= h263_v_loop_filter_mmx;
  2532. c->h263_h_loop_filter= h263_h_loop_filter_mmx;
  2533. }
  2534. c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_mmx_rnd;
  2535. c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_mmx;
  2536. c->put_no_rnd_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_mmx_nornd;
  2537. c->put_rv40_chroma_pixels_tab[0]= put_rv40_chroma_mc8_mmx;
  2538. c->put_rv40_chroma_pixels_tab[1]= put_rv40_chroma_mc4_mmx;
  2539. c->h264_idct_dc_add=
  2540. c->h264_idct_add= ff_h264_idct_add_mmx;
  2541. c->h264_idct8_dc_add=
  2542. c->h264_idct8_add= ff_h264_idct8_add_mmx;
  2543. c->h264_idct_add16 = ff_h264_idct_add16_mmx;
  2544. c->h264_idct8_add4 = ff_h264_idct8_add4_mmx;
  2545. c->h264_idct_add8 = ff_h264_idct_add8_mmx;
  2546. c->h264_idct_add16intra= ff_h264_idct_add16intra_mmx;
  2547. if (CONFIG_VP6_DECODER) {
  2548. c->vp6_filter_diag4 = ff_vp6_filter_diag4_mmx;
  2549. }
  2550. if (mm_flags & FF_MM_MMXEXT) {
  2551. c->prefetch = prefetch_mmx2;
  2552. c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2;
  2553. c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2;
  2554. c->avg_pixels_tab[0][0] = avg_pixels16_mmx2;
  2555. c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx2;
  2556. c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx2;
  2557. c->put_pixels_tab[1][1] = put_pixels8_x2_mmx2;
  2558. c->put_pixels_tab[1][2] = put_pixels8_y2_mmx2;
  2559. c->avg_pixels_tab[1][0] = avg_pixels8_mmx2;
  2560. c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2;
  2561. c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2;
  2562. c->h264_idct_dc_add= ff_h264_idct_dc_add_mmx2;
  2563. c->h264_idct8_dc_add= ff_h264_idct8_dc_add_mmx2;
  2564. c->h264_idct_add16 = ff_h264_idct_add16_mmx2;
  2565. c->h264_idct8_add4 = ff_h264_idct8_add4_mmx2;
  2566. c->h264_idct_add8 = ff_h264_idct_add8_mmx2;
  2567. c->h264_idct_add16intra= ff_h264_idct_add16intra_mmx2;
  2568. if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
  2569. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx2;
  2570. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx2;
  2571. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2;
  2572. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2;
  2573. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2;
  2574. c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2;
  2575. if (CONFIG_VP3_DECODER || CONFIG_THEORA_DECODER) {
  2576. c->vp3_v_loop_filter= ff_vp3_v_loop_filter_mmx2;
  2577. c->vp3_h_loop_filter= ff_vp3_h_loop_filter_mmx2;
  2578. }
  2579. }
  2580. #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU) \
  2581. c->PFX ## _pixels_tab[IDX][ 0] = PFX ## SIZE ## _mc00_ ## CPU; \
  2582. c->PFX ## _pixels_tab[IDX][ 1] = PFX ## SIZE ## _mc10_ ## CPU; \
  2583. c->PFX ## _pixels_tab[IDX][ 2] = PFX ## SIZE ## _mc20_ ## CPU; \
  2584. c->PFX ## _pixels_tab[IDX][ 3] = PFX ## SIZE ## _mc30_ ## CPU; \
  2585. c->PFX ## _pixels_tab[IDX][ 4] = PFX ## SIZE ## _mc01_ ## CPU; \
  2586. c->PFX ## _pixels_tab[IDX][ 5] = PFX ## SIZE ## _mc11_ ## CPU; \
  2587. c->PFX ## _pixels_tab[IDX][ 6] = PFX ## SIZE ## _mc21_ ## CPU; \
  2588. c->PFX ## _pixels_tab[IDX][ 7] = PFX ## SIZE ## _mc31_ ## CPU; \
  2589. c->PFX ## _pixels_tab[IDX][ 8] = PFX ## SIZE ## _mc02_ ## CPU; \
  2590. c->PFX ## _pixels_tab[IDX][ 9] = PFX ## SIZE ## _mc12_ ## CPU; \
  2591. c->PFX ## _pixels_tab[IDX][10] = PFX ## SIZE ## _mc22_ ## CPU; \
  2592. c->PFX ## _pixels_tab[IDX][11] = PFX ## SIZE ## _mc32_ ## CPU; \
  2593. c->PFX ## _pixels_tab[IDX][12] = PFX ## SIZE ## _mc03_ ## CPU; \
  2594. c->PFX ## _pixels_tab[IDX][13] = PFX ## SIZE ## _mc13_ ## CPU; \
  2595. c->PFX ## _pixels_tab[IDX][14] = PFX ## SIZE ## _mc23_ ## CPU; \
  2596. c->PFX ## _pixels_tab[IDX][15] = PFX ## SIZE ## _mc33_ ## CPU
  2597. SET_QPEL_FUNCS(put_qpel, 0, 16, mmx2);
  2598. SET_QPEL_FUNCS(put_qpel, 1, 8, mmx2);
  2599. SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmx2);
  2600. SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmx2);
  2601. SET_QPEL_FUNCS(avg_qpel, 0, 16, mmx2);
  2602. SET_QPEL_FUNCS(avg_qpel, 1, 8, mmx2);
  2603. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmx2);
  2604. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, mmx2);
  2605. SET_QPEL_FUNCS(put_h264_qpel, 2, 4, mmx2);
  2606. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmx2);
  2607. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, mmx2);
  2608. SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, mmx2);
  2609. SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, mmx2);
  2610. SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, mmx2);
  2611. SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, mmx2);
  2612. SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, mmx2);
  2613. c->avg_rv40_chroma_pixels_tab[0]= avg_rv40_chroma_mc8_mmx2;
  2614. c->avg_rv40_chroma_pixels_tab[1]= avg_rv40_chroma_mc4_mmx2;
  2615. c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_mmx2_rnd;
  2616. c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_mmx2;
  2617. c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_mmx2;
  2618. c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_mmx2;
  2619. c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_mmx2;
  2620. c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_mmx2;
  2621. c->h264_v_loop_filter_chroma= h264_v_loop_filter_chroma_mmx2;
  2622. c->h264_h_loop_filter_chroma= h264_h_loop_filter_chroma_mmx2;
  2623. c->h264_v_loop_filter_chroma_intra= h264_v_loop_filter_chroma_intra_mmx2;
  2624. c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_mmx2;
  2625. c->h264_loop_filter_strength= h264_loop_filter_strength_mmx2;
  2626. c->weight_h264_pixels_tab[0]= ff_h264_weight_16x16_mmx2;
  2627. c->weight_h264_pixels_tab[1]= ff_h264_weight_16x8_mmx2;
  2628. c->weight_h264_pixels_tab[2]= ff_h264_weight_8x16_mmx2;
  2629. c->weight_h264_pixels_tab[3]= ff_h264_weight_8x8_mmx2;
  2630. c->weight_h264_pixels_tab[4]= ff_h264_weight_8x4_mmx2;
  2631. c->weight_h264_pixels_tab[5]= ff_h264_weight_4x8_mmx2;
  2632. c->weight_h264_pixels_tab[6]= ff_h264_weight_4x4_mmx2;
  2633. c->weight_h264_pixels_tab[7]= ff_h264_weight_4x2_mmx2;
  2634. c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16x16_mmx2;
  2635. c->biweight_h264_pixels_tab[1]= ff_h264_biweight_16x8_mmx2;
  2636. c->biweight_h264_pixels_tab[2]= ff_h264_biweight_8x16_mmx2;
  2637. c->biweight_h264_pixels_tab[3]= ff_h264_biweight_8x8_mmx2;
  2638. c->biweight_h264_pixels_tab[4]= ff_h264_biweight_8x4_mmx2;
  2639. c->biweight_h264_pixels_tab[5]= ff_h264_biweight_4x8_mmx2;
  2640. c->biweight_h264_pixels_tab[6]= ff_h264_biweight_4x4_mmx2;
  2641. c->biweight_h264_pixels_tab[7]= ff_h264_biweight_4x2_mmx2;
  2642. #if HAVE_YASM
  2643. c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmx2;
  2644. #endif
  2645. #if HAVE_7REGS && HAVE_TEN_OPERANDS
  2646. if( mm_flags&FF_MM_3DNOW )
  2647. c->add_hfyu_median_prediction = add_hfyu_median_prediction_cmov;
  2648. #endif
  2649. if (CONFIG_CAVS_DECODER)
  2650. ff_cavsdsp_init_mmx2(c, avctx);
  2651. if (CONFIG_VC1_DECODER || CONFIG_WMV3_DECODER)
  2652. ff_vc1dsp_init_mmx(c, avctx);
  2653. c->add_png_paeth_prediction= add_png_paeth_prediction_mmx2;
  2654. } else if (mm_flags & FF_MM_3DNOW) {
  2655. c->prefetch = prefetch_3dnow;
  2656. c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
  2657. c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
  2658. c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
  2659. c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
  2660. c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
  2661. c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
  2662. c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
  2663. c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
  2664. c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
  2665. c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
  2666. if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
  2667. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
  2668. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
  2669. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
  2670. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
  2671. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
  2672. c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
  2673. }
  2674. SET_QPEL_FUNCS(put_qpel, 0, 16, 3dnow);
  2675. SET_QPEL_FUNCS(put_qpel, 1, 8, 3dnow);
  2676. SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, 3dnow);
  2677. SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, 3dnow);
  2678. SET_QPEL_FUNCS(avg_qpel, 0, 16, 3dnow);
  2679. SET_QPEL_FUNCS(avg_qpel, 1, 8, 3dnow);
  2680. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 3dnow);
  2681. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 3dnow);
  2682. SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 3dnow);
  2683. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 3dnow);
  2684. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 3dnow);
  2685. SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 3dnow);
  2686. SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, 3dnow);
  2687. SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, 3dnow);
  2688. SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, 3dnow);
  2689. SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, 3dnow);
  2690. c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_3dnow_rnd;
  2691. c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_3dnow;
  2692. c->avg_rv40_chroma_pixels_tab[0]= avg_rv40_chroma_mc8_3dnow;
  2693. c->avg_rv40_chroma_pixels_tab[1]= avg_rv40_chroma_mc4_3dnow;
  2694. if (CONFIG_CAVS_DECODER)
  2695. ff_cavsdsp_init_3dnow(c, avctx);
  2696. }
  2697. #define H264_QPEL_FUNCS(x, y, CPU)\
  2698. c->put_h264_qpel_pixels_tab[0][x+y*4] = put_h264_qpel16_mc##x##y##_##CPU;\
  2699. c->put_h264_qpel_pixels_tab[1][x+y*4] = put_h264_qpel8_mc##x##y##_##CPU;\
  2700. c->avg_h264_qpel_pixels_tab[0][x+y*4] = avg_h264_qpel16_mc##x##y##_##CPU;\
  2701. c->avg_h264_qpel_pixels_tab[1][x+y*4] = avg_h264_qpel8_mc##x##y##_##CPU;
  2702. if((mm_flags & FF_MM_SSE2) && !(mm_flags & FF_MM_3DNOW)){
  2703. // these functions are slower than mmx on AMD, but faster on Intel
  2704. /* FIXME works in most codecs, but crashes svq1 due to unaligned chroma
  2705. c->put_pixels_tab[0][0] = put_pixels16_sse2;
  2706. c->avg_pixels_tab[0][0] = avg_pixels16_sse2;
  2707. */
  2708. H264_QPEL_FUNCS(0, 0, sse2);
  2709. }
  2710. if(mm_flags & FF_MM_SSE2){
  2711. c->h264_idct8_add = ff_h264_idct8_add_sse2;
  2712. c->h264_idct8_add4= ff_h264_idct8_add4_sse2;
  2713. H264_QPEL_FUNCS(0, 1, sse2);
  2714. H264_QPEL_FUNCS(0, 2, sse2);
  2715. H264_QPEL_FUNCS(0, 3, sse2);
  2716. H264_QPEL_FUNCS(1, 1, sse2);
  2717. H264_QPEL_FUNCS(1, 2, sse2);
  2718. H264_QPEL_FUNCS(1, 3, sse2);
  2719. H264_QPEL_FUNCS(2, 1, sse2);
  2720. H264_QPEL_FUNCS(2, 2, sse2);
  2721. H264_QPEL_FUNCS(2, 3, sse2);
  2722. H264_QPEL_FUNCS(3, 1, sse2);
  2723. H264_QPEL_FUNCS(3, 2, sse2);
  2724. H264_QPEL_FUNCS(3, 3, sse2);
  2725. if (CONFIG_VP6_DECODER) {
  2726. c->vp6_filter_diag4 = ff_vp6_filter_diag4_sse2;
  2727. }
  2728. }
  2729. #if HAVE_SSSE3
  2730. if(mm_flags & FF_MM_SSSE3){
  2731. H264_QPEL_FUNCS(1, 0, ssse3);
  2732. H264_QPEL_FUNCS(1, 1, ssse3);
  2733. H264_QPEL_FUNCS(1, 2, ssse3);
  2734. H264_QPEL_FUNCS(1, 3, ssse3);
  2735. H264_QPEL_FUNCS(2, 0, ssse3);
  2736. H264_QPEL_FUNCS(2, 1, ssse3);
  2737. H264_QPEL_FUNCS(2, 2, ssse3);
  2738. H264_QPEL_FUNCS(2, 3, ssse3);
  2739. H264_QPEL_FUNCS(3, 0, ssse3);
  2740. H264_QPEL_FUNCS(3, 1, ssse3);
  2741. H264_QPEL_FUNCS(3, 2, ssse3);
  2742. H264_QPEL_FUNCS(3, 3, ssse3);
  2743. c->put_no_rnd_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_ssse3_nornd;
  2744. c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_ssse3_rnd;
  2745. c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_ssse3_rnd;
  2746. c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_ssse3;
  2747. c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_ssse3;
  2748. c->add_png_paeth_prediction= add_png_paeth_prediction_ssse3;
  2749. }
  2750. #endif
  2751. #if CONFIG_GPL && HAVE_YASM
  2752. if( mm_flags&FF_MM_MMXEXT ){
  2753. #if ARCH_X86_32
  2754. c->h264_v_loop_filter_luma_intra = ff_x264_deblock_v_luma_intra_mmxext;
  2755. c->h264_h_loop_filter_luma_intra = ff_x264_deblock_h_luma_intra_mmxext;
  2756. #endif
  2757. if( mm_flags&FF_MM_SSE2 ){
  2758. #if ARCH_X86_64 || !defined(__ICC) || __ICC > 1100
  2759. c->h264_v_loop_filter_luma = ff_x264_deblock_v_luma_sse2;
  2760. c->h264_h_loop_filter_luma = ff_x264_deblock_h_luma_sse2;
  2761. c->h264_v_loop_filter_luma_intra = ff_x264_deblock_v_luma_intra_sse2;
  2762. c->h264_h_loop_filter_luma_intra = ff_x264_deblock_h_luma_intra_sse2;
  2763. #endif
  2764. c->h264_idct_add16 = ff_h264_idct_add16_sse2;
  2765. c->h264_idct_add8 = ff_h264_idct_add8_sse2;
  2766. c->h264_idct_add16intra = ff_h264_idct_add16intra_sse2;
  2767. }
  2768. }
  2769. #endif
  2770. #if CONFIG_SNOW_DECODER
  2771. if(mm_flags & FF_MM_SSE2 & 0){
  2772. c->horizontal_compose97i = ff_snow_horizontal_compose97i_sse2;
  2773. #if HAVE_7REGS
  2774. c->vertical_compose97i = ff_snow_vertical_compose97i_sse2;
  2775. #endif
  2776. c->inner_add_yblock = ff_snow_inner_add_yblock_sse2;
  2777. }
  2778. else{
  2779. if(mm_flags & FF_MM_MMXEXT){
  2780. c->horizontal_compose97i = ff_snow_horizontal_compose97i_mmx;
  2781. #if HAVE_7REGS
  2782. c->vertical_compose97i = ff_snow_vertical_compose97i_mmx;
  2783. #endif
  2784. }
  2785. c->inner_add_yblock = ff_snow_inner_add_yblock_mmx;
  2786. }
  2787. #endif
  2788. if(mm_flags & FF_MM_3DNOW){
  2789. c->vorbis_inverse_coupling = vorbis_inverse_coupling_3dnow;
  2790. c->vector_fmul = vector_fmul_3dnow;
  2791. if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
  2792. c->float_to_int16 = float_to_int16_3dnow;
  2793. c->float_to_int16_interleave = float_to_int16_interleave_3dnow;
  2794. }
  2795. }
  2796. if(mm_flags & FF_MM_3DNOWEXT){
  2797. c->vector_fmul_reverse = vector_fmul_reverse_3dnow2;
  2798. c->vector_fmul_window = vector_fmul_window_3dnow2;
  2799. if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
  2800. c->float_to_int16_interleave = float_to_int16_interleave_3dn2;
  2801. }
  2802. }
  2803. if(mm_flags & FF_MM_SSE){
  2804. c->vorbis_inverse_coupling = vorbis_inverse_coupling_sse;
  2805. c->ac3_downmix = ac3_downmix_sse;
  2806. c->vector_fmul = vector_fmul_sse;
  2807. c->vector_fmul_reverse = vector_fmul_reverse_sse;
  2808. c->vector_fmul_add_add = vector_fmul_add_add_sse;
  2809. c->vector_fmul_window = vector_fmul_window_sse;
  2810. c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse;
  2811. c->float_to_int16 = float_to_int16_sse;
  2812. c->float_to_int16_interleave = float_to_int16_interleave_sse;
  2813. }
  2814. if(mm_flags & FF_MM_3DNOW)
  2815. c->vector_fmul_add_add = vector_fmul_add_add_3dnow; // faster than sse
  2816. if(mm_flags & FF_MM_SSE2){
  2817. c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse2;
  2818. c->float_to_int16 = float_to_int16_sse2;
  2819. c->float_to_int16_interleave = float_to_int16_interleave_sse2;
  2820. c->add_int16 = add_int16_sse2;
  2821. c->sub_int16 = sub_int16_sse2;
  2822. c->scalarproduct_int16 = scalarproduct_int16_sse2;
  2823. }
  2824. }
  2825. if (CONFIG_ENCODERS)
  2826. dsputilenc_init_mmx(c, avctx);
  2827. #if 0
  2828. // for speed testing
  2829. get_pixels = just_return;
  2830. put_pixels_clamped = just_return;
  2831. add_pixels_clamped = just_return;
  2832. pix_abs16x16 = just_return;
  2833. pix_abs16x16_x2 = just_return;
  2834. pix_abs16x16_y2 = just_return;
  2835. pix_abs16x16_xy2 = just_return;
  2836. put_pixels_tab[0] = just_return;
  2837. put_pixels_tab[1] = just_return;
  2838. put_pixels_tab[2] = just_return;
  2839. put_pixels_tab[3] = just_return;
  2840. put_no_rnd_pixels_tab[0] = just_return;
  2841. put_no_rnd_pixels_tab[1] = just_return;
  2842. put_no_rnd_pixels_tab[2] = just_return;
  2843. put_no_rnd_pixels_tab[3] = just_return;
  2844. avg_pixels_tab[0] = just_return;
  2845. avg_pixels_tab[1] = just_return;
  2846. avg_pixels_tab[2] = just_return;
  2847. avg_pixels_tab[3] = just_return;
  2848. avg_no_rnd_pixels_tab[0] = just_return;
  2849. avg_no_rnd_pixels_tab[1] = just_return;
  2850. avg_no_rnd_pixels_tab[2] = just_return;
  2851. avg_no_rnd_pixels_tab[3] = just_return;
  2852. //av_fdct = just_return;
  2853. //ff_idct = just_return;
  2854. #endif
  2855. }