|
|
Warp wrote:
> Perhaps you shouldn't rely on the ability of the compiler to realize
> that the exact same sqrt() is being performed here, and instead calculate
> it only once into a variable. That way you remove the risk of the
> code actually calculating the slow sqrt() twice for no reason.
>
Good point, thanks for the suggestion. I checked the assembly output and
g++ produces better results with a temporary variable. Less code and
less jumps. Few questions:
1. I understand that sqrtsd takes the square root. What does "call sqrt"
do? Calls a subroutine called "sqrt"? Why on earth are they both needed?
The version with temp variable used one "call sqrt" and the original
version used 2 calls. And both had one sqrtsd.
2. What does "ucomisd %xmm0, %xmm0" effectively do? It compares the same
register.
(Last time I really programmed assembly was 10 years ago when I did a
burning flame demo program..."
Anyway, this was the best version:
double halfChord = sqrt(halfChord2);
double a = nearestPointDistance - halfChord;
if(a > EPSILON)
return a;
else
return nearestPointDistance + halfChord;
Post a reply to this message
|
|