[Mesa-dev] [PATCH 21/28] Replace IS_INF_OR_NAN with util_is_inf_or_nan

Dylan Baker dylan at pnwbakers.com
Fri Nov 9 18:40:14 UTC 2018


---
 src/mesa/main/draw.c            |  4 ++--
 src/mesa/main/imports.h         | 23 -----------------------
 src/mesa/program/prog_execute.c | 28 ++++++++++++++--------------
 src/mesa/swrast/s_aalinetemp.h  |  2 +-
 src/mesa/swrast/s_aatritemp.h   |  2 +-
 src/mesa/swrast/s_linetemp.h    |  2 +-
 src/mesa/swrast/s_points.c      |  2 +-
 src/mesa/swrast/s_tritemp.h     |  3 ++-
 src/mesa/tnl/t_split_copy.c     |  2 +-
 src/mesa/tnl/t_vb_cliptmp.h     |  8 ++++----
 src/mesa/tnl/t_vb_program.c     |  2 +-
 11 files changed, 28 insertions(+), 50 deletions(-)

diff --git a/src/mesa/main/draw.c b/src/mesa/main/draw.c
index 99ea4d928be..d22cdc4eff6 100644
--- a/src/mesa/main/draw.c
+++ b/src/mesa/main/draw.c
@@ -88,7 +88,7 @@ check_array_data(struct gl_context *ctx, struct gl_vertex_array_object *vao,
             GLfloat *f = (GLfloat *) ((GLubyte *) data + binding->Stride * j);
             GLint k;
             for (k = 0; k < array->Size; k++) {
-               if (IS_INF_OR_NAN(f[k]) || f[k] >= 1.0e20F || f[k] <= -1.0e10F) {
+               if (util_is_inf_or_nan(f[k]) || f[k] >= 1.0e20F || f[k] <= -1.0e10F) {
                   printf("Bad array data:\n");
                   printf("  Element[%u].%u = %f\n", j, k, f[k]);
                   printf("  Array %u at %p\n", attrib, (void *) array);
@@ -98,7 +98,7 @@ check_array_data(struct gl_context *ctx, struct gl_vertex_array_object *vao,
                          array->Ptr, bo->Name);
                   f[k] = 1.0F;  /* XXX replace the bad value! */
                }
-               /*assert(!IS_INF_OR_NAN(f[k])); */
+               /*assert(!util_is_inf_or_nan(f[k])); */
             }
          }
          break;
diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h
index 555abda6983..1aaa9d88294 100644
--- a/src/mesa/main/imports.h
+++ b/src/mesa/main/imports.h
@@ -84,29 +84,6 @@ typedef union { GLfloat f; GLint i; GLuint u; } fi_type;
 /*@}*/
 
 
-
-/**
- * finite macro.
- */
-#if defined(_MSC_VER)
-#  define finite _finite
-#endif
-
-
-/***
- *** IS_INF_OR_NAN: test if float is infinite or NaN
- ***/
-#if defined(isfinite)
-#define IS_INF_OR_NAN(x)        (!isfinite(x))
-#elif defined(finite)
-#define IS_INF_OR_NAN(x)        (!finite(x))
-#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-#define IS_INF_OR_NAN(x)        (!isfinite(x))
-#else
-#define IS_INF_OR_NAN(x)        (!finite(x))
-#endif
-
-
 /**********************************************************************
  * Functions
  */
diff --git a/src/mesa/program/prog_execute.c b/src/mesa/program/prog_execute.c
index 6ada78565cc..956b84a20d6 100644
--- a/src/mesa/program/prog_execute.c
+++ b/src/mesa/program/prog_execute.c
@@ -213,10 +213,10 @@ fetch_vector4(const struct prog_src_register *source,
    }
 
 #ifdef NAN_CHECK
-   assert(!IS_INF_OR_NAN(result[0]));
-   assert(!IS_INF_OR_NAN(result[0]));
-   assert(!IS_INF_OR_NAN(result[0]));
-   assert(!IS_INF_OR_NAN(result[0]));
+   assert(!util_is_inf_or_nan(result[0]));
+   assert(!util_is_inf_or_nan(result[0]));
+   assert(!util_is_inf_or_nan(result[0]));
+   assert(!util_is_inf_or_nan(result[0]));
 #endif
 }
 
