aboutsummaryrefslogtreecommitdiffstats
path: root/postproc/rgb2rgb.c
diff options
context:
space:
mode:
authorNick Kurshev <nickols_k@mail.ru>2001-11-06 16:21:38 +0000
committerNick Kurshev <nickols_k@mail.ru>2001-11-06 16:21:38 +0000
commit3eb2151c15540bfb77f7adc0dc5772c56a80a46a (patch)
tree1742918c423599c741800871c46cd4f31acc55d6 /postproc/rgb2rgb.c
parent761635727d096a69e816c17a7ef1531aa3f0da9e (diff)
downloadffmpeg-3eb2151c15540bfb77f7adc0dc5772c56a80a46a.tar.gz
optimized rgb24to16 stuff
Originally committed as revision 2741 to svn://svn.mplayerhq.hu/mplayer/trunk/postproc
Diffstat (limited to 'postproc/rgb2rgb.c')
-rw-r--r--postproc/rgb2rgb.c68
1 files changed, 43 insertions, 25 deletions
diff --git a/postproc/rgb2rgb.c b/postproc/rgb2rgb.c
index d38a2a95d1..bb74bbda0c 100644
--- a/postproc/rgb2rgb.c
+++ b/postproc/rgb2rgb.c
@@ -19,6 +19,9 @@ static const uint64_t mask24h __attribute__((aligned(8))) = 0x0000FFFFFF000000U
static const uint64_t mask15b __attribute__((aligned(8))) = 0x001F001F001F001FULL; /* 00000000 00011111 xxB */
static const uint64_t mask15rg __attribute__((aligned(8))) = 0x7FE07FE07FE07FE0ULL; /* 01111111 11100000 RGx */
static const uint64_t mask15s __attribute__((aligned(8))) = 0xFFE0FFE0FFE0FFE0ULL;
+static const uint64_t red_mask __attribute__((aligned(8))) = 0x0000f8000000f800ULL;
+static const uint64_t green_mask __attribute__((aligned(8)))= 0x000007e0000007e0ULL;
+static const uint64_t blue_mask __attribute__((aligned(8))) = 0x0000001f0000001fULL;
#endif
void rgb24to32(const uint8_t *src,uint8_t *dst,unsigned src_size)
@@ -32,9 +35,9 @@ void rgb24to32(const uint8_t *src,uint8_t *dst,unsigned src_size)
end = s + src_size;
#ifdef HAVE_MMX
__asm __volatile(PREFETCH" %0"::"m"(*s):"memory");
- mm_end = (uint8_t*)((((unsigned long)end)/(MMREG_SIZE*2))*(MMREG_SIZE*2));
+ mm_end = (uint8_t*)((((unsigned long)end)/(MMREG_SIZE*4))*(MMREG_SIZE*4));
__asm __volatile("movq %0, %%mm7"::"m"(mask32):"memory");
- if(mm_end == end) mm_end -= MMREG_SIZE*2;
+ if(mm_end == end) mm_end -= MMREG_SIZE*4;
while(s < mm_end)
{
__asm __volatile(
@@ -253,26 +256,24 @@ void rgb32to15(const uint8_t *src, uint8_t *dst, unsigned src_size)
void rgb24to16(const uint8_t *src, uint8_t *dst, unsigned src_size)
{
- unsigned j,i,num_pixels=src_size/3;
+#ifdef HAVE_MMX
+ const uint8_t *s = src;
+ const uint8_t *end,*mm_end;
uint16_t *d = (uint16_t *)dst;
-#if 0/*def HAVE_MMX*/
- unsigned mm_npix;
- const uint64_t mm_fc = 0xFCFCFCFCFCFCFCFCULL, mm_f8 = 0xF8F8F8F8F8F8F8F8ULL;
- mm_npix = ((num_pixels)/(MMREG_SIZE*2))*(MMREG_SIZE*2);
- num_pixels -= mm_npix;
+ end = s + src_size;
+ mm_end = (uint8_t*)((((unsigned long)end)/(MMREG_SIZE*2))*(MMREG_SIZE*2));
__asm __volatile(PREFETCH" %0"::"m"(*src):"memory");
__asm __volatile(
"movq %0, %%mm7\n\t"
"movq %1, %%mm6\n\t"
- ::"m"(mm_fc),"m"(mm_f8));
-
- for(j=0,i=0;j<mm_npix;j+=4,i+=12)
+ ::"m"(red_mask),"m"(green_mask));
+ while(s < mm_end)
{
__asm __volatile(
PREFETCH" 32%1\n\t"
"movd %1, %%mm0\n\t"
- "punpckldq 3%1, %%mm0\n\t"
- "movd 6%1, %%mm3\n\t"
+ "movd 3%1, %%mm3\n\t"
+ "punpckldq 6%1, %%mm0\n\t"
"punpckldq 9%1, %%mm3\n\t"
"movq %%mm0, %%mm1\n\t"
"movq %%mm0, %%mm2\n\t"
@@ -280,23 +281,39 @@ void rgb24to16(const uint8_t *src, uint8_t *dst, unsigned src_size)
"movq %%mm3, %%mm5\n\t"
"psrlq $3, %%mm0\n\t"
"psrlq $3, %%mm3\n\t"
- "pand %%mm7, %%mm1\n\t"
- "pand %%mm7, %%mm4\n\t"
- "psllq $3, %%mm1\n\t"
- "psllq $3, %%mm4\n\t"
- "pand %%mm6, %%mm2\n\t"
- "pand %%mm6, %%mm5\n\t"
- "psllq $8, %%mm2\n\t"
- "psllq $8, %%mm5\n\t"
+ "pand %2, %%mm0\n\t"
+ "pand %2, %%mm3\n\t"
+ "psrlq $5, %%mm1\n\t"
+ "psrlq $5, %%mm4\n\t"
+ "pand %%mm6, %%mm1\n\t"
+ "pand %%mm6, %%mm4\n\t"
+ "psrlq $8, %%mm2\n\t"
+ "psrlq $8, %%mm5\n\t"
+ "pand %%mm7, %%mm2\n\t"
+ "pand %%mm7, %%mm5\n\t"
"por %%mm1, %%mm0\n\t"
- "por %%mm2, %%mm0\n\t"
"por %%mm4, %%mm3\n\t"
+ "por %%mm2, %%mm0\n\t"
"por %%mm5, %%mm3\n\t"
- "punpcklwd %%mm3, %%mm0\n\t"
+ "psllq $16, %%mm3\n\t"
+ "por %%mm3, %%mm0\n\t"
MOVNTQ" %%mm0, %0\n\t"
- :"=m"(d[j]):"m"(src[i]):"memory");
+ :"=m"(*d):"m"(*s),"m"(blue_mask):"memory");
+ d += 4;
+ s += 12;
}
-#endif
+ while(s < end)
+ {
+ const int b= *s++;
+ const int g= *s++;
+ const int r= *s++;
+ *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8);
+ }
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#else
+ unsigned j,i,num_pixels=src_size/3;
+ uint16_t *d = (uint16_t *)dst;
for(i=0,j=0; j<num_pixels; i+=3,j++)
{
const int b= src[i+0];
@@ -305,6 +322,7 @@ void rgb24to16(const uint8_t *src, uint8_t *dst, unsigned src_size)
d[j]= (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8);
}
+#endif
}
void rgb24to15(const uint8_t *src, uint8_t *dst, unsigned src_size)