diff options
| author | Frederic Weisbecker <fweisbec@gmail.com> | 2013-05-02 17:37:49 +0200 | 
|---|---|---|
| committer | Frederic Weisbecker <fweisbec@gmail.com> | 2013-05-02 17:54:19 +0200 | 
| commit | c032862fba51a3ca504752d3a25186b324c5ce83 (patch) | |
| tree | 955dc2ba4ab3df76ecc2bb780ee84aca04967e8d /lib/int_sqrt.c | |
| parent | fda76e074c7737fc57855dd17c762e50ed526052 (diff) | |
| parent | 8700c95adb033843fc163d112b9d21d4fda78018 (diff) | |
| download | olio-linux-3.10-c032862fba51a3ca504752d3a25186b324c5ce83.tar.xz olio-linux-3.10-c032862fba51a3ca504752d3a25186b324c5ce83.zip  | |
Merge commit '8700c95adb03' into timers/nohz
The full dynticks tree needs the latest RCU and sched
upstream updates in order to fix some dependencies.
Merge a common upstream merge point that has these
updates.
Conflicts:
	include/linux/perf_event.h
	kernel/rcutree.h
	kernel/rcutree_plugin.h
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Diffstat (limited to 'lib/int_sqrt.c')
| -rw-r--r-- | lib/int_sqrt.c | 32 | 
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/int_sqrt.c b/lib/int_sqrt.c index fc2eeb7cb2e..1ef4cc34497 100644 --- a/lib/int_sqrt.c +++ b/lib/int_sqrt.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2013 Davidlohr Bueso <davidlohr.bueso@hp.com> + * + *  Based on the shift-and-subtract algorithm for computing integer + *  square root from Guy L. Steele. + */  #include <linux/kernel.h>  #include <linux/export.h> @@ -10,23 +16,23 @@   */  unsigned long int_sqrt(unsigned long x)  { -	unsigned long op, res, one; +	unsigned long b, m, y = 0; -	op = x; -	res = 0; +	if (x <= 1) +		return x; -	one = 1UL << (BITS_PER_LONG - 2); -	while (one > op) -		one >>= 2; +	m = 1UL << (BITS_PER_LONG - 2); +	while (m != 0) { +		b = y + m; +		y >>= 1; -	while (one != 0) { -		if (op >= res + one) { -			op = op - (res + one); -			res = res +  2 * one; +		if (x >= b) { +			x -= b; +			y += m;  		} -		res /= 2; -		one /= 4; +		m >>= 2;  	} -	return res; + +	return y;  }  EXPORT_SYMBOL(int_sqrt);  |