Skip to contentSkip to conversation

lib/int_sqrt.c: Optimize square root function

PATCH Superseded Anshul Garg 1 participant 1 message Jan 29, 2015 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/int_sqrt.c: Optimize square root function

From: Anshul Garg <[email protected]>

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.

---
 lib/int_sqrt.c |    3 +++
 1 file changed, 3 insertions(+)
lib/int_sqrt.c +3 -0
index 1ef4cc3..64ae722 100644
@@ -22,6 +22,9 @@ unsigned long int_sqrt(unsigned long x)
 		return x;
 
 	m = 1UL << (BITS_PER_LONG - 2);
+
+	while (m > x)
+		m >>= 2;
 	while (m != 0) {
 		b = y + m;
 		y >>= 1;
Signature · 6 lines
1.7.9.5


---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com