From: bernie Date: Sat, 27 May 2006 17:17:34 +0000 (+0000) Subject: Optimize away divisions in RAST_ADDR/MASK macros. X-Git-Tag: 1.0.0~605 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=31b4a3ad1e2824fd9beb298695dec7fb34ee6130;p=bertos.git Optimize away divisions in RAST_ADDR/MASK macros. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@636 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/gfx/gfx.h b/gfx/gfx.h index be008f02..5fe1e300 100755 --- a/gfx/gfx.h +++ b/gfx/gfx.h @@ -14,6 +14,9 @@ /*#* *#* $Log$ + *#* Revision 1.16 2006/05/27 17:17:34 bernie + *#* Optimize away divisions in RAST_ADDR/MASK macros. + *#* *#* Revision 1.15 2006/05/25 23:35:40 bernie *#* Cleanup. *#* @@ -78,6 +81,7 @@ EXTERN_C_BEGIN /*! Common type for coordinates expressed in pixel units */ typedef int coord_t; +typedef unsigned int ucoord_t; #if CONFIG_GFX_VCOORDS /*! Common type for coordinates expressed in logical units */ @@ -126,8 +130,11 @@ typedef struct Rect { coord_t xmin, ymin, xmax, ymax; } Rect; /* Fwd decl */ struct Font; -/*! +/** * Control structure to draw in a bitmap + * + * \todo For better ortogonality, split this structure into + * an Image and a plain drawing context called Painter. */ typedef struct Bitmap { diff --git a/gfx/gfx_p.h b/gfx/gfx_p.h index 5b483ab1..a599a8aa 100755 --- a/gfx/gfx_p.h +++ b/gfx/gfx_p.h @@ -15,6 +15,9 @@ /*#* *#* $Log$ + *#* Revision 1.6 2006/05/27 17:17:34 bernie + *#* Optimize away divisions in RAST_ADDR/MASK macros. + *#* *#* Revision 1.5 2006/05/25 23:35:40 bernie *#* Cleanup. *#* @@ -35,16 +38,23 @@ #ifndef GFX_GFX_P_H #define GFX_GFX_P_H +#include #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB - #define RAST_ADDR(raster, x, y, stride) ((raster) + (y) * (stride) + (x) / 8) - #define RAST_MASK(raster, x, y) (1 << (7 - (x) % 8)) + /* We use ucoord_t to let the compiler optimize away the division/modulo. */ + #define RAST_ADDR(raster, x, y, stride) \ + ((raster) + (ucoord_t)(y) * (ucoord_t)(stride) + (ucoord_t)(x) / 8) + #define RAST_MASK(raster, x, y) \ + (1 << (7 - (ucoord_t)(x) % 8)) #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB - #define RAST_ADDR(raster, x, y, stride) ((raster) + ((y) / 8) * (stride) + (x)) - #define RAST_MASK(raster, x, y) (1 << ((y) % 8)) + /* We use ucoord_t to let the compiler optimize away the division/modulo. */ + #define RAST_ADDR(raster, x, y, stride) \ + ((raster) + ((ucoord_t)(y) / 8) * (ucoord_t)(stride) + (ucoord_t)(x)) + #define RAST_MASK(raster, x, y) \ + (1 << ((ucoord_t)(y) % 8)) #else #error Unknown value of CONFIG_BITMAP_FMT