25112 Rev. 3.06 September 2005

Software Optimization Guide for AMD64 Processors

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;

}

Chapter 2

C and C++ Source-Level Optimizations

45

Page 61
Image 61
AMD 250 manual Listing 17. Preferred