You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3076 lines
110KB

  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 modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (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
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * 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. * The C code (not assembly, MMX, ...) of this file can be used
  27. * under the LGPL license.
  28. */
  29. #include <stddef.h>
  30. #undef PREFETCH
  31. #undef MOVNTQ
  32. #undef EMMS
  33. #undef SFENCE
  34. #undef MMREG_SIZE
  35. #undef PREFETCHW
  36. #undef PAVGB
  37. #if HAVE_SSE2
  38. #define MMREG_SIZE 16
  39. #else
  40. #define MMREG_SIZE 8
  41. #endif
  42. #if HAVE_AMD3DNOW
  43. #define PREFETCH "prefetch"
  44. #define PREFETCHW "prefetchw"
  45. #define PAVGB "pavgusb"
  46. #elif HAVE_MMX2
  47. #define PREFETCH "prefetchnta"
  48. #define PREFETCHW "prefetcht0"
  49. #define PAVGB "pavgb"
  50. #else
  51. #define PREFETCH " # nop"
  52. #define PREFETCHW " # nop"
  53. #endif
  54. #if HAVE_AMD3DNOW
  55. /* On K6 femms is faster than emms. On K7 femms is directly mapped to emms. */
  56. #define EMMS "femms"
  57. #else
  58. #define EMMS "emms"
  59. #endif
  60. #if HAVE_MMX2
  61. #define MOVNTQ "movntq"
  62. #define SFENCE "sfence"
  63. #else
  64. #define MOVNTQ "movq"
  65. #define SFENCE " # nop"
  66. #endif
  67. static inline void RENAME(rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size)
  68. {
  69. uint8_t *dest = dst;
  70. const uint8_t *s = src;
  71. const uint8_t *end;
  72. #if HAVE_MMX
  73. const uint8_t *mm_end;
  74. #endif
  75. end = s + src_size;
  76. #if HAVE_MMX
  77. __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory");
  78. mm_end = end - 23;
  79. __asm__ volatile("movq %0, %%mm7"::"m"(mask32a):"memory");
  80. while (s < mm_end)
  81. {
  82. __asm__ volatile(
  83. PREFETCH" 32%1 \n\t"
  84. "movd %1, %%mm0 \n\t"
  85. "punpckldq 3%1, %%mm0 \n\t"
  86. "movd 6%1, %%mm1 \n\t"
  87. "punpckldq 9%1, %%mm1 \n\t"
  88. "movd 12%1, %%mm2 \n\t"
  89. "punpckldq 15%1, %%mm2 \n\t"
  90. "movd 18%1, %%mm3 \n\t"
  91. "punpckldq 21%1, %%mm3 \n\t"
  92. "por %%mm7, %%mm0 \n\t"
  93. "por %%mm7, %%mm1 \n\t"
  94. "por %%mm7, %%mm2 \n\t"
  95. "por %%mm7, %%mm3 \n\t"
  96. MOVNTQ" %%mm0, %0 \n\t"
  97. MOVNTQ" %%mm1, 8%0 \n\t"
  98. MOVNTQ" %%mm2, 16%0 \n\t"
  99. MOVNTQ" %%mm3, 24%0"
  100. :"=m"(*dest)
  101. :"m"(*s)
  102. :"memory");
  103. dest += 32;
  104. s += 24;
  105. }
  106. __asm__ volatile(SFENCE:::"memory");
  107. __asm__ volatile(EMMS:::"memory");
  108. #endif
  109. while (s < end)
  110. {
  111. #ifdef WORDS_BIGENDIAN
  112. /* RGB24 (= R,G,B) -> RGB32 (= A,B,G,R) */
  113. *dest++ = 255;
  114. *dest++ = s[2];
  115. *dest++ = s[1];
  116. *dest++ = s[0];
  117. s+=3;
  118. #else
  119. *dest++ = *s++;
  120. *dest++ = *s++;
  121. *dest++ = *s++;
  122. *dest++ = 255;
  123. #endif
  124. }
  125. }
  126. static inline void RENAME(rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size)
  127. {
  128. uint8_t *dest = dst;
  129. const uint8_t *s = src;
  130. const uint8_t *end;
  131. #if HAVE_MMX
  132. const uint8_t *mm_end;
  133. #endif
  134. end = s + src_size;
  135. #if HAVE_MMX
  136. __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory");
  137. mm_end = end - 31;
  138. while (s < mm_end)
  139. {
  140. __asm__ volatile(
  141. PREFETCH" 32%1 \n\t"
  142. "movq %1, %%mm0 \n\t"
  143. "movq 8%1, %%mm1 \n\t"
  144. "movq 16%1, %%mm4 \n\t"
  145. "movq 24%1, %%mm5 \n\t"
  146. "movq %%mm0, %%mm2 \n\t"
  147. "movq %%mm1, %%mm3 \n\t"
  148. "movq %%mm4, %%mm6 \n\t"
  149. "movq %%mm5, %%mm7 \n\t"
  150. "psrlq $8, %%mm2 \n\t"
  151. "psrlq $8, %%mm3 \n\t"
  152. "psrlq $8, %%mm6 \n\t"
  153. "psrlq $8, %%mm7 \n\t"
  154. "pand %2, %%mm0 \n\t"
  155. "pand %2, %%mm1 \n\t"
  156. "pand %2, %%mm4 \n\t"
  157. "pand %2, %%mm5 \n\t"
  158. "pand %3, %%mm2 \n\t"
  159. "pand %3, %%mm3 \n\t"
  160. "pand %3, %%mm6 \n\t"
  161. "pand %3, %%mm7 \n\t"
  162. "por %%mm2, %%mm0 \n\t"
  163. "por %%mm3, %%mm1 \n\t"
  164. "por %%mm6, %%mm4 \n\t"
  165. "por %%mm7, %%mm5 \n\t"
  166. "movq %%mm1, %%mm2 \n\t"
  167. "movq %%mm4, %%mm3 \n\t"
  168. "psllq $48, %%mm2 \n\t"
  169. "psllq $32, %%mm3 \n\t"
  170. "pand %4, %%mm2 \n\t"
  171. "pand %5, %%mm3 \n\t"
  172. "por %%mm2, %%mm0 \n\t"
  173. "psrlq $16, %%mm1 \n\t"
  174. "psrlq $32, %%mm4 \n\t"
  175. "psllq $16, %%mm5 \n\t"
  176. "por %%mm3, %%mm1 \n\t"
  177. "pand %6, %%mm5 \n\t"
  178. "por %%mm5, %%mm4 \n\t"
  179. MOVNTQ" %%mm0, %0 \n\t"
  180. MOVNTQ" %%mm1, 8%0 \n\t"
  181. MOVNTQ" %%mm4, 16%0"
  182. :"=m"(*dest)
  183. :"m"(*s),"m"(mask24l),
  184. "m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh)
  185. :"memory");
  186. dest += 24;
  187. s += 32;
  188. }
  189. __asm__ volatile(SFENCE:::"memory");
  190. __asm__ volatile(EMMS:::"memory");
  191. #endif
  192. while (s < end)
  193. {
  194. #ifdef WORDS_BIGENDIAN
  195. /* RGB32 (= A,B,G,R) -> RGB24 (= R,G,B) */
  196. s++;
  197. dest[2] = *s++;
  198. dest[1] = *s++;
  199. dest[0] = *s++;
  200. dest += 3;
  201. #else
  202. *dest++ = *s++;
  203. *dest++ = *s++;
  204. *dest++ = *s++;
  205. s++;
  206. #endif
  207. }
  208. }
  209. /*
  210. original by Strepto/Astral
  211. ported to gcc & bugfixed: A'rpi
  212. MMX2, 3DNOW optimization by Nick Kurshev
  213. 32-bit C version, and and&add trick by Michael Niedermayer
  214. */
  215. static inline void RENAME(rgb15to16)(const uint8_t *src, uint8_t *dst, long src_size)
  216. {
  217. register const uint8_t* s=src;
  218. register uint8_t* d=dst;
  219. register const uint8_t *end;
  220. const uint8_t *mm_end;
  221. end = s + src_size;
  222. #if HAVE_MMX
  223. __asm__ volatile(PREFETCH" %0"::"m"(*s));
  224. __asm__ volatile("movq %0, %%mm4"::"m"(mask15s));
  225. mm_end = end - 15;
  226. while (s<mm_end)
  227. {
  228. __asm__ volatile(
  229. PREFETCH" 32%1 \n\t"
  230. "movq %1, %%mm0 \n\t"
  231. "movq 8%1, %%mm2 \n\t"
  232. "movq %%mm0, %%mm1 \n\t"
  233. "movq %%mm2, %%mm3 \n\t"
  234. "pand %%mm4, %%mm0 \n\t"
  235. "pand %%mm4, %%mm2 \n\t"
  236. "paddw %%mm1, %%mm0 \n\t"
  237. "paddw %%mm3, %%mm2 \n\t"
  238. MOVNTQ" %%mm0, %0 \n\t"
  239. MOVNTQ" %%mm2, 8%0"
  240. :"=m"(*d)
  241. :"m"(*s)
  242. );
  243. d+=16;
  244. s+=16;
  245. }
  246. __asm__ volatile(SFENCE:::"memory");
  247. __asm__ volatile(EMMS:::"memory");
  248. #endif
  249. mm_end = end - 3;
  250. while (s < mm_end)
  251. {
  252. register unsigned x= *((const uint32_t *)s);
  253. *((uint32_t *)d) = (x&0x7FFF7FFF) + (x&0x7FE07FE0);
  254. d+=4;
  255. s+=4;
  256. }
  257. if (s < end)
  258. {
  259. register unsigned short x= *((const uint16_t *)s);
  260. *((uint16_t *)d) = (x&0x7FFF) + (x&0x7FE0);
  261. }
  262. }
  263. static inline void RENAME(rgb16to15)(const uint8_t *src, uint8_t *dst, long src_size)
  264. {
  265. register const uint8_t* s=src;
  266. register uint8_t* d=dst;
  267. register const uint8_t *end;
  268. const uint8_t *mm_end;
  269. end = s + src_size;
  270. #if HAVE_MMX
  271. __asm__ volatile(PREFETCH" %0"::"m"(*s));
  272. __asm__ volatile("movq %0, %%mm7"::"m"(mask15rg));
  273. __asm__ volatile("movq %0, %%mm6"::"m"(mask15b));
  274. mm_end = end - 15;
  275. while (s<mm_end)
  276. {
  277. __asm__ volatile(
  278. PREFETCH" 32%1 \n\t"
  279. "movq %1, %%mm0 \n\t"
  280. "movq 8%1, %%mm2 \n\t"
  281. "movq %%mm0, %%mm1 \n\t"
  282. "movq %%mm2, %%mm3 \n\t"
  283. "psrlq $1, %%mm0 \n\t"
  284. "psrlq $1, %%mm2 \n\t"
  285. "pand %%mm7, %%mm0 \n\t"
  286. "pand %%mm7, %%mm2 \n\t"
  287. "pand %%mm6, %%mm1 \n\t"
  288. "pand %%mm6, %%mm3 \n\t"
  289. "por %%mm1, %%mm0 \n\t"
  290. "por %%mm3, %%mm2 \n\t"
  291. MOVNTQ" %%mm0, %0 \n\t"
  292. MOVNTQ" %%mm2, 8%0"
  293. :"=m"(*d)
  294. :"m"(*s)
  295. );
  296. d+=16;
  297. s+=16;
  298. }
  299. __asm__ volatile(SFENCE:::"memory");
  300. __asm__ volatile(EMMS:::"memory");
  301. #endif
  302. mm_end = end - 3;
  303. while (s < mm_end)
  304. {
  305. register uint32_t x= *((const uint32_t*)s);
  306. *((uint32_t *)d) = ((x>>1)&0x7FE07FE0) | (x&0x001F001F);
  307. s+=4;
  308. d+=4;
  309. }
  310. if (s < end)
  311. {
  312. register uint16_t x= *((const uint16_t*)s);
  313. *((uint16_t *)d) = ((x>>1)&0x7FE0) | (x&0x001F);
  314. }
  315. }
  316. static inline void RENAME(rgb32to16)(const uint8_t *src, uint8_t *dst, long src_size)
  317. {
  318. const uint8_t *s = src;
  319. const uint8_t *end;
  320. #if HAVE_MMX
  321. const uint8_t *mm_end;
  322. #endif
  323. uint16_t *d = (uint16_t *)dst;
  324. end = s + src_size;
  325. #if HAVE_MMX
  326. mm_end = end - 15;
  327. #if 1 //is faster only if multiplies are reasonably fast (FIXME figure out on which CPUs this is faster, on Athlon it is slightly faster)
  328. __asm__ volatile(
  329. "movq %3, %%mm5 \n\t"
  330. "movq %4, %%mm6 \n\t"
  331. "movq %5, %%mm7 \n\t"
  332. "jmp 2f \n\t"
  333. ASMALIGN(4)
  334. "1: \n\t"
  335. PREFETCH" 32(%1) \n\t"
  336. "movd (%1), %%mm0 \n\t"
  337. "movd 4(%1), %%mm3 \n\t"
  338. "punpckldq 8(%1), %%mm0 \n\t"
  339. "punpckldq 12(%1), %%mm3 \n\t"
  340. "movq %%mm0, %%mm1 \n\t"
  341. "movq %%mm3, %%mm4 \n\t"
  342. "pand %%mm6, %%mm0 \n\t"
  343. "pand %%mm6, %%mm3 \n\t"
  344. "pmaddwd %%mm7, %%mm0 \n\t"
  345. "pmaddwd %%mm7, %%mm3 \n\t"
  346. "pand %%mm5, %%mm1 \n\t"
  347. "pand %%mm5, %%mm4 \n\t"
  348. "por %%mm1, %%mm0 \n\t"
  349. "por %%mm4, %%mm3 \n\t"
  350. "psrld $5, %%mm0 \n\t"
  351. "pslld $11, %%mm3 \n\t"
  352. "por %%mm3, %%mm0 \n\t"
  353. MOVNTQ" %%mm0, (%0) \n\t"
  354. "add $16, %1 \n\t"
  355. "add $8, %0 \n\t"
  356. "2: \n\t"
  357. "cmp %2, %1 \n\t"
  358. " jb 1b \n\t"
  359. : "+r" (d), "+r"(s)
  360. : "r" (mm_end), "m" (mask3216g), "m" (mask3216br), "m" (mul3216)
  361. );
  362. #else
  363. __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory");
  364. __asm__ volatile(
  365. "movq %0, %%mm7 \n\t"
  366. "movq %1, %%mm6 \n\t"
  367. ::"m"(red_16mask),"m"(green_16mask));
  368. while (s < mm_end)
  369. {
  370. __asm__ volatile(
  371. PREFETCH" 32%1 \n\t"
  372. "movd %1, %%mm0 \n\t"
  373. "movd 4%1, %%mm3 \n\t"
  374. "punpckldq 8%1, %%mm0 \n\t"
  375. "punpckldq 12%1, %%mm3 \n\t"
  376. "movq %%mm0, %%mm1 \n\t"
  377. "movq %%mm0, %%mm2 \n\t"
  378. "movq %%mm3, %%mm4 \n\t"
  379. "movq %%mm3, %%mm5 \n\t"
  380. "psrlq $3, %%mm0 \n\t"
  381. "psrlq $3, %%mm3 \n\t"
  382. "pand %2, %%mm0 \n\t"
  383. "pand %2, %%mm3 \n\t"
  384. "psrlq $5, %%mm1 \n\t"
  385. "psrlq $5, %%mm4 \n\t"
  386. "pand %%mm6, %%mm1 \n\t"
  387. "pand %%mm6, %%mm4 \n\t"
  388. "psrlq $8, %%mm2 \n\t"
  389. "psrlq $8, %%mm5 \n\t"
  390. "pand %%mm7, %%mm2 \n\t"
  391. "pand %%mm7, %%mm5 \n\t"
  392. "por %%mm1, %%mm0 \n\t"
  393. "por %%mm4, %%mm3 \n\t"
  394. "por %%mm2, %%mm0 \n\t"
  395. "por %%mm5, %%mm3 \n\t"
  396. "psllq $16, %%mm3 \n\t"
  397. "por %%mm3, %%mm0 \n\t"
  398. MOVNTQ" %%mm0, %0 \n\t"
  399. :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory");
  400. d += 4;
  401. s += 16;
  402. }
  403. #endif
  404. __asm__ volatile(SFENCE:::"memory");
  405. __asm__ volatile(EMMS:::"memory");
  406. #endif
  407. while (s < end)
  408. {
  409. register int rgb = *(const uint32_t*)s; s += 4;
  410. *d++ = ((rgb&0xFF)>>3) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>8);
  411. }
  412. }
  413. static inline void RENAME(rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size)
  414. {
  415. const uint8_t *s = src;
  416. const uint8_t *end;
  417. #if HAVE_MMX
  418. const uint8_t *mm_end;
  419. #endif
  420. uint16_t *d = (uint16_t *)dst;
  421. end = s + src_size;
  422. #if HAVE_MMX
  423. __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory");
  424. __asm__ volatile(
  425. "movq %0, %%mm7 \n\t"
  426. "movq %1, %%mm6 \n\t"
  427. ::"m"(red_16mask),"m"(green_16mask));
  428. mm_end = end - 15;
  429. while (s < mm_end)
  430. {
  431. __asm__ volatile(
  432. PREFETCH" 32%1 \n\t"
  433. "movd %1, %%mm0 \n\t"
  434. "movd 4%1, %%mm3 \n\t"
  435. "punpckldq 8%1, %%mm0 \n\t"
  436. "punpckldq 12%1, %%mm3 \n\t"
  437. "movq %%mm0, %%mm1 \n\t"
  438. "movq %%mm0, %%mm2 \n\t"
  439. "movq %%mm3, %%mm4 \n\t"
  440. "movq %%mm3, %%mm5 \n\t"
  441. "psllq $8, %%mm0 \n\t"
  442. "psllq $8, %%mm3 \n\t"
  443. "pand %%mm7, %%mm0 \n\t"
  444. "pand %%mm7, %%mm3 \n\t"
  445. "psrlq $5, %%mm1 \n\t"
  446. "psrlq $5, %%mm4 \n\t"
  447. "pand %%mm6, %%mm1 \n\t"
  448. "pand %%mm6, %%mm4 \n\t"
  449. "psrlq $19, %%mm2 \n\t"
  450. "psrlq $19, %%mm5 \n\t"
  451. "pand %2, %%mm2 \n\t"
  452. "pand %2, %%mm5 \n\t"
  453. "por %%mm1, %%mm0 \n\t"
  454. "por %%mm4, %%mm3 \n\t"
  455. "por %%mm2, %%mm0 \n\t"
  456. "por %%mm5, %%mm3 \n\t"
  457. "psllq $16, %%mm3 \n\t"
  458. "por %%mm3, %%mm0 \n\t"
  459. MOVNTQ" %%mm0, %0 \n\t"
  460. :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory");
  461. d += 4;
  462. s += 16;
  463. }
  464. __asm__ volatile(SFENCE:::"memory");
  465. __asm__ volatile(EMMS:::"memory");
  466. #endif
  467. while (s < end)
  468. {
  469. register int rgb = *(const uint32_t*)s; s += 4;
  470. *d++ = ((rgb&0xF8)<<8) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>19);
  471. }
  472. }
  473. static inline void RENAME(rgb32to15)(const uint8_t *src, uint8_t *dst, long src_size)
  474. {
  475. const uint8_t *s = src;
  476. const uint8_t *end;
  477. #if HAVE_MMX
  478. const uint8_t *mm_end;
  479. #endif
  480. uint16_t *d = (uint16_t *)dst;
  481. end = s + src_size;
  482. #if HAVE_MMX
  483. mm_end = end - 15;
  484. #if 1 //is faster only if multiplies are reasonably fast (FIXME figure out on which CPUs this is faster, on Athlon it is slightly faster)
  485. __asm__ volatile(
  486. "movq %3, %%mm5 \n\t"
  487. "movq %4, %%mm6 \n\t"
  488. "movq %5, %%mm7 \n\t"
  489. "jmp 2f \n\t"
  490. ASMALIGN(4)
  491. "1: \n\t"
  492. PREFETCH" 32(%1) \n\t"
  493. "movd (%1), %%mm0 \n\t"
  494. "movd 4(%1), %%mm3 \n\t"
  495. "punpckldq 8(%1), %%mm0 \n\t"
  496. "punpckldq 12(%1), %%mm3 \n\t"
  497. "movq %%mm0, %%mm1 \n\t"
  498. "movq %%mm3, %%mm4 \n\t"
  499. "pand %%mm6, %%mm0 \n\t"
  500. "pand %%mm6, %%mm3 \n\t"
  501. "pmaddwd %%mm7, %%mm0 \n\t"
  502. "pmaddwd %%mm7, %%mm3 \n\t"
  503. "pand %%mm5, %%mm1 \n\t"
  504. "pand %%mm5, %%mm4 \n\t"
  505. "por %%mm1, %%mm0 \n\t"
  506. "por %%mm4, %%mm3 \n\t"
  507. "psrld $6, %%mm0 \n\t"
  508. "pslld $10, %%mm3 \n\t"
  509. "por %%mm3, %%mm0 \n\t"
  510. MOVNTQ" %%mm0, (%0) \n\t"
  511. "add $16, %1 \n\t"
  512. "add $8, %0 \n\t"
  513. "2: \n\t"
  514. "cmp %2, %1 \n\t"
  515. " jb 1b \n\t"
  516. : "+r" (d), "+r"(s)
  517. : "r" (mm_end), "m" (mask3215g), "m" (mask3216br), "m" (mul3215)
  518. );
  519. #else
  520. __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory");
  521. __asm__ volatile(
  522. "movq %0, %%mm7 \n\t"
  523. "movq %1, %%mm6 \n\t"
  524. ::"m"(red_15mask),"m"(green_15mask));
  525. while (s < mm_end)
  526. {
  527. __asm__ volatile(
  528. PREFETCH" 32%1 \n\t"
  529. "movd %1, %%mm0 \n\t"
  530. "movd 4%1, %%mm3 \n\t"
  531. "punpckldq 8%1, %%mm0 \n\t"
  532. "punpckldq 12%1, %%mm3 \n\t"
  533. "movq %%mm0, %%mm1 \n\t"
  534. "movq %%mm0, %%mm2 \n\t"
  535. "movq %%mm3, %%mm4 \n\t"
  536. "movq %%mm3, %%mm5 \n\t"
  537. "psrlq $3, %%mm0 \n\t"
  538. "psrlq $3, %%mm3 \n\t"
  539. "pand %2, %%mm0 \n\t"
  540. "pand %2, %%mm3 \n\t"
  541. "psrlq $6, %%mm1 \n\t"
  542. "psrlq $6, %%mm4 \n\t"
  543. "pand %%mm6, %%mm1 \n\t"
  544. "pand %%mm6, %%mm4 \n\t"
  545. "psrlq $9, %%mm2 \n\t"
  546. "psrlq $9, %%mm5 \n\t"
  547. "pand %%mm7, %%mm2 \n\t"
  548. "pand %%mm7, %%mm5 \n\t"
  549. "por %%mm1, %%mm0 \n\t"
  550. "por %%mm4, %%mm3 \n\t"
  551. "por %%mm2, %%mm0 \n\t"
  552. "por %%mm5, %%mm3 \n\t"
  553. "psllq $16, %%mm3 \n\t"
  554. "por %%mm3, %%mm0 \n\t"
  555. MOVNTQ" %%mm0, %0 \n\t"
  556. :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory");
  557. d += 4;
  558. s += 16;
  559. }
  560. #endif
  561. __asm__ volatile(SFENCE:::"memory");
  562. __asm__ volatile(EMMS:::"memory");
  563. #endif
  564. while (s < end)
  565. {
  566. register int rgb = *(const uint32_t*)s; s += 4;
  567. *d++ = ((rgb&0xFF)>>3) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>9);
  568. }
  569. }
  570. static inline void RENAME(rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size)
  571. {
  572. const uint8_t *s = src;
  573. const uint8_t *end;
  574. #if HAVE_MMX
  575. const uint8_t *mm_end;
  576. #endif
  577. uint16_t *d = (uint16_t *)dst;
  578. end = s + src_size;
  579. #if HAVE_MMX
  580. __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory");
  581. __asm__ volatile(
  582. "movq %0, %%mm7 \n\t"
  583. "movq %1, %%mm6 \n\t"
  584. ::"m"(red_15mask),"m"(green_15mask));
  585. mm_end = end - 15;
  586. while (s < mm_end)
  587. {
  588. __asm__ volatile(
  589. PREFETCH" 32%1 \n\t"
  590. "movd %1, %%mm0 \n\t"
  591. "movd 4%1, %%mm3 \n\t"
  592. "punpckldq 8%1, %%mm0 \n\t"
  593. "punpckldq 12%1, %%mm3 \n\t"
  594. "movq %%mm0, %%mm1 \n\t"
  595. "movq %%mm0, %%mm2 \n\t"
  596. "movq %%mm3, %%mm4 \n\t"
  597. "movq %%mm3, %%mm5 \n\t"
  598. "psllq $7, %%mm0 \n\t"
  599. "psllq $7, %%mm3 \n\t"
  600. "pand %%mm7, %%mm0 \n\t"
  601. "pand %%mm7, %%mm3 \n\t"
  602. "psrlq $6, %%mm1 \n\t"
  603. "psrlq $6, %%mm4 \n\t"
  604. "pand %%mm6, %%mm1 \n\t"
  605. "pand %%mm6, %%mm4 \n\t"
  606. "psrlq $19, %%mm2 \n\t"
  607. "psrlq $19, %%mm5 \n\t"
  608. "pand %2, %%mm2 \n\t"
  609. "pand %2, %%mm5 \n\t"
  610. "por %%mm1, %%mm0 \n\t"
  611. "por %%mm4, %%mm3 \n\t"
  612. "por %%mm2, %%mm0 \n\t"
  613. "por %%mm5, %%mm3 \n\t"
  614. "psllq $16, %%mm3 \n\t"
  615. "por %%mm3, %%mm0 \n\t"
  616. MOVNTQ" %%mm0, %0 \n\t"
  617. :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory");
  618. d += 4;
  619. s += 16;
  620. }
  621. __asm__ volatile(SFENCE:::"memory");
  622. __asm__ volatile(EMMS:::"memory");
  623. #endif
  624. while (s < end)
  625. {
  626. register int rgb = *(const uint32_t*)s; s += 4;
  627. *d++ = ((rgb&0xF8)<<7) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>19);
  628. }
  629. }
  630. static inline void RENAME(rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size)
  631. {
  632. const uint8_t *s = src;
  633. const uint8_t *end;
  634. #if HAVE_MMX
  635. const uint8_t *mm_end;
  636. #endif
  637. uint16_t *d = (uint16_t *)dst;
  638. end = s + src_size;
  639. #if HAVE_MMX
  640. __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory");
  641. __asm__ volatile(
  642. "movq %0, %%mm7 \n\t"
  643. "movq %1, %%mm6 \n\t"
  644. ::"m"(red_16mask),"m"(green_16mask));
  645. mm_end = end - 11;
  646. while (s < mm_end)
  647. {
  648. __asm__ volatile(
  649. PREFETCH" 32%1 \n\t"
  650. "movd %1, %%mm0 \n\t"
  651. "movd 3%1, %%mm3 \n\t"
  652. "punpckldq 6%1, %%mm0 \n\t"
  653. "punpckldq 9%1, %%mm3 \n\t"
  654. "movq %%mm0, %%mm1 \n\t"
  655. "movq %%mm0, %%mm2 \n\t"
  656. "movq %%mm3, %%mm4 \n\t"
  657. "movq %%mm3, %%mm5 \n\t"
  658. "psrlq $3, %%mm0 \n\t"
  659. "psrlq $3, %%mm3 \n\t"
  660. "pand %2, %%mm0 \n\t"
  661. "pand %2, %%mm3 \n\t"
  662. "psrlq $5, %%mm1 \n\t"
  663. "psrlq $5, %%mm4 \n\t"
  664. "pand %%mm6, %%mm1 \n\t"
  665. "pand %%mm6, %%mm4 \n\t"
  666. "psrlq $8, %%mm2 \n\t"
  667. "psrlq $8, %%mm5 \n\t"
  668. "pand %%mm7, %%mm2 \n\t"
  669. "pand %%mm7, %%mm5 \n\t"
  670. "por %%mm1, %%mm0 \n\t"
  671. "por %%mm4, %%mm3 \n\t"
  672. "por %%mm2, %%mm0 \n\t"
  673. "por %%mm5, %%mm3 \n\t"
  674. "psllq $16, %%mm3 \n\t"
  675. "por %%mm3, %%mm0 \n\t"
  676. MOVNTQ" %%mm0, %0 \n\t"
  677. :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory");
  678. d += 4;
  679. s += 12;
  680. }
  681. __asm__ volatile(SFENCE:::"memory");
  682. __asm__ volatile(EMMS:::"memory");
  683. #endif
  684. while (s < end)
  685. {
  686. const int b = *s++;
  687. const int g = *s++;
  688. const int r = *s++;
  689. *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8);
  690. }
  691. }
  692. static inline void RENAME(rgb24to16)(const uint8_t *src, uint8_t *dst, long src_size)
  693. {
  694. const uint8_t *s = src;
  695. const uint8_t *end;
  696. #if HAVE_MMX
  697. const uint8_t *mm_end;
  698. #endif
  699. uint16_t *d = (uint16_t *)dst;
  700. end = s + src_size;
  701. #if HAVE_MMX
  702. __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory");
  703. __asm__ volatile(
  704. "movq %0, %%mm7 \n\t"
  705. "movq %1, %%mm6 \n\t"
  706. ::"m"(red_16mask),"m"(green_16mask));
  707. mm_end = end - 15;
  708. while (s < mm_end)
  709. {
  710. __asm__ volatile(
  711. PREFETCH" 32%1 \n\t"
  712. "movd %1, %%mm0 \n\t"
  713. "movd 3%1, %%mm3 \n\t"
  714. "punpckldq 6%1, %%mm0 \n\t"
  715. "punpckldq 9%1, %%mm3 \n\t"
  716. "movq %%mm0, %%mm1 \n\t"
  717. "movq %%mm0, %%mm2 \n\t"
  718. "movq %%mm3, %%mm4 \n\t"
  719. "movq %%mm3, %%mm5 \n\t"
  720. "psllq $8, %%mm0 \n\t"
  721. "psllq $8, %%mm3 \n\t"
  722. "pand %%mm7, %%mm0 \n\t"
  723. "pand %%mm7, %%mm3 \n\t"
  724. "psrlq $5, %%mm1 \n\t"
  725. "psrlq $5, %%mm4 \n\t"
  726. "pand %%mm6, %%mm1 \n\t"
  727. "pand %%mm6, %%mm4 \n\t"
  728. "psrlq $19, %%mm2 \n\t"
  729. "psrlq $19, %%mm5 \n\t"
  730. "pand %2, %%mm2 \n\t"
  731. "pand %2, %%mm5 \n\t"
  732. "por %%mm1, %%mm0 \n\t"
  733. "por %%mm4, %%mm3 \n\t"
  734. "por %%mm2, %%mm0 \n\t"
  735. "por %%mm5, %%mm3 \n\t"
  736. "psllq $16, %%mm3 \n\t"
  737. "por %%mm3, %%mm0 \n\t"
  738. MOVNTQ" %%mm0, %0 \n\t"
  739. :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory");
  740. d += 4;
  741. s += 12;
  742. }
  743. __asm__ volatile(SFENCE:::"memory");
  744. __asm__ volatile(EMMS:::"memory");
  745. #endif
  746. while (s < end)
  747. {
  748. const int r = *s++;
  749. const int g = *s++;
  750. const int b = *s++;
  751. *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8);
  752. }
  753. }
  754. static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size)
  755. {
  756. const uint8_t *s = src;
  757. const uint8_t *end;
  758. #if HAVE_MMX
  759. const uint8_t *mm_end;
  760. #endif
  761. uint16_t *d = (uint16_t *)dst;
  762. end = s + src_size;
  763. #if HAVE_MMX
  764. __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory");
  765. __asm__ volatile(
  766. "movq %0, %%mm7 \n\t"
  767. "movq %1, %%mm6 \n\t"
  768. ::"m"(red_15mask),"m"(green_15mask));
  769. mm_end = end - 11;
  770. while (s < mm_end)
  771. {
  772. __asm__ volatile(
  773. PREFETCH" 32%1 \n\t"
  774. "movd %1, %%mm0 \n\t"
  775. "movd 3%1, %%mm3 \n\t"
  776. "punpckldq 6%1, %%mm0 \n\t"
  777. "punpckldq 9%1, %%mm3 \n\t"
  778. "movq %%mm0, %%mm1 \n\t"
  779. "movq %%mm0, %%mm2 \n\t"
  780. "movq %%mm3, %%mm4 \n\t"
  781. "movq %%mm3, %%mm5 \n\t"
  782. "psrlq $3, %%mm0 \n\t"
  783. "psrlq $3, %%mm3 \n\t"
  784. "pand %2, %%mm0 \n\t"
  785. "pand %2, %%mm3 \n\t"
  786. "psrlq $6, %%mm1 \n\t"
  787. "psrlq $6, %%mm4 \n\t"
  788. "pand %%mm6, %%mm1 \n\t"
  789. "pand %%mm6, %%mm4 \n\t"
  790. "psrlq $9, %%mm2 \n\t"
  791. "psrlq $9, %%mm5 \n\t"
  792. "pand %%mm7, %%mm2 \n\t"
  793. "pand %%mm7, %%mm5 \n\t"
  794. "por %%mm1, %%mm0 \n\t"
  795. "por %%mm4, %%mm3 \n\t"
  796. "por %%mm2, %%mm0 \n\t"
  797. "por %%mm5, %%mm3 \n\t"
  798. "psllq $16, %%mm3 \n\t"
  799. "por %%mm3, %%mm0 \n\t"
  800. MOVNTQ" %%mm0, %0 \n\t"
  801. :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory");
  802. d += 4;
  803. s += 12;
  804. }
  805. __asm__ volatile(SFENCE:::"memory");
  806. __asm__ volatile(EMMS:::"memory");
  807. #endif
  808. while (s < end)
  809. {
  810. const int b = *s++;
  811. const int g = *s++;
  812. const int r = *s++;
  813. *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7);
  814. }
  815. }
  816. static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, long src_size)
  817. {
  818. const uint8_t *s = src;
  819. const uint8_t *end;
  820. #if HAVE_MMX
  821. const uint8_t *mm_end;
  822. #endif
  823. uint16_t *d = (uint16_t *)dst;
  824. end = s + src_size;
  825. #if HAVE_MMX
  826. __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory");
  827. __asm__ volatile(
  828. "movq %0, %%mm7 \n\t"
  829. "movq %1, %%mm6 \n\t"
  830. ::"m"(red_15mask),"m"(green_15mask));
  831. mm_end = end - 15;
  832. while (s < mm_end)
  833. {
  834. __asm__ volatile(
  835. PREFETCH" 32%1 \n\t"
  836. "movd %1, %%mm0 \n\t"
  837. "movd 3%1, %%mm3 \n\t"
  838. "punpckldq 6%1, %%mm0 \n\t"
  839. "punpckldq 9%1, %%mm3 \n\t"
  840. "movq %%mm0, %%mm1 \n\t"
  841. "movq %%mm0, %%mm2 \n\t"
  842. "movq %%mm3, %%mm4 \n\t"
  843. "movq %%mm3, %%mm5 \n\t"
  844. "psllq $7, %%mm0 \n\t"
  845. "psllq $7, %%mm3 \n\t"
  846. "pand %%mm7, %%mm0 \n\t"
  847. "pand %%mm7, %%mm3 \n\t"
  848. "psrlq $6, %%mm1 \n\t"
  849. "psrlq $6, %%mm4 \n\t"
  850. "pand %%mm6, %%mm1 \n\t"
  851. "pand %%mm6, %%mm4 \n\t"
  852. "psrlq $19, %%mm2 \n\t"
  853. "psrlq $19, %%mm5 \n\t"
  854. "pand %2, %%mm2 \n\t"
  855. "pand %2, %%mm5 \n\t"
  856. "por %%mm1, %%mm0 \n\t"
  857. "por %%mm4, %%mm3 \n\t"
  858. "por %%mm2, %%mm0 \n\t"
  859. "por %%mm5, %%mm3 \n\t"
  860. "psllq $16, %%mm3 \n\t"
  861. "por %%mm3, %%mm0 \n\t"
  862. MOVNTQ" %%mm0, %0 \n\t"
  863. :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory");
  864. d += 4;
  865. s += 12;
  866. }
  867. __asm__ volatile(SFENCE:::"memory");
  868. __asm__ volatile(EMMS:::"memory");
  869. #endif
  870. while (s < end)
  871. {
  872. const int r = *s++;
  873. const int g = *s++;
  874. const int b = *s++;
  875. *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7);
  876. }
  877. }
  878. /*
  879. I use less accurate approximation here by simply left-shifting the input
  880. value and filling the low order bits with zeroes. This method improves PNG
  881. compression but this scheme cannot reproduce white exactly, since it does
  882. not generate an all-ones maximum value; the net effect is to darken the
  883. image slightly.
  884. The better method should be "left bit replication":
  885. 4 3 2 1 0
  886. ---------
  887. 1 1 0 1 1
  888. 7 6 5 4 3 2 1 0
  889. ----------------
  890. 1 1 0 1 1 1 1 0
  891. |=======| |===|
  892. | leftmost bits repeated to fill open bits
  893. |
  894. original bits
  895. */
  896. static inline void RENAME(rgb15tobgr24)(const uint8_t *src, uint8_t *dst, long src_size)
  897. {
  898. const uint16_t *end;
  899. #if HAVE_MMX
  900. const uint16_t *mm_end;
  901. #endif
  902. uint8_t *d = dst;
  903. const uint16_t *s = (const uint16_t*)src;
  904. end = s + src_size/2;
  905. #if HAVE_MMX
  906. __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory");
  907. mm_end = end - 7;
  908. while (s < mm_end)
  909. {
  910. __asm__ volatile(
  911. PREFETCH" 32%1 \n\t"
  912. "movq %1, %%mm0 \n\t"
  913. "movq %1, %%mm1 \n\t"
  914. "movq %1, %%mm2 \n\t"
  915. "pand %2, %%mm0 \n\t"
  916. "pand %3, %%mm1 \n\t"
  917. "pand %4, %%mm2 \n\t"
  918. "psllq $3, %%mm0 \n\t"
  919. "psrlq $2, %%mm1 \n\t"
  920. "psrlq $7, %%mm2 \n\t"
  921. "movq %%mm0, %%mm3 \n\t"
  922. "movq %%mm1, %%mm4 \n\t"
  923. "movq %%mm2, %%mm5 \n\t"
  924. "punpcklwd %5, %%mm0 \n\t"
  925. "punpcklwd %5, %%mm1 \n\t"
  926. "punpcklwd %5, %%mm2 \n\t"
  927. "punpckhwd %5, %%mm3 \n\t"
  928. "punpckhwd %5, %%mm4 \n\t"
  929. "punpckhwd %5, %%mm5 \n\t"
  930. "psllq $8, %%mm1 \n\t"
  931. "psllq $16, %%mm2 \n\t"
  932. "por %%mm1, %%mm0 \n\t"
  933. "por %%mm2, %%mm0 \n\t"
  934. "psllq $8, %%mm4 \n\t"
  935. "psllq $16, %%mm5 \n\t"
  936. "por %%mm4, %%mm3 \n\t"
  937. "por %%mm5, %%mm3 \n\t"
  938. "movq %%mm0, %%mm6 \n\t"
  939. "movq %%mm3, %%mm7 \n\t"
  940. "movq 8%1, %%mm0 \n\t"
  941. "movq 8%1, %%mm1 \n\t"
  942. "movq 8%1, %%mm2 \n\t"
  943. "pand %2, %%mm0 \n\t"
  944. "pand %3, %%mm1 \n\t"
  945. "pand %4, %%mm2 \n\t"
  946. "psllq $3, %%mm0 \n\t"
  947. "psrlq $2, %%mm1 \n\t"
  948. "psrlq $7, %%mm2 \n\t"
  949. "movq %%mm0, %%mm3 \n\t"
  950. "movq %%mm1, %%mm4 \n\t"
  951. "movq %%mm2, %%mm5 \n\t"
  952. "punpcklwd %5, %%mm0 \n\t"
  953. "punpcklwd %5, %%mm1 \n\t"
  954. "punpcklwd %5, %%mm2 \n\t"
  955. "punpckhwd %5, %%mm3 \n\t"
  956. "punpckhwd %5, %%mm4 \n\t"
  957. "punpckhwd %5, %%mm5 \n\t"
  958. "psllq $8, %%mm1 \n\t"
  959. "psllq $16, %%mm2 \n\t"
  960. "por %%mm1, %%mm0 \n\t"
  961. "por %%mm2, %%mm0 \n\t"
  962. "psllq $8, %%mm4 \n\t"
  963. "psllq $16, %%mm5 \n\t"
  964. "por %%mm4, %%mm3 \n\t"
  965. "por %%mm5, %%mm3 \n\t"
  966. :"=m"(*d)
  967. :"m"(*s),"m"(mask15b),"m"(mask15g),"m"(mask15r), "m"(mmx_null)
  968. :"memory");
  969. /* borrowed 32 to 24 */
  970. __asm__ volatile(
  971. "movq %%mm0, %%mm4 \n\t"
  972. "movq %%mm3, %%mm5 \n\t"
  973. "movq %%mm6, %%mm0 \n\t"
  974. "movq %%mm7, %%mm1 \n\t"
  975. "movq %%mm4, %%mm6 \n\t"
  976. "movq %%mm5, %%mm7 \n\t"
  977. "movq %%mm0, %%mm2 \n\t"
  978. "movq %%mm1, %%mm3 \n\t"
  979. "psrlq $8, %%mm2 \n\t"
  980. "psrlq $8, %%mm3 \n\t"
  981. "psrlq $8, %%mm6 \n\t"
  982. "psrlq $8, %%mm7 \n\t"
  983. "pand %2, %%mm0 \n\t"
  984. "pand %2, %%mm1 \n\t"
  985. "pand %2, %%mm4 \n\t"
  986. "pand %2, %%mm5 \n\t"
  987. "pand %3, %%mm2 \n\t"
  988. "pand %3, %%mm3 \n\t"
  989. "pand %3, %%mm6 \n\t"
  990. "pand %3, %%mm7 \n\t"
  991. "por %%mm2, %%mm0 \n\t"
  992. "por %%mm3, %%mm1 \n\t"
  993. "por %%mm6, %%mm4 \n\t"
  994. "por %%mm7, %%mm5 \n\t"
  995. "movq %%mm1, %%mm2 \n\t"
  996. "movq %%mm4, %%mm3 \n\t"
  997. "psllq $48, %%mm2 \n\t"
  998. "psllq $32, %%mm3 \n\t"
  999. "pand %4, %%mm2 \n\t"
  1000. "pand %5, %%mm3 \n\t"
  1001. "por %%mm2, %%mm0 \n\t"
  1002. "psrlq $16, %%mm1 \n\t"
  1003. "psrlq $32, %%mm4 \n\t"
  1004. "psllq $16, %%mm5 \n\t"
  1005. "por %%mm3, %%mm1 \n\t"
  1006. "pand %6, %%mm5 \n\t"
  1007. "por %%mm5, %%mm4 \n\t"
  1008. MOVNTQ" %%mm0, %0 \n\t"
  1009. MOVNTQ" %%mm1, 8%0 \n\t"
  1010. MOVNTQ" %%mm4, 16%0"
  1011. :"=m"(*d)
  1012. :"m"(*s),"m"(mask24l),"m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh)
  1013. :"memory");
  1014. d += 24;
  1015. s += 8;
  1016. }
  1017. __asm__ volatile(SFENCE:::"memory");
  1018. __asm__ volatile(EMMS:::"memory");
  1019. #endif
  1020. while (s < end)
  1021. {
  1022. register uint16_t bgr;
  1023. bgr = *s++;
  1024. *d++ = (bgr&0x1F)<<3;
  1025. *d++ = (bgr&0x3E0)>>2;
  1026. *d++ = (bgr&0x7C00)>>7;
  1027. }
  1028. }
  1029. static inline void RENAME(rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long src_size)
  1030. {
  1031. const uint16_t *end;
  1032. #if HAVE_MMX
  1033. const uint16_t *mm_end;
  1034. #endif
  1035. uint8_t *d = (uint8_t *)dst;
  1036. const uint16_t *s = (const uint16_t *)src;
  1037. end = s + src_size/2;
  1038. #if HAVE_MMX
  1039. __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory");
  1040. mm_end = end - 7;
  1041. while (s < mm_end)
  1042. {
  1043. __asm__ volatile(
  1044. PREFETCH" 32%1 \n\t"
  1045. "movq %1, %%mm0 \n\t"
  1046. "movq %1, %%mm1 \n\t"
  1047. "movq %1, %%mm2 \n\t"
  1048. "pand %2, %%mm0 \n\t"
  1049. "pand %3, %%mm1 \n\t"
  1050. "pand %4, %%mm2 \n\t"
  1051. "psllq $3, %%mm0 \n\t"
  1052. "psrlq $3, %%mm1 \n\t"
  1053. "psrlq $8, %%mm2 \n\t"
  1054. "movq %%mm0, %%mm3 \n\t"
  1055. "movq %%mm1, %%mm4 \n\t"
  1056. "movq %%mm2, %%mm5 \n\t"
  1057. "punpcklwd %5, %%mm0 \n\t"
  1058. "punpcklwd %5, %%mm1 \n\t"
  1059. "punpcklwd %5, %%mm2 \n\t"
  1060. "punpckhwd %5, %%mm3 \n\t"
  1061. "punpckhwd %5, %%mm4 \n\t"
  1062. "punpckhwd %5, %%mm5 \n\t"
  1063. "psllq $8, %%mm1 \n\t"
  1064. "psllq $16, %%mm2 \n\t"
  1065. "por %%mm1, %%mm0 \n\t"
  1066. "por %%mm2, %%mm0 \n\t"
  1067. "psllq $8, %%mm4 \n\t"
  1068. "psllq $16, %%mm5 \n\t"
  1069. "por %%mm4, %%mm3 \n\t"
  1070. "por %%mm5, %%mm3 \n\t"
  1071. "movq %%mm0, %%mm6 \n\t"
  1072. "movq %%mm3, %%mm7 \n\t"
  1073. "movq 8%1, %%mm0 \n\t"
  1074. "movq 8%1, %%mm1 \n\t"
  1075. "movq 8%1, %%mm2 \n\t"
  1076. "pand %2, %%mm0 \n\t"
  1077. "pand %3, %%mm1 \n\t"
  1078. "pand %4, %%mm2 \n\t"
  1079. "psllq $3, %%mm0 \n\t"
  1080. "psrlq $3, %%mm1 \n\t"
  1081. "psrlq $8, %%mm2 \n\t"
  1082. "movq %%mm0, %%mm3 \n\t"
  1083. "movq %%mm1, %%mm4 \n\t"
  1084. "movq %%mm2, %%mm5 \n\t"
  1085. "punpcklwd %5, %%mm0 \n\t"
  1086. "punpcklwd %5, %%mm1 \n\t"
  1087. "punpcklwd %5, %%mm2 \n\t"
  1088. "punpckhwd %5, %%mm3 \n\t"
  1089. "punpckhwd %5, %%mm4 \n\t"
  1090. "punpckhwd %5, %%mm5 \n\t"
  1091. "psllq $8, %%mm1 \n\t"
  1092. "psllq $16, %%mm2 \n\t"
  1093. "por %%mm1, %%mm0 \n\t"
  1094. "por %%mm2, %%mm0 \n\t"
  1095. "psllq $8, %%mm4 \n\t"
  1096. "psllq $16, %%mm5 \n\t"
  1097. "por %%mm4, %%mm3 \n\t"
  1098. "por %%mm5, %%mm3 \n\t"
  1099. :"=m"(*d)
  1100. :"m"(*s),"m"(mask16b),"m"(mask16g),"m"(mask16r),"m"(mmx_null)
  1101. :"memory");
  1102. /* borrowed 32 to 24 */
  1103. __asm__ volatile(
  1104. "movq %%mm0, %%mm4 \n\t"
  1105. "movq %%mm3, %%mm5 \n\t"
  1106. "movq %%mm6, %%mm0 \n\t"
  1107. "movq %%mm7, %%mm1 \n\t"
  1108. "movq %%mm4, %%mm6 \n\t"
  1109. "movq %%mm5, %%mm7 \n\t"
  1110. "movq %%mm0, %%mm2 \n\t"
  1111. "movq %%mm1, %%mm3 \n\t"
  1112. "psrlq $8, %%mm2 \n\t"
  1113. "psrlq $8, %%mm3 \n\t"
  1114. "psrlq $8, %%mm6 \n\t"
  1115. "psrlq $8, %%mm7 \n\t"
  1116. "pand %2, %%mm0 \n\t"
  1117. "pand %2, %%mm1 \n\t"
  1118. "pand %2, %%mm4 \n\t"
  1119. "pand %2, %%mm5 \n\t"
  1120. "pand %3, %%mm2 \n\t"
  1121. "pand %3, %%mm3 \n\t"
  1122. "pand %3, %%mm6 \n\t"
  1123. "pand %3, %%mm7 \n\t"
  1124. "por %%mm2, %%mm0 \n\t"
  1125. "por %%mm3, %%mm1 \n\t"
  1126. "por %%mm6, %%mm4 \n\t"
  1127. "por %%mm7, %%mm5 \n\t"
  1128. "movq %%mm1, %%mm2 \n\t"
  1129. "movq %%mm4, %%mm3 \n\t"
  1130. "psllq $48, %%mm2 \n\t"
  1131. "psllq $32, %%mm3 \n\t"
  1132. "pand %4, %%mm2 \n\t"
  1133. "pand %5, %%mm3 \n\t"
  1134. "por %%mm2, %%mm0 \n\t"
  1135. "psrlq $16, %%mm1 \n\t"
  1136. "psrlq $32, %%mm4 \n\t"
  1137. "psllq $16, %%mm5 \n\t"
  1138. "por %%mm3, %%mm1 \n\t"
  1139. "pand %6, %%mm5 \n\t"
  1140. "por %%mm5, %%mm4 \n\t"
  1141. MOVNTQ" %%mm0, %0 \n\t"
  1142. MOVNTQ" %%mm1, 8%0 \n\t"
  1143. MOVNTQ" %%mm4, 16%0"
  1144. :"=m"(*d)
  1145. :"m"(*s),"m"(mask24l),"m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh)
  1146. :"memory");
  1147. d += 24;
  1148. s += 8;
  1149. }
  1150. __asm__ volatile(SFENCE:::"memory");
  1151. __asm__ volatile(EMMS:::"memory");
  1152. #endif
  1153. while (s < end)
  1154. {
  1155. register uint16_t bgr;
  1156. bgr = *s++;
  1157. *d++ = (bgr&0x1F)<<3;
  1158. *d++ = (bgr&0x7E0)>>3;
  1159. *d++ = (bgr&0xF800)>>8;
  1160. }
  1161. }
  1162. /*
  1163. * mm0 = 00 B3 00 B2 00 B1 00 B0
  1164. * mm1 = 00 G3 00 G2 00 G1 00 G0
  1165. * mm2 = 00 R3 00 R2 00 R1 00 R0
  1166. * mm6 = FF FF FF FF FF FF FF FF
  1167. * mm7 = 00 00 00 00 00 00 00 00
  1168. */
  1169. #define PACK_RGB32 \
  1170. "packuswb %%mm7, %%mm0 \n\t" /* 00 00 00 00 B3 B2 B1 B0 */ \
  1171. "packuswb %%mm7, %%mm1 \n\t" /* 00 00 00 00 G3 G2 G1 G0 */ \
  1172. "packuswb %%mm7, %%mm2 \n\t" /* 00 00 00 00 R3 R2 R1 R0 */ \
  1173. "punpcklbw %%mm1, %%mm0 \n\t" /* G3 B3 G2 B2 G1 B1 G0 B0 */ \
  1174. "punpcklbw %%mm6, %%mm2 \n\t" /* FF R3 FF R2 FF R1 FF R0 */ \
  1175. "movq %%mm0, %%mm3 \n\t" \
  1176. "punpcklwd %%mm2, %%mm0 \n\t" /* FF R1 G1 B1 FF R0 G0 B0 */ \
  1177. "punpckhwd %%mm2, %%mm3 \n\t" /* FF R3 G3 B3 FF R2 G2 B2 */ \
  1178. MOVNTQ" %%mm0, %0 \n\t" \
  1179. MOVNTQ" %%mm3, 8%0 \n\t" \
  1180. static inline void RENAME(rgb15to32)(const uint8_t *src, uint8_t *dst, long src_size)
  1181. {
  1182. const uint16_t *end;
  1183. #if HAVE_MMX
  1184. const uint16_t *mm_end;
  1185. #endif
  1186. uint8_t *d = dst;
  1187. const uint16_t *s = (const uint16_t *)src;
  1188. end = s + src_size/2;
  1189. #if HAVE_MMX
  1190. __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory");
  1191. __asm__ volatile("pxor %%mm7,%%mm7 \n\t":::"memory");
  1192. __asm__ volatile("pcmpeqd %%mm6,%%mm6 \n\t":::"memory");
  1193. mm_end = end - 3;
  1194. while (s < mm_end)
  1195. {
  1196. __asm__ volatile(
  1197. PREFETCH" 32%1 \n\t"
  1198. "movq %1, %%mm0 \n\t"
  1199. "movq %1, %%mm1 \n\t"
  1200. "movq %1, %%mm2 \n\t"
  1201. "pand %2, %%mm0 \n\t"
  1202. "pand %3, %%mm1 \n\t"
  1203. "pand %4, %%mm2 \n\t"
  1204. "psllq $3, %%mm0 \n\t"
  1205. "psrlq $2, %%mm1 \n\t"
  1206. "psrlq $7, %%mm2 \n\t"
  1207. PACK_RGB32
  1208. :"=m"(*d)
  1209. :"m"(*s),"m"(mask15b),"m"(mask15g),"m"(mask15r)
  1210. :"memory");
  1211. d += 16;
  1212. s += 4;
  1213. }
  1214. __asm__ volatile(SFENCE:::"memory");
  1215. __asm__ volatile(EMMS:::"memory");
  1216. #endif
  1217. while (s < end)
  1218. {
  1219. #if 0 //slightly slower on Athlon
  1220. int bgr= *s++;
  1221. *((uint32_t*)d)++ = ((bgr&0x1F)<<3) + ((bgr&0x3E0)<<6) + ((bgr&0x7C00)<<9);
  1222. #else
  1223. register uint16_t bgr;
  1224. bgr = *s++;
  1225. #ifdef WORDS_BIGENDIAN
  1226. *d++ = 255;
  1227. *d++ = (bgr&0x7C00)>>7;
  1228. *d++ = (bgr&0x3E0)>>2;
  1229. *d++ = (bgr&0x1F)<<3;
  1230. #else
  1231. *d++ = (bgr&0x1F)<<3;
  1232. *d++ = (bgr&0x3E0)>>2;
  1233. *d++ = (bgr&0x7C00)>>7;
  1234. *d++ = 255;
  1235. #endif
  1236. #endif
  1237. }
  1238. }
  1239. static inline void RENAME(rgb16to32)(const uint8_t *src, uint8_t *dst, long src_size)
  1240. {
  1241. const uint16_t *end;
  1242. #if HAVE_MMX
  1243. const uint16_t *mm_end;
  1244. #endif
  1245. uint8_t *d = dst;
  1246. const uint16_t *s = (const uint16_t*)src;
  1247. end = s + src_size/2;
  1248. #if HAVE_MMX
  1249. __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory");
  1250. __asm__ volatile("pxor %%mm7,%%mm7 \n\t":::"memory");
  1251. __asm__ volatile("pcmpeqd %%mm6,%%mm6 \n\t":::"memory");
  1252. mm_end = end - 3;
  1253. while (s < mm_end)
  1254. {
  1255. __asm__ volatile(
  1256. PREFETCH" 32%1 \n\t"
  1257. "movq %1, %%mm0 \n\t"
  1258. "movq %1, %%mm1 \n\t"
  1259. "movq %1, %%mm2 \n\t"
  1260. "pand %2, %%mm0 \n\t"
  1261. "pand %3, %%mm1 \n\t"
  1262. "pand %4, %%mm2 \n\t"
  1263. "psllq $3, %%mm0 \n\t"
  1264. "psrlq $3, %%mm1 \n\t"
  1265. "psrlq $8, %%mm2 \n\t"
  1266. PACK_RGB32
  1267. :"=m"(*d)
  1268. :"m"(*s),"m"(mask16b),"m"(mask16g),"m"(mask16r)
  1269. :"memory");
  1270. d += 16;
  1271. s += 4;
  1272. }
  1273. __asm__ volatile(SFENCE:::"memory");
  1274. __asm__ volatile(EMMS:::"memory");
  1275. #endif
  1276. while (s < end)
  1277. {
  1278. register uint16_t bgr;
  1279. bgr = *s++;
  1280. #ifdef WORDS_BIGENDIAN
  1281. *d++ = 255;
  1282. *d++ = (bgr&0xF800)>>8;
  1283. *d++ = (bgr&0x7E0)>>3;
  1284. *d++ = (bgr&0x1F)<<3;
  1285. #else
  1286. *d++ = (bgr&0x1F)<<3;
  1287. *d++ = (bgr&0x7E0)>>3;
  1288. *d++ = (bgr&0xF800)>>8;
  1289. *d++ = 255;
  1290. #endif
  1291. }
  1292. }
  1293. static inline void RENAME(rgb32tobgr32)(const uint8_t *src, uint8_t *dst, long src_size)
  1294. {
  1295. x86_reg idx = 15 - src_size;
  1296. const uint8_t *s = src-idx;
  1297. uint8_t *d = dst-idx;
  1298. #if HAVE_MMX
  1299. __asm__ volatile(
  1300. "test %0, %0 \n\t"
  1301. "jns 2f \n\t"
  1302. PREFETCH" (%1, %0) \n\t"
  1303. "movq %3, %%mm7 \n\t"
  1304. "pxor %4, %%mm7 \n\t"
  1305. "movq %%mm7, %%mm6 \n\t"
  1306. "pxor %5, %%mm7 \n\t"
  1307. ASMALIGN(4)
  1308. "1: \n\t"
  1309. PREFETCH" 32(%1, %0) \n\t"
  1310. "movq (%1, %0), %%mm0 \n\t"
  1311. "movq 8(%1, %0), %%mm1 \n\t"
  1312. # if HAVE_MMX2
  1313. "pshufw $177, %%mm0, %%mm3 \n\t"
  1314. "pshufw $177, %%mm1, %%mm5 \n\t"
  1315. "pand %%mm7, %%mm0 \n\t"
  1316. "pand %%mm6, %%mm3 \n\t"
  1317. "pand %%mm7, %%mm1 \n\t"
  1318. "pand %%mm6, %%mm5 \n\t"
  1319. "por %%mm3, %%mm0 \n\t"
  1320. "por %%mm5, %%mm1 \n\t"
  1321. # else
  1322. "movq %%mm0, %%mm2 \n\t"
  1323. "movq %%mm1, %%mm4 \n\t"
  1324. "pand %%mm7, %%mm0 \n\t"
  1325. "pand %%mm6, %%mm2 \n\t"
  1326. "pand %%mm7, %%mm1 \n\t"
  1327. "pand %%mm6, %%mm4 \n\t"
  1328. "movq %%mm2, %%mm3 \n\t"
  1329. "movq %%mm4, %%mm5 \n\t"
  1330. "pslld $16, %%mm2 \n\t"
  1331. "psrld $16, %%mm3 \n\t"
  1332. "pslld $16, %%mm4 \n\t"
  1333. "psrld $16, %%mm5 \n\t"
  1334. "por %%mm2, %%mm0 \n\t"
  1335. "por %%mm4, %%mm1 \n\t"
  1336. "por %%mm3, %%mm0 \n\t"
  1337. "por %%mm5, %%mm1 \n\t"
  1338. # endif
  1339. MOVNTQ" %%mm0, (%2, %0) \n\t"
  1340. MOVNTQ" %%mm1, 8(%2, %0) \n\t"
  1341. "add $16, %0 \n\t"
  1342. "js 1b \n\t"
  1343. SFENCE" \n\t"
  1344. EMMS" \n\t"
  1345. "2: \n\t"
  1346. : "+&r"(idx)
  1347. : "r" (s), "r" (d), "m" (mask32b), "m" (mask32r), "m" (mmx_one)
  1348. : "memory");
  1349. #endif
  1350. for (; idx<15; idx+=4) {
  1351. register int v = *(const uint32_t *)&s[idx], g = v & 0xff00ff00;
  1352. v &= 0xff00ff;
  1353. *(uint32_t *)&d[idx] = (v>>16) + g + (v<<16);
  1354. }
  1355. }
  1356. static inline void RENAME(rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size)
  1357. {
  1358. unsigned i;
  1359. #if HAVE_MMX
  1360. x86_reg mmx_size= 23 - src_size;
  1361. __asm__ volatile (
  1362. "test %%"REG_a", %%"REG_a" \n\t"
  1363. "jns 2f \n\t"
  1364. "movq "MANGLE(mask24r)", %%mm5 \n\t"
  1365. "movq "MANGLE(mask24g)", %%mm6 \n\t"
  1366. "movq "MANGLE(mask24b)", %%mm7 \n\t"
  1367. ASMALIGN(4)
  1368. "1: \n\t"
  1369. PREFETCH" 32(%1, %%"REG_a") \n\t"
  1370. "movq (%1, %%"REG_a"), %%mm0 \n\t" // BGR BGR BG
  1371. "movq (%1, %%"REG_a"), %%mm1 \n\t" // BGR BGR BG
  1372. "movq 2(%1, %%"REG_a"), %%mm2 \n\t" // R BGR BGR B
  1373. "psllq $16, %%mm0 \n\t" // 00 BGR BGR
  1374. "pand %%mm5, %%mm0 \n\t"
  1375. "pand %%mm6, %%mm1 \n\t"
  1376. "pand %%mm7, %%mm2 \n\t"
  1377. "por %%mm0, %%mm1 \n\t"
  1378. "por %%mm2, %%mm1 \n\t"
  1379. "movq 6(%1, %%"REG_a"), %%mm0 \n\t" // BGR BGR BG
  1380. MOVNTQ" %%mm1, (%2, %%"REG_a") \n\t" // RGB RGB RG
  1381. "movq 8(%1, %%"REG_a"), %%mm1 \n\t" // R BGR BGR B
  1382. "movq 10(%1, %%"REG_a"), %%mm2 \n\t" // GR BGR BGR
  1383. "pand %%mm7, %%mm0 \n\t"
  1384. "pand %%mm5, %%mm1 \n\t"
  1385. "pand %%mm6, %%mm2 \n\t"
  1386. "por %%mm0, %%mm1 \n\t"
  1387. "por %%mm2, %%mm1 \n\t"
  1388. "movq 14(%1, %%"REG_a"), %%mm0 \n\t" // R BGR BGR B
  1389. MOVNTQ" %%mm1, 8(%2, %%"REG_a") \n\t" // B RGB RGB R
  1390. "movq 16(%1, %%"REG_a"), %%mm1 \n\t" // GR BGR BGR
  1391. "movq 18(%1, %%"REG_a"), %%mm2 \n\t" // BGR BGR BG
  1392. "pand %%mm6, %%mm0 \n\t"
  1393. "pand %%mm7, %%mm1 \n\t"
  1394. "pand %%mm5, %%mm2 \n\t"
  1395. "por %%mm0, %%mm1 \n\t"
  1396. "por %%mm2, %%mm1 \n\t"
  1397. MOVNTQ" %%mm1, 16(%2, %%"REG_a") \n\t"
  1398. "add $24, %%"REG_a" \n\t"
  1399. " js 1b \n\t"
  1400. "2: \n\t"
  1401. : "+a" (mmx_size)
  1402. : "r" (src-mmx_size), "r"(dst-mmx_size)
  1403. );
  1404. __asm__ volatile(SFENCE:::"memory");
  1405. __asm__ volatile(EMMS:::"memory");
  1406. if (mmx_size==23) return; //finished, was multiple of 8
  1407. src+= src_size;
  1408. dst+= src_size;
  1409. src_size= 23-mmx_size;
  1410. src-= src_size;
  1411. dst-= src_size;
  1412. #endif
  1413. for (i=0; i<src_size; i+=3)
  1414. {
  1415. register uint8_t x;
  1416. x = src[i + 2];
  1417. dst[i + 1] = src[i + 1];
  1418. dst[i + 2] = src[i + 0];
  1419. dst[i + 0] = x;
  1420. }
  1421. }
  1422. static inline void RENAME(yuvPlanartoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  1423. long width, long height,
  1424. long lumStride, long chromStride, long dstStride, long vertLumPerChroma)
  1425. {
  1426. long y;
  1427. const x86_reg chromWidth= width>>1;
  1428. for (y=0; y<height; y++)
  1429. {
  1430. #if HAVE_MMX
  1431. //FIXME handle 2 lines at once (fewer prefetches, reuse some chroma, but very likely memory-limited anyway)
  1432. __asm__ volatile(
  1433. "xor %%"REG_a", %%"REG_a" \n\t"
  1434. ASMALIGN(4)
  1435. "1: \n\t"
  1436. PREFETCH" 32(%1, %%"REG_a", 2) \n\t"
  1437. PREFETCH" 32(%2, %%"REG_a") \n\t"
  1438. PREFETCH" 32(%3, %%"REG_a") \n\t"
  1439. "movq (%2, %%"REG_a"), %%mm0 \n\t" // U(0)
  1440. "movq %%mm0, %%mm2 \n\t" // U(0)
  1441. "movq (%3, %%"REG_a"), %%mm1 \n\t" // V(0)
  1442. "punpcklbw %%mm1, %%mm0 \n\t" // UVUV UVUV(0)
  1443. "punpckhbw %%mm1, %%mm2 \n\t" // UVUV UVUV(8)
  1444. "movq (%1, %%"REG_a",2), %%mm3 \n\t" // Y(0)
  1445. "movq 8(%1, %%"REG_a",2), %%mm5 \n\t" // Y(8)
  1446. "movq %%mm3, %%mm4 \n\t" // Y(0)
  1447. "movq %%mm5, %%mm6 \n\t" // Y(8)
  1448. "punpcklbw %%mm0, %%mm3 \n\t" // YUYV YUYV(0)
  1449. "punpckhbw %%mm0, %%mm4 \n\t" // YUYV YUYV(4)
  1450. "punpcklbw %%mm2, %%mm5 \n\t" // YUYV YUYV(8)
  1451. "punpckhbw %%mm2, %%mm6 \n\t" // YUYV YUYV(12)
  1452. MOVNTQ" %%mm3, (%0, %%"REG_a", 4) \n\t"
  1453. MOVNTQ" %%mm4, 8(%0, %%"REG_a", 4) \n\t"
  1454. MOVNTQ" %%mm5, 16(%0, %%"REG_a", 4) \n\t"
  1455. MOVNTQ" %%mm6, 24(%0, %%"REG_a", 4) \n\t"
  1456. "add $8, %%"REG_a" \n\t"
  1457. "cmp %4, %%"REG_a" \n\t"
  1458. " jb 1b \n\t"
  1459. ::"r"(dst), "r"(ysrc), "r"(usrc), "r"(vsrc), "g" (chromWidth)
  1460. : "%"REG_a
  1461. );
  1462. #else
  1463. #if ARCH_ALPHA && HAVE_MVI
  1464. #define pl2yuy2(n) \
  1465. y1 = yc[n]; \
  1466. y2 = yc2[n]; \
  1467. u = uc[n]; \
  1468. v = vc[n]; \
  1469. __asm__("unpkbw %1, %0" : "=r"(y1) : "r"(y1)); \
  1470. __asm__("unpkbw %1, %0" : "=r"(y2) : "r"(y2)); \
  1471. __asm__("unpkbl %1, %0" : "=r"(u) : "r"(u)); \
  1472. __asm__("unpkbl %1, %0" : "=r"(v) : "r"(v)); \
  1473. yuv1 = (u << 8) + (v << 24); \
  1474. yuv2 = yuv1 + y2; \
  1475. yuv1 += y1; \
  1476. qdst[n] = yuv1; \
  1477. qdst2[n] = yuv2;
  1478. int i;
  1479. uint64_t *qdst = (uint64_t *) dst;
  1480. uint64_t *qdst2 = (uint64_t *) (dst + dstStride);
  1481. const uint32_t *yc = (uint32_t *) ysrc;
  1482. const uint32_t *yc2 = (uint32_t *) (ysrc + lumStride);
  1483. const uint16_t *uc = (uint16_t*) usrc, *vc = (uint16_t*) vsrc;
  1484. for (i = 0; i < chromWidth; i += 8){
  1485. uint64_t y1, y2, yuv1, yuv2;
  1486. uint64_t u, v;
  1487. /* Prefetch */
  1488. __asm__("ldq $31,64(%0)" :: "r"(yc));
  1489. __asm__("ldq $31,64(%0)" :: "r"(yc2));
  1490. __asm__("ldq $31,64(%0)" :: "r"(uc));
  1491. __asm__("ldq $31,64(%0)" :: "r"(vc));
  1492. pl2yuy2(0);
  1493. pl2yuy2(1);
  1494. pl2yuy2(2);
  1495. pl2yuy2(3);
  1496. yc += 4;
  1497. yc2 += 4;
  1498. uc += 4;
  1499. vc += 4;
  1500. qdst += 4;
  1501. qdst2 += 4;
  1502. }
  1503. y++;
  1504. ysrc += lumStride;
  1505. dst += dstStride;
  1506. #elif HAVE_FAST_64BIT
  1507. int i;
  1508. uint64_t *ldst = (uint64_t *) dst;
  1509. const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
  1510. for (i = 0; i < chromWidth; i += 2){
  1511. uint64_t k, l;
  1512. k = yc[0] + (uc[0] << 8) +
  1513. (yc[1] << 16) + (vc[0] << 24);
  1514. l = yc[2] + (uc[1] << 8) +
  1515. (yc[3] << 16) + (vc[1] << 24);
  1516. *ldst++ = k + (l << 32);
  1517. yc += 4;
  1518. uc += 2;
  1519. vc += 2;
  1520. }
  1521. #else
  1522. int i, *idst = (int32_t *) dst;
  1523. const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
  1524. for (i = 0; i < chromWidth; i++){
  1525. #ifdef WORDS_BIGENDIAN
  1526. *idst++ = (yc[0] << 24)+ (uc[0] << 16) +
  1527. (yc[1] << 8) + (vc[0] << 0);
  1528. #else
  1529. *idst++ = yc[0] + (uc[0] << 8) +
  1530. (yc[1] << 16) + (vc[0] << 24);
  1531. #endif
  1532. yc += 2;
  1533. uc++;
  1534. vc++;
  1535. }
  1536. #endif
  1537. #endif
  1538. if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1)
  1539. {
  1540. usrc += chromStride;
  1541. vsrc += chromStride;
  1542. }
  1543. ysrc += lumStride;
  1544. dst += dstStride;
  1545. }
  1546. #if HAVE_MMX
  1547. __asm__( EMMS" \n\t"
  1548. SFENCE" \n\t"
  1549. :::"memory");
  1550. #endif
  1551. }
  1552. /**
  1553. * Height should be a multiple of 2 and width should be a multiple of 16.
  1554. * (If this is a problem for anyone then tell me, and I will fix it.)
  1555. */
  1556. static inline void RENAME(yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  1557. long width, long height,
  1558. long lumStride, long chromStride, long dstStride)
  1559. {
  1560. //FIXME interpolate chroma
  1561. RENAME(yuvPlanartoyuy2)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 2);
  1562. }
  1563. static inline void RENAME(yuvPlanartouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  1564. long width, long height,
  1565. long lumStride, long chromStride, long dstStride, long vertLumPerChroma)
  1566. {
  1567. long y;
  1568. const x86_reg chromWidth= width>>1;
  1569. for (y=0; y<height; y++)
  1570. {
  1571. #if HAVE_MMX
  1572. //FIXME handle 2 lines at once (fewer prefetches, reuse some chroma, but very likely memory-limited anyway)
  1573. __asm__ volatile(
  1574. "xor %%"REG_a", %%"REG_a" \n\t"
  1575. ASMALIGN(4)
  1576. "1: \n\t"
  1577. PREFETCH" 32(%1, %%"REG_a", 2) \n\t"
  1578. PREFETCH" 32(%2, %%"REG_a") \n\t"
  1579. PREFETCH" 32(%3, %%"REG_a") \n\t"
  1580. "movq (%2, %%"REG_a"), %%mm0 \n\t" // U(0)
  1581. "movq %%mm0, %%mm2 \n\t" // U(0)
  1582. "movq (%3, %%"REG_a"), %%mm1 \n\t" // V(0)
  1583. "punpcklbw %%mm1, %%mm0 \n\t" // UVUV UVUV(0)
  1584. "punpckhbw %%mm1, %%mm2 \n\t" // UVUV UVUV(8)
  1585. "movq (%1, %%"REG_a",2), %%mm3 \n\t" // Y(0)
  1586. "movq 8(%1, %%"REG_a",2), %%mm5 \n\t" // Y(8)
  1587. "movq %%mm0, %%mm4 \n\t" // Y(0)
  1588. "movq %%mm2, %%mm6 \n\t" // Y(8)
  1589. "punpcklbw %%mm3, %%mm0 \n\t" // YUYV YUYV(0)
  1590. "punpckhbw %%mm3, %%mm4 \n\t" // YUYV YUYV(4)
  1591. "punpcklbw %%mm5, %%mm2 \n\t" // YUYV YUYV(8)
  1592. "punpckhbw %%mm5, %%mm6 \n\t" // YUYV YUYV(12)
  1593. MOVNTQ" %%mm0, (%0, %%"REG_a", 4) \n\t"
  1594. MOVNTQ" %%mm4, 8(%0, %%"REG_a", 4) \n\t"
  1595. MOVNTQ" %%mm2, 16(%0, %%"REG_a", 4) \n\t"
  1596. MOVNTQ" %%mm6, 24(%0, %%"REG_a", 4) \n\t"
  1597. "add $8, %%"REG_a" \n\t"
  1598. "cmp %4, %%"REG_a" \n\t"
  1599. " jb 1b \n\t"
  1600. ::"r"(dst), "r"(ysrc), "r"(usrc), "r"(vsrc), "g" (chromWidth)
  1601. : "%"REG_a
  1602. );
  1603. #else
  1604. //FIXME adapt the Alpha ASM code from yv12->yuy2
  1605. #if HAVE_FAST_64BIT
  1606. int i;
  1607. uint64_t *ldst = (uint64_t *) dst;
  1608. const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
  1609. for (i = 0; i < chromWidth; i += 2){
  1610. uint64_t k, l;
  1611. k = uc[0] + (yc[0] << 8) +
  1612. (vc[0] << 16) + (yc[1] << 24);
  1613. l = uc[1] + (yc[2] << 8) +
  1614. (vc[1] << 16) + (yc[3] << 24);
  1615. *ldst++ = k + (l << 32);
  1616. yc += 4;
  1617. uc += 2;
  1618. vc += 2;
  1619. }
  1620. #else
  1621. int i, *idst = (int32_t *) dst;
  1622. const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
  1623. for (i = 0; i < chromWidth; i++){
  1624. #ifdef WORDS_BIGENDIAN
  1625. *idst++ = (uc[0] << 24)+ (yc[0] << 16) +
  1626. (vc[0] << 8) + (yc[1] << 0);
  1627. #else
  1628. *idst++ = uc[0] + (yc[0] << 8) +
  1629. (vc[0] << 16) + (yc[1] << 24);
  1630. #endif
  1631. yc += 2;
  1632. uc++;
  1633. vc++;
  1634. }
  1635. #endif
  1636. #endif
  1637. if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1)
  1638. {
  1639. usrc += chromStride;
  1640. vsrc += chromStride;
  1641. }
  1642. ysrc += lumStride;
  1643. dst += dstStride;
  1644. }
  1645. #if HAVE_MMX
  1646. __asm__( EMMS" \n\t"
  1647. SFENCE" \n\t"
  1648. :::"memory");
  1649. #endif
  1650. }
  1651. /**
  1652. * Height should be a multiple of 2 and width should be a multiple of 16
  1653. * (If this is a problem for anyone then tell me, and I will fix it.)
  1654. */
  1655. static inline void RENAME(yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  1656. long width, long height,
  1657. long lumStride, long chromStride, long dstStride)
  1658. {
  1659. //FIXME interpolate chroma
  1660. RENAME(yuvPlanartouyvy)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 2);
  1661. }
  1662. /**
  1663. * Width should be a multiple of 16.
  1664. */
  1665. static inline void RENAME(yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  1666. long width, long height,
  1667. long lumStride, long chromStride, long dstStride)
  1668. {
  1669. RENAME(yuvPlanartouyvy)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 1);
  1670. }
  1671. /**
  1672. * Width should be a multiple of 16.
  1673. */
  1674. static inline void RENAME(yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  1675. long width, long height,
  1676. long lumStride, long chromStride, long dstStride)
  1677. {
  1678. RENAME(yuvPlanartoyuy2)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 1);
  1679. }
  1680. /**
  1681. * Height should be a multiple of 2 and width should be a multiple of 16.
  1682. * (If this is a problem for anyone then tell me, and I will fix it.)
  1683. */
  1684. static inline void RENAME(yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  1685. long width, long height,
  1686. long lumStride, long chromStride, long srcStride)
  1687. {
  1688. long y;
  1689. const x86_reg chromWidth= width>>1;
  1690. for (y=0; y<height; y+=2)
  1691. {
  1692. #if HAVE_MMX
  1693. __asm__ volatile(
  1694. "xor %%"REG_a", %%"REG_a" \n\t"
  1695. "pcmpeqw %%mm7, %%mm7 \n\t"
  1696. "psrlw $8, %%mm7 \n\t" // FF,00,FF,00...
  1697. ASMALIGN(4)
  1698. "1: \n\t"
  1699. PREFETCH" 64(%0, %%"REG_a", 4) \n\t"
  1700. "movq (%0, %%"REG_a", 4), %%mm0 \n\t" // YUYV YUYV(0)
  1701. "movq 8(%0, %%"REG_a", 4), %%mm1 \n\t" // YUYV YUYV(4)
  1702. "movq %%mm0, %%mm2 \n\t" // YUYV YUYV(0)
  1703. "movq %%mm1, %%mm3 \n\t" // YUYV YUYV(4)
  1704. "psrlw $8, %%mm0 \n\t" // U0V0 U0V0(0)
  1705. "psrlw $8, %%mm1 \n\t" // U0V0 U0V0(4)
  1706. "pand %%mm7, %%mm2 \n\t" // Y0Y0 Y0Y0(0)
  1707. "pand %%mm7, %%mm3 \n\t" // Y0Y0 Y0Y0(4)
  1708. "packuswb %%mm1, %%mm0 \n\t" // UVUV UVUV(0)
  1709. "packuswb %%mm3, %%mm2 \n\t" // YYYY YYYY(0)
  1710. MOVNTQ" %%mm2, (%1, %%"REG_a", 2) \n\t"
  1711. "movq 16(%0, %%"REG_a", 4), %%mm1 \n\t" // YUYV YUYV(8)
  1712. "movq 24(%0, %%"REG_a", 4), %%mm2 \n\t" // YUYV YUYV(12)
  1713. "movq %%mm1, %%mm3 \n\t" // YUYV YUYV(8)
  1714. "movq %%mm2, %%mm4 \n\t" // YUYV YUYV(12)
  1715. "psrlw $8, %%mm1 \n\t" // U0V0 U0V0(8)
  1716. "psrlw $8, %%mm2 \n\t" // U0V0 U0V0(12)
  1717. "pand %%mm7, %%mm3 \n\t" // Y0Y0 Y0Y0(8)
  1718. "pand %%mm7, %%mm4 \n\t" // Y0Y0 Y0Y0(12)
  1719. "packuswb %%mm2, %%mm1 \n\t" // UVUV UVUV(8)
  1720. "packuswb %%mm4, %%mm3 \n\t" // YYYY YYYY(8)
  1721. MOVNTQ" %%mm3, 8(%1, %%"REG_a", 2) \n\t"
  1722. "movq %%mm0, %%mm2 \n\t" // UVUV UVUV(0)
  1723. "movq %%mm1, %%mm3 \n\t" // UVUV UVUV(8)
  1724. "psrlw $8, %%mm0 \n\t" // V0V0 V0V0(0)
  1725. "psrlw $8, %%mm1 \n\t" // V0V0 V0V0(8)
  1726. "pand %%mm7, %%mm2 \n\t" // U0U0 U0U0(0)
  1727. "pand %%mm7, %%mm3 \n\t" // U0U0 U0U0(8)
  1728. "packuswb %%mm1, %%mm0 \n\t" // VVVV VVVV(0)
  1729. "packuswb %%mm3, %%mm2 \n\t" // UUUU UUUU(0)
  1730. MOVNTQ" %%mm0, (%3, %%"REG_a") \n\t"
  1731. MOVNTQ" %%mm2, (%2, %%"REG_a") \n\t"
  1732. "add $8, %%"REG_a" \n\t"
  1733. "cmp %4, %%"REG_a" \n\t"
  1734. " jb 1b \n\t"
  1735. ::"r"(src), "r"(ydst), "r"(udst), "r"(vdst), "g" (chromWidth)
  1736. : "memory", "%"REG_a
  1737. );
  1738. ydst += lumStride;
  1739. src += srcStride;
  1740. __asm__ volatile(
  1741. "xor %%"REG_a", %%"REG_a" \n\t"
  1742. ASMALIGN(4)
  1743. "1: \n\t"
  1744. PREFETCH" 64(%0, %%"REG_a", 4) \n\t"
  1745. "movq (%0, %%"REG_a", 4), %%mm0 \n\t" // YUYV YUYV(0)
  1746. "movq 8(%0, %%"REG_a", 4), %%mm1 \n\t" // YUYV YUYV(4)
  1747. "movq 16(%0, %%"REG_a", 4), %%mm2 \n\t" // YUYV YUYV(8)
  1748. "movq 24(%0, %%"REG_a", 4), %%mm3 \n\t" // YUYV YUYV(12)
  1749. "pand %%mm7, %%mm0 \n\t" // Y0Y0 Y0Y0(0)
  1750. "pand %%mm7, %%mm1 \n\t" // Y0Y0 Y0Y0(4)
  1751. "pand %%mm7, %%mm2 \n\t" // Y0Y0 Y0Y0(8)
  1752. "pand %%mm7, %%mm3 \n\t" // Y0Y0 Y0Y0(12)
  1753. "packuswb %%mm1, %%mm0 \n\t" // YYYY YYYY(0)
  1754. "packuswb %%mm3, %%mm2 \n\t" // YYYY YYYY(8)
  1755. MOVNTQ" %%mm0, (%1, %%"REG_a", 2) \n\t"
  1756. MOVNTQ" %%mm2, 8(%1, %%"REG_a", 2) \n\t"
  1757. "add $8, %%"REG_a" \n\t"
  1758. "cmp %4, %%"REG_a" \n\t"
  1759. " jb 1b \n\t"
  1760. ::"r"(src), "r"(ydst), "r"(udst), "r"(vdst), "g" (chromWidth)
  1761. : "memory", "%"REG_a
  1762. );
  1763. #else
  1764. long i;
  1765. for (i=0; i<chromWidth; i++)
  1766. {
  1767. ydst[2*i+0] = src[4*i+0];
  1768. udst[i] = src[4*i+1];
  1769. ydst[2*i+1] = src[4*i+2];
  1770. vdst[i] = src[4*i+3];
  1771. }
  1772. ydst += lumStride;
  1773. src += srcStride;
  1774. for (i=0; i<chromWidth; i++)
  1775. {
  1776. ydst[2*i+0] = src[4*i+0];
  1777. ydst[2*i+1] = src[4*i+2];
  1778. }
  1779. #endif
  1780. udst += chromStride;
  1781. vdst += chromStride;
  1782. ydst += lumStride;
  1783. src += srcStride;
  1784. }
  1785. #if HAVE_MMX
  1786. __asm__ volatile( EMMS" \n\t"
  1787. SFENCE" \n\t"
  1788. :::"memory");
  1789. #endif
  1790. }
  1791. static inline void RENAME(yvu9toyv12)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc,
  1792. uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  1793. long width, long height, long lumStride, long chromStride)
  1794. {
  1795. /* Y Plane */
  1796. memcpy(ydst, ysrc, width*height);
  1797. /* XXX: implement upscaling for U,V */
  1798. }
  1799. static inline void RENAME(planar2x)(const uint8_t *src, uint8_t *dst, long srcWidth, long srcHeight, long srcStride, long dstStride)
  1800. {
  1801. long x,y;
  1802. dst[0]= src[0];
  1803. // first line
  1804. for (x=0; x<srcWidth-1; x++){
  1805. dst[2*x+1]= (3*src[x] + src[x+1])>>2;
  1806. dst[2*x+2]= ( src[x] + 3*src[x+1])>>2;
  1807. }
  1808. dst[2*srcWidth-1]= src[srcWidth-1];
  1809. dst+= dstStride;
  1810. for (y=1; y<srcHeight; y++){
  1811. #if HAVE_MMX2 || HAVE_AMD3DNOW
  1812. const x86_reg mmxSize= srcWidth&~15;
  1813. __asm__ volatile(
  1814. "mov %4, %%"REG_a" \n\t"
  1815. "1: \n\t"
  1816. "movq (%0, %%"REG_a"), %%mm0 \n\t"
  1817. "movq (%1, %%"REG_a"), %%mm1 \n\t"
  1818. "movq 1(%0, %%"REG_a"), %%mm2 \n\t"
  1819. "movq 1(%1, %%"REG_a"), %%mm3 \n\t"
  1820. "movq -1(%0, %%"REG_a"), %%mm4 \n\t"
  1821. "movq -1(%1, %%"REG_a"), %%mm5 \n\t"
  1822. PAVGB" %%mm0, %%mm5 \n\t"
  1823. PAVGB" %%mm0, %%mm3 \n\t"
  1824. PAVGB" %%mm0, %%mm5 \n\t"
  1825. PAVGB" %%mm0, %%mm3 \n\t"
  1826. PAVGB" %%mm1, %%mm4 \n\t"
  1827. PAVGB" %%mm1, %%mm2 \n\t"
  1828. PAVGB" %%mm1, %%mm4 \n\t"
  1829. PAVGB" %%mm1, %%mm2 \n\t"
  1830. "movq %%mm5, %%mm7 \n\t"
  1831. "movq %%mm4, %%mm6 \n\t"
  1832. "punpcklbw %%mm3, %%mm5 \n\t"
  1833. "punpckhbw %%mm3, %%mm7 \n\t"
  1834. "punpcklbw %%mm2, %%mm4 \n\t"
  1835. "punpckhbw %%mm2, %%mm6 \n\t"
  1836. #if 1
  1837. MOVNTQ" %%mm5, (%2, %%"REG_a", 2) \n\t"
  1838. MOVNTQ" %%mm7, 8(%2, %%"REG_a", 2) \n\t"
  1839. MOVNTQ" %%mm4, (%3, %%"REG_a", 2) \n\t"
  1840. MOVNTQ" %%mm6, 8(%3, %%"REG_a", 2) \n\t"
  1841. #else
  1842. "movq %%mm5, (%2, %%"REG_a", 2) \n\t"
  1843. "movq %%mm7, 8(%2, %%"REG_a", 2) \n\t"
  1844. "movq %%mm4, (%3, %%"REG_a", 2) \n\t"
  1845. "movq %%mm6, 8(%3, %%"REG_a", 2) \n\t"
  1846. #endif
  1847. "add $8, %%"REG_a" \n\t"
  1848. " js 1b \n\t"
  1849. :: "r" (src + mmxSize ), "r" (src + srcStride + mmxSize ),
  1850. "r" (dst + mmxSize*2), "r" (dst + dstStride + mmxSize*2),
  1851. "g" (-mmxSize)
  1852. : "%"REG_a
  1853. );
  1854. #else
  1855. const x86_reg mmxSize=1;
  1856. #endif
  1857. dst[0 ]= (3*src[0] + src[srcStride])>>2;
  1858. dst[dstStride]= ( src[0] + 3*src[srcStride])>>2;
  1859. for (x=mmxSize-1; x<srcWidth-1; x++){
  1860. dst[2*x +1]= (3*src[x+0] + src[x+srcStride+1])>>2;
  1861. dst[2*x+dstStride+2]= ( src[x+0] + 3*src[x+srcStride+1])>>2;
  1862. dst[2*x+dstStride+1]= ( src[x+1] + 3*src[x+srcStride ])>>2;
  1863. dst[2*x +2]= (3*src[x+1] + src[x+srcStride ])>>2;
  1864. }
  1865. dst[srcWidth*2 -1 ]= (3*src[srcWidth-1] + src[srcWidth-1 + srcStride])>>2;
  1866. dst[srcWidth*2 -1 + dstStride]= ( src[srcWidth-1] + 3*src[srcWidth-1 + srcStride])>>2;
  1867. dst+=dstStride*2;
  1868. src+=srcStride;
  1869. }
  1870. // last line
  1871. #if 1
  1872. dst[0]= src[0];
  1873. for (x=0; x<srcWidth-1; x++){
  1874. dst[2*x+1]= (3*src[x] + src[x+1])>>2;
  1875. dst[2*x+2]= ( src[x] + 3*src[x+1])>>2;
  1876. }
  1877. dst[2*srcWidth-1]= src[srcWidth-1];
  1878. #else
  1879. for (x=0; x<srcWidth; x++){
  1880. dst[2*x+0]=
  1881. dst[2*x+1]= src[x];
  1882. }
  1883. #endif
  1884. #if HAVE_MMX
  1885. __asm__ volatile( EMMS" \n\t"
  1886. SFENCE" \n\t"
  1887. :::"memory");
  1888. #endif
  1889. }
  1890. /**
  1891. * Height should be a multiple of 2 and width should be a multiple of 16.
  1892. * (If this is a problem for anyone then tell me, and I will fix it.)
  1893. * Chrominance data is only taken from every second line, others are ignored.
  1894. * FIXME: Write HQ version.
  1895. */
  1896. static inline void RENAME(uyvytoyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  1897. long width, long height,
  1898. long lumStride, long chromStride, long srcStride)
  1899. {
  1900. long y;
  1901. const x86_reg chromWidth= width>>1;
  1902. for (y=0; y<height; y+=2)
  1903. {
  1904. #if HAVE_MMX
  1905. __asm__ volatile(
  1906. "xor %%"REG_a", %%"REG_a" \n\t"
  1907. "pcmpeqw %%mm7, %%mm7 \n\t"
  1908. "psrlw $8, %%mm7 \n\t" // FF,00,FF,00...
  1909. ASMALIGN(4)
  1910. "1: \n\t"
  1911. PREFETCH" 64(%0, %%"REG_a", 4) \n\t"
  1912. "movq (%0, %%"REG_a", 4), %%mm0 \n\t" // UYVY UYVY(0)
  1913. "movq 8(%0, %%"REG_a", 4), %%mm1 \n\t" // UYVY UYVY(4)
  1914. "movq %%mm0, %%mm2 \n\t" // UYVY UYVY(0)
  1915. "movq %%mm1, %%mm3 \n\t" // UYVY UYVY(4)
  1916. "pand %%mm7, %%mm0 \n\t" // U0V0 U0V0(0)
  1917. "pand %%mm7, %%mm1 \n\t" // U0V0 U0V0(4)
  1918. "psrlw $8, %%mm2 \n\t" // Y0Y0 Y0Y0(0)
  1919. "psrlw $8, %%mm3 \n\t" // Y0Y0 Y0Y0(4)
  1920. "packuswb %%mm1, %%mm0 \n\t" // UVUV UVUV(0)
  1921. "packuswb %%mm3, %%mm2 \n\t" // YYYY YYYY(0)
  1922. MOVNTQ" %%mm2, (%1, %%"REG_a", 2) \n\t"
  1923. "movq 16(%0, %%"REG_a", 4), %%mm1 \n\t" // UYVY UYVY(8)
  1924. "movq 24(%0, %%"REG_a", 4), %%mm2 \n\t" // UYVY UYVY(12)
  1925. "movq %%mm1, %%mm3 \n\t" // UYVY UYVY(8)
  1926. "movq %%mm2, %%mm4 \n\t" // UYVY UYVY(12)
  1927. "pand %%mm7, %%mm1 \n\t" // U0V0 U0V0(8)
  1928. "pand %%mm7, %%mm2 \n\t" // U0V0 U0V0(12)
  1929. "psrlw $8, %%mm3 \n\t" // Y0Y0 Y0Y0(8)
  1930. "psrlw $8, %%mm4 \n\t" // Y0Y0 Y0Y0(12)
  1931. "packuswb %%mm2, %%mm1 \n\t" // UVUV UVUV(8)
  1932. "packuswb %%mm4, %%mm3 \n\t" // YYYY YYYY(8)
  1933. MOVNTQ" %%mm3, 8(%1, %%"REG_a", 2) \n\t"
  1934. "movq %%mm0, %%mm2 \n\t" // UVUV UVUV(0)
  1935. "movq %%mm1, %%mm3 \n\t" // UVUV UVUV(8)
  1936. "psrlw $8, %%mm0 \n\t" // V0V0 V0V0(0)
  1937. "psrlw $8, %%mm1 \n\t" // V0V0 V0V0(8)
  1938. "pand %%mm7, %%mm2 \n\t" // U0U0 U0U0(0)
  1939. "pand %%mm7, %%mm3 \n\t" // U0U0 U0U0(8)
  1940. "packuswb %%mm1, %%mm0 \n\t" // VVVV VVVV(0)
  1941. "packuswb %%mm3, %%mm2 \n\t" // UUUU UUUU(0)
  1942. MOVNTQ" %%mm0, (%3, %%"REG_a") \n\t"
  1943. MOVNTQ" %%mm2, (%2, %%"REG_a") \n\t"
  1944. "add $8, %%"REG_a" \n\t"
  1945. "cmp %4, %%"REG_a" \n\t"
  1946. " jb 1b \n\t"
  1947. ::"r"(src), "r"(ydst), "r"(udst), "r"(vdst), "g" (chromWidth)
  1948. : "memory", "%"REG_a
  1949. );
  1950. ydst += lumStride;
  1951. src += srcStride;
  1952. __asm__ volatile(
  1953. "xor %%"REG_a", %%"REG_a" \n\t"
  1954. ASMALIGN(4)
  1955. "1: \n\t"
  1956. PREFETCH" 64(%0, %%"REG_a", 4) \n\t"
  1957. "movq (%0, %%"REG_a", 4), %%mm0 \n\t" // YUYV YUYV(0)
  1958. "movq 8(%0, %%"REG_a", 4), %%mm1 \n\t" // YUYV YUYV(4)
  1959. "movq 16(%0, %%"REG_a", 4), %%mm2 \n\t" // YUYV YUYV(8)
  1960. "movq 24(%0, %%"REG_a", 4), %%mm3 \n\t" // YUYV YUYV(12)
  1961. "psrlw $8, %%mm0 \n\t" // Y0Y0 Y0Y0(0)
  1962. "psrlw $8, %%mm1 \n\t" // Y0Y0 Y0Y0(4)
  1963. "psrlw $8, %%mm2 \n\t" // Y0Y0 Y0Y0(8)
  1964. "psrlw $8, %%mm3 \n\t" // Y0Y0 Y0Y0(12)
  1965. "packuswb %%mm1, %%mm0 \n\t" // YYYY YYYY(0)
  1966. "packuswb %%mm3, %%mm2 \n\t" // YYYY YYYY(8)
  1967. MOVNTQ" %%mm0, (%1, %%"REG_a", 2) \n\t"
  1968. MOVNTQ" %%mm2, 8(%1, %%"REG_a", 2) \n\t"
  1969. "add $8, %%"REG_a" \n\t"
  1970. "cmp %4, %%"REG_a" \n\t"
  1971. " jb 1b \n\t"
  1972. ::"r"(src), "r"(ydst), "r"(udst), "r"(vdst), "g" (chromWidth)
  1973. : "memory", "%"REG_a
  1974. );
  1975. #else
  1976. long i;
  1977. for (i=0; i<chromWidth; i++)
  1978. {
  1979. udst[i] = src[4*i+0];
  1980. ydst[2*i+0] = src[4*i+1];
  1981. vdst[i] = src[4*i+2];
  1982. ydst[2*i+1] = src[4*i+3];
  1983. }
  1984. ydst += lumStride;
  1985. src += srcStride;
  1986. for (i=0; i<chromWidth; i++)
  1987. {
  1988. ydst[2*i+0] = src[4*i+1];
  1989. ydst[2*i+1] = src[4*i+3];
  1990. }
  1991. #endif
  1992. udst += chromStride;
  1993. vdst += chromStride;
  1994. ydst += lumStride;
  1995. src += srcStride;
  1996. }
  1997. #if HAVE_MMX
  1998. __asm__ volatile( EMMS" \n\t"
  1999. SFENCE" \n\t"
  2000. :::"memory");
  2001. #endif
  2002. }
  2003. /**
  2004. * Height should be a multiple of 2 and width should be a multiple of 2.
  2005. * (If this is a problem for anyone then tell me, and I will fix it.)
  2006. * Chrominance data is only taken from every second line,
  2007. * others are ignored in the C version.
  2008. * FIXME: Write HQ version.
  2009. */
  2010. static inline void RENAME(rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  2011. long width, long height,
  2012. long lumStride, long chromStride, long srcStride)
  2013. {
  2014. long y;
  2015. const x86_reg chromWidth= width>>1;
  2016. #if HAVE_MMX
  2017. for (y=0; y<height-2; y+=2)
  2018. {
  2019. long i;
  2020. for (i=0; i<2; i++)
  2021. {
  2022. __asm__ volatile(
  2023. "mov %2, %%"REG_a" \n\t"
  2024. "movq "MANGLE(ff_bgr2YCoeff)", %%mm6 \n\t"
  2025. "movq "MANGLE(ff_w1111)", %%mm5 \n\t"
  2026. "pxor %%mm7, %%mm7 \n\t"
  2027. "lea (%%"REG_a", %%"REG_a", 2), %%"REG_d" \n\t"
  2028. ASMALIGN(4)
  2029. "1: \n\t"
  2030. PREFETCH" 64(%0, %%"REG_d") \n\t"
  2031. "movd (%0, %%"REG_d"), %%mm0 \n\t"
  2032. "movd 3(%0, %%"REG_d"), %%mm1 \n\t"
  2033. "punpcklbw %%mm7, %%mm0 \n\t"
  2034. "punpcklbw %%mm7, %%mm1 \n\t"
  2035. "movd 6(%0, %%"REG_d"), %%mm2 \n\t"
  2036. "movd 9(%0, %%"REG_d"), %%mm3 \n\t"
  2037. "punpcklbw %%mm7, %%mm2 \n\t"
  2038. "punpcklbw %%mm7, %%mm3 \n\t"
  2039. "pmaddwd %%mm6, %%mm0 \n\t"
  2040. "pmaddwd %%mm6, %%mm1 \n\t"
  2041. "pmaddwd %%mm6, %%mm2 \n\t"
  2042. "pmaddwd %%mm6, %%mm3 \n\t"
  2043. #ifndef FAST_BGR2YV12
  2044. "psrad $8, %%mm0 \n\t"
  2045. "psrad $8, %%mm1 \n\t"
  2046. "psrad $8, %%mm2 \n\t"
  2047. "psrad $8, %%mm3 \n\t"
  2048. #endif
  2049. "packssdw %%mm1, %%mm0 \n\t"
  2050. "packssdw %%mm3, %%mm2 \n\t"
  2051. "pmaddwd %%mm5, %%mm0 \n\t"
  2052. "pmaddwd %%mm5, %%mm2 \n\t"
  2053. "packssdw %%mm2, %%mm0 \n\t"
  2054. "psraw $7, %%mm0 \n\t"
  2055. "movd 12(%0, %%"REG_d"), %%mm4 \n\t"
  2056. "movd 15(%0, %%"REG_d"), %%mm1 \n\t"
  2057. "punpcklbw %%mm7, %%mm4 \n\t"
  2058. "punpcklbw %%mm7, %%mm1 \n\t"
  2059. "movd 18(%0, %%"REG_d"), %%mm2 \n\t"
  2060. "movd 21(%0, %%"REG_d"), %%mm3 \n\t"
  2061. "punpcklbw %%mm7, %%mm2 \n\t"
  2062. "punpcklbw %%mm7, %%mm3 \n\t"
  2063. "pmaddwd %%mm6, %%mm4 \n\t"
  2064. "pmaddwd %%mm6, %%mm1 \n\t"
  2065. "pmaddwd %%mm6, %%mm2 \n\t"
  2066. "pmaddwd %%mm6, %%mm3 \n\t"
  2067. #ifndef FAST_BGR2YV12
  2068. "psrad $8, %%mm4 \n\t"
  2069. "psrad $8, %%mm1 \n\t"
  2070. "psrad $8, %%mm2 \n\t"
  2071. "psrad $8, %%mm3 \n\t"
  2072. #endif
  2073. "packssdw %%mm1, %%mm4 \n\t"
  2074. "packssdw %%mm3, %%mm2 \n\t"
  2075. "pmaddwd %%mm5, %%mm4 \n\t"
  2076. "pmaddwd %%mm5, %%mm2 \n\t"
  2077. "add $24, %%"REG_d" \n\t"
  2078. "packssdw %%mm2, %%mm4 \n\t"
  2079. "psraw $7, %%mm4 \n\t"
  2080. "packuswb %%mm4, %%mm0 \n\t"
  2081. "paddusb "MANGLE(ff_bgr2YOffset)", %%mm0 \n\t"
  2082. MOVNTQ" %%mm0, (%1, %%"REG_a") \n\t"
  2083. "add $8, %%"REG_a" \n\t"
  2084. " js 1b \n\t"
  2085. : : "r" (src+width*3), "r" (ydst+width), "g" ((x86_reg)-width)
  2086. : "%"REG_a, "%"REG_d
  2087. );
  2088. ydst += lumStride;
  2089. src += srcStride;
  2090. }
  2091. src -= srcStride*2;
  2092. __asm__ volatile(
  2093. "mov %4, %%"REG_a" \n\t"
  2094. "movq "MANGLE(ff_w1111)", %%mm5 \n\t"
  2095. "movq "MANGLE(ff_bgr2UCoeff)", %%mm6 \n\t"
  2096. "pxor %%mm7, %%mm7 \n\t"
  2097. "lea (%%"REG_a", %%"REG_a", 2), %%"REG_d" \n\t"
  2098. "add %%"REG_d", %%"REG_d" \n\t"
  2099. ASMALIGN(4)
  2100. "1: \n\t"
  2101. PREFETCH" 64(%0, %%"REG_d") \n\t"
  2102. PREFETCH" 64(%1, %%"REG_d") \n\t"
  2103. #if HAVE_MMX2 || HAVE_AMD3DNOW
  2104. "movq (%0, %%"REG_d"), %%mm0 \n\t"
  2105. "movq (%1, %%"REG_d"), %%mm1 \n\t"
  2106. "movq 6(%0, %%"REG_d"), %%mm2 \n\t"
  2107. "movq 6(%1, %%"REG_d"), %%mm3 \n\t"
  2108. PAVGB" %%mm1, %%mm0 \n\t"
  2109. PAVGB" %%mm3, %%mm2 \n\t"
  2110. "movq %%mm0, %%mm1 \n\t"
  2111. "movq %%mm2, %%mm3 \n\t"
  2112. "psrlq $24, %%mm0 \n\t"
  2113. "psrlq $24, %%mm2 \n\t"
  2114. PAVGB" %%mm1, %%mm0 \n\t"
  2115. PAVGB" %%mm3, %%mm2 \n\t"
  2116. "punpcklbw %%mm7, %%mm0 \n\t"
  2117. "punpcklbw %%mm7, %%mm2 \n\t"
  2118. #else
  2119. "movd (%0, %%"REG_d"), %%mm0 \n\t"
  2120. "movd (%1, %%"REG_d"), %%mm1 \n\t"
  2121. "movd 3(%0, %%"REG_d"), %%mm2 \n\t"
  2122. "movd 3(%1, %%"REG_d"), %%mm3 \n\t"
  2123. "punpcklbw %%mm7, %%mm0 \n\t"
  2124. "punpcklbw %%mm7, %%mm1 \n\t"
  2125. "punpcklbw %%mm7, %%mm2 \n\t"
  2126. "punpcklbw %%mm7, %%mm3 \n\t"
  2127. "paddw %%mm1, %%mm0 \n\t"
  2128. "paddw %%mm3, %%mm2 \n\t"
  2129. "paddw %%mm2, %%mm0 \n\t"
  2130. "movd 6(%0, %%"REG_d"), %%mm4 \n\t"
  2131. "movd 6(%1, %%"REG_d"), %%mm1 \n\t"
  2132. "movd 9(%0, %%"REG_d"), %%mm2 \n\t"
  2133. "movd 9(%1, %%"REG_d"), %%mm3 \n\t"
  2134. "punpcklbw %%mm7, %%mm4 \n\t"
  2135. "punpcklbw %%mm7, %%mm1 \n\t"
  2136. "punpcklbw %%mm7, %%mm2 \n\t"
  2137. "punpcklbw %%mm7, %%mm3 \n\t"
  2138. "paddw %%mm1, %%mm4 \n\t"
  2139. "paddw %%mm3, %%mm2 \n\t"
  2140. "paddw %%mm4, %%mm2 \n\t"
  2141. "psrlw $2, %%mm0 \n\t"
  2142. "psrlw $2, %%mm2 \n\t"
  2143. #endif
  2144. "movq "MANGLE(ff_bgr2VCoeff)", %%mm1 \n\t"
  2145. "movq "MANGLE(ff_bgr2VCoeff)", %%mm3 \n\t"
  2146. "pmaddwd %%mm0, %%mm1 \n\t"
  2147. "pmaddwd %%mm2, %%mm3 \n\t"
  2148. "pmaddwd %%mm6, %%mm0 \n\t"
  2149. "pmaddwd %%mm6, %%mm2 \n\t"
  2150. #ifndef FAST_BGR2YV12
  2151. "psrad $8, %%mm0 \n\t"
  2152. "psrad $8, %%mm1 \n\t"
  2153. "psrad $8, %%mm2 \n\t"
  2154. "psrad $8, %%mm3 \n\t"
  2155. #endif
  2156. "packssdw %%mm2, %%mm0 \n\t"
  2157. "packssdw %%mm3, %%mm1 \n\t"
  2158. "pmaddwd %%mm5, %%mm0 \n\t"
  2159. "pmaddwd %%mm5, %%mm1 \n\t"
  2160. "packssdw %%mm1, %%mm0 \n\t" // V1 V0 U1 U0
  2161. "psraw $7, %%mm0 \n\t"
  2162. #if HAVE_MMX2 || HAVE_AMD3DNOW
  2163. "movq 12(%0, %%"REG_d"), %%mm4 \n\t"
  2164. "movq 12(%1, %%"REG_d"), %%mm1 \n\t"
  2165. "movq 18(%0, %%"REG_d"), %%mm2 \n\t"
  2166. "movq 18(%1, %%"REG_d"), %%mm3 \n\t"
  2167. PAVGB" %%mm1, %%mm4 \n\t"
  2168. PAVGB" %%mm3, %%mm2 \n\t"
  2169. "movq %%mm4, %%mm1 \n\t"
  2170. "movq %%mm2, %%mm3 \n\t"
  2171. "psrlq $24, %%mm4 \n\t"
  2172. "psrlq $24, %%mm2 \n\t"
  2173. PAVGB" %%mm1, %%mm4 \n\t"
  2174. PAVGB" %%mm3, %%mm2 \n\t"
  2175. "punpcklbw %%mm7, %%mm4 \n\t"
  2176. "punpcklbw %%mm7, %%mm2 \n\t"
  2177. #else
  2178. "movd 12(%0, %%"REG_d"), %%mm4 \n\t"
  2179. "movd 12(%1, %%"REG_d"), %%mm1 \n\t"
  2180. "movd 15(%0, %%"REG_d"), %%mm2 \n\t"
  2181. "movd 15(%1, %%"REG_d"), %%mm3 \n\t"
  2182. "punpcklbw %%mm7, %%mm4 \n\t"
  2183. "punpcklbw %%mm7, %%mm1 \n\t"
  2184. "punpcklbw %%mm7, %%mm2 \n\t"
  2185. "punpcklbw %%mm7, %%mm3 \n\t"
  2186. "paddw %%mm1, %%mm4 \n\t"
  2187. "paddw %%mm3, %%mm2 \n\t"
  2188. "paddw %%mm2, %%mm4 \n\t"
  2189. "movd 18(%0, %%"REG_d"), %%mm5 \n\t"
  2190. "movd 18(%1, %%"REG_d"), %%mm1 \n\t"
  2191. "movd 21(%0, %%"REG_d"), %%mm2 \n\t"
  2192. "movd 21(%1, %%"REG_d"), %%mm3 \n\t"
  2193. "punpcklbw %%mm7, %%mm5 \n\t"
  2194. "punpcklbw %%mm7, %%mm1 \n\t"
  2195. "punpcklbw %%mm7, %%mm2 \n\t"
  2196. "punpcklbw %%mm7, %%mm3 \n\t"
  2197. "paddw %%mm1, %%mm5 \n\t"
  2198. "paddw %%mm3, %%mm2 \n\t"
  2199. "paddw %%mm5, %%mm2 \n\t"
  2200. "movq "MANGLE(ff_w1111)", %%mm5 \n\t"
  2201. "psrlw $2, %%mm4 \n\t"
  2202. "psrlw $2, %%mm2 \n\t"
  2203. #endif
  2204. "movq "MANGLE(ff_bgr2VCoeff)", %%mm1 \n\t"
  2205. "movq "MANGLE(ff_bgr2VCoeff)", %%mm3 \n\t"
  2206. "pmaddwd %%mm4, %%mm1 \n\t"
  2207. "pmaddwd %%mm2, %%mm3 \n\t"
  2208. "pmaddwd %%mm6, %%mm4 \n\t"
  2209. "pmaddwd %%mm6, %%mm2 \n\t"
  2210. #ifndef FAST_BGR2YV12
  2211. "psrad $8, %%mm4 \n\t"
  2212. "psrad $8, %%mm1 \n\t"
  2213. "psrad $8, %%mm2 \n\t"
  2214. "psrad $8, %%mm3 \n\t"
  2215. #endif
  2216. "packssdw %%mm2, %%mm4 \n\t"
  2217. "packssdw %%mm3, %%mm1 \n\t"
  2218. "pmaddwd %%mm5, %%mm4 \n\t"
  2219. "pmaddwd %%mm5, %%mm1 \n\t"
  2220. "add $24, %%"REG_d" \n\t"
  2221. "packssdw %%mm1, %%mm4 \n\t" // V3 V2 U3 U2
  2222. "psraw $7, %%mm4 \n\t"
  2223. "movq %%mm0, %%mm1 \n\t"
  2224. "punpckldq %%mm4, %%mm0 \n\t"
  2225. "punpckhdq %%mm4, %%mm1 \n\t"
  2226. "packsswb %%mm1, %%mm0 \n\t"
  2227. "paddb "MANGLE(ff_bgr2UVOffset)", %%mm0 \n\t"
  2228. "movd %%mm0, (%2, %%"REG_a") \n\t"
  2229. "punpckhdq %%mm0, %%mm0 \n\t"
  2230. "movd %%mm0, (%3, %%"REG_a") \n\t"
  2231. "add $4, %%"REG_a" \n\t"
  2232. " js 1b \n\t"
  2233. : : "r" (src+chromWidth*6), "r" (src+srcStride+chromWidth*6), "r" (udst+chromWidth), "r" (vdst+chromWidth), "g" (-chromWidth)
  2234. : "%"REG_a, "%"REG_d
  2235. );
  2236. udst += chromStride;
  2237. vdst += chromStride;
  2238. src += srcStride*2;
  2239. }
  2240. __asm__ volatile( EMMS" \n\t"
  2241. SFENCE" \n\t"
  2242. :::"memory");
  2243. #else
  2244. y=0;
  2245. #endif
  2246. for (; y<height; y+=2)
  2247. {
  2248. long i;
  2249. for (i=0; i<chromWidth; i++)
  2250. {
  2251. unsigned int b = src[6*i+0];
  2252. unsigned int g = src[6*i+1];
  2253. unsigned int r = src[6*i+2];
  2254. unsigned int Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
  2255. unsigned int V = ((RV*r + GV*g + BV*b)>>RGB2YUV_SHIFT) + 128;
  2256. unsigned int U = ((RU*r + GU*g + BU*b)>>RGB2YUV_SHIFT) + 128;
  2257. udst[i] = U;
  2258. vdst[i] = V;
  2259. ydst[2*i] = Y;
  2260. b = src[6*i+3];
  2261. g = src[6*i+4];
  2262. r = src[6*i+5];
  2263. Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
  2264. ydst[2*i+1] = Y;
  2265. }
  2266. ydst += lumStride;
  2267. src += srcStride;
  2268. for (i=0; i<chromWidth; i++)
  2269. {
  2270. unsigned int b = src[6*i+0];
  2271. unsigned int g = src[6*i+1];
  2272. unsigned int r = src[6*i+2];
  2273. unsigned int Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
  2274. ydst[2*i] = Y;
  2275. b = src[6*i+3];
  2276. g = src[6*i+4];
  2277. r = src[6*i+5];
  2278. Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
  2279. ydst[2*i+1] = Y;
  2280. }
  2281. udst += chromStride;
  2282. vdst += chromStride;
  2283. ydst += lumStride;
  2284. src += srcStride;
  2285. }
  2286. }
  2287. static void RENAME(interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dest,
  2288. long width, long height, long src1Stride,
  2289. long src2Stride, long dstStride){
  2290. long h;
  2291. for (h=0; h < height; h++)
  2292. {
  2293. long w;
  2294. #if HAVE_MMX
  2295. #if HAVE_SSE2
  2296. __asm__(
  2297. "xor %%"REG_a", %%"REG_a" \n\t"
  2298. "1: \n\t"
  2299. PREFETCH" 64(%1, %%"REG_a") \n\t"
  2300. PREFETCH" 64(%2, %%"REG_a") \n\t"
  2301. "movdqa (%1, %%"REG_a"), %%xmm0 \n\t"
  2302. "movdqa (%1, %%"REG_a"), %%xmm1 \n\t"
  2303. "movdqa (%2, %%"REG_a"), %%xmm2 \n\t"
  2304. "punpcklbw %%xmm2, %%xmm0 \n\t"
  2305. "punpckhbw %%xmm2, %%xmm1 \n\t"
  2306. "movntdq %%xmm0, (%0, %%"REG_a", 2) \n\t"
  2307. "movntdq %%xmm1, 16(%0, %%"REG_a", 2) \n\t"
  2308. "add $16, %%"REG_a" \n\t"
  2309. "cmp %3, %%"REG_a" \n\t"
  2310. " jb 1b \n\t"
  2311. ::"r"(dest), "r"(src1), "r"(src2), "r" ((x86_reg)width-15)
  2312. : "memory", "%"REG_a""
  2313. );
  2314. #else
  2315. __asm__(
  2316. "xor %%"REG_a", %%"REG_a" \n\t"
  2317. "1: \n\t"
  2318. PREFETCH" 64(%1, %%"REG_a") \n\t"
  2319. PREFETCH" 64(%2, %%"REG_a") \n\t"
  2320. "movq (%1, %%"REG_a"), %%mm0 \n\t"
  2321. "movq 8(%1, %%"REG_a"), %%mm2 \n\t"
  2322. "movq %%mm0, %%mm1 \n\t"
  2323. "movq %%mm2, %%mm3 \n\t"
  2324. "movq (%2, %%"REG_a"), %%mm4 \n\t"
  2325. "movq 8(%2, %%"REG_a"), %%mm5 \n\t"
  2326. "punpcklbw %%mm4, %%mm0 \n\t"
  2327. "punpckhbw %%mm4, %%mm1 \n\t"
  2328. "punpcklbw %%mm5, %%mm2 \n\t"
  2329. "punpckhbw %%mm5, %%mm3 \n\t"
  2330. MOVNTQ" %%mm0, (%0, %%"REG_a", 2) \n\t"
  2331. MOVNTQ" %%mm1, 8(%0, %%"REG_a", 2) \n\t"
  2332. MOVNTQ" %%mm2, 16(%0, %%"REG_a", 2) \n\t"
  2333. MOVNTQ" %%mm3, 24(%0, %%"REG_a", 2) \n\t"
  2334. "add $16, %%"REG_a" \n\t"
  2335. "cmp %3, %%"REG_a" \n\t"
  2336. " jb 1b \n\t"
  2337. ::"r"(dest), "r"(src1), "r"(src2), "r" ((x86_reg)width-15)
  2338. : "memory", "%"REG_a
  2339. );
  2340. #endif
  2341. for (w= (width&(~15)); w < width; w++)
  2342. {
  2343. dest[2*w+0] = src1[w];
  2344. dest[2*w+1] = src2[w];
  2345. }
  2346. #else
  2347. for (w=0; w < width; w++)
  2348. {
  2349. dest[2*w+0] = src1[w];
  2350. dest[2*w+1] = src2[w];
  2351. }
  2352. #endif
  2353. dest += dstStride;
  2354. src1 += src1Stride;
  2355. src2 += src2Stride;
  2356. }
  2357. #if HAVE_MMX
  2358. __asm__(
  2359. EMMS" \n\t"
  2360. SFENCE" \n\t"
  2361. ::: "memory"
  2362. );
  2363. #endif
  2364. }
  2365. static inline void RENAME(vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
  2366. uint8_t *dst1, uint8_t *dst2,
  2367. long width, long height,
  2368. long srcStride1, long srcStride2,
  2369. long dstStride1, long dstStride2)
  2370. {
  2371. x86_reg y;
  2372. long x,w,h;
  2373. w=width/2; h=height/2;
  2374. #if HAVE_MMX
  2375. __asm__ volatile(
  2376. PREFETCH" %0 \n\t"
  2377. PREFETCH" %1 \n\t"
  2378. ::"m"(*(src1+srcStride1)),"m"(*(src2+srcStride2)):"memory");
  2379. #endif
  2380. for (y=0;y<h;y++){
  2381. const uint8_t* s1=src1+srcStride1*(y>>1);
  2382. uint8_t* d=dst1+dstStride1*y;
  2383. x=0;
  2384. #if HAVE_MMX
  2385. for (;x<w-31;x+=32)
  2386. {
  2387. __asm__ volatile(
  2388. PREFETCH" 32%1 \n\t"
  2389. "movq %1, %%mm0 \n\t"
  2390. "movq 8%1, %%mm2 \n\t"
  2391. "movq 16%1, %%mm4 \n\t"
  2392. "movq 24%1, %%mm6 \n\t"
  2393. "movq %%mm0, %%mm1 \n\t"
  2394. "movq %%mm2, %%mm3 \n\t"
  2395. "movq %%mm4, %%mm5 \n\t"
  2396. "movq %%mm6, %%mm7 \n\t"
  2397. "punpcklbw %%mm0, %%mm0 \n\t"
  2398. "punpckhbw %%mm1, %%mm1 \n\t"
  2399. "punpcklbw %%mm2, %%mm2 \n\t"
  2400. "punpckhbw %%mm3, %%mm3 \n\t"
  2401. "punpcklbw %%mm4, %%mm4 \n\t"
  2402. "punpckhbw %%mm5, %%mm5 \n\t"
  2403. "punpcklbw %%mm6, %%mm6 \n\t"
  2404. "punpckhbw %%mm7, %%mm7 \n\t"
  2405. MOVNTQ" %%mm0, %0 \n\t"
  2406. MOVNTQ" %%mm1, 8%0 \n\t"
  2407. MOVNTQ" %%mm2, 16%0 \n\t"
  2408. MOVNTQ" %%mm3, 24%0 \n\t"
  2409. MOVNTQ" %%mm4, 32%0 \n\t"
  2410. MOVNTQ" %%mm5, 40%0 \n\t"
  2411. MOVNTQ" %%mm6, 48%0 \n\t"
  2412. MOVNTQ" %%mm7, 56%0"
  2413. :"=m"(d[2*x])
  2414. :"m"(s1[x])
  2415. :"memory");
  2416. }
  2417. #endif
  2418. for (;x<w;x++) d[2*x]=d[2*x+1]=s1[x];
  2419. }
  2420. for (y=0;y<h;y++){
  2421. const uint8_t* s2=src2+srcStride2*(y>>1);
  2422. uint8_t* d=dst2+dstStride2*y;
  2423. x=0;
  2424. #if HAVE_MMX
  2425. for (;x<w-31;x+=32)
  2426. {
  2427. __asm__ volatile(
  2428. PREFETCH" 32%1 \n\t"
  2429. "movq %1, %%mm0 \n\t"
  2430. "movq 8%1, %%mm2 \n\t"
  2431. "movq 16%1, %%mm4 \n\t"
  2432. "movq 24%1, %%mm6 \n\t"
  2433. "movq %%mm0, %%mm1 \n\t"
  2434. "movq %%mm2, %%mm3 \n\t"
  2435. "movq %%mm4, %%mm5 \n\t"
  2436. "movq %%mm6, %%mm7 \n\t"
  2437. "punpcklbw %%mm0, %%mm0 \n\t"
  2438. "punpckhbw %%mm1, %%mm1 \n\t"
  2439. "punpcklbw %%mm2, %%mm2 \n\t"
  2440. "punpckhbw %%mm3, %%mm3 \n\t"
  2441. "punpcklbw %%mm4, %%mm4 \n\t"
  2442. "punpckhbw %%mm5, %%mm5 \n\t"
  2443. "punpcklbw %%mm6, %%mm6 \n\t"
  2444. "punpckhbw %%mm7, %%mm7 \n\t"
  2445. MOVNTQ" %%mm0, %0 \n\t"
  2446. MOVNTQ" %%mm1, 8%0 \n\t"
  2447. MOVNTQ" %%mm2, 16%0 \n\t"
  2448. MOVNTQ" %%mm3, 24%0 \n\t"
  2449. MOVNTQ" %%mm4, 32%0 \n\t"
  2450. MOVNTQ" %%mm5, 40%0 \n\t"
  2451. MOVNTQ" %%mm6, 48%0 \n\t"
  2452. MOVNTQ" %%mm7, 56%0"
  2453. :"=m"(d[2*x])
  2454. :"m"(s2[x])
  2455. :"memory");
  2456. }
  2457. #endif
  2458. for (;x<w;x++) d[2*x]=d[2*x+1]=s2[x];
  2459. }
  2460. #if HAVE_MMX
  2461. __asm__(
  2462. EMMS" \n\t"
  2463. SFENCE" \n\t"
  2464. ::: "memory"
  2465. );
  2466. #endif
  2467. }
  2468. static inline void RENAME(yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
  2469. uint8_t *dst,
  2470. long width, long height,
  2471. long srcStride1, long srcStride2,
  2472. long srcStride3, long dstStride)
  2473. {
  2474. x86_reg x;
  2475. long y,w,h;
  2476. w=width/2; h=height;
  2477. for (y=0;y<h;y++){
  2478. const uint8_t* yp=src1+srcStride1*y;
  2479. const uint8_t* up=src2+srcStride2*(y>>2);
  2480. const uint8_t* vp=src3+srcStride3*(y>>2);
  2481. uint8_t* d=dst+dstStride*y;
  2482. x=0;
  2483. #if HAVE_MMX
  2484. for (;x<w-7;x+=8)
  2485. {
  2486. __asm__ volatile(
  2487. PREFETCH" 32(%1, %0) \n\t"
  2488. PREFETCH" 32(%2, %0) \n\t"
  2489. PREFETCH" 32(%3, %0) \n\t"
  2490. "movq (%1, %0, 4), %%mm0 \n\t" /* Y0Y1Y2Y3Y4Y5Y6Y7 */
  2491. "movq (%2, %0), %%mm1 \n\t" /* U0U1U2U3U4U5U6U7 */
  2492. "movq (%3, %0), %%mm2 \n\t" /* V0V1V2V3V4V5V6V7 */
  2493. "movq %%mm0, %%mm3 \n\t" /* Y0Y1Y2Y3Y4Y5Y6Y7 */
  2494. "movq %%mm1, %%mm4 \n\t" /* U0U1U2U3U4U5U6U7 */
  2495. "movq %%mm2, %%mm5 \n\t" /* V0V1V2V3V4V5V6V7 */
  2496. "punpcklbw %%mm1, %%mm1 \n\t" /* U0U0 U1U1 U2U2 U3U3 */
  2497. "punpcklbw %%mm2, %%mm2 \n\t" /* V0V0 V1V1 V2V2 V3V3 */
  2498. "punpckhbw %%mm4, %%mm4 \n\t" /* U4U4 U5U5 U6U6 U7U7 */
  2499. "punpckhbw %%mm5, %%mm5 \n\t" /* V4V4 V5V5 V6V6 V7V7 */
  2500. "movq %%mm1, %%mm6 \n\t"
  2501. "punpcklbw %%mm2, %%mm1 \n\t" /* U0V0 U0V0 U1V1 U1V1*/
  2502. "punpcklbw %%mm1, %%mm0 \n\t" /* Y0U0 Y1V0 Y2U0 Y3V0*/
  2503. "punpckhbw %%mm1, %%mm3 \n\t" /* Y4U1 Y5V1 Y6U1 Y7V1*/
  2504. MOVNTQ" %%mm0, (%4, %0, 8) \n\t"
  2505. MOVNTQ" %%mm3, 8(%4, %0, 8) \n\t"
  2506. "punpckhbw %%mm2, %%mm6 \n\t" /* U2V2 U2V2 U3V3 U3V3*/
  2507. "movq 8(%1, %0, 4), %%mm0 \n\t"
  2508. "movq %%mm0, %%mm3 \n\t"
  2509. "punpcklbw %%mm6, %%mm0 \n\t" /* Y U2 Y V2 Y U2 Y V2*/
  2510. "punpckhbw %%mm6, %%mm3 \n\t" /* Y U3 Y V3 Y U3 Y V3*/
  2511. MOVNTQ" %%mm0, 16(%4, %0, 8) \n\t"
  2512. MOVNTQ" %%mm3, 24(%4, %0, 8) \n\t"
  2513. "movq %%mm4, %%mm6 \n\t"
  2514. "movq 16(%1, %0, 4), %%mm0 \n\t"
  2515. "movq %%mm0, %%mm3 \n\t"
  2516. "punpcklbw %%mm5, %%mm4 \n\t"
  2517. "punpcklbw %%mm4, %%mm0 \n\t" /* Y U4 Y V4 Y U4 Y V4*/
  2518. "punpckhbw %%mm4, %%mm3 \n\t" /* Y U5 Y V5 Y U5 Y V5*/
  2519. MOVNTQ" %%mm0, 32(%4, %0, 8) \n\t"
  2520. MOVNTQ" %%mm3, 40(%4, %0, 8) \n\t"
  2521. "punpckhbw %%mm5, %%mm6 \n\t"
  2522. "movq 24(%1, %0, 4), %%mm0 \n\t"
  2523. "movq %%mm0, %%mm3 \n\t"
  2524. "punpcklbw %%mm6, %%mm0 \n\t" /* Y U6 Y V6 Y U6 Y V6*/
  2525. "punpckhbw %%mm6, %%mm3 \n\t" /* Y U7 Y V7 Y U7 Y V7*/
  2526. MOVNTQ" %%mm0, 48(%4, %0, 8) \n\t"
  2527. MOVNTQ" %%mm3, 56(%4, %0, 8) \n\t"
  2528. : "+r" (x)
  2529. : "r"(yp), "r" (up), "r"(vp), "r"(d)
  2530. :"memory");
  2531. }
  2532. #endif
  2533. for (; x<w; x++)
  2534. {
  2535. const long x2 = x<<2;
  2536. d[8*x+0] = yp[x2];
  2537. d[8*x+1] = up[x];
  2538. d[8*x+2] = yp[x2+1];
  2539. d[8*x+3] = vp[x];
  2540. d[8*x+4] = yp[x2+2];
  2541. d[8*x+5] = up[x];
  2542. d[8*x+6] = yp[x2+3];
  2543. d[8*x+7] = vp[x];
  2544. }
  2545. }
  2546. #if HAVE_MMX
  2547. __asm__(
  2548. EMMS" \n\t"
  2549. SFENCE" \n\t"
  2550. ::: "memory"
  2551. );
  2552. #endif
  2553. }
  2554. static void RENAME(extract_even)(const uint8_t *src, uint8_t *dst, x86_reg count)
  2555. {
  2556. dst += count;
  2557. src += 2*count;
  2558. count= - count;
  2559. #if HAVE_MMX
  2560. if(count <= -16){
  2561. count += 15;
  2562. __asm__ volatile(
  2563. "pcmpeqw %%mm7, %%mm7 \n\t"
  2564. "psrlw $8, %%mm7 \n\t"
  2565. "1: \n\t"
  2566. "movq -30(%1, %0, 2), %%mm0 \n\t"
  2567. "movq -22(%1, %0, 2), %%mm1 \n\t"
  2568. "movq -14(%1, %0, 2), %%mm2 \n\t"
  2569. "movq -6(%1, %0, 2), %%mm3 \n\t"
  2570. "pand %%mm7, %%mm0 \n\t"
  2571. "pand %%mm7, %%mm1 \n\t"
  2572. "pand %%mm7, %%mm2 \n\t"
  2573. "pand %%mm7, %%mm3 \n\t"
  2574. "packuswb %%mm1, %%mm0 \n\t"
  2575. "packuswb %%mm3, %%mm2 \n\t"
  2576. MOVNTQ" %%mm0,-15(%2, %0) \n\t"
  2577. MOVNTQ" %%mm2,- 7(%2, %0) \n\t"
  2578. "add $16, %0 \n\t"
  2579. " js 1b \n\t"
  2580. : "+r"(count)
  2581. : "r"(src), "r"(dst)
  2582. );
  2583. count -= 15;
  2584. }
  2585. #endif
  2586. while(count<0){
  2587. dst[count]= src[2*count];
  2588. count++;
  2589. }
  2590. }
  2591. static void RENAME(extract_even2)(const uint8_t *src, uint8_t *dst0, uint8_t *dst1, x86_reg count)
  2592. {
  2593. dst0+= count;
  2594. dst1+= count;
  2595. src += 4*count;
  2596. count= - count;
  2597. #if HAVE_MMX
  2598. if(count <= -8){
  2599. count += 7;
  2600. __asm__ volatile(
  2601. "pcmpeqw %%mm7, %%mm7 \n\t"
  2602. "psrlw $8, %%mm7 \n\t"
  2603. "1: \n\t"
  2604. "movq -28(%1, %0, 4), %%mm0 \n\t"
  2605. "movq -20(%1, %0, 4), %%mm1 \n\t"
  2606. "movq -12(%1, %0, 4), %%mm2 \n\t"
  2607. "movq -4(%1, %0, 4), %%mm3 \n\t"
  2608. "pand %%mm7, %%mm0 \n\t"
  2609. "pand %%mm7, %%mm1 \n\t"
  2610. "pand %%mm7, %%mm2 \n\t"
  2611. "pand %%mm7, %%mm3 \n\t"
  2612. "packuswb %%mm1, %%mm0 \n\t"
  2613. "packuswb %%mm3, %%mm2 \n\t"
  2614. "movq %%mm0, %%mm1 \n\t"
  2615. "movq %%mm2, %%mm3 \n\t"
  2616. "psrlw $8, %%mm0 \n\t"
  2617. "psrlw $8, %%mm2 \n\t"
  2618. "pand %%mm7, %%mm1 \n\t"
  2619. "pand %%mm7, %%mm3 \n\t"
  2620. "packuswb %%mm2, %%mm0 \n\t"
  2621. "packuswb %%mm3, %%mm1 \n\t"
  2622. MOVNTQ" %%mm0,- 7(%3, %0) \n\t"
  2623. MOVNTQ" %%mm1,- 7(%2, %0) \n\t"
  2624. "add $8, %0 \n\t"
  2625. " js 1b \n\t"
  2626. : "+r"(count)
  2627. : "r"(src), "r"(dst0), "r"(dst1)
  2628. );
  2629. count -= 7;
  2630. }
  2631. #endif
  2632. while(count<0){
  2633. dst0[count]= src[4*count+0];
  2634. dst1[count]= src[4*count+2];
  2635. count++;
  2636. }
  2637. }
  2638. static void RENAME(extract_even2avg)(const uint8_t *src0, const uint8_t *src1, uint8_t *dst0, uint8_t *dst1, x86_reg count)
  2639. {
  2640. dst0 += count;
  2641. dst1 += count;
  2642. src0 += 4*count;
  2643. src1 += 4*count;
  2644. count= - count;
  2645. #ifdef PAVGB
  2646. if(count <= -8){
  2647. count += 7;
  2648. __asm__ volatile(
  2649. "pcmpeqw %%mm7, %%mm7 \n\t"
  2650. "psrlw $8, %%mm7 \n\t"
  2651. "1: \n\t"
  2652. "movq -28(%1, %0, 4), %%mm0 \n\t"
  2653. "movq -20(%1, %0, 4), %%mm1 \n\t"
  2654. "movq -12(%1, %0, 4), %%mm2 \n\t"
  2655. "movq -4(%1, %0, 4), %%mm3 \n\t"
  2656. PAVGB" -28(%2, %0, 4), %%mm0 \n\t"
  2657. PAVGB" -20(%2, %0, 4), %%mm1 \n\t"
  2658. PAVGB" -12(%2, %0, 4), %%mm2 \n\t"
  2659. PAVGB" - 4(%2, %0, 4), %%mm3 \n\t"
  2660. "pand %%mm7, %%mm0 \n\t"
  2661. "pand %%mm7, %%mm1 \n\t"
  2662. "pand %%mm7, %%mm2 \n\t"
  2663. "pand %%mm7, %%mm3 \n\t"
  2664. "packuswb %%mm1, %%mm0 \n\t"
  2665. "packuswb %%mm3, %%mm2 \n\t"
  2666. "movq %%mm0, %%mm1 \n\t"
  2667. "movq %%mm2, %%mm3 \n\t"
  2668. "psrlw $8, %%mm0 \n\t"
  2669. "psrlw $8, %%mm2 \n\t"
  2670. "pand %%mm7, %%mm1 \n\t"
  2671. "pand %%mm7, %%mm3 \n\t"
  2672. "packuswb %%mm2, %%mm0 \n\t"
  2673. "packuswb %%mm3, %%mm1 \n\t"
  2674. MOVNTQ" %%mm0,- 7(%4, %0) \n\t"
  2675. MOVNTQ" %%mm1,- 7(%3, %0) \n\t"
  2676. "add $8, %0 \n\t"
  2677. " js 1b \n\t"
  2678. : "+r"(count)
  2679. : "r"(src0), "r"(src1), "r"(dst0), "r"(dst1)
  2680. );
  2681. count -= 7;
  2682. }
  2683. #endif
  2684. while(count<0){
  2685. dst0[count]= (src0[4*count+0]+src1[4*count+0])>>1;
  2686. dst1[count]= (src0[4*count+2]+src1[4*count+2])>>1;
  2687. count++;
  2688. }
  2689. }
  2690. static void RENAME(extract_odd2)(const uint8_t *src, uint8_t *dst0, uint8_t *dst1, x86_reg count)
  2691. {
  2692. dst0+= count;
  2693. dst1+= count;
  2694. src += 4*count;
  2695. count= - count;
  2696. #if HAVE_MMX
  2697. if(count <= -8){
  2698. count += 7;
  2699. __asm__ volatile(
  2700. "pcmpeqw %%mm7, %%mm7 \n\t"
  2701. "psrlw $8, %%mm7 \n\t"
  2702. "1: \n\t"
  2703. "movq -28(%1, %0, 4), %%mm0 \n\t"
  2704. "movq -20(%1, %0, 4), %%mm1 \n\t"
  2705. "movq -12(%1, %0, 4), %%mm2 \n\t"
  2706. "movq -4(%1, %0, 4), %%mm3 \n\t"
  2707. "psrlw $8, %%mm0 \n\t"
  2708. "psrlw $8, %%mm1 \n\t"
  2709. "psrlw $8, %%mm2 \n\t"
  2710. "psrlw $8, %%mm3 \n\t"
  2711. "packuswb %%mm1, %%mm0 \n\t"
  2712. "packuswb %%mm3, %%mm2 \n\t"
  2713. "movq %%mm0, %%mm1 \n\t"
  2714. "movq %%mm2, %%mm3 \n\t"
  2715. "psrlw $8, %%mm0 \n\t"
  2716. "psrlw $8, %%mm2 \n\t"
  2717. "pand %%mm7, %%mm1 \n\t"
  2718. "pand %%mm7, %%mm3 \n\t"
  2719. "packuswb %%mm2, %%mm0 \n\t"
  2720. "packuswb %%mm3, %%mm1 \n\t"
  2721. MOVNTQ" %%mm0,- 7(%3, %0) \n\t"
  2722. MOVNTQ" %%mm1,- 7(%2, %0) \n\t"
  2723. "add $8, %0 \n\t"
  2724. " js 1b \n\t"
  2725. : "+r"(count)
  2726. : "r"(src), "r"(dst0), "r"(dst1)
  2727. );
  2728. count -= 7;
  2729. }
  2730. #endif
  2731. src++;
  2732. while(count<0){
  2733. dst0[count]= src[4*count+0];
  2734. dst1[count]= src[4*count+2];
  2735. count++;
  2736. }
  2737. }
  2738. static void RENAME(extract_odd2avg)(const uint8_t *src0, const uint8_t *src1, uint8_t *dst0, uint8_t *dst1, x86_reg count)
  2739. {
  2740. dst0 += count;
  2741. dst1 += count;
  2742. src0 += 4*count;
  2743. src1 += 4*count;
  2744. count= - count;
  2745. #ifdef PAVGB
  2746. if(count <= -8){
  2747. count += 7;
  2748. __asm__ volatile(
  2749. "pcmpeqw %%mm7, %%mm7 \n\t"
  2750. "psrlw $8, %%mm7 \n\t"
  2751. "1: \n\t"
  2752. "movq -28(%1, %0, 4), %%mm0 \n\t"
  2753. "movq -20(%1, %0, 4), %%mm1 \n\t"
  2754. "movq -12(%1, %0, 4), %%mm2 \n\t"
  2755. "movq -4(%1, %0, 4), %%mm3 \n\t"
  2756. PAVGB" -28(%2, %0, 4), %%mm0 \n\t"
  2757. PAVGB" -20(%2, %0, 4), %%mm1 \n\t"
  2758. PAVGB" -12(%2, %0, 4), %%mm2 \n\t"
  2759. PAVGB" - 4(%2, %0, 4), %%mm3 \n\t"
  2760. "psrlw $8, %%mm0 \n\t"
  2761. "psrlw $8, %%mm1 \n\t"
  2762. "psrlw $8, %%mm2 \n\t"
  2763. "psrlw $8, %%mm3 \n\t"
  2764. "packuswb %%mm1, %%mm0 \n\t"
  2765. "packuswb %%mm3, %%mm2 \n\t"
  2766. "movq %%mm0, %%mm1 \n\t"
  2767. "movq %%mm2, %%mm3 \n\t"
  2768. "psrlw $8, %%mm0 \n\t"
  2769. "psrlw $8, %%mm2 \n\t"
  2770. "pand %%mm7, %%mm1 \n\t"
  2771. "pand %%mm7, %%mm3 \n\t"
  2772. "packuswb %%mm2, %%mm0 \n\t"
  2773. "packuswb %%mm3, %%mm1 \n\t"
  2774. MOVNTQ" %%mm0,- 7(%4, %0) \n\t"
  2775. MOVNTQ" %%mm1,- 7(%3, %0) \n\t"
  2776. "add $8, %0 \n\t"
  2777. " js 1b \n\t"
  2778. : "+r"(count)
  2779. : "r"(src0), "r"(src1), "r"(dst0), "r"(dst1)
  2780. );
  2781. count -= 7;
  2782. }
  2783. #endif
  2784. src0++;
  2785. src1++;
  2786. while(count<0){
  2787. dst0[count]= (src0[4*count+0]+src1[4*count+0])>>1;
  2788. dst1[count]= (src0[4*count+2]+src1[4*count+2])>>1;
  2789. count++;
  2790. }
  2791. }
  2792. static void RENAME(yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
  2793. long width, long height,
  2794. long lumStride, long chromStride, long srcStride)
  2795. {
  2796. long y;
  2797. const long chromWidth= -((-width)>>1);
  2798. for (y=0; y<height; y++){
  2799. RENAME(extract_even)(src, ydst, width);
  2800. if(y&1){
  2801. RENAME(extract_odd2avg)(src-srcStride, src, udst, vdst, chromWidth);
  2802. udst+= chromStride;
  2803. vdst+= chromStride;
  2804. }
  2805. src += srcStride;
  2806. ydst+= lumStride;
  2807. }
  2808. #if HAVE_MMX
  2809. __asm__(
  2810. EMMS" \n\t"
  2811. SFENCE" \n\t"
  2812. ::: "memory"
  2813. );
  2814. #endif
  2815. }
  2816. static void RENAME(yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
  2817. long width, long height,
  2818. long lumStride, long chromStride, long srcStride)
  2819. {
  2820. long y;
  2821. const long chromWidth= -((-width)>>1);
  2822. for (y=0; y<height; y++){
  2823. RENAME(extract_even)(src, ydst, width);
  2824. RENAME(extract_odd2)(src, udst, vdst, chromWidth);
  2825. src += srcStride;
  2826. ydst+= lumStride;
  2827. udst+= chromStride;
  2828. vdst+= chromStride;
  2829. }
  2830. #if HAVE_MMX
  2831. __asm__(
  2832. EMMS" \n\t"
  2833. SFENCE" \n\t"
  2834. ::: "memory"
  2835. );
  2836. #endif
  2837. }
  2838. static void RENAME(uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
  2839. long width, long height,
  2840. long lumStride, long chromStride, long srcStride)
  2841. {
  2842. long y;
  2843. const long chromWidth= -((-width)>>1);
  2844. for (y=0; y<height; y++){
  2845. RENAME(extract_even)(src+1, ydst, width);
  2846. if(y&1){
  2847. RENAME(extract_even2avg)(src-srcStride, src, udst, vdst, chromWidth);
  2848. udst+= chromStride;
  2849. vdst+= chromStride;
  2850. }
  2851. src += srcStride;
  2852. ydst+= lumStride;
  2853. }
  2854. #if HAVE_MMX
  2855. __asm__(
  2856. EMMS" \n\t"
  2857. SFENCE" \n\t"
  2858. ::: "memory"
  2859. );
  2860. #endif
  2861. }
  2862. static void RENAME(uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
  2863. long width, long height,
  2864. long lumStride, long chromStride, long srcStride)
  2865. {
  2866. long y;
  2867. const long chromWidth= -((-width)>>1);
  2868. for (y=0; y<height; y++){
  2869. RENAME(extract_even)(src+1, ydst, width);
  2870. RENAME(extract_even2)(src, udst, vdst, chromWidth);
  2871. src += srcStride;
  2872. ydst+= lumStride;
  2873. udst+= chromStride;
  2874. vdst+= chromStride;
  2875. }
  2876. #if HAVE_MMX
  2877. __asm__(
  2878. EMMS" \n\t"
  2879. SFENCE" \n\t"
  2880. ::: "memory"
  2881. );
  2882. #endif
  2883. }
  2884. static inline void RENAME(rgb2rgb_init)(void){
  2885. rgb15to16 = RENAME(rgb15to16);
  2886. rgb15tobgr24 = RENAME(rgb15tobgr24);
  2887. rgb15to32 = RENAME(rgb15to32);
  2888. rgb16tobgr24 = RENAME(rgb16tobgr24);
  2889. rgb16to32 = RENAME(rgb16to32);
  2890. rgb16to15 = RENAME(rgb16to15);
  2891. rgb24tobgr16 = RENAME(rgb24tobgr16);
  2892. rgb24tobgr15 = RENAME(rgb24tobgr15);
  2893. rgb24tobgr32 = RENAME(rgb24tobgr32);
  2894. rgb32to16 = RENAME(rgb32to16);
  2895. rgb32to15 = RENAME(rgb32to15);
  2896. rgb32tobgr24 = RENAME(rgb32tobgr24);
  2897. rgb24to15 = RENAME(rgb24to15);
  2898. rgb24to16 = RENAME(rgb24to16);
  2899. rgb24tobgr24 = RENAME(rgb24tobgr24);
  2900. rgb32tobgr32 = RENAME(rgb32tobgr32);
  2901. rgb32tobgr16 = RENAME(rgb32tobgr16);
  2902. rgb32tobgr15 = RENAME(rgb32tobgr15);
  2903. yv12toyuy2 = RENAME(yv12toyuy2);
  2904. yv12touyvy = RENAME(yv12touyvy);
  2905. yuv422ptoyuy2 = RENAME(yuv422ptoyuy2);
  2906. yuv422ptouyvy = RENAME(yuv422ptouyvy);
  2907. yuy2toyv12 = RENAME(yuy2toyv12);
  2908. // yvu9toyv12 = RENAME(yvu9toyv12);
  2909. planar2x = RENAME(planar2x);
  2910. rgb24toyv12 = RENAME(rgb24toyv12);
  2911. interleaveBytes = RENAME(interleaveBytes);
  2912. vu9_to_vu12 = RENAME(vu9_to_vu12);
  2913. yvu9_to_yuy2 = RENAME(yvu9_to_yuy2);
  2914. uyvytoyuv420 = RENAME(uyvytoyuv420);
  2915. uyvytoyuv422 = RENAME(uyvytoyuv422);
  2916. yuyvtoyuv420 = RENAME(yuyvtoyuv420);
  2917. yuyvtoyuv422 = RENAME(yuyvtoyuv422);
  2918. }