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.

149 lines
3.0KB

  1. #include <inttypes.h>
  2. #include "../config.h"
  3. #include "rgb2rgb.h"
  4. #include "mmx.h"
  5. #ifdef HAVE_3DNOW
  6. #define PREFETCH "prefetch"
  7. #define PREFETCHW "prefetchw"
  8. #elif HAVE_MMX2
  9. #define PREFETCH "prefetchnta"
  10. #define PREFETCHW "prefetcht0"
  11. #endif
  12. #ifdef HAVE_3DNOW
  13. #define EMMS "femms"
  14. #else
  15. #define EMMS "emms"
  16. #endif
  17. #ifdef HAVE_MMX2
  18. #define MOVNTQ "movntq"
  19. #else
  20. #define MOVNTQ "movq"
  21. #endif
  22. void rgb24to32(uint8_t *src,uint8_t *dst,uint32_t src_size)
  23. {
  24. uint8_t *dest = dst;
  25. uint8_t *s = src;
  26. uint8_t *end;
  27. #ifdef HAVE_MMX
  28. const uint64_t mask32 = 0x00FFFFFF00FFFFFFULL;
  29. uint8_t *mm_end;
  30. #endif
  31. end = s + src_size;
  32. #ifdef HAVE_MMX
  33. #ifdef PREFETCH
  34. __asm __volatile(
  35. PREFETCH" %0\n\t"
  36. PREFETCH" 64%0\n\t"
  37. PREFETCHW" %1\n\t"
  38. PREFETCHW" 64%1\n\t"::"m"(*s),"m"(*dest):"memory");
  39. #endif
  40. mm_end = (uint8_t*)((((unsigned long)end)/16)*16);
  41. __asm __volatile("movq %0, %%mm7"::"m"(mask32):"memory");
  42. while(s < mm_end)
  43. {
  44. #ifdef PREFETCH
  45. __asm __volatile(
  46. PREFETCH" 128%0\n\t"
  47. PREFETCHW" 128%1"
  48. ::"m"(*s),"m"(*dest):"memory");
  49. #endif
  50. __asm __volatile(
  51. "movd %1, %%mm0\n\t"
  52. "movd 3%1, %%mm1\n\t"
  53. "movd 6%1, %%mm2\n\t"
  54. "movd 9%1, %%mm3\n\t"
  55. "punpckldq %%mm1, %%mm0\n\t"
  56. "punpckldq %%mm3, %%mm2\n\t"
  57. "pand %%mm7, %%mm0\n\t"
  58. "pand %%mm7, %%mm2\n\t"
  59. MOVNTQ" %%mm0, %0\n\t"
  60. MOVNTQ" %%mm2, 8%0"
  61. :"=m"(*dest)
  62. :"m"(*s)
  63. :"memory");
  64. dest += 16;
  65. s += 12;
  66. }
  67. __asm __volatile(EMMS:::"memory");
  68. #endif
  69. while(s < end)
  70. {
  71. *dest++ = *s++;
  72. *dest++ = *s++;
  73. *dest++ = *s++;
  74. *dest++ = 0;
  75. }
  76. }
  77. /* TODO: MMX optimization */
  78. void rgb32to24(uint8_t *src,uint8_t *dst,uint32_t src_size)
  79. {
  80. uint8_t *dest = dst;
  81. uint8_t *s = src;
  82. uint8_t *end;
  83. end = s + src_size;
  84. while(s < end)
  85. {
  86. *dest++ = *s++;
  87. *dest++ = *s++;
  88. *dest++ = *s++;
  89. s++;
  90. }
  91. }
  92. /* Original by Strepto/Astral
  93. ported to gcc & bugfixed : A'rpi */
  94. void rgb15to16(uint8_t *src,uint8_t *dst,uint32_t src_size)
  95. {
  96. #ifdef HAVE_MMX
  97. static uint64_t mask_b = 0x001F001F001F001FLL; // 00000000 00011111 xxB
  98. static uint64_t mask_rg = 0x7FE07FE07FE07FE0LL; // 01111111 11100000 RGx
  99. register char* s=src+src_size;
  100. register char* d=dst+src_size;
  101. register int offs=-src_size;
  102. movq_m2r (mask_b, mm4);
  103. movq_m2r (mask_rg, mm5);
  104. while(offs<0){
  105. movq_m2r (*(s+offs), mm0);
  106. movq_r2r (mm0, mm1);
  107. movq_m2r (*(s+8+offs), mm2);
  108. movq_r2r (mm2, mm3);
  109. pand_r2r (mm4, mm0);
  110. pand_r2r (mm5, mm1);
  111. psllq_i2r(1,mm1);
  112. pand_r2r (mm4, mm2);
  113. pand_r2r (mm5, mm3);
  114. por_r2r (mm1, mm0);
  115. psllq_i2r(1,mm3);
  116. movq_r2m (mm0,*(d+offs));
  117. por_r2r (mm3,mm2);
  118. movq_r2m (mm2,*(d+8+offs));
  119. offs+=16;
  120. }
  121. emms();
  122. #else
  123. uint16_t *s1=( uint16_t * )src;
  124. uint16_t *d1=( uint16_t * )dst;
  125. uint16_t *e=((uint8_t *)s1)+src_size;
  126. while( s1<e ){
  127. register int x=*( s1++ );
  128. /* rrrrrggggggbbbbb
  129. 0rrrrrgggggbbbbb
  130. 0111 1111 1110 0000=0x7FE0
  131. 00000000000001 1111=0x001F */
  132. *( d1++ )=( x&0x001F )|( ( x&0x7FE0 )<<1 );
  133. }
  134. #endif
  135. }