Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00026 #ifndef __CS_CSQSQRT_H__
00027 #define __CS_CSQSQRT_H__
00028
00029 #include "cssysdef.h"
00030 #include <math.h>
00031
00039 static CS_FORCEINLINE float csQsqrt (float x);
00040
00048 static CS_FORCEINLINE float csQisqrt (float x);
00049
00052 #if !defined(CS_NO_QSQRT) && \
00053 defined(CS_PROCESSOR_POWERPC) && defined(CS_COMPILER_GCC)
00054
00055
00056
00057
00058
00059
00060
00061
00062 static CS_FORCEINLINE float csQsqrt(float x)
00063 {
00064 float y0 = 0.0;
00065
00066 if (x != 0.0)
00067 {
00068 float x0 = x * 0.5f;
00069
00070 __asm__ __volatile__ ("frsqrte %0,%1" : "=f" (y0) : "f" (x));
00071
00072 y0 = y0 * (1.5f - x0 * y0 * y0);
00073 y0 = (y0 * (1.5f - x0 * y0 * y0)) * x;
00074 }
00075
00076 return y0;
00077 }
00078
00079
00080
00081
00082
00083 static inline float csQisqrt(float x)
00084 {
00085 float x0 = x * 0.5f;
00086 float y0;
00087 __asm__ __volatile__ ("frsqrte %0,%1" : "=f" (y0) : "f" (x));
00088
00089 y0 = y0 * (1.5f - x0 * y0 * y0);
00090 y0 = y0 * (1.5f - x0 * y0 * y0);
00091
00092 return y0;
00093 }
00094
00095 #else
00096
00097 static CS_FORCEINLINE float csQsqrt (float x) { return sqrtf(x); }
00098 static CS_FORCEINLINE float csQisqrt(float x) { return 1.0f / sqrtf(x); }
00099
00100 #endif
00101
00102 #endif // __CS_CSQSQRT_H__