diff options
author | Brian Paul <brian.paul@tungstengraphics.com> | 2008-08-22 15:51:38 -0600 |
---|---|---|
committer | Brian Paul <brian.paul@tungstengraphics.com> | 2008-08-22 15:51:38 -0600 |
commit | a22bdd42d77bc858814f37d657fa940a520dbe56 (patch) | |
tree | 7f0c4307322a02a436d0a17a108f0a8c20eb7146 /src/gallium/auxiliary/util | |
parent | 9935e3b7303da656e258d4bd5bc799ffbfbc737b (diff) |
gallium: move math macros from p_util.h to u_math.h
More can be done...
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r-- | src/gallium/auxiliary/util/u_math.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index e179ce700f..09c55e437f 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/src/gallium/auxiliary/util/u_math.h @@ -29,6 +29,9 @@ /** * Math utilities and approximations for common math functions. * Reduced precision is usually acceptable in shaders... + * + * "fast" is used in the names of functions which are low-precision, + * or at least lower-precision than the normal C lib functions. */ @@ -36,6 +39,7 @@ #define U_MATH_H +#include "pipe/p_compiler.h" #include "pipe/p_util.h" #include "util/u_math.h" @@ -141,4 +145,49 @@ util_fast_pow(float x, float y) } + +/** + * Floor(x), returned as int. + */ +static INLINE int +util_ifloor(float f) +{ + int ai, bi; + double af, bf; + union fi u; + af = (3 << 22) + 0.5 + (double)f; + bf = (3 << 22) + 0.5 - (double)f; + u.f = (float) af; ai = u.i; + u.f = (float) bf; bi = u.i; + return (ai - bi) >> 1; +} + + +/** + * Round float to nearest int. + */ +static INLINE int +util_iround(float f) +{ +#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86) + int r; + __asm__ ("fistpl %0" : "=m" (r) : "t" (f) : "st"); + return r; +#elif defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86) + int r; + _asm { + fld f + fistp r + } + return r; +#else + if (f >= 0.0f) + return (int) (f + 0.5f); + else + return (int) (f - 0.5f); +#endif +} + + + #endif /* U_MATH_H */ |