Chapter 2 C and C++ Source-Level Optimizations 45
Software Optimization Guide for AMD64 Processors
25112 Rev. 3.06 September 2005
Listing 17. Preferred
// Assumes pointers are different and q != r.
void isqrt(unsigned long a, unsigned long *q, unsigned long *r) {
unsigned long qq, rr;
qq = a;
if (a > 0) {
while (qq > (rr = a / qq)) {
qq = (qq + rr) >> 1;
}
}
rr = a - qq * qq;
*q = qq;
*r = rr;
}