https://github.com/torvalds/linux
Revision 6411fe69b8c4fd7811339c88c1843d562099fa2b authored by Stefano Stabellini on 01 December 2010, 14:51:44 UTC, committed by Stefano Stabellini on 02 December 2010, 14:40:48 UTC
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
1 parent af42b8d
Raw File
Tip revision: 6411fe69b8c4fd7811339c88c1843d562099fa2b authored by Stefano Stabellini on 01 December 2010, 14:51:44 UTC
xen: resume the pv console for hvm guests too
Tip revision: 6411fe6
int_sqrt.c

#include <linux/kernel.h>
#include <linux/module.h>

/**
 * int_sqrt - rough approximation to sqrt
 * @x: integer of which to calculate the sqrt
 *
 * A very rough approximation to the sqrt() function.
 */
unsigned long int_sqrt(unsigned long x)
{
	unsigned long op, res, one;

	op = x;
	res = 0;

	one = 1UL << (BITS_PER_LONG - 2);
	while (one > op)
		one >>= 2;

	while (one != 0) {
		if (op >= res + one) {
			op = op - (res + one);
			res = res +  2 * one;
		}
		res /= 2;
		one /= 4;
	}
	return res;
}
EXPORT_SYMBOL(int_sqrt);
back to top