summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/util
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2008-08-22 15:51:38 -0600
committerBrian Paul <brian.paul@tungstengraphics.com>2008-08-22 15:51:38 -0600
commita22bdd42d77bc858814f37d657fa940a520dbe56 (patch)
tree7f0c4307322a02a436d0a17a108f0a8c20eb7146 /src/gallium/auxiliary/util
parent9935e3b7303da656e258d4bd5bc799ffbfbc737b (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.h49
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 */