[Mesa-dev] [PATCH 4/5] glsl: Add isinf() and isnan() builtins.

Paul Berry stereotype441 at gmail.com
Wed Oct 26 18:42:55 PDT 2011


The implementations are as follows:

isinf(x) = (abs(x) == +infinity)
isnan(x) = (x != x)

Note: the latter formula is not necessarily obvious.  It works because
NaN is the only floating point number that does not equal itself.

Fixes piglit tests "isinf-and-isnan fs_basic" and "isinf-and-isnan
vs_basic".
---
 src/glsl/builtins/ir/isinf.ir       |   17 +++++++++++++++++
 src/glsl/builtins/ir/isnan.ir       |   17 +++++++++++++++++
 src/glsl/builtins/profiles/130.frag |    2 --
 src/glsl/builtins/profiles/130.vert |    2 --
 4 files changed, 34 insertions(+), 4 deletions(-)
 create mode 100644 src/glsl/builtins/ir/isinf.ir
 create mode 100644 src/glsl/builtins/ir/isnan.ir

diff --git a/src/glsl/builtins/ir/isinf.ir b/src/glsl/builtins/ir/isinf.ir
new file mode 100644
index 0000000..b19e510
--- /dev/null
+++ b/src/glsl/builtins/ir/isinf.ir
@@ -0,0 +1,17 @@
+((function isinf
+   (signature bool
+     (parameters
+       (declare (in) float x))
+     ((return (expression bool == (expression float abs (var_ref x)) (constant float (#inf))))))
+   (signature bvec2
+     (parameters
+       (declare (in) vec2 x))
+     ((return (expression bvec2 == (expression vec2 abs (var_ref x)) (constant vec2 (#inf #inf))))))
+   (signature bvec3
+     (parameters
+       (declare (in) vec3 x))
+     ((return (expression bvec3 == (expression vec3 abs (var_ref x)) (constant vec3 (#inf #inf #inf))))))
+   (signature bvec4
+     (parameters
+       (declare (in) vec4 x))
+     ((return (expression bvec4 == (expression vec4 abs (var_ref x)) (constant vec4 (#inf #inf #inf #inf))))))))
diff --git a/src/glsl/builtins/ir/isnan.ir b/src/glsl/builtins/ir/isnan.ir
new file mode 100644
index 0000000..b67349f
--- /dev/null
+++ b/src/glsl/builtins/ir/isnan.ir
@@ -0,0 +1,17 @@
+((function isnan
+   (signature bool
+     (parameters
+       (declare (in) float x))
+     ((return (expression bool != (var_ref x) (var_ref x)))))
+   (signature bvec2
+     (parameters
+       (declare (in) vec2 x))
+     ((return (expression bvec2 != (var_ref x) (var_ref x)))))
+   (signature bvec3
+     (parameters
+       (declare (in) vec3 x))
+     ((return (expression bvec3 != (var_ref x) (var_ref x)))))
+   (signature bvec4
+     (parameters
+       (declare (in) vec4 x))
+     ((return (expression bvec4 != (var_ref x) (var_ref x)))))))
diff --git a/src/glsl/builtins/profiles/130.frag b/src/glsl/builtins/profiles/130.frag
index c121859..1f212c1 100644
--- a/src/glsl/builtins/profiles/130.frag
+++ b/src/glsl/builtins/profiles/130.frag
@@ -288,7 +288,6 @@ vec2  smoothstep(float edge0, float edge1, vec2  x);
 vec3  smoothstep(float edge0, float edge1, vec3  x);
 vec4  smoothstep(float edge0, float edge1, vec4  x);
 
-#if 0
 bool  isnan(float x);
 bvec2 isnan(vec2  x);
 bvec3 isnan(vec3  x);
@@ -298,7 +297,6 @@ bool  isinf(float x);
 bvec2 isinf(vec2  x);
 bvec3 isinf(vec3  x);
 bvec4 isinf(vec4  x);
-#endif
 
 /*
  * 8.4 - Geometric Functions
diff --git a/src/glsl/builtins/profiles/130.vert b/src/glsl/builtins/profiles/130.vert
index ebd9a50..df17ede 100644
--- a/src/glsl/builtins/profiles/130.vert
+++ b/src/glsl/builtins/profiles/130.vert
@@ -288,7 +288,6 @@ vec2  smoothstep(float edge0, float edge1, vec2  x);
 vec3  smoothstep(float edge0, float edge1, vec3  x);
 vec4  smoothstep(float edge0, float edge1, vec4  x);
 
-#if 0
 bool  isnan(float x);
 bvec2 isnan(vec2  x);
 bvec3 isnan(vec3  x);
@@ -298,7 +297,6 @@ bool  isinf(float x);
 bvec2 isinf(vec2  x);
 bvec3 isinf(vec3  x);
 bvec4 isinf(vec4  x);
-#endif
 
 /*
  * 8.4 - Geometric Functions
-- 
1.7.6.4



More information about the mesa-dev mailing list