[U-Boot] [PATCH v2] ARM: Use do_div() instead of division for "long long".

Guennadi Liakhovetski lg at denx.de
Tue Sep 9 22:55:04 CEST 2008


On Tue, 9 Sep 2008, Wolfgang Denk wrote:

> diff --git a/board/trab/tsc2000.c b/board/trab/tsc2000.c
> index 382a85b..f13a5a9 100644
> --- a/board/trab/tsc2000.c
> +++ b/board/trab/tsc2000.c
> @@ -27,6 +27,7 @@
>  
>  #include <common.h>
>  #include <s3c2400.h>
> +#include <div64.h>
>  #include "tsc2000.h"
>  
>  #include "Pt1000_temp_data.h"
> @@ -332,6 +333,7 @@ void tsc2000_reg_init (void)
>  int tsc2000_interpolate(long value, long data[][2], long *result)
>  {
>  	int i;
> +	unsigned long long val;
>  
>  	/* the data is sorted and the first element is upper
>  	 * limit so we can easily check for out-of-band values
> @@ -347,10 +349,10 @@ int tsc2000_interpolate(long value, long data[][2], long *result)
>  	   result in 'long long'.
>  	*/
>  
> -	*result = data[i-1][1] +
> -		((unsigned long long)(data[i][1] - data[i-1][1])
> -		 * (unsigned long long)(value - data[i-1][0]))
> -		/ (data[i][0] - data[i-1][0]);
> +	val = ((unsigned long long)(data[i][1] - data[i-1][1])
> +		   * (unsigned long long)(value - data[i-1][0]));
> +	do_div(val, (data[i][0] - data[i-1][0]));

Looking at how do_div() is defined, and it handles its parameters 
carefully, one shouldn't need the extra parenthesis here, i.e.,

+	do_div(val, data[i][0] - data[i-1][0]);

should be enough.

> +	*result = data[i-1][1] + val;
>  
>  	return 0;
>  }
> diff --git a/cpu/arm1176/s3c64xx/interrupts.c b/cpu/arm1176/s3c64xx/interrupts.c
> index 8356ae4..e34369f 100644
> --- a/cpu/arm1176/s3c64xx/interrupts.c
> +++ b/cpu/arm1176/s3c64xx/interrupts.c
> @@ -41,6 +41,7 @@
>  #include <common.h>
>  #include <asm/proc-armv/ptrace.h>
>  #include <s3c6400.h>
> +#include <div64.h>
>  
>  static ulong timer_load_val;
>  
> @@ -148,7 +149,9 @@ void reset_timer(void)
>  
>  ulong get_timer_masked(void)
>  {
> -	return get_ticks() / (timer_load_val / (100 * CFG_HZ));
> +	unsigned long long res = get_ticks();
> +	do_div (res, (timer_load_val / (100 * CFG_HZ)));

Same here.

+	do_div (res, timer_load_val / (100 * CFG_HZ));

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.

DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de


More information about the U-Boot mailing list