Re: PowerPC optional instructions
Re: PowerPC optional instructions
- Subject: Re: PowerPC optional instructions
- From: Urs Heckmann <email@hidden>
- Date: Wed, 26 May 2004 23:30:43 +0200
Am 26.05.2004 um 22:00 schrieb Pavol Markovic:
If you look into motorola/ibm cpu tech specs you'll find the answer.
If I remember right it's implemented in G3/G4/G5 CPU's.
My question is, how to use this instruction - asm block in C code?
Here's what I use in XCode (defined in a header file, of course):
static inline float __fsel(float number, float val1, float val2)
{
float y;
asm("fsel %0,%1,%2,%3" : "=f" (y) : "f" (number), "f" (val1), "f"
(val2));
return y;
}
static inline float __fres(float number)
{
float y;
asm("fres %0,%1" : "=f" (y) : "f" (number));
return y;
}
static inline float __frsqrte(float number)
{
float y;
asm("frsqrte %0,%1" : "=f" (y) : "f" (number + 0.000001f));
return y;
}
static inline float FastReciprocalSqrt( float number ) {
float x = 0.5f * number;
float y;
y = __frsqrte( number );
y *= (1.5f - (x * y * y));
return y * (1.5f - (x * y * y));
}
static inline float FastSqrt(float x)
{
return x * FastReciprocalSqrt(x);
}
// compute two square roots at once... faster...
static inline void FastSqrt2( float &num1, float &num2 )
{
float x1 = 0.5f * num1;
float x2 = 0.5f * num2;
float y1, y2;
asm("frsqrte %0,%1" : "=f" (y1) : "f" (num1 + 0.000001f));
asm("frsqrte %0,%1" : "=f" (y2) : "f" (num2 + 0.000001f));
y1 = y1 * ( 1.5f - ( x1 * y1 * y1 ));
y2 = y2 * ( 1.5f - ( x2 * y2 * y2 ));
y1 = y1 * ( 1.5f - ( x1 * y1 * y1 ));
y2 = y2 * ( 1.5f - ( x2 * y2 * y2 ));
num1 *= y1;
num2 *= y2;
}
Cheers,
;) Urs
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.