[PATCH] savage: Avoid unnecessary float calculation in video display

walter harms wharms at bfs.de
Sat Sep 17 04:03:10 PDT 2011



Am 17.09.2011 11:58, schrieb Tormod Volden:
> From: Tormod Volden <debian.tormod at gmail.com>
> 
> There is no reason to do the division using floats as long as
> the result is an integer and there is no risk of intermediate
> overflow.
> 
> This is in the code for "Old" chipsets. Integer division was already
> used in the parallel code for "New" chipsets.
> 
> Also fixed up the whitespace in both blocks.
> 
> Signed-off-by: Tormod Volden <debian.tormod at gmail.com>
> ---
>  src/savage_video.c |   23 +++++++++++------------
>  1 files changed, 11 insertions(+), 12 deletions(-)
> 
> diff --git a/src/savage_video.c b/src/savage_video.c
> index 7d571ad..5f08a18 100644
> --- a/src/savage_video.c
> +++ b/src/savage_video.c
> @@ -1503,16 +1503,15 @@ SavageDisplayVideoOld(
>        }
>  
>      if (S3_MOBILE_TWISTER_SERIES(psav->Chipset)
> -        && psav->FPExpansion) {
> -        drw_w = (((float)(drw_w * psav->XExp1)/(float)psav->XExp2)+1);
> -        drw_h = (float)(drw_h * psav->YExp1)/(float)psav->YExp2+1;
> -        dstBox->x1 = (float)(dstBox->x1 * psav->XExp1)/(float)psav->XExp2;
> -        dstBox->y1 = (float)(dstBox->y1 * psav->YExp1)/(float)psav->YExp2;
> +	&& psav->FPExpansion) {
> +	drw_w = (drw_w * psav->XExp1) / psav->XExp2 + 1;
> +	drw_h = (drw_h * psav->YExp1) / psav->YExp2 + 1;

to improve readability i would suggest a writing like this:

	scale=  psav->XExp1/psav->XExp2;
	drw_w = 1+  drw_w *scale ;
	drw_h = 1+  drw_h *scale ;

the price of float is small these days  ...

re,
 wh

> +	dstBox->x1 = (dstBox->x1 * psav->XExp1) / psav->XExp2;
> +	dstBox->y1 = (dstBox->y1 * psav->YExp1) / psav->YExp2;
>  	dstBox->x2 = (dstBox->x2 * psav->XExp1) / psav->XExp2;
>  	dstBox->y2 = (dstBox->y2 * psav->YExp1) / psav->YExp2;
> -
> -        dstBox->x1 += psav->displayXoffset;
> -        dstBox->y1 += psav->displayYoffset;
> +	dstBox->x1 += psav->displayXoffset;
> +	dstBox->y1 += psav->displayYoffset;
>  	dstBox->x2 += psav->displayXoffset;
>  	dstBox->y2 += psav->displayYoffset;
>      }
> @@ -1668,10 +1667,10 @@ SavageDisplayVideoNew(
>  	    !psav->CrtOnly &&
>  	    !psav->TvOn) 
>      {
> -	drw_w = (drw_w * psav->XExp1)/psav->XExp2 + 1;
> -	drw_h = (drw_h * psav->YExp1)/psav->YExp2 + 1;
> -	dstBox->x1 = (dstBox->x1 * psav->XExp1)/psav->XExp2;
> -	dstBox->y1 = (dstBox->y1 * psav->YExp1)/psav->YExp2;
> +	drw_w = (drw_w * psav->XExp1) / psav->XExp2 + 1;
> +	drw_h = (drw_h * psav->YExp1) / psav->YExp2 + 1;
> +	dstBox->x1 = (dstBox->x1 * psav->XExp1) / psav->XExp2;
> +	dstBox->y1 = (dstBox->y1 * psav->YExp1) / psav->YExp2;
>  	dstBox->x2 = (dstBox->x2 * psav->XExp1) / psav->XExp2;
>  	dstBox->y2 = (dstBox->y2 * psav->YExp1) / psav->YExp2;
>  	dstBox->x1 += psav->displayXoffset;


More information about the xorg-devel mailing list