|
From: Edward K. C. <ek...@lg...> - 2004-02-12 15:40:28
|
On Feb 10, 2004, at 16:44, Seth Willits wrote:
> What about __fsqrt? Brian used it in all of his code. I'm assuming it
> was because it was/is faster than sqrt.
I think __fsqrt is only implemented on the G5 (PPC970), am I right?
Also, I am not sure it is supported by all development environments
yet. Does anyone know if CodeWarrior 9 has it? I heard it has yet to
be tuned for the G5, which is why I am not in a hurry to upgrade from
8.3.
It would be great to use __fsqrt, but presumably you would then need
two version of the Quesa library: one for the G5 and one for pre-G5s.
For the latter, __frsqrte has been around since the PPC603. FWIW, I
wrote a function like this and it speeded up my code quite a bit:
float mysqrtf(float x) {
float y;
if(x == 0.0f) y = 0.0f;
else {
const float k = 1.5f;
const float halfx = 0.5f * x;
y = __frsqrte(x);
y *= k - halfx * y * y;
y *= k - halfx * y * y; // add 2 more iterations for double
y *= x;
}
return y;
}
If you need a whole batch of single-precision square roots, I would
recommend vec_rsqrte as an alternative to __frsqrte. Not only does
altivec crunch four at a time, but vec_rsqrte gives you 20 bits of
precision (compared to only 5 for __frsqrte), meaning you can generally
get away with only one iterative refinement.
-Ted
|