gallium: move math macros from p_util.h to u_math.h

More can be done...
This commit is contained in:
Brian Paul
2008-08-22 15:51:38 -06:00
parent 9935e3b730
commit a22bdd42d7
2 changed files with 49 additions and 51 deletions
+49
View File
@@ -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 */
-51
View File
@@ -399,57 +399,6 @@ do { \
} while (0)
static INLINE int 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;
}
#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)
static INLINE int iround(float f)
{
int r;
__asm__ ("fistpl %0" : "=m" (r) : "t" (f) : "st");
return r;
}
#elif defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86)
static INLINE int iround(float f)
{
int r;
_asm {
fld f
fistp r
}
return r;
}
#else
#define IROUND(f) ((int) (((f) >= 0.0F) ? ((f) + 0.5F) : ((f) - 0.5F)))
#endif
/* Could maybe have an inline version of this?
*/
#if defined(__GNUC__)
#define FABSF(x) fabsf(x)
#else
#define FABSF(x) ((float) fabs(x))
#endif
#if defined(__GNUC__)
#define CEILF(x) ceilf(x)
#else
#define CEILF(x) ((float) ceil(x))
#endif
static INLINE int align(int value, int alignment)
{
return (value + alignment - 1) & ~(alignment - 1);