Mesa (master): mesa: check/prevent NaN for EX2/LG2

Brian Paul brianp at kemper.freedesktop.org
Wed Jun 3 23:18:43 UTC 2009


Module: Mesa
Branch: master
Commit: 035de6a82b6c911a81ca9c678aac59772eaff8d3
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=035de6a82b6c911a81ca9c678aac59772eaff8d3

Author: Brian Paul <brianp at vmware.com>
Date:   Wed Jun  3 15:42:52 2009 -0600

mesa: check/prevent NaN for EX2/LG2

---

 src/mesa/shader/prog_execute.c |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/mesa/shader/prog_execute.c b/src/mesa/shader/prog_execute.c
index 68a5935..2b7237e 100644
--- a/src/mesa/shader/prog_execute.c
+++ b/src/mesa/shader/prog_execute.c
@@ -832,10 +832,14 @@ _mesa_execute_program(GLcontext * ctx,
          break;
       case OPCODE_EX2:         /* Exponential base 2 */
          {
-            GLfloat a[4], result[4];
+            GLfloat a[4], result[4], val;
             fetch_vector1(&inst->SrcReg[0], machine, a);
-            result[0] = result[1] = result[2] = result[3] =
-               (GLfloat) _mesa_pow(2.0, a[0]);
+            val = (GLfloat) _mesa_pow(2.0, a[0]);
+            /*
+            if (IS_INF_OR_NAN(val))
+               val = 1.0e10;
+            */
+            result[0] = result[1] = result[2] = result[3] = val;
             store_vector4(inst, machine, result);
          }
          break;
@@ -911,12 +915,17 @@ _mesa_execute_program(GLcontext * ctx,
          break;
       case OPCODE_LG2:         /* log base 2 */
          {
-            GLfloat a[4], result[4];
+            GLfloat a[4], result[4], val;
             fetch_vector1(&inst->SrcReg[0], machine, a);
 	    /* The fast LOG2 macro doesn't meet the precision requirements.
 	     */
-            result[0] = result[1] = result[2] = result[3] =
-		(log(a[0]) * 1.442695F);
+            if (a[0] == 0.0F) {
+               val = 0.0F;
+            }
+            else {
+               val = log(a[0]) * 1.442695F;
+            }
+            result[0] = result[1] = result[2] = result[3] = val;
             store_vector4(inst, machine, result);
          }
          break;




More information about the mesa-commit mailing list