lkml.org 
[lkml]   [2015]   [Feb]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] lib/int_sqrt.c: Optimize square root function
From
Date
On Mon, 2015-02-02 at 09:12 -0800, Anshul Garg wrote:
> From: Anshul Garg <aksgarg1989@gmail.com>
>
> Unnecessary instructions are executing even though m is
> greater than x so added logic to make m less than equal to
> x before performing these operations.
>
> Signed-off-by: Anshul Garg <aksgarg1989@gmail.com>
> ---
> lib/int_sqrt.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/lib/int_sqrt.c b/lib/int_sqrt.c
[]
> @@ -22,6 +22,9 @@ unsigned long int_sqrt(unsigned long x)
> return x;
>
> m = 1UL << (BITS_PER_LONG - 2);
> +
> + while (m > x)
> + m >>= 2;

Perhaps removing the while and using fls(x) would be better.

Perhaps something like:

m = 1UL << min(sizeof(unsigned long) == sizeof(u64) ?
fls64(x) : fls(x),
BITS_PER_LONG - 2);

> while (m != 0) {
> b = y + m;
> y >>= 1;





\
 
 \ /
  Last update: 2015-02-02 20:41    [W:0.114 / U:0.960 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site