DirectFB - Home of the pragmatist Roadmap


[directfb-dev] drawstring optimization for rgb16
Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[directfb-dev] drawstring optimization for rgb16



None of my graphics cards supports 15bpp color depth (only 16).  I think
15bpp would make it possible to have only one multiplication in the
inner loop of Sop_a8_set_alphapixel_Dop_rgb15.  Anyway, here is my take
on a slightly faster Sop_a8_set_alphapixel_Dop_rgb16.  I don't
understand why those SET_ALPHA_PIXEL things are done as macros.  grep
shows that they are only used in src/gfx/generic/generic.c, and there
only once each.

Anyway, I decided to leave generic.h alone in my tests and hack around
in generic.c instead.  Thus, this patch is by no means production
quality, although on my box it speeds up the drawstring test in df_dok
from ~34 to ~39.5 MChars/sec.  I did some things that should have
yielded even better performance, yet in reality performance actually
suffered.  That's why the last SET_ALPHA_PIXEL_RGB16 implementation is
"#if 0'ed" away.  Part of the speed-up comes from exploiting the fact
that r,g and b stay the same throughout the loop and moving two
precomputed values out of the loop.  That's why the new macro
implementation should probably stay in generic.c and not go to generic.h
because it uses the precomputed values which are only there in
Sop_a8_set_alphapixel_Dop_rgb16.

Here is the diff against generic.c.  Please test the last version on
powerpc, too.  Maybe it is faster there.  By the way: I also tried
fetching two pixels at a time in the loop (i.e. one 32-bit word instead
of two 16-bit words).  That slowed things down noticeably. :-(

Felix


Index: generic.c
===================================================================
RCS file: /cvs/directfb/DirectFB/src/gfx/generic/generic.c,v
retrieving revision 1.20
diff -u -3 -p -u -r1.20 generic.c
--- generic.c	2001/05/29 15:10:02	1.20
+++ generic.c	2001/06/03 01:54:19
@@ -1325,12 +1325,78 @@ static void Sop_a8_set_alphapixel_Dop_rg
      }
 }
 
+#undef SET_ALPHA_PIXEL_RGB16
+#define SET_ALPHA_PIXEL_RGB16(d,r,g,b,a) \
+     if (a) {\
+          if ((a) == 0xff) {\
+               *(d) = (((r)&0xf8) << 8) | (((g)&0xfc) << 3) | (((b)&0xf8) >> 3);\
+          }\
+          else {\
+               __u32 pixel = *(d);\
+               __u8  s = ((a)>>2)+1;\
+     	       __u8 s1 = 64-s;\
+               \
+     	       pixel = (((((pixel & 0x0000f81f) * s1) + (((((r)&0xf8)<<8) | ((b)>>3)) * s)) & 0x003e07c0) + \
+     	                ((((pixel & 0x000007e0) * s1) +   (((g)<<3)                   * s)) & 0x0001f800)) >> 6;\
+               *(d) = pixel;\
+          }\
+     }
+
+#undef SET_ALPHA_PIXEL_RGB16
+#define SET_ALPHA_PIXEL_RGB16(d,r,g,b,a) \
+     switch (a) {\
+     case 0xff: *(d) = __rb+__g; \
+     case 0: break; \
+     default: {\
+	__u32 pixel = *(d);\
+	__u8  s = ((a)>>2)+1;\
+	register __u32 t1,t2; \
+	t1 = (pixel&0xf81f); t2 = (pixel&0x07e0); \
+	pixel = ((((__rb-t1)*s+(t1<<6)) & 0x003e07c0) + \
+	         ((( __g-t2)*s+(t2<<6)) & 0x0001f800)) >> 6; \
+	*(d) = pixel;\
+      }\
+     }
+
+#if 0
+#undef SET_ALPHA_PIXEL_RGB16
+#define SET_ALPHA_PIXEL_RGB16(d,r,g,b,a) \
+     switch (a) {\
+     case 0xff: *(d) = __rb+__g; \
+     case 0: break; \
+     default: {\
+	__u32 pixel = *(d);\
+	__u8  s = ((a)>>2)+1;\
+	*(d) = pixel + (((((__rb-(pixel&0xf81f))*s) & 0x003e07c0) + \
+	         ((( __g-(pixel&0x07e0))*s) & 0x0001f800)) >> 6); \
+      }\
+     }
+#endif
+
+/* x*s+y*(1-s) == x*s+y-y*s == (x-y)*s+y; */
 static void Sop_a8_set_alphapixel_Dop_rgb16()
 {
      int    w = Dlength;
      __u8  *S = Sop;
      __u16 *D = (__u16*)Dop;
+     __u32 __rb = (((color.r&0xf8)<<8) | ((color.b&0xf8)>>3));
+     __u32 __g = ((color.g&0xfc)<<3);
 
+     while (w>4) {
+	SET_ALPHA_PIXEL_RGB16( D, color.r, color.g, color.b, *S );
+	D++;
+	S++;
+	SET_ALPHA_PIXEL_RGB16( D, color.r, color.g, color.b, *S );
+	D++;
+	S++;
+	SET_ALPHA_PIXEL_RGB16( D, color.r, color.g, color.b, *S );
+	D++;
+	S++;
+	SET_ALPHA_PIXEL_RGB16( D, color.r, color.g, color.b, *S );
+	D++;
+	S++;
+	w-=4;
+     }
      while (w--) {
           SET_ALPHA_PIXEL_RGB16( D, color.r, color.g, color.b, *S );
 


-- 
Info:  To unsubscribe send a mail to listar@directfb.org with 
"unsubscribe directfb-dev" as subject.



Home | Main Index | Thread Index


directfb.org / Development / Old Archives