summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/util
diff options
context:
space:
mode:
authorZack Rusin <zackr@vmware.com>2013-07-08 23:45:55 -0400
committerZack Rusin <zackr@vmware.com>2013-07-09 23:30:55 -0400
commit63386b2f66a6d450889cd5368bc599beb7f1efbf (patch)
treea82f6a2acbbfc7d639687033060a44a0621e12a3 /src/gallium/auxiliary/util
parent80bc14370a4db876ababc13404a93526c2b14de7 (diff)
downloadexternal_mesa3d-63386b2f66a6d450889cd5368bc599beb7f1efbf.zip
external_mesa3d-63386b2f66a6d450889cd5368bc599beb7f1efbf.tar.gz
external_mesa3d-63386b2f66a6d450889cd5368bc599beb7f1efbf.tar.bz2
util: treat denorm'ed floats like zero
The D3D10 spec is very explicit about treatment of denorm floats and the behavior is exactly the same for them as it would be for -0 or +0. This makes our shading code match that behavior, since OpenGL doesn't care and on a few cpu's it's faster (worst case the same). Float16 conversions will likely break but we'll fix them in a follow up commit. Signed-off-by: Zack Rusin <zackr@vmware.com> Reviewed-by: Jose Fonseca <jfonseca@vmware.com> Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r--src/gallium/auxiliary/util/u_math.c56
-rw-r--r--src/gallium/auxiliary/util/u_math.h7
2 files changed, 63 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_math.c b/src/gallium/auxiliary/util/u_math.c
index 2811475..2487bc7 100644
--- a/src/gallium/auxiliary/util/u_math.c
+++ b/src/gallium/auxiliary/util/u_math.c
@@ -28,6 +28,7 @@
#include "util/u_math.h"
+#include "util/u_cpu_detect.h"
/** 2^x, for x in [-1.0, 1.0) */
@@ -70,4 +71,59 @@ util_init_math(void)
}
}
+/**
+ * Fetches the contents of the fpstate (mxcsr on x86) register.
+ *
+ * On platforms without support for it just returns 0.
+ */
+unsigned
+util_fpstate_get(void)
+{
+ unsigned mxcsr = 0;
+
+#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
+ if (util_cpu_caps.has_sse) {
+ mxcsr = __builtin_ia32_stmxcsr();
+ }
+#endif
+ return mxcsr;
+}
+
+/**
+ * Make sure that the fp treats the denormalized floating
+ * point numbers as zero.
+ *
+ * This is the behavior required by D3D10. OpenGL doesn't care.
+ */
+unsigned
+util_fpstate_set_denorms_to_zero(unsigned current_mxcsr)
+{
+#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
+#define MXCSR_DAZ (1 << 6) /* Enable denormals are zero mode */
+#define MXCSR_FTZ (1 << 15) /* Enable flush to zero mode */
+ if (util_cpu_caps.has_sse) {
+ current_mxcsr |= MXCSR_FTZ;
+ if (util_cpu_caps.has_sse3) {
+ current_mxcsr |= MXCSR_DAZ;
+ }
+ util_fpstate_set(current_mxcsr);
+ }
+#endif
+ return current_mxcsr;
+}
+
+/**
+ * Set the state of the fpstate (mxcsr on x86) register.
+ *
+ * On platforms without support for it's a noop.
+ */
+void
+util_fpstate_set(unsigned mxcsr)
+{
+#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
+ if (util_cpu_caps.has_sse) {
+ __builtin_ia32_ldmxcsr(mxcsr);
+ }
+#endif
+}
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index 64d16cb..bc39488 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -763,6 +763,13 @@ static INLINE int32_t util_signed_fixed(float value, unsigned frac_bits)
return (int32_t)(value * (1<<frac_bits));
}
+unsigned
+util_fpstate_get(void);
+unsigned
+util_fpstate_set_denorms_to_zero(unsigned current_fpstate);
+void
+util_fpstate_set(unsigned fpstate);
+
#ifdef __cplusplus