rgb2rgb_template.c 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452
  1. /*
  2. * software RGB to RGB converter
  3. * pluralize by software PAL8 to RGB converter
  4. * software YUV to YUV converter
  5. * software YUV to RGB converter
  6. * Written by Nick Kurshev.
  7. * palette & YUV & runtime CPU stuff by Michael (michaelni@gmx.at)
  8. * lot of big-endian byte order fixes by Alex Beregszaszi
  9. *
  10. * This file is part of FFmpeg.
  11. *
  12. * FFmpeg is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU Lesser General Public
  14. * License as published by the Free Software Foundation; either
  15. * version 2.1 of the License, or (at your option) any later version.
  16. *
  17. * FFmpeg is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public
  23. * License along with FFmpeg; if not, write to the Free Software
  24. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  25. */
  26. #include <stddef.h>
  27. #include <stdint.h>
  28. #include "libavutil/attributes.h"
  29. #include "libavutil/x86/asm.h"
  30. #undef PREFETCH
  31. #undef MOVNTQ
  32. #undef EMMS
  33. #undef SFENCE
  34. #undef PAVGB
  35. #define PREFETCH "prefetchnta"
  36. #define PAVGB "pavgb"
  37. #define MOVNTQ "movntq"
  38. #define SFENCE "sfence"
  39. #define EMMS "emms"
  40. #if !COMPILE_TEMPLATE_SSE2
  41. static inline void RENAME(rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size)
  42. {
  43. uint8_t *dest = dst;
  44. const uint8_t *s = src;
  45. const uint8_t *end;
  46. const uint8_t *mm_end;
  47. end = s + src_size;
  48. __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory");
  49. mm_end = end - 23;
  50. __asm__ volatile("movq %0, %%mm7"::"m"(mask32a):"memory");
  51. while (s < mm_end) {
  52. __asm__ volatile(
  53. PREFETCH" 32(%1) \n\t"
  54. "movd (%1), %%mm0 \n\t"
  55. "punpckldq 3(%1), %%mm0 \n\t"
  56. "movd 6(%1), %%mm1 \n\t"
  57. "punpckldq 9(%1), %%mm1 \n\t"
  58. "movd 12(%1), %%mm2 \n\t"
  59. "punpckldq 15(%1), %%mm2 \n\t"
  60. "movd 18(%1), %%mm3 \n\t"
  61. "punpckldq 21(%1), %%mm3 \n\t"
  62. "por %%mm7, %%mm0 \n\t"
  63. "por %%mm7, %%mm1 \n\t"
  64. "por %%mm7, %%mm2 \n\t"
  65. "por %%mm7, %%mm3 \n\t"
  66. MOVNTQ" %%mm0, (%0) \n\t"
  67. MOVNTQ" %%mm1, 8(%0) \n\t"
  68. MOVNTQ" %%mm2, 16(%0) \n\t"
  69. MOVNTQ" %%mm3, 24(%0)"
  70. :: "r"(dest), "r"(s)
  71. :"memory");
  72. dest += 32;
  73. s += 24;
  74. }
  75. __asm__ volatile(SFENCE:::"memory");
  76. __asm__ volatile(EMMS:::"memory");
  77. while (s < end) {
  78. *dest++ = *s++;
  79. *dest++ = *s++;
  80. *dest++ = *s++;
  81. *dest++ = 255;
  82. }
  83. }
  84. #define STORE_BGR24_MMX \
  85. "psrlq $8, %%mm2 \n\t" \
  86. "psrlq $8, %%mm3 \n\t" \
  87. "psrlq $8, %%mm6 \n\t" \
  88. "psrlq $8, %%mm7 \n\t" \
  89. "pand "MANGLE(mask24l)", %%mm0\n\t" \
  90. "pand "MANGLE(mask24l)", %%mm1\n\t" \
  91. "pand "MANGLE(mask24l)", %%mm4\n\t" \
  92. "pand "MANGLE(mask24l)", %%mm5\n\t" \
  93. "pand "MANGLE(mask24h)", %%mm2\n\t" \
  94. "pand "MANGLE(mask24h)", %%mm3\n\t" \
  95. "pand "MANGLE(mask24h)", %%mm6\n\t" \
  96. "pand "MANGLE(mask24h)", %%mm7\n\t" \
  97. "por %%mm2, %%mm0 \n\t" \
  98. "por %%mm3, %%mm1 \n\t" \
  99. "por %%mm6, %%mm4 \n\t" \
  100. "por %%mm7, %%mm5 \n\t" \
  101. \
  102. "movq %%mm1, %%mm2 \n\t" \
  103. "movq %%mm4, %%mm3 \n\t" \
  104. "psllq $48, %%mm2 \n\t" \
  105. "psllq $32, %%mm3 \n\t" \
  106. "por %%mm2, %%mm0 \n\t" \
  107. "psrlq $16, %%mm1 \n\t" \
  108. "psrlq $32, %%mm4 \n\t" \
  109. "psllq $16, %%mm5 \n\t" \
  110. "por %%mm3, %%mm1 \n\t" \
  111. "por %%mm5, %%mm4 \n\t" \
  112. \
  113. MOVNTQ" %%mm0, (%0) \n\t" \
  114. MOVNTQ" %%mm1, 8(%0) \n\t" \
  115. MOVNTQ" %%mm4, 16(%0)"
  116. static inline void RENAME(rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
  117. {
  118. uint8_t *dest = dst;
  119. const uint8_t *s = src;
  120. const uint8_t *end;
  121. const uint8_t *mm_end;
  122. end = s + src_size;
  123. __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory");
  124. mm_end = end - 31;
  125. while (s < mm_end) {
  126. __asm__ volatile(
  127. PREFETCH" 32(%1) \n\t"
  128. "movq (%1), %%mm0 \n\t"
  129. "movq 8(%1), %%mm1 \n\t"
  130. "movq 16(%1), %%mm4 \n\t"
  131. "movq 24(%1), %%mm5 \n\t"
  132. "movq %%mm0, %%mm2 \n\t"
  133. "movq %%mm1, %%mm3 \n\t"
  134. "movq %%mm4, %%mm6 \n\t"
  135. "movq %%mm5, %%mm7 \n\t"
  136. STORE_BGR24_MMX
  137. :: "r"(dest), "r"(s)
  138. NAMED_CONSTRAINTS_ADD(mask24l,mask24h)
  139. :"memory");
  140. dest += 24;
  141. s += 32;
  142. }
  143. __asm__ volatile(SFENCE:::"memory");
  144. __asm__ volatile(EMMS:::"memory");
  145. while (s < end) {
  146. *dest++ = *s++;
  147. *dest++ = *s++;
  148. *dest++ = *s++;
  149. s++;
  150. }
  151. }
  152. /*
  153. original by Strepto/Astral
  154. ported to gcc & bugfixed: A'rpi
  155. MMXEXT, 3DNOW optimization by Nick Kurshev
  156. 32-bit C version, and and&add trick by Michael Niedermayer
  157. */
  158. static inline void RENAME(rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size)
  159. {
  160. register const uint8_t* s=src;
  161. register uint8_t* d=dst;
  162. register const uint8_t *end;
  163. const uint8_t *mm_end;
  164. end = s + src_size;
  165. __asm__ volatile(PREFETCH" %0"::"m"(*s));
  166. __asm__ volatile("movq %0, %%mm4"::"m"(mask15s));
  167. mm_end = end - 15;
  168. while (s<mm_end) {
  169. __asm__ volatile(
  170. PREFETCH" 32(%1) \n\t"
  171. "movq (%1), %%mm0 \n\t"
  172. "movq 8(%1), %%mm2 \n\t"
  173. "movq %%mm0, %%mm1 \n\t"
  174. "movq %%mm2, %%mm3 \n\t"
  175. "pand %%mm4, %%mm0 \n\t"
  176. "pand %%mm4, %%mm2 \n\t"
  177. "paddw %%mm1, %%mm0 \n\t"
  178. "paddw %%mm3, %%mm2 \n\t"
  179. MOVNTQ" %%mm0, (%0) \n\t"
  180. MOVNTQ" %%mm2, 8(%0)"
  181. :: "r"(d), "r"(s)
  182. );
  183. d+=16;
  184. s+=16;
  185. }
  186. __asm__ volatile(SFENCE:::"memory");
  187. __asm__ volatile(EMMS:::"memory");
  188. mm_end = end - 3;
  189. while (s < mm_end) {
  190. register unsigned x= *((const uint32_t *)s);
  191. *((uint32_t *)d) = (x&0x7FFF7FFF) + (x&0x7FE07FE0);
  192. d+=4;
  193. s+=4;
  194. }
  195. if (s < end) {
  196. register unsigned short x= *((const uint16_t *)s);
  197. *((uint16_t *)d) = (x&0x7FFF) + (x&0x7FE0);
  198. }
  199. }
  200. static inline void RENAME(rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size)
  201. {
  202. register const uint8_t* s=src;
  203. register uint8_t* d=dst;
  204. register const uint8_t *end;
  205. const uint8_t *mm_end;
  206. end = s + src_size;
  207. __asm__ volatile(PREFETCH" %0"::"m"(*s));
  208. __asm__ volatile("movq %0, %%mm7"::"m"(mask15rg));
  209. __asm__ volatile("movq %0, %%mm6"::"m"(mask15b));
  210. mm_end = end - 15;
  211. while (s<mm_end) {
  212. __asm__ volatile(
  213. PREFETCH" 32(%1) \n\t"
  214. "movq (%1), %%mm0 \n\t"
  215. "movq 8(%1), %%mm2 \n\t"
  216. "movq %%mm0, %%mm1 \n\t"
  217. "movq %%mm2, %%mm3 \n\t"
  218. "psrlq $1, %%mm0 \n\t"
  219. "psrlq $1, %%mm2 \n\t"
  220. "pand %%mm7, %%mm0 \n\t"
  221. "pand %%mm7, %%mm2 \n\t"
  222. "pand %%mm6, %%mm1 \n\t"
  223. "pand %%mm6, %%mm3 \n\t"
  224. "por %%mm1, %%mm0 \n\t"
  225. "por %%mm3, %%mm2 \n\t"
  226. MOVNTQ" %%mm0, (%0) \n\t"
  227. MOVNTQ" %%mm2, 8(%0)"
  228. :: "r"(d), "r"(s)
  229. );
  230. d+=16;
  231. s+=16;
  232. }
  233. __asm__ volatile(SFENCE:::"memory");
  234. __asm__ volatile(EMMS:::"memory");
  235. mm_end = end - 3;
  236. while (s < mm_end) {
  237. register uint32_t x= *((const uint32_t*)s);
  238. *((uint32_t *)d) = ((x>>1)&0x7FE07FE0) | (x&0x001F001F);
  239. s+=4;
  240. d+=4;
  241. }
  242. if (s < end) {
  243. register uint16_t x= *((const uint16_t*)s);
  244. *((uint16_t *)d) = ((x>>1)&0x7FE0) | (x&0x001F);
  245. }
  246. }
  247. static inline void RENAME(rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size)
  248. {
  249. const uint8_t *s = src;
  250. const uint8_t *end;
  251. const uint8_t *mm_end;
  252. uint16_t *d = (uint16_t *)dst;
  253. end = s + src_size;
  254. mm_end = end - 15;
  255. __asm__ volatile(
  256. "movq %3, %%mm5 \n\t"
  257. "movq %4, %%mm6 \n\t"
  258. "movq %5, %%mm7 \n\t"
  259. "jmp 2f \n\t"
  260. ".p2align 4 \n\t"
  261. "1: \n\t"
  262. PREFETCH" 32(%1) \n\t"
  263. "movd (%1), %%mm0 \n\t"
  264. "movd 4(%1), %%mm3 \n\t"
  265. "punpckldq 8(%1), %%mm0 \n\t"
  266. "punpckldq 12(%1), %%mm3 \n\t"
  267. "movq %%mm0, %%mm1 \n\t"
  268. "movq %%mm3, %%mm4 \n\t"
  269. "pand %%mm6, %%mm0 \n\t"
  270. "pand %%mm6, %%mm3 \n\t"
  271. "pmaddwd %%mm7, %%mm0 \n\t"
  272. "pmaddwd %%mm7, %%mm3 \n\t"
  273. "pand %%mm5, %%mm1 \n\t"
  274. "pand %%mm5, %%mm4 \n\t"
  275. "por %%mm1, %%mm0 \n\t"
  276. "por %%mm4, %%mm3 \n\t"
  277. "psrld $5, %%mm0 \n\t"
  278. "pslld $11, %%mm3 \n\t"
  279. "por %%mm3, %%mm0 \n\t"
  280. MOVNTQ" %%mm0, (%0) \n\t"
  281. "add $16, %1 \n\t"
  282. "add $8, %0 \n\t"
  283. "2: \n\t"
  284. "cmp %2, %1 \n\t"
  285. " jb 1b \n\t"
  286. : "+r" (d), "+r"(s)
  287. : "r" (mm_end), "m" (mask3216g), "m" (mask3216br), "m" (mul3216)
  288. );
  289. __asm__ volatile(SFENCE:::"memory");
  290. __asm__ volatile(EMMS:::"memory");
  291. while (s < end) {
  292. register int rgb = *(const uint32_t*)s; s += 4;
  293. *d++ = ((rgb&0xFF)>>3) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>8);
  294. }
  295. }
  296. static inline void RENAME(rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size)
  297. {
  298. const uint8_t *s = src;
  299. const uint8_t *end;
  300. const uint8_t *mm_end;
  301. uint16_t *d = (uint16_t *)dst;
  302. end = s + src_size;
  303. __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory");
  304. __asm__ volatile(
  305. "movq %0, %%mm7 \n\t"
  306. "movq %1, %%mm6 \n\t"
  307. ::"m"(red_16mask),"m"(green_16mask));
  308. mm_end = end - 15;
  309. while (s < mm_end) {
  310. __asm__ volatile(
  311. PREFETCH" 32(%1) \n\t"
  312. "movd (%1), %%mm0 \n\t"
  313. "movd 4(%1), %%mm3 \n\t"
  314. "punpckldq 8(%1), %%mm0 \n\t"
  315. "punpckldq 12(%1), %%mm3 \n\t"
  316. "movq %%mm0, %%mm1 \n\t"
  317. "movq %%mm0, %%mm2 \n\t"
  318. "movq %%mm3, %%mm4 \n\t"
  319. "movq %%mm3, %%mm5 \n\t"
  320. "psllq $8, %%mm0 \n\t"
  321. "psllq $8, %%mm3 \n\t"
  322. "pand %%mm7, %%mm0 \n\t"
  323. "pand %%mm7, %%mm3 \n\t"
  324. "psrlq $5, %%mm1 \n\t"
  325. "psrlq $5, %%mm4 \n\t"
  326. "pand %%mm6, %%mm1 \n\t"
  327. "pand %%mm6, %%mm4 \n\t"
  328. "psrlq $19, %%mm2 \n\t"
  329. "psrlq $19, %%mm5 \n\t"
  330. "pand %2, %%mm2 \n\t"
  331. "pand %2, %%mm5 \n\t"
  332. "por %%mm1, %%mm0 \n\t"
  333. "por %%mm4, %%mm3 \n\t"
  334. "por %%mm2, %%mm0 \n\t"
  335. "por %%mm5, %%mm3 \n\t"
  336. "psllq $16, %%mm3 \n\t"
  337. "por %%mm3, %%mm0 \n\t"
  338. MOVNTQ" %%mm0, (%0) \n\t"
  339. :: "r"(d),"r"(s),"m"(blue_16mask):"memory");
  340. d += 4;
  341. s += 16;
  342. }
  343. __asm__ volatile(SFENCE:::"memory");
  344. __asm__ volatile(EMMS:::"memory");
  345. while (s < end) {
  346. register int rgb = *(const uint32_t*)s; s += 4;
  347. *d++ = ((rgb&0xF8)<<8) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>19);
  348. }
  349. }
  350. static inline void RENAME(rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size)
  351. {
  352. const uint8_t *s = src;
  353. const uint8_t *end;
  354. const uint8_t *mm_end;
  355. uint16_t *d = (uint16_t *)dst;
  356. end = s + src_size;
  357. mm_end = end - 15;
  358. __asm__ volatile(
  359. "movq %3, %%mm5 \n\t"
  360. "movq %4, %%mm6 \n\t"
  361. "movq %5, %%mm7 \n\t"
  362. "jmp 2f \n\t"
  363. ".p2align 4 \n\t"
  364. "1: \n\t"
  365. PREFETCH" 32(%1) \n\t"
  366. "movd (%1), %%mm0 \n\t"
  367. "movd 4(%1), %%mm3 \n\t"
  368. "punpckldq 8(%1), %%mm0 \n\t"
  369. "punpckldq 12(%1), %%mm3 \n\t"
  370. "movq %%mm0, %%mm1 \n\t"
  371. "movq %%mm3, %%mm4 \n\t"
  372. "pand %%mm6, %%mm0 \n\t"
  373. "pand %%mm6, %%mm3 \n\t"
  374. "pmaddwd %%mm7, %%mm0 \n\t"
  375. "pmaddwd %%mm7, %%mm3 \n\t"
  376. "pand %%mm5, %%mm1 \n\t"
  377. "pand %%mm5, %%mm4 \n\t"
  378. "por %%mm1, %%mm0 \n\t"
  379. "por %%mm4, %%mm3 \n\t"
  380. "psrld $6, %%mm0 \n\t"
  381. "pslld $10, %%mm3 \n\t"
  382. "por %%mm3, %%mm0 \n\t"
  383. MOVNTQ" %%mm0, (%0) \n\t"
  384. "add $16, %1 \n\t"
  385. "add $8, %0 \n\t"
  386. "2: \n\t"
  387. "cmp %2, %1 \n\t"
  388. " jb 1b \n\t"
  389. : "+r" (d), "+r"(s)
  390. : "r" (mm_end), "m" (mask3215g), "m" (mask3216br), "m" (mul3215)
  391. );
  392. __asm__ volatile(SFENCE:::"memory");
  393. __asm__ volatile(EMMS:::"memory");
  394. while (s < end) {
  395. register int rgb = *(const uint32_t*)s; s += 4;
  396. *d++ = ((rgb&0xFF)>>3) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>9);
  397. }
  398. }
  399. static inline void RENAME(rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size)
  400. {
  401. const uint8_t *s = src;
  402. const uint8_t *end;
  403. const uint8_t *mm_end;
  404. uint16_t *d = (uint16_t *)dst;
  405. end = s + src_size;
  406. __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory");
  407. __asm__ volatile(
  408. "movq %0, %%mm7 \n\t"
  409. "movq %1, %%mm6 \n\t"
  410. ::"m"(red_15mask),"m"(green_15mask));
  411. mm_end = end - 15;
  412. while (s < mm_end) {
  413. __asm__ volatile(
  414. PREFETCH" 32(%1) \n\t"
  415. "movd (%1), %%mm0 \n\t"
  416. "movd 4(%1), %%mm3 \n\t"
  417. "punpckldq 8(%1), %%mm0 \n\t"
  418. "punpckldq 12(%1), %%mm3 \n\t"
  419. "movq %%mm0, %%mm1 \n\t"
  420. "movq %%mm0, %%mm2 \n\t"
  421. "movq %%mm3, %%mm4 \n\t"
  422. "movq %%mm3, %%mm5 \n\t"
  423. "psllq $7, %%mm0 \n\t"
  424. "psllq $7, %%mm3 \n\t"
  425. "pand %%mm7, %%mm0 \n\t"
  426. "pand %%mm7, %%mm3 \n\t"
  427. "psrlq $6, %%mm1 \n\t"
  428. "psrlq $6, %%mm4 \n\t"
  429. "pand %%mm6, %%mm1 \n\t"
  430. "pand %%mm6, %%mm4 \n\t"
  431. "psrlq $19, %%mm2 \n\t"
  432. "psrlq $19, %%mm5 \n\t"
  433. "pand %2, %%mm2 \n\t"
  434. "pand %2, %%mm5 \n\t"
  435. "por %%mm1, %%mm0 \n\t"
  436. "por %%mm4, %%mm3 \n\t"
  437. "por %%mm2, %%mm0 \n\t"
  438. "por %%mm5, %%mm3 \n\t"
  439. "psllq $16, %%mm3 \n\t"
  440. "por %%mm3, %%mm0 \n\t"
  441. MOVNTQ" %%mm0, (%0) \n\t"
  442. ::"r"(d),"r"(s),"m"(blue_15mask):"memory");
  443. d += 4;
  444. s += 16;
  445. }
  446. __asm__ volatile(SFENCE:::"memory");
  447. __asm__ volatile(EMMS:::"memory");
  448. while (s < end) {
  449. register int rgb = *(const uint32_t*)s; s += 4;
  450. *d++ = ((rgb&0xF8)<<7) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>19);
  451. }
  452. }
  453. static inline void RENAME(rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size)
  454. {
  455. const uint8_t *s = src;
  456. const uint8_t *end;
  457. const uint8_t *mm_end;
  458. uint16_t *d = (uint16_t *)dst;
  459. end = s + src_size;
  460. __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory");
  461. __asm__ volatile(
  462. "movq %0, %%mm7 \n\t"
  463. "movq %1, %%mm6 \n\t"
  464. ::"m"(red_16mask),"m"(green_16mask));
  465. mm_end = end - 11;
  466. while (s < mm_end) {
  467. __asm__ volatile(
  468. PREFETCH" 32(%1) \n\t"
  469. "movd (%1), %%mm0 \n\t"
  470. "movd 3(%1), %%mm3 \n\t"
  471. "punpckldq 6(%1), %%mm0 \n\t"
  472. "punpckldq 9(%1), %%mm3 \n\t"
  473. "movq %%mm0, %%mm1 \n\t"
  474. "movq %%mm0, %%mm2 \n\t"
  475. "movq %%mm3, %%mm4 \n\t"
  476. "movq %%mm3, %%mm5 \n\t"
  477. "psrlq $3, %%mm0 \n\t"
  478. "psrlq $3, %%mm3 \n\t"
  479. "pand %2, %%mm0 \n\t"
  480. "pand %2, %%mm3 \n\t"
  481. "psrlq $5, %%mm1 \n\t"
  482. "psrlq $5, %%mm4 \n\t"
  483. "pand %%mm6, %%mm1 \n\t"
  484. "pand %%mm6, %%mm4 \n\t"
  485. "psrlq $8, %%mm2 \n\t"
  486. "psrlq $8, %%mm5 \n\t"
  487. "pand %%mm7, %%mm2 \n\t"
  488. "pand %%mm7, %%mm5 \n\t"
  489. "por %%mm1, %%mm0 \n\t"
  490. "por %%mm4, %%mm3 \n\t"
  491. "por %%mm2, %%mm0 \n\t"
  492. "por %%mm5, %%mm3 \n\t"
  493. "psllq $16, %%mm3 \n\t"
  494. "por %%mm3, %%mm0 \n\t"
  495. MOVNTQ" %%mm0, (%0) \n\t"
  496. ::"r"(d),"r"(s),"m"(blue_16mask):"memory");
  497. d += 4;
  498. s += 12;
  499. }
  500. __asm__ volatile(SFENCE:::"memory");
  501. __asm__ volatile(EMMS:::"memory");
  502. while (s < end) {
  503. const int b = *s++;
  504. const int g = *s++;
  505. const int r = *s++;
  506. *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8);
  507. }
  508. }
  509. static inline void RENAME(rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size)
  510. {
  511. const uint8_t *s = src;
  512. const uint8_t *end;
  513. const uint8_t *mm_end;
  514. uint16_t *d = (uint16_t *)dst;
  515. end = s + src_size;
  516. __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory");
  517. __asm__ volatile(
  518. "movq %0, %%mm7 \n\t"
  519. "movq %1, %%mm6 \n\t"
  520. ::"m"(red_16mask),"m"(green_16mask));
  521. mm_end = end - 15;
  522. while (s < mm_end) {
  523. __asm__ volatile(
  524. PREFETCH" 32(%1) \n\t"
  525. "movd (%1), %%mm0 \n\t"
  526. "movd 3(%1), %%mm3 \n\t"
  527. "punpckldq 6(%1), %%mm0 \n\t"
  528. "punpckldq 9(%1), %%mm3 \n\t"
  529. "movq %%mm0, %%mm1 \n\t"
  530. "movq %%mm0, %%mm2 \n\t"
  531. "movq %%mm3, %%mm4 \n\t"
  532. "movq %%mm3, %%mm5 \n\t"
  533. "psllq $8, %%mm0 \n\t"
  534. "psllq $8, %%mm3 \n\t"
  535. "pand %%mm7, %%mm0 \n\t"
  536. "pand %%mm7, %%mm3 \n\t"
  537. "psrlq $5, %%mm1 \n\t"
  538. "psrlq $5, %%mm4 \n\t"
  539. "pand %%mm6, %%mm1 \n\t"
  540. "pand %%mm6, %%mm4 \n\t"
  541. "psrlq $19, %%mm2 \n\t"
  542. "psrlq $19, %%mm5 \n\t"
  543. "pand %2, %%mm2 \n\t"
  544. "pand %2, %%mm5 \n\t"
  545. "por %%mm1, %%mm0 \n\t"
  546. "por %%mm4, %%mm3 \n\t"
  547. "por %%mm2, %%mm0 \n\t"
  548. "por %%mm5, %%mm3 \n\t"
  549. "psllq $16, %%mm3 \n\t"
  550. "por %%mm3, %%mm0 \n\t"
  551. MOVNTQ" %%mm0, (%0) \n\t"
  552. ::"r"(d),"r"(s),"m"(blue_16mask):"memory");
  553. d += 4;
  554. s += 12;
  555. }
  556. __asm__ volatile(SFENCE:::"memory");
  557. __asm__ volatile(EMMS:::"memory");
  558. while (s < end) {
  559. const int r = *s++;
  560. const int g = *s++;
  561. const int b = *s++;
  562. *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8);
  563. }
  564. }
  565. static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size)
  566. {
  567. const uint8_t *s = src;
  568. const uint8_t *end;
  569. const uint8_t *mm_end;
  570. uint16_t *d = (uint16_t *)dst;
  571. end = s + src_size;
  572. __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory");
  573. __asm__ volatile(
  574. "movq %0, %%mm7 \n\t"
  575. "movq %1, %%mm6 \n\t"
  576. ::"m"(red_15mask),"m"(green_15mask));
  577. mm_end = end - 11;
  578. while (s < mm_end) {
  579. __asm__ volatile(
  580. PREFETCH" 32(%1) \n\t"
  581. "movd (%1), %%mm0 \n\t"
  582. "movd 3(%1), %%mm3 \n\t"
  583. "punpckldq 6(%1), %%mm0 \n\t"
  584. "punpckldq 9(%1), %%mm3 \n\t"
  585. "movq %%mm0, %%mm1 \n\t"
  586. "movq %%mm0, %%mm2 \n\t"
  587. "movq %%mm3, %%mm4 \n\t"
  588. "movq %%mm3, %%mm5 \n\t"
  589. "psrlq $3, %%mm0 \n\t"
  590. "psrlq $3, %%mm3 \n\t"
  591. "pand %2, %%mm0 \n\t"
  592. "pand %2, %%mm3 \n\t"
  593. "psrlq $6, %%mm1 \n\t"
  594. "psrlq $6, %%mm4 \n\t"
  595. "pand %%mm6, %%mm1 \n\t"
  596. "pand %%mm6, %%mm4 \n\t"
  597. "psrlq $9, %%mm2 \n\t"
  598. "psrlq $9, %%mm5 \n\t"
  599. "pand %%mm7, %%mm2 \n\t"
  600. "pand %%mm7, %%mm5 \n\t"
  601. "por %%mm1, %%mm0 \n\t"
  602. "por %%mm4, %%mm3 \n\t"
  603. "por %%mm2, %%mm0 \n\t"
  604. "por %%mm5, %%mm3 \n\t"
  605. "psllq $16, %%mm3 \n\t"
  606. "por %%mm3, %%mm0 \n\t"
  607. MOVNTQ" %%mm0, (%0) \n\t"
  608. ::"r"(d),"r"(s),"m"(blue_15mask):"memory");
  609. d += 4;
  610. s += 12;
  611. }
  612. __asm__ volatile(SFENCE:::"memory");
  613. __asm__ volatile(EMMS:::"memory");
  614. while (s < end) {
  615. const int b = *s++;
  616. const int g = *s++;
  617. const int r = *s++;
  618. *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7);
  619. }
  620. }
  621. static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size)
  622. {
  623. const uint8_t *s = src;
  624. const uint8_t *end;
  625. const uint8_t *mm_end;
  626. uint16_t *d = (uint16_t *)dst;
  627. end = s + src_size;
  628. __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory");
  629. __asm__ volatile(
  630. "movq %0, %%mm7 \n\t"
  631. "movq %1, %%mm6 \n\t"
  632. ::"m"(red_15mask),"m"(green_15mask));
  633. mm_end = end - 15;
  634. while (s < mm_end) {
  635. __asm__ volatile(
  636. PREFETCH" 32(%1) \n\t"
  637. "movd (%1), %%mm0 \n\t"
  638. "movd 3(%1), %%mm3 \n\t"
  639. "punpckldq 6(%1), %%mm0 \n\t"
  640. "punpckldq 9(%1), %%mm3 \n\t"
  641. "movq %%mm0, %%mm1 \n\t"
  642. "movq %%mm0, %%mm2 \n\t"
  643. "movq %%mm3, %%mm4 \n\t"
  644. "movq %%mm3, %%mm5 \n\t"
  645. "psllq $7, %%mm0 \n\t"
  646. "psllq $7, %%mm3 \n\t"
  647. "pand %%mm7, %%mm0 \n\t"
  648. "pand %%mm7, %%mm3 \n\t"
  649. "psrlq $6, %%mm1 \n\t"
  650. "psrlq $6, %%mm4 \n\t"
  651. "pand %%mm6, %%mm1 \n\t"
  652. "pand %%mm6, %%mm4 \n\t"
  653. "psrlq $19, %%mm2 \n\t"
  654. "psrlq $19, %%mm5 \n\t"
  655. "pand %2, %%mm2 \n\t"
  656. "pand %2, %%mm5 \n\t"
  657. "por %%mm1, %%mm0 \n\t"
  658. "por %%mm4, %%mm3 \n\t"
  659. "por %%mm2, %%mm0 \n\t"
  660. "por %%mm5, %%mm3 \n\t"
  661. "psllq $16, %%mm3 \n\t"
  662. "por %%mm3, %%mm0 \n\t"
  663. MOVNTQ" %%mm0, (%0) \n\t"
  664. ::"r"(d),"r"(s),"m"(blue_15mask):"memory");
  665. d += 4;
  666. s += 12;
  667. }
  668. __asm__ volatile(SFENCE:::"memory");
  669. __asm__ volatile(EMMS:::"memory");
  670. while (s < end) {
  671. const int r = *s++;
  672. const int g = *s++;
  673. const int b = *s++;
  674. *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7);
  675. }
  676. }
  677. static inline void RENAME(rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
  678. {
  679. const uint16_t *end;
  680. const uint16_t *mm_end;
  681. uint8_t *d = dst;
  682. const uint16_t *s = (const uint16_t*)src;
  683. end = s + src_size/2;
  684. __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory");
  685. mm_end = end - 7;
  686. while (s < mm_end) {
  687. __asm__ volatile(
  688. PREFETCH" 32(%1) \n\t"
  689. "movq (%1), %%mm0 \n\t"
  690. "movq (%1), %%mm1 \n\t"
  691. "movq (%1), %%mm2 \n\t"
  692. "pand %2, %%mm0 \n\t"
  693. "pand %3, %%mm1 \n\t"
  694. "pand %4, %%mm2 \n\t"
  695. "psllq $5, %%mm0 \n\t"
  696. "pmulhw "MANGLE(mul15_mid)", %%mm0 \n\t"
  697. "pmulhw "MANGLE(mul15_mid)", %%mm1 \n\t"
  698. "pmulhw "MANGLE(mul15_hi)", %%mm2 \n\t"
  699. "movq %%mm0, %%mm3 \n\t"
  700. "movq %%mm1, %%mm4 \n\t"
  701. "movq %%mm2, %%mm5 \n\t"
  702. "punpcklwd %5, %%mm0 \n\t"
  703. "punpcklwd %5, %%mm1 \n\t"
  704. "punpcklwd %5, %%mm2 \n\t"
  705. "punpckhwd %5, %%mm3 \n\t"
  706. "punpckhwd %5, %%mm4 \n\t"
  707. "punpckhwd %5, %%mm5 \n\t"
  708. "psllq $8, %%mm1 \n\t"
  709. "psllq $16, %%mm2 \n\t"
  710. "por %%mm1, %%mm0 \n\t"
  711. "por %%mm2, %%mm0 \n\t"
  712. "psllq $8, %%mm4 \n\t"
  713. "psllq $16, %%mm5 \n\t"
  714. "por %%mm4, %%mm3 \n\t"
  715. "por %%mm5, %%mm3 \n\t"
  716. "movq %%mm0, %%mm6 \n\t"
  717. "movq %%mm3, %%mm7 \n\t"
  718. "movq 8(%1), %%mm0 \n\t"
  719. "movq 8(%1), %%mm1 \n\t"
  720. "movq 8(%1), %%mm2 \n\t"
  721. "pand %2, %%mm0 \n\t"
  722. "pand %3, %%mm1 \n\t"
  723. "pand %4, %%mm2 \n\t"
  724. "psllq $5, %%mm0 \n\t"
  725. "pmulhw "MANGLE(mul15_mid)", %%mm0 \n\t"
  726. "pmulhw "MANGLE(mul15_mid)", %%mm1 \n\t"
  727. "pmulhw "MANGLE(mul15_hi)", %%mm2 \n\t"
  728. "movq %%mm0, %%mm3 \n\t"
  729. "movq %%mm1, %%mm4 \n\t"
  730. "movq %%mm2, %%mm5 \n\t"
  731. "punpcklwd %5, %%mm0 \n\t"
  732. "punpcklwd %5, %%mm1 \n\t"
  733. "punpcklwd %5, %%mm2 \n\t"
  734. "punpckhwd %5, %%mm3 \n\t"
  735. "punpckhwd %5, %%mm4 \n\t"
  736. "punpckhwd %5, %%mm5 \n\t"
  737. "psllq $8, %%mm1 \n\t"
  738. "psllq $16, %%mm2 \n\t"
  739. "por %%mm1, %%mm0 \n\t"
  740. "por %%mm2, %%mm0 \n\t"
  741. "psllq $8, %%mm4 \n\t"
  742. "psllq $16, %%mm5 \n\t"
  743. "por %%mm4, %%mm3 \n\t"
  744. "por %%mm5, %%mm3 \n\t"
  745. :"=m"(*d)
  746. :"r"(s),"m"(mask15b),"m"(mask15g),"m"(mask15r), "m"(mmx_null)
  747. NAMED_CONSTRAINTS_ADD(mul15_mid,mul15_hi)
  748. :"memory");
  749. /* borrowed 32 to 24 */
  750. __asm__ volatile(
  751. "movq %%mm0, %%mm4 \n\t"
  752. "movq %%mm3, %%mm5 \n\t"
  753. "movq %%mm6, %%mm0 \n\t"
  754. "movq %%mm7, %%mm1 \n\t"
  755. "movq %%mm4, %%mm6 \n\t"
  756. "movq %%mm5, %%mm7 \n\t"
  757. "movq %%mm0, %%mm2 \n\t"
  758. "movq %%mm1, %%mm3 \n\t"
  759. STORE_BGR24_MMX
  760. :: "r"(d), "m"(*s)
  761. NAMED_CONSTRAINTS_ADD(mask24l,mask24h)
  762. :"memory");
  763. d += 24;
  764. s += 8;
  765. }
  766. __asm__ volatile(SFENCE:::"memory");
  767. __asm__ volatile(EMMS:::"memory");
  768. while (s < end) {
  769. register uint16_t bgr;
  770. bgr = *s++;
  771. *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
  772. *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7);
  773. *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
  774. }
  775. }
  776. static inline void RENAME(rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
  777. {
  778. const uint16_t *end;
  779. const uint16_t *mm_end;
  780. uint8_t *d = (uint8_t *)dst;
  781. const uint16_t *s = (const uint16_t *)src;
  782. end = s + src_size/2;
  783. __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory");
  784. mm_end = end - 7;
  785. while (s < mm_end) {
  786. __asm__ volatile(
  787. PREFETCH" 32(%1) \n\t"
  788. "movq (%1), %%mm0 \n\t"
  789. "movq (%1), %%mm1 \n\t"
  790. "movq (%1), %%mm2 \n\t"
  791. "pand %2, %%mm0 \n\t"
  792. "pand %3, %%mm1 \n\t"
  793. "pand %4, %%mm2 \n\t"
  794. "psllq $5, %%mm0 \n\t"
  795. "psrlq $1, %%mm2 \n\t"
  796. "pmulhw "MANGLE(mul15_mid)", %%mm0 \n\t"
  797. "pmulhw "MANGLE(mul16_mid)", %%mm1 \n\t"
  798. "pmulhw "MANGLE(mul15_hi)", %%mm2 \n\t"
  799. "movq %%mm0, %%mm3 \n\t"
  800. "movq %%mm1, %%mm4 \n\t"
  801. "movq %%mm2, %%mm5 \n\t"
  802. "punpcklwd %5, %%mm0 \n\t"
  803. "punpcklwd %5, %%mm1 \n\t"
  804. "punpcklwd %5, %%mm2 \n\t"
  805. "punpckhwd %5, %%mm3 \n\t"
  806. "punpckhwd %5, %%mm4 \n\t"
  807. "punpckhwd %5, %%mm5 \n\t"
  808. "psllq $8, %%mm1 \n\t"
  809. "psllq $16, %%mm2 \n\t"
  810. "por %%mm1, %%mm0 \n\t"
  811. "por %%mm2, %%mm0 \n\t"
  812. "psllq $8, %%mm4 \n\t"
  813. "psllq $16, %%mm5 \n\t"
  814. "por %%mm4, %%mm3 \n\t"
  815. "por %%mm5, %%mm3 \n\t"
  816. "movq %%mm0, %%mm6 \n\t"
  817. "movq %%mm3, %%mm7 \n\t"
  818. "movq 8(%1), %%mm0 \n\t"
  819. "movq 8(%1), %%mm1 \n\t"
  820. "movq 8(%1), %%mm2 \n\t"
  821. "pand %2, %%mm0 \n\t"
  822. "pand %3, %%mm1 \n\t"
  823. "pand %4, %%mm2 \n\t"
  824. "psllq $5, %%mm0 \n\t"
  825. "psrlq $1, %%mm2 \n\t"
  826. "pmulhw "MANGLE(mul15_mid)", %%mm0 \n\t"
  827. "pmulhw "MANGLE(mul16_mid)", %%mm1 \n\t"
  828. "pmulhw "MANGLE(mul15_hi)", %%mm2 \n\t"
  829. "movq %%mm0, %%mm3 \n\t"
  830. "movq %%mm1, %%mm4 \n\t"
  831. "movq %%mm2, %%mm5 \n\t"
  832. "punpcklwd %5, %%mm0 \n\t"
  833. "punpcklwd %5, %%mm1 \n\t"
  834. "punpcklwd %5, %%mm2 \n\t"
  835. "punpckhwd %5, %%mm3 \n\t"
  836. "punpckhwd %5, %%mm4 \n\t"
  837. "punpckhwd %5, %%mm5 \n\t"
  838. "psllq $8, %%mm1 \n\t"
  839. "psllq $16, %%mm2 \n\t"
  840. "por %%mm1, %%mm0 \n\t"
  841. "por %%mm2, %%mm0 \n\t"
  842. "psllq $8, %%mm4 \n\t"
  843. "psllq $16, %%mm5 \n\t"
  844. "por %%mm4, %%mm3 \n\t"
  845. "por %%mm5, %%mm3 \n\t"
  846. :"=m"(*d)
  847. :"r"(s),"m"(mask16b),"m"(mask16g),"m"(mask16r),"m"(mmx_null)
  848. NAMED_CONSTRAINTS_ADD(mul15_mid,mul16_mid,mul15_hi)
  849. :"memory");
  850. /* borrowed 32 to 24 */
  851. __asm__ volatile(
  852. "movq %%mm0, %%mm4 \n\t"
  853. "movq %%mm3, %%mm5 \n\t"
  854. "movq %%mm6, %%mm0 \n\t"
  855. "movq %%mm7, %%mm1 \n\t"
  856. "movq %%mm4, %%mm6 \n\t"
  857. "movq %%mm5, %%mm7 \n\t"
  858. "movq %%mm0, %%mm2 \n\t"
  859. "movq %%mm1, %%mm3 \n\t"
  860. STORE_BGR24_MMX
  861. :: "r"(d), "m"(*s)
  862. NAMED_CONSTRAINTS_ADD(mask24l,mask24h)
  863. :"memory");
  864. d += 24;
  865. s += 8;
  866. }
  867. __asm__ volatile(SFENCE:::"memory");
  868. __asm__ volatile(EMMS:::"memory");
  869. while (s < end) {
  870. register uint16_t bgr;
  871. bgr = *s++;
  872. *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
  873. *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9);
  874. *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
  875. }
  876. }
  877. /*
  878. * mm0 = 00 B3 00 B2 00 B1 00 B0
  879. * mm1 = 00 G3 00 G2 00 G1 00 G0
  880. * mm2 = 00 R3 00 R2 00 R1 00 R0
  881. * mm6 = FF FF FF FF FF FF FF FF
  882. * mm7 = 00 00 00 00 00 00 00 00
  883. */
  884. #define PACK_RGB32 \
  885. "packuswb %%mm7, %%mm0 \n\t" /* 00 00 00 00 B3 B2 B1 B0 */ \
  886. "packuswb %%mm7, %%mm1 \n\t" /* 00 00 00 00 G3 G2 G1 G0 */ \
  887. "packuswb %%mm7, %%mm2 \n\t" /* 00 00 00 00 R3 R2 R1 R0 */ \
  888. "punpcklbw %%mm1, %%mm0 \n\t" /* G3 B3 G2 B2 G1 B1 G0 B0 */ \
  889. "punpcklbw %%mm6, %%mm2 \n\t" /* FF R3 FF R2 FF R1 FF R0 */ \
  890. "movq %%mm0, %%mm3 \n\t" \
  891. "punpcklwd %%mm2, %%mm0 \n\t" /* FF R1 G1 B1 FF R0 G0 B0 */ \
  892. "punpckhwd %%mm2, %%mm3 \n\t" /* FF R3 G3 B3 FF R2 G2 B2 */ \
  893. MOVNTQ" %%mm0, (%0) \n\t" \
  894. MOVNTQ" %%mm3, 8(%0) \n\t" \
  895. static inline void RENAME(rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size)
  896. {
  897. const uint16_t *end;
  898. const uint16_t *mm_end;
  899. uint8_t *d = dst;
  900. const uint16_t *s = (const uint16_t *)src;
  901. end = s + src_size/2;
  902. __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory");
  903. __asm__ volatile("pxor %%mm7,%%mm7 \n\t":::"memory");
  904. __asm__ volatile("pcmpeqd %%mm6,%%mm6 \n\t":::"memory");
  905. mm_end = end - 3;
  906. while (s < mm_end) {
  907. __asm__ volatile(
  908. PREFETCH" 32(%1) \n\t"
  909. "movq (%1), %%mm0 \n\t"
  910. "movq (%1), %%mm1 \n\t"
  911. "movq (%1), %%mm2 \n\t"
  912. "pand %2, %%mm0 \n\t"
  913. "pand %3, %%mm1 \n\t"
  914. "pand %4, %%mm2 \n\t"
  915. "psllq $5, %%mm0 \n\t"
  916. "pmulhw %5, %%mm0 \n\t"
  917. "pmulhw %5, %%mm1 \n\t"
  918. "pmulhw "MANGLE(mul15_hi)", %%mm2 \n\t"
  919. PACK_RGB32
  920. ::"r"(d),"r"(s),"m"(mask15b),"m"(mask15g),"m"(mask15r) ,"m"(mul15_mid)
  921. NAMED_CONSTRAINTS_ADD(mul15_hi)
  922. :"memory");
  923. d += 16;
  924. s += 4;
  925. }
  926. __asm__ volatile(SFENCE:::"memory");
  927. __asm__ volatile(EMMS:::"memory");
  928. while (s < end) {
  929. register uint16_t bgr;
  930. bgr = *s++;
  931. *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
  932. *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7);
  933. *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
  934. *d++ = 255;
  935. }
  936. }
  937. static inline void RENAME(rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size)
  938. {
  939. const uint16_t *end;
  940. const uint16_t *mm_end;
  941. uint8_t *d = dst;
  942. const uint16_t *s = (const uint16_t*)src;
  943. end = s + src_size/2;
  944. __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory");
  945. __asm__ volatile("pxor %%mm7,%%mm7 \n\t":::"memory");
  946. __asm__ volatile("pcmpeqd %%mm6,%%mm6 \n\t":::"memory");
  947. mm_end = end - 3;
  948. while (s < mm_end) {
  949. __asm__ volatile(
  950. PREFETCH" 32(%1) \n\t"
  951. "movq (%1), %%mm0 \n\t"
  952. "movq (%1), %%mm1 \n\t"
  953. "movq (%1), %%mm2 \n\t"
  954. "pand %2, %%mm0 \n\t"
  955. "pand %3, %%mm1 \n\t"
  956. "pand %4, %%mm2 \n\t"
  957. "psllq $5, %%mm0 \n\t"
  958. "psrlq $1, %%mm2 \n\t"
  959. "pmulhw %5, %%mm0 \n\t"
  960. "pmulhw "MANGLE(mul16_mid)", %%mm1 \n\t"
  961. "pmulhw "MANGLE(mul15_hi)", %%mm2 \n\t"
  962. PACK_RGB32
  963. ::"r"(d),"r"(s),"m"(mask16b),"m"(mask16g),"m"(mask16r),"m"(mul15_mid)
  964. NAMED_CONSTRAINTS_ADD(mul16_mid,mul15_hi)
  965. :"memory");
  966. d += 16;
  967. s += 4;
  968. }
  969. __asm__ volatile(SFENCE:::"memory");
  970. __asm__ volatile(EMMS:::"memory");
  971. while (s < end) {
  972. register uint16_t bgr;
  973. bgr = *s++;
  974. *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
  975. *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9);
  976. *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
  977. *d++ = 255;
  978. }
  979. }
  980. static inline void RENAME(rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
  981. {
  982. unsigned i;
  983. x86_reg mmx_size= 23 - src_size;
  984. __asm__ volatile (
  985. "test %%"FF_REG_a", %%"FF_REG_a" \n\t"
  986. "jns 2f \n\t"
  987. "movq "MANGLE(mask24r)", %%mm5 \n\t"
  988. "movq "MANGLE(mask24g)", %%mm6 \n\t"
  989. "movq "MANGLE(mask24b)", %%mm7 \n\t"
  990. ".p2align 4 \n\t"
  991. "1: \n\t"
  992. PREFETCH" 32(%1, %%"FF_REG_a") \n\t"
  993. "movq (%1, %%"FF_REG_a"), %%mm0 \n\t" // BGR BGR BG
  994. "movq (%1, %%"FF_REG_a"), %%mm1 \n\t" // BGR BGR BG
  995. "movq 2(%1, %%"FF_REG_a"), %%mm2 \n\t" // R BGR BGR B
  996. "psllq $16, %%mm0 \n\t" // 00 BGR BGR
  997. "pand %%mm5, %%mm0 \n\t"
  998. "pand %%mm6, %%mm1 \n\t"
  999. "pand %%mm7, %%mm2 \n\t"
  1000. "por %%mm0, %%mm1 \n\t"
  1001. "por %%mm2, %%mm1 \n\t"
  1002. "movq 6(%1, %%"FF_REG_a"), %%mm0 \n\t" // BGR BGR BG
  1003. MOVNTQ" %%mm1,(%2, %%"FF_REG_a") \n\t" // RGB RGB RG
  1004. "movq 8(%1, %%"FF_REG_a"), %%mm1 \n\t" // R BGR BGR B
  1005. "movq 10(%1, %%"FF_REG_a"), %%mm2 \n\t" // GR BGR BGR
  1006. "pand %%mm7, %%mm0 \n\t"
  1007. "pand %%mm5, %%mm1 \n\t"
  1008. "pand %%mm6, %%mm2 \n\t"
  1009. "por %%mm0, %%mm1 \n\t"
  1010. "por %%mm2, %%mm1 \n\t"
  1011. "movq 14(%1, %%"FF_REG_a"), %%mm0 \n\t" // R BGR BGR B
  1012. MOVNTQ" %%mm1, 8(%2, %%"FF_REG_a")\n\t" // B RGB RGB R
  1013. "movq 16(%1, %%"FF_REG_a"), %%mm1 \n\t" // GR BGR BGR
  1014. "movq 18(%1, %%"FF_REG_a"), %%mm2 \n\t" // BGR BGR BG
  1015. "pand %%mm6, %%mm0 \n\t"
  1016. "pand %%mm7, %%mm1 \n\t"
  1017. "pand %%mm5, %%mm2 \n\t"
  1018. "por %%mm0, %%mm1 \n\t"
  1019. "por %%mm2, %%mm1 \n\t"
  1020. MOVNTQ" %%mm1, 16(%2, %%"FF_REG_a") \n\t"
  1021. "add $24, %%"FF_REG_a" \n\t"
  1022. " js 1b \n\t"
  1023. "2: \n\t"
  1024. : "+a" (mmx_size)
  1025. : "r" (src-mmx_size), "r"(dst-mmx_size)
  1026. NAMED_CONSTRAINTS_ADD(mask24r,mask24g,mask24b)
  1027. );
  1028. __asm__ volatile(SFENCE:::"memory");
  1029. __asm__ volatile(EMMS:::"memory");
  1030. if (mmx_size==23) return; //finished, was multiple of 8
  1031. src+= src_size;
  1032. dst+= src_size;
  1033. src_size= 23-mmx_size;
  1034. src-= src_size;
  1035. dst-= src_size;
  1036. for (i=0; i<src_size; i+=3) {
  1037. register uint8_t x;
  1038. x = src[i + 2];
  1039. dst[i + 1] = src[i + 1];
  1040. dst[i + 2] = src[i + 0];
  1041. dst[i + 0] = x;
  1042. }
  1043. }
  1044. static inline void RENAME(yuvPlanartoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  1045. int width, int height,
  1046. int lumStride, int chromStride, int dstStride, int vertLumPerChroma)
  1047. {
  1048. int y;
  1049. const x86_reg chromWidth= width>>1;
  1050. for (y=0; y<height; y++) {
  1051. //FIXME handle 2 lines at once (fewer prefetches, reuse some chroma, but very likely memory-limited anyway)
  1052. __asm__ volatile(
  1053. "xor %%"FF_REG_a", %%"FF_REG_a" \n\t"
  1054. ".p2align 4 \n\t"
  1055. "1: \n\t"
  1056. PREFETCH" 32(%1, %%"FF_REG_a", 2) \n\t"
  1057. PREFETCH" 32(%2, %%"FF_REG_a") \n\t"
  1058. PREFETCH" 32(%3, %%"FF_REG_a") \n\t"
  1059. "movq (%2, %%"FF_REG_a"), %%mm0 \n\t" // U(0)
  1060. "movq %%mm0, %%mm2 \n\t" // U(0)
  1061. "movq (%3, %%"FF_REG_a"), %%mm1 \n\t" // V(0)
  1062. "punpcklbw %%mm1, %%mm0 \n\t" // UVUV UVUV(0)
  1063. "punpckhbw %%mm1, %%mm2 \n\t" // UVUV UVUV(8)
  1064. "movq (%1, %%"FF_REG_a",2), %%mm3 \n\t" // Y(0)
  1065. "movq 8(%1, %%"FF_REG_a",2), %%mm5 \n\t" // Y(8)
  1066. "movq %%mm3, %%mm4 \n\t" // Y(0)
  1067. "movq %%mm5, %%mm6 \n\t" // Y(8)
  1068. "punpcklbw %%mm0, %%mm3 \n\t" // YUYV YUYV(0)
  1069. "punpckhbw %%mm0, %%mm4 \n\t" // YUYV YUYV(4)
  1070. "punpcklbw %%mm2, %%mm5 \n\t" // YUYV YUYV(8)
  1071. "punpckhbw %%mm2, %%mm6 \n\t" // YUYV YUYV(12)
  1072. MOVNTQ" %%mm3, (%0, %%"FF_REG_a", 4) \n\t"
  1073. MOVNTQ" %%mm4, 8(%0, %%"FF_REG_a", 4) \n\t"
  1074. MOVNTQ" %%mm5, 16(%0, %%"FF_REG_a", 4) \n\t"
  1075. MOVNTQ" %%mm6, 24(%0, %%"FF_REG_a", 4) \n\t"
  1076. "add $8, %%"FF_REG_a" \n\t"
  1077. "cmp %4, %%"FF_REG_a" \n\t"
  1078. " jb 1b \n\t"
  1079. ::"r"(dst), "r"(ysrc), "r"(usrc), "r"(vsrc), "g" (chromWidth)
  1080. : "%"FF_REG_a
  1081. );
  1082. if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) {
  1083. usrc += chromStride;
  1084. vsrc += chromStride;
  1085. }
  1086. ysrc += lumStride;
  1087. dst += dstStride;
  1088. }
  1089. __asm__(EMMS" \n\t"
  1090. SFENCE" \n\t"
  1091. :::"memory");
  1092. }
  1093. /**
  1094. * Height should be a multiple of 2 and width should be a multiple of 16.
  1095. * (If this is a problem for anyone then tell me, and I will fix it.)
  1096. */
  1097. static inline void RENAME(yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  1098. int width, int height,
  1099. int lumStride, int chromStride, int dstStride)
  1100. {
  1101. //FIXME interpolate chroma
  1102. RENAME(yuvPlanartoyuy2)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 2);
  1103. }
  1104. static inline void RENAME(yuvPlanartouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  1105. int width, int height,
  1106. int lumStride, int chromStride, int dstStride, int vertLumPerChroma)
  1107. {
  1108. int y;
  1109. const x86_reg chromWidth= width>>1;
  1110. for (y=0; y<height; y++) {
  1111. //FIXME handle 2 lines at once (fewer prefetches, reuse some chroma, but very likely memory-limited anyway)
  1112. __asm__ volatile(
  1113. "xor %%"FF_REG_a", %%"FF_REG_a" \n\t"
  1114. ".p2align 4 \n\t"
  1115. "1: \n\t"
  1116. PREFETCH" 32(%1, %%"FF_REG_a", 2) \n\t"
  1117. PREFETCH" 32(%2, %%"FF_REG_a") \n\t"
  1118. PREFETCH" 32(%3, %%"FF_REG_a") \n\t"
  1119. "movq (%2, %%"FF_REG_a"), %%mm0 \n\t" // U(0)
  1120. "movq %%mm0, %%mm2 \n\t" // U(0)
  1121. "movq (%3, %%"FF_REG_a"), %%mm1 \n\t" // V(0)
  1122. "punpcklbw %%mm1, %%mm0 \n\t" // UVUV UVUV(0)
  1123. "punpckhbw %%mm1, %%mm2 \n\t" // UVUV UVUV(8)
  1124. "movq (%1, %%"FF_REG_a",2), %%mm3 \n\t" // Y(0)
  1125. "movq 8(%1, %%"FF_REG_a",2), %%mm5 \n\t" // Y(8)
  1126. "movq %%mm0, %%mm4 \n\t" // Y(0)
  1127. "movq %%mm2, %%mm6 \n\t" // Y(8)
  1128. "punpcklbw %%mm3, %%mm0 \n\t" // YUYV YUYV(0)
  1129. "punpckhbw %%mm3, %%mm4 \n\t" // YUYV YUYV(4)
  1130. "punpcklbw %%mm5, %%mm2 \n\t" // YUYV YUYV(8)
  1131. "punpckhbw %%mm5, %%mm6 \n\t" // YUYV YUYV(12)
  1132. MOVNTQ" %%mm0, (%0, %%"FF_REG_a", 4) \n\t"
  1133. MOVNTQ" %%mm4, 8(%0, %%"FF_REG_a", 4) \n\t"
  1134. MOVNTQ" %%mm2, 16(%0, %%"FF_REG_a", 4) \n\t"
  1135. MOVNTQ" %%mm6, 24(%0, %%"FF_REG_a", 4) \n\t"
  1136. "add $8, %%"FF_REG_a" \n\t"
  1137. "cmp %4, %%"FF_REG_a" \n\t"
  1138. " jb 1b \n\t"
  1139. ::"r"(dst), "r"(ysrc), "r"(usrc), "r"(vsrc), "g" (chromWidth)
  1140. : "%"FF_REG_a
  1141. );
  1142. if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) {
  1143. usrc += chromStride;
  1144. vsrc += chromStride;
  1145. }
  1146. ysrc += lumStride;
  1147. dst += dstStride;
  1148. }
  1149. __asm__(EMMS" \n\t"
  1150. SFENCE" \n\t"
  1151. :::"memory");
  1152. }
  1153. /**
  1154. * Height should be a multiple of 2 and width should be a multiple of 16
  1155. * (If this is a problem for anyone then tell me, and I will fix it.)
  1156. */
  1157. static inline void RENAME(yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  1158. int width, int height,
  1159. int lumStride, int chromStride, int dstStride)
  1160. {
  1161. //FIXME interpolate chroma
  1162. RENAME(yuvPlanartouyvy)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 2);
  1163. }
  1164. /**
  1165. * Width should be a multiple of 16.
  1166. */
  1167. static inline void RENAME(yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  1168. int width, int height,
  1169. int lumStride, int chromStride, int dstStride)
  1170. {
  1171. RENAME(yuvPlanartouyvy)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 1);
  1172. }
  1173. /**
  1174. * Width should be a multiple of 16.
  1175. */
  1176. static inline void RENAME(yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  1177. int width, int height,
  1178. int lumStride, int chromStride, int dstStride)
  1179. {
  1180. RENAME(yuvPlanartoyuy2)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 1);
  1181. }
  1182. /**
  1183. * Height should be a multiple of 2 and width should be a multiple of 16.
  1184. * (If this is a problem for anyone then tell me, and I will fix it.)
  1185. */
  1186. static inline void RENAME(yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  1187. int width, int height,
  1188. int lumStride, int chromStride, int srcStride)
  1189. {
  1190. int y;
  1191. const x86_reg chromWidth= width>>1;
  1192. for (y=0; y<height; y+=2) {
  1193. __asm__ volatile(
  1194. "xor %%"FF_REG_a", %%"FF_REG_a"\n\t"
  1195. "pcmpeqw %%mm7, %%mm7 \n\t"
  1196. "psrlw $8, %%mm7 \n\t" // FF,00,FF,00...
  1197. ".p2align 4 \n\t"
  1198. "1: \n\t"
  1199. PREFETCH" 64(%0, %%"FF_REG_a", 4) \n\t"
  1200. "movq (%0, %%"FF_REG_a", 4), %%mm0 \n\t" // YUYV YUYV(0)
  1201. "movq 8(%0, %%"FF_REG_a", 4), %%mm1 \n\t" // YUYV YUYV(4)
  1202. "movq %%mm0, %%mm2 \n\t" // YUYV YUYV(0)
  1203. "movq %%mm1, %%mm3 \n\t" // YUYV YUYV(4)
  1204. "psrlw $8, %%mm0 \n\t" // U0V0 U0V0(0)
  1205. "psrlw $8, %%mm1 \n\t" // U0V0 U0V0(4)
  1206. "pand %%mm7, %%mm2 \n\t" // Y0Y0 Y0Y0(0)
  1207. "pand %%mm7, %%mm3 \n\t" // Y0Y0 Y0Y0(4)
  1208. "packuswb %%mm1, %%mm0 \n\t" // UVUV UVUV(0)
  1209. "packuswb %%mm3, %%mm2 \n\t" // YYYY YYYY(0)
  1210. MOVNTQ" %%mm2, (%1, %%"FF_REG_a", 2) \n\t"
  1211. "movq 16(%0, %%"FF_REG_a", 4), %%mm1 \n\t" // YUYV YUYV(8)
  1212. "movq 24(%0, %%"FF_REG_a", 4), %%mm2 \n\t" // YUYV YUYV(12)
  1213. "movq %%mm1, %%mm3 \n\t" // YUYV YUYV(8)
  1214. "movq %%mm2, %%mm4 \n\t" // YUYV YUYV(12)
  1215. "psrlw $8, %%mm1 \n\t" // U0V0 U0V0(8)
  1216. "psrlw $8, %%mm2 \n\t" // U0V0 U0V0(12)
  1217. "pand %%mm7, %%mm3 \n\t" // Y0Y0 Y0Y0(8)
  1218. "pand %%mm7, %%mm4 \n\t" // Y0Y0 Y0Y0(12)
  1219. "packuswb %%mm2, %%mm1 \n\t" // UVUV UVUV(8)
  1220. "packuswb %%mm4, %%mm3 \n\t" // YYYY YYYY(8)
  1221. MOVNTQ" %%mm3, 8(%1, %%"FF_REG_a", 2) \n\t"
  1222. "movq %%mm0, %%mm2 \n\t" // UVUV UVUV(0)
  1223. "movq %%mm1, %%mm3 \n\t" // UVUV UVUV(8)
  1224. "psrlw $8, %%mm0 \n\t" // V0V0 V0V0(0)
  1225. "psrlw $8, %%mm1 \n\t" // V0V0 V0V0(8)
  1226. "pand %%mm7, %%mm2 \n\t" // U0U0 U0U0(0)
  1227. "pand %%mm7, %%mm3 \n\t" // U0U0 U0U0(8)
  1228. "packuswb %%mm1, %%mm0 \n\t" // VVVV VVVV(0)
  1229. "packuswb %%mm3, %%mm2 \n\t" // UUUU UUUU(0)
  1230. MOVNTQ" %%mm0, (%3, %%"FF_REG_a") \n\t"
  1231. MOVNTQ" %%mm2, (%2, %%"FF_REG_a") \n\t"
  1232. "add $8, %%"FF_REG_a" \n\t"
  1233. "cmp %4, %%"FF_REG_a" \n\t"
  1234. " jb 1b \n\t"
  1235. ::"r"(src), "r"(ydst), "r"(udst), "r"(vdst), "g" (chromWidth)
  1236. : "memory", "%"FF_REG_a
  1237. );
  1238. ydst += lumStride;
  1239. src += srcStride;
  1240. __asm__ volatile(
  1241. "xor %%"FF_REG_a", %%"FF_REG_a"\n\t"
  1242. ".p2align 4 \n\t"
  1243. "1: \n\t"
  1244. PREFETCH" 64(%0, %%"FF_REG_a", 4) \n\t"
  1245. "movq (%0, %%"FF_REG_a", 4), %%mm0 \n\t" // YUYV YUYV(0)
  1246. "movq 8(%0, %%"FF_REG_a", 4), %%mm1 \n\t" // YUYV YUYV(4)
  1247. "movq 16(%0, %%"FF_REG_a", 4), %%mm2 \n\t" // YUYV YUYV(8)
  1248. "movq 24(%0, %%"FF_REG_a", 4), %%mm3 \n\t" // YUYV YUYV(12)
  1249. "pand %%mm7, %%mm0 \n\t" // Y0Y0 Y0Y0(0)
  1250. "pand %%mm7, %%mm1 \n\t" // Y0Y0 Y0Y0(4)
  1251. "pand %%mm7, %%mm2 \n\t" // Y0Y0 Y0Y0(8)
  1252. "pand %%mm7, %%mm3 \n\t" // Y0Y0 Y0Y0(12)
  1253. "packuswb %%mm1, %%mm0 \n\t" // YYYY YYYY(0)
  1254. "packuswb %%mm3, %%mm2 \n\t" // YYYY YYYY(8)
  1255. MOVNTQ" %%mm0, (%1, %%"FF_REG_a", 2) \n\t"
  1256. MOVNTQ" %%mm2, 8(%1, %%"FF_REG_a", 2) \n\t"
  1257. "add $8, %%"FF_REG_a"\n\t"
  1258. "cmp %4, %%"FF_REG_a"\n\t"
  1259. " jb 1b \n\t"
  1260. ::"r"(src), "r"(ydst), "r"(udst), "r"(vdst), "g" (chromWidth)
  1261. : "memory", "%"FF_REG_a
  1262. );
  1263. udst += chromStride;
  1264. vdst += chromStride;
  1265. ydst += lumStride;
  1266. src += srcStride;
  1267. }
  1268. __asm__ volatile(EMMS" \n\t"
  1269. SFENCE" \n\t"
  1270. :::"memory");
  1271. }
  1272. static inline void RENAME(planar2x)(const uint8_t *src, uint8_t *dst, int srcWidth, int srcHeight, int srcStride, int dstStride)
  1273. {
  1274. int x,y;
  1275. dst[0]= src[0];
  1276. // first line
  1277. for (x=0; x<srcWidth-1; x++) {
  1278. dst[2*x+1]= (3*src[x] + src[x+1])>>2;
  1279. dst[2*x+2]= ( src[x] + 3*src[x+1])>>2;
  1280. }
  1281. dst[2*srcWidth-1]= src[srcWidth-1];
  1282. dst+= dstStride;
  1283. for (y=1; y<srcHeight; y++) {
  1284. x86_reg mmxSize= srcWidth&~15;
  1285. if (mmxSize) {
  1286. __asm__ volatile(
  1287. "mov %4, %%"FF_REG_a" \n\t"
  1288. "movq "MANGLE(mmx_ff)", %%mm0 \n\t"
  1289. "movq (%0, %%"FF_REG_a"), %%mm4 \n\t"
  1290. "movq %%mm4, %%mm2 \n\t"
  1291. "psllq $8, %%mm4 \n\t"
  1292. "pand %%mm0, %%mm2 \n\t"
  1293. "por %%mm2, %%mm4 \n\t"
  1294. "movq (%1, %%"FF_REG_a"), %%mm5 \n\t"
  1295. "movq %%mm5, %%mm3 \n\t"
  1296. "psllq $8, %%mm5 \n\t"
  1297. "pand %%mm0, %%mm3 \n\t"
  1298. "por %%mm3, %%mm5 \n\t"
  1299. "1: \n\t"
  1300. "movq (%0, %%"FF_REG_a"), %%mm0 \n\t"
  1301. "movq (%1, %%"FF_REG_a"), %%mm1 \n\t"
  1302. "movq 1(%0, %%"FF_REG_a"), %%mm2 \n\t"
  1303. "movq 1(%1, %%"FF_REG_a"), %%mm3 \n\t"
  1304. PAVGB" %%mm0, %%mm5 \n\t"
  1305. PAVGB" %%mm0, %%mm3 \n\t"
  1306. PAVGB" %%mm0, %%mm5 \n\t"
  1307. PAVGB" %%mm0, %%mm3 \n\t"
  1308. PAVGB" %%mm1, %%mm4 \n\t"
  1309. PAVGB" %%mm1, %%mm2 \n\t"
  1310. PAVGB" %%mm1, %%mm4 \n\t"
  1311. PAVGB" %%mm1, %%mm2 \n\t"
  1312. "movq %%mm5, %%mm7 \n\t"
  1313. "movq %%mm4, %%mm6 \n\t"
  1314. "punpcklbw %%mm3, %%mm5 \n\t"
  1315. "punpckhbw %%mm3, %%mm7 \n\t"
  1316. "punpcklbw %%mm2, %%mm4 \n\t"
  1317. "punpckhbw %%mm2, %%mm6 \n\t"
  1318. MOVNTQ" %%mm5, (%2, %%"FF_REG_a", 2) \n\t"
  1319. MOVNTQ" %%mm7, 8(%2, %%"FF_REG_a", 2) \n\t"
  1320. MOVNTQ" %%mm4, (%3, %%"FF_REG_a", 2) \n\t"
  1321. MOVNTQ" %%mm6, 8(%3, %%"FF_REG_a", 2) \n\t"
  1322. "add $8, %%"FF_REG_a" \n\t"
  1323. "movq -1(%0, %%"FF_REG_a"), %%mm4 \n\t"
  1324. "movq -1(%1, %%"FF_REG_a"), %%mm5 \n\t"
  1325. " js 1b \n\t"
  1326. :: "r" (src + mmxSize ), "r" (src + srcStride + mmxSize ),
  1327. "r" (dst + mmxSize*2), "r" (dst + dstStride + mmxSize*2),
  1328. "g" (-mmxSize)
  1329. NAMED_CONSTRAINTS_ADD(mmx_ff)
  1330. : "%"FF_REG_a
  1331. );
  1332. } else {
  1333. mmxSize = 1;
  1334. dst[0] = (src[0] * 3 + src[srcStride]) >> 2;
  1335. dst[dstStride] = (src[0] + 3 * src[srcStride]) >> 2;
  1336. }
  1337. for (x=mmxSize-1; x<srcWidth-1; x++) {
  1338. dst[2*x +1]= (3*src[x+0] + src[x+srcStride+1])>>2;
  1339. dst[2*x+dstStride+2]= ( src[x+0] + 3*src[x+srcStride+1])>>2;
  1340. dst[2*x+dstStride+1]= ( src[x+1] + 3*src[x+srcStride ])>>2;
  1341. dst[2*x +2]= (3*src[x+1] + src[x+srcStride ])>>2;
  1342. }
  1343. dst[srcWidth*2 -1 ]= (3*src[srcWidth-1] + src[srcWidth-1 + srcStride])>>2;
  1344. dst[srcWidth*2 -1 + dstStride]= ( src[srcWidth-1] + 3*src[srcWidth-1 + srcStride])>>2;
  1345. dst+=dstStride*2;
  1346. src+=srcStride;
  1347. }
  1348. // last line
  1349. dst[0]= src[0];
  1350. for (x=0; x<srcWidth-1; x++) {
  1351. dst[2*x+1]= (3*src[x] + src[x+1])>>2;
  1352. dst[2*x+2]= ( src[x] + 3*src[x+1])>>2;
  1353. }
  1354. dst[2*srcWidth-1]= src[srcWidth-1];
  1355. __asm__ volatile(EMMS" \n\t"
  1356. SFENCE" \n\t"
  1357. :::"memory");
  1358. }
  1359. /**
  1360. * Height should be a multiple of 2 and width should be a multiple of 16.
  1361. * (If this is a problem for anyone then tell me, and I will fix it.)
  1362. * Chrominance data is only taken from every second line, others are ignored.
  1363. * FIXME: Write HQ version.
  1364. */
  1365. static inline void RENAME(uyvytoyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  1366. int width, int height,
  1367. int lumStride, int chromStride, int srcStride)
  1368. {
  1369. int y;
  1370. const x86_reg chromWidth= width>>1;
  1371. for (y=0; y<height; y+=2) {
  1372. __asm__ volatile(
  1373. "xor %%"FF_REG_a", %%"FF_REG_a" \n\t"
  1374. "pcmpeqw %%mm7, %%mm7 \n\t"
  1375. "psrlw $8, %%mm7 \n\t" // FF,00,FF,00...
  1376. ".p2align 4 \n\t"
  1377. "1: \n\t"
  1378. PREFETCH" 64(%0, %%"FF_REG_a", 4) \n\t"
  1379. "movq (%0, %%"FF_REG_a", 4), %%mm0 \n\t" // UYVY UYVY(0)
  1380. "movq 8(%0, %%"FF_REG_a", 4), %%mm1 \n\t" // UYVY UYVY(4)
  1381. "movq %%mm0, %%mm2 \n\t" // UYVY UYVY(0)
  1382. "movq %%mm1, %%mm3 \n\t" // UYVY UYVY(4)
  1383. "pand %%mm7, %%mm0 \n\t" // U0V0 U0V0(0)
  1384. "pand %%mm7, %%mm1 \n\t" // U0V0 U0V0(4)
  1385. "psrlw $8, %%mm2 \n\t" // Y0Y0 Y0Y0(0)
  1386. "psrlw $8, %%mm3 \n\t" // Y0Y0 Y0Y0(4)
  1387. "packuswb %%mm1, %%mm0 \n\t" // UVUV UVUV(0)
  1388. "packuswb %%mm3, %%mm2 \n\t" // YYYY YYYY(0)
  1389. MOVNTQ" %%mm2, (%1, %%"FF_REG_a", 2) \n\t"
  1390. "movq 16(%0, %%"FF_REG_a", 4), %%mm1 \n\t" // UYVY UYVY(8)
  1391. "movq 24(%0, %%"FF_REG_a", 4), %%mm2 \n\t" // UYVY UYVY(12)
  1392. "movq %%mm1, %%mm3 \n\t" // UYVY UYVY(8)
  1393. "movq %%mm2, %%mm4 \n\t" // UYVY UYVY(12)
  1394. "pand %%mm7, %%mm1 \n\t" // U0V0 U0V0(8)
  1395. "pand %%mm7, %%mm2 \n\t" // U0V0 U0V0(12)
  1396. "psrlw $8, %%mm3 \n\t" // Y0Y0 Y0Y0(8)
  1397. "psrlw $8, %%mm4 \n\t" // Y0Y0 Y0Y0(12)
  1398. "packuswb %%mm2, %%mm1 \n\t" // UVUV UVUV(8)
  1399. "packuswb %%mm4, %%mm3 \n\t" // YYYY YYYY(8)
  1400. MOVNTQ" %%mm3, 8(%1, %%"FF_REG_a", 2) \n\t"
  1401. "movq %%mm0, %%mm2 \n\t" // UVUV UVUV(0)
  1402. "movq %%mm1, %%mm3 \n\t" // UVUV UVUV(8)
  1403. "psrlw $8, %%mm0 \n\t" // V0V0 V0V0(0)
  1404. "psrlw $8, %%mm1 \n\t" // V0V0 V0V0(8)
  1405. "pand %%mm7, %%mm2 \n\t" // U0U0 U0U0(0)
  1406. "pand %%mm7, %%mm3 \n\t" // U0U0 U0U0(8)
  1407. "packuswb %%mm1, %%mm0 \n\t" // VVVV VVVV(0)
  1408. "packuswb %%mm3, %%mm2 \n\t" // UUUU UUUU(0)
  1409. MOVNTQ" %%mm0, (%3, %%"FF_REG_a") \n\t"
  1410. MOVNTQ" %%mm2, (%2, %%"FF_REG_a") \n\t"
  1411. "add $8, %%"FF_REG_a" \n\t"
  1412. "cmp %4, %%"FF_REG_a" \n\t"
  1413. " jb 1b \n\t"
  1414. ::"r"(src), "r"(ydst), "r"(udst), "r"(vdst), "g" (chromWidth)
  1415. : "memory", "%"FF_REG_a
  1416. );
  1417. ydst += lumStride;
  1418. src += srcStride;
  1419. __asm__ volatile(
  1420. "xor %%"FF_REG_a", %%"FF_REG_a" \n\t"
  1421. ".p2align 4 \n\t"
  1422. "1: \n\t"
  1423. PREFETCH" 64(%0, %%"FF_REG_a", 4) \n\t"
  1424. "movq (%0, %%"FF_REG_a", 4), %%mm0 \n\t" // YUYV YUYV(0)
  1425. "movq 8(%0, %%"FF_REG_a", 4), %%mm1 \n\t" // YUYV YUYV(4)
  1426. "movq 16(%0, %%"FF_REG_a", 4), %%mm2 \n\t" // YUYV YUYV(8)
  1427. "movq 24(%0, %%"FF_REG_a", 4), %%mm3 \n\t" // YUYV YUYV(12)
  1428. "psrlw $8, %%mm0 \n\t" // Y0Y0 Y0Y0(0)
  1429. "psrlw $8, %%mm1 \n\t" // Y0Y0 Y0Y0(4)
  1430. "psrlw $8, %%mm2 \n\t" // Y0Y0 Y0Y0(8)
  1431. "psrlw $8, %%mm3 \n\t" // Y0Y0 Y0Y0(12)
  1432. "packuswb %%mm1, %%mm0 \n\t" // YYYY YYYY(0)
  1433. "packuswb %%mm3, %%mm2 \n\t" // YYYY YYYY(8)
  1434. MOVNTQ" %%mm0, (%1, %%"FF_REG_a", 2) \n\t"
  1435. MOVNTQ" %%mm2, 8(%1, %%"FF_REG_a", 2) \n\t"
  1436. "add $8, %%"FF_REG_a" \n\t"
  1437. "cmp %4, %%"FF_REG_a" \n\t"
  1438. " jb 1b \n\t"
  1439. ::"r"(src), "r"(ydst), "r"(udst), "r"(vdst), "g" (chromWidth)
  1440. : "memory", "%"FF_REG_a
  1441. );
  1442. udst += chromStride;
  1443. vdst += chromStride;
  1444. ydst += lumStride;
  1445. src += srcStride;
  1446. }
  1447. __asm__ volatile(EMMS" \n\t"
  1448. SFENCE" \n\t"
  1449. :::"memory");
  1450. }
  1451. /**
  1452. * Height should be a multiple of 2 and width should be a multiple of 2.
  1453. * (If this is a problem for anyone then tell me, and I will fix it.)
  1454. * Chrominance data is only taken from every second line,
  1455. * others are ignored in the C version.
  1456. * FIXME: Write HQ version.
  1457. */
  1458. #if HAVE_7REGS
  1459. static inline void RENAME(rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  1460. int width, int height,
  1461. int lumStride, int chromStride, int srcStride,
  1462. int32_t *rgb2yuv)
  1463. {
  1464. #define BGR2Y_IDX "16*4+16*32"
  1465. #define BGR2U_IDX "16*4+16*33"
  1466. #define BGR2V_IDX "16*4+16*34"
  1467. int y;
  1468. const x86_reg chromWidth= width>>1;
  1469. if (height > 2) {
  1470. ff_rgb24toyv12_c(src, ydst, udst, vdst, width, 2, lumStride, chromStride, srcStride, rgb2yuv);
  1471. src += 2*srcStride;
  1472. ydst += 2*lumStride;
  1473. udst += chromStride;
  1474. vdst += chromStride;
  1475. height -= 2;
  1476. }
  1477. for (y=0; y<height-2; y+=2) {
  1478. int i;
  1479. for (i=0; i<2; i++) {
  1480. __asm__ volatile(
  1481. "mov %2, %%"FF_REG_a"\n\t"
  1482. "movq "BGR2Y_IDX"(%3), %%mm6 \n\t"
  1483. "movq "MANGLE(ff_w1111)", %%mm5 \n\t"
  1484. "pxor %%mm7, %%mm7 \n\t"
  1485. "lea (%%"FF_REG_a", %%"FF_REG_a", 2), %%"FF_REG_d" \n\t"
  1486. ".p2align 4 \n\t"
  1487. "1: \n\t"
  1488. PREFETCH" 64(%0, %%"FF_REG_d") \n\t"
  1489. "movd (%0, %%"FF_REG_d"), %%mm0 \n\t"
  1490. "movd 3(%0, %%"FF_REG_d"), %%mm1 \n\t"
  1491. "punpcklbw %%mm7, %%mm0 \n\t"
  1492. "punpcklbw %%mm7, %%mm1 \n\t"
  1493. "movd 6(%0, %%"FF_REG_d"), %%mm2 \n\t"
  1494. "movd 9(%0, %%"FF_REG_d"), %%mm3 \n\t"
  1495. "punpcklbw %%mm7, %%mm2 \n\t"
  1496. "punpcklbw %%mm7, %%mm3 \n\t"
  1497. "pmaddwd %%mm6, %%mm0 \n\t"
  1498. "pmaddwd %%mm6, %%mm1 \n\t"
  1499. "pmaddwd %%mm6, %%mm2 \n\t"
  1500. "pmaddwd %%mm6, %%mm3 \n\t"
  1501. "psrad $8, %%mm0 \n\t"
  1502. "psrad $8, %%mm1 \n\t"
  1503. "psrad $8, %%mm2 \n\t"
  1504. "psrad $8, %%mm3 \n\t"
  1505. "packssdw %%mm1, %%mm0 \n\t"
  1506. "packssdw %%mm3, %%mm2 \n\t"
  1507. "pmaddwd %%mm5, %%mm0 \n\t"
  1508. "pmaddwd %%mm5, %%mm2 \n\t"
  1509. "packssdw %%mm2, %%mm0 \n\t"
  1510. "psraw $7, %%mm0 \n\t"
  1511. "movd 12(%0, %%"FF_REG_d"), %%mm4 \n\t"
  1512. "movd 15(%0, %%"FF_REG_d"), %%mm1 \n\t"
  1513. "punpcklbw %%mm7, %%mm4 \n\t"
  1514. "punpcklbw %%mm7, %%mm1 \n\t"
  1515. "movd 18(%0, %%"FF_REG_d"), %%mm2 \n\t"
  1516. "movd 21(%0, %%"FF_REG_d"), %%mm3 \n\t"
  1517. "punpcklbw %%mm7, %%mm2 \n\t"
  1518. "punpcklbw %%mm7, %%mm3 \n\t"
  1519. "pmaddwd %%mm6, %%mm4 \n\t"
  1520. "pmaddwd %%mm6, %%mm1 \n\t"
  1521. "pmaddwd %%mm6, %%mm2 \n\t"
  1522. "pmaddwd %%mm6, %%mm3 \n\t"
  1523. "psrad $8, %%mm4 \n\t"
  1524. "psrad $8, %%mm1 \n\t"
  1525. "psrad $8, %%mm2 \n\t"
  1526. "psrad $8, %%mm3 \n\t"
  1527. "packssdw %%mm1, %%mm4 \n\t"
  1528. "packssdw %%mm3, %%mm2 \n\t"
  1529. "pmaddwd %%mm5, %%mm4 \n\t"
  1530. "pmaddwd %%mm5, %%mm2 \n\t"
  1531. "add $24, %%"FF_REG_d"\n\t"
  1532. "packssdw %%mm2, %%mm4 \n\t"
  1533. "psraw $7, %%mm4 \n\t"
  1534. "packuswb %%mm4, %%mm0 \n\t"
  1535. "paddusb "MANGLE(ff_bgr2YOffset)", %%mm0 \n\t"
  1536. MOVNTQ" %%mm0, (%1, %%"FF_REG_a") \n\t"
  1537. "add $8, %%"FF_REG_a" \n\t"
  1538. " js 1b \n\t"
  1539. : : "r" (src+width*3), "r" (ydst+width), "g" ((x86_reg)-width), "r"(rgb2yuv)
  1540. NAMED_CONSTRAINTS_ADD(ff_w1111,ff_bgr2YOffset)
  1541. : "%"FF_REG_a, "%"FF_REG_d
  1542. );
  1543. ydst += lumStride;
  1544. src += srcStride;
  1545. }
  1546. src -= srcStride*2;
  1547. __asm__ volatile(
  1548. "mov %4, %%"FF_REG_a"\n\t"
  1549. "movq "MANGLE(ff_w1111)", %%mm5 \n\t"
  1550. "movq "BGR2U_IDX"(%5), %%mm6 \n\t"
  1551. "pxor %%mm7, %%mm7 \n\t"
  1552. "lea (%%"FF_REG_a", %%"FF_REG_a", 2), %%"FF_REG_d" \n\t"
  1553. "add %%"FF_REG_d", %%"FF_REG_d"\n\t"
  1554. ".p2align 4 \n\t"
  1555. "1: \n\t"
  1556. PREFETCH" 64(%0, %%"FF_REG_d") \n\t"
  1557. PREFETCH" 64(%1, %%"FF_REG_d") \n\t"
  1558. "movq (%0, %%"FF_REG_d"), %%mm0 \n\t"
  1559. "movq (%1, %%"FF_REG_d"), %%mm1 \n\t"
  1560. "movq 6(%0, %%"FF_REG_d"), %%mm2 \n\t"
  1561. "movq 6(%1, %%"FF_REG_d"), %%mm3 \n\t"
  1562. PAVGB" %%mm1, %%mm0 \n\t"
  1563. PAVGB" %%mm3, %%mm2 \n\t"
  1564. "movq %%mm0, %%mm1 \n\t"
  1565. "movq %%mm2, %%mm3 \n\t"
  1566. "psrlq $24, %%mm0 \n\t"
  1567. "psrlq $24, %%mm2 \n\t"
  1568. PAVGB" %%mm1, %%mm0 \n\t"
  1569. PAVGB" %%mm3, %%mm2 \n\t"
  1570. "punpcklbw %%mm7, %%mm0 \n\t"
  1571. "punpcklbw %%mm7, %%mm2 \n\t"
  1572. "movq "BGR2V_IDX"(%5), %%mm1 \n\t"
  1573. "movq "BGR2V_IDX"(%5), %%mm3 \n\t"
  1574. "pmaddwd %%mm0, %%mm1 \n\t"
  1575. "pmaddwd %%mm2, %%mm3 \n\t"
  1576. "pmaddwd %%mm6, %%mm0 \n\t"
  1577. "pmaddwd %%mm6, %%mm2 \n\t"
  1578. "psrad $8, %%mm0 \n\t"
  1579. "psrad $8, %%mm1 \n\t"
  1580. "psrad $8, %%mm2 \n\t"
  1581. "psrad $8, %%mm3 \n\t"
  1582. "packssdw %%mm2, %%mm0 \n\t"
  1583. "packssdw %%mm3, %%mm1 \n\t"
  1584. "pmaddwd %%mm5, %%mm0 \n\t"
  1585. "pmaddwd %%mm5, %%mm1 \n\t"
  1586. "packssdw %%mm1, %%mm0 \n\t" // V1 V0 U1 U0
  1587. "psraw $7, %%mm0 \n\t"
  1588. "movq 12(%0, %%"FF_REG_d"), %%mm4 \n\t"
  1589. "movq 12(%1, %%"FF_REG_d"), %%mm1 \n\t"
  1590. "movq 18(%0, %%"FF_REG_d"), %%mm2 \n\t"
  1591. "movq 18(%1, %%"FF_REG_d"), %%mm3 \n\t"
  1592. PAVGB" %%mm1, %%mm4 \n\t"
  1593. PAVGB" %%mm3, %%mm2 \n\t"
  1594. "movq %%mm4, %%mm1 \n\t"
  1595. "movq %%mm2, %%mm3 \n\t"
  1596. "psrlq $24, %%mm4 \n\t"
  1597. "psrlq $24, %%mm2 \n\t"
  1598. PAVGB" %%mm1, %%mm4 \n\t"
  1599. PAVGB" %%mm3, %%mm2 \n\t"
  1600. "punpcklbw %%mm7, %%mm4 \n\t"
  1601. "punpcklbw %%mm7, %%mm2 \n\t"
  1602. "movq "BGR2V_IDX"(%5), %%mm1 \n\t"
  1603. "movq "BGR2V_IDX"(%5), %%mm3 \n\t"
  1604. "pmaddwd %%mm4, %%mm1 \n\t"
  1605. "pmaddwd %%mm2, %%mm3 \n\t"
  1606. "pmaddwd %%mm6, %%mm4 \n\t"
  1607. "pmaddwd %%mm6, %%mm2 \n\t"
  1608. "psrad $8, %%mm4 \n\t"
  1609. "psrad $8, %%mm1 \n\t"
  1610. "psrad $8, %%mm2 \n\t"
  1611. "psrad $8, %%mm3 \n\t"
  1612. "packssdw %%mm2, %%mm4 \n\t"
  1613. "packssdw %%mm3, %%mm1 \n\t"
  1614. "pmaddwd %%mm5, %%mm4 \n\t"
  1615. "pmaddwd %%mm5, %%mm1 \n\t"
  1616. "add $24, %%"FF_REG_d"\n\t"
  1617. "packssdw %%mm1, %%mm4 \n\t" // V3 V2 U3 U2
  1618. "psraw $7, %%mm4 \n\t"
  1619. "movq %%mm0, %%mm1 \n\t"
  1620. "punpckldq %%mm4, %%mm0 \n\t"
  1621. "punpckhdq %%mm4, %%mm1 \n\t"
  1622. "packsswb %%mm1, %%mm0 \n\t"
  1623. "paddb "MANGLE(ff_bgr2UVOffset)", %%mm0 \n\t"
  1624. "movd %%mm0, (%2, %%"FF_REG_a") \n\t"
  1625. "punpckhdq %%mm0, %%mm0 \n\t"
  1626. "movd %%mm0, (%3, %%"FF_REG_a") \n\t"
  1627. "add $4, %%"FF_REG_a" \n\t"
  1628. " js 1b \n\t"
  1629. : : "r" (src+chromWidth*6), "r" (src+srcStride+chromWidth*6), "r" (udst+chromWidth), "r" (vdst+chromWidth), "g" (-chromWidth), "r"(rgb2yuv)
  1630. NAMED_CONSTRAINTS_ADD(ff_w1111,ff_bgr2UVOffset)
  1631. : "%"FF_REG_a, "%"FF_REG_d
  1632. );
  1633. udst += chromStride;
  1634. vdst += chromStride;
  1635. src += srcStride*2;
  1636. }
  1637. __asm__ volatile(EMMS" \n\t"
  1638. SFENCE" \n\t"
  1639. :::"memory");
  1640. ff_rgb24toyv12_c(src, ydst, udst, vdst, width, height-y, lumStride, chromStride, srcStride, rgb2yuv);
  1641. }
  1642. #endif /* HAVE_7REGS */
  1643. #endif /* !COMPILE_TEMPLATE_SSE2 */
  1644. #if !COMPILE_TEMPLATE_AVX && COMPILE_TEMPLATE_SSE2
  1645. static void RENAME(interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dest,
  1646. int width, int height, int src1Stride,
  1647. int src2Stride, int dstStride)
  1648. {
  1649. int h;
  1650. for (h=0; h < height; h++) {
  1651. int w;
  1652. if (width >= 16) {
  1653. if (!((((intptr_t)src1) | ((intptr_t)src2) | ((intptr_t)dest))&15)) {
  1654. __asm__(
  1655. "xor %%"FF_REG_a", %%"FF_REG_a" \n\t"
  1656. "1: \n\t"
  1657. PREFETCH" 64(%1, %%"FF_REG_a") \n\t"
  1658. PREFETCH" 64(%2, %%"FF_REG_a") \n\t"
  1659. "movdqa (%1, %%"FF_REG_a"), %%xmm0 \n\t"
  1660. "movdqa (%1, %%"FF_REG_a"), %%xmm1 \n\t"
  1661. "movdqa (%2, %%"FF_REG_a"), %%xmm2 \n\t"
  1662. "punpcklbw %%xmm2, %%xmm0 \n\t"
  1663. "punpckhbw %%xmm2, %%xmm1 \n\t"
  1664. "movntdq %%xmm0, (%0, %%"FF_REG_a", 2) \n\t"
  1665. "movntdq %%xmm1, 16(%0, %%"FF_REG_a", 2) \n\t"
  1666. "add $16, %%"FF_REG_a" \n\t"
  1667. "cmp %3, %%"FF_REG_a" \n\t"
  1668. " jb 1b \n\t"
  1669. ::"r"(dest), "r"(src1), "r"(src2), "r" ((x86_reg)width-15)
  1670. : "memory", XMM_CLOBBERS("xmm0", "xmm1", "xmm2",) "%"FF_REG_a
  1671. );
  1672. } else
  1673. __asm__(
  1674. "xor %%"FF_REG_a", %%"FF_REG_a" \n\t"
  1675. "1: \n\t"
  1676. PREFETCH" 64(%1, %%"FF_REG_a") \n\t"
  1677. PREFETCH" 64(%2, %%"FF_REG_a") \n\t"
  1678. "movq (%1, %%"FF_REG_a"), %%mm0 \n\t"
  1679. "movq 8(%1, %%"FF_REG_a"), %%mm2 \n\t"
  1680. "movq %%mm0, %%mm1 \n\t"
  1681. "movq %%mm2, %%mm3 \n\t"
  1682. "movq (%2, %%"FF_REG_a"), %%mm4 \n\t"
  1683. "movq 8(%2, %%"FF_REG_a"), %%mm5 \n\t"
  1684. "punpcklbw %%mm4, %%mm0 \n\t"
  1685. "punpckhbw %%mm4, %%mm1 \n\t"
  1686. "punpcklbw %%mm5, %%mm2 \n\t"
  1687. "punpckhbw %%mm5, %%mm3 \n\t"
  1688. MOVNTQ" %%mm0, (%0, %%"FF_REG_a", 2) \n\t"
  1689. MOVNTQ" %%mm1, 8(%0, %%"FF_REG_a", 2) \n\t"
  1690. MOVNTQ" %%mm2, 16(%0, %%"FF_REG_a", 2) \n\t"
  1691. MOVNTQ" %%mm3, 24(%0, %%"FF_REG_a", 2) \n\t"
  1692. "add $16, %%"FF_REG_a" \n\t"
  1693. "cmp %3, %%"FF_REG_a" \n\t"
  1694. " jb 1b \n\t"
  1695. ::"r"(dest), "r"(src1), "r"(src2), "r" ((x86_reg)width-15)
  1696. : "memory", "%"FF_REG_a
  1697. );
  1698. }
  1699. for (w= (width&(~15)); w < width; w++) {
  1700. dest[2*w+0] = src1[w];
  1701. dest[2*w+1] = src2[w];
  1702. }
  1703. dest += dstStride;
  1704. src1 += src1Stride;
  1705. src2 += src2Stride;
  1706. }
  1707. __asm__(
  1708. EMMS" \n\t"
  1709. SFENCE" \n\t"
  1710. ::: "memory"
  1711. );
  1712. }
  1713. #endif /* !COMPILE_TEMPLATE_AVX && COMPILE_TEMPLATE_SSE2 */
  1714. #if !COMPILE_TEMPLATE_AVX || HAVE_AVX_EXTERNAL
  1715. #if COMPILE_TEMPLATE_SSE2 && HAVE_X86ASM
  1716. void RENAME(ff_nv12ToUV)(uint8_t *dstU, uint8_t *dstV,
  1717. const uint8_t *unused,
  1718. const uint8_t *src1,
  1719. const uint8_t *src2,
  1720. int w,
  1721. uint32_t *unused2);
  1722. static void RENAME(deinterleaveBytes)(const uint8_t *src, uint8_t *dst1, uint8_t *dst2,
  1723. int width, int height, int srcStride,
  1724. int dst1Stride, int dst2Stride)
  1725. {
  1726. int h;
  1727. for (h = 0; h < height; h++) {
  1728. RENAME(ff_nv12ToUV)(dst1, dst2, NULL, src, NULL, width, NULL);
  1729. src += srcStride;
  1730. dst1 += dst1Stride;
  1731. dst2 += dst2Stride;
  1732. }
  1733. __asm__(
  1734. SFENCE" \n\t"
  1735. ::: "memory"
  1736. );
  1737. }
  1738. #endif /* COMPILE_TEMPLATE_SSE2 && HAVE_X86ASM */
  1739. #endif /* !COMPILE_TEMPLATE_AVX || HAVE_AVX_EXTERNAL */
  1740. #if !COMPILE_TEMPLATE_SSE2
  1741. static inline void RENAME(vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
  1742. uint8_t *dst1, uint8_t *dst2,
  1743. int width, int height,
  1744. int srcStride1, int srcStride2,
  1745. int dstStride1, int dstStride2)
  1746. {
  1747. x86_reg x, y;
  1748. int w,h;
  1749. w=width/2; h=height/2;
  1750. __asm__ volatile(
  1751. PREFETCH" %0 \n\t"
  1752. PREFETCH" %1 \n\t"
  1753. ::"m"(*(src1+srcStride1)),"m"(*(src2+srcStride2)):"memory");
  1754. for (y=0;y<h;y++) {
  1755. const uint8_t* s1=src1+srcStride1*(y>>1);
  1756. uint8_t* d=dst1+dstStride1*y;
  1757. x=0;
  1758. for (;x<w-31;x+=32) {
  1759. __asm__ volatile(
  1760. PREFETCH" 32(%1,%2) \n\t"
  1761. "movq (%1,%2), %%mm0 \n\t"
  1762. "movq 8(%1,%2), %%mm2 \n\t"
  1763. "movq 16(%1,%2), %%mm4 \n\t"
  1764. "movq 24(%1,%2), %%mm6 \n\t"
  1765. "movq %%mm0, %%mm1 \n\t"
  1766. "movq %%mm2, %%mm3 \n\t"
  1767. "movq %%mm4, %%mm5 \n\t"
  1768. "movq %%mm6, %%mm7 \n\t"
  1769. "punpcklbw %%mm0, %%mm0 \n\t"
  1770. "punpckhbw %%mm1, %%mm1 \n\t"
  1771. "punpcklbw %%mm2, %%mm2 \n\t"
  1772. "punpckhbw %%mm3, %%mm3 \n\t"
  1773. "punpcklbw %%mm4, %%mm4 \n\t"
  1774. "punpckhbw %%mm5, %%mm5 \n\t"
  1775. "punpcklbw %%mm6, %%mm6 \n\t"
  1776. "punpckhbw %%mm7, %%mm7 \n\t"
  1777. MOVNTQ" %%mm0, (%0,%2,2) \n\t"
  1778. MOVNTQ" %%mm1, 8(%0,%2,2) \n\t"
  1779. MOVNTQ" %%mm2, 16(%0,%2,2) \n\t"
  1780. MOVNTQ" %%mm3, 24(%0,%2,2) \n\t"
  1781. MOVNTQ" %%mm4, 32(%0,%2,2) \n\t"
  1782. MOVNTQ" %%mm5, 40(%0,%2,2) \n\t"
  1783. MOVNTQ" %%mm6, 48(%0,%2,2) \n\t"
  1784. MOVNTQ" %%mm7, 56(%0,%2,2)"
  1785. :: "r"(d), "r"(s1), "r"(x)
  1786. :"memory");
  1787. }
  1788. for (;x<w;x++) d[2*x]=d[2*x+1]=s1[x];
  1789. }
  1790. for (y=0;y<h;y++) {
  1791. const uint8_t* s2=src2+srcStride2*(y>>1);
  1792. uint8_t* d=dst2+dstStride2*y;
  1793. x=0;
  1794. for (;x<w-31;x+=32) {
  1795. __asm__ volatile(
  1796. PREFETCH" 32(%1,%2) \n\t"
  1797. "movq (%1,%2), %%mm0 \n\t"
  1798. "movq 8(%1,%2), %%mm2 \n\t"
  1799. "movq 16(%1,%2), %%mm4 \n\t"
  1800. "movq 24(%1,%2), %%mm6 \n\t"
  1801. "movq %%mm0, %%mm1 \n\t"
  1802. "movq %%mm2, %%mm3 \n\t"
  1803. "movq %%mm4, %%mm5 \n\t"
  1804. "movq %%mm6, %%mm7 \n\t"
  1805. "punpcklbw %%mm0, %%mm0 \n\t"
  1806. "punpckhbw %%mm1, %%mm1 \n\t"
  1807. "punpcklbw %%mm2, %%mm2 \n\t"
  1808. "punpckhbw %%mm3, %%mm3 \n\t"
  1809. "punpcklbw %%mm4, %%mm4 \n\t"
  1810. "punpckhbw %%mm5, %%mm5 \n\t"
  1811. "punpcklbw %%mm6, %%mm6 \n\t"
  1812. "punpckhbw %%mm7, %%mm7 \n\t"
  1813. MOVNTQ" %%mm0, (%0,%2,2) \n\t"
  1814. MOVNTQ" %%mm1, 8(%0,%2,2) \n\t"
  1815. MOVNTQ" %%mm2, 16(%0,%2,2) \n\t"
  1816. MOVNTQ" %%mm3, 24(%0,%2,2) \n\t"
  1817. MOVNTQ" %%mm4, 32(%0,%2,2) \n\t"
  1818. MOVNTQ" %%mm5, 40(%0,%2,2) \n\t"
  1819. MOVNTQ" %%mm6, 48(%0,%2,2) \n\t"
  1820. MOVNTQ" %%mm7, 56(%0,%2,2)"
  1821. :: "r"(d), "r"(s2), "r"(x)
  1822. :"memory");
  1823. }
  1824. for (;x<w;x++) d[2*x]=d[2*x+1]=s2[x];
  1825. }
  1826. __asm__(
  1827. EMMS" \n\t"
  1828. SFENCE" \n\t"
  1829. ::: "memory"
  1830. );
  1831. }
  1832. static inline void RENAME(yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
  1833. uint8_t *dst,
  1834. int width, int height,
  1835. int srcStride1, int srcStride2,
  1836. int srcStride3, int dstStride)
  1837. {
  1838. x86_reg x;
  1839. int y,w,h;
  1840. w=width/2; h=height;
  1841. for (y=0;y<h;y++) {
  1842. const uint8_t* yp=src1+srcStride1*y;
  1843. const uint8_t* up=src2+srcStride2*(y>>2);
  1844. const uint8_t* vp=src3+srcStride3*(y>>2);
  1845. uint8_t* d=dst+dstStride*y;
  1846. x=0;
  1847. for (;x<w-7;x+=8) {
  1848. __asm__ volatile(
  1849. PREFETCH" 32(%1, %0) \n\t"
  1850. PREFETCH" 32(%2, %0) \n\t"
  1851. PREFETCH" 32(%3, %0) \n\t"
  1852. "movq (%1, %0, 4), %%mm0 \n\t" /* Y0Y1Y2Y3Y4Y5Y6Y7 */
  1853. "movq (%2, %0), %%mm1 \n\t" /* U0U1U2U3U4U5U6U7 */
  1854. "movq (%3, %0), %%mm2 \n\t" /* V0V1V2V3V4V5V6V7 */
  1855. "movq %%mm0, %%mm3 \n\t" /* Y0Y1Y2Y3Y4Y5Y6Y7 */
  1856. "movq %%mm1, %%mm4 \n\t" /* U0U1U2U3U4U5U6U7 */
  1857. "movq %%mm2, %%mm5 \n\t" /* V0V1V2V3V4V5V6V7 */
  1858. "punpcklbw %%mm1, %%mm1 \n\t" /* U0U0 U1U1 U2U2 U3U3 */
  1859. "punpcklbw %%mm2, %%mm2 \n\t" /* V0V0 V1V1 V2V2 V3V3 */
  1860. "punpckhbw %%mm4, %%mm4 \n\t" /* U4U4 U5U5 U6U6 U7U7 */
  1861. "punpckhbw %%mm5, %%mm5 \n\t" /* V4V4 V5V5 V6V6 V7V7 */
  1862. "movq %%mm1, %%mm6 \n\t"
  1863. "punpcklbw %%mm2, %%mm1 \n\t" /* U0V0 U0V0 U1V1 U1V1*/
  1864. "punpcklbw %%mm1, %%mm0 \n\t" /* Y0U0 Y1V0 Y2U0 Y3V0*/
  1865. "punpckhbw %%mm1, %%mm3 \n\t" /* Y4U1 Y5V1 Y6U1 Y7V1*/
  1866. MOVNTQ" %%mm0, (%4, %0, 8) \n\t"
  1867. MOVNTQ" %%mm3, 8(%4, %0, 8) \n\t"
  1868. "punpckhbw %%mm2, %%mm6 \n\t" /* U2V2 U2V2 U3V3 U3V3*/
  1869. "movq 8(%1, %0, 4), %%mm0 \n\t"
  1870. "movq %%mm0, %%mm3 \n\t"
  1871. "punpcklbw %%mm6, %%mm0 \n\t" /* Y U2 Y V2 Y U2 Y V2*/
  1872. "punpckhbw %%mm6, %%mm3 \n\t" /* Y U3 Y V3 Y U3 Y V3*/
  1873. MOVNTQ" %%mm0, 16(%4, %0, 8) \n\t"
  1874. MOVNTQ" %%mm3, 24(%4, %0, 8) \n\t"
  1875. "movq %%mm4, %%mm6 \n\t"
  1876. "movq 16(%1, %0, 4), %%mm0 \n\t"
  1877. "movq %%mm0, %%mm3 \n\t"
  1878. "punpcklbw %%mm5, %%mm4 \n\t"
  1879. "punpcklbw %%mm4, %%mm0 \n\t" /* Y U4 Y V4 Y U4 Y V4*/
  1880. "punpckhbw %%mm4, %%mm3 \n\t" /* Y U5 Y V5 Y U5 Y V5*/
  1881. MOVNTQ" %%mm0, 32(%4, %0, 8) \n\t"
  1882. MOVNTQ" %%mm3, 40(%4, %0, 8) \n\t"
  1883. "punpckhbw %%mm5, %%mm6 \n\t"
  1884. "movq 24(%1, %0, 4), %%mm0 \n\t"
  1885. "movq %%mm0, %%mm3 \n\t"
  1886. "punpcklbw %%mm6, %%mm0 \n\t" /* Y U6 Y V6 Y U6 Y V6*/
  1887. "punpckhbw %%mm6, %%mm3 \n\t" /* Y U7 Y V7 Y U7 Y V7*/
  1888. MOVNTQ" %%mm0, 48(%4, %0, 8) \n\t"
  1889. MOVNTQ" %%mm3, 56(%4, %0, 8) \n\t"
  1890. : "+r" (x)
  1891. : "r"(yp), "r" (up), "r"(vp), "r"(d)
  1892. :"memory");
  1893. }
  1894. for (; x<w; x++) {
  1895. const int x2 = x<<2;
  1896. d[8*x+0] = yp[x2];
  1897. d[8*x+1] = up[x];
  1898. d[8*x+2] = yp[x2+1];
  1899. d[8*x+3] = vp[x];
  1900. d[8*x+4] = yp[x2+2];
  1901. d[8*x+5] = up[x];
  1902. d[8*x+6] = yp[x2+3];
  1903. d[8*x+7] = vp[x];
  1904. }
  1905. }
  1906. __asm__(
  1907. EMMS" \n\t"
  1908. SFENCE" \n\t"
  1909. ::: "memory"
  1910. );
  1911. }
  1912. static void RENAME(extract_even)(const uint8_t *src, uint8_t *dst, x86_reg count)
  1913. {
  1914. dst += count;
  1915. src += 2*count;
  1916. count= - count;
  1917. if(count <= -16) {
  1918. count += 15;
  1919. __asm__ volatile(
  1920. "pcmpeqw %%mm7, %%mm7 \n\t"
  1921. "psrlw $8, %%mm7 \n\t"
  1922. "1: \n\t"
  1923. "movq -30(%1, %0, 2), %%mm0 \n\t"
  1924. "movq -22(%1, %0, 2), %%mm1 \n\t"
  1925. "movq -14(%1, %0, 2), %%mm2 \n\t"
  1926. "movq -6(%1, %0, 2), %%mm3 \n\t"
  1927. "pand %%mm7, %%mm0 \n\t"
  1928. "pand %%mm7, %%mm1 \n\t"
  1929. "pand %%mm7, %%mm2 \n\t"
  1930. "pand %%mm7, %%mm3 \n\t"
  1931. "packuswb %%mm1, %%mm0 \n\t"
  1932. "packuswb %%mm3, %%mm2 \n\t"
  1933. MOVNTQ" %%mm0,-15(%2, %0) \n\t"
  1934. MOVNTQ" %%mm2,- 7(%2, %0) \n\t"
  1935. "add $16, %0 \n\t"
  1936. " js 1b \n\t"
  1937. : "+r"(count)
  1938. : "r"(src), "r"(dst)
  1939. );
  1940. count -= 15;
  1941. }
  1942. while(count<0) {
  1943. dst[count]= src[2*count];
  1944. count++;
  1945. }
  1946. }
  1947. static void RENAME(extract_odd)(const uint8_t *src, uint8_t *dst, x86_reg count)
  1948. {
  1949. src ++;
  1950. dst += count;
  1951. src += 2*count;
  1952. count= - count;
  1953. if(count < -16) {
  1954. count += 16;
  1955. __asm__ volatile(
  1956. "pcmpeqw %%mm7, %%mm7 \n\t"
  1957. "psrlw $8, %%mm7 \n\t"
  1958. "1: \n\t"
  1959. "movq -32(%1, %0, 2), %%mm0 \n\t"
  1960. "movq -24(%1, %0, 2), %%mm1 \n\t"
  1961. "movq -16(%1, %0, 2), %%mm2 \n\t"
  1962. "movq -8(%1, %0, 2), %%mm3 \n\t"
  1963. "pand %%mm7, %%mm0 \n\t"
  1964. "pand %%mm7, %%mm1 \n\t"
  1965. "pand %%mm7, %%mm2 \n\t"
  1966. "pand %%mm7, %%mm3 \n\t"
  1967. "packuswb %%mm1, %%mm0 \n\t"
  1968. "packuswb %%mm3, %%mm2 \n\t"
  1969. MOVNTQ" %%mm0,-16(%2, %0) \n\t"
  1970. MOVNTQ" %%mm2,- 8(%2, %0) \n\t"
  1971. "add $16, %0 \n\t"
  1972. " js 1b \n\t"
  1973. : "+r"(count)
  1974. : "r"(src), "r"(dst)
  1975. );
  1976. count -= 16;
  1977. }
  1978. while(count<0) {
  1979. dst[count]= src[2*count];
  1980. count++;
  1981. }
  1982. }
  1983. #if ARCH_X86_32
  1984. static void RENAME(extract_even2)(const uint8_t *src, uint8_t *dst0, uint8_t *dst1, x86_reg count)
  1985. {
  1986. dst0+= count;
  1987. dst1+= count;
  1988. src += 4*count;
  1989. count= - count;
  1990. if(count <= -8) {
  1991. count += 7;
  1992. __asm__ volatile(
  1993. "pcmpeqw %%mm7, %%mm7 \n\t"
  1994. "psrlw $8, %%mm7 \n\t"
  1995. "1: \n\t"
  1996. "movq -28(%1, %0, 4), %%mm0 \n\t"
  1997. "movq -20(%1, %0, 4), %%mm1 \n\t"
  1998. "movq -12(%1, %0, 4), %%mm2 \n\t"
  1999. "movq -4(%1, %0, 4), %%mm3 \n\t"
  2000. "pand %%mm7, %%mm0 \n\t"
  2001. "pand %%mm7, %%mm1 \n\t"
  2002. "pand %%mm7, %%mm2 \n\t"
  2003. "pand %%mm7, %%mm3 \n\t"
  2004. "packuswb %%mm1, %%mm0 \n\t"
  2005. "packuswb %%mm3, %%mm2 \n\t"
  2006. "movq %%mm0, %%mm1 \n\t"
  2007. "movq %%mm2, %%mm3 \n\t"
  2008. "psrlw $8, %%mm0 \n\t"
  2009. "psrlw $8, %%mm2 \n\t"
  2010. "pand %%mm7, %%mm1 \n\t"
  2011. "pand %%mm7, %%mm3 \n\t"
  2012. "packuswb %%mm2, %%mm0 \n\t"
  2013. "packuswb %%mm3, %%mm1 \n\t"
  2014. MOVNTQ" %%mm0,- 7(%3, %0) \n\t"
  2015. MOVNTQ" %%mm1,- 7(%2, %0) \n\t"
  2016. "add $8, %0 \n\t"
  2017. " js 1b \n\t"
  2018. : "+r"(count)
  2019. : "r"(src), "r"(dst0), "r"(dst1)
  2020. );
  2021. count -= 7;
  2022. }
  2023. while(count<0) {
  2024. dst0[count]= src[4*count+0];
  2025. dst1[count]= src[4*count+2];
  2026. count++;
  2027. }
  2028. }
  2029. #endif /* ARCH_X86_32 */
  2030. static void RENAME(extract_even2avg)(const uint8_t *src0, const uint8_t *src1, uint8_t *dst0, uint8_t *dst1, x86_reg count)
  2031. {
  2032. dst0 += count;
  2033. dst1 += count;
  2034. src0 += 4*count;
  2035. src1 += 4*count;
  2036. count= - count;
  2037. #ifdef PAVGB
  2038. if(count <= -8) {
  2039. count += 7;
  2040. __asm__ volatile(
  2041. "pcmpeqw %%mm7, %%mm7 \n\t"
  2042. "psrlw $8, %%mm7 \n\t"
  2043. "1: \n\t"
  2044. "movq -28(%1, %0, 4), %%mm0 \n\t"
  2045. "movq -20(%1, %0, 4), %%mm1 \n\t"
  2046. "movq -12(%1, %0, 4), %%mm2 \n\t"
  2047. "movq -4(%1, %0, 4), %%mm3 \n\t"
  2048. PAVGB" -28(%2, %0, 4), %%mm0 \n\t"
  2049. PAVGB" -20(%2, %0, 4), %%mm1 \n\t"
  2050. PAVGB" -12(%2, %0, 4), %%mm2 \n\t"
  2051. PAVGB" - 4(%2, %0, 4), %%mm3 \n\t"
  2052. "pand %%mm7, %%mm0 \n\t"
  2053. "pand %%mm7, %%mm1 \n\t"
  2054. "pand %%mm7, %%mm2 \n\t"
  2055. "pand %%mm7, %%mm3 \n\t"
  2056. "packuswb %%mm1, %%mm0 \n\t"
  2057. "packuswb %%mm3, %%mm2 \n\t"
  2058. "movq %%mm0, %%mm1 \n\t"
  2059. "movq %%mm2, %%mm3 \n\t"
  2060. "psrlw $8, %%mm0 \n\t"
  2061. "psrlw $8, %%mm2 \n\t"
  2062. "pand %%mm7, %%mm1 \n\t"
  2063. "pand %%mm7, %%mm3 \n\t"
  2064. "packuswb %%mm2, %%mm0 \n\t"
  2065. "packuswb %%mm3, %%mm1 \n\t"
  2066. MOVNTQ" %%mm0,- 7(%4, %0) \n\t"
  2067. MOVNTQ" %%mm1,- 7(%3, %0) \n\t"
  2068. "add $8, %0 \n\t"
  2069. " js 1b \n\t"
  2070. : "+r"(count)
  2071. : "r"(src0), "r"(src1), "r"(dst0), "r"(dst1)
  2072. );
  2073. count -= 7;
  2074. }
  2075. #endif
  2076. while(count<0) {
  2077. dst0[count]= (src0[4*count+0]+src1[4*count+0])>>1;
  2078. dst1[count]= (src0[4*count+2]+src1[4*count+2])>>1;
  2079. count++;
  2080. }
  2081. }
  2082. static void RENAME(extract_odd2)(const uint8_t *src, uint8_t *dst0, uint8_t *dst1, x86_reg count)
  2083. {
  2084. dst0+= count;
  2085. dst1+= count;
  2086. src += 4*count;
  2087. count= - count;
  2088. if(count <= -8) {
  2089. count += 7;
  2090. __asm__ volatile(
  2091. "pcmpeqw %%mm7, %%mm7 \n\t"
  2092. "psrlw $8, %%mm7 \n\t"
  2093. "1: \n\t"
  2094. "movq -28(%1, %0, 4), %%mm0 \n\t"
  2095. "movq -20(%1, %0, 4), %%mm1 \n\t"
  2096. "movq -12(%1, %0, 4), %%mm2 \n\t"
  2097. "movq -4(%1, %0, 4), %%mm3 \n\t"
  2098. "psrlw $8, %%mm0 \n\t"
  2099. "psrlw $8, %%mm1 \n\t"
  2100. "psrlw $8, %%mm2 \n\t"
  2101. "psrlw $8, %%mm3 \n\t"
  2102. "packuswb %%mm1, %%mm0 \n\t"
  2103. "packuswb %%mm3, %%mm2 \n\t"
  2104. "movq %%mm0, %%mm1 \n\t"
  2105. "movq %%mm2, %%mm3 \n\t"
  2106. "psrlw $8, %%mm0 \n\t"
  2107. "psrlw $8, %%mm2 \n\t"
  2108. "pand %%mm7, %%mm1 \n\t"
  2109. "pand %%mm7, %%mm3 \n\t"
  2110. "packuswb %%mm2, %%mm0 \n\t"
  2111. "packuswb %%mm3, %%mm1 \n\t"
  2112. MOVNTQ" %%mm0,- 7(%3, %0) \n\t"
  2113. MOVNTQ" %%mm1,- 7(%2, %0) \n\t"
  2114. "add $8, %0 \n\t"
  2115. " js 1b \n\t"
  2116. : "+r"(count)
  2117. : "r"(src), "r"(dst0), "r"(dst1)
  2118. );
  2119. count -= 7;
  2120. }
  2121. src++;
  2122. while(count<0) {
  2123. dst0[count]= src[4*count+0];
  2124. dst1[count]= src[4*count+2];
  2125. count++;
  2126. }
  2127. }
  2128. static void RENAME(extract_odd2avg)(const uint8_t *src0, const uint8_t *src1, uint8_t *dst0, uint8_t *dst1, x86_reg count)
  2129. {
  2130. dst0 += count;
  2131. dst1 += count;
  2132. src0 += 4*count;
  2133. src1 += 4*count;
  2134. count= - count;
  2135. #ifdef PAVGB
  2136. if(count <= -8) {
  2137. count += 7;
  2138. __asm__ volatile(
  2139. "pcmpeqw %%mm7, %%mm7 \n\t"
  2140. "psrlw $8, %%mm7 \n\t"
  2141. "1: \n\t"
  2142. "movq -28(%1, %0, 4), %%mm0 \n\t"
  2143. "movq -20(%1, %0, 4), %%mm1 \n\t"
  2144. "movq -12(%1, %0, 4), %%mm2 \n\t"
  2145. "movq -4(%1, %0, 4), %%mm3 \n\t"
  2146. PAVGB" -28(%2, %0, 4), %%mm0 \n\t"
  2147. PAVGB" -20(%2, %0, 4), %%mm1 \n\t"
  2148. PAVGB" -12(%2, %0, 4), %%mm2 \n\t"
  2149. PAVGB" - 4(%2, %0, 4), %%mm3 \n\t"
  2150. "psrlw $8, %%mm0 \n\t"
  2151. "psrlw $8, %%mm1 \n\t"
  2152. "psrlw $8, %%mm2 \n\t"
  2153. "psrlw $8, %%mm3 \n\t"
  2154. "packuswb %%mm1, %%mm0 \n\t"
  2155. "packuswb %%mm3, %%mm2 \n\t"
  2156. "movq %%mm0, %%mm1 \n\t"
  2157. "movq %%mm2, %%mm3 \n\t"
  2158. "psrlw $8, %%mm0 \n\t"
  2159. "psrlw $8, %%mm2 \n\t"
  2160. "pand %%mm7, %%mm1 \n\t"
  2161. "pand %%mm7, %%mm3 \n\t"
  2162. "packuswb %%mm2, %%mm0 \n\t"
  2163. "packuswb %%mm3, %%mm1 \n\t"
  2164. MOVNTQ" %%mm0,- 7(%4, %0) \n\t"
  2165. MOVNTQ" %%mm1,- 7(%3, %0) \n\t"
  2166. "add $8, %0 \n\t"
  2167. " js 1b \n\t"
  2168. : "+r"(count)
  2169. : "r"(src0), "r"(src1), "r"(dst0), "r"(dst1)
  2170. );
  2171. count -= 7;
  2172. }
  2173. #endif
  2174. src0++;
  2175. src1++;
  2176. while(count<0) {
  2177. dst0[count]= (src0[4*count+0]+src1[4*count+0])>>1;
  2178. dst1[count]= (src0[4*count+2]+src1[4*count+2])>>1;
  2179. count++;
  2180. }
  2181. }
  2182. static void RENAME(yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
  2183. int width, int height,
  2184. int lumStride, int chromStride, int srcStride)
  2185. {
  2186. int y;
  2187. const int chromWidth = AV_CEIL_RSHIFT(width, 1);
  2188. for (y=0; y<height; y++) {
  2189. RENAME(extract_even)(src, ydst, width);
  2190. if(y&1) {
  2191. RENAME(extract_odd2avg)(src-srcStride, src, udst, vdst, chromWidth);
  2192. udst+= chromStride;
  2193. vdst+= chromStride;
  2194. }
  2195. src += srcStride;
  2196. ydst+= lumStride;
  2197. }
  2198. __asm__(
  2199. EMMS" \n\t"
  2200. SFENCE" \n\t"
  2201. ::: "memory"
  2202. );
  2203. }
  2204. static void RENAME(yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
  2205. int width, int height,
  2206. int lumStride, int chromStride, int srcStride)
  2207. {
  2208. int y;
  2209. const int chromWidth = AV_CEIL_RSHIFT(width, 1);
  2210. for (y=0; y<height; y++) {
  2211. RENAME(extract_even)(src, ydst, width);
  2212. RENAME(extract_odd2)(src, udst, vdst, chromWidth);
  2213. src += srcStride;
  2214. ydst+= lumStride;
  2215. udst+= chromStride;
  2216. vdst+= chromStride;
  2217. }
  2218. __asm__(
  2219. EMMS" \n\t"
  2220. SFENCE" \n\t"
  2221. ::: "memory"
  2222. );
  2223. }
  2224. static void RENAME(uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
  2225. int width, int height,
  2226. int lumStride, int chromStride, int srcStride)
  2227. {
  2228. int y;
  2229. const int chromWidth = AV_CEIL_RSHIFT(width, 1);
  2230. for (y=0; y<height; y++) {
  2231. RENAME(extract_odd)(src, ydst, width);
  2232. if(y&1) {
  2233. RENAME(extract_even2avg)(src-srcStride, src, udst, vdst, chromWidth);
  2234. udst+= chromStride;
  2235. vdst+= chromStride;
  2236. }
  2237. src += srcStride;
  2238. ydst+= lumStride;
  2239. }
  2240. __asm__(
  2241. EMMS" \n\t"
  2242. SFENCE" \n\t"
  2243. ::: "memory"
  2244. );
  2245. }
  2246. #if ARCH_X86_32
  2247. static void RENAME(uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
  2248. int width, int height,
  2249. int lumStride, int chromStride, int srcStride)
  2250. {
  2251. int y;
  2252. const int chromWidth = AV_CEIL_RSHIFT(width, 1);
  2253. for (y=0; y<height; y++) {
  2254. RENAME(extract_odd)(src, ydst, width);
  2255. RENAME(extract_even2)(src, udst, vdst, chromWidth);
  2256. src += srcStride;
  2257. ydst+= lumStride;
  2258. udst+= chromStride;
  2259. vdst+= chromStride;
  2260. }
  2261. __asm__(
  2262. EMMS" \n\t"
  2263. SFENCE" \n\t"
  2264. ::: "memory"
  2265. );
  2266. }
  2267. #endif /* ARCH_X86_32 */
  2268. #endif /* !COMPILE_TEMPLATE_SSE2 */
  2269. static av_cold void RENAME(rgb2rgb_init)(void)
  2270. {
  2271. #if !COMPILE_TEMPLATE_SSE2
  2272. rgb15to16 = RENAME(rgb15to16);
  2273. rgb15tobgr24 = RENAME(rgb15tobgr24);
  2274. rgb15to32 = RENAME(rgb15to32);
  2275. rgb16tobgr24 = RENAME(rgb16tobgr24);
  2276. rgb16to32 = RENAME(rgb16to32);
  2277. rgb16to15 = RENAME(rgb16to15);
  2278. rgb24tobgr16 = RENAME(rgb24tobgr16);
  2279. rgb24tobgr15 = RENAME(rgb24tobgr15);
  2280. rgb24tobgr32 = RENAME(rgb24tobgr32);
  2281. rgb32to16 = RENAME(rgb32to16);
  2282. rgb32to15 = RENAME(rgb32to15);
  2283. rgb32tobgr24 = RENAME(rgb32tobgr24);
  2284. rgb24to15 = RENAME(rgb24to15);
  2285. rgb24to16 = RENAME(rgb24to16);
  2286. rgb24tobgr24 = RENAME(rgb24tobgr24);
  2287. rgb32tobgr16 = RENAME(rgb32tobgr16);
  2288. rgb32tobgr15 = RENAME(rgb32tobgr15);
  2289. yv12toyuy2 = RENAME(yv12toyuy2);
  2290. yv12touyvy = RENAME(yv12touyvy);
  2291. yuv422ptoyuy2 = RENAME(yuv422ptoyuy2);
  2292. yuv422ptouyvy = RENAME(yuv422ptouyvy);
  2293. yuy2toyv12 = RENAME(yuy2toyv12);
  2294. vu9_to_vu12 = RENAME(vu9_to_vu12);
  2295. yvu9_to_yuy2 = RENAME(yvu9_to_yuy2);
  2296. #if ARCH_X86_32
  2297. uyvytoyuv422 = RENAME(uyvytoyuv422);
  2298. #endif
  2299. yuyvtoyuv422 = RENAME(yuyvtoyuv422);
  2300. planar2x = RENAME(planar2x);
  2301. #if HAVE_7REGS
  2302. ff_rgb24toyv12 = RENAME(rgb24toyv12);
  2303. #endif /* HAVE_7REGS */
  2304. yuyvtoyuv420 = RENAME(yuyvtoyuv420);
  2305. uyvytoyuv420 = RENAME(uyvytoyuv420);
  2306. #endif /* !COMPILE_TEMPLATE_SSE2 */
  2307. #if !COMPILE_TEMPLATE_AVX && COMPILE_TEMPLATE_SSE2
  2308. interleaveBytes = RENAME(interleaveBytes);
  2309. #endif /* !COMPILE_TEMPLATE_AVX && COMPILE_TEMPLATE_SSE2 */
  2310. #if !COMPILE_TEMPLATE_AVX || HAVE_AVX_EXTERNAL
  2311. #if COMPILE_TEMPLATE_SSE2 && HAVE_X86ASM
  2312. deinterleaveBytes = RENAME(deinterleaveBytes);
  2313. #endif
  2314. #endif
  2315. }