lkml.org 
[lkml]   [2004]   [Apr]   [3]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
DateSat, 3 Apr 2004 13:16:23 +0200
From<>(Walter Harms)
Subjectpatch: linux-2.6.4/lib/int_sqrt.c long aware
hi list,
this patch make int_sqrt() handle long properly. i tested it
on my alpha and i386. also some comparision again an alternativ int_sqrt() code.
The placement (and using) of 'tmp' is a bit odd but faster (on alpha, no matter on i386).

happy hacking,
walter

ps: i must use c&p so be aware of possible tab->space translations


--- linux-2.6.4/lib/int_sqrt.c.org	2004-03-21 12:58:55.783035928 +0100
+++ linux-2.6.4/lib/int_sqrt.c	2004-03-21 13:16:20.999138928 +0100
@@ -10,22 +10,23 @@
  */
 unsigned long int_sqrt(unsigned long x)
 {
-	unsigned long op, res, one;
+	unsigned long op, res, one,tmp;
 
 	op = x;
 	res = 0;
 
-	one = 1 << 30;
+	one = 1UL << (BITS_PER_LONG-2);
 	while (one > op)
 		one >>= 2;
 
 	while (one != 0) {
+		tmp=res + one;
 		if (op >= res + one) {
-			op = op - (res + one);
-			res = res +  2 * one;
+			op = op - tmp;
+			res = tmp + one;
 		}
-		res /= 2;
-		one /= 4;
+		res >>= 1;
+		one >>= 2;
 	}
 	return res;
 }
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:02    [from the cache]
©2003-2008