2 * Copyright (C) 2013 Davidlohr Bueso <davidlohr.bueso@hp.com>
4 * Based on the shift-and-subtract algorithm for computing integer
5 * square root from Guy L. Steele.
8 #include <linux/kernel.h>
9 #include <linux/export.h>
10 #include <linux/bitops.h>
13 * int_sqrt - rough approximation to sqrt
14 * @x: integer of which to calculate the sqrt
16 * A very rough approximation to the sqrt() function.
18 unsigned long int_sqrt(unsigned long x
)
20 unsigned long b
, m
, y
= 0;
25 m
= 1UL << (__fls(x
) & ~1UL);
39 EXPORT_SYMBOL(int_sqrt
);