@@ -332,9 +332,9 @@ store_vector4(const struct prog_instruction *inst,
 
 #if 0
    if (value[0] > 1.0e10 ||
-       IS_INF_OR_NAN(value[0]) ||
-       IS_INF_OR_NAN(value[1]) ||
-       IS_INF_OR_NAN(value[2]) || IS_INF_OR_NAN(value[3]))
+       util_is_inf_or_nan(value[0]) ||
+       util_is_inf_or_nan(value[1]) ||
+       util_is_inf_or_nan(value[2]) || util_is_inf_or_nan(value[3]))
       printf("store %g %g %g %g\n", value[0], value[1], value[2], value[3]);
 #endif
 
@@ -347,10 +347,10 @@ store_vector4(const struct prog_instruction *inst,
    }
 
 #ifdef NAN_CHECK
-   assert(!IS_INF_OR_NAN(value[0]));
-   assert(!IS_INF_OR_NAN(value[0]));
-   assert(!IS_INF_OR_NAN(value[0]));
-   assert(!IS_INF_OR_NAN(value[0]));
+   assert(!util_is_inf_or_nan(value[0]));
+   assert(!util_is_inf_or_nan(value[0]));
+   assert(!util_is_inf_or_nan(value[0]));
+   assert(!util_is_inf_or_nan(value[0]));
 #endif
 
    if (writeMask & WRITEMASK_X)
@@ -614,7 +614,7 @@ _mesa_execute_program(struct gl_context * ctx,
             fetch_vector1(&inst->SrcReg[0], machine, a);
             val = exp2f(a[0]);
             /*
-            if (IS_INF_OR_NAN(val))
+            if (util_is_inf_or_nan(val))
                val = 1.0e10;
             */
             result[0] = result[1] = result[2] = result[3] = val;
@@ -744,7 +744,7 @@ _mesa_execute_program(struct gl_context * ctx,
             fetch_vector1(&inst->SrcReg[0], machine, t);
             abs_t0 = fabsf(t[0]);
             if (abs_t0 != 0.0F) {
-               if (IS_INF_OR_NAN(abs_t0))
+               if (util_is_inf_or_nan(abs_t0))
                {
                   SET_POS_INFINITY(q[0]);
                   q[1] = 1.0F;
@@ -931,7 +931,7 @@ _mesa_execute_program(struct gl_context * ctx,
             if (DEBUG_PROG) {
                if (a[0] == 0)
                   printf("RCP(0)\n");
-               else if (IS_INF_OR_NAN(a[0]))
+               else if (util_is_inf_or_nan(a[0]))
                   printf("RCP(inf)\n");
             }
             result[0] = result[1] = result[2] = result[3] = 1.0F / a[0];
diff --git a/src/mesa/swrast/s_aalinetemp.h b/src/mesa/swrast/s_aalinetemp.h
index 64767a3a564..9997d03753a 100644
--- a/src/mesa/swrast/s_aalinetemp.h
+++ b/src/mesa/swrast/s_aalinetemp.h
@@ -123,7 +123,7 @@ NAME(line)(struct gl_context *ctx, const SWvertex *v0, const SWvertex *v1)
                                  ctx->Const.MinLineWidthAA,
                                  ctx->Const.MaxLineWidthAA);
 
-   if (line.len == 0.0F || IS_INF_OR_NAN(line.len))
+   if (line.len == 0.0F || util_is_inf_or_nan(line.len))
       return;
 
    INIT_SPAN(line.span, GL_LINE);
diff --git a/src/mesa/swrast/s_aatritemp.h b/src/mesa/swrast/s_aatritemp.h
index 230dab81633..1de627208a1 100644
--- a/src/mesa/swrast/s_aatritemp.h
+++ b/src/mesa/swrast/s_aatritemp.h
@@ -103,7 +103,7 @@
       const GLfloat botDy = vMid->attrib[VARYING_SLOT_POS][1] - vMin->attrib[VARYING_SLOT_POS][1];
       const GLfloat area = majDx * botDy - botDx * majDy;
       /* Do backface culling */
-      if (area * bf < 0 || area == 0 || IS_INF_OR_NAN(area))
+      if (area * bf < 0 || area == 0 || util_is_inf_or_nan(area))
 	 return;
       ltor = (GLboolean) (area < 0.0F);
 
diff --git a/src/mesa/swrast/s_linetemp.h b/src/mesa/swrast/s_linetemp.h
index 035a1e6409a..6706ec788b1 100644
--- a/src/mesa/swrast/s_linetemp.h
+++ b/src/mesa/swrast/s_linetemp.h
@@ -101,7 +101,7 @@ NAME( struct gl_context *ctx, const SWvertex *vert0, const SWvertex *vert1 )
    {
       GLfloat tmp = vert0->attrib[VARYING_SLOT_POS][0] + vert0->attrib[VARYING_SLOT_POS][1]
                   + vert1->attrib[VARYING_SLOT_POS][0] + vert1->attrib[VARYING_SLOT_POS][1];
-      if (IS_INF_OR_NAN(tmp))
+      if (util_is_inf_or_nan(tmp))
 	 return;
    }
 
diff --git a/src/mesa/swrast/s_points.c b/src/mesa/swrast/s_points.c
index de5cd692170..1c6c239042a 100644
--- a/src/mesa/swrast/s_points.c
+++ b/src/mesa/swrast/s_points.c
@@ -38,7 +38,7 @@
    do {                                              \
       float tmp = (V)->attrib[VARYING_SLOT_POS][0]   \
                 + (V)->attrib[VARYING_SLOT_POS][1];  \
-      if (IS_INF_OR_NAN(tmp))                        \
+      if (util_is_inf_or_nan(tmp))                   \
 	 return;                                     \
    } while(0)
 
diff --git a/src/mesa/swrast/s_tritemp.h b/src/mesa/swrast/s_tritemp.h
index 1d71839713c..4dc42a80a72 100644
--- a/src/mesa/swrast/s_tritemp.h
+++ b/src/mesa/swrast/s_tritemp.h
@@ -90,6 +90,7 @@
  * SUB_PIXEL_BITS.
  */
 
+#include "util/u_math.h"
 
 #ifndef MAX_GLUINT
 #define MAX_GLUINT	0xffffffffu
@@ -239,7 +240,7 @@ static void NAME(struct gl_context *ctx, const SWvertex *v0,
    {
       const GLfloat area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy;
 
-      if (IS_INF_OR_NAN(area) || area == 0.0F)
+      if (util_is_inf_or_nan(area) || area == 0.0F)
          return;
 
       if (area * bf * swrast->_BackfaceCullSign < 0.0F)
diff --git a/src/mesa/tnl/t_split_copy.c b/src/mesa/tnl/t_split_copy.c
index 085ae9a28c9..edd7eb901c8 100644
--- a/src/mesa/tnl/t_split_copy.c
+++ b/src/mesa/tnl/t_split_copy.c
@@ -280,7 +280,7 @@ elt(struct copy_context *copy, GLuint elt_idx)
             GLuint k;
             GLfloat *f = (GLfloat *) srcptr;
             for (k = 0; k < srcarray->Size; k++) {
-               assert(!IS_INF_OR_NAN(f[k]));
+               assert(!util_is_inf_or_nan(f[k]));
                assert(f[k] <= 1.0e20 && f[k] >= -1.0e20);
             }
          }
diff --git a/src/mesa/tnl/t_vb_cliptmp.h b/src/mesa/tnl/t_vb_cliptmp.h
index c6546668806..9f2d5161d99 100644
--- a/src/mesa/tnl/t_vb_cliptmp.h
+++ b/src/mesa/tnl/t_vb_cliptmp.h
@@ -206,10 +206,10 @@ TAG(clip_tri)( struct gl_context *ctx, GLuint v0, GLuint v1, GLuint v2, GLubyte
          printf("  %u: %u: %f, %f, %f, %f\n",
 		i, j,
 		coord[j][0], coord[j][1], coord[j][2], coord[j][3]);
-         assert(!IS_INF_OR_NAN(coord[j][0]));
-         assert(!IS_INF_OR_NAN(coord[j][1]));
-         assert(!IS_INF_OR_NAN(coord[j][2]));
-         assert(!IS_INF_OR_NAN(coord[j][3]));
+         assert(!util_is_inf_or_nan(coord[j][0]));
+         assert(!util_is_inf_or_nan(coord[j][1]));
+         assert(!util_is_inf_or_nan(coord[j][2]));
+         assert(!util_is_inf_or_nan(coord[j][3]));
       }
    }
 
diff --git a/src/mesa/tnl/t_vb_program.c b/src/mesa/tnl/t_vb_program.c
index 8d8aca614e3..3c760382acf 100644
--- a/src/mesa/tnl/t_vb_program.c
+++ b/src/mesa/tnl/t_vb_program.c
@@ -53,7 +53,7 @@
 static inline void
 check_float(float x)
 {
-   assert(!IS_INF_OR_NAN(x));
+   assert(!util_is_inf_or_nan(x));
    assert(1.0e-15 <= x && x <= 1.0e15);
 }
 #endif
-- 
2.19.1



More information about the mesa-dev mailing